18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2018, Intel Corporation. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _ICE_TXRX_H_
58c2ecf20Sopenharmony_ci#define _ICE_TXRX_H_
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "ice_type.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define ICE_DFLT_IRQ_WORK	256
108c2ecf20Sopenharmony_ci#define ICE_RXBUF_3072		3072
118c2ecf20Sopenharmony_ci#define ICE_RXBUF_2048		2048
128c2ecf20Sopenharmony_ci#define ICE_RXBUF_1536		1536
138c2ecf20Sopenharmony_ci#define ICE_MAX_CHAINED_RX_BUFS	5
148c2ecf20Sopenharmony_ci#define ICE_MAX_BUF_TXD		8
158c2ecf20Sopenharmony_ci#define ICE_MIN_TX_LEN		17
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* The size limit for a transmit buffer in a descriptor is (16K - 1).
188c2ecf20Sopenharmony_ci * In order to align with the read requests we will align the value to
198c2ecf20Sopenharmony_ci * the nearest 4K which represents our maximum read request size.
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci#define ICE_MAX_READ_REQ_SIZE	4096
228c2ecf20Sopenharmony_ci#define ICE_MAX_DATA_PER_TXD	(16 * 1024 - 1)
238c2ecf20Sopenharmony_ci#define ICE_MAX_DATA_PER_TXD_ALIGNED \
248c2ecf20Sopenharmony_ci	(~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define ICE_RX_BUF_WRITE	16	/* Must be power of 2 */
278c2ecf20Sopenharmony_ci#define ICE_MAX_TXQ_PER_TXQG	128
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* Attempt to maximize the headroom available for incoming frames. We use a 2K
308c2ecf20Sopenharmony_ci * buffer for MTUs <= 1500 and need 1536/1534 to store the data for the frame.
318c2ecf20Sopenharmony_ci * This leaves us with 512 bytes of room.  From that we need to deduct the
328c2ecf20Sopenharmony_ci * space needed for the shared info and the padding needed to IP align the
338c2ecf20Sopenharmony_ci * frame.
348c2ecf20Sopenharmony_ci *
358c2ecf20Sopenharmony_ci * Note: For cache line sizes 256 or larger this value is going to end
368c2ecf20Sopenharmony_ci *	 up negative.  In these cases we should fall back to the legacy
378c2ecf20Sopenharmony_ci *	 receive path.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_ci#if (PAGE_SIZE < 8192)
408c2ecf20Sopenharmony_ci#define ICE_2K_TOO_SMALL_WITH_PADDING \
418c2ecf20Sopenharmony_ci	((unsigned int)(NET_SKB_PAD + ICE_RXBUF_1536) > \
428c2ecf20Sopenharmony_ci			SKB_WITH_OVERHEAD(ICE_RXBUF_2048))
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/**
458c2ecf20Sopenharmony_ci * ice_compute_pad - compute the padding
468c2ecf20Sopenharmony_ci * @rx_buf_len: buffer length
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci * Figure out the size of half page based on given buffer length and
498c2ecf20Sopenharmony_ci * then subtract the skb_shared_info followed by subtraction of the
508c2ecf20Sopenharmony_ci * actual buffer length; this in turn results in the actual space that
518c2ecf20Sopenharmony_ci * is left for padding usage
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_cistatic inline int ice_compute_pad(int rx_buf_len)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	int half_page_size;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	half_page_size = ALIGN(rx_buf_len, PAGE_SIZE / 2);
588c2ecf20Sopenharmony_ci	return SKB_WITH_OVERHEAD(half_page_size) - rx_buf_len;
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/**
628c2ecf20Sopenharmony_ci * ice_skb_pad - determine the padding that we can supply
638c2ecf20Sopenharmony_ci *
648c2ecf20Sopenharmony_ci * Figure out the right Rx buffer size and based on that calculate the
658c2ecf20Sopenharmony_ci * padding
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_cistatic inline int ice_skb_pad(void)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	int rx_buf_len;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	/* If a 2K buffer cannot handle a standard Ethernet frame then
728c2ecf20Sopenharmony_ci	 * optimize padding for a 3K buffer instead of a 1.5K buffer.
738c2ecf20Sopenharmony_ci	 *
748c2ecf20Sopenharmony_ci	 * For a 3K buffer we need to add enough padding to allow for
758c2ecf20Sopenharmony_ci	 * tailroom due to NET_IP_ALIGN possibly shifting us out of
768c2ecf20Sopenharmony_ci	 * cache-line alignment.
778c2ecf20Sopenharmony_ci	 */
788c2ecf20Sopenharmony_ci	if (ICE_2K_TOO_SMALL_WITH_PADDING)
798c2ecf20Sopenharmony_ci		rx_buf_len = ICE_RXBUF_3072 + SKB_DATA_ALIGN(NET_IP_ALIGN);
808c2ecf20Sopenharmony_ci	else
818c2ecf20Sopenharmony_ci		rx_buf_len = ICE_RXBUF_1536;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	/* if needed make room for NET_IP_ALIGN */
848c2ecf20Sopenharmony_ci	rx_buf_len -= NET_IP_ALIGN;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	return ice_compute_pad(rx_buf_len);
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define ICE_SKB_PAD ice_skb_pad()
908c2ecf20Sopenharmony_ci#else
918c2ecf20Sopenharmony_ci#define ICE_2K_TOO_SMALL_WITH_PADDING false
928c2ecf20Sopenharmony_ci#define ICE_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
938c2ecf20Sopenharmony_ci#endif
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* We are assuming that the cache line is always 64 Bytes here for ice.
968c2ecf20Sopenharmony_ci * In order to make sure that is a correct assumption there is a check in probe
978c2ecf20Sopenharmony_ci * to print a warning if the read from GLPCI_CNF2 tells us that the cache line
988c2ecf20Sopenharmony_ci * size is 128 bytes. We do it this way because we do not want to read the
998c2ecf20Sopenharmony_ci * GLPCI_CNF2 register or a variable containing the value on every pass through
1008c2ecf20Sopenharmony_ci * the Tx path.
1018c2ecf20Sopenharmony_ci */
1028c2ecf20Sopenharmony_ci#define ICE_CACHE_LINE_BYTES		64
1038c2ecf20Sopenharmony_ci#define ICE_DESCS_PER_CACHE_LINE	(ICE_CACHE_LINE_BYTES / \
1048c2ecf20Sopenharmony_ci					 sizeof(struct ice_tx_desc))
1058c2ecf20Sopenharmony_ci#define ICE_DESCS_FOR_CTX_DESC		1
1068c2ecf20Sopenharmony_ci#define ICE_DESCS_FOR_SKB_DATA_PTR	1
1078c2ecf20Sopenharmony_ci/* Tx descriptors needed, worst case */
1088c2ecf20Sopenharmony_ci#define DESC_NEEDED (MAX_SKB_FRAGS + ICE_DESCS_FOR_CTX_DESC + \
1098c2ecf20Sopenharmony_ci		     ICE_DESCS_PER_CACHE_LINE + ICE_DESCS_FOR_SKB_DATA_PTR)
1108c2ecf20Sopenharmony_ci#define ICE_DESC_UNUSED(R)	\
1118c2ecf20Sopenharmony_ci	(u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
1128c2ecf20Sopenharmony_ci	      (R)->next_to_clean - (R)->next_to_use - 1)
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_TSO	BIT(0)
1158c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_HW_VLAN	BIT(1)
1168c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_SW_VLAN	BIT(2)
1178c2ecf20Sopenharmony_ci/* ICE_TX_FLAGS_DUMMY_PKT is used to mark dummy packets that should be
1188c2ecf20Sopenharmony_ci * freed instead of returned like skb packets.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_DUMMY_PKT	BIT(3)
1218c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_IPV4	BIT(5)
1228c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_IPV6	BIT(6)
1238c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_TUNNEL	BIT(7)
1248c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_VLAN_M	0xffff0000
1258c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_VLAN_PR_M	0xe0000000
1268c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_VLAN_PR_S	29
1278c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_VLAN_S	16
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define ICE_XDP_PASS		0
1308c2ecf20Sopenharmony_ci#define ICE_XDP_CONSUMED	BIT(0)
1318c2ecf20Sopenharmony_ci#define ICE_XDP_TX		BIT(1)
1328c2ecf20Sopenharmony_ci#define ICE_XDP_REDIR		BIT(2)
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define ICE_RX_DMA_ATTR \
1358c2ecf20Sopenharmony_ci	(DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define ICE_ETH_PKT_HDR_PAD	(ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define ICE_TXD_LAST_DESC_CMD (ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistruct ice_tx_buf {
1428c2ecf20Sopenharmony_ci	struct ice_tx_desc *next_to_watch;
1438c2ecf20Sopenharmony_ci	union {
1448c2ecf20Sopenharmony_ci		struct sk_buff *skb;
1458c2ecf20Sopenharmony_ci		void *raw_buf; /* used for XDP */
1468c2ecf20Sopenharmony_ci	};
1478c2ecf20Sopenharmony_ci	unsigned int bytecount;
1488c2ecf20Sopenharmony_ci	unsigned short gso_segs;
1498c2ecf20Sopenharmony_ci	u32 tx_flags;
1508c2ecf20Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(len);
1518c2ecf20Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(dma);
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistruct ice_tx_offload_params {
1558c2ecf20Sopenharmony_ci	u64 cd_qw1;
1568c2ecf20Sopenharmony_ci	struct ice_ring *tx_ring;
1578c2ecf20Sopenharmony_ci	u32 td_cmd;
1588c2ecf20Sopenharmony_ci	u32 td_offset;
1598c2ecf20Sopenharmony_ci	u32 td_l2tag1;
1608c2ecf20Sopenharmony_ci	u32 cd_tunnel_params;
1618c2ecf20Sopenharmony_ci	u16 cd_l2tag2;
1628c2ecf20Sopenharmony_ci	u8 header_len;
1638c2ecf20Sopenharmony_ci};
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistruct ice_rx_buf {
1668c2ecf20Sopenharmony_ci	union {
1678c2ecf20Sopenharmony_ci		struct {
1688c2ecf20Sopenharmony_ci			struct sk_buff *skb;
1698c2ecf20Sopenharmony_ci			dma_addr_t dma;
1708c2ecf20Sopenharmony_ci			struct page *page;
1718c2ecf20Sopenharmony_ci			unsigned int page_offset;
1728c2ecf20Sopenharmony_ci			u16 pagecnt_bias;
1738c2ecf20Sopenharmony_ci		};
1748c2ecf20Sopenharmony_ci		struct {
1758c2ecf20Sopenharmony_ci			struct xdp_buff *xdp;
1768c2ecf20Sopenharmony_ci		};
1778c2ecf20Sopenharmony_ci	};
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistruct ice_q_stats {
1818c2ecf20Sopenharmony_ci	u64 pkts;
1828c2ecf20Sopenharmony_ci	u64 bytes;
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistruct ice_txq_stats {
1868c2ecf20Sopenharmony_ci	u64 restart_q;
1878c2ecf20Sopenharmony_ci	u64 tx_busy;
1888c2ecf20Sopenharmony_ci	u64 tx_linearize;
1898c2ecf20Sopenharmony_ci	int prev_pkt; /* negative if no pending Tx descriptors */
1908c2ecf20Sopenharmony_ci};
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistruct ice_rxq_stats {
1938c2ecf20Sopenharmony_ci	u64 non_eop_descs;
1948c2ecf20Sopenharmony_ci	u64 alloc_page_failed;
1958c2ecf20Sopenharmony_ci	u64 alloc_buf_failed;
1968c2ecf20Sopenharmony_ci	u64 gro_dropped; /* GRO returned dropped */
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* this enum matches hardware bits and is meant to be used by DYN_CTLN
2008c2ecf20Sopenharmony_ci * registers and QINT registers or more generally anywhere in the manual
2018c2ecf20Sopenharmony_ci * mentioning ITR_INDX, ITR_NONE cannot be used as an index 'n' into any
2028c2ecf20Sopenharmony_ci * register but instead is a special value meaning "don't update" ITR0/1/2.
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_cienum ice_dyn_idx_t {
2058c2ecf20Sopenharmony_ci	ICE_IDX_ITR0 = 0,
2068c2ecf20Sopenharmony_ci	ICE_IDX_ITR1 = 1,
2078c2ecf20Sopenharmony_ci	ICE_IDX_ITR2 = 2,
2088c2ecf20Sopenharmony_ci	ICE_ITR_NONE = 3	/* ITR_NONE must not be used as an index */
2098c2ecf20Sopenharmony_ci};
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* Header split modes defined by DTYPE field of Rx RLAN context */
2128c2ecf20Sopenharmony_cienum ice_rx_dtype {
2138c2ecf20Sopenharmony_ci	ICE_RX_DTYPE_NO_SPLIT		= 0,
2148c2ecf20Sopenharmony_ci	ICE_RX_DTYPE_HEADER_SPLIT	= 1,
2158c2ecf20Sopenharmony_ci	ICE_RX_DTYPE_SPLIT_ALWAYS	= 2,
2168c2ecf20Sopenharmony_ci};
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/* indices into GLINT_ITR registers */
2198c2ecf20Sopenharmony_ci#define ICE_RX_ITR	ICE_IDX_ITR0
2208c2ecf20Sopenharmony_ci#define ICE_TX_ITR	ICE_IDX_ITR1
2218c2ecf20Sopenharmony_ci#define ICE_ITR_8K	124
2228c2ecf20Sopenharmony_ci#define ICE_ITR_20K	50
2238c2ecf20Sopenharmony_ci#define ICE_ITR_MAX	8160
2248c2ecf20Sopenharmony_ci#define ICE_DFLT_TX_ITR	(ICE_ITR_20K | ICE_ITR_DYNAMIC)
2258c2ecf20Sopenharmony_ci#define ICE_DFLT_RX_ITR	(ICE_ITR_20K | ICE_ITR_DYNAMIC)
2268c2ecf20Sopenharmony_ci#define ICE_ITR_DYNAMIC	0x8000  /* used as flag for itr_setting */
2278c2ecf20Sopenharmony_ci#define ITR_IS_DYNAMIC(setting) (!!((setting) & ICE_ITR_DYNAMIC))
2288c2ecf20Sopenharmony_ci#define ITR_TO_REG(setting)	((setting) & ~ICE_ITR_DYNAMIC)
2298c2ecf20Sopenharmony_ci#define ICE_ITR_GRAN_S		1	/* ITR granularity is always 2us */
2308c2ecf20Sopenharmony_ci#define ICE_ITR_GRAN_US		BIT(ICE_ITR_GRAN_S)
2318c2ecf20Sopenharmony_ci#define ICE_ITR_MASK		0x1FFE	/* ITR register value alignment mask */
2328c2ecf20Sopenharmony_ci#define ITR_REG_ALIGN(setting)	((setting) & ICE_ITR_MASK)
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci#define ICE_ITR_ADAPTIVE_MIN_INC	0x0002
2358c2ecf20Sopenharmony_ci#define ICE_ITR_ADAPTIVE_MIN_USECS	0x0002
2368c2ecf20Sopenharmony_ci#define ICE_ITR_ADAPTIVE_MAX_USECS	0x00FA
2378c2ecf20Sopenharmony_ci#define ICE_ITR_ADAPTIVE_LATENCY	0x8000
2388c2ecf20Sopenharmony_ci#define ICE_ITR_ADAPTIVE_BULK		0x0000
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci#define ICE_DFLT_INTRL	0
2418c2ecf20Sopenharmony_ci#define ICE_MAX_INTRL	236
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci#define ICE_WB_ON_ITR_USECS	2
2448c2ecf20Sopenharmony_ci#define ICE_IN_WB_ON_ITR_MODE	255
2458c2ecf20Sopenharmony_ci/* Sets WB_ON_ITR and assumes INTENA bit is already cleared, which allows
2468c2ecf20Sopenharmony_ci * setting the MSK_M bit to tell hardware to ignore the INTENA_M bit. Also,
2478c2ecf20Sopenharmony_ci * set the write-back latency to the usecs passed in.
2488c2ecf20Sopenharmony_ci */
2498c2ecf20Sopenharmony_ci#define ICE_GLINT_DYN_CTL_WB_ON_ITR(usecs, itr_idx)	\
2508c2ecf20Sopenharmony_ci	((((usecs) << (GLINT_DYN_CTL_INTERVAL_S - ICE_ITR_GRAN_S)) & \
2518c2ecf20Sopenharmony_ci	  GLINT_DYN_CTL_INTERVAL_M) | \
2528c2ecf20Sopenharmony_ci	 (((itr_idx) << GLINT_DYN_CTL_ITR_INDX_S) & \
2538c2ecf20Sopenharmony_ci	  GLINT_DYN_CTL_ITR_INDX_M) | GLINT_DYN_CTL_INTENA_MSK_M | \
2548c2ecf20Sopenharmony_ci	 GLINT_DYN_CTL_WB_ON_ITR_M)
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci/* Legacy or Advanced Mode Queue */
2578c2ecf20Sopenharmony_ci#define ICE_TX_ADVANCED	0
2588c2ecf20Sopenharmony_ci#define ICE_TX_LEGACY	1
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci/* descriptor ring, associated with a VSI */
2618c2ecf20Sopenharmony_cistruct ice_ring {
2628c2ecf20Sopenharmony_ci	/* CL1 - 1st cacheline starts here */
2638c2ecf20Sopenharmony_ci	struct ice_ring *next;		/* pointer to next ring in q_vector */
2648c2ecf20Sopenharmony_ci	void *desc;			/* Descriptor ring memory */
2658c2ecf20Sopenharmony_ci	struct device *dev;		/* Used for DMA mapping */
2668c2ecf20Sopenharmony_ci	struct net_device *netdev;	/* netdev ring maps to */
2678c2ecf20Sopenharmony_ci	struct ice_vsi *vsi;		/* Backreference to associated VSI */
2688c2ecf20Sopenharmony_ci	struct ice_q_vector *q_vector;	/* Backreference to associated vector */
2698c2ecf20Sopenharmony_ci	u8 __iomem *tail;
2708c2ecf20Sopenharmony_ci	union {
2718c2ecf20Sopenharmony_ci		struct ice_tx_buf *tx_buf;
2728c2ecf20Sopenharmony_ci		struct ice_rx_buf *rx_buf;
2738c2ecf20Sopenharmony_ci	};
2748c2ecf20Sopenharmony_ci	/* CL2 - 2nd cacheline starts here */
2758c2ecf20Sopenharmony_ci	u16 q_index;			/* Queue number of ring */
2768c2ecf20Sopenharmony_ci	u16 q_handle;			/* Queue handle per TC */
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	u8 ring_active:1;		/* is ring online or not */
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	u16 count;			/* Number of descriptors */
2818c2ecf20Sopenharmony_ci	u16 reg_idx;			/* HW register index of the ring */
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	/* used in interrupt processing */
2848c2ecf20Sopenharmony_ci	u16 next_to_use;
2858c2ecf20Sopenharmony_ci	u16 next_to_clean;
2868c2ecf20Sopenharmony_ci	u16 next_to_alloc;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	/* stats structs */
2898c2ecf20Sopenharmony_ci	struct ice_q_stats	stats;
2908c2ecf20Sopenharmony_ci	struct u64_stats_sync syncp;
2918c2ecf20Sopenharmony_ci	union {
2928c2ecf20Sopenharmony_ci		struct ice_txq_stats tx_stats;
2938c2ecf20Sopenharmony_ci		struct ice_rxq_stats rx_stats;
2948c2ecf20Sopenharmony_ci	};
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	struct rcu_head rcu;		/* to avoid race on free */
2978c2ecf20Sopenharmony_ci	struct bpf_prog *xdp_prog;
2988c2ecf20Sopenharmony_ci	struct xsk_buff_pool *xsk_pool;
2998c2ecf20Sopenharmony_ci	/* CL3 - 3rd cacheline starts here */
3008c2ecf20Sopenharmony_ci	struct xdp_rxq_info xdp_rxq;
3018c2ecf20Sopenharmony_ci	/* CLX - the below items are only accessed infrequently and should be
3028c2ecf20Sopenharmony_ci	 * in their own cache line if possible
3038c2ecf20Sopenharmony_ci	 */
3048c2ecf20Sopenharmony_ci#define ICE_TX_FLAGS_RING_XDP		BIT(0)
3058c2ecf20Sopenharmony_ci#define ICE_RX_FLAGS_RING_BUILD_SKB	BIT(1)
3068c2ecf20Sopenharmony_ci	u8 flags;
3078c2ecf20Sopenharmony_ci	dma_addr_t dma;			/* physical address of ring */
3088c2ecf20Sopenharmony_ci	unsigned int size;		/* length of descriptor ring in bytes */
3098c2ecf20Sopenharmony_ci	u32 txq_teid;			/* Added Tx queue TEID */
3108c2ecf20Sopenharmony_ci	u16 rx_buf_len;
3118c2ecf20Sopenharmony_ci	u8 dcb_tc;			/* Traffic class of ring */
3128c2ecf20Sopenharmony_ci} ____cacheline_internodealigned_in_smp;
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic inline bool ice_ring_uses_build_skb(struct ice_ring *ring)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	return !!(ring->flags & ICE_RX_FLAGS_RING_BUILD_SKB);
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic inline void ice_set_ring_build_skb_ena(struct ice_ring *ring)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	ring->flags |= ICE_RX_FLAGS_RING_BUILD_SKB;
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic inline void ice_clear_ring_build_skb_ena(struct ice_ring *ring)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	ring->flags &= ~ICE_RX_FLAGS_RING_BUILD_SKB;
3278c2ecf20Sopenharmony_ci}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic inline bool ice_ring_is_xdp(struct ice_ring *ring)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	return !!(ring->flags & ICE_TX_FLAGS_RING_XDP);
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistruct ice_ring_container {
3358c2ecf20Sopenharmony_ci	/* head of linked-list of rings */
3368c2ecf20Sopenharmony_ci	struct ice_ring *ring;
3378c2ecf20Sopenharmony_ci	unsigned long next_update;	/* jiffies value of next queue update */
3388c2ecf20Sopenharmony_ci	unsigned int total_bytes;	/* total bytes processed this int */
3398c2ecf20Sopenharmony_ci	unsigned int total_pkts;	/* total packets processed this int */
3408c2ecf20Sopenharmony_ci	u16 itr_idx;		/* index in the interrupt vector */
3418c2ecf20Sopenharmony_ci	u16 target_itr;		/* value in usecs divided by the hw->itr_gran */
3428c2ecf20Sopenharmony_ci	u16 current_itr;	/* value in usecs divided by the hw->itr_gran */
3438c2ecf20Sopenharmony_ci	/* high bit set means dynamic ITR, rest is used to store user
3448c2ecf20Sopenharmony_ci	 * readable ITR value in usecs and must be converted before programming
3458c2ecf20Sopenharmony_ci	 * to a register.
3468c2ecf20Sopenharmony_ci	 */
3478c2ecf20Sopenharmony_ci	u16 itr_setting;
3488c2ecf20Sopenharmony_ci};
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_cistruct ice_coalesce_stored {
3518c2ecf20Sopenharmony_ci	u16 itr_tx;
3528c2ecf20Sopenharmony_ci	u16 itr_rx;
3538c2ecf20Sopenharmony_ci	u8 intrl;
3548c2ecf20Sopenharmony_ci	u8 tx_valid;
3558c2ecf20Sopenharmony_ci	u8 rx_valid;
3568c2ecf20Sopenharmony_ci};
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci/* iterator for handling rings in ring container */
3598c2ecf20Sopenharmony_ci#define ice_for_each_ring(pos, head) \
3608c2ecf20Sopenharmony_ci	for (pos = (head).ring; pos; pos = pos->next)
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_cistatic inline unsigned int ice_rx_pg_order(struct ice_ring *ring)
3638c2ecf20Sopenharmony_ci{
3648c2ecf20Sopenharmony_ci#if (PAGE_SIZE < 8192)
3658c2ecf20Sopenharmony_ci	if (ring->rx_buf_len > (PAGE_SIZE / 2))
3668c2ecf20Sopenharmony_ci		return 1;
3678c2ecf20Sopenharmony_ci#endif
3688c2ecf20Sopenharmony_ci	return 0;
3698c2ecf20Sopenharmony_ci}
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci#define ice_rx_pg_size(_ring) (PAGE_SIZE << ice_rx_pg_order(_ring))
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ciunion ice_32b_rx_flex_desc;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cibool ice_alloc_rx_bufs(struct ice_ring *rxr, u16 cleaned_count);
3768c2ecf20Sopenharmony_cinetdev_tx_t ice_start_xmit(struct sk_buff *skb, struct net_device *netdev);
3778c2ecf20Sopenharmony_civoid ice_clean_tx_ring(struct ice_ring *tx_ring);
3788c2ecf20Sopenharmony_civoid ice_clean_rx_ring(struct ice_ring *rx_ring);
3798c2ecf20Sopenharmony_ciint ice_setup_tx_ring(struct ice_ring *tx_ring);
3808c2ecf20Sopenharmony_ciint ice_setup_rx_ring(struct ice_ring *rx_ring);
3818c2ecf20Sopenharmony_civoid ice_free_tx_ring(struct ice_ring *tx_ring);
3828c2ecf20Sopenharmony_civoid ice_free_rx_ring(struct ice_ring *rx_ring);
3838c2ecf20Sopenharmony_ciint ice_napi_poll(struct napi_struct *napi, int budget);
3848c2ecf20Sopenharmony_ciint
3858c2ecf20Sopenharmony_ciice_prgm_fdir_fltr(struct ice_vsi *vsi, struct ice_fltr_desc *fdir_desc,
3868c2ecf20Sopenharmony_ci		   u8 *raw_packet);
3878c2ecf20Sopenharmony_ciint ice_clean_rx_irq(struct ice_ring *rx_ring, int budget);
3888c2ecf20Sopenharmony_civoid ice_clean_ctrl_tx_irq(struct ice_ring *tx_ring);
3898c2ecf20Sopenharmony_ci#endif /* _ICE_TXRX_H_ */
390