1 /* 10G controller driver for Samsung SoCs
3 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Author: Siva Reddy Kallam <siva.kallam@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/bitops.h>
16 #include <linux/export.h>
18 #include <linux/netdevice.h>
19 #include <linux/phy.h>
21 #include "sxgbe_common.h"
22 #include "sxgbe_dma.h"
23 #include "sxgbe_desc.h"
25 /* DMA TX descriptor ring initialization */
26 static void sxgbe_init_tx_desc(struct sxgbe_tx_norm_desc *p)
28 p->tdes23.tx_rd_des23.own_bit = 0;
31 static void sxgbe_tx_desc_enable_tse(struct sxgbe_tx_norm_desc *p, u8 is_tse,
32 u32 total_hdr_len, u32 tcp_hdr_len,
35 p->tdes23.tx_rd_des23.tse_bit = is_tse;
36 p->tdes23.tx_rd_des23.buf1_size = total_hdr_len;
37 p->tdes23.tx_rd_des23.tcp_hdr_len = tcp_hdr_len / 4;
38 p->tdes23.tx_rd_des23.tx_pkt_len.tcp_payload_len = tcp_payload_len;
41 /* Assign buffer lengths for descriptor */
42 static void sxgbe_prepare_tx_desc(struct sxgbe_tx_norm_desc *p, u8 is_fd,
43 int buf1_len, int pkt_len, int cksum)
45 p->tdes23.tx_rd_des23.first_desc = is_fd;
46 p->tdes23.tx_rd_des23.buf1_size = buf1_len;
48 p->tdes23.tx_rd_des23.tx_pkt_len.cksum_pktlen.total_pkt_len = pkt_len;
51 p->tdes23.tx_rd_des23.tx_pkt_len.cksum_pktlen.cksum_ctl = cic_full;
54 /* Set VLAN control information */
55 static void sxgbe_tx_vlanctl_desc(struct sxgbe_tx_norm_desc *p, int vlan_ctl)
57 p->tdes23.tx_rd_des23.vlan_tag_ctl = vlan_ctl;
60 /* Set the owner of Normal descriptor */
61 static void sxgbe_set_tx_owner(struct sxgbe_tx_norm_desc *p)
63 p->tdes23.tx_rd_des23.own_bit = 1;
66 /* Get the owner of Normal descriptor */
67 static int sxgbe_get_tx_owner(struct sxgbe_tx_norm_desc *p)
69 return p->tdes23.tx_rd_des23.own_bit;
72 /* Invoked by the xmit function to close the tx descriptor */
73 static void sxgbe_close_tx_desc(struct sxgbe_tx_norm_desc *p)
75 p->tdes23.tx_rd_des23.last_desc = 1;
76 p->tdes23.tx_rd_des23.int_on_com = 1;
79 /* Clean the tx descriptor as soon as the tx irq is received */
80 static void sxgbe_release_tx_desc(struct sxgbe_tx_norm_desc *p)
82 memset(p, 0, sizeof(*p));
85 /* Clear interrupt on tx frame completion. When this bit is
86 * set an interrupt happens as soon as the frame is transmitted
88 static void sxgbe_clear_tx_ic(struct sxgbe_tx_norm_desc *p)
90 p->tdes23.tx_rd_des23.int_on_com = 0;
93 /* Last tx segment reports the transmit status */
94 static int sxgbe_get_tx_ls(struct sxgbe_tx_norm_desc *p)
96 return p->tdes23.tx_rd_des23.last_desc;
99 /* Get the buffer size from the descriptor */
100 static int sxgbe_get_tx_len(struct sxgbe_tx_norm_desc *p)
102 return p->tdes23.tx_rd_des23.buf1_size;
105 /* Set tx timestamp enable bit */
106 static void sxgbe_tx_enable_tstamp(struct sxgbe_tx_norm_desc *p)
108 p->tdes23.tx_rd_des23.timestmp_enable = 1;
111 /* get tx timestamp status */
112 static int sxgbe_get_tx_timestamp_status(struct sxgbe_tx_norm_desc *p)
114 return p->tdes23.tx_rd_des23.timestmp_enable;
117 /* TX Context Descripto Specific */
118 static void sxgbe_tx_ctxt_desc_set_ctxt(struct sxgbe_tx_ctxt_desc *p)
123 /* Set the owner of TX context descriptor */
124 static void sxgbe_tx_ctxt_desc_set_owner(struct sxgbe_tx_ctxt_desc *p)
129 /* Get the owner of TX context descriptor */
130 static int sxgbe_tx_ctxt_desc_get_owner(struct sxgbe_tx_ctxt_desc *p)
135 /* Set TX mss in TX context Descriptor */
136 static void sxgbe_tx_ctxt_desc_set_mss(struct sxgbe_tx_ctxt_desc *p, u16 mss)
138 p->maxseg_size = mss;
141 /* Get TX mss from TX context Descriptor */
142 static int sxgbe_tx_ctxt_desc_get_mss(struct sxgbe_tx_ctxt_desc *p)
144 return p->maxseg_size;
147 /* Set TX tcmssv in TX context Descriptor */
148 static void sxgbe_tx_ctxt_desc_set_tcmssv(struct sxgbe_tx_ctxt_desc *p)
153 /* Reset TX ostc in TX context Descriptor */
154 static void sxgbe_tx_ctxt_desc_reset_ostc(struct sxgbe_tx_ctxt_desc *p)
159 /* Set IVLAN information */
160 static void sxgbe_tx_ctxt_desc_set_ivlantag(struct sxgbe_tx_ctxt_desc *p,
161 int is_ivlanvalid, int ivlan_tag,
165 p->ivlan_tag_valid = is_ivlanvalid;
166 p->ivlan_tag = ivlan_tag;
167 p->ivlan_tag_ctl = ivlan_ctl;
171 /* Return IVLAN Tag */
172 static int sxgbe_tx_ctxt_desc_get_ivlantag(struct sxgbe_tx_ctxt_desc *p)
178 static void sxgbe_tx_ctxt_desc_set_vlantag(struct sxgbe_tx_ctxt_desc *p,
179 int is_vlanvalid, int vlan_tag)
182 p->vltag_valid = is_vlanvalid;
183 p->vlan_tag = vlan_tag;
187 /* Return VLAN Tag */
188 static int sxgbe_tx_ctxt_desc_get_vlantag(struct sxgbe_tx_ctxt_desc *p)
194 static void sxgbe_tx_ctxt_desc_set_tstamp(struct sxgbe_tx_ctxt_desc *p,
195 u8 ostc_enable, u64 tstamp)
198 p->ostc = ostc_enable;
199 p->tstamp_lo = (u32) tstamp;
200 p->tstamp_hi = (u32) (tstamp>>32);
203 /* Close TX context descriptor */
204 static void sxgbe_tx_ctxt_desc_close(struct sxgbe_tx_ctxt_desc *p)
209 /* WB status of context descriptor */
210 static int sxgbe_tx_ctxt_desc_get_cde(struct sxgbe_tx_ctxt_desc *p)
212 return p->ctxt_desc_err;
215 /* DMA RX descriptor ring initialization */
216 static void sxgbe_init_rx_desc(struct sxgbe_rx_norm_desc *p, int disable_rx_ic,
219 p->rdes23.rx_rd_des23.own_bit = 1;
221 p->rdes23.rx_rd_des23.int_on_com = disable_rx_ic;
225 static int sxgbe_get_rx_owner(struct sxgbe_rx_norm_desc *p)
227 return p->rdes23.rx_rd_des23.own_bit;
231 static void sxgbe_set_rx_owner(struct sxgbe_rx_norm_desc *p)
233 p->rdes23.rx_rd_des23.own_bit = 1;
236 /* Get the receive frame size */
237 static int sxgbe_get_rx_frame_len(struct sxgbe_rx_norm_desc *p)
239 return p->rdes23.rx_wb_des23.pkt_len;
242 /* Return first Descriptor status */
243 static int sxgbe_get_rx_fd_status(struct sxgbe_rx_norm_desc *p)
245 return p->rdes23.rx_wb_des23.first_desc;
248 /* Return Last Descriptor status */
249 static int sxgbe_get_rx_ld_status(struct sxgbe_rx_norm_desc *p)
251 return p->rdes23.rx_wb_des23.last_desc;
255 /* Return the RX status looking at the WB fields */
256 static int sxgbe_rx_wbstatus(struct sxgbe_rx_norm_desc *p,
257 struct sxgbe_extra_stats *x, int *checksum)
261 *checksum = CHECKSUM_UNNECESSARY;
262 if (p->rdes23.rx_wb_des23.err_summary) {
263 switch (p->rdes23.rx_wb_des23.err_l2_type) {
266 x->rx_code_gmii_err++;
268 case RX_WATCHDOG_ERR:
270 x->rx_watchdog_err++;
278 x->rx_gaint_pkt_err++;
281 *checksum = CHECKSUM_NONE;
285 *checksum = CHECKSUM_NONE;
288 case RX_OVERFLOW_ERR:
293 pr_err("Invalid Error type\n");
297 switch (p->rdes23.rx_wb_des23.err_l2_type) {
325 case RX_DVLAN_OCVLAN_ICVLAN_PKT:
326 x->dvlan_ocvlan_icvlan_pkt++;
328 case RX_DVLAN_OSVLAN_ISVLAN_PKT:
329 x->dvlan_osvlan_isvlan_pkt++;
331 case RX_DVLAN_OSVLAN_ICVLAN_PKT:
332 x->dvlan_osvlan_icvlan_pkt++;
334 case RX_DVLAN_OCVLAN_ISVLAN_PKT:
335 x->dvlan_ocvlan_icvlan_pkt++;
338 pr_err("Invalid L2 Packet type\n");
344 switch (p->rdes23.rx_wb_des23.layer34_pkt_type) {
348 case RX_IPV4_TCP_PKT:
351 case RX_IPV4_UDP_PKT:
354 case RX_IPV4_ICMP_PKT:
357 case RX_IPV4_UNKNOWN_PKT:
358 x->ip4_unknown_pkt++;
360 case RX_IPV6_TCP_PKT:
363 case RX_IPV6_UDP_PKT:
366 case RX_IPV6_ICMP_PKT:
369 case RX_IPV6_UNKNOWN_PKT:
370 x->ip6_unknown_pkt++;
373 pr_err("Invalid L3/L4 Packet type\n");
378 if (p->rdes23.rx_wb_des23.vlan_filter_match)
379 x->vlan_filter_match++;
381 if (p->rdes23.rx_wb_des23.sa_filter_fail) {
385 if (p->rdes23.rx_wb_des23.da_filter_fail) {
389 if (p->rdes23.rx_wb_des23.hash_filter_pass)
390 x->hash_filter_pass++;
392 if (p->rdes23.rx_wb_des23.l3_filter_match)
393 x->l3_filter_match++;
395 if (p->rdes23.rx_wb_des23.l4_filter_match)
396 x->l4_filter_match++;
401 /* Get own bit of context descriptor */
402 static int sxgbe_get_rx_ctxt_owner(struct sxgbe_rx_ctxt_desc *p)
407 /* Set own bit for context descriptor */
408 static void sxgbe_set_ctxt_rx_owner(struct sxgbe_rx_ctxt_desc *p)
414 /* Return the reception status looking at Context control information */
415 static void sxgbe_rx_ctxt_wbstatus(struct sxgbe_rx_ctxt_desc *p,
416 struct sxgbe_extra_stats *x)
418 if (p->tstamp_dropped)
419 x->timestamp_dropped++;
422 if (p->ptp_msgtype == RX_NO_PTP)
423 x->rx_msg_type_no_ptp++;
424 else if (p->ptp_msgtype == RX_PTP_SYNC)
425 x->rx_ptp_type_sync++;
426 else if (p->ptp_msgtype == RX_PTP_FOLLOW_UP)
427 x->rx_ptp_type_follow_up++;
428 else if (p->ptp_msgtype == RX_PTP_DELAY_REQ)
429 x->rx_ptp_type_delay_req++;
430 else if (p->ptp_msgtype == RX_PTP_DELAY_RESP)
431 x->rx_ptp_type_delay_resp++;
432 else if (p->ptp_msgtype == RX_PTP_PDELAY_REQ)
433 x->rx_ptp_type_pdelay_req++;
434 else if (p->ptp_msgtype == RX_PTP_PDELAY_RESP)
435 x->rx_ptp_type_pdelay_resp++;
436 else if (p->ptp_msgtype == RX_PTP_PDELAY_FOLLOW_UP)
437 x->rx_ptp_type_pdelay_follow_up++;
438 else if (p->ptp_msgtype == RX_PTP_ANNOUNCE)
439 x->rx_ptp_announce++;
440 else if (p->ptp_msgtype == RX_PTP_MGMT)
442 else if (p->ptp_msgtype == RX_PTP_SIGNAL)
444 else if (p->ptp_msgtype == RX_PTP_RESV_MSG)
445 x->rx_ptp_resv_msg_type++;
448 /* Get rx timestamp status */
449 static int sxgbe_get_rx_ctxt_tstamp_status(struct sxgbe_rx_ctxt_desc *p)
451 if ((p->tstamp_hi == 0xffffffff) && (p->tstamp_lo == 0xffffffff)) {
452 pr_err("Time stamp corrupted\n");
456 return p->tstamp_available;
460 static u64 sxgbe_get_rx_timestamp(struct sxgbe_rx_ctxt_desc *p)
465 ns |= ((u64)p->tstamp_hi) << 32;
470 static const struct sxgbe_desc_ops desc_ops = {
471 .init_tx_desc = sxgbe_init_tx_desc,
472 .tx_desc_enable_tse = sxgbe_tx_desc_enable_tse,
473 .prepare_tx_desc = sxgbe_prepare_tx_desc,
474 .tx_vlanctl_desc = sxgbe_tx_vlanctl_desc,
475 .set_tx_owner = sxgbe_set_tx_owner,
476 .get_tx_owner = sxgbe_get_tx_owner,
477 .close_tx_desc = sxgbe_close_tx_desc,
478 .release_tx_desc = sxgbe_release_tx_desc,
479 .clear_tx_ic = sxgbe_clear_tx_ic,
480 .get_tx_ls = sxgbe_get_tx_ls,
481 .get_tx_len = sxgbe_get_tx_len,
482 .tx_enable_tstamp = sxgbe_tx_enable_tstamp,
483 .get_tx_timestamp_status = sxgbe_get_tx_timestamp_status,
484 .tx_ctxt_desc_set_ctxt = sxgbe_tx_ctxt_desc_set_ctxt,
485 .tx_ctxt_desc_set_owner = sxgbe_tx_ctxt_desc_set_owner,
486 .get_tx_ctxt_owner = sxgbe_tx_ctxt_desc_get_owner,
487 .tx_ctxt_desc_set_mss = sxgbe_tx_ctxt_desc_set_mss,
488 .tx_ctxt_desc_get_mss = sxgbe_tx_ctxt_desc_get_mss,
489 .tx_ctxt_desc_set_tcmssv = sxgbe_tx_ctxt_desc_set_tcmssv,
490 .tx_ctxt_desc_reset_ostc = sxgbe_tx_ctxt_desc_reset_ostc,
491 .tx_ctxt_desc_set_ivlantag = sxgbe_tx_ctxt_desc_set_ivlantag,
492 .tx_ctxt_desc_get_ivlantag = sxgbe_tx_ctxt_desc_get_ivlantag,
493 .tx_ctxt_desc_set_vlantag = sxgbe_tx_ctxt_desc_set_vlantag,
494 .tx_ctxt_desc_get_vlantag = sxgbe_tx_ctxt_desc_get_vlantag,
495 .tx_ctxt_set_tstamp = sxgbe_tx_ctxt_desc_set_tstamp,
496 .close_tx_ctxt_desc = sxgbe_tx_ctxt_desc_close,
497 .get_tx_ctxt_cde = sxgbe_tx_ctxt_desc_get_cde,
498 .init_rx_desc = sxgbe_init_rx_desc,
499 .get_rx_owner = sxgbe_get_rx_owner,
500 .set_rx_owner = sxgbe_set_rx_owner,
501 .get_rx_frame_len = sxgbe_get_rx_frame_len,
502 .get_rx_fd_status = sxgbe_get_rx_fd_status,
503 .get_rx_ld_status = sxgbe_get_rx_ld_status,
504 .rx_wbstatus = sxgbe_rx_wbstatus,
505 .get_rx_ctxt_owner = sxgbe_get_rx_ctxt_owner,
506 .set_rx_ctxt_owner = sxgbe_set_ctxt_rx_owner,
507 .rx_ctxt_wbstatus = sxgbe_rx_ctxt_wbstatus,
508 .get_rx_ctxt_tstamp_status = sxgbe_get_rx_ctxt_tstamp_status,
509 .get_timestamp = sxgbe_get_rx_timestamp,
512 const struct sxgbe_desc_ops *sxgbe_get_desc_ops(void)