xref: /openbmc/linux/drivers/net/ethernet/samsung/sxgbe/sxgbe_desc.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21edb9ca6SSiva Reddy /* 10G controller driver for Samsung SoCs
31edb9ca6SSiva Reddy  *
41edb9ca6SSiva Reddy  * Copyright (C) 2013 Samsung Electronics Co., Ltd.
51edb9ca6SSiva Reddy  *		http://www.samsung.com
61edb9ca6SSiva Reddy  *
71edb9ca6SSiva Reddy  * Author: Siva Reddy Kallam <siva.kallam@samsung.com>
81edb9ca6SSiva Reddy  */
91edb9ca6SSiva Reddy 
101edb9ca6SSiva Reddy #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
111edb9ca6SSiva Reddy 
121edb9ca6SSiva Reddy #include <linux/bitops.h>
131edb9ca6SSiva Reddy #include <linux/export.h>
141edb9ca6SSiva Reddy #include <linux/io.h>
151edb9ca6SSiva Reddy #include <linux/netdevice.h>
161edb9ca6SSiva Reddy #include <linux/phy.h>
171edb9ca6SSiva Reddy 
181edb9ca6SSiva Reddy #include "sxgbe_common.h"
191edb9ca6SSiva Reddy #include "sxgbe_dma.h"
201edb9ca6SSiva Reddy #include "sxgbe_desc.h"
211edb9ca6SSiva Reddy 
221edb9ca6SSiva Reddy /* DMA TX descriptor ring initialization */
sxgbe_init_tx_desc(struct sxgbe_tx_norm_desc * p)231edb9ca6SSiva Reddy static void sxgbe_init_tx_desc(struct sxgbe_tx_norm_desc *p)
241edb9ca6SSiva Reddy {
251edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.own_bit = 0;
261edb9ca6SSiva Reddy }
271edb9ca6SSiva Reddy 
sxgbe_tx_desc_enable_tse(struct sxgbe_tx_norm_desc * p,u8 is_tse,u32 total_hdr_len,u32 tcp_hdr_len,u32 tcp_payload_len)281edb9ca6SSiva Reddy static void sxgbe_tx_desc_enable_tse(struct sxgbe_tx_norm_desc *p, u8 is_tse,
291edb9ca6SSiva Reddy 				     u32 total_hdr_len, u32 tcp_hdr_len,
301edb9ca6SSiva Reddy 				     u32 tcp_payload_len)
311edb9ca6SSiva Reddy {
321edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.tse_bit = is_tse;
331edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.buf1_size = total_hdr_len;
341edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.tcp_hdr_len = tcp_hdr_len / 4;
351edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.tx_pkt_len.tcp_payload_len  = tcp_payload_len;
361edb9ca6SSiva Reddy }
371edb9ca6SSiva Reddy 
381edb9ca6SSiva Reddy /* Assign buffer lengths for descriptor */
sxgbe_prepare_tx_desc(struct sxgbe_tx_norm_desc * p,u8 is_fd,int buf1_len,int pkt_len,int cksum)391edb9ca6SSiva Reddy static void sxgbe_prepare_tx_desc(struct sxgbe_tx_norm_desc *p, u8 is_fd,
401edb9ca6SSiva Reddy 				  int buf1_len, int pkt_len, int cksum)
411edb9ca6SSiva Reddy {
421edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.first_desc = is_fd;
431edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.buf1_size = buf1_len;
441edb9ca6SSiva Reddy 
453ee2b7c4SByungho An 	p->tdes23.tx_rd_des23.tx_pkt_len.pkt_len.total_pkt_len = pkt_len;
461edb9ca6SSiva Reddy 
471edb9ca6SSiva Reddy 	if (cksum)
483ee2b7c4SByungho An 		p->tdes23.tx_rd_des23.cksum_ctl = cic_full;
491edb9ca6SSiva Reddy }
501edb9ca6SSiva Reddy 
511edb9ca6SSiva Reddy /* Set VLAN control information */
sxgbe_tx_vlanctl_desc(struct sxgbe_tx_norm_desc * p,int vlan_ctl)521edb9ca6SSiva Reddy static void sxgbe_tx_vlanctl_desc(struct sxgbe_tx_norm_desc *p, int vlan_ctl)
531edb9ca6SSiva Reddy {
541edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.vlan_tag_ctl = vlan_ctl;
551edb9ca6SSiva Reddy }
561edb9ca6SSiva Reddy 
571edb9ca6SSiva Reddy /* Set the owner of Normal descriptor */
sxgbe_set_tx_owner(struct sxgbe_tx_norm_desc * p)581edb9ca6SSiva Reddy static void sxgbe_set_tx_owner(struct sxgbe_tx_norm_desc *p)
591edb9ca6SSiva Reddy {
601edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.own_bit = 1;
611edb9ca6SSiva Reddy }
621edb9ca6SSiva Reddy 
631edb9ca6SSiva Reddy /* Get the owner of Normal descriptor */
sxgbe_get_tx_owner(struct sxgbe_tx_norm_desc * p)641edb9ca6SSiva Reddy static int sxgbe_get_tx_owner(struct sxgbe_tx_norm_desc *p)
651edb9ca6SSiva Reddy {
661edb9ca6SSiva Reddy 	return p->tdes23.tx_rd_des23.own_bit;
671edb9ca6SSiva Reddy }
681edb9ca6SSiva Reddy 
691edb9ca6SSiva Reddy /* Invoked by the xmit function to close the tx descriptor */
sxgbe_close_tx_desc(struct sxgbe_tx_norm_desc * p)701edb9ca6SSiva Reddy static void sxgbe_close_tx_desc(struct sxgbe_tx_norm_desc *p)
711edb9ca6SSiva Reddy {
721edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.last_desc = 1;
731edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.int_on_com = 1;
741edb9ca6SSiva Reddy }
751edb9ca6SSiva Reddy 
761edb9ca6SSiva Reddy /* Clean the tx descriptor as soon as the tx irq is received */
sxgbe_release_tx_desc(struct sxgbe_tx_norm_desc * p)771edb9ca6SSiva Reddy static void sxgbe_release_tx_desc(struct sxgbe_tx_norm_desc *p)
781edb9ca6SSiva Reddy {
791edb9ca6SSiva Reddy 	memset(p, 0, sizeof(*p));
801edb9ca6SSiva Reddy }
811edb9ca6SSiva Reddy 
821edb9ca6SSiva Reddy /* Clear interrupt on tx frame completion. When this bit is
831edb9ca6SSiva Reddy  * set an interrupt happens as soon as the frame is transmitted
841edb9ca6SSiva Reddy  */
sxgbe_clear_tx_ic(struct sxgbe_tx_norm_desc * p)851edb9ca6SSiva Reddy static void sxgbe_clear_tx_ic(struct sxgbe_tx_norm_desc *p)
861edb9ca6SSiva Reddy {
871edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.int_on_com = 0;
881edb9ca6SSiva Reddy }
891edb9ca6SSiva Reddy 
901edb9ca6SSiva Reddy /* Last tx segment reports the transmit status */
sxgbe_get_tx_ls(struct sxgbe_tx_norm_desc * p)911edb9ca6SSiva Reddy static int sxgbe_get_tx_ls(struct sxgbe_tx_norm_desc *p)
921edb9ca6SSiva Reddy {
931edb9ca6SSiva Reddy 	return p->tdes23.tx_rd_des23.last_desc;
941edb9ca6SSiva Reddy }
951edb9ca6SSiva Reddy 
961edb9ca6SSiva Reddy /* Get the buffer size from the descriptor */
sxgbe_get_tx_len(struct sxgbe_tx_norm_desc * p)971edb9ca6SSiva Reddy static int sxgbe_get_tx_len(struct sxgbe_tx_norm_desc *p)
981edb9ca6SSiva Reddy {
991edb9ca6SSiva Reddy 	return p->tdes23.tx_rd_des23.buf1_size;
1001edb9ca6SSiva Reddy }
1011edb9ca6SSiva Reddy 
1021edb9ca6SSiva Reddy /* Set tx timestamp enable bit */
sxgbe_tx_enable_tstamp(struct sxgbe_tx_norm_desc * p)1031edb9ca6SSiva Reddy static void sxgbe_tx_enable_tstamp(struct sxgbe_tx_norm_desc *p)
1041edb9ca6SSiva Reddy {
1051edb9ca6SSiva Reddy 	p->tdes23.tx_rd_des23.timestmp_enable = 1;
1061edb9ca6SSiva Reddy }
1071edb9ca6SSiva Reddy 
1081edb9ca6SSiva Reddy /* get tx timestamp status */
sxgbe_get_tx_timestamp_status(struct sxgbe_tx_norm_desc * p)1091edb9ca6SSiva Reddy static int sxgbe_get_tx_timestamp_status(struct sxgbe_tx_norm_desc *p)
1101edb9ca6SSiva Reddy {
1111edb9ca6SSiva Reddy 	return p->tdes23.tx_rd_des23.timestmp_enable;
1121edb9ca6SSiva Reddy }
1131edb9ca6SSiva Reddy 
1141edb9ca6SSiva Reddy /* TX Context Descripto Specific */
sxgbe_tx_ctxt_desc_set_ctxt(struct sxgbe_tx_ctxt_desc * p)1151edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_set_ctxt(struct sxgbe_tx_ctxt_desc *p)
1161edb9ca6SSiva Reddy {
1171edb9ca6SSiva Reddy 	p->ctxt_bit = 1;
1181edb9ca6SSiva Reddy }
1191edb9ca6SSiva Reddy 
1201edb9ca6SSiva Reddy /* Set the owner of TX context descriptor */
sxgbe_tx_ctxt_desc_set_owner(struct sxgbe_tx_ctxt_desc * p)1211edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_set_owner(struct sxgbe_tx_ctxt_desc *p)
1221edb9ca6SSiva Reddy {
1231edb9ca6SSiva Reddy 	p->own_bit = 1;
1241edb9ca6SSiva Reddy }
1251edb9ca6SSiva Reddy 
1261edb9ca6SSiva Reddy /* Get the owner of TX context descriptor */
sxgbe_tx_ctxt_desc_get_owner(struct sxgbe_tx_ctxt_desc * p)1271edb9ca6SSiva Reddy static int sxgbe_tx_ctxt_desc_get_owner(struct sxgbe_tx_ctxt_desc *p)
1281edb9ca6SSiva Reddy {
1291edb9ca6SSiva Reddy 	return p->own_bit;
1301edb9ca6SSiva Reddy }
1311edb9ca6SSiva Reddy 
1321edb9ca6SSiva Reddy /* Set TX mss in TX context Descriptor */
sxgbe_tx_ctxt_desc_set_mss(struct sxgbe_tx_ctxt_desc * p,u16 mss)1331051125dSVipul Pandya static void sxgbe_tx_ctxt_desc_set_mss(struct sxgbe_tx_ctxt_desc *p, u16 mss)
1341edb9ca6SSiva Reddy {
1351edb9ca6SSiva Reddy 	p->maxseg_size = mss;
1361edb9ca6SSiva Reddy }
1371edb9ca6SSiva Reddy 
1381edb9ca6SSiva Reddy /* Get TX mss from TX context Descriptor */
sxgbe_tx_ctxt_desc_get_mss(struct sxgbe_tx_ctxt_desc * p)1391edb9ca6SSiva Reddy static int sxgbe_tx_ctxt_desc_get_mss(struct sxgbe_tx_ctxt_desc *p)
1401edb9ca6SSiva Reddy {
1411edb9ca6SSiva Reddy 	return p->maxseg_size;
1421edb9ca6SSiva Reddy }
1431edb9ca6SSiva Reddy 
1441edb9ca6SSiva Reddy /* Set TX tcmssv in TX context Descriptor */
sxgbe_tx_ctxt_desc_set_tcmssv(struct sxgbe_tx_ctxt_desc * p)1451edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_set_tcmssv(struct sxgbe_tx_ctxt_desc *p)
1461edb9ca6SSiva Reddy {
1471edb9ca6SSiva Reddy 	p->tcmssv = 1;
1481edb9ca6SSiva Reddy }
1491edb9ca6SSiva Reddy 
1501edb9ca6SSiva Reddy /* Reset TX ostc in TX context Descriptor */
sxgbe_tx_ctxt_desc_reset_ostc(struct sxgbe_tx_ctxt_desc * p)1511edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_reset_ostc(struct sxgbe_tx_ctxt_desc *p)
1521edb9ca6SSiva Reddy {
1531edb9ca6SSiva Reddy 	p->ostc = 0;
1541edb9ca6SSiva Reddy }
1551edb9ca6SSiva Reddy 
1561edb9ca6SSiva Reddy /* Set IVLAN information */
sxgbe_tx_ctxt_desc_set_ivlantag(struct sxgbe_tx_ctxt_desc * p,int is_ivlanvalid,int ivlan_tag,int ivlan_ctl)1571edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_set_ivlantag(struct sxgbe_tx_ctxt_desc *p,
1581edb9ca6SSiva Reddy 					    int is_ivlanvalid, int ivlan_tag,
1591edb9ca6SSiva Reddy 					    int ivlan_ctl)
1601edb9ca6SSiva Reddy {
1611edb9ca6SSiva Reddy 	if (is_ivlanvalid) {
1621edb9ca6SSiva Reddy 		p->ivlan_tag_valid = is_ivlanvalid;
1631edb9ca6SSiva Reddy 		p->ivlan_tag = ivlan_tag;
1641edb9ca6SSiva Reddy 		p->ivlan_tag_ctl = ivlan_ctl;
1651edb9ca6SSiva Reddy 	}
1661edb9ca6SSiva Reddy }
1671edb9ca6SSiva Reddy 
1681edb9ca6SSiva Reddy /* Return IVLAN Tag */
sxgbe_tx_ctxt_desc_get_ivlantag(struct sxgbe_tx_ctxt_desc * p)1691edb9ca6SSiva Reddy static int sxgbe_tx_ctxt_desc_get_ivlantag(struct sxgbe_tx_ctxt_desc *p)
1701edb9ca6SSiva Reddy {
1711edb9ca6SSiva Reddy 	return p->ivlan_tag;
1721edb9ca6SSiva Reddy }
1731edb9ca6SSiva Reddy 
1741edb9ca6SSiva Reddy /* Set VLAN Tag */
sxgbe_tx_ctxt_desc_set_vlantag(struct sxgbe_tx_ctxt_desc * p,int is_vlanvalid,int vlan_tag)1751edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_set_vlantag(struct sxgbe_tx_ctxt_desc *p,
1761edb9ca6SSiva Reddy 					   int is_vlanvalid, int vlan_tag)
1771edb9ca6SSiva Reddy {
1781edb9ca6SSiva Reddy 	if (is_vlanvalid) {
1791edb9ca6SSiva Reddy 		p->vltag_valid = is_vlanvalid;
1801edb9ca6SSiva Reddy 		p->vlan_tag = vlan_tag;
1811edb9ca6SSiva Reddy 	}
1821edb9ca6SSiva Reddy }
1831edb9ca6SSiva Reddy 
1841edb9ca6SSiva Reddy /* Return VLAN Tag */
sxgbe_tx_ctxt_desc_get_vlantag(struct sxgbe_tx_ctxt_desc * p)1851edb9ca6SSiva Reddy static int sxgbe_tx_ctxt_desc_get_vlantag(struct sxgbe_tx_ctxt_desc *p)
1861edb9ca6SSiva Reddy {
1871edb9ca6SSiva Reddy 	return p->vlan_tag;
1881edb9ca6SSiva Reddy }
1891edb9ca6SSiva Reddy 
1901edb9ca6SSiva Reddy /* Set Time stamp */
sxgbe_tx_ctxt_desc_set_tstamp(struct sxgbe_tx_ctxt_desc * p,u8 ostc_enable,u64 tstamp)1911edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_set_tstamp(struct sxgbe_tx_ctxt_desc *p,
1921edb9ca6SSiva Reddy 					  u8 ostc_enable, u64 tstamp)
1931edb9ca6SSiva Reddy {
1941edb9ca6SSiva Reddy 	if (ostc_enable) {
1951edb9ca6SSiva Reddy 		p->ostc = ostc_enable;
1961edb9ca6SSiva Reddy 		p->tstamp_lo = (u32) tstamp;
1971edb9ca6SSiva Reddy 		p->tstamp_hi = (u32) (tstamp>>32);
1981edb9ca6SSiva Reddy 	}
1991edb9ca6SSiva Reddy }
2001edb9ca6SSiva Reddy /* Close TX context descriptor */
sxgbe_tx_ctxt_desc_close(struct sxgbe_tx_ctxt_desc * p)2011edb9ca6SSiva Reddy static void sxgbe_tx_ctxt_desc_close(struct sxgbe_tx_ctxt_desc *p)
2021edb9ca6SSiva Reddy {
2031edb9ca6SSiva Reddy 	p->own_bit = 1;
2041edb9ca6SSiva Reddy }
2051edb9ca6SSiva Reddy 
2061edb9ca6SSiva Reddy /* WB status of context descriptor */
sxgbe_tx_ctxt_desc_get_cde(struct sxgbe_tx_ctxt_desc * p)2071edb9ca6SSiva Reddy static int sxgbe_tx_ctxt_desc_get_cde(struct sxgbe_tx_ctxt_desc *p)
2081edb9ca6SSiva Reddy {
2091edb9ca6SSiva Reddy 	return p->ctxt_desc_err;
2101edb9ca6SSiva Reddy }
2111edb9ca6SSiva Reddy 
2121edb9ca6SSiva Reddy /* DMA RX descriptor ring initialization */
sxgbe_init_rx_desc(struct sxgbe_rx_norm_desc * p,int disable_rx_ic,int mode,int end)2131edb9ca6SSiva Reddy static void sxgbe_init_rx_desc(struct sxgbe_rx_norm_desc *p, int disable_rx_ic,
2141edb9ca6SSiva Reddy 			       int mode, int end)
2151edb9ca6SSiva Reddy {
2161edb9ca6SSiva Reddy 	p->rdes23.rx_rd_des23.own_bit = 1;
2171edb9ca6SSiva Reddy 	if (disable_rx_ic)
2181edb9ca6SSiva Reddy 		p->rdes23.rx_rd_des23.int_on_com = disable_rx_ic;
2191edb9ca6SSiva Reddy }
2201edb9ca6SSiva Reddy 
2211edb9ca6SSiva Reddy /* Get RX own bit */
sxgbe_get_rx_owner(struct sxgbe_rx_norm_desc * p)2221edb9ca6SSiva Reddy static int sxgbe_get_rx_owner(struct sxgbe_rx_norm_desc *p)
2231edb9ca6SSiva Reddy {
2241edb9ca6SSiva Reddy 	return p->rdes23.rx_rd_des23.own_bit;
2251edb9ca6SSiva Reddy }
2261edb9ca6SSiva Reddy 
2271edb9ca6SSiva Reddy /* Set RX own bit */
sxgbe_set_rx_owner(struct sxgbe_rx_norm_desc * p)2281edb9ca6SSiva Reddy static void sxgbe_set_rx_owner(struct sxgbe_rx_norm_desc *p)
2291edb9ca6SSiva Reddy {
2301edb9ca6SSiva Reddy 	p->rdes23.rx_rd_des23.own_bit = 1;
2311edb9ca6SSiva Reddy }
2321edb9ca6SSiva Reddy 
2333dc638d1SByungho An /* Set Interrupt on completion bit */
sxgbe_set_rx_int_on_com(struct sxgbe_rx_norm_desc * p)2343dc638d1SByungho An static void sxgbe_set_rx_int_on_com(struct sxgbe_rx_norm_desc *p)
2353dc638d1SByungho An {
2363dc638d1SByungho An 	p->rdes23.rx_rd_des23.int_on_com = 1;
2373dc638d1SByungho An }
2383dc638d1SByungho An 
2391edb9ca6SSiva Reddy /* Get the receive frame size */
sxgbe_get_rx_frame_len(struct sxgbe_rx_norm_desc * p)2401edb9ca6SSiva Reddy static int sxgbe_get_rx_frame_len(struct sxgbe_rx_norm_desc *p)
2411edb9ca6SSiva Reddy {
2421edb9ca6SSiva Reddy 	return p->rdes23.rx_wb_des23.pkt_len;
2431edb9ca6SSiva Reddy }
2441edb9ca6SSiva Reddy 
2451edb9ca6SSiva Reddy /* Return first Descriptor status */
sxgbe_get_rx_fd_status(struct sxgbe_rx_norm_desc * p)2461edb9ca6SSiva Reddy static int sxgbe_get_rx_fd_status(struct sxgbe_rx_norm_desc *p)
2471edb9ca6SSiva Reddy {
2481edb9ca6SSiva Reddy 	return p->rdes23.rx_wb_des23.first_desc;
2491edb9ca6SSiva Reddy }
2501edb9ca6SSiva Reddy 
2511edb9ca6SSiva Reddy /* Return Last Descriptor status */
sxgbe_get_rx_ld_status(struct sxgbe_rx_norm_desc * p)2521edb9ca6SSiva Reddy static int sxgbe_get_rx_ld_status(struct sxgbe_rx_norm_desc *p)
2531edb9ca6SSiva Reddy {
2541edb9ca6SSiva Reddy 	return p->rdes23.rx_wb_des23.last_desc;
2551edb9ca6SSiva Reddy }
2561edb9ca6SSiva Reddy 
2571edb9ca6SSiva Reddy 
2581edb9ca6SSiva Reddy /* Return the RX status looking at the WB fields */
sxgbe_rx_wbstatus(struct sxgbe_rx_norm_desc * p,struct sxgbe_extra_stats * x,int * checksum)2591edb9ca6SSiva Reddy static int sxgbe_rx_wbstatus(struct sxgbe_rx_norm_desc *p,
2601edb9ca6SSiva Reddy 			     struct sxgbe_extra_stats *x, int *checksum)
2611edb9ca6SSiva Reddy {
2621edb9ca6SSiva Reddy 	int status = 0;
2631edb9ca6SSiva Reddy 
2641edb9ca6SSiva Reddy 	*checksum = CHECKSUM_UNNECESSARY;
2651edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.err_summary) {
2661edb9ca6SSiva Reddy 		switch (p->rdes23.rx_wb_des23.err_l2_type) {
2671edb9ca6SSiva Reddy 		case RX_GMII_ERR:
2681edb9ca6SSiva Reddy 			status = -EINVAL;
2691edb9ca6SSiva Reddy 			x->rx_code_gmii_err++;
2701edb9ca6SSiva Reddy 			break;
2711edb9ca6SSiva Reddy 		case RX_WATCHDOG_ERR:
2721edb9ca6SSiva Reddy 			status = -EINVAL;
2731edb9ca6SSiva Reddy 			x->rx_watchdog_err++;
2741edb9ca6SSiva Reddy 			break;
2751edb9ca6SSiva Reddy 		case RX_CRC_ERR:
2761edb9ca6SSiva Reddy 			status = -EINVAL;
2771edb9ca6SSiva Reddy 			x->rx_crc_err++;
2781edb9ca6SSiva Reddy 			break;
2791edb9ca6SSiva Reddy 		case RX_GAINT_ERR:
2801edb9ca6SSiva Reddy 			status = -EINVAL;
2811edb9ca6SSiva Reddy 			x->rx_gaint_pkt_err++;
2821edb9ca6SSiva Reddy 			break;
2831edb9ca6SSiva Reddy 		case RX_IP_HDR_ERR:
2841edb9ca6SSiva Reddy 			*checksum = CHECKSUM_NONE;
2851edb9ca6SSiva Reddy 			x->ip_hdr_err++;
2861edb9ca6SSiva Reddy 			break;
2871edb9ca6SSiva Reddy 		case RX_PAYLOAD_ERR:
2881edb9ca6SSiva Reddy 			*checksum = CHECKSUM_NONE;
2891edb9ca6SSiva Reddy 			x->ip_payload_err++;
2901edb9ca6SSiva Reddy 			break;
2911edb9ca6SSiva Reddy 		case RX_OVERFLOW_ERR:
2921edb9ca6SSiva Reddy 			status = -EINVAL;
2931edb9ca6SSiva Reddy 			x->overflow_error++;
2941edb9ca6SSiva Reddy 			break;
2951edb9ca6SSiva Reddy 		default:
2961edb9ca6SSiva Reddy 			pr_err("Invalid Error type\n");
2971edb9ca6SSiva Reddy 			break;
2981edb9ca6SSiva Reddy 		}
2991edb9ca6SSiva Reddy 	} else {
3001edb9ca6SSiva Reddy 		switch (p->rdes23.rx_wb_des23.err_l2_type) {
3011edb9ca6SSiva Reddy 		case RX_LEN_PKT:
3021edb9ca6SSiva Reddy 			x->len_pkt++;
3031edb9ca6SSiva Reddy 			break;
3041edb9ca6SSiva Reddy 		case RX_MACCTL_PKT:
3051edb9ca6SSiva Reddy 			x->mac_ctl_pkt++;
3061edb9ca6SSiva Reddy 			break;
3071edb9ca6SSiva Reddy 		case RX_DCBCTL_PKT:
3081edb9ca6SSiva Reddy 			x->dcb_ctl_pkt++;
3091edb9ca6SSiva Reddy 			break;
3101edb9ca6SSiva Reddy 		case RX_ARP_PKT:
3111edb9ca6SSiva Reddy 			x->arp_pkt++;
3121edb9ca6SSiva Reddy 			break;
3131edb9ca6SSiva Reddy 		case RX_OAM_PKT:
3141edb9ca6SSiva Reddy 			x->oam_pkt++;
3151edb9ca6SSiva Reddy 			break;
3161edb9ca6SSiva Reddy 		case RX_UNTAG_PKT:
3171edb9ca6SSiva Reddy 			x->untag_okt++;
3181edb9ca6SSiva Reddy 			break;
3191edb9ca6SSiva Reddy 		case RX_OTHER_PKT:
3201edb9ca6SSiva Reddy 			x->other_pkt++;
3211edb9ca6SSiva Reddy 			break;
3221edb9ca6SSiva Reddy 		case RX_SVLAN_PKT:
3231edb9ca6SSiva Reddy 			x->svlan_tag_pkt++;
3241edb9ca6SSiva Reddy 			break;
3251edb9ca6SSiva Reddy 		case RX_CVLAN_PKT:
3261edb9ca6SSiva Reddy 			x->cvlan_tag_pkt++;
3271edb9ca6SSiva Reddy 			break;
3281edb9ca6SSiva Reddy 		case RX_DVLAN_OCVLAN_ICVLAN_PKT:
3291edb9ca6SSiva Reddy 			x->dvlan_ocvlan_icvlan_pkt++;
3301edb9ca6SSiva Reddy 			break;
3311edb9ca6SSiva Reddy 		case RX_DVLAN_OSVLAN_ISVLAN_PKT:
3321edb9ca6SSiva Reddy 			x->dvlan_osvlan_isvlan_pkt++;
3331edb9ca6SSiva Reddy 			break;
3341edb9ca6SSiva Reddy 		case RX_DVLAN_OSVLAN_ICVLAN_PKT:
3351edb9ca6SSiva Reddy 			x->dvlan_osvlan_icvlan_pkt++;
3361edb9ca6SSiva Reddy 			break;
3371edb9ca6SSiva Reddy 		case RX_DVLAN_OCVLAN_ISVLAN_PKT:
3381edb9ca6SSiva Reddy 			x->dvlan_ocvlan_icvlan_pkt++;
3391edb9ca6SSiva Reddy 			break;
3401edb9ca6SSiva Reddy 		default:
3411edb9ca6SSiva Reddy 			pr_err("Invalid L2 Packet type\n");
3421edb9ca6SSiva Reddy 			break;
3431edb9ca6SSiva Reddy 		}
3441edb9ca6SSiva Reddy 	}
3451edb9ca6SSiva Reddy 
3461edb9ca6SSiva Reddy 	/* L3/L4 Pkt type */
3471edb9ca6SSiva Reddy 	switch (p->rdes23.rx_wb_des23.layer34_pkt_type) {
3481edb9ca6SSiva Reddy 	case RX_NOT_IP_PKT:
3491edb9ca6SSiva Reddy 		x->not_ip_pkt++;
3501edb9ca6SSiva Reddy 		break;
3511edb9ca6SSiva Reddy 	case RX_IPV4_TCP_PKT:
3521edb9ca6SSiva Reddy 		x->ip4_tcp_pkt++;
3531edb9ca6SSiva Reddy 		break;
3541edb9ca6SSiva Reddy 	case RX_IPV4_UDP_PKT:
3551edb9ca6SSiva Reddy 		x->ip4_udp_pkt++;
3561edb9ca6SSiva Reddy 		break;
3571edb9ca6SSiva Reddy 	case RX_IPV4_ICMP_PKT:
3581edb9ca6SSiva Reddy 		x->ip4_icmp_pkt++;
3591edb9ca6SSiva Reddy 		break;
3601edb9ca6SSiva Reddy 	case RX_IPV4_UNKNOWN_PKT:
3611edb9ca6SSiva Reddy 		x->ip4_unknown_pkt++;
3621edb9ca6SSiva Reddy 		break;
3631edb9ca6SSiva Reddy 	case RX_IPV6_TCP_PKT:
3641edb9ca6SSiva Reddy 		x->ip6_tcp_pkt++;
3651edb9ca6SSiva Reddy 		break;
3661edb9ca6SSiva Reddy 	case RX_IPV6_UDP_PKT:
3671edb9ca6SSiva Reddy 		x->ip6_udp_pkt++;
3681edb9ca6SSiva Reddy 		break;
3691edb9ca6SSiva Reddy 	case RX_IPV6_ICMP_PKT:
3701edb9ca6SSiva Reddy 		x->ip6_icmp_pkt++;
3711edb9ca6SSiva Reddy 		break;
3721edb9ca6SSiva Reddy 	case RX_IPV6_UNKNOWN_PKT:
3731edb9ca6SSiva Reddy 		x->ip6_unknown_pkt++;
3741edb9ca6SSiva Reddy 		break;
3751edb9ca6SSiva Reddy 	default:
3761edb9ca6SSiva Reddy 		pr_err("Invalid L3/L4 Packet type\n");
3771edb9ca6SSiva Reddy 		break;
3781edb9ca6SSiva Reddy 	}
3791edb9ca6SSiva Reddy 
3801edb9ca6SSiva Reddy 	/* Filter */
3811edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.vlan_filter_match)
3821edb9ca6SSiva Reddy 		x->vlan_filter_match++;
3831edb9ca6SSiva Reddy 
3841edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.sa_filter_fail) {
3851edb9ca6SSiva Reddy 		status = -EINVAL;
3861edb9ca6SSiva Reddy 		x->sa_filter_fail++;
3871edb9ca6SSiva Reddy 	}
3881edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.da_filter_fail) {
3891edb9ca6SSiva Reddy 		status = -EINVAL;
3901edb9ca6SSiva Reddy 		x->da_filter_fail++;
3911edb9ca6SSiva Reddy 	}
3921edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.hash_filter_pass)
3931edb9ca6SSiva Reddy 		x->hash_filter_pass++;
3941edb9ca6SSiva Reddy 
3951edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.l3_filter_match)
3961edb9ca6SSiva Reddy 		x->l3_filter_match++;
3971edb9ca6SSiva Reddy 
3981edb9ca6SSiva Reddy 	if (p->rdes23.rx_wb_des23.l4_filter_match)
3991edb9ca6SSiva Reddy 		x->l4_filter_match++;
4001edb9ca6SSiva Reddy 
4011edb9ca6SSiva Reddy 	return status;
4021edb9ca6SSiva Reddy }
4031edb9ca6SSiva Reddy 
4041edb9ca6SSiva Reddy /* Get own bit of context descriptor */
sxgbe_get_rx_ctxt_owner(struct sxgbe_rx_ctxt_desc * p)4051edb9ca6SSiva Reddy static int sxgbe_get_rx_ctxt_owner(struct sxgbe_rx_ctxt_desc *p)
4061edb9ca6SSiva Reddy {
4071edb9ca6SSiva Reddy 	return p->own_bit;
4081edb9ca6SSiva Reddy }
4091edb9ca6SSiva Reddy 
4101edb9ca6SSiva Reddy /* Set own bit for context descriptor */
sxgbe_set_ctxt_rx_owner(struct sxgbe_rx_ctxt_desc * p)4111edb9ca6SSiva Reddy static void sxgbe_set_ctxt_rx_owner(struct sxgbe_rx_ctxt_desc *p)
4121edb9ca6SSiva Reddy {
4131edb9ca6SSiva Reddy 	p->own_bit = 1;
4141edb9ca6SSiva Reddy }
4151edb9ca6SSiva Reddy 
4161edb9ca6SSiva Reddy 
4171edb9ca6SSiva Reddy /* Return the reception status looking at Context control information */
sxgbe_rx_ctxt_wbstatus(struct sxgbe_rx_ctxt_desc * p,struct sxgbe_extra_stats * x)4181edb9ca6SSiva Reddy static void sxgbe_rx_ctxt_wbstatus(struct sxgbe_rx_ctxt_desc *p,
4191edb9ca6SSiva Reddy 				   struct sxgbe_extra_stats *x)
4201edb9ca6SSiva Reddy {
4211edb9ca6SSiva Reddy 	if (p->tstamp_dropped)
4221edb9ca6SSiva Reddy 		x->timestamp_dropped++;
4231edb9ca6SSiva Reddy 
4241edb9ca6SSiva Reddy 	/* ptp */
4251edb9ca6SSiva Reddy 	if (p->ptp_msgtype == RX_NO_PTP)
4261edb9ca6SSiva Reddy 		x->rx_msg_type_no_ptp++;
4271edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_SYNC)
4281edb9ca6SSiva Reddy 		x->rx_ptp_type_sync++;
4291edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_FOLLOW_UP)
4301edb9ca6SSiva Reddy 		x->rx_ptp_type_follow_up++;
4311edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_DELAY_REQ)
4321edb9ca6SSiva Reddy 		x->rx_ptp_type_delay_req++;
4331edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_DELAY_RESP)
4341edb9ca6SSiva Reddy 		x->rx_ptp_type_delay_resp++;
4351edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_PDELAY_REQ)
4361edb9ca6SSiva Reddy 		x->rx_ptp_type_pdelay_req++;
4371edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_PDELAY_RESP)
4381edb9ca6SSiva Reddy 		x->rx_ptp_type_pdelay_resp++;
4391edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_PDELAY_FOLLOW_UP)
4401edb9ca6SSiva Reddy 		x->rx_ptp_type_pdelay_follow_up++;
4411edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_ANNOUNCE)
4421edb9ca6SSiva Reddy 		x->rx_ptp_announce++;
4431edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_MGMT)
4441edb9ca6SSiva Reddy 		x->rx_ptp_mgmt++;
4451edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_SIGNAL)
4461edb9ca6SSiva Reddy 		x->rx_ptp_signal++;
4471edb9ca6SSiva Reddy 	else if (p->ptp_msgtype == RX_PTP_RESV_MSG)
4481edb9ca6SSiva Reddy 		x->rx_ptp_resv_msg_type++;
4491edb9ca6SSiva Reddy }
4501edb9ca6SSiva Reddy 
4511edb9ca6SSiva Reddy /* Get rx timestamp status */
sxgbe_get_rx_ctxt_tstamp_status(struct sxgbe_rx_ctxt_desc * p)4521edb9ca6SSiva Reddy static int sxgbe_get_rx_ctxt_tstamp_status(struct sxgbe_rx_ctxt_desc *p)
4531edb9ca6SSiva Reddy {
4541edb9ca6SSiva Reddy 	if ((p->tstamp_hi == 0xffffffff) && (p->tstamp_lo == 0xffffffff)) {
4551edb9ca6SSiva Reddy 		pr_err("Time stamp corrupted\n");
4561edb9ca6SSiva Reddy 		return 0;
4571edb9ca6SSiva Reddy 	}
4581edb9ca6SSiva Reddy 
4591edb9ca6SSiva Reddy 	return p->tstamp_available;
4601edb9ca6SSiva Reddy }
4611edb9ca6SSiva Reddy 
4621edb9ca6SSiva Reddy 
sxgbe_get_rx_timestamp(struct sxgbe_rx_ctxt_desc * p)4631edb9ca6SSiva Reddy static u64 sxgbe_get_rx_timestamp(struct sxgbe_rx_ctxt_desc *p)
4641edb9ca6SSiva Reddy {
4651edb9ca6SSiva Reddy 	u64 ns;
4661edb9ca6SSiva Reddy 
4671edb9ca6SSiva Reddy 	ns = p->tstamp_lo;
4681edb9ca6SSiva Reddy 	ns |= ((u64)p->tstamp_hi) << 32;
4691edb9ca6SSiva Reddy 
4701edb9ca6SSiva Reddy 	return ns;
4711edb9ca6SSiva Reddy }
4721edb9ca6SSiva Reddy 
4731edb9ca6SSiva Reddy static const struct sxgbe_desc_ops desc_ops = {
4741edb9ca6SSiva Reddy 	.init_tx_desc			= sxgbe_init_tx_desc,
4751edb9ca6SSiva Reddy 	.tx_desc_enable_tse		= sxgbe_tx_desc_enable_tse,
4761edb9ca6SSiva Reddy 	.prepare_tx_desc		= sxgbe_prepare_tx_desc,
4771edb9ca6SSiva Reddy 	.tx_vlanctl_desc		= sxgbe_tx_vlanctl_desc,
4781edb9ca6SSiva Reddy 	.set_tx_owner			= sxgbe_set_tx_owner,
4791edb9ca6SSiva Reddy 	.get_tx_owner			= sxgbe_get_tx_owner,
4801edb9ca6SSiva Reddy 	.close_tx_desc			= sxgbe_close_tx_desc,
4811edb9ca6SSiva Reddy 	.release_tx_desc		= sxgbe_release_tx_desc,
4821edb9ca6SSiva Reddy 	.clear_tx_ic			= sxgbe_clear_tx_ic,
4831edb9ca6SSiva Reddy 	.get_tx_ls			= sxgbe_get_tx_ls,
4841edb9ca6SSiva Reddy 	.get_tx_len			= sxgbe_get_tx_len,
4851edb9ca6SSiva Reddy 	.tx_enable_tstamp		= sxgbe_tx_enable_tstamp,
4861edb9ca6SSiva Reddy 	.get_tx_timestamp_status	= sxgbe_get_tx_timestamp_status,
4871edb9ca6SSiva Reddy 	.tx_ctxt_desc_set_ctxt		= sxgbe_tx_ctxt_desc_set_ctxt,
4881edb9ca6SSiva Reddy 	.tx_ctxt_desc_set_owner		= sxgbe_tx_ctxt_desc_set_owner,
4891edb9ca6SSiva Reddy 	.get_tx_ctxt_owner		= sxgbe_tx_ctxt_desc_get_owner,
4901edb9ca6SSiva Reddy 	.tx_ctxt_desc_set_mss		= sxgbe_tx_ctxt_desc_set_mss,
4911edb9ca6SSiva Reddy 	.tx_ctxt_desc_get_mss		= sxgbe_tx_ctxt_desc_get_mss,
4921edb9ca6SSiva Reddy 	.tx_ctxt_desc_set_tcmssv	= sxgbe_tx_ctxt_desc_set_tcmssv,
4931edb9ca6SSiva Reddy 	.tx_ctxt_desc_reset_ostc	= sxgbe_tx_ctxt_desc_reset_ostc,
4941edb9ca6SSiva Reddy 	.tx_ctxt_desc_set_ivlantag	= sxgbe_tx_ctxt_desc_set_ivlantag,
4951edb9ca6SSiva Reddy 	.tx_ctxt_desc_get_ivlantag	= sxgbe_tx_ctxt_desc_get_ivlantag,
4961edb9ca6SSiva Reddy 	.tx_ctxt_desc_set_vlantag	= sxgbe_tx_ctxt_desc_set_vlantag,
4971edb9ca6SSiva Reddy 	.tx_ctxt_desc_get_vlantag	= sxgbe_tx_ctxt_desc_get_vlantag,
4981edb9ca6SSiva Reddy 	.tx_ctxt_set_tstamp		= sxgbe_tx_ctxt_desc_set_tstamp,
4991edb9ca6SSiva Reddy 	.close_tx_ctxt_desc		= sxgbe_tx_ctxt_desc_close,
5001edb9ca6SSiva Reddy 	.get_tx_ctxt_cde		= sxgbe_tx_ctxt_desc_get_cde,
5011edb9ca6SSiva Reddy 	.init_rx_desc			= sxgbe_init_rx_desc,
5021edb9ca6SSiva Reddy 	.get_rx_owner			= sxgbe_get_rx_owner,
5031edb9ca6SSiva Reddy 	.set_rx_owner			= sxgbe_set_rx_owner,
5043dc638d1SByungho An 	.set_rx_int_on_com		= sxgbe_set_rx_int_on_com,
5051edb9ca6SSiva Reddy 	.get_rx_frame_len		= sxgbe_get_rx_frame_len,
5061edb9ca6SSiva Reddy 	.get_rx_fd_status		= sxgbe_get_rx_fd_status,
5071edb9ca6SSiva Reddy 	.get_rx_ld_status		= sxgbe_get_rx_ld_status,
5081edb9ca6SSiva Reddy 	.rx_wbstatus			= sxgbe_rx_wbstatus,
5091edb9ca6SSiva Reddy 	.get_rx_ctxt_owner		= sxgbe_get_rx_ctxt_owner,
5101edb9ca6SSiva Reddy 	.set_rx_ctxt_owner		= sxgbe_set_ctxt_rx_owner,
5111edb9ca6SSiva Reddy 	.rx_ctxt_wbstatus		= sxgbe_rx_ctxt_wbstatus,
5121edb9ca6SSiva Reddy 	.get_rx_ctxt_tstamp_status	= sxgbe_get_rx_ctxt_tstamp_status,
5131edb9ca6SSiva Reddy 	.get_timestamp			= sxgbe_get_rx_timestamp,
5141edb9ca6SSiva Reddy };
5151edb9ca6SSiva Reddy 
sxgbe_get_desc_ops(void)5161edb9ca6SSiva Reddy const struct sxgbe_desc_ops *sxgbe_get_desc_ops(void)
5171edb9ca6SSiva Reddy {
5181edb9ca6SSiva Reddy 	return &desc_ops;
5191edb9ca6SSiva Reddy }
520