Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2024 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _COMMON_INTEL_TX_H_
6 : : #define _COMMON_INTEL_TX_H_
7 : :
8 : : #include <stdint.h>
9 : : #include <rte_mbuf.h>
10 : : #include <rte_ethdev.h>
11 : : #include <rte_vect.h>
12 : :
13 : : /* Common TX Descriptor QW1 Field Definitions */
14 : : #define CI_TXD_QW1_DTYPE_S 0
15 : : #define CI_TXD_QW1_DTYPE_M (0xFUL << CI_TXD_QW1_DTYPE_S)
16 : : #define CI_TXD_QW1_CMD_S 4
17 : : #define CI_TXD_QW1_CMD_M (0xFFFUL << CI_TXD_QW1_CMD_S)
18 : : #define CI_TXD_QW1_OFFSET_S 16
19 : : #define CI_TXD_QW1_OFFSET_M (0x3FFFFULL << CI_TXD_QW1_OFFSET_S)
20 : : #define CI_TXD_QW1_TX_BUF_SZ_S 34
21 : : #define CI_TXD_QW1_TX_BUF_SZ_M (0x3FFFULL << CI_TXD_QW1_TX_BUF_SZ_S)
22 : : #define CI_TXD_QW1_L2TAG1_S 48
23 : : #define CI_TXD_QW1_L2TAG1_M (0xFFFFULL << CI_TXD_QW1_L2TAG1_S)
24 : :
25 : : /* Common Descriptor Types */
26 : : #define CI_TX_DESC_DTYPE_DATA 0x0
27 : : #define CI_TX_DESC_DTYPE_CTX 0x1
28 : : #define CI_TX_DESC_DTYPE_DESC_DONE 0xF
29 : :
30 : : /* Common TX Descriptor Command Flags */
31 : : #define CI_TX_DESC_CMD_EOP 0x0001
32 : : #define CI_TX_DESC_CMD_RS 0x0002
33 : : #define CI_TX_DESC_CMD_ICRC 0x0004
34 : : #define CI_TX_DESC_CMD_IL2TAG1 0x0008
35 : : #define CI_TX_DESC_CMD_DUMMY 0x0010
36 : : #define CI_TX_DESC_CMD_IIPT_IPV6 0x0020
37 : : #define CI_TX_DESC_CMD_IIPT_IPV4 0x0040
38 : : #define CI_TX_DESC_CMD_IIPT_IPV4_CSUM 0x0060
39 : : #define CI_TX_DESC_CMD_L4T_EOFT_TCP 0x0100
40 : : #define CI_TX_DESC_CMD_L4T_EOFT_SCTP 0x0200
41 : : #define CI_TX_DESC_CMD_L4T_EOFT_UDP 0x0300
42 : :
43 : : /* Common TX Context Descriptor Commands */
44 : : #define CI_TX_CTX_DESC_TSO 0x01
45 : : #define CI_TX_CTX_DESC_TSYN 0x02
46 : : #define CI_TX_CTX_DESC_IL2TAG2 0x04
47 : :
48 : : /**
49 : : * L2TAG1 Field Source Selection
50 : : * Specifies which mbuf VLAN field to use for the L2TAG1 field in data descriptors.
51 : : * Context descriptor VLAN handling (L2TAG2) is managed by driver-specific callbacks.
52 : : */
53 : : enum ci_tx_l2tag1_field {
54 : : /** For VLAN (not QinQ), use L2Tag1 field in data desc */
55 : : CI_VLAN_IN_L2TAG1,
56 : :
57 : : /** For VLAN (not QinQ), use L2Tag2 field in ctx desc.
58 : : * NOTE: When set, drivers must set the VLAN tag in the context
59 : : * descriptor callback function, rather than relying on the
60 : : * common Tx code to insert it.
61 : : */
62 : : CI_VLAN_IN_L2TAG2,
63 : : };
64 : :
65 : : /* Common TX Descriptor Length Field Shifts */
66 : : #define CI_TX_DESC_LEN_MACLEN_S 0 /* 7 BITS */
67 : : #define CI_TX_DESC_LEN_IPLEN_S 7 /* 7 BITS */
68 : : #define CI_TX_DESC_LEN_L4_LEN_S 14 /* 4 BITS */
69 : :
70 : : /* Common maximum data per TX descriptor */
71 : : #define CI_MAX_DATA_PER_TXD (CI_TXD_QW1_TX_BUF_SZ_M >> CI_TXD_QW1_TX_BUF_SZ_S)
72 : :
73 : : /* Common TX maximum burst size for chunked transmission in simple paths */
74 : : #define CI_TX_MAX_BURST 32
75 : :
76 : : /* Common TX maximum free buffer size for batched bulk freeing */
77 : : #define CI_TX_MAX_FREE_BUF_SZ 64
78 : :
79 : : /* Common TX descriptor command flags for simple transmit */
80 : : #define CI_TX_DESC_CMD_DEFAULT (CI_TX_DESC_CMD_ICRC | CI_TX_DESC_CMD_EOP)
81 : :
82 : : /* Checksum offload mask to identify packets requesting offload */
83 : : #define CI_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM | \
84 : : RTE_MBUF_F_TX_L4_MASK | \
85 : : RTE_MBUF_F_TX_TCP_SEG | \
86 : : RTE_MBUF_F_TX_UDP_SEG | \
87 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
88 : : RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
89 : :
90 : : /**
91 : : * Common TX offload union for Intel drivers.
92 : : * Supports both basic offloads (l2_len, l3_len, l4_len, tso_segsz) and
93 : : * extended offloads (outer_l2_len, outer_l3_len) for tunneling support.
94 : : */
95 : : union ci_tx_offload {
96 : : uint64_t data;
97 : : struct {
98 : : uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
99 : : uint64_t l3_len:9; /**< L3 (IP) Header Length. */
100 : : uint64_t l4_len:8; /**< L4 Header Length. */
101 : : uint64_t tso_segsz:16; /**< TCP TSO segment size */
102 : : uint64_t outer_l2_len:8; /**< outer L2 Header Length */
103 : : uint64_t outer_l3_len:16; /**< outer L3 Header Length */
104 : : };
105 : : };
106 : :
107 : : /*
108 : : * Structure of a 16-byte Tx descriptor common across i40e, ice, iavf and idpf drivers
109 : : */
110 : : struct ci_tx_desc {
111 : : uint64_t buffer_addr; /* Address of descriptor's data buf */
112 : : uint64_t cmd_type_offset_bsz;
113 : : };
114 : :
115 : : /* forward declaration of the common intel (ci) queue structure */
116 : : struct ci_tx_queue;
117 : :
118 : : /**
119 : : * Structure associated with each descriptor of the TX ring of a TX queue.
120 : : */
121 : : struct ci_tx_entry {
122 : : struct rte_mbuf *mbuf; /* mbuf associated with TX desc, if any. */
123 : : uint16_t next_id; /* Index of next descriptor in ring. */
124 : : uint16_t first_id; /* Split-queue: first sw_id of packet at EOP entry. */
125 : : };
126 : :
127 : : /**
128 : : * Structure associated with each descriptor of the TX ring of a TX queue in vector Tx.
129 : : */
130 : : struct ci_tx_entry_vec {
131 : : struct rte_mbuf *mbuf; /* mbuf associated with TX desc, if any. */
132 : : };
133 : :
134 : : typedef void (*ice_tx_release_mbufs_t)(struct ci_tx_queue *txq);
135 : :
136 : : struct ci_tx_queue {
137 : : union { /* TX ring virtual address */
138 : : volatile struct ci_tx_desc *ci_tx_ring;
139 : : volatile union ixgbe_adv_tx_desc *ixgbe_tx_ring;
140 : : };
141 : : volatile uint8_t *qtx_tail; /* register address of tail */
142 : : union {
143 : : struct ci_tx_entry *sw_ring; /* virtual address of SW ring */
144 : : struct ci_tx_entry_vec *sw_ring_vec;
145 : : };
146 : : /* Scalar TX path: Array tracking last_id at each RS threshold boundary */
147 : : uint16_t *rs_last_id;
148 : : uint16_t nb_tx_desc; /* number of TX descriptors */
149 : : uint16_t tx_tail; /* current value of tail register */
150 : : /* index to last TX descriptor to have been cleaned */
151 : : uint16_t last_desc_cleaned;
152 : : /* Total number of TX descriptors ready to be allocated. */
153 : : uint16_t nb_tx_free;
154 : : /* Start freeing TX buffers if there are less free descriptors than
155 : : * this value.
156 : : */
157 : : uint16_t tx_free_thresh;
158 : : /* Number of TX descriptors to use before RS bit is set. */
159 : : uint16_t tx_rs_thresh;
160 : : /* Scalar TX path: log2 of tx_rs_thresh for efficient bit operations */
161 : : uint8_t log2_rs_thresh;
162 : : uint16_t port_id; /* Device port identifier. */
163 : : uint16_t queue_id; /* TX queue index. */
164 : : uint16_t reg_idx;
165 : : uint16_t tx_next_dd;
166 : : uint16_t tx_next_rs;
167 : : /* Mempool pointer for fast release of mbufs.
168 : : * NULL if disabled, UINTPTR_MAX if enabled and not yet known.
169 : : * Set at first use (if enabled and not yet known).
170 : : */
171 : : struct rte_mempool *fast_free_mp;
172 : : uint64_t offloads;
173 : : uint64_t mbuf_errors;
174 : : rte_iova_t tx_ring_dma; /* TX ring DMA address */
175 : : bool tx_deferred_start; /* don't start this queue in dev start */
176 : : bool q_set; /* indicate if tx queue has been configured */
177 : : bool use_vec_entry; /* use sw_ring_vec (true for vector and simple paths) */
178 : : union { /* the VSI this queue belongs to */
179 : : struct i40e_vsi *i40e_vsi;
180 : : struct iavf_vsi *iavf_vsi;
181 : : struct ice_vsi *ice_vsi;
182 : : };
183 : : const struct rte_memzone *mz;
184 : :
185 : : union {
186 : : struct { /* ICE driver specific values */
187 : : struct ice_txtime *tsq; /* Tx Time based queue */
188 : : uint32_t q_teid; /* TX schedule node id. */
189 : : };
190 : : struct { /* I40E driver specific values */
191 : : uint8_t dcb_tc;
192 : : };
193 : : struct { /* iavf driver specific values */
194 : : uint16_t ipsec_crypto_pkt_md_offset;
195 : : #define IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(0)
196 : : #define IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(1)
197 : : uint8_t vlan_flag;
198 : : uint8_t tc;
199 : : bool use_ctx; /* with ctx info, each pkt needs two descriptors */
200 : : uint8_t lldp_mode; /* ptype or dynfield */
201 : : };
202 : : struct { /* ixgbe specific values */
203 : : const struct ixgbe_txq_ops *ops;
204 : : struct ixgbe_advctx_info *ctx_cache;
205 : : uint8_t ctx_curr;
206 : : uint8_t pthresh; /**< Prefetch threshold register. */
207 : : uint8_t hthresh; /**< Host threshold register. */
208 : : uint8_t wthresh; /**< Write-back threshold reg. */
209 : : uint8_t using_ipsec; /**< indicates that IPsec TX feature is in use */
210 : : uint8_t is_vf; /**< indicates that this is a VF queue */
211 : : uint8_t vf_ctx_initialized; /**< VF context descriptors initialized */
212 : : };
213 : : struct { /* idpf specific values */
214 : : struct idpf_flex_tx_sched_desc *desc_ring;
215 : : struct idpf_complq *complq;
216 : : uint32_t latch_idx; /* Tx timestamp latch index */
217 : : uint16_t sw_nb_desc;
218 : : uint16_t sw_tail;
219 : : uint16_t rs_compl_count;
220 : : };
221 : : };
222 : : };
223 : :
224 : : struct ci_tx_path_features {
225 : : uint32_t tx_offloads;
226 : : enum rte_vect_max_simd simd_width;
227 : : bool simple_tx;
228 : : bool ctx_desc;
229 : : bool disabled;
230 : : bool single_queue;
231 : : };
232 : :
233 : : struct ci_tx_path_info {
234 : : eth_tx_burst_t pkt_burst;
235 : : const char *info;
236 : : struct ci_tx_path_features features;
237 : : eth_tx_prep_t pkt_prep;
238 : : };
239 : :
240 : : static __rte_always_inline void
241 : : ci_tx_backlog_entry(struct ci_tx_entry *txep, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
242 : : {
243 : : for (uint16_t i = 0; i < (int)nb_pkts; ++i)
244 : : txep[i].mbuf = tx_pkts[i];
245 : : }
246 : :
247 : : static __rte_always_inline void
248 : : ci_tx_backlog_entry_vec(struct ci_tx_entry_vec *txep, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
249 : : {
250 [ # # # # : 0 : for (uint16_t i = 0; i < nb_pkts; ++i)
# # # # #
# # # # #
# # ]
251 : 0 : txep[i].mbuf = tx_pkts[i];
252 : : }
253 : :
254 : : #define IETH_VPMD_TX_MAX_FREE_BUF 64
255 : :
256 : : typedef int (*ci_desc_done_fn)(struct ci_tx_queue *txq, uint16_t idx);
257 : :
258 : : static __rte_always_inline int
259 : : ci_tx_free_bufs_vec(struct ci_tx_queue *txq, ci_desc_done_fn desc_done, bool ctx_descs)
260 : : {
261 : : int nb_free = 0;
262 : : struct rte_mbuf *free[IETH_VPMD_TX_MAX_FREE_BUF];
263 : : struct rte_mbuf *m;
264 : :
265 : : /* check DD bits on threshold descriptor */
266 [ # # # # : 0 : if (!desc_done(txq, txq->tx_next_dd))
# # # # ]
267 : : return 0;
268 : :
269 : 0 : const uint32_t n = txq->tx_rs_thresh >> ctx_descs;
270 : :
271 : : /* first buffer to free from S/W ring is at index
272 : : * tx_next_dd - (tx_rs_thresh - 1)
273 : : */
274 : 0 : struct ci_tx_entry_vec *txep = txq->sw_ring_vec;
275 : 0 : txep += (txq->tx_next_dd >> ctx_descs) - (n - 1);
276 : :
277 : : /* is fast-free enabled? */
278 : : struct rte_mempool *mp =
279 : 0 : likely(txq->fast_free_mp != (void *)UINTPTR_MAX) ?
280 [ # # # # : 0 : txq->fast_free_mp :
# # # # ]
281 : 0 : (txq->fast_free_mp = txep[0].mbuf->pool);
282 : :
283 [ # # # # : 0 : if (mp != NULL && (n & 31) == 0) {
# # # # #
# # # # #
# # ]
284 : : static_assert(sizeof(*txep) == sizeof(struct rte_mbuf *),
285 : : "txep array is not similar to an array of rte_mbuf pointers");
286 : : rte_mbuf_raw_free_bulk(mp, (void *)txep, n);
287 : 0 : goto done;
288 : : }
289 : :
290 [ # # # # : 0 : m = rte_pktmbuf_prefree_seg(txep[0].mbuf);
# # # # ]
291 [ # # # # : 0 : if (likely(m)) {
# # # # ]
292 : 0 : free[0] = m;
293 : : nb_free = 1;
294 [ # # # # : 0 : for (uint32_t i = 1; i < n; i++) {
# # # # ]
295 [ # # # # : 0 : m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
# # # # ]
296 [ # # # # : 0 : if (likely(m)) {
# # # # ]
297 [ # # # # : 0 : if (likely(m->pool == free[0]->pool)) {
# # # # ]
298 : 0 : free[nb_free++] = m;
299 : : } else {
300 [ # # # # : 0 : rte_mbuf_raw_free_bulk(free[0]->pool, free, nb_free);
# # # # ]
301 : 0 : free[0] = m;
302 : : nb_free = 1;
303 : : }
304 : : }
305 : : }
306 [ # # # # : 0 : rte_mbuf_raw_free_bulk(free[0]->pool, free, nb_free);
# # # # ]
307 : : } else {
308 [ # # # # : 0 : for (uint32_t i = 1; i < n; i++) {
# # # # ]
309 [ # # # # : 0 : m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
# # # # ]
310 : : if (m)
311 [ # # # # : 0 : rte_mempool_put(m->pool, m);
# # # # ]
312 : : }
313 : : }
314 : :
315 : 0 : done:
316 : : /* buffers were freed, update counters */
317 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
318 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
319 [ # # # # : 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
# # # # ]
320 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
321 : :
322 [ # # ]: 0 : return txq->tx_rs_thresh;
323 : : }
324 : :
325 : : static inline void
326 : 0 : ci_txq_release_all_mbufs(struct ci_tx_queue *txq, bool use_ctx)
327 : : {
328 [ # # # # ]: 0 : if (unlikely(!txq || !txq->sw_ring))
329 : : return;
330 : :
331 [ # # ]: 0 : if (!txq->use_vec_entry) {
332 : : /* Regular scalar path uses sw_ring with ci_tx_entry */
333 [ # # ]: 0 : for (uint16_t i = 0; i < txq->nb_tx_desc; i++) {
334 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
335 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
336 : 0 : txq->sw_ring[i].mbuf = NULL;
337 : : }
338 : : }
339 : : return;
340 : : }
341 : :
342 : : /**
343 : : * Vector and simple paths use sw_ring_vec (ci_tx_entry_vec).
344 : : * vPMD tx will not set sw_ring's mbuf to NULL after free,
345 : : * so determining buffers to free is a little more complex.
346 : : */
347 : 0 : const uint16_t start = (txq->tx_next_dd - txq->tx_rs_thresh + 1) >> use_ctx;
348 : 0 : const uint16_t nb_desc = txq->nb_tx_desc >> use_ctx;
349 : 0 : const uint16_t end = txq->tx_tail >> use_ctx;
350 : :
351 : : uint16_t i = start;
352 [ # # ]: 0 : if (end < i) {
353 [ # # ]: 0 : for (; i < nb_desc; i++)
354 : 0 : rte_pktmbuf_free_seg(txq->sw_ring_vec[i].mbuf);
355 : : i = 0;
356 : : }
357 [ # # ]: 0 : for (; i < end; i++)
358 : 0 : rte_pktmbuf_free_seg(txq->sw_ring_vec[i].mbuf);
359 : 0 : memset(txq->sw_ring_vec, 0, sizeof(txq->sw_ring_vec[0]) * nb_desc);
360 : : }
361 : :
362 : : /**
363 : : * Select the best matching Tx path based on features
364 : : *
365 : : * @param req_features
366 : : * The requested features for the Tx path
367 : : * @param infos
368 : : * Array of information about the available Tx paths
369 : : * @param num_paths
370 : : * Number of available paths in the infos array
371 : : * @param default_path
372 : : * Index of the default path to use if no suitable path is found
373 : : *
374 : : * @return
375 : : * The packet burst function index that best matches the requested features,
376 : : * or default_path if no suitable path is found
377 : : */
378 : : static inline int
379 : 0 : ci_tx_path_select(const struct ci_tx_path_features *req_features,
380 : : const struct ci_tx_path_info *infos,
381 : : size_t num_paths,
382 : : int default_path)
383 : : {
384 : : int idx = default_path;
385 : : const struct ci_tx_path_features *chosen_path_features = NULL;
386 : :
387 [ # # ]: 0 : for (unsigned int i = 0; i < num_paths; i++) {
388 : 0 : const struct ci_tx_path_features *path_features = &infos[i].features;
389 : :
390 : : /* Do not select a path with a NULL pkt_burst function. */
391 [ # # ]: 0 : if (infos[i].pkt_burst == NULL)
392 : 0 : continue;
393 : :
394 : : /* Do not select a disabled tx path. */
395 [ # # ]: 0 : if (path_features->disabled)
396 : 0 : continue;
397 : :
398 : : /* Do not use a simple tx path if not requested. */
399 [ # # # # ]: 0 : if (path_features->simple_tx && !req_features->simple_tx)
400 : 0 : continue;
401 : :
402 : : /* If a context descriptor is requested, ensure the path supports it. */
403 [ # # # # ]: 0 : if (!path_features->ctx_desc && req_features->ctx_desc)
404 : 0 : continue;
405 : :
406 : : /* If requested, ensure the path supports single queue TX. */
407 [ # # ]: 0 : if (path_features->single_queue != req_features->single_queue)
408 : 0 : continue;
409 : :
410 : : /* Ensure the path supports the requested TX offloads. */
411 [ # # ]: 0 : if ((path_features->tx_offloads & req_features->tx_offloads) !=
412 : : req_features->tx_offloads)
413 : 0 : continue;
414 : :
415 : : /* Ensure the path's SIMD width is compatible with the requested width. */
416 [ # # ]: 0 : if (path_features->simd_width > req_features->simd_width)
417 : 0 : continue;
418 : :
419 : : /* Do not select the path if it is less suitable than the chosen path. */
420 [ # # ]: 0 : if (chosen_path_features != NULL) {
421 : : /* Do not select paths with lower SIMD width than the chosen path. */
422 [ # # ]: 0 : if (path_features->simd_width < chosen_path_features->simd_width)
423 : 0 : continue;
424 : : /* Do not select paths with more offloads enabled than the chosen path if
425 : : * the SIMD widths are the same.
426 : : */
427 [ # # ]: 0 : if (path_features->simd_width == chosen_path_features->simd_width &&
428 : : rte_popcount32(path_features->tx_offloads) >
429 [ # # ]: 0 : rte_popcount32(chosen_path_features->tx_offloads))
430 : 0 : continue;
431 : :
432 : : /* Don't use a context descriptor unless necessary */
433 [ # # # # ]: 0 : if (path_features->ctx_desc && !chosen_path_features->ctx_desc)
434 : 0 : continue;
435 : : }
436 : :
437 : : /* Finally, select the path since it has met all the requirements. */
438 : 0 : idx = i;
439 : 0 : chosen_path_features = &infos[idx].features;
440 : : }
441 : :
442 : 0 : return idx;
443 : : }
444 : :
445 : : /* include the scalar functions at the end, so they can use the common definitions.
446 : : * This is done so drivers can use all functions just by including tx.h
447 : : */
448 : : #include "tx_scalar.h"
449 : :
450 : : #endif /* _COMMON_INTEL_TX_H_ */
|