1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
9 #define ICE_DFLT_IRQ_WORK 256
10 #define ICE_RXBUF_3072 3072
11 #define ICE_RXBUF_2048 2048
12 #define ICE_RXBUF_1536 1536
13 #define ICE_MAX_CHAINED_RX_BUFS 5
14 #define ICE_MAX_BUF_TXD 8
15 #define ICE_MIN_TX_LEN 17
17 /* The size limit for a transmit buffer in a descriptor is (16K - 1).
18 * In order to align with the read requests we will align the value to
19 * the nearest 4K which represents our maximum read request size.
21 #define ICE_MAX_READ_REQ_SIZE 4096
22 #define ICE_MAX_DATA_PER_TXD (16 * 1024 - 1)
23 #define ICE_MAX_DATA_PER_TXD_ALIGNED \
24 (~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD)
26 #define ICE_RX_BUF_WRITE 16 /* Must be power of 2 */
27 #define ICE_MAX_TXQ_PER_TXQG 128
29 /* Attempt to maximize the headroom available for incoming frames. We use a 2K
30 * buffer for MTUs <= 1500 and need 1536/1534 to store the data for the frame.
31 * This leaves us with 512 bytes of room. From that we need to deduct the
32 * space needed for the shared info and the padding needed to IP align the
35 * Note: For cache line sizes 256 or larger this value is going to end
36 * up negative. In these cases we should fall back to the legacy
39 #if (PAGE_SIZE < 8192)
40 #define ICE_2K_TOO_SMALL_WITH_PADDING \
41 ((unsigned int)(NET_SKB_PAD + ICE_RXBUF_1536) > \
42 SKB_WITH_OVERHEAD(ICE_RXBUF_2048))
45 * ice_compute_pad - compute the padding
46 * @rx_buf_len: buffer length
48 * Figure out the size of half page based on given buffer length and
49 * then subtract the skb_shared_info followed by subtraction of the
50 * actual buffer length; this in turn results in the actual space that
51 * is left for padding usage
53 static inline int ice_compute_pad(int rx_buf_len
)
57 half_page_size
= ALIGN(rx_buf_len
, PAGE_SIZE
/ 2);
58 return SKB_WITH_OVERHEAD(half_page_size
) - rx_buf_len
;
62 * ice_skb_pad - determine the padding that we can supply
64 * Figure out the right Rx buffer size and based on that calculate the
67 static inline int ice_skb_pad(void)
71 /* If a 2K buffer cannot handle a standard Ethernet frame then
72 * optimize padding for a 3K buffer instead of a 1.5K buffer.
74 * For a 3K buffer we need to add enough padding to allow for
75 * tailroom due to NET_IP_ALIGN possibly shifting us out of
76 * cache-line alignment.
78 if (ICE_2K_TOO_SMALL_WITH_PADDING
)
79 rx_buf_len
= ICE_RXBUF_3072
+ SKB_DATA_ALIGN(NET_IP_ALIGN
);
81 rx_buf_len
= ICE_RXBUF_1536
;
83 /* if needed make room for NET_IP_ALIGN */
84 rx_buf_len
-= NET_IP_ALIGN
;
86 return ice_compute_pad(rx_buf_len
);
89 #define ICE_SKB_PAD ice_skb_pad()
91 #define ICE_2K_TOO_SMALL_WITH_PADDING false
92 #define ICE_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
95 /* We are assuming that the cache line is always 64 Bytes here for ice.
96 * In order to make sure that is a correct assumption there is a check in probe
97 * to print a warning if the read from GLPCI_CNF2 tells us that the cache line
98 * size is 128 bytes. We do it this way because we do not want to read the
99 * GLPCI_CNF2 register or a variable containing the value on every pass through
102 #define ICE_CACHE_LINE_BYTES 64
103 #define ICE_DESCS_PER_CACHE_LINE (ICE_CACHE_LINE_BYTES / \
104 sizeof(struct ice_tx_desc))
105 #define ICE_DESCS_FOR_CTX_DESC 1
106 #define ICE_DESCS_FOR_SKB_DATA_PTR 1
107 /* Tx descriptors needed, worst case */
108 #define DESC_NEEDED (MAX_SKB_FRAGS + ICE_DESCS_FOR_CTX_DESC + \
109 ICE_DESCS_PER_CACHE_LINE + ICE_DESCS_FOR_SKB_DATA_PTR)
110 #define ICE_DESC_UNUSED(R) \
111 (u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
112 (R)->next_to_clean - (R)->next_to_use - 1)
114 #define ICE_TX_FLAGS_TSO BIT(0)
115 #define ICE_TX_FLAGS_HW_VLAN BIT(1)
116 #define ICE_TX_FLAGS_SW_VLAN BIT(2)
117 /* ICE_TX_FLAGS_DUMMY_PKT is used to mark dummy packets that should be
118 * freed instead of returned like skb packets.
120 #define ICE_TX_FLAGS_DUMMY_PKT BIT(3)
121 #define ICE_TX_FLAGS_IPV4 BIT(5)
122 #define ICE_TX_FLAGS_IPV6 BIT(6)
123 #define ICE_TX_FLAGS_TUNNEL BIT(7)
124 #define ICE_TX_FLAGS_VLAN_M 0xffff0000
125 #define ICE_TX_FLAGS_VLAN_PR_M 0xe0000000
126 #define ICE_TX_FLAGS_VLAN_PR_S 29
127 #define ICE_TX_FLAGS_VLAN_S 16
129 #define ICE_XDP_PASS 0
130 #define ICE_XDP_CONSUMED BIT(0)
131 #define ICE_XDP_TX BIT(1)
132 #define ICE_XDP_REDIR BIT(2)
134 #define ICE_RX_DMA_ATTR \
135 (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
137 #define ICE_ETH_PKT_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
139 #define ICE_TXD_LAST_DESC_CMD (ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)
142 struct ice_tx_desc
*next_to_watch
;
145 void *raw_buf
; /* used for XDP */
147 unsigned int bytecount
;
148 unsigned short gso_segs
;
150 DEFINE_DMA_UNMAP_LEN(len
);
151 DEFINE_DMA_UNMAP_ADDR(dma
);
154 struct ice_tx_offload_params
{
156 struct ice_ring
*tx_ring
;
160 u32 cd_tunnel_params
;
171 unsigned int page_offset
;
175 struct xdp_buff
*xdp
;
185 struct ice_txq_stats
{
189 int prev_pkt
; /* negative if no pending Tx descriptors */
192 struct ice_rxq_stats
{
194 u64 alloc_page_failed
;
195 u64 alloc_buf_failed
;
196 u64 gro_dropped
; /* GRO returned dropped */
199 /* this enum matches hardware bits and is meant to be used by DYN_CTLN
200 * registers and QINT registers or more generally anywhere in the manual
201 * mentioning ITR_INDX, ITR_NONE cannot be used as an index 'n' into any
202 * register but instead is a special value meaning "don't update" ITR0/1/2.
208 ICE_ITR_NONE
= 3 /* ITR_NONE must not be used as an index */
211 /* Header split modes defined by DTYPE field of Rx RLAN context */
213 ICE_RX_DTYPE_NO_SPLIT
= 0,
214 ICE_RX_DTYPE_HEADER_SPLIT
= 1,
215 ICE_RX_DTYPE_SPLIT_ALWAYS
= 2,
218 /* indices into GLINT_ITR registers */
219 #define ICE_RX_ITR ICE_IDX_ITR0
220 #define ICE_TX_ITR ICE_IDX_ITR1
221 #define ICE_ITR_8K 124
222 #define ICE_ITR_20K 50
223 #define ICE_ITR_MAX 8160
224 #define ICE_DFLT_TX_ITR (ICE_ITR_20K | ICE_ITR_DYNAMIC)
225 #define ICE_DFLT_RX_ITR (ICE_ITR_20K | ICE_ITR_DYNAMIC)
226 #define ICE_ITR_DYNAMIC 0x8000 /* used as flag for itr_setting */
227 #define ITR_IS_DYNAMIC(setting) (!!((setting) & ICE_ITR_DYNAMIC))
228 #define ITR_TO_REG(setting) ((setting) & ~ICE_ITR_DYNAMIC)
229 #define ICE_ITR_GRAN_S 1 /* ITR granularity is always 2us */
230 #define ICE_ITR_GRAN_US BIT(ICE_ITR_GRAN_S)
231 #define ICE_ITR_MASK 0x1FFE /* ITR register value alignment mask */
232 #define ITR_REG_ALIGN(setting) ((setting) & ICE_ITR_MASK)
234 #define ICE_ITR_ADAPTIVE_MIN_INC 0x0002
235 #define ICE_ITR_ADAPTIVE_MIN_USECS 0x0002
236 #define ICE_ITR_ADAPTIVE_MAX_USECS 0x00FA
237 #define ICE_ITR_ADAPTIVE_LATENCY 0x8000
238 #define ICE_ITR_ADAPTIVE_BULK 0x0000
240 #define ICE_DFLT_INTRL 0
241 #define ICE_MAX_INTRL 236
243 #define ICE_WB_ON_ITR_USECS 2
244 #define ICE_IN_WB_ON_ITR_MODE 255
245 /* Sets WB_ON_ITR and assumes INTENA bit is already cleared, which allows
246 * setting the MSK_M bit to tell hardware to ignore the INTENA_M bit. Also,
247 * set the write-back latency to the usecs passed in.
249 #define ICE_GLINT_DYN_CTL_WB_ON_ITR(usecs, itr_idx) \
250 ((((usecs) << (GLINT_DYN_CTL_INTERVAL_S - ICE_ITR_GRAN_S)) & \
251 GLINT_DYN_CTL_INTERVAL_M) | \
252 (((itr_idx) << GLINT_DYN_CTL_ITR_INDX_S) & \
253 GLINT_DYN_CTL_ITR_INDX_M) | GLINT_DYN_CTL_INTENA_MSK_M | \
254 GLINT_DYN_CTL_WB_ON_ITR_M)
256 /* Legacy or Advanced Mode Queue */
257 #define ICE_TX_ADVANCED 0
258 #define ICE_TX_LEGACY 1
260 /* descriptor ring, associated with a VSI */
262 /* CL1 - 1st cacheline starts here */
263 struct ice_ring
*next
; /* pointer to next ring in q_vector */
264 void *desc
; /* Descriptor ring memory */
265 struct device
*dev
; /* Used for DMA mapping */
266 struct net_device
*netdev
; /* netdev ring maps to */
267 struct ice_vsi
*vsi
; /* Backreference to associated VSI */
268 struct ice_q_vector
*q_vector
; /* Backreference to associated vector */
271 struct ice_tx_buf
*tx_buf
;
272 struct ice_rx_buf
*rx_buf
;
274 /* CL2 - 2nd cacheline starts here */
275 u16 q_index
; /* Queue number of ring */
276 u16 q_handle
; /* Queue handle per TC */
278 u8 ring_active
:1; /* is ring online or not */
280 u16 count
; /* Number of descriptors */
281 u16 reg_idx
; /* HW register index of the ring */
283 /* used in interrupt processing */
289 struct ice_q_stats stats
;
290 struct u64_stats_sync syncp
;
292 struct ice_txq_stats tx_stats
;
293 struct ice_rxq_stats rx_stats
;
296 struct rcu_head rcu
; /* to avoid race on free */
297 struct bpf_prog
*xdp_prog
;
298 struct xsk_buff_pool
*xsk_pool
;
299 /* CL3 - 3rd cacheline starts here */
300 struct xdp_rxq_info xdp_rxq
;
301 /* CLX - the below items are only accessed infrequently and should be
302 * in their own cache line if possible
304 #define ICE_TX_FLAGS_RING_XDP BIT(0)
305 #define ICE_RX_FLAGS_RING_BUILD_SKB BIT(1)
307 dma_addr_t dma
; /* physical address of ring */
308 unsigned int size
; /* length of descriptor ring in bytes */
309 u32 txq_teid
; /* Added Tx queue TEID */
311 u8 dcb_tc
; /* Traffic class of ring */
312 } ____cacheline_internodealigned_in_smp
;
314 static inline bool ice_ring_uses_build_skb(struct ice_ring
*ring
)
316 return !!(ring
->flags
& ICE_RX_FLAGS_RING_BUILD_SKB
);
319 static inline void ice_set_ring_build_skb_ena(struct ice_ring
*ring
)
321 ring
->flags
|= ICE_RX_FLAGS_RING_BUILD_SKB
;
324 static inline void ice_clear_ring_build_skb_ena(struct ice_ring
*ring
)
326 ring
->flags
&= ~ICE_RX_FLAGS_RING_BUILD_SKB
;
329 static inline bool ice_ring_is_xdp(struct ice_ring
*ring
)
331 return !!(ring
->flags
& ICE_TX_FLAGS_RING_XDP
);
334 struct ice_ring_container
{
335 /* head of linked-list of rings */
336 struct ice_ring
*ring
;
337 unsigned long next_update
; /* jiffies value of next queue update */
338 unsigned int total_bytes
; /* total bytes processed this int */
339 unsigned int total_pkts
; /* total packets processed this int */
340 u16 itr_idx
; /* index in the interrupt vector */
341 u16 target_itr
; /* value in usecs divided by the hw->itr_gran */
342 u16 current_itr
; /* value in usecs divided by the hw->itr_gran */
343 /* high bit set means dynamic ITR, rest is used to store user
344 * readable ITR value in usecs and must be converted before programming
350 struct ice_coalesce_stored
{
356 /* iterator for handling rings in ring container */
357 #define ice_for_each_ring(pos, head) \
358 for (pos = (head).ring; pos; pos = pos->next)
360 static inline unsigned int ice_rx_pg_order(struct ice_ring
*ring
)
362 #if (PAGE_SIZE < 8192)
363 if (ring
->rx_buf_len
> (PAGE_SIZE
/ 2))
369 #define ice_rx_pg_size(_ring) (PAGE_SIZE << ice_rx_pg_order(_ring))
371 union ice_32b_rx_flex_desc
;
373 bool ice_alloc_rx_bufs(struct ice_ring
*rxr
, u16 cleaned_count
);
374 netdev_tx_t
ice_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
);
375 void ice_clean_tx_ring(struct ice_ring
*tx_ring
);
376 void ice_clean_rx_ring(struct ice_ring
*rx_ring
);
377 int ice_setup_tx_ring(struct ice_ring
*tx_ring
);
378 int ice_setup_rx_ring(struct ice_ring
*rx_ring
);
379 void ice_free_tx_ring(struct ice_ring
*tx_ring
);
380 void ice_free_rx_ring(struct ice_ring
*rx_ring
);
381 int ice_napi_poll(struct napi_struct
*napi
, int budget
);
383 ice_prgm_fdir_fltr(struct ice_vsi
*vsi
, struct ice_fltr_desc
*fdir_desc
,
385 int ice_clean_rx_irq(struct ice_ring
*rx_ring
, int budget
);
386 void ice_clean_ctrl_tx_irq(struct ice_ring
*tx_ring
);
387 #endif /* _ICE_TXRX_H_ */