162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright (c) 2018, Intel Corporation. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _ICE_TXRX_H_
562306a36Sopenharmony_ci#define _ICE_TXRX_H_
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include "ice_type.h"
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#define ICE_DFLT_IRQ_WORK	256
1062306a36Sopenharmony_ci#define ICE_RXBUF_3072		3072
1162306a36Sopenharmony_ci#define ICE_RXBUF_2048		2048
1262306a36Sopenharmony_ci#define ICE_RXBUF_1664		1664
1362306a36Sopenharmony_ci#define ICE_RXBUF_1536		1536
1462306a36Sopenharmony_ci#define ICE_MAX_CHAINED_RX_BUFS	5
1562306a36Sopenharmony_ci#define ICE_MAX_BUF_TXD		8
1662306a36Sopenharmony_ci#define ICE_MIN_TX_LEN		17
1762306a36Sopenharmony_ci#define ICE_MAX_FRAME_LEGACY_RX 8320
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* The size limit for a transmit buffer in a descriptor is (16K - 1).
2062306a36Sopenharmony_ci * In order to align with the read requests we will align the value to
2162306a36Sopenharmony_ci * the nearest 4K which represents our maximum read request size.
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ci#define ICE_MAX_READ_REQ_SIZE	4096
2462306a36Sopenharmony_ci#define ICE_MAX_DATA_PER_TXD	(16 * 1024 - 1)
2562306a36Sopenharmony_ci#define ICE_MAX_DATA_PER_TXD_ALIGNED \
2662306a36Sopenharmony_ci	(~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define ICE_MAX_TXQ_PER_TXQG	128
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/* Attempt to maximize the headroom available for incoming frames. We use a 2K
3162306a36Sopenharmony_ci * buffer for MTUs <= 1500 and need 1536/1534 to store the data for the frame.
3262306a36Sopenharmony_ci * This leaves us with 512 bytes of room.  From that we need to deduct the
3362306a36Sopenharmony_ci * space needed for the shared info and the padding needed to IP align the
3462306a36Sopenharmony_ci * frame.
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci * Note: For cache line sizes 256 or larger this value is going to end
3762306a36Sopenharmony_ci *	 up negative.  In these cases we should fall back to the legacy
3862306a36Sopenharmony_ci *	 receive path.
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_ci#if (PAGE_SIZE < 8192)
4162306a36Sopenharmony_ci#define ICE_2K_TOO_SMALL_WITH_PADDING \
4262306a36Sopenharmony_ci	((unsigned int)(NET_SKB_PAD + ICE_RXBUF_1536) > \
4362306a36Sopenharmony_ci			SKB_WITH_OVERHEAD(ICE_RXBUF_2048))
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/**
4662306a36Sopenharmony_ci * ice_compute_pad - compute the padding
4762306a36Sopenharmony_ci * @rx_buf_len: buffer length
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci * Figure out the size of half page based on given buffer length and
5062306a36Sopenharmony_ci * then subtract the skb_shared_info followed by subtraction of the
5162306a36Sopenharmony_ci * actual buffer length; this in turn results in the actual space that
5262306a36Sopenharmony_ci * is left for padding usage
5362306a36Sopenharmony_ci */
5462306a36Sopenharmony_cistatic inline int ice_compute_pad(int rx_buf_len)
5562306a36Sopenharmony_ci{
5662306a36Sopenharmony_ci	int half_page_size;
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	half_page_size = ALIGN(rx_buf_len, PAGE_SIZE / 2);
5962306a36Sopenharmony_ci	return SKB_WITH_OVERHEAD(half_page_size) - rx_buf_len;
6062306a36Sopenharmony_ci}
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/**
6362306a36Sopenharmony_ci * ice_skb_pad - determine the padding that we can supply
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci * Figure out the right Rx buffer size and based on that calculate the
6662306a36Sopenharmony_ci * padding
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_cistatic inline int ice_skb_pad(void)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	int rx_buf_len;
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	/* If a 2K buffer cannot handle a standard Ethernet frame then
7362306a36Sopenharmony_ci	 * optimize padding for a 3K buffer instead of a 1.5K buffer.
7462306a36Sopenharmony_ci	 *
7562306a36Sopenharmony_ci	 * For a 3K buffer we need to add enough padding to allow for
7662306a36Sopenharmony_ci	 * tailroom due to NET_IP_ALIGN possibly shifting us out of
7762306a36Sopenharmony_ci	 * cache-line alignment.
7862306a36Sopenharmony_ci	 */
7962306a36Sopenharmony_ci	if (ICE_2K_TOO_SMALL_WITH_PADDING)
8062306a36Sopenharmony_ci		rx_buf_len = ICE_RXBUF_3072 + SKB_DATA_ALIGN(NET_IP_ALIGN);
8162306a36Sopenharmony_ci	else
8262306a36Sopenharmony_ci		rx_buf_len = ICE_RXBUF_1536;
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	/* if needed make room for NET_IP_ALIGN */
8562306a36Sopenharmony_ci	rx_buf_len -= NET_IP_ALIGN;
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci	return ice_compute_pad(rx_buf_len);
8862306a36Sopenharmony_ci}
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define ICE_SKB_PAD ice_skb_pad()
9162306a36Sopenharmony_ci#else
9262306a36Sopenharmony_ci#define ICE_2K_TOO_SMALL_WITH_PADDING false
9362306a36Sopenharmony_ci#define ICE_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
9462306a36Sopenharmony_ci#endif
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/* We are assuming that the cache line is always 64 Bytes here for ice.
9762306a36Sopenharmony_ci * In order to make sure that is a correct assumption there is a check in probe
9862306a36Sopenharmony_ci * to print a warning if the read from GLPCI_CNF2 tells us that the cache line
9962306a36Sopenharmony_ci * size is 128 bytes. We do it this way because we do not want to read the
10062306a36Sopenharmony_ci * GLPCI_CNF2 register or a variable containing the value on every pass through
10162306a36Sopenharmony_ci * the Tx path.
10262306a36Sopenharmony_ci */
10362306a36Sopenharmony_ci#define ICE_CACHE_LINE_BYTES		64
10462306a36Sopenharmony_ci#define ICE_DESCS_PER_CACHE_LINE	(ICE_CACHE_LINE_BYTES / \
10562306a36Sopenharmony_ci					 sizeof(struct ice_tx_desc))
10662306a36Sopenharmony_ci#define ICE_DESCS_FOR_CTX_DESC		1
10762306a36Sopenharmony_ci#define ICE_DESCS_FOR_SKB_DATA_PTR	1
10862306a36Sopenharmony_ci/* Tx descriptors needed, worst case */
10962306a36Sopenharmony_ci#define DESC_NEEDED (MAX_SKB_FRAGS + ICE_DESCS_FOR_CTX_DESC + \
11062306a36Sopenharmony_ci		     ICE_DESCS_PER_CACHE_LINE + ICE_DESCS_FOR_SKB_DATA_PTR)
11162306a36Sopenharmony_ci#define ICE_DESC_UNUSED(R)	\
11262306a36Sopenharmony_ci	(u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
11362306a36Sopenharmony_ci	      (R)->next_to_clean - (R)->next_to_use - 1)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define ICE_RX_DESC_UNUSED(R)	\
11662306a36Sopenharmony_ci	((((R)->first_desc > (R)->next_to_use) ? 0 : (R)->count) + \
11762306a36Sopenharmony_ci	      (R)->first_desc - (R)->next_to_use - 1)
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#define ICE_RING_QUARTER(R) ((R)->count >> 2)
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define ICE_TX_FLAGS_TSO	BIT(0)
12262306a36Sopenharmony_ci#define ICE_TX_FLAGS_HW_VLAN	BIT(1)
12362306a36Sopenharmony_ci#define ICE_TX_FLAGS_SW_VLAN	BIT(2)
12462306a36Sopenharmony_ci/* Free, was ICE_TX_FLAGS_DUMMY_PKT */
12562306a36Sopenharmony_ci#define ICE_TX_FLAGS_TSYN	BIT(4)
12662306a36Sopenharmony_ci#define ICE_TX_FLAGS_IPV4	BIT(5)
12762306a36Sopenharmony_ci#define ICE_TX_FLAGS_IPV6	BIT(6)
12862306a36Sopenharmony_ci#define ICE_TX_FLAGS_TUNNEL	BIT(7)
12962306a36Sopenharmony_ci#define ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN	BIT(8)
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci#define ICE_XDP_PASS		0
13262306a36Sopenharmony_ci#define ICE_XDP_CONSUMED	BIT(0)
13362306a36Sopenharmony_ci#define ICE_XDP_TX		BIT(1)
13462306a36Sopenharmony_ci#define ICE_XDP_REDIR		BIT(2)
13562306a36Sopenharmony_ci#define ICE_XDP_EXIT		BIT(3)
13662306a36Sopenharmony_ci#define ICE_SKB_CONSUMED	ICE_XDP_CONSUMED
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define ICE_RX_DMA_ATTR \
13962306a36Sopenharmony_ci	(DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci#define ICE_ETH_PKT_HDR_PAD	(ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#define ICE_TXD_LAST_DESC_CMD (ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/**
14662306a36Sopenharmony_ci * enum ice_tx_buf_type - type of &ice_tx_buf to act on Tx completion
14762306a36Sopenharmony_ci * @ICE_TX_BUF_EMPTY: unused OR XSk frame, no action required
14862306a36Sopenharmony_ci * @ICE_TX_BUF_DUMMY: dummy Flow Director packet, unmap and kfree()
14962306a36Sopenharmony_ci * @ICE_TX_BUF_FRAG: mapped skb OR &xdp_buff frag, only unmap DMA
15062306a36Sopenharmony_ci * @ICE_TX_BUF_SKB: &sk_buff, unmap and consume_skb(), update stats
15162306a36Sopenharmony_ci * @ICE_TX_BUF_XDP_TX: &xdp_buff, unmap and page_frag_free(), stats
15262306a36Sopenharmony_ci * @ICE_TX_BUF_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame(), stats
15362306a36Sopenharmony_ci * @ICE_TX_BUF_XSK_TX: &xdp_buff on XSk queue, xsk_buff_free(), stats
15462306a36Sopenharmony_ci */
15562306a36Sopenharmony_cienum ice_tx_buf_type {
15662306a36Sopenharmony_ci	ICE_TX_BUF_EMPTY	= 0U,
15762306a36Sopenharmony_ci	ICE_TX_BUF_DUMMY,
15862306a36Sopenharmony_ci	ICE_TX_BUF_FRAG,
15962306a36Sopenharmony_ci	ICE_TX_BUF_SKB,
16062306a36Sopenharmony_ci	ICE_TX_BUF_XDP_TX,
16162306a36Sopenharmony_ci	ICE_TX_BUF_XDP_XMIT,
16262306a36Sopenharmony_ci	ICE_TX_BUF_XSK_TX,
16362306a36Sopenharmony_ci};
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_cistruct ice_tx_buf {
16662306a36Sopenharmony_ci	union {
16762306a36Sopenharmony_ci		struct ice_tx_desc *next_to_watch;
16862306a36Sopenharmony_ci		u32 rs_idx;
16962306a36Sopenharmony_ci	};
17062306a36Sopenharmony_ci	union {
17162306a36Sopenharmony_ci		void *raw_buf;		/* used for XDP_TX and FDir rules */
17262306a36Sopenharmony_ci		struct sk_buff *skb;	/* used for .ndo_start_xmit() */
17362306a36Sopenharmony_ci		struct xdp_frame *xdpf;	/* used for .ndo_xdp_xmit() */
17462306a36Sopenharmony_ci		struct xdp_buff *xdp;	/* used for XDP_TX ZC */
17562306a36Sopenharmony_ci	};
17662306a36Sopenharmony_ci	unsigned int bytecount;
17762306a36Sopenharmony_ci	union {
17862306a36Sopenharmony_ci		unsigned int gso_segs;
17962306a36Sopenharmony_ci		unsigned int nr_frags;	/* used for mbuf XDP */
18062306a36Sopenharmony_ci	};
18162306a36Sopenharmony_ci	u32 tx_flags:12;
18262306a36Sopenharmony_ci	u32 type:4;			/* &ice_tx_buf_type */
18362306a36Sopenharmony_ci	u32 vid:16;
18462306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(len);
18562306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(dma);
18662306a36Sopenharmony_ci};
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_cistruct ice_tx_offload_params {
18962306a36Sopenharmony_ci	u64 cd_qw1;
19062306a36Sopenharmony_ci	struct ice_tx_ring *tx_ring;
19162306a36Sopenharmony_ci	u32 td_cmd;
19262306a36Sopenharmony_ci	u32 td_offset;
19362306a36Sopenharmony_ci	u32 td_l2tag1;
19462306a36Sopenharmony_ci	u32 cd_tunnel_params;
19562306a36Sopenharmony_ci	u16 cd_l2tag2;
19662306a36Sopenharmony_ci	u8 header_len;
19762306a36Sopenharmony_ci};
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_cistruct ice_rx_buf {
20062306a36Sopenharmony_ci	dma_addr_t dma;
20162306a36Sopenharmony_ci	struct page *page;
20262306a36Sopenharmony_ci	unsigned int page_offset;
20362306a36Sopenharmony_ci	unsigned int pgcnt;
20462306a36Sopenharmony_ci	unsigned int act;
20562306a36Sopenharmony_ci	unsigned int pagecnt_bias;
20662306a36Sopenharmony_ci};
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_cistruct ice_q_stats {
20962306a36Sopenharmony_ci	u64 pkts;
21062306a36Sopenharmony_ci	u64 bytes;
21162306a36Sopenharmony_ci};
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_cistruct ice_txq_stats {
21462306a36Sopenharmony_ci	u64 restart_q;
21562306a36Sopenharmony_ci	u64 tx_busy;
21662306a36Sopenharmony_ci	u64 tx_linearize;
21762306a36Sopenharmony_ci	int prev_pkt; /* negative if no pending Tx descriptors */
21862306a36Sopenharmony_ci};
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_cistruct ice_rxq_stats {
22162306a36Sopenharmony_ci	u64 non_eop_descs;
22262306a36Sopenharmony_ci	u64 alloc_page_failed;
22362306a36Sopenharmony_ci	u64 alloc_buf_failed;
22462306a36Sopenharmony_ci};
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_cistruct ice_ring_stats {
22762306a36Sopenharmony_ci	struct rcu_head rcu;	/* to avoid race on free */
22862306a36Sopenharmony_ci	struct ice_q_stats stats;
22962306a36Sopenharmony_ci	struct u64_stats_sync syncp;
23062306a36Sopenharmony_ci	union {
23162306a36Sopenharmony_ci		struct ice_txq_stats tx_stats;
23262306a36Sopenharmony_ci		struct ice_rxq_stats rx_stats;
23362306a36Sopenharmony_ci	};
23462306a36Sopenharmony_ci};
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_cienum ice_ring_state_t {
23762306a36Sopenharmony_ci	ICE_TX_XPS_INIT_DONE,
23862306a36Sopenharmony_ci	ICE_TX_NBITS,
23962306a36Sopenharmony_ci};
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci/* this enum matches hardware bits and is meant to be used by DYN_CTLN
24262306a36Sopenharmony_ci * registers and QINT registers or more generally anywhere in the manual
24362306a36Sopenharmony_ci * mentioning ITR_INDX, ITR_NONE cannot be used as an index 'n' into any
24462306a36Sopenharmony_ci * register but instead is a special value meaning "don't update" ITR0/1/2.
24562306a36Sopenharmony_ci */
24662306a36Sopenharmony_cienum ice_dyn_idx_t {
24762306a36Sopenharmony_ci	ICE_IDX_ITR0 = 0,
24862306a36Sopenharmony_ci	ICE_IDX_ITR1 = 1,
24962306a36Sopenharmony_ci	ICE_IDX_ITR2 = 2,
25062306a36Sopenharmony_ci	ICE_ITR_NONE = 3	/* ITR_NONE must not be used as an index */
25162306a36Sopenharmony_ci};
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci/* Header split modes defined by DTYPE field of Rx RLAN context */
25462306a36Sopenharmony_cienum ice_rx_dtype {
25562306a36Sopenharmony_ci	ICE_RX_DTYPE_NO_SPLIT		= 0,
25662306a36Sopenharmony_ci	ICE_RX_DTYPE_HEADER_SPLIT	= 1,
25762306a36Sopenharmony_ci	ICE_RX_DTYPE_SPLIT_ALWAYS	= 2,
25862306a36Sopenharmony_ci};
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci/* indices into GLINT_ITR registers */
26162306a36Sopenharmony_ci#define ICE_RX_ITR	ICE_IDX_ITR0
26262306a36Sopenharmony_ci#define ICE_TX_ITR	ICE_IDX_ITR1
26362306a36Sopenharmony_ci#define ICE_ITR_8K	124
26462306a36Sopenharmony_ci#define ICE_ITR_20K	50
26562306a36Sopenharmony_ci#define ICE_ITR_MAX	8160 /* 0x1FE0 */
26662306a36Sopenharmony_ci#define ICE_DFLT_TX_ITR	ICE_ITR_20K
26762306a36Sopenharmony_ci#define ICE_DFLT_RX_ITR	ICE_ITR_20K
26862306a36Sopenharmony_cienum ice_dynamic_itr {
26962306a36Sopenharmony_ci	ITR_STATIC = 0,
27062306a36Sopenharmony_ci	ITR_DYNAMIC = 1
27162306a36Sopenharmony_ci};
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci#define ITR_IS_DYNAMIC(rc) ((rc)->itr_mode == ITR_DYNAMIC)
27462306a36Sopenharmony_ci#define ICE_ITR_GRAN_S		1	/* ITR granularity is always 2us */
27562306a36Sopenharmony_ci#define ICE_ITR_GRAN_US		BIT(ICE_ITR_GRAN_S)
27662306a36Sopenharmony_ci#define ICE_ITR_MASK		0x1FFE	/* ITR register value alignment mask */
27762306a36Sopenharmony_ci#define ITR_REG_ALIGN(setting)	((setting) & ICE_ITR_MASK)
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci#define ICE_DFLT_INTRL	0
28062306a36Sopenharmony_ci#define ICE_MAX_INTRL	236
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci#define ICE_IN_WB_ON_ITR_MODE	255
28362306a36Sopenharmony_ci/* Sets WB_ON_ITR and assumes INTENA bit is already cleared, which allows
28462306a36Sopenharmony_ci * setting the MSK_M bit to tell hardware to ignore the INTENA_M bit. Also,
28562306a36Sopenharmony_ci * set the write-back latency to the usecs passed in.
28662306a36Sopenharmony_ci */
28762306a36Sopenharmony_ci#define ICE_GLINT_DYN_CTL_WB_ON_ITR(usecs, itr_idx)	\
28862306a36Sopenharmony_ci	((((usecs) << (GLINT_DYN_CTL_INTERVAL_S - ICE_ITR_GRAN_S)) & \
28962306a36Sopenharmony_ci	  GLINT_DYN_CTL_INTERVAL_M) | \
29062306a36Sopenharmony_ci	 (((itr_idx) << GLINT_DYN_CTL_ITR_INDX_S) & \
29162306a36Sopenharmony_ci	  GLINT_DYN_CTL_ITR_INDX_M) | GLINT_DYN_CTL_INTENA_MSK_M | \
29262306a36Sopenharmony_ci	 GLINT_DYN_CTL_WB_ON_ITR_M)
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci/* Legacy or Advanced Mode Queue */
29562306a36Sopenharmony_ci#define ICE_TX_ADVANCED	0
29662306a36Sopenharmony_ci#define ICE_TX_LEGACY	1
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci/* descriptor ring, associated with a VSI */
29962306a36Sopenharmony_cistruct ice_rx_ring {
30062306a36Sopenharmony_ci	/* CL1 - 1st cacheline starts here */
30162306a36Sopenharmony_ci	struct ice_rx_ring *next;	/* pointer to next ring in q_vector */
30262306a36Sopenharmony_ci	void *desc;			/* Descriptor ring memory */
30362306a36Sopenharmony_ci	struct device *dev;		/* Used for DMA mapping */
30462306a36Sopenharmony_ci	struct net_device *netdev;	/* netdev ring maps to */
30562306a36Sopenharmony_ci	struct ice_vsi *vsi;		/* Backreference to associated VSI */
30662306a36Sopenharmony_ci	struct ice_q_vector *q_vector;	/* Backreference to associated vector */
30762306a36Sopenharmony_ci	u8 __iomem *tail;
30862306a36Sopenharmony_ci	u16 q_index;			/* Queue number of ring */
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci	u16 count;			/* Number of descriptors */
31162306a36Sopenharmony_ci	u16 reg_idx;			/* HW register index of the ring */
31262306a36Sopenharmony_ci	u16 next_to_alloc;
31362306a36Sopenharmony_ci	/* CL2 - 2nd cacheline starts here */
31462306a36Sopenharmony_ci	union {
31562306a36Sopenharmony_ci		struct ice_rx_buf *rx_buf;
31662306a36Sopenharmony_ci		struct xdp_buff **xdp_buf;
31762306a36Sopenharmony_ci	};
31862306a36Sopenharmony_ci	struct xdp_buff xdp;
31962306a36Sopenharmony_ci	/* CL3 - 3rd cacheline starts here */
32062306a36Sopenharmony_ci	struct bpf_prog *xdp_prog;
32162306a36Sopenharmony_ci	u16 rx_offset;
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci	/* used in interrupt processing */
32462306a36Sopenharmony_ci	u16 next_to_use;
32562306a36Sopenharmony_ci	u16 next_to_clean;
32662306a36Sopenharmony_ci	u16 first_desc;
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci	/* stats structs */
32962306a36Sopenharmony_ci	struct ice_ring_stats *ring_stats;
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ci	struct rcu_head rcu;		/* to avoid race on free */
33262306a36Sopenharmony_ci	/* CL4 - 4th cacheline starts here */
33362306a36Sopenharmony_ci	struct ice_channel *ch;
33462306a36Sopenharmony_ci	struct ice_tx_ring *xdp_ring;
33562306a36Sopenharmony_ci	struct xsk_buff_pool *xsk_pool;
33662306a36Sopenharmony_ci	u32 nr_frags;
33762306a36Sopenharmony_ci	dma_addr_t dma;			/* physical address of ring */
33862306a36Sopenharmony_ci	u64 cached_phctime;
33962306a36Sopenharmony_ci	u16 rx_buf_len;
34062306a36Sopenharmony_ci	u8 dcb_tc;			/* Traffic class of ring */
34162306a36Sopenharmony_ci	u8 ptp_rx;
34262306a36Sopenharmony_ci#define ICE_RX_FLAGS_RING_BUILD_SKB	BIT(1)
34362306a36Sopenharmony_ci#define ICE_RX_FLAGS_CRC_STRIP_DIS	BIT(2)
34462306a36Sopenharmony_ci	u8 flags;
34562306a36Sopenharmony_ci	/* CL5 - 5th cacheline starts here */
34662306a36Sopenharmony_ci	struct xdp_rxq_info xdp_rxq;
34762306a36Sopenharmony_ci} ____cacheline_internodealigned_in_smp;
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_cistruct ice_tx_ring {
35062306a36Sopenharmony_ci	/* CL1 - 1st cacheline starts here */
35162306a36Sopenharmony_ci	struct ice_tx_ring *next;	/* pointer to next ring in q_vector */
35262306a36Sopenharmony_ci	void *desc;			/* Descriptor ring memory */
35362306a36Sopenharmony_ci	struct device *dev;		/* Used for DMA mapping */
35462306a36Sopenharmony_ci	u8 __iomem *tail;
35562306a36Sopenharmony_ci	struct ice_tx_buf *tx_buf;
35662306a36Sopenharmony_ci	struct ice_q_vector *q_vector;	/* Backreference to associated vector */
35762306a36Sopenharmony_ci	struct net_device *netdev;	/* netdev ring maps to */
35862306a36Sopenharmony_ci	struct ice_vsi *vsi;		/* Backreference to associated VSI */
35962306a36Sopenharmony_ci	/* CL2 - 2nd cacheline starts here */
36062306a36Sopenharmony_ci	dma_addr_t dma;			/* physical address of ring */
36162306a36Sopenharmony_ci	struct xsk_buff_pool *xsk_pool;
36262306a36Sopenharmony_ci	u16 next_to_use;
36362306a36Sopenharmony_ci	u16 next_to_clean;
36462306a36Sopenharmony_ci	u16 q_handle;			/* Queue handle per TC */
36562306a36Sopenharmony_ci	u16 reg_idx;			/* HW register index of the ring */
36662306a36Sopenharmony_ci	u16 count;			/* Number of descriptors */
36762306a36Sopenharmony_ci	u16 q_index;			/* Queue number of ring */
36862306a36Sopenharmony_ci	u16 xdp_tx_active;
36962306a36Sopenharmony_ci	/* stats structs */
37062306a36Sopenharmony_ci	struct ice_ring_stats *ring_stats;
37162306a36Sopenharmony_ci	/* CL3 - 3rd cacheline starts here */
37262306a36Sopenharmony_ci	struct rcu_head rcu;		/* to avoid race on free */
37362306a36Sopenharmony_ci	DECLARE_BITMAP(xps_state, ICE_TX_NBITS);	/* XPS Config State */
37462306a36Sopenharmony_ci	struct ice_channel *ch;
37562306a36Sopenharmony_ci	struct ice_ptp_tx *tx_tstamps;
37662306a36Sopenharmony_ci	spinlock_t tx_lock;
37762306a36Sopenharmony_ci	u32 txq_teid;			/* Added Tx queue TEID */
37862306a36Sopenharmony_ci	/* CL4 - 4th cacheline starts here */
37962306a36Sopenharmony_ci#define ICE_TX_FLAGS_RING_XDP		BIT(0)
38062306a36Sopenharmony_ci#define ICE_TX_FLAGS_RING_VLAN_L2TAG1	BIT(1)
38162306a36Sopenharmony_ci#define ICE_TX_FLAGS_RING_VLAN_L2TAG2	BIT(2)
38262306a36Sopenharmony_ci	u8 flags;
38362306a36Sopenharmony_ci	u8 dcb_tc;			/* Traffic class of ring */
38462306a36Sopenharmony_ci	u8 ptp_tx;
38562306a36Sopenharmony_ci} ____cacheline_internodealigned_in_smp;
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_cistatic inline bool ice_ring_uses_build_skb(struct ice_rx_ring *ring)
38862306a36Sopenharmony_ci{
38962306a36Sopenharmony_ci	return !!(ring->flags & ICE_RX_FLAGS_RING_BUILD_SKB);
39062306a36Sopenharmony_ci}
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_cistatic inline void ice_set_ring_build_skb_ena(struct ice_rx_ring *ring)
39362306a36Sopenharmony_ci{
39462306a36Sopenharmony_ci	ring->flags |= ICE_RX_FLAGS_RING_BUILD_SKB;
39562306a36Sopenharmony_ci}
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_cistatic inline void ice_clear_ring_build_skb_ena(struct ice_rx_ring *ring)
39862306a36Sopenharmony_ci{
39962306a36Sopenharmony_ci	ring->flags &= ~ICE_RX_FLAGS_RING_BUILD_SKB;
40062306a36Sopenharmony_ci}
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_cistatic inline bool ice_ring_ch_enabled(struct ice_tx_ring *ring)
40362306a36Sopenharmony_ci{
40462306a36Sopenharmony_ci	return !!ring->ch;
40562306a36Sopenharmony_ci}
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_cistatic inline bool ice_ring_is_xdp(struct ice_tx_ring *ring)
40862306a36Sopenharmony_ci{
40962306a36Sopenharmony_ci	return !!(ring->flags & ICE_TX_FLAGS_RING_XDP);
41062306a36Sopenharmony_ci}
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_cienum ice_container_type {
41362306a36Sopenharmony_ci	ICE_RX_CONTAINER,
41462306a36Sopenharmony_ci	ICE_TX_CONTAINER,
41562306a36Sopenharmony_ci};
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_cistruct ice_ring_container {
41862306a36Sopenharmony_ci	/* head of linked-list of rings */
41962306a36Sopenharmony_ci	union {
42062306a36Sopenharmony_ci		struct ice_rx_ring *rx_ring;
42162306a36Sopenharmony_ci		struct ice_tx_ring *tx_ring;
42262306a36Sopenharmony_ci	};
42362306a36Sopenharmony_ci	struct dim dim;		/* data for net_dim algorithm */
42462306a36Sopenharmony_ci	u16 itr_idx;		/* index in the interrupt vector */
42562306a36Sopenharmony_ci	/* this matches the maximum number of ITR bits, but in usec
42662306a36Sopenharmony_ci	 * values, so it is shifted left one bit (bit zero is ignored)
42762306a36Sopenharmony_ci	 */
42862306a36Sopenharmony_ci	union {
42962306a36Sopenharmony_ci		struct {
43062306a36Sopenharmony_ci			u16 itr_setting:13;
43162306a36Sopenharmony_ci			u16 itr_reserved:2;
43262306a36Sopenharmony_ci			u16 itr_mode:1;
43362306a36Sopenharmony_ci		};
43462306a36Sopenharmony_ci		u16 itr_settings;
43562306a36Sopenharmony_ci	};
43662306a36Sopenharmony_ci	enum ice_container_type type;
43762306a36Sopenharmony_ci};
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_cistruct ice_coalesce_stored {
44062306a36Sopenharmony_ci	u16 itr_tx;
44162306a36Sopenharmony_ci	u16 itr_rx;
44262306a36Sopenharmony_ci	u8 intrl;
44362306a36Sopenharmony_ci	u8 tx_valid;
44462306a36Sopenharmony_ci	u8 rx_valid;
44562306a36Sopenharmony_ci};
44662306a36Sopenharmony_ci
44762306a36Sopenharmony_ci/* iterator for handling rings in ring container */
44862306a36Sopenharmony_ci#define ice_for_each_rx_ring(pos, head) \
44962306a36Sopenharmony_ci	for (pos = (head).rx_ring; pos; pos = pos->next)
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci#define ice_for_each_tx_ring(pos, head) \
45262306a36Sopenharmony_ci	for (pos = (head).tx_ring; pos; pos = pos->next)
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_cistatic inline unsigned int ice_rx_pg_order(struct ice_rx_ring *ring)
45562306a36Sopenharmony_ci{
45662306a36Sopenharmony_ci#if (PAGE_SIZE < 8192)
45762306a36Sopenharmony_ci	if (ring->rx_buf_len > (PAGE_SIZE / 2))
45862306a36Sopenharmony_ci		return 1;
45962306a36Sopenharmony_ci#endif
46062306a36Sopenharmony_ci	return 0;
46162306a36Sopenharmony_ci}
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci#define ice_rx_pg_size(_ring) (PAGE_SIZE << ice_rx_pg_order(_ring))
46462306a36Sopenharmony_ci
46562306a36Sopenharmony_ciunion ice_32b_rx_flex_desc;
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_cibool ice_alloc_rx_bufs(struct ice_rx_ring *rxr, unsigned int cleaned_count);
46862306a36Sopenharmony_cinetdev_tx_t ice_start_xmit(struct sk_buff *skb, struct net_device *netdev);
46962306a36Sopenharmony_ciu16
47062306a36Sopenharmony_ciice_select_queue(struct net_device *dev, struct sk_buff *skb,
47162306a36Sopenharmony_ci		 struct net_device *sb_dev);
47262306a36Sopenharmony_civoid ice_clean_tx_ring(struct ice_tx_ring *tx_ring);
47362306a36Sopenharmony_civoid ice_clean_rx_ring(struct ice_rx_ring *rx_ring);
47462306a36Sopenharmony_ciint ice_setup_tx_ring(struct ice_tx_ring *tx_ring);
47562306a36Sopenharmony_ciint ice_setup_rx_ring(struct ice_rx_ring *rx_ring);
47662306a36Sopenharmony_civoid ice_free_tx_ring(struct ice_tx_ring *tx_ring);
47762306a36Sopenharmony_civoid ice_free_rx_ring(struct ice_rx_ring *rx_ring);
47862306a36Sopenharmony_ciint ice_napi_poll(struct napi_struct *napi, int budget);
47962306a36Sopenharmony_ciint
48062306a36Sopenharmony_ciice_prgm_fdir_fltr(struct ice_vsi *vsi, struct ice_fltr_desc *fdir_desc,
48162306a36Sopenharmony_ci		   u8 *raw_packet);
48262306a36Sopenharmony_ciint ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget);
48362306a36Sopenharmony_civoid ice_clean_ctrl_tx_irq(struct ice_tx_ring *tx_ring);
48462306a36Sopenharmony_ci#endif /* _ICE_TXRX_H_ */
485