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 : : #include <rte_io.h>
13 : : #include <rte_byteorder.h>
14 : :
15 : : #define CI_VPMD_TX_BURST 32
16 : : #define CI_VPMD_TX_MAX_FREE_BUF 64
17 : :
18 : : /* basic vector path */
19 : : #define CI_TX_VECTOR_OFFLOADS RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
20 : : /* offload vector path */
21 : : #define CI_TX_VEC_OFFLOAD_PATH_OFFLOADS ( \
22 : : CI_TX_VECTOR_OFFLOADS | \
23 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT | \
24 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \
25 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | \
26 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \
27 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM)
28 : : /* offload vector path with context descriptor */
29 : : #define CI_TX_VEC_CTX_OFFLOAD_PATH_OFFLOADS ( \
30 : : CI_TX_VECTOR_OFFLOADS | \
31 : : CI_TX_VEC_OFFLOAD_PATH_OFFLOADS | \
32 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
33 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM | \
34 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT)
35 : :
36 : : /* Common TX Descriptor QW1 Field Definitions */
37 : : #define CI_TXD_QW1_DTYPE_S 0
38 : : #define CI_TXD_QW1_DTYPE_M (0xFUL << CI_TXD_QW1_DTYPE_S)
39 : : #define CI_TXD_QW1_CMD_S 4
40 : : #define CI_TXD_QW1_CMD_M (0xFFFUL << CI_TXD_QW1_CMD_S)
41 : : #define CI_TXD_QW1_OFFSET_S 16
42 : : #define CI_TXD_QW1_OFFSET_M (0x3FFFFULL << CI_TXD_QW1_OFFSET_S)
43 : : #define CI_TXD_QW1_TX_BUF_SZ_S 34
44 : : #define CI_TXD_QW1_TX_BUF_SZ_M (0x3FFFULL << CI_TXD_QW1_TX_BUF_SZ_S)
45 : : #define CI_TXD_QW1_L2TAG1_S 48
46 : : #define CI_TXD_QW1_L2TAG1_M (0xFFFFULL << CI_TXD_QW1_L2TAG1_S)
47 : :
48 : : /* Common Descriptor Types */
49 : : #define CI_TX_DESC_DTYPE_DATA 0x0
50 : : #define CI_TX_DESC_DTYPE_CTX 0x1
51 : : #define CI_TX_DESC_DTYPE_DESC_DONE 0xF
52 : :
53 : : /* Common TX Descriptor Command Flags */
54 : : #define CI_TX_DESC_CMD_EOP 0x0001
55 : : #define CI_TX_DESC_CMD_RS 0x0002
56 : : #define CI_TX_DESC_CMD_ICRC 0x0004
57 : : #define CI_TX_DESC_CMD_IL2TAG1 0x0008
58 : : #define CI_TX_DESC_CMD_DUMMY 0x0010
59 : : #define CI_TX_DESC_CMD_IIPT_IPV6 0x0020
60 : : #define CI_TX_DESC_CMD_IIPT_IPV4 0x0040
61 : : #define CI_TX_DESC_CMD_IIPT_IPV4_CSUM 0x0060
62 : : #define CI_TX_DESC_CMD_L4T_EOFT_TCP 0x0100
63 : : #define CI_TX_DESC_CMD_L4T_EOFT_SCTP 0x0200
64 : : #define CI_TX_DESC_CMD_L4T_EOFT_UDP 0x0300
65 : :
66 : : /* Common TX Context Descriptor Commands */
67 : : #define CI_TX_CTX_DESC_TSO 0x01
68 : : #define CI_TX_CTX_DESC_TSYN 0x02
69 : : #define CI_TX_CTX_DESC_IL2TAG2 0x04
70 : :
71 : : /* Common TX Context Descriptor QW0 Field Shifts */
72 : : #define CI_TXD_CTX_QW0_L2TAG2_S 32
73 : : #define CI_TXD_CTX_QW0_EIPT_S 0 /* 2 BITS - external IP type */
74 : : #define CI_TXD_CTX_QW0_EIPLEN_S 2 /* 7 BITS - external IP header length */
75 : : #define CI_TXD_CTX_QW0_NATT_S 9 /* 2 BITS - L4 tunnel type */
76 : : #define CI_TXD_CTX_QW0_EIP_NOINC_S 11 /* 1 BIT - external IP ID not incremented */
77 : : #define CI_TXD_CTX_QW0_NATLEN_S 12 /* 7 BITS - L4 tunnel header length */
78 : : #define CI_TXD_CTX_QW0_L4T_CS_S 23 /* 1 BIT - tunnel UDP checksum enable */
79 : :
80 : : /**
81 : : * Enum for the external (outer) IP type field of a Tx context descriptor's
82 : : * tunnel parameters (QW0 bits 0-1).
83 : : */
84 : : enum ci_tx_ctx_eipt {
85 : : CI_TX_CTX_EIPT_NONE,
86 : : CI_TX_CTX_EIPT_IPV6,
87 : : CI_TX_CTX_EIPT_IPV4_NO_CSUM,
88 : : CI_TX_CTX_EIPT_IPV4,
89 : : };
90 : :
91 : : #define CI_TXD_CTX_UDP_TUNNELING (0x1ULL << CI_TXD_CTX_QW0_NATT_S)
92 : : #define CI_TXD_CTX_GRE_TUNNELING (0x2ULL << CI_TXD_CTX_QW0_NATT_S)
93 : : #define CI_TXD_CTX_QW0_L4T_CS_M (0x1ULL << CI_TXD_CTX_QW0_L4T_CS_S)
94 : :
95 : : /**
96 : : * Enum to specify where a VLAN tag is to be placed for packet Tx.
97 : : */
98 : : enum ci_l2tag_pos {
99 : : /** Insert via the data descriptor's L2Tag1 field. */
100 : : CI_TAG_IN_DATA_DESC,
101 : :
102 : : /** Insert via the context descriptor's L2Tag2 field.
103 : : * NOTE: When set, drivers must set the VLAN tag in the context
104 : : * descriptor callback function, rather than relying on the
105 : : * common Tx code to insert it.
106 : : */
107 : : CI_TAG_IN_CTX_DESC,
108 : : };
109 : :
110 : : /* Common TX Descriptor Length Field Shifts */
111 : : #define CI_TX_DESC_LEN_MACLEN_S 0 /* 7 BITS */
112 : : #define CI_TX_DESC_LEN_IPLEN_S 7 /* 7 BITS */
113 : : #define CI_TX_DESC_LEN_L4_LEN_S 14 /* 4 BITS */
114 : :
115 : : /* Common maximum data per TX descriptor */
116 : : #define CI_MAX_DATA_PER_TXD (CI_TXD_QW1_TX_BUF_SZ_M >> CI_TXD_QW1_TX_BUF_SZ_S)
117 : :
118 : : /* Common TX maximum burst size for chunked transmission in simple paths */
119 : : #define CI_TX_MAX_BURST 32
120 : :
121 : : /* Common TX maximum free buffer size for batched bulk freeing */
122 : : #define CI_TX_MAX_FREE_BUF_SZ 64
123 : :
124 : : /* Common TX descriptor command flags for simple transmit */
125 : : #define CI_TX_DESC_CMD_DEFAULT (CI_TX_DESC_CMD_ICRC | CI_TX_DESC_CMD_EOP)
126 : :
127 : : /* Checksum offload mask to identify packets requesting offload */
128 : : #define CI_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM | \
129 : : RTE_MBUF_F_TX_L4_MASK | \
130 : : RTE_MBUF_F_TX_TCP_SEG | \
131 : : RTE_MBUF_F_TX_UDP_SEG | \
132 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
133 : : RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
134 : :
135 : : /**
136 : : * Common TX offload union for Intel drivers.
137 : : * Supports both basic offloads (l2_len, l3_len, l4_len, tso_segsz) and
138 : : * extended offloads (outer_l2_len, outer_l3_len) for tunneling support.
139 : : */
140 : : union ci_tx_offload {
141 : : uint64_t data;
142 : : struct {
143 : : uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
144 : : uint64_t l3_len:9; /**< L3 (IP) Header Length. */
145 : : uint64_t l4_len:8; /**< L4 Header Length. */
146 : : uint64_t tso_segsz:16; /**< TCP TSO segment size */
147 : : uint64_t outer_l2_len:8; /**< outer L2 Header Length */
148 : : uint64_t outer_l3_len:16; /**< outer L3 Header Length */
149 : : };
150 : : };
151 : :
152 : : /*
153 : : * Structure of a 16-byte Tx descriptor common across i40e, ice, iavf and idpf drivers
154 : : */
155 : : struct ci_tx_desc {
156 : : uint64_t buffer_addr; /* Address of descriptor's data buf */
157 : : uint64_t cmd_type_offset_bsz;
158 : : };
159 : :
160 : : /* forward declaration of the common intel (ci) queue structure */
161 : : struct ci_tx_queue;
162 : :
163 : : /**
164 : : * Structure associated with each descriptor of the TX ring of a TX queue.
165 : : */
166 : : struct ci_tx_entry {
167 : : struct rte_mbuf *mbuf; /* mbuf associated with TX desc, if any. */
168 : : uint16_t next_id; /* Index of next descriptor in ring. */
169 : : };
170 : :
171 : : /**
172 : : * Structure associated with each descriptor of the TX ring of a TX queue in vector Tx.
173 : : */
174 : : struct ci_tx_entry_vec {
175 : : struct rte_mbuf *mbuf; /* mbuf associated with TX desc, if any. */
176 : : };
177 : :
178 : : typedef void (*ice_tx_release_mbufs_t)(struct ci_tx_queue *txq);
179 : :
180 : : struct ci_tx_queue {
181 : : union { /* TX ring virtual address */
182 : : volatile struct ci_tx_desc *ci_tx_ring;
183 : : volatile union ixgbe_adv_tx_desc *ixgbe_tx_ring;
184 : : };
185 : : volatile uint8_t *qtx_tail; /* register address of tail */
186 : : union {
187 : : struct ci_tx_entry *sw_ring; /* virtual address of SW ring */
188 : : struct ci_tx_entry_vec *sw_ring_vec;
189 : : /* IDPF split scalar: packet ownership indexed by completion tag. */
190 : : struct rte_mbuf **tx_pending_pkts;
191 : : };
192 : : /* Scalar TX path: Array tracking last_id at each RS threshold boundary */
193 : : uint16_t *rs_last_id;
194 : : uint16_t nb_tx_desc; /* number of TX descriptors */
195 : : uint16_t tx_tail; /* current value of tail register */
196 : : /* index to last TX descriptor to have been cleaned */
197 : : uint16_t last_desc_cleaned;
198 : : /* Total number of TX descriptors ready to be allocated. */
199 : : uint16_t nb_tx_free;
200 : : /* Start freeing TX buffers if there are less free descriptors than
201 : : * this value.
202 : : */
203 : : uint16_t tx_free_thresh;
204 : : /* Number of TX descriptors to use before RS bit is set. */
205 : : uint16_t tx_rs_thresh;
206 : : /* Scalar TX path: log2 of tx_rs_thresh for efficient bit operations */
207 : : uint8_t log2_rs_thresh;
208 : : uint16_t port_id; /* Device port identifier. */
209 : : uint16_t queue_id; /* TX queue index. */
210 : : uint16_t reg_idx;
211 : : uint16_t tx_next_dd;
212 : : uint16_t tx_next_rs;
213 : : /* Mempool pointer for fast release of mbufs.
214 : : * NULL if disabled, UINTPTR_MAX if enabled and not yet known.
215 : : * Set at first use (if enabled and not yet known).
216 : : */
217 : : struct rte_mempool *fast_free_mp;
218 : : uint64_t offloads;
219 : : uint64_t mbuf_errors;
220 : : rte_iova_t tx_ring_dma; /* TX ring DMA address */
221 : : bool tx_deferred_start; /* don't start this queue in dev start */
222 : : bool q_set; /* indicate if tx queue has been configured */
223 : : bool use_vec_entry; /* use sw_ring_vec (true for vector and simple paths) */
224 : : bool use_ctx; /* with ctx info, each pkt needs two desc in vec paths */
225 : : union { /* the VSI this queue belongs to */
226 : : struct i40e_vsi *i40e_vsi;
227 : : struct iavf_vsi *iavf_vsi;
228 : : struct ice_vsi *ice_vsi;
229 : : };
230 : : const struct rte_memzone *mz;
231 : :
232 : : union {
233 : : struct { /* ICE driver specific values */
234 : : struct ice_txtime *tsq; /* Tx Time based queue */
235 : : uint32_t q_teid; /* TX schedule node id. */
236 : : };
237 : : struct { /* I40E driver specific values */
238 : : uint8_t dcb_tc;
239 : : };
240 : : struct { /* iavf driver specific values */
241 : : uint16_t ipsec_crypto_pkt_md_offset;
242 : : #define IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(0)
243 : : #define IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(1)
244 : : uint8_t vlan_flag;
245 : : uint8_t tc;
246 : : bool lldp_enabled;
247 : : };
248 : : struct { /* ixgbe specific values */
249 : : const struct ixgbe_txq_ops *ops;
250 : : struct ixgbe_advctx_info *ctx_cache;
251 : : uint8_t ctx_curr;
252 : : uint8_t pthresh; /**< Prefetch threshold register. */
253 : : uint8_t hthresh; /**< Host threshold register. */
254 : : uint8_t wthresh; /**< Write-back threshold reg. */
255 : : uint8_t using_ipsec; /**< indicates that IPsec TX feature is in use */
256 : : uint8_t is_vf; /**< indicates that this is a VF queue */
257 : : uint8_t vf_ctx_initialized; /**< VF context descriptors initialized */
258 : : };
259 : : struct { /* idpf specific values */
260 : : struct idpf_flex_tx_sched_desc *desc_ring;
261 : : struct idpf_complq *complq;
262 : : uint32_t latch_idx; /* Tx timestamp latch index */
263 : : uint16_t sw_nb_desc;
264 : : uint16_t rs_compl_count;
265 : : uint16_t tx_next_compl_tag;
266 : : };
267 : : };
268 : : };
269 : :
270 : : struct ci_tx_path_features {
271 : : uint32_t tx_offloads;
272 : : enum rte_vect_max_simd simd_width;
273 : : bool simple_tx;
274 : : bool disabled;
275 : : bool single_queue;
276 : : };
277 : :
278 : : struct ci_tx_path_info {
279 : : eth_tx_burst_t pkt_burst;
280 : : const char *info;
281 : : struct ci_tx_path_features features;
282 : : eth_tx_prep_t pkt_prep;
283 : : bool supports_ctx;
284 : : };
285 : :
286 : : /* basic check for a vector-driver capable Tx queue.
287 : : * Individual drivers may have other further tests beyond this.
288 : : */
289 : : static inline bool
290 : : ci_txq_vec_capable(uint16_t rs_thresh)
291 : : {
292 [ # # ]: 0 : return rs_thresh >= CI_VPMD_TX_BURST && rs_thresh <= CI_VPMD_TX_MAX_FREE_BUF;
293 : : }
294 : :
295 : : static __rte_always_inline void
296 : : ci_tx_backlog_entry(struct ci_tx_entry *txep, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
297 : : {
298 : : for (uint16_t i = 0; i < (int)nb_pkts; ++i)
299 : : txep[i].mbuf = tx_pkts[i];
300 : : }
301 : :
302 : : static __rte_always_inline void
303 : : ci_tx_backlog_entry_vec(struct ci_tx_entry_vec *txep, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
304 : : {
305 [ # # # # : 0 : for (uint16_t i = 0; i < nb_pkts; ++i)
# # # # #
# # # # #
# # ]
306 : 0 : txep[i].mbuf = tx_pkts[i];
307 : : }
308 : :
309 : :
310 : : /* Write the Tx tail register, byte-swapped for hardware regardless of host endianness. */
311 : : static __rte_always_inline void
312 : : ci_tx_qtx_tail_write(struct ci_tx_queue *txq, uint16_t tx_id)
313 : : {
314 : 0 : rte_write32_wc(rte_cpu_to_le_32((uint32_t)tx_id), txq->qtx_tail);
315 : : }
316 : :
317 : : #define IETH_VPMD_TX_MAX_FREE_BUF 64
318 : :
319 : : typedef int (*ci_desc_done_fn)(struct ci_tx_queue *txq, uint16_t idx);
320 : :
321 : : static __rte_always_inline int
322 : : ci_tx_free_bufs_vec(struct ci_tx_queue *txq, ci_desc_done_fn desc_done, bool ctx_descs)
323 : : {
324 : : int nb_free = 0;
325 : : struct rte_mbuf *free[IETH_VPMD_TX_MAX_FREE_BUF];
326 : : struct rte_mbuf *m;
327 : :
328 : : /* check DD bits on threshold descriptor */
329 [ # # # # : 0 : if (!desc_done(txq, txq->tx_next_dd))
# # # # ]
330 : : return 0;
331 : :
332 : 0 : const uint32_t n = txq->tx_rs_thresh >> ctx_descs;
333 : :
334 : : /* first buffer to free from S/W ring is at index
335 : : * tx_next_dd - (tx_rs_thresh - 1)
336 : : */
337 : 0 : struct ci_tx_entry_vec *txep = txq->sw_ring_vec;
338 : 0 : txep += (txq->tx_next_dd >> ctx_descs) - (n - 1);
339 : :
340 : : /* is fast-free enabled? */
341 : : struct rte_mempool *mp =
342 : 0 : likely(txq->fast_free_mp != (void *)UINTPTR_MAX) ?
343 [ # # # # : 0 : txq->fast_free_mp :
# # # # ]
344 : 0 : (txq->fast_free_mp = txep[0].mbuf->pool);
345 : :
346 [ # # # # : 0 : if (mp != NULL && (n & 31) == 0) {
# # # # #
# # # # #
# # ]
347 : : static_assert(sizeof(*txep) == sizeof(struct rte_mbuf *),
348 : : "txep array is not similar to an array of rte_mbuf pointers");
349 : : rte_mbuf_raw_free_bulk(mp, (void *)txep, n);
350 : 0 : goto done;
351 : : }
352 : :
353 [ # # # # : 0 : m = rte_pktmbuf_prefree_seg(txep[0].mbuf);
# # # # ]
354 [ # # # # : 0 : if (likely(m)) {
# # # # ]
355 : 0 : free[0] = m;
356 : : nb_free = 1;
357 [ # # # # : 0 : for (uint32_t i = 1; i < n; i++) {
# # # # ]
358 [ # # # # : 0 : m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
# # # # ]
359 [ # # # # : 0 : if (likely(m)) {
# # # # ]
360 [ # # # # : 0 : if (likely(m->pool == free[0]->pool)) {
# # # # ]
361 : 0 : free[nb_free++] = m;
362 : : } else {
363 [ # # # # : 0 : rte_mbuf_raw_free_bulk(free[0]->pool, free, nb_free);
# # # # ]
364 : 0 : free[0] = m;
365 : : nb_free = 1;
366 : : }
367 : : }
368 : : }
369 [ # # # # : 0 : rte_mbuf_raw_free_bulk(free[0]->pool, free, nb_free);
# # # # ]
370 : : } else {
371 [ # # # # : 0 : for (uint32_t i = 1; i < n; i++) {
# # # # ]
372 [ # # # # : 0 : m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
# # # # ]
373 : : if (m)
374 [ # # # # : 0 : rte_mempool_put(m->pool, m);
# # # # ]
375 : : }
376 : : }
377 : :
378 : 0 : done:
379 : : /* buffers were freed, update counters */
380 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
381 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
382 [ # # # # : 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
# # # # ]
383 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
384 : :
385 [ # # ]: 0 : return txq->tx_rs_thresh;
386 : : }
387 : :
388 : : static inline void
389 : 0 : ci_txq_release_all_mbufs(struct ci_tx_queue *txq, bool use_ctx)
390 : : {
391 [ # # # # ]: 0 : if (unlikely(!txq || !txq->sw_ring))
392 : : return;
393 : :
394 [ # # ]: 0 : if (!txq->use_vec_entry) {
395 : : /* Free mbufs from (last_desc_cleaned + 1) to (tx_tail - 1). */
396 : 0 : const uint16_t start = (txq->last_desc_cleaned + 1) % txq->nb_tx_desc;
397 : : const uint16_t nb_desc = txq->nb_tx_desc;
398 : 0 : const uint16_t end = txq->tx_tail;
399 : :
400 : : uint16_t i = start;
401 [ # # ]: 0 : if (end < i) {
402 [ # # ]: 0 : for (; i < nb_desc; i++)
403 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL)
404 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
405 : : i = 0;
406 : : }
407 [ # # ]: 0 : for (; i < end; i++)
408 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL)
409 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
410 : 0 : memset(txq->sw_ring, 0, sizeof(txq->sw_ring[0]) * nb_desc);
411 : 0 : return;
412 : : }
413 : :
414 : : /**
415 : : * Vector and simple paths use sw_ring_vec (ci_tx_entry_vec).
416 : : * vPMD tx will not set sw_ring's mbuf to NULL after free,
417 : : * so determining buffers to free is a little more complex.
418 : : */
419 : 0 : const uint16_t start = (txq->tx_next_dd - txq->tx_rs_thresh + 1) >> use_ctx;
420 : 0 : const uint16_t nb_desc = txq->nb_tx_desc >> use_ctx;
421 : 0 : const uint16_t end = txq->tx_tail >> use_ctx;
422 : :
423 : : uint16_t i = start;
424 [ # # ]: 0 : if (end < i) {
425 [ # # ]: 0 : for (; i < nb_desc; i++)
426 : 0 : rte_pktmbuf_free_seg(txq->sw_ring_vec[i].mbuf);
427 : : i = 0;
428 : : }
429 [ # # ]: 0 : for (; i < end; i++)
430 : 0 : rte_pktmbuf_free_seg(txq->sw_ring_vec[i].mbuf);
431 : 0 : memset(txq->sw_ring_vec, 0, sizeof(txq->sw_ring_vec[0]) * nb_desc);
432 : : }
433 : :
434 : : /**
435 : : * Select the best matching Tx path based on features
436 : : *
437 : : * @param req_features
438 : : * The requested features for the Tx path
439 : : * @param infos
440 : : * Array of information about the available Tx paths
441 : : * @param num_paths
442 : : * Number of available paths in the infos array
443 : : * @param default_path
444 : : * Index of the default path to use if no suitable path is found
445 : : * @param force_ctx
446 : : * If true, only paths that support context descriptors may be selected.
447 : : * Use this for offloads that require a context descriptor but cannot be
448 : : * discovered purely from req_features->tx_offloads (e.g. a driver-specific
449 : : * devarg, or a runtime/hardware-negotiated tag placement).
450 : : *
451 : : * @return
452 : : * The packet burst function index that best matches the requested features,
453 : : * or default_path if no suitable path is found
454 : : */
455 : : static inline int
456 : 0 : ci_tx_path_select(const struct ci_tx_path_features *req_features,
457 : : const struct ci_tx_path_info *infos,
458 : : size_t num_paths,
459 : : int default_path,
460 : : bool force_ctx)
461 : : {
462 : : int idx = default_path;
463 : : const struct ci_tx_path_features *chosen_path_features = NULL;
464 : : bool chosen_supports_ctx = false;
465 : :
466 [ # # ]: 0 : for (unsigned int i = 0; i < num_paths; i++) {
467 : 0 : const struct ci_tx_path_features *path_features = &infos[i].features;
468 : :
469 : : /* Do not select a path with a NULL pkt_burst function. */
470 [ # # ]: 0 : if (infos[i].pkt_burst == NULL)
471 : 0 : continue;
472 : :
473 : : /* Do not select a disabled tx path. */
474 [ # # ]: 0 : if (path_features->disabled)
475 : 0 : continue;
476 : :
477 : : /* Do not use a simple tx path if not requested. */
478 [ # # # # ]: 0 : if (path_features->simple_tx && !req_features->simple_tx)
479 : 0 : continue;
480 : :
481 : : /* If a context descriptor is required, ensure the path supports it. */
482 [ # # # # ]: 0 : if (!infos[i].supports_ctx && force_ctx)
483 : 0 : continue;
484 : :
485 : : /* If requested, ensure the path supports single queue TX. */
486 [ # # ]: 0 : if (path_features->single_queue != req_features->single_queue)
487 : 0 : continue;
488 : :
489 : : /* Ensure the path supports the requested TX offloads. */
490 [ # # ]: 0 : if ((path_features->tx_offloads & req_features->tx_offloads) !=
491 : : req_features->tx_offloads)
492 : 0 : continue;
493 : :
494 : : /* Ensure the path's SIMD width is compatible with the requested width. */
495 [ # # ]: 0 : if (path_features->simd_width > req_features->simd_width)
496 : 0 : continue;
497 : :
498 : : /* Do not select the path if it is less suitable than the chosen path. */
499 [ # # ]: 0 : if (chosen_path_features != NULL) {
500 : : /* Do not select paths with lower SIMD width than the chosen path. */
501 [ # # ]: 0 : if (path_features->simd_width < chosen_path_features->simd_width)
502 : 0 : continue;
503 : : /* The following tie-breaks only matter when SIMD widths are tied;
504 : : * a strictly wider path is always preferred regardless of offload
505 : : * count or ctx-descriptor use.
506 : : */
507 [ # # ]: 0 : if (path_features->simd_width == chosen_path_features->simd_width) {
508 : : /* Do not select paths with more offloads enabled than the
509 : : * chosen path.
510 : : */
511 : 0 : if (rte_popcount32(path_features->tx_offloads) >
512 [ # # ]: 0 : rte_popcount32(chosen_path_features->tx_offloads))
513 : 0 : continue;
514 : :
515 : : /* Don't use a context descriptor unless necessary */
516 [ # # # # ]: 0 : if (infos[i].supports_ctx && !chosen_supports_ctx)
517 : 0 : continue;
518 : : }
519 : : }
520 : :
521 : : /* Finally, select the path since it has met all the requirements. */
522 : 0 : idx = i;
523 : 0 : chosen_path_features = &infos[idx].features;
524 : 0 : chosen_supports_ctx = infos[idx].supports_ctx;
525 : : }
526 : :
527 : 0 : return idx;
528 : : }
529 : :
530 : : /* include the scalar functions at the end, so they can use the common definitions.
531 : : * This is done so drivers can use all functions just by including tx.h
532 : : */
533 : : #include "tx_scalar.h"
534 : :
535 : : #endif /* _COMMON_INTEL_TX_H_ */
|