Debian Codegraph @

drivers/net/ethernet/intel/ice/ice_txrx.h

raw
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3
4 #ifndef _ICE_TXRX_H_
5 #define _ICE_TXRX_H_
6
7 #include <net/libeth/types.h>
8
9 #include "ice_type.h"
10
11 #define ICE_DFLT_IRQ_WORK 256
12 #define ICE_RXBUF_3072 3072
13 #define ICE_RXBUF_2048 2048
14 #define ICE_RXBUF_1664 1664
15 #define ICE_RXBUF_1536 1536
16 #define ICE_MAX_CHAINED_RX_BUFS 5
17 #define ICE_MAX_BUF_TXD 8
18 #define ICE_MIN_TX_LEN 17
19 #define ICE_MAX_FRAME_LEGACY_RX 8320
20
21 /* The size limit for a transmit buffer in a descriptor is (16K - 1).
22 * In order to align with the read requests we will align the value to
23 * the nearest 4K which represents our maximum read request size.
24 */
25 #define ICE_MAX_READ_REQ_SIZE 4096
26 #define ICE_MAX_DATA_PER_TXD (16 * 1024 - 1)
27 #define ICE_MAX_DATA_PER_TXD_ALIGNED \
28 (~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD)
29
30 #define ICE_MAX_TXQ_PER_TXQG 128
31
32 /* We are assuming that the cache line is always 64 Bytes here for ice.
33 * In order to make sure that is a correct assumption there is a check in probe
34 * to print a warning if the read from GLPCI_CNF2 tells us that the cache line
35 * size is 128 bytes. We do it this way because we do not want to read the
36 * GLPCI_CNF2 register or a variable containing the value on every pass through
37 * the Tx path.
38 */
39 #define ICE_CACHE_LINE_BYTES 64
40 #define ICE_DESCS_PER_CACHE_LINE (ICE_CACHE_LINE_BYTES / \
41 sizeof(struct ice_tx_desc))
42 #define ICE_DESCS_FOR_CTX_DESC 1
43 #define ICE_DESCS_FOR_SKB_DATA_PTR 1
44 /* Tx descriptors needed, worst case */
45 #define DESC_NEEDED (MAX_SKB_FRAGS + ICE_DESCS_FOR_CTX_DESC + \
46 ICE_DESCS_PER_CACHE_LINE + ICE_DESCS_FOR_SKB_DATA_PTR)
47 #define ICE_DESC_UNUSED(R) \
48 (u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
49 (R)->next_to_clean - (R)->next_to_use - 1)
50
51 #define ICE_RING_QUARTER(R) ((R)->count >> 2)
52
53 #define ICE_TX_FLAGS_TSO BIT(0)
54 #define ICE_TX_FLAGS_HW_VLAN BIT(1)
55 #define ICE_TX_FLAGS_SW_VLAN BIT(2)
56 /* Free, was ICE_TX_FLAGS_DUMMY_PKT */
57 #define ICE_TX_FLAGS_TSYN BIT(4)
58 #define ICE_TX_FLAGS_IPV4 BIT(5)
59 #define ICE_TX_FLAGS_IPV6 BIT(6)
60 #define ICE_TX_FLAGS_TUNNEL BIT(7)
61 #define ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN BIT(8)
62
63 #define ICE_XDP_PASS 0
64 #define ICE_XDP_CONSUMED BIT(0)
65 #define ICE_XDP_TX BIT(1)
66 #define ICE_XDP_REDIR BIT(2)
67 #define ICE_XDP_EXIT BIT(3)
68 #define ICE_SKB_CONSUMED ICE_XDP_CONSUMED
69
70 #define ICE_RX_DMA_ATTR \
71 (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
72
73 #define ICE_ETH_PKT_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
74
75 #define ICE_TXD_LAST_DESC_CMD (ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)
76
77 /**
78 * enum ice_tx_buf_type - type of &ice_tx_buf to act on Tx completion
79 * @ICE_TX_BUF_EMPTY: unused OR XSk frame, no action required
80 * @ICE_TX_BUF_DUMMY: dummy Flow Director packet, unmap and kfree()
81 * @ICE_TX_BUF_FRAG: mapped skb OR &xdp_buff frag, only unmap DMA
82 * @ICE_TX_BUF_SKB: &sk_buff, unmap and consume_skb(), update stats
83 * @ICE_TX_BUF_XDP_TX: &xdp_buff, unmap and page_frag_free(), stats
84 * @ICE_TX_BUF_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame(), stats
85 * @ICE_TX_BUF_XSK_TX: &xdp_buff on XSk queue, xsk_buff_free(), stats
86 */
87 enum ice_tx_buf_type {
88 ICE_TX_BUF_EMPTY = 0U,
89 ICE_TX_BUF_DUMMY,
90 ICE_TX_BUF_FRAG,
91 ICE_TX_BUF_SKB,
92 ICE_TX_BUF_XDP_TX,
93 ICE_TX_BUF_XDP_XMIT,
94 ICE_TX_BUF_XSK_TX,
95 };
96
97 struct ice_tx_buf {
98 union {
99 struct ice_tx_desc *next_to_watch;
100 u32 rs_idx;
101 };
102 union {
103 void *raw_buf; /* used for XDP_TX and FDir rules */
104 struct sk_buff *skb; /* used for .ndo_start_xmit() */
105 struct xdp_frame *xdpf; /* used for .ndo_xdp_xmit() */
106 struct xdp_buff *xdp; /* used for XDP_TX ZC */
107 };
108 unsigned int bytecount;
109 union {
110 unsigned int gso_segs;
111 unsigned int nr_frags; /* used for mbuf XDP */
112 };
113 u32 tx_flags:12;
114 u32 type:4; /* &ice_tx_buf_type */
115 u32 vid:16;
116 DEFINE_DMA_UNMAP_LEN(len);
117 DEFINE_DMA_UNMAP_ADDR(dma);
118 };
119
120 struct ice_tx_offload_params {
121 u64 cd_qw1;
122 struct ice_tx_ring *tx_ring;
123 u32 td_cmd;
124 u32 td_offset;
125 u32 td_l2tag1;
126 u32 cd_tunnel_params;
127 u16 cd_l2tag2;
128 u16 cd_gcs_params;
129 u8 header_len;
130 };
131
132 struct ice_ring_stats {
133 struct rcu_head rcu; /* to avoid race on free */
134 struct u64_stats_sync syncp;
135 struct_group(stats,
136 u64_stats_t pkts;
137 u64_stats_t bytes;
138 union {
139 struct_group(tx,
140 u64_stats_t tx_restart_q;
141 u64_stats_t tx_busy;
142 u64_stats_t tx_linearize;
143 /* negative if no pending Tx descriptors */
144 int prev_pkt;
145 );
146 struct_group(rx,
147 u64_stats_t rx_non_eop_descs;
148 u64_stats_t rx_page_failed;
149 u64_stats_t rx_buf_failed;
150 );
151 };
152 );
153 };
154
155 /**
156 * ice_stats_read - Read a single ring stat value
157 * @stats: pointer to ring_stats structure for a queue
158 * @member: the ice_ring_stats member to read
159 *
160 * Shorthand for reading a single 64-bit stat value from struct
161 * ice_ring_stats.
162 *
163 * Return: the value of the requested stat.
164 */
165 #define ice_stats_read(stats, member) ({ \
166 struct ice_ring_stats *__stats = (stats); \
167 unsigned int start; \
168 u64 val; \
169 do { \
170 start = u64_stats_fetch_begin(&__stats->syncp); \
171 val = u64_stats_read(&__stats->member); \
172 } while (u64_stats_fetch_retry(&__stats->syncp, start)); \
173 val; \
174 })
175
176 /**
177 * ice_stats_inc - Increment a single ring stat value
178 * @stats: pointer to the ring_stats structure for a queue
179 * @member: the ice_ring_stats member to increment
180 *
181 * Shorthand for incrementing a single 64-bit stat value in struct
182 * ice_ring_stats.
183 */
184 #define ice_stats_inc(stats, member) do { \
185 struct ice_ring_stats *__stats = (stats); \
186 u64_stats_update_begin(&__stats->syncp); \
187 u64_stats_inc(&__stats->member); \
188 u64_stats_update_end(&__stats->syncp); \
189 } while (0)
190
191 enum ice_ring_state_t {
192 ICE_TX_XPS_INIT_DONE,
193 ICE_TX_NBITS,
194 };
195
196 /* this enum matches hardware bits and is meant to be used by DYN_CTLN
197 * registers and QINT registers or more generally anywhere in the manual
198 * mentioning ITR_INDX, ITR_NONE cannot be used as an index 'n' into any
199 * register but instead is a special value meaning "don't update" ITR0/1/2.
200 */
201 enum ice_dyn_idx_t {
202 ICE_IDX_ITR0 = 0,
203 ICE_IDX_ITR1 = 1,
204 ICE_IDX_ITR2 = 2,
205 ICE_ITR_NONE = 3 /* ITR_NONE must not be used as an index */
206 };
207
208 /* Header split modes defined by DTYPE field of Rx RLAN context */
209 enum ice_rx_dtype {
210 ICE_RX_DTYPE_NO_SPLIT = 0,
211 ICE_RX_DTYPE_HEADER_SPLIT = 1,
212 ICE_RX_DTYPE_SPLIT_ALWAYS = 2,
213 };
214
215 enum ice_tx_ring_flags {
216 ICE_TX_RING_FLAGS_XDP,
217 ICE_TX_RING_FLAGS_VLAN_L2TAG1,
218 ICE_TX_RING_FLAGS_VLAN_L2TAG2,
219 ICE_TX_RING_FLAGS_TXTIME,
220 ICE_TX_RING_FLAGS_NBITS,
221 };
222
223 struct ice_pkt_ctx {
224 u64 cached_phctime;
225 __be16 vlan_proto;
226 };
227
228 /* indices into GLINT_ITR registers */
229 #define ICE_RX_ITR ICE_IDX_ITR0
230 #define ICE_TX_ITR ICE_IDX_ITR1
231 #define ICE_ITR_8K 124
232 #define ICE_ITR_20K 50
233 #define ICE_ITR_MAX 8160 /* 0x1FE0 */
234 #define ICE_DFLT_TX_ITR ICE_ITR_20K
235 #define ICE_DFLT_RX_ITR ICE_ITR_20K
236 enum ice_dynamic_itr {
237 ITR_STATIC = 0,
238 ITR_DYNAMIC = 1
239 };
240
241 #define ITR_IS_DYNAMIC(rc) ((rc)->itr_mode == ITR_DYNAMIC)
242 #define ICE_ITR_GRAN_S 1 /* ITR granularity is always 2us */
243 #define ICE_ITR_GRAN_US BIT(ICE_ITR_GRAN_S)
244 #define ICE_ITR_MASK 0x1FFE /* ITR register value alignment mask */
245 #define ITR_REG_ALIGN(setting) ((setting) & ICE_ITR_MASK)
246
247 #define ICE_DFLT_INTRL 0
248 #define ICE_MAX_INTRL 236
249
250 #define ICE_IN_WB_ON_ITR_MODE 255
251 /* Sets WB_ON_ITR and assumes INTENA bit is already cleared, which allows
252 * setting the MSK_M bit to tell hardware to ignore the INTENA_M bit. Also,
253 * set the write-back latency to the usecs passed in.
254 */
255 #define ICE_GLINT_DYN_CTL_WB_ON_ITR(usecs, itr_idx) \
256 ((((usecs) << (GLINT_DYN_CTL_INTERVAL_S - ICE_ITR_GRAN_S)) & \
257 GLINT_DYN_CTL_INTERVAL_M) | \
258 (((itr_idx) << GLINT_DYN_CTL_ITR_INDX_S) & \
259 GLINT_DYN_CTL_ITR_INDX_M) | GLINT_DYN_CTL_INTENA_MSK_M | \
260 GLINT_DYN_CTL_WB_ON_ITR_M)
261
262 /* Legacy or Advanced Mode Queue */
263 #define ICE_TX_ADVANCED 0
264 #define ICE_TX_LEGACY 1
265
266 /* descriptor ring, associated with a VSI */
267 struct ice_tstamp_ring {
268 struct ice_tx_ring *tx_ring; /* Backreference to associated Tx ring */
269 dma_addr_t dma; /* physical address of ring */
270 struct rcu_head rcu; /* to avoid race on free */
271 u8 __iomem *tail;
272 void *desc;
273 u16 next_to_use;
274 u16 count;
275 } ____cacheline_internodealigned_in_smp;
276
277 struct ice_rx_ring {
278 __cacheline_group_begin_aligned(read_mostly);
279 void *desc; /* Descriptor ring memory */
280 struct page_pool *pp;
281 struct net_device *netdev; /* netdev ring maps to */
282 struct ice_q_vector *q_vector; /* Backreference to associated vector */
283 u8 __iomem *tail;
284
285 union {
286 struct libeth_fqe *rx_fqes;
287 struct xdp_buff **xdp_buf;
288 };
289
290 u16 count; /* Number of descriptors */
291 u8 ptp_rx;
292
293 u8 flags;
294 #define ICE_RX_FLAGS_CRC_STRIP_DIS BIT(2)
295 #define ICE_RX_FLAGS_MULTIDEV BIT(3)
296 #define ICE_RX_FLAGS_RING_GCS BIT(4)
297
298 u32 truesize;
299
300 struct page_pool *hdr_pp;
301 struct libeth_fqe *hdr_fqes;
302
303 struct bpf_prog *xdp_prog;
304 struct ice_tx_ring *xdp_ring;
305 struct xsk_buff_pool *xsk_pool;
306
307 /* stats structs */
308 struct ice_ring_stats *ring_stats;
309 struct ice_rx_ring *next; /* pointer to next ring in q_vector */
310
311 u32 hdr_truesize;
312
313 struct xdp_rxq_info xdp_rxq;
314 __cacheline_group_end_aligned(read_mostly);
315
316 __cacheline_group_begin_aligned(read_write);
317 union {
318 struct libeth_xdp_buff_stash xdp;
319 struct libeth_xdp_buff *xsk;
320 };
321 union {
322 struct ice_pkt_ctx pkt_ctx;
323 struct {
324 u64 cached_phctime;
325 __be16 vlan_proto;
326 };
327 };
328
329 /* used in interrupt processing */
330 u16 next_to_use;
331 u16 next_to_clean;
332 __cacheline_group_end_aligned(read_write);
333
334 __cacheline_group_begin_aligned(cold);
335 struct rcu_head rcu; /* to avoid race on free */
336 struct ice_vsi *vsi; /* Backreference to associated VSI */
337 struct ice_channel *ch;
338
339 dma_addr_t dma; /* physical address of ring */
340 u16 q_index; /* Queue number of ring */
341 u16 reg_idx; /* HW register index of the ring */
342 u8 dcb_tc; /* Traffic class of ring */
343
344 u16 rx_hdr_len;
345 u16 rx_buf_len;
346 __cacheline_group_end_aligned(cold);
347 } ____cacheline_internodealigned_in_smp;
348
349 struct ice_tx_ring {
350 __cacheline_group_begin_aligned(read_mostly);
351 void *desc; /* Descriptor ring memory */
352 struct device *dev; /* Used for DMA mapping */
353 u8 __iomem *tail;
354 struct ice_tx_buf *tx_buf;
355
356 struct ice_q_vector *q_vector; /* Backreference to associated vector */
357 struct net_device *netdev; /* netdev ring maps to */
358 struct ice_vsi *vsi; /* Backreference to associated VSI */
359
360 u16 count; /* Number of descriptors */
361 u16 q_index; /* Queue number of ring */
362
363 DECLARE_BITMAP(flags, ICE_TX_RING_FLAGS_NBITS);
364
365 struct xsk_buff_pool *xsk_pool;
366
367 /* stats structs */
368 struct ice_ring_stats *ring_stats;
369 struct ice_tx_ring *next; /* pointer to next ring in q_vector */
370
371 struct ice_tstamp_ring *tstamp_ring;
372 struct ice_ptp_tx *tx_tstamps;
373 __cacheline_group_end_aligned(read_mostly);
374
375 __cacheline_group_begin_aligned(read_write);
376 u16 next_to_use;
377 u16 next_to_clean;
378
379 u16 xdp_tx_active;
380 spinlock_t tx_lock;
381 __cacheline_group_end_aligned(read_write);
382
383 __cacheline_group_begin_aligned(cold);
384 struct rcu_head rcu; /* to avoid race on free */
385 DECLARE_BITMAP(xps_state, ICE_TX_NBITS); /* XPS Config State */
386 struct ice_channel *ch;
387
388 dma_addr_t dma; /* physical address of ring */
389 u16 q_handle; /* Queue handle per TC */
390 u16 reg_idx; /* HW register index of the ring */
391 u8 dcb_tc; /* Traffic class of ring */
392
393 u16 quanta_prof_id;
394 u32 txq_teid; /* Added Tx queue TEID */
395 __cacheline_group_end_aligned(cold);
396 } ____cacheline_internodealigned_in_smp;
397
398 static inline bool ice_ring_ch_enabled(struct ice_tx_ring *ring)
399 {
400 return !!ring->ch;
401 }
402
403 static inline bool ice_ring_is_xdp(struct ice_tx_ring *ring)
404 {
405 return test_bit(ICE_TX_RING_FLAGS_XDP, ring->flags);
406 }
407
408 enum ice_container_type {
409 ICE_RX_CONTAINER,
410 ICE_TX_CONTAINER,
411 };
412
413 struct ice_ring_container {
414 /* head of linked-list of rings */
415 union {
416 struct ice_rx_ring *rx_ring;
417 struct ice_tx_ring *tx_ring;
418 };
419 struct dim dim; /* data for net_dim algorithm */
420 u16 itr_idx; /* index in the interrupt vector */
421 /* this matches the maximum number of ITR bits, but in usec
422 * values, so it is shifted left one bit (bit zero is ignored)
423 */
424 union {
425 struct {
426 u16 itr_setting:13;
427 u16 itr_reserved:2;
428 u16 itr_mode:1;
429 };
430 u16 itr_settings;
431 };
432 enum ice_container_type type;
433 };
434
435 struct ice_coalesce_stored {
436 u16 itr_tx;
437 u16 itr_rx;
438 u8 intrl;
439 u8 tx_valid;
440 u8 rx_valid;
441 };
442
443 /* iterator for handling rings in ring container */
444 #define ice_for_each_rx_ring(pos, head) \
445 for (pos = (head).rx_ring; pos; pos = pos->next)
446
447 #define ice_for_each_tx_ring(pos, head) \
448 for (pos = (head).tx_ring; pos; pos = pos->next)
449
450 static inline unsigned int ice_rx_pg_order(struct ice_rx_ring *ring)
451 {
452 return 0;
453 }
454
455 union ice_32b_rx_flex_desc;
456
457 void ice_init_ctrl_rx_descs(struct ice_rx_ring *rx_ring, u32 num_descs);
458 void ice_rxq_pp_destroy(struct ice_rx_ring *rq);
459 bool ice_alloc_rx_bufs(struct ice_rx_ring *rxr, unsigned int cleaned_count);
460 netdev_tx_t ice_start_xmit(struct sk_buff *skb, struct net_device *netdev);
461 u16
462 ice_select_queue(struct net_device *dev, struct sk_buff *skb,
463 struct net_device *sb_dev);
464 void ice_clean_tx_ring(struct ice_tx_ring *tx_ring);
465 void ice_clean_rx_ring(struct ice_rx_ring *rx_ring);
466 int ice_setup_tx_ring(struct ice_tx_ring *tx_ring);
467 int ice_setup_rx_ring(struct ice_rx_ring *rx_ring);
468 int ice_alloc_setup_tstamp_ring(struct ice_tx_ring *tx_ring);
469 void ice_free_tx_ring(struct ice_tx_ring *tx_ring);
470 void ice_free_rx_ring(struct ice_rx_ring *rx_ring);
471 int ice_napi_poll(struct napi_struct *napi, int budget);
472 int
473 ice_prgm_fdir_fltr(struct ice_vsi *vsi, struct ice_fltr_desc *fdir_desc,
474 u8 *raw_packet);
475 void ice_clean_ctrl_tx_irq(struct ice_tx_ring *tx_ring);
476 void ice_clean_ctrl_rx_irq(struct ice_rx_ring *rx_ring);
477 void ice_free_tx_tstamp_ring(struct ice_tx_ring *tx_ring);
478 void ice_free_tstamp_ring(struct ice_tx_ring *tx_ring);
479 #endif /* _ICE_TXRX_H_ */