1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015-2019 Mellanox Technologies, Ltd
11 #include <rte_mempool.h>
12 #include <rte_prefetch.h>
13 #include <rte_common.h>
14 #include <rte_branch_prediction.h>
15 #include <rte_ether.h>
16 #include <rte_cycles.h>
19 #include <mlx5_glue.h>
20 #include <mlx5_devx_cmds.h>
22 #include <mlx5_common.h>
24 #include "mlx5_defs.h"
27 #include "mlx5_utils.h"
28 #include "mlx5_rxtx.h"
29 #include "mlx5_autoconf.h"
31 /* TX burst subroutines return codes. */
32 enum mlx5_txcmp_code {
33 MLX5_TXCMP_CODE_EXIT = 0,
34 MLX5_TXCMP_CODE_ERROR,
35 MLX5_TXCMP_CODE_SINGLE,
36 MLX5_TXCMP_CODE_MULTI,
42 * These defines are used to configure Tx burst routine option set
43 * supported at compile time. The not specified options are optimized out
44 * out due to if conditions can be explicitly calculated at compile time.
45 * The offloads with bigger runtime check (require more CPU cycles to
46 * skip) overhead should have the bigger index - this is needed to
47 * select the better matching routine function if no exact match and
48 * some offloads are not actually requested.
50 #define MLX5_TXOFF_CONFIG_MULTI (1u << 0) /* Multi-segment packets.*/
51 #define MLX5_TXOFF_CONFIG_TSO (1u << 1) /* TCP send offload supported.*/
52 #define MLX5_TXOFF_CONFIG_SWP (1u << 2) /* Tunnels/SW Parser offloads.*/
53 #define MLX5_TXOFF_CONFIG_CSUM (1u << 3) /* Check Sums offloaded. */
54 #define MLX5_TXOFF_CONFIG_INLINE (1u << 4) /* Data inlining supported. */
55 #define MLX5_TXOFF_CONFIG_VLAN (1u << 5) /* VLAN insertion supported.*/
56 #define MLX5_TXOFF_CONFIG_METADATA (1u << 6) /* Flow metadata. */
57 #define MLX5_TXOFF_CONFIG_EMPW (1u << 8) /* Enhanced MPW supported.*/
58 #define MLX5_TXOFF_CONFIG_MPW (1u << 9) /* Legacy MPW supported.*/
59 #define MLX5_TXOFF_CONFIG_TXPP (1u << 10) /* Scheduling on timestamp.*/
61 /* The most common offloads groups. */
62 #define MLX5_TXOFF_CONFIG_NONE 0
63 #define MLX5_TXOFF_CONFIG_FULL (MLX5_TXOFF_CONFIG_MULTI | \
64 MLX5_TXOFF_CONFIG_TSO | \
65 MLX5_TXOFF_CONFIG_SWP | \
66 MLX5_TXOFF_CONFIG_CSUM | \
67 MLX5_TXOFF_CONFIG_INLINE | \
68 MLX5_TXOFF_CONFIG_VLAN | \
69 MLX5_TXOFF_CONFIG_METADATA)
71 #define MLX5_TXOFF_CONFIG(mask) (olx & MLX5_TXOFF_CONFIG_##mask)
73 #define MLX5_TXOFF_DECL(func, olx) \
74 static uint16_t mlx5_tx_burst_##func(void *txq, \
75 struct rte_mbuf **pkts, \
78 return mlx5_tx_burst_tmpl((struct mlx5_txq_data *)txq, \
79 pkts, pkts_n, (olx)); \
82 #define MLX5_TXOFF_INFO(func, olx) {mlx5_tx_burst_##func, olx},
84 static __rte_always_inline uint32_t
85 rxq_cq_to_pkt_type(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe);
87 static __rte_always_inline int
88 mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
89 uint16_t cqe_cnt, volatile struct mlx5_mini_cqe8 **mcqe);
91 static __rte_always_inline uint32_t
92 rxq_cq_to_ol_flags(volatile struct mlx5_cqe *cqe);
94 static __rte_always_inline void
95 rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
96 volatile struct mlx5_cqe *cqe, uint32_t rss_hash_res);
98 static __rte_always_inline void
99 mprq_buf_replace(struct mlx5_rxq_data *rxq, uint16_t rq_idx,
100 const unsigned int strd_n);
103 mlx5_queue_state_modify(struct rte_eth_dev *dev,
104 struct mlx5_mp_arg_queue_state_modify *sm);
107 mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_restrict tcp,
108 volatile struct mlx5_cqe *__rte_restrict cqe,
112 mlx5_lro_update_hdr(uint8_t *__rte_restrict padd,
113 volatile struct mlx5_cqe *__rte_restrict cqe,
116 uint32_t mlx5_ptype_table[] __rte_cache_aligned = {
117 [0xff] = RTE_PTYPE_ALL_MASK, /* Last entry for errored packet. */
120 uint8_t mlx5_cksum_table[1 << 10] __rte_cache_aligned;
121 uint8_t mlx5_swp_types_table[1 << 10] __rte_cache_aligned;
123 uint64_t rte_net_mlx5_dynf_inline_mask;
124 #define PKT_TX_DYNF_NOINLINE rte_net_mlx5_dynf_inline_mask
127 * Build a table to translate Rx completion flags to packet type.
129 * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
132 mlx5_set_ptype_table(void)
135 uint32_t (*p)[RTE_DIM(mlx5_ptype_table)] = &mlx5_ptype_table;
137 /* Last entry must not be overwritten, reserved for errored packet. */
138 for (i = 0; i < RTE_DIM(mlx5_ptype_table) - 1; ++i)
139 (*p)[i] = RTE_PTYPE_UNKNOWN;
141 * The index to the array should have:
142 * bit[1:0] = l3_hdr_type
143 * bit[4:2] = l4_hdr_type
146 * bit[7] = outer_l3_type
149 (*p)[0x00] = RTE_PTYPE_L2_ETHER;
151 (*p)[0x01] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
152 RTE_PTYPE_L4_NONFRAG;
153 (*p)[0x02] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
154 RTE_PTYPE_L4_NONFRAG;
156 (*p)[0x21] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
158 (*p)[0x22] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
161 (*p)[0x05] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
163 (*p)[0x06] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
165 (*p)[0x0d] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
167 (*p)[0x0e] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
169 (*p)[0x11] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
171 (*p)[0x12] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
174 (*p)[0x09] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
176 (*p)[0x0a] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
178 /* Repeat with outer_l3_type being set. Just in case. */
179 (*p)[0x81] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
180 RTE_PTYPE_L4_NONFRAG;
181 (*p)[0x82] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
182 RTE_PTYPE_L4_NONFRAG;
183 (*p)[0xa1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
185 (*p)[0xa2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
187 (*p)[0x85] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
189 (*p)[0x86] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
191 (*p)[0x8d] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
193 (*p)[0x8e] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
195 (*p)[0x91] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
197 (*p)[0x92] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
199 (*p)[0x89] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
201 (*p)[0x8a] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
204 (*p)[0x40] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
205 (*p)[0x41] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
206 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
207 RTE_PTYPE_INNER_L4_NONFRAG;
208 (*p)[0x42] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
209 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
210 RTE_PTYPE_INNER_L4_NONFRAG;
211 (*p)[0xc0] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
212 (*p)[0xc1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
213 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
214 RTE_PTYPE_INNER_L4_NONFRAG;
215 (*p)[0xc2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
216 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
217 RTE_PTYPE_INNER_L4_NONFRAG;
218 /* Tunneled - Fragmented */
219 (*p)[0x61] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
220 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
221 RTE_PTYPE_INNER_L4_FRAG;
222 (*p)[0x62] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
223 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
224 RTE_PTYPE_INNER_L4_FRAG;
225 (*p)[0xe1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
226 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
227 RTE_PTYPE_INNER_L4_FRAG;
228 (*p)[0xe2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
229 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
230 RTE_PTYPE_INNER_L4_FRAG;
232 (*p)[0x45] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
233 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
234 RTE_PTYPE_INNER_L4_TCP;
235 (*p)[0x46] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
236 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
237 RTE_PTYPE_INNER_L4_TCP;
238 (*p)[0x4d] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
239 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
240 RTE_PTYPE_INNER_L4_TCP;
241 (*p)[0x4e] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
242 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
243 RTE_PTYPE_INNER_L4_TCP;
244 (*p)[0x51] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
245 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
246 RTE_PTYPE_INNER_L4_TCP;
247 (*p)[0x52] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
248 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
249 RTE_PTYPE_INNER_L4_TCP;
250 (*p)[0xc5] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
251 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
252 RTE_PTYPE_INNER_L4_TCP;
253 (*p)[0xc6] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
254 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
255 RTE_PTYPE_INNER_L4_TCP;
256 (*p)[0xcd] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
257 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
258 RTE_PTYPE_INNER_L4_TCP;
259 (*p)[0xce] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
260 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
261 RTE_PTYPE_INNER_L4_TCP;
262 (*p)[0xd1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
263 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
264 RTE_PTYPE_INNER_L4_TCP;
265 (*p)[0xd2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
266 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
267 RTE_PTYPE_INNER_L4_TCP;
269 (*p)[0x49] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
270 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
271 RTE_PTYPE_INNER_L4_UDP;
272 (*p)[0x4a] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
273 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
274 RTE_PTYPE_INNER_L4_UDP;
275 (*p)[0xc9] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
276 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
277 RTE_PTYPE_INNER_L4_UDP;
278 (*p)[0xca] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
279 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
280 RTE_PTYPE_INNER_L4_UDP;
284 * Build a table to translate packet to checksum type of Verbs.
287 mlx5_set_cksum_table(void)
293 * The index should have:
294 * bit[0] = PKT_TX_TCP_SEG
295 * bit[2:3] = PKT_TX_UDP_CKSUM, PKT_TX_TCP_CKSUM
296 * bit[4] = PKT_TX_IP_CKSUM
297 * bit[8] = PKT_TX_OUTER_IP_CKSUM
300 for (i = 0; i < RTE_DIM(mlx5_cksum_table); ++i) {
303 /* Tunneled packet. */
304 if (i & (1 << 8)) /* Outer IP. */
305 v |= MLX5_ETH_WQE_L3_CSUM;
306 if (i & (1 << 4)) /* Inner IP. */
307 v |= MLX5_ETH_WQE_L3_INNER_CSUM;
308 if (i & (3 << 2 | 1 << 0)) /* L4 or TSO. */
309 v |= MLX5_ETH_WQE_L4_INNER_CSUM;
312 if (i & (1 << 4)) /* IP. */
313 v |= MLX5_ETH_WQE_L3_CSUM;
314 if (i & (3 << 2 | 1 << 0)) /* L4 or TSO. */
315 v |= MLX5_ETH_WQE_L4_CSUM;
317 mlx5_cksum_table[i] = v;
322 * Build a table to translate packet type of mbuf to SWP type of Verbs.
325 mlx5_set_swp_types_table(void)
331 * The index should have:
332 * bit[0:1] = PKT_TX_L4_MASK
333 * bit[4] = PKT_TX_IPV6
334 * bit[8] = PKT_TX_OUTER_IPV6
335 * bit[9] = PKT_TX_OUTER_UDP
337 for (i = 0; i < RTE_DIM(mlx5_swp_types_table); ++i) {
340 v |= MLX5_ETH_WQE_L3_OUTER_IPV6;
342 v |= MLX5_ETH_WQE_L4_OUTER_UDP;
344 v |= MLX5_ETH_WQE_L3_INNER_IPV6;
345 if ((i & 3) == (PKT_TX_UDP_CKSUM >> 52))
346 v |= MLX5_ETH_WQE_L4_INNER_UDP;
347 mlx5_swp_types_table[i] = v;
352 * Set Software Parser flags and offsets in Ethernet Segment of WQE.
353 * Flags must be preliminary initialized to zero.
356 * Pointer to burst routine local context.
358 * Pointer to store Software Parser flags
360 * Configured Tx offloads mask. It is fully defined at
361 * compile time and may be used for optimization.
364 * Software Parser offsets packed in dword.
365 * Software Parser flags are set by pointer.
367 static __rte_always_inline uint32_t
368 txq_mbuf_to_swp(struct mlx5_txq_local *__rte_restrict loc,
373 unsigned int idx, off;
376 if (!MLX5_TXOFF_CONFIG(SWP))
378 ol = loc->mbuf->ol_flags;
379 tunnel = ol & PKT_TX_TUNNEL_MASK;
381 * Check whether Software Parser is required.
382 * Only customized tunnels may ask for.
384 if (likely(tunnel != PKT_TX_TUNNEL_UDP && tunnel != PKT_TX_TUNNEL_IP))
387 * The index should have:
388 * bit[0:1] = PKT_TX_L4_MASK
389 * bit[4] = PKT_TX_IPV6
390 * bit[8] = PKT_TX_OUTER_IPV6
391 * bit[9] = PKT_TX_OUTER_UDP
393 idx = (ol & (PKT_TX_L4_MASK | PKT_TX_IPV6 | PKT_TX_OUTER_IPV6)) >> 52;
394 idx |= (tunnel == PKT_TX_TUNNEL_UDP) ? (1 << 9) : 0;
395 *swp_flags = mlx5_swp_types_table[idx];
397 * Set offsets for SW parser. Since ConnectX-5, SW parser just
398 * complements HW parser. SW parser starts to engage only if HW parser
399 * can't reach a header. For the older devices, HW parser will not kick
400 * in if any of SWP offsets is set. Therefore, all of the L3 offsets
401 * should be set regardless of HW offload.
403 off = loc->mbuf->outer_l2_len;
404 if (MLX5_TXOFF_CONFIG(VLAN) && ol & PKT_TX_VLAN_PKT)
405 off += sizeof(struct rte_vlan_hdr);
406 set = (off >> 1) << 8; /* Outer L3 offset. */
407 off += loc->mbuf->outer_l3_len;
408 if (tunnel == PKT_TX_TUNNEL_UDP)
409 set |= off >> 1; /* Outer L4 offset. */
410 if (ol & (PKT_TX_IPV4 | PKT_TX_IPV6)) { /* Inner IP. */
411 const uint64_t csum = ol & PKT_TX_L4_MASK;
412 off += loc->mbuf->l2_len;
413 set |= (off >> 1) << 24; /* Inner L3 offset. */
414 if (csum == PKT_TX_TCP_CKSUM ||
415 csum == PKT_TX_UDP_CKSUM ||
416 (MLX5_TXOFF_CONFIG(TSO) && ol & PKT_TX_TCP_SEG)) {
417 off += loc->mbuf->l3_len;
418 set |= (off >> 1) << 16; /* Inner L4 offset. */
421 set = rte_cpu_to_le_32(set);
426 * Convert the Checksum offloads to Verbs.
429 * Pointer to the mbuf.
432 * Converted checksum flags.
434 static __rte_always_inline uint8_t
435 txq_ol_cksum_to_cs(struct rte_mbuf *buf)
438 uint8_t is_tunnel = !!(buf->ol_flags & PKT_TX_TUNNEL_MASK);
439 const uint64_t ol_flags_mask = PKT_TX_TCP_SEG | PKT_TX_L4_MASK |
440 PKT_TX_IP_CKSUM | PKT_TX_OUTER_IP_CKSUM;
443 * The index should have:
444 * bit[0] = PKT_TX_TCP_SEG
445 * bit[2:3] = PKT_TX_UDP_CKSUM, PKT_TX_TCP_CKSUM
446 * bit[4] = PKT_TX_IP_CKSUM
447 * bit[8] = PKT_TX_OUTER_IP_CKSUM
450 idx = ((buf->ol_flags & ol_flags_mask) >> 50) | (!!is_tunnel << 9);
451 return mlx5_cksum_table[idx];
455 * Internal function to compute the number of used descriptors in an RX queue
461 * The number of used rx descriptor.
464 rx_queue_count(struct mlx5_rxq_data *rxq)
466 struct rxq_zip *zip = &rxq->zip;
467 volatile struct mlx5_cqe *cqe;
468 const unsigned int cqe_n = (1 << rxq->cqe_n);
469 const unsigned int cqe_cnt = cqe_n - 1;
473 /* if we are processing a compressed cqe */
475 used = zip->cqe_cnt - zip->ca;
481 cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
482 while (check_cqe(cqe, cqe_n, cq_ci) != MLX5_CQE_STATUS_HW_OWN) {
486 op_own = cqe->op_own;
487 if (MLX5_CQE_FORMAT(op_own) == MLX5_COMPRESSED)
488 n = rte_be_to_cpu_32(cqe->byte_cnt);
493 cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
495 used = RTE_MIN(used, (1U << rxq->elts_n) - 1);
500 * DPDK callback to check the status of a rx descriptor.
505 * The index of the descriptor in the ring.
508 * The status of the tx descriptor.
511 mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset)
513 struct mlx5_rxq_data *rxq = rx_queue;
514 struct mlx5_rxq_ctrl *rxq_ctrl =
515 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
516 struct rte_eth_dev *dev = ETH_DEV(rxq_ctrl->priv);
518 if (dev->rx_pkt_burst != mlx5_rx_burst) {
522 if (offset >= (1 << rxq->elts_n)) {
526 if (offset < rx_queue_count(rxq))
527 return RTE_ETH_RX_DESC_DONE;
528 return RTE_ETH_RX_DESC_AVAIL;
532 * DPDK callback to get the RX queue information
535 * Pointer to the device structure.
538 * Rx queue identificator.
541 * Pointer to the RX queue information structure.
548 mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
549 struct rte_eth_rxq_info *qinfo)
551 struct mlx5_priv *priv = dev->data->dev_private;
552 struct mlx5_rxq_data *rxq = (*priv->rxqs)[rx_queue_id];
553 struct mlx5_rxq_ctrl *rxq_ctrl =
554 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
558 qinfo->mp = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
559 rxq->mprq_mp : rxq->mp;
560 qinfo->conf.rx_thresh.pthresh = 0;
561 qinfo->conf.rx_thresh.hthresh = 0;
562 qinfo->conf.rx_thresh.wthresh = 0;
563 qinfo->conf.rx_free_thresh = rxq->rq_repl_thresh;
564 qinfo->conf.rx_drop_en = 1;
565 qinfo->conf.rx_deferred_start = rxq_ctrl ? 0 : 1;
566 qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
567 qinfo->scattered_rx = dev->data->scattered_rx;
568 qinfo->nb_desc = 1 << rxq->elts_n;
572 * DPDK callback to get the RX packet burst mode information
575 * Pointer to the device structure.
578 * Rx queue identificatior.
581 * Pointer to the burts mode information.
584 * 0 as success, -EINVAL as failure.
588 mlx5_rx_burst_mode_get(struct rte_eth_dev *dev,
589 uint16_t rx_queue_id __rte_unused,
590 struct rte_eth_burst_mode *mode)
592 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
594 if (pkt_burst == mlx5_rx_burst) {
595 snprintf(mode->info, sizeof(mode->info), "%s", "Scalar");
596 } else if (pkt_burst == mlx5_rx_burst_mprq) {
597 snprintf(mode->info, sizeof(mode->info), "%s", "Multi-Packet RQ");
598 } else if (pkt_burst == mlx5_rx_burst_vec) {
599 #if defined RTE_ARCH_X86_64
600 snprintf(mode->info, sizeof(mode->info), "%s", "Vector SSE");
601 #elif defined RTE_ARCH_ARM64
602 snprintf(mode->info, sizeof(mode->info), "%s", "Vector Neon");
603 #elif defined RTE_ARCH_PPC_64
604 snprintf(mode->info, sizeof(mode->info), "%s", "Vector AltiVec");
615 * DPDK callback to get the number of used descriptors in a RX queue
618 * Pointer to the device structure.
624 * The number of used rx descriptor.
625 * -EINVAL if the queue is invalid
628 mlx5_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
630 struct mlx5_priv *priv = dev->data->dev_private;
631 struct mlx5_rxq_data *rxq;
633 if (dev->rx_pkt_burst != mlx5_rx_burst) {
637 rxq = (*priv->rxqs)[rx_queue_id];
642 return rx_queue_count(rxq);
645 #define MLX5_SYSTEM_LOG_DIR "/var/log"
647 * Dump debug information to log file.
652 * If not NULL this string is printed as a header to the output
653 * and the output will be in hexadecimal view.
655 * This is the buffer address to print out.
657 * The number of bytes to dump out.
660 mlx5_dump_debug_information(const char *fname, const char *hex_title,
661 const void *buf, unsigned int hex_len)
665 MKSTR(path, "%s/%s", MLX5_SYSTEM_LOG_DIR, fname);
666 fd = fopen(path, "a+");
668 DRV_LOG(WARNING, "cannot open %s for debug dump", path);
669 MKSTR(path2, "./%s", fname);
670 fd = fopen(path2, "a+");
672 DRV_LOG(ERR, "cannot open %s for debug dump", path2);
675 DRV_LOG(INFO, "New debug dump in file %s", path2);
677 DRV_LOG(INFO, "New debug dump in file %s", path);
680 rte_hexdump(fd, hex_title, buf, hex_len);
682 fprintf(fd, "%s", (const char *)buf);
683 fprintf(fd, "\n\n\n");
688 * Move QP from error state to running state and initialize indexes.
691 * Pointer to TX queue control structure.
694 * 0 on success, else -1.
697 tx_recover_qp(struct mlx5_txq_ctrl *txq_ctrl)
699 struct mlx5_mp_arg_queue_state_modify sm = {
701 .queue_id = txq_ctrl->txq.idx,
704 if (mlx5_queue_state_modify(ETH_DEV(txq_ctrl->priv), &sm))
706 txq_ctrl->txq.wqe_ci = 0;
707 txq_ctrl->txq.wqe_pi = 0;
708 txq_ctrl->txq.elts_comp = 0;
712 /* Return 1 if the error CQE is signed otherwise, sign it and return 0. */
714 check_err_cqe_seen(volatile struct mlx5_err_cqe *err_cqe)
716 static const uint8_t magic[] = "seen";
720 for (i = 0; i < sizeof(magic); ++i)
721 if (!ret || err_cqe->rsvd1[i] != magic[i]) {
723 err_cqe->rsvd1[i] = magic[i];
732 * Pointer to TX queue structure.
734 * Pointer to the error CQE.
737 * Negative value if queue recovery failed, otherwise
738 * the error completion entry is handled successfully.
741 mlx5_tx_error_cqe_handle(struct mlx5_txq_data *__rte_restrict txq,
742 volatile struct mlx5_err_cqe *err_cqe)
744 if (err_cqe->syndrome != MLX5_CQE_SYNDROME_WR_FLUSH_ERR) {
745 const uint16_t wqe_m = ((1 << txq->wqe_n) - 1);
746 struct mlx5_txq_ctrl *txq_ctrl =
747 container_of(txq, struct mlx5_txq_ctrl, txq);
748 uint16_t new_wqe_pi = rte_be_to_cpu_16(err_cqe->wqe_counter);
749 int seen = check_err_cqe_seen(err_cqe);
751 if (!seen && txq_ctrl->dump_file_n <
752 txq_ctrl->priv->config.max_dump_files_num) {
753 MKSTR(err_str, "Unexpected CQE error syndrome "
754 "0x%02x CQN = %u SQN = %u wqe_counter = %u "
755 "wq_ci = %u cq_ci = %u", err_cqe->syndrome,
756 txq->cqe_s, txq->qp_num_8s >> 8,
757 rte_be_to_cpu_16(err_cqe->wqe_counter),
758 txq->wqe_ci, txq->cq_ci);
759 MKSTR(name, "dpdk_mlx5_port_%u_txq_%u_index_%u_%u",
760 PORT_ID(txq_ctrl->priv), txq->idx,
761 txq_ctrl->dump_file_n, (uint32_t)rte_rdtsc());
762 mlx5_dump_debug_information(name, NULL, err_str, 0);
763 mlx5_dump_debug_information(name, "MLX5 Error CQ:",
764 (const void *)((uintptr_t)
768 mlx5_dump_debug_information(name, "MLX5 Error SQ:",
769 (const void *)((uintptr_t)
773 txq_ctrl->dump_file_n++;
777 * Count errors in WQEs units.
778 * Later it can be improved to count error packets,
779 * for example, by SQ parsing to find how much packets
780 * should be counted for each WQE.
782 txq->stats.oerrors += ((txq->wqe_ci & wqe_m) -
784 if (tx_recover_qp(txq_ctrl)) {
785 /* Recovering failed - retry later on the same WQE. */
788 /* Release all the remaining buffers. */
789 txq_free_elts(txq_ctrl);
795 * Translate RX completion flags to packet type.
798 * Pointer to RX queue structure.
802 * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
805 * Packet type for struct rte_mbuf.
807 static inline uint32_t
808 rxq_cq_to_pkt_type(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe)
811 uint8_t pinfo = cqe->pkt_info;
812 uint16_t ptype = cqe->hdr_type_etc;
815 * The index to the array should have:
816 * bit[1:0] = l3_hdr_type
817 * bit[4:2] = l4_hdr_type
820 * bit[7] = outer_l3_type
822 idx = ((pinfo & 0x3) << 6) | ((ptype & 0xfc00) >> 10);
823 return mlx5_ptype_table[idx] | rxq->tunnel * !!(idx & (1 << 6));
827 * Initialize Rx WQ and indexes.
830 * Pointer to RX queue structure.
833 mlx5_rxq_initialize(struct mlx5_rxq_data *rxq)
835 const unsigned int wqe_n = 1 << rxq->elts_n;
838 for (i = 0; (i != wqe_n); ++i) {
839 volatile struct mlx5_wqe_data_seg *scat;
843 if (mlx5_rxq_mprq_enabled(rxq)) {
844 struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[i];
846 scat = &((volatile struct mlx5_wqe_mprq *)
848 addr = (uintptr_t)mlx5_mprq_buf_addr(buf,
849 1 << rxq->strd_num_n);
850 byte_count = (1 << rxq->strd_sz_n) *
851 (1 << rxq->strd_num_n);
853 struct rte_mbuf *buf = (*rxq->elts)[i];
855 scat = &((volatile struct mlx5_wqe_data_seg *)
857 addr = rte_pktmbuf_mtod(buf, uintptr_t);
858 byte_count = DATA_LEN(buf);
860 /* scat->addr must be able to store a pointer. */
861 MLX5_ASSERT(sizeof(scat->addr) >= sizeof(uintptr_t));
862 *scat = (struct mlx5_wqe_data_seg){
863 .addr = rte_cpu_to_be_64(addr),
864 .byte_count = rte_cpu_to_be_32(byte_count),
865 .lkey = mlx5_rx_addr2mr(rxq, addr),
868 rxq->consumed_strd = 0;
869 rxq->decompressed = 0;
871 rxq->zip = (struct rxq_zip){
874 /* Update doorbell counter. */
875 rxq->rq_ci = wqe_n >> rxq->sges_n;
877 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
881 * Modify a Verbs/DevX queue state.
882 * This must be called from the primary process.
885 * Pointer to Ethernet device.
887 * State modify request parameters.
890 * 0 in case of success else non-zero value and rte_errno is set.
893 mlx5_queue_state_modify_primary(struct rte_eth_dev *dev,
894 const struct mlx5_mp_arg_queue_state_modify *sm)
897 struct mlx5_priv *priv = dev->data->dev_private;
900 struct mlx5_rxq_data *rxq = (*priv->rxqs)[sm->queue_id];
901 struct mlx5_rxq_ctrl *rxq_ctrl =
902 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
904 if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV) {
905 struct ibv_wq_attr mod = {
906 .attr_mask = IBV_WQ_ATTR_STATE,
907 .wq_state = sm->state,
910 ret = mlx5_glue->modify_wq(rxq_ctrl->obj->wq, &mod);
911 } else { /* rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ. */
912 struct mlx5_devx_modify_rq_attr rq_attr;
914 memset(&rq_attr, 0, sizeof(rq_attr));
915 if (sm->state == IBV_WQS_RESET) {
916 rq_attr.rq_state = MLX5_RQC_STATE_ERR;
917 rq_attr.state = MLX5_RQC_STATE_RST;
918 } else if (sm->state == IBV_WQS_RDY) {
919 rq_attr.rq_state = MLX5_RQC_STATE_RST;
920 rq_attr.state = MLX5_RQC_STATE_RDY;
921 } else if (sm->state == IBV_WQS_ERR) {
922 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
923 rq_attr.state = MLX5_RQC_STATE_ERR;
925 ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq,
929 DRV_LOG(ERR, "Cannot change Rx WQ state to %u - %s",
930 sm->state, strerror(errno));
935 struct mlx5_txq_data *txq = (*priv->txqs)[sm->queue_id];
936 struct mlx5_txq_ctrl *txq_ctrl =
937 container_of(txq, struct mlx5_txq_ctrl, txq);
939 if (txq_ctrl->obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_SQ) {
940 struct mlx5_devx_modify_sq_attr msq_attr = { 0 };
942 /* Change queue state to reset. */
943 msq_attr.sq_state = MLX5_SQC_STATE_ERR;
944 msq_attr.state = MLX5_SQC_STATE_RST;
945 ret = mlx5_devx_cmd_modify_sq(txq_ctrl->obj->sq_devx,
948 DRV_LOG(ERR, "Cannot change the "
949 "Tx QP state to RESET %s",
954 /* Change queue state to ready. */
955 msq_attr.sq_state = MLX5_SQC_STATE_RST;
956 msq_attr.state = MLX5_SQC_STATE_RDY;
957 ret = mlx5_devx_cmd_modify_sq(txq_ctrl->obj->sq_devx,
960 DRV_LOG(ERR, "Cannot change the "
961 "Tx QP state to READY %s",
967 struct ibv_qp_attr mod = {
968 .qp_state = IBV_QPS_RESET,
969 .port_num = (uint8_t)priv->dev_port,
971 struct ibv_qp *qp = txq_ctrl->obj->qp;
974 (txq_ctrl->obj->type == MLX5_TXQ_OBJ_TYPE_IBV);
976 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
978 DRV_LOG(ERR, "Cannot change the "
979 "Tx QP state to RESET %s",
984 mod.qp_state = IBV_QPS_INIT;
985 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
987 DRV_LOG(ERR, "Cannot change the "
988 "Tx QP state to INIT %s",
993 mod.qp_state = IBV_QPS_RTR;
994 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
996 DRV_LOG(ERR, "Cannot change the "
997 "Tx QP state to RTR %s",
1002 mod.qp_state = IBV_QPS_RTS;
1003 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
1005 DRV_LOG(ERR, "Cannot change the "
1006 "Tx QP state to RTS %s",
1017 * Modify a Verbs queue state.
1020 * Pointer to Ethernet device.
1022 * State modify request parameters.
1025 * 0 in case of success else non-zero value.
1028 mlx5_queue_state_modify(struct rte_eth_dev *dev,
1029 struct mlx5_mp_arg_queue_state_modify *sm)
1031 struct mlx5_priv *priv = dev->data->dev_private;
1034 switch (rte_eal_process_type()) {
1035 case RTE_PROC_PRIMARY:
1036 ret = mlx5_queue_state_modify_primary(dev, sm);
1038 case RTE_PROC_SECONDARY:
1039 ret = mlx5_mp_req_queue_state_modify(&priv->mp_id, sm);
1048 * Handle a Rx error.
1049 * The function inserts the RQ state to reset when the first error CQE is
1050 * shown, then drains the CQ by the caller function loop. When the CQ is empty,
1051 * it moves the RQ state to ready and initializes the RQ.
1052 * Next CQE identification and error counting are in the caller responsibility.
1055 * Pointer to RX queue structure.
1057 * 1 when called from vectorized Rx burst, need to prepare mbufs for the RQ.
1058 * 0 when called from non-vectorized Rx burst.
1061 * -1 in case of recovery error, otherwise the CQE status.
1064 mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec)
1066 const uint16_t cqe_n = 1 << rxq->cqe_n;
1067 const uint16_t cqe_mask = cqe_n - 1;
1068 const unsigned int wqe_n = 1 << rxq->elts_n;
1069 struct mlx5_rxq_ctrl *rxq_ctrl =
1070 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
1072 volatile struct mlx5_cqe *cqe;
1073 volatile struct mlx5_err_cqe *err_cqe;
1075 .cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask],
1077 struct mlx5_mp_arg_queue_state_modify sm;
1080 switch (rxq->err_state) {
1081 case MLX5_RXQ_ERR_STATE_NO_ERROR:
1082 rxq->err_state = MLX5_RXQ_ERR_STATE_NEED_RESET;
1084 case MLX5_RXQ_ERR_STATE_NEED_RESET:
1086 sm.queue_id = rxq->idx;
1087 sm.state = IBV_WQS_RESET;
1088 if (mlx5_queue_state_modify(ETH_DEV(rxq_ctrl->priv), &sm))
1090 if (rxq_ctrl->dump_file_n <
1091 rxq_ctrl->priv->config.max_dump_files_num) {
1092 MKSTR(err_str, "Unexpected CQE error syndrome "
1093 "0x%02x CQN = %u RQN = %u wqe_counter = %u"
1094 " rq_ci = %u cq_ci = %u", u.err_cqe->syndrome,
1095 rxq->cqn, rxq_ctrl->wqn,
1096 rte_be_to_cpu_16(u.err_cqe->wqe_counter),
1097 rxq->rq_ci << rxq->sges_n, rxq->cq_ci);
1098 MKSTR(name, "dpdk_mlx5_port_%u_rxq_%u_%u",
1099 rxq->port_id, rxq->idx, (uint32_t)rte_rdtsc());
1100 mlx5_dump_debug_information(name, NULL, err_str, 0);
1101 mlx5_dump_debug_information(name, "MLX5 Error CQ:",
1102 (const void *)((uintptr_t)
1104 sizeof(*u.cqe) * cqe_n);
1105 mlx5_dump_debug_information(name, "MLX5 Error RQ:",
1106 (const void *)((uintptr_t)
1109 rxq_ctrl->dump_file_n++;
1111 rxq->err_state = MLX5_RXQ_ERR_STATE_NEED_READY;
1113 case MLX5_RXQ_ERR_STATE_NEED_READY:
1114 ret = check_cqe(u.cqe, cqe_n, rxq->cq_ci);
1115 if (ret == MLX5_CQE_STATUS_HW_OWN) {
1117 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1120 * The RQ consumer index must be zeroed while moving
1121 * from RESET state to RDY state.
1123 *rxq->rq_db = rte_cpu_to_be_32(0);
1126 sm.queue_id = rxq->idx;
1127 sm.state = IBV_WQS_RDY;
1128 if (mlx5_queue_state_modify(ETH_DEV(rxq_ctrl->priv),
1132 const uint16_t q_mask = wqe_n - 1;
1134 struct rte_mbuf **elt;
1136 unsigned int n = wqe_n - (rxq->rq_ci -
1139 for (i = 0; i < (int)n; ++i) {
1140 elt_idx = (rxq->rq_ci + i) & q_mask;
1141 elt = &(*rxq->elts)[elt_idx];
1142 *elt = rte_mbuf_raw_alloc(rxq->mp);
1144 for (i--; i >= 0; --i) {
1145 elt_idx = (rxq->rq_ci +
1149 rte_pktmbuf_free_seg
1155 for (i = 0; i < (int)wqe_n; ++i) {
1156 elt = &(*rxq->elts)[i];
1158 (uint16_t)((*elt)->buf_len -
1159 rte_pktmbuf_headroom(*elt));
1161 /* Padding with a fake mbuf for vec Rx. */
1162 for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
1163 (*rxq->elts)[wqe_n + i] =
1166 mlx5_rxq_initialize(rxq);
1167 rxq->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
1176 * Get size of the next packet for a given CQE. For compressed CQEs, the
1177 * consumer index is updated only once all packets of the current one have
1181 * Pointer to RX queue.
1185 * Store pointer to mini-CQE if compressed. Otherwise, the pointer is not
1189 * 0 in case of empty CQE, otherwise the packet size in bytes.
1192 mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
1193 uint16_t cqe_cnt, volatile struct mlx5_mini_cqe8 **mcqe)
1195 struct rxq_zip *zip = &rxq->zip;
1196 uint16_t cqe_n = cqe_cnt + 1;
1202 /* Process compressed data in the CQE and mini arrays. */
1204 volatile struct mlx5_mini_cqe8 (*mc)[8] =
1205 (volatile struct mlx5_mini_cqe8 (*)[8])
1206 (uintptr_t)(&(*rxq->cqes)[zip->ca &
1209 len = rte_be_to_cpu_32((*mc)[zip->ai & 7].byte_cnt);
1210 *mcqe = &(*mc)[zip->ai & 7];
1211 if ((++zip->ai & 7) == 0) {
1212 /* Invalidate consumed CQEs */
1215 while (idx != end) {
1216 (*rxq->cqes)[idx & cqe_cnt].op_own =
1217 MLX5_CQE_INVALIDATE;
1221 * Increment consumer index to skip the number
1222 * of CQEs consumed. Hardware leaves holes in
1223 * the CQ ring for software use.
1228 if (unlikely(rxq->zip.ai == rxq->zip.cqe_cnt)) {
1229 /* Invalidate the rest */
1233 while (idx != end) {
1234 (*rxq->cqes)[idx & cqe_cnt].op_own =
1235 MLX5_CQE_INVALIDATE;
1238 rxq->cq_ci = zip->cq_ci;
1242 * No compressed data, get next CQE and verify if it is
1249 ret = check_cqe(cqe, cqe_n, rxq->cq_ci);
1250 if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
1251 if (unlikely(ret == MLX5_CQE_STATUS_ERR ||
1253 ret = mlx5_rx_err_handle(rxq, 0);
1254 if (ret == MLX5_CQE_STATUS_HW_OWN ||
1262 op_own = cqe->op_own;
1263 if (MLX5_CQE_FORMAT(op_own) == MLX5_COMPRESSED) {
1264 volatile struct mlx5_mini_cqe8 (*mc)[8] =
1265 (volatile struct mlx5_mini_cqe8 (*)[8])
1266 (uintptr_t)(&(*rxq->cqes)
1270 /* Fix endianness. */
1271 zip->cqe_cnt = rte_be_to_cpu_32(cqe->byte_cnt);
1273 * Current mini array position is the one
1274 * returned by check_cqe64().
1276 * If completion comprises several mini arrays,
1277 * as a special case the second one is located
1278 * 7 CQEs after the initial CQE instead of 8
1279 * for subsequent ones.
1281 zip->ca = rxq->cq_ci;
1282 zip->na = zip->ca + 7;
1283 /* Compute the next non compressed CQE. */
1285 zip->cq_ci = rxq->cq_ci + zip->cqe_cnt;
1286 /* Get packet size to return. */
1287 len = rte_be_to_cpu_32((*mc)[0].byte_cnt);
1290 /* Prefetch all to be invalidated */
1293 while (idx != end) {
1294 rte_prefetch0(&(*rxq->cqes)[(idx) &
1299 len = rte_be_to_cpu_32(cqe->byte_cnt);
1302 if (unlikely(rxq->err_state)) {
1303 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_cnt];
1304 ++rxq->stats.idropped;
1312 * Translate RX completion flags to offload flags.
1318 * Offload flags (ol_flags) for struct rte_mbuf.
1320 static inline uint32_t
1321 rxq_cq_to_ol_flags(volatile struct mlx5_cqe *cqe)
1323 uint32_t ol_flags = 0;
1324 uint16_t flags = rte_be_to_cpu_16(cqe->hdr_type_etc);
1328 MLX5_CQE_RX_L3_HDR_VALID,
1329 PKT_RX_IP_CKSUM_GOOD) |
1331 MLX5_CQE_RX_L4_HDR_VALID,
1332 PKT_RX_L4_CKSUM_GOOD);
1337 * Fill in mbuf fields from RX completion flags.
1338 * Note that pkt->ol_flags should be initialized outside of this function.
1341 * Pointer to RX queue.
1346 * @param rss_hash_res
1347 * Packet RSS Hash result.
1350 rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
1351 volatile struct mlx5_cqe *cqe, uint32_t rss_hash_res)
1353 /* Update packet information. */
1354 pkt->packet_type = rxq_cq_to_pkt_type(rxq, cqe);
1355 if (rss_hash_res && rxq->rss_hash) {
1356 pkt->hash.rss = rss_hash_res;
1357 pkt->ol_flags |= PKT_RX_RSS_HASH;
1359 if (rxq->mark && MLX5_FLOW_MARK_IS_VALID(cqe->sop_drop_qpn)) {
1360 pkt->ol_flags |= PKT_RX_FDIR;
1361 if (cqe->sop_drop_qpn !=
1362 rte_cpu_to_be_32(MLX5_FLOW_MARK_DEFAULT)) {
1363 uint32_t mark = cqe->sop_drop_qpn;
1365 pkt->ol_flags |= PKT_RX_FDIR_ID;
1366 pkt->hash.fdir.hi = mlx5_flow_mark_get(mark);
1369 if (rxq->dynf_meta && cqe->flow_table_metadata) {
1370 pkt->ol_flags |= rxq->flow_meta_mask;
1371 *RTE_MBUF_DYNFIELD(pkt, rxq->flow_meta_offset, uint32_t *) =
1372 cqe->flow_table_metadata;
1375 pkt->ol_flags |= rxq_cq_to_ol_flags(cqe);
1376 if (rxq->vlan_strip &&
1377 (cqe->hdr_type_etc & rte_cpu_to_be_16(MLX5_CQE_VLAN_STRIPPED))) {
1378 pkt->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
1379 pkt->vlan_tci = rte_be_to_cpu_16(cqe->vlan_info);
1381 if (rxq->hw_timestamp) {
1382 uint64_t ts = rte_be_to_cpu_64(cqe->timestamp);
1384 if (rxq->rt_timestamp)
1385 ts = mlx5_txpp_convert_rx_ts(rxq->sh, ts);
1386 pkt->timestamp = ts;
1387 pkt->ol_flags |= PKT_RX_TIMESTAMP;
1392 * DPDK callback for RX.
1395 * Generic pointer to RX queue structure.
1397 * Array to store received packets.
1399 * Maximum number of packets in array.
1402 * Number of packets successfully received (<= pkts_n).
1405 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1407 struct mlx5_rxq_data *rxq = dpdk_rxq;
1408 const unsigned int wqe_cnt = (1 << rxq->elts_n) - 1;
1409 const unsigned int cqe_cnt = (1 << rxq->cqe_n) - 1;
1410 const unsigned int sges_n = rxq->sges_n;
1411 struct rte_mbuf *pkt = NULL;
1412 struct rte_mbuf *seg = NULL;
1413 volatile struct mlx5_cqe *cqe =
1414 &(*rxq->cqes)[rxq->cq_ci & cqe_cnt];
1416 unsigned int rq_ci = rxq->rq_ci << sges_n;
1417 int len = 0; /* keep its value across iterations. */
1420 unsigned int idx = rq_ci & wqe_cnt;
1421 volatile struct mlx5_wqe_data_seg *wqe =
1422 &((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[idx];
1423 struct rte_mbuf *rep = (*rxq->elts)[idx];
1424 volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1425 uint32_t rss_hash_res;
1433 rep = rte_mbuf_raw_alloc(rxq->mp);
1434 if (unlikely(rep == NULL)) {
1435 ++rxq->stats.rx_nombuf;
1438 * no buffers before we even started,
1439 * bail out silently.
1443 while (pkt != seg) {
1444 MLX5_ASSERT(pkt != (*rxq->elts)[idx]);
1448 rte_mbuf_raw_free(pkt);
1454 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_cnt];
1455 len = mlx5_rx_poll_len(rxq, cqe, cqe_cnt, &mcqe);
1457 rte_mbuf_raw_free(rep);
1461 MLX5_ASSERT(len >= (rxq->crc_present << 2));
1462 pkt->ol_flags &= EXT_ATTACHED_MBUF;
1463 /* If compressed, take hash result from mini-CQE. */
1464 rss_hash_res = rte_be_to_cpu_32(mcqe == NULL ?
1466 mcqe->rx_hash_result);
1467 rxq_cq_to_mbuf(rxq, pkt, cqe, rss_hash_res);
1468 if (rxq->crc_present)
1469 len -= RTE_ETHER_CRC_LEN;
1471 if (cqe->lro_num_seg > 1) {
1473 (rte_pktmbuf_mtod(pkt, uint8_t *), cqe,
1475 pkt->ol_flags |= PKT_RX_LRO;
1476 pkt->tso_segsz = len / cqe->lro_num_seg;
1479 DATA_LEN(rep) = DATA_LEN(seg);
1480 PKT_LEN(rep) = PKT_LEN(seg);
1481 SET_DATA_OFF(rep, DATA_OFF(seg));
1482 PORT(rep) = PORT(seg);
1483 (*rxq->elts)[idx] = rep;
1485 * Fill NIC descriptor with the new buffer. The lkey and size
1486 * of the buffers are already known, only the buffer address
1489 wqe->addr = rte_cpu_to_be_64(rte_pktmbuf_mtod(rep, uintptr_t));
1490 /* If there's only one MR, no need to replace LKey in WQE. */
1491 if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
1492 wqe->lkey = mlx5_rx_mb2mr(rxq, rep);
1493 if (len > DATA_LEN(seg)) {
1494 len -= DATA_LEN(seg);
1499 DATA_LEN(seg) = len;
1500 #ifdef MLX5_PMD_SOFT_COUNTERS
1501 /* Increment bytes counter. */
1502 rxq->stats.ibytes += PKT_LEN(pkt);
1504 /* Return packet. */
1509 /* Align consumer index to the next stride. */
1514 if (unlikely((i == 0) && ((rq_ci >> sges_n) == rxq->rq_ci)))
1516 /* Update the consumer index. */
1517 rxq->rq_ci = rq_ci >> sges_n;
1519 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1521 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1522 #ifdef MLX5_PMD_SOFT_COUNTERS
1523 /* Increment packets counter. */
1524 rxq->stats.ipackets += i;
1530 * Update LRO packet TCP header.
1531 * The HW LRO feature doesn't update the TCP header after coalescing the
1532 * TCP segments but supplies information in CQE to fill it by SW.
1535 * Pointer to the TCP header.
1537 * Pointer to the completion entry..
1539 * The L3 pseudo-header checksum.
1542 mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_restrict tcp,
1543 volatile struct mlx5_cqe *__rte_restrict cqe,
1546 uint8_t l4_type = (rte_be_to_cpu_16(cqe->hdr_type_etc) &
1547 MLX5_CQE_L4_TYPE_MASK) >> MLX5_CQE_L4_TYPE_SHIFT;
1549 * The HW calculates only the TCP payload checksum, need to complete
1550 * the TCP header checksum and the L3 pseudo-header checksum.
1552 uint32_t csum = phcsum + cqe->csum;
1554 if (l4_type == MLX5_L4_HDR_TYPE_TCP_EMPTY_ACK ||
1555 l4_type == MLX5_L4_HDR_TYPE_TCP_WITH_ACL) {
1556 tcp->tcp_flags |= RTE_TCP_ACK_FLAG;
1557 tcp->recv_ack = cqe->lro_ack_seq_num;
1558 tcp->rx_win = cqe->lro_tcp_win;
1560 if (cqe->lro_tcppsh_abort_dupack & MLX5_CQE_LRO_PUSH_MASK)
1561 tcp->tcp_flags |= RTE_TCP_PSH_FLAG;
1563 csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
1564 csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
1565 csum = (~csum) & 0xffff;
1572 * Update LRO packet headers.
1573 * The HW LRO feature doesn't update the L3/TCP headers after coalescing the
1574 * TCP segments but supply information in CQE to fill it by SW.
1577 * The packet address.
1579 * Pointer to the completion entry..
1581 * The packet length.
1584 mlx5_lro_update_hdr(uint8_t *__rte_restrict padd,
1585 volatile struct mlx5_cqe *__rte_restrict cqe,
1589 struct rte_ether_hdr *eth;
1590 struct rte_vlan_hdr *vlan;
1591 struct rte_ipv4_hdr *ipv4;
1592 struct rte_ipv6_hdr *ipv6;
1593 struct rte_tcp_hdr *tcp;
1598 uint16_t proto = h.eth->ether_type;
1602 while (proto == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
1603 proto == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
1604 proto = h.vlan->eth_proto;
1607 if (proto == RTE_BE16(RTE_ETHER_TYPE_IPV4)) {
1608 h.ipv4->time_to_live = cqe->lro_min_ttl;
1609 h.ipv4->total_length = rte_cpu_to_be_16(len - (h.hdr - padd));
1610 h.ipv4->hdr_checksum = 0;
1611 h.ipv4->hdr_checksum = rte_ipv4_cksum(h.ipv4);
1612 phcsum = rte_ipv4_phdr_cksum(h.ipv4, 0);
1615 h.ipv6->hop_limits = cqe->lro_min_ttl;
1616 h.ipv6->payload_len = rte_cpu_to_be_16(len - (h.hdr - padd) -
1618 phcsum = rte_ipv6_phdr_cksum(h.ipv6, 0);
1621 mlx5_lro_update_tcp_hdr(h.tcp, cqe, phcsum);
1625 mlx5_mprq_buf_free_cb(void *addr __rte_unused, void *opaque)
1627 struct mlx5_mprq_buf *buf = opaque;
1629 if (rte_atomic16_read(&buf->refcnt) == 1) {
1630 rte_mempool_put(buf->mp, buf);
1631 } else if (rte_atomic16_add_return(&buf->refcnt, -1) == 0) {
1632 rte_atomic16_set(&buf->refcnt, 1);
1633 rte_mempool_put(buf->mp, buf);
1638 mlx5_mprq_buf_free(struct mlx5_mprq_buf *buf)
1640 mlx5_mprq_buf_free_cb(NULL, buf);
1644 mprq_buf_replace(struct mlx5_rxq_data *rxq, uint16_t rq_idx,
1645 const unsigned int strd_n)
1647 struct mlx5_mprq_buf *rep = rxq->mprq_repl;
1648 volatile struct mlx5_wqe_data_seg *wqe =
1649 &((volatile struct mlx5_wqe_mprq *)rxq->wqes)[rq_idx].dseg;
1652 MLX5_ASSERT(rep != NULL);
1653 /* Replace MPRQ buf. */
1654 (*rxq->mprq_bufs)[rq_idx] = rep;
1656 addr = mlx5_mprq_buf_addr(rep, strd_n);
1657 wqe->addr = rte_cpu_to_be_64((uintptr_t)addr);
1658 /* If there's only one MR, no need to replace LKey in WQE. */
1659 if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
1660 wqe->lkey = mlx5_rx_addr2mr(rxq, (uintptr_t)addr);
1661 /* Stash a mbuf for next replacement. */
1662 if (likely(!rte_mempool_get(rxq->mprq_mp, (void **)&rep)))
1663 rxq->mprq_repl = rep;
1665 rxq->mprq_repl = NULL;
1669 * DPDK callback for RX with Multi-Packet RQ support.
1672 * Generic pointer to RX queue structure.
1674 * Array to store received packets.
1676 * Maximum number of packets in array.
1679 * Number of packets successfully received (<= pkts_n).
1682 mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1684 struct mlx5_rxq_data *rxq = dpdk_rxq;
1685 const unsigned int strd_n = 1 << rxq->strd_num_n;
1686 const unsigned int strd_sz = 1 << rxq->strd_sz_n;
1687 const unsigned int strd_shift =
1688 MLX5_MPRQ_STRIDE_SHIFT_BYTE * rxq->strd_shift_en;
1689 const unsigned int cq_mask = (1 << rxq->cqe_n) - 1;
1690 const unsigned int wq_mask = (1 << rxq->elts_n) - 1;
1691 volatile struct mlx5_cqe *cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1693 uint32_t rq_ci = rxq->rq_ci;
1694 uint16_t consumed_strd = rxq->consumed_strd;
1695 struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1697 while (i < pkts_n) {
1698 struct rte_mbuf *pkt;
1706 int32_t hdrm_overlap;
1707 volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1708 uint32_t rss_hash_res = 0;
1710 if (consumed_strd == strd_n) {
1711 /* Replace WQE only if the buffer is still in use. */
1712 if (rte_atomic16_read(&buf->refcnt) > 1) {
1713 mprq_buf_replace(rxq, rq_ci & wq_mask, strd_n);
1714 /* Release the old buffer. */
1715 mlx5_mprq_buf_free(buf);
1716 } else if (unlikely(rxq->mprq_repl == NULL)) {
1717 struct mlx5_mprq_buf *rep;
1720 * Currently, the MPRQ mempool is out of buffer
1721 * and doing memcpy regardless of the size of Rx
1722 * packet. Retry allocation to get back to
1725 if (!rte_mempool_get(rxq->mprq_mp,
1727 rxq->mprq_repl = rep;
1729 /* Advance to the next WQE. */
1732 buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1734 cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1735 ret = mlx5_rx_poll_len(rxq, cqe, cq_mask, &mcqe);
1739 strd_cnt = (byte_cnt & MLX5_MPRQ_STRIDE_NUM_MASK) >>
1740 MLX5_MPRQ_STRIDE_NUM_SHIFT;
1741 MLX5_ASSERT(strd_cnt);
1742 consumed_strd += strd_cnt;
1743 if (byte_cnt & MLX5_MPRQ_FILLER_MASK)
1746 rss_hash_res = rte_be_to_cpu_32(cqe->rx_hash_res);
1747 strd_idx = rte_be_to_cpu_16(cqe->wqe_counter);
1749 /* mini-CQE for MPRQ doesn't have hash result. */
1750 strd_idx = rte_be_to_cpu_16(mcqe->stride_idx);
1752 MLX5_ASSERT(strd_idx < strd_n);
1753 MLX5_ASSERT(!((rte_be_to_cpu_16(cqe->wqe_id) ^ rq_ci) &
1755 pkt = rte_pktmbuf_alloc(rxq->mp);
1756 if (unlikely(pkt == NULL)) {
1757 ++rxq->stats.rx_nombuf;
1760 len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
1761 MLX5_ASSERT((int)len >= (rxq->crc_present << 2));
1762 if (rxq->crc_present)
1763 len -= RTE_ETHER_CRC_LEN;
1764 offset = strd_idx * strd_sz + strd_shift;
1765 addr = RTE_PTR_ADD(mlx5_mprq_buf_addr(buf, strd_n), offset);
1766 hdrm_overlap = len + RTE_PKTMBUF_HEADROOM - strd_cnt * strd_sz;
1768 * Memcpy packets to the target mbuf if:
1769 * - The size of packet is smaller than mprq_max_memcpy_len.
1770 * - Out of buffer in the Mempool for Multi-Packet RQ.
1771 * - The packet's stride overlaps a headroom and scatter is off.
1773 if (len <= rxq->mprq_max_memcpy_len ||
1774 rxq->mprq_repl == NULL ||
1775 (hdrm_overlap > 0 && !rxq->strd_scatter_en)) {
1776 if (likely(rte_pktmbuf_tailroom(pkt) >= len)) {
1777 rte_memcpy(rte_pktmbuf_mtod(pkt, void *),
1779 DATA_LEN(pkt) = len;
1780 } else if (rxq->strd_scatter_en) {
1781 struct rte_mbuf *prev = pkt;
1783 RTE_MIN(rte_pktmbuf_tailroom(pkt), len);
1784 uint32_t rem_len = len - seg_len;
1786 rte_memcpy(rte_pktmbuf_mtod(pkt, void *),
1788 DATA_LEN(pkt) = seg_len;
1790 struct rte_mbuf *next =
1791 rte_pktmbuf_alloc(rxq->mp);
1793 if (unlikely(next == NULL)) {
1794 rte_pktmbuf_free(pkt);
1795 ++rxq->stats.rx_nombuf;
1799 SET_DATA_OFF(next, 0);
1800 addr = RTE_PTR_ADD(addr, seg_len);
1802 (rte_pktmbuf_tailroom(next),
1805 (rte_pktmbuf_mtod(next, void *),
1807 DATA_LEN(next) = seg_len;
1813 rte_pktmbuf_free_seg(pkt);
1814 ++rxq->stats.idropped;
1818 rte_iova_t buf_iova;
1819 struct rte_mbuf_ext_shared_info *shinfo;
1820 uint16_t buf_len = strd_cnt * strd_sz;
1823 /* Increment the refcnt of the whole chunk. */
1824 rte_atomic16_add_return(&buf->refcnt, 1);
1825 MLX5_ASSERT((uint16_t)rte_atomic16_read(&buf->refcnt) <=
1827 buf_addr = RTE_PTR_SUB(addr, RTE_PKTMBUF_HEADROOM);
1829 * MLX5 device doesn't use iova but it is necessary in a
1830 * case where the Rx packet is transmitted via a
1833 buf_iova = rte_mempool_virt2iova(buf) +
1834 RTE_PTR_DIFF(buf_addr, buf);
1835 shinfo = &buf->shinfos[strd_idx];
1836 rte_mbuf_ext_refcnt_set(shinfo, 1);
1838 * EXT_ATTACHED_MBUF will be set to pkt->ol_flags when
1839 * attaching the stride to mbuf and more offload flags
1840 * will be added below by calling rxq_cq_to_mbuf().
1841 * Other fields will be overwritten.
1843 rte_pktmbuf_attach_extbuf(pkt, buf_addr, buf_iova,
1845 /* Set mbuf head-room. */
1846 SET_DATA_OFF(pkt, RTE_PKTMBUF_HEADROOM);
1847 MLX5_ASSERT(pkt->ol_flags == EXT_ATTACHED_MBUF);
1848 MLX5_ASSERT(rte_pktmbuf_tailroom(pkt) >=
1849 len - (hdrm_overlap > 0 ? hdrm_overlap : 0));
1850 DATA_LEN(pkt) = len;
1852 * Copy the last fragment of a packet (up to headroom
1853 * size bytes) in case there is a stride overlap with
1854 * a next packet's headroom. Allocate a separate mbuf
1855 * to store this fragment and link it. Scatter is on.
1857 if (hdrm_overlap > 0) {
1858 MLX5_ASSERT(rxq->strd_scatter_en);
1859 struct rte_mbuf *seg =
1860 rte_pktmbuf_alloc(rxq->mp);
1862 if (unlikely(seg == NULL)) {
1863 rte_pktmbuf_free_seg(pkt);
1864 ++rxq->stats.rx_nombuf;
1867 SET_DATA_OFF(seg, 0);
1868 rte_memcpy(rte_pktmbuf_mtod(seg, void *),
1869 RTE_PTR_ADD(addr, len - hdrm_overlap),
1871 DATA_LEN(seg) = hdrm_overlap;
1872 DATA_LEN(pkt) = len - hdrm_overlap;
1877 rxq_cq_to_mbuf(rxq, pkt, cqe, rss_hash_res);
1878 if (cqe->lro_num_seg > 1) {
1879 mlx5_lro_update_hdr(addr, cqe, len);
1880 pkt->ol_flags |= PKT_RX_LRO;
1881 pkt->tso_segsz = len / cqe->lro_num_seg;
1884 PORT(pkt) = rxq->port_id;
1885 #ifdef MLX5_PMD_SOFT_COUNTERS
1886 /* Increment bytes counter. */
1887 rxq->stats.ibytes += PKT_LEN(pkt);
1889 /* Return packet. */
1894 /* Update the consumer indexes. */
1895 rxq->consumed_strd = consumed_strd;
1897 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1898 if (rq_ci != rxq->rq_ci) {
1901 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1903 #ifdef MLX5_PMD_SOFT_COUNTERS
1904 /* Increment packets counter. */
1905 rxq->stats.ipackets += i;
1911 * Dummy DPDK callback for TX.
1913 * This function is used to temporarily replace the real callback during
1914 * unsafe control operations on the queue, or in case of error.
1917 * Generic pointer to TX queue structure.
1919 * Packets to transmit.
1921 * Number of packets in array.
1924 * Number of packets successfully transmitted (<= pkts_n).
1927 removed_tx_burst(void *dpdk_txq __rte_unused,
1928 struct rte_mbuf **pkts __rte_unused,
1929 uint16_t pkts_n __rte_unused)
1936 * Dummy DPDK callback for RX.
1938 * This function is used to temporarily replace the real callback during
1939 * unsafe control operations on the queue, or in case of error.
1942 * Generic pointer to RX queue structure.
1944 * Array to store received packets.
1946 * Maximum number of packets in array.
1949 * Number of packets successfully received (<= pkts_n).
1952 removed_rx_burst(void *dpdk_txq __rte_unused,
1953 struct rte_mbuf **pkts __rte_unused,
1954 uint16_t pkts_n __rte_unused)
1961 * Vectorized Rx/Tx routines are not compiled in when required vector
1962 * instructions are not supported on a target architecture. The following null
1963 * stubs are needed for linkage when those are not included outside of this file
1964 * (e.g. mlx5_rxtx_vec_sse.c for x86).
1968 mlx5_rx_burst_vec(void *dpdk_txq __rte_unused,
1969 struct rte_mbuf **pkts __rte_unused,
1970 uint16_t pkts_n __rte_unused)
1976 mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq __rte_unused)
1982 mlx5_check_vec_rx_support(struct rte_eth_dev *dev __rte_unused)
1988 * Free the mbufs from the linear array of pointers.
1991 * Pointer to array of packets to be free.
1993 * Number of packets to be freed.
1995 * Configured Tx offloads mask. It is fully defined at
1996 * compile time and may be used for optimization.
1998 static __rte_always_inline void
1999 mlx5_tx_free_mbuf(struct rte_mbuf **__rte_restrict pkts,
2000 unsigned int pkts_n,
2001 unsigned int olx __rte_unused)
2003 struct rte_mempool *pool = NULL;
2004 struct rte_mbuf **p_free = NULL;
2005 struct rte_mbuf *mbuf;
2006 unsigned int n_free = 0;
2009 * The implemented algorithm eliminates
2010 * copying pointers to temporary array
2011 * for rte_mempool_put_bulk() calls.
2014 MLX5_ASSERT(pkts_n);
2018 * Decrement mbuf reference counter, detach
2019 * indirect and external buffers if needed.
2021 mbuf = rte_pktmbuf_prefree_seg(*pkts);
2022 if (likely(mbuf != NULL)) {
2023 MLX5_ASSERT(mbuf == *pkts);
2024 if (likely(n_free != 0)) {
2025 if (unlikely(pool != mbuf->pool))
2026 /* From different pool. */
2029 /* Start new scan array. */
2036 if (unlikely(pkts_n == 0)) {
2042 * This happens if mbuf is still referenced.
2043 * We can't put it back to the pool, skip.
2047 if (unlikely(n_free != 0))
2048 /* There is some array to free.*/
2050 if (unlikely(pkts_n == 0))
2051 /* Last mbuf, nothing to free. */
2057 * This loop is implemented to avoid multiple
2058 * inlining of rte_mempool_put_bulk().
2061 MLX5_ASSERT(p_free);
2062 MLX5_ASSERT(n_free);
2064 * Free the array of pre-freed mbufs
2065 * belonging to the same memory pool.
2067 rte_mempool_put_bulk(pool, (void *)p_free, n_free);
2068 if (unlikely(mbuf != NULL)) {
2069 /* There is the request to start new scan. */
2074 if (likely(pkts_n != 0))
2077 * This is the last mbuf to be freed.
2078 * Do one more loop iteration to complete.
2079 * This is rare case of the last unique mbuf.
2084 if (likely(pkts_n == 0))
2093 * Free the mbuf from the elts ring buffer till new tail.
2096 * Pointer to Tx queue structure.
2098 * Index in elts to free up to, becomes new elts tail.
2100 * Configured Tx offloads mask. It is fully defined at
2101 * compile time and may be used for optimization.
2103 static __rte_always_inline void
2104 mlx5_tx_free_elts(struct mlx5_txq_data *__rte_restrict txq,
2106 unsigned int olx __rte_unused)
2108 uint16_t n_elts = tail - txq->elts_tail;
2110 MLX5_ASSERT(n_elts);
2111 MLX5_ASSERT(n_elts <= txq->elts_s);
2113 * Implement a loop to support ring buffer wraparound
2114 * with single inlining of mlx5_tx_free_mbuf().
2119 part = txq->elts_s - (txq->elts_tail & txq->elts_m);
2120 part = RTE_MIN(part, n_elts);
2122 MLX5_ASSERT(part <= txq->elts_s);
2123 mlx5_tx_free_mbuf(&txq->elts[txq->elts_tail & txq->elts_m],
2125 txq->elts_tail += part;
2131 * Store the mbuf being sent into elts ring buffer.
2132 * On Tx completion these mbufs will be freed.
2135 * Pointer to Tx queue structure.
2137 * Pointer to array of packets to be stored.
2139 * Number of packets to be stored.
2141 * Configured Tx offloads mask. It is fully defined at
2142 * compile time and may be used for optimization.
2144 static __rte_always_inline void
2145 mlx5_tx_copy_elts(struct mlx5_txq_data *__rte_restrict txq,
2146 struct rte_mbuf **__rte_restrict pkts,
2147 unsigned int pkts_n,
2148 unsigned int olx __rte_unused)
2151 struct rte_mbuf **elts = (struct rte_mbuf **)txq->elts;
2154 MLX5_ASSERT(pkts_n);
2155 part = txq->elts_s - (txq->elts_head & txq->elts_m);
2157 MLX5_ASSERT(part <= txq->elts_s);
2158 /* This code is a good candidate for vectorizing with SIMD. */
2159 rte_memcpy((void *)(elts + (txq->elts_head & txq->elts_m)),
2161 RTE_MIN(part, pkts_n) * sizeof(struct rte_mbuf *));
2162 txq->elts_head += pkts_n;
2163 if (unlikely(part < pkts_n))
2164 /* The copy is wrapping around the elts array. */
2165 rte_memcpy((void *)elts, (void *)(pkts + part),
2166 (pkts_n - part) * sizeof(struct rte_mbuf *));
2170 * Update completion queue consuming index via doorbell
2171 * and flush the completed data buffers.
2174 * Pointer to TX queue structure.
2175 * @param valid CQE pointer
2176 * if not NULL update txq->wqe_pi and flush the buffers
2178 * Configured Tx offloads mask. It is fully defined at
2179 * compile time and may be used for optimization.
2181 static __rte_always_inline void
2182 mlx5_tx_comp_flush(struct mlx5_txq_data *__rte_restrict txq,
2183 volatile struct mlx5_cqe *last_cqe,
2184 unsigned int olx __rte_unused)
2186 if (likely(last_cqe != NULL)) {
2189 txq->wqe_pi = rte_be_to_cpu_16(last_cqe->wqe_counter);
2190 tail = txq->fcqs[(txq->cq_ci - 1) & txq->cqe_m];
2191 if (likely(tail != txq->elts_tail)) {
2192 mlx5_tx_free_elts(txq, tail, olx);
2193 MLX5_ASSERT(tail == txq->elts_tail);
2199 * Manage TX completions. This routine checks the CQ for
2200 * arrived CQEs, deduces the last accomplished WQE in SQ,
2201 * updates SQ producing index and frees all completed mbufs.
2204 * Pointer to TX queue structure.
2206 * Configured Tx offloads mask. It is fully defined at
2207 * compile time and may be used for optimization.
2209 * NOTE: not inlined intentionally, it makes tx_burst
2210 * routine smaller, simple and faster - from experiments.
2213 mlx5_tx_handle_completion(struct mlx5_txq_data *__rte_restrict txq,
2214 unsigned int olx __rte_unused)
2216 unsigned int count = MLX5_TX_COMP_MAX_CQE;
2217 volatile struct mlx5_cqe *last_cqe = NULL;
2218 bool ring_doorbell = false;
2221 static_assert(MLX5_CQE_STATUS_HW_OWN < 0, "Must be negative value");
2222 static_assert(MLX5_CQE_STATUS_SW_OWN < 0, "Must be negative value");
2224 volatile struct mlx5_cqe *cqe;
2226 cqe = &txq->cqes[txq->cq_ci & txq->cqe_m];
2227 ret = check_cqe(cqe, txq->cqe_s, txq->cq_ci);
2228 if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
2229 if (likely(ret != MLX5_CQE_STATUS_ERR)) {
2230 /* No new CQEs in completion queue. */
2231 MLX5_ASSERT(ret == MLX5_CQE_STATUS_HW_OWN);
2235 * Some error occurred, try to restart.
2236 * We have no barrier after WQE related Doorbell
2237 * written, make sure all writes are completed
2238 * here, before we might perform SQ reset.
2241 ret = mlx5_tx_error_cqe_handle
2242 (txq, (volatile struct mlx5_err_cqe *)cqe);
2243 if (unlikely(ret < 0)) {
2245 * Some error occurred on queue error
2246 * handling, we do not advance the index
2247 * here, allowing to retry on next call.
2252 * We are going to fetch all entries with
2253 * MLX5_CQE_SYNDROME_WR_FLUSH_ERR status.
2254 * The send queue is supposed to be empty.
2256 ring_doorbell = true;
2258 txq->cq_pi = txq->cq_ci;
2262 /* Normal transmit completion. */
2263 MLX5_ASSERT(txq->cq_ci != txq->cq_pi);
2264 MLX5_ASSERT((txq->fcqs[txq->cq_ci & txq->cqe_m] >> 16) ==
2266 ring_doorbell = true;
2270 * We have to restrict the amount of processed CQEs
2271 * in one tx_burst routine call. The CQ may be large
2272 * and many CQEs may be updated by the NIC in one
2273 * transaction. Buffers freeing is time consuming,
2274 * multiple iterations may introduce significant
2277 if (likely(--count == 0))
2280 if (likely(ring_doorbell)) {
2281 /* Ring doorbell to notify hardware. */
2282 rte_compiler_barrier();
2283 *txq->cq_db = rte_cpu_to_be_32(txq->cq_ci);
2284 mlx5_tx_comp_flush(txq, last_cqe, olx);
2289 * Check if the completion request flag should be set in the last WQE.
2290 * Both pushed mbufs and WQEs are monitored and the completion request
2291 * flag is set if any of thresholds is reached.
2294 * Pointer to TX queue structure.
2296 * Pointer to burst routine local context.
2298 * Configured Tx offloads mask. It is fully defined at
2299 * compile time and may be used for optimization.
2301 static __rte_always_inline void
2302 mlx5_tx_request_completion(struct mlx5_txq_data *__rte_restrict txq,
2303 struct mlx5_txq_local *__rte_restrict loc,
2306 uint16_t head = txq->elts_head;
2309 part = MLX5_TXOFF_CONFIG(INLINE) ?
2310 0 : loc->pkts_sent - loc->pkts_copy;
2312 if ((uint16_t)(head - txq->elts_comp) >= MLX5_TX_COMP_THRESH ||
2313 (MLX5_TXOFF_CONFIG(INLINE) &&
2314 (uint16_t)(txq->wqe_ci - txq->wqe_comp) >= txq->wqe_thres)) {
2315 volatile struct mlx5_wqe *last = loc->wqe_last;
2318 txq->elts_comp = head;
2319 if (MLX5_TXOFF_CONFIG(INLINE))
2320 txq->wqe_comp = txq->wqe_ci;
2321 /* Request unconditional completion on last WQE. */
2322 last->cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
2323 MLX5_COMP_MODE_OFFSET);
2324 /* Save elts_head in dedicated free on completion queue. */
2325 #ifdef RTE_LIBRTE_MLX5_DEBUG
2326 txq->fcqs[txq->cq_pi++ & txq->cqe_m] = head |
2327 (last->cseg.opcode >> 8) << 16;
2329 txq->fcqs[txq->cq_pi++ & txq->cqe_m] = head;
2331 /* A CQE slot must always be available. */
2332 MLX5_ASSERT((txq->cq_pi - txq->cq_ci) <= txq->cqe_s);
2337 * DPDK callback to check the status of a tx descriptor.
2342 * The index of the descriptor in the ring.
2345 * The status of the tx descriptor.
2348 mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset)
2350 struct mlx5_txq_data *__rte_restrict txq = tx_queue;
2353 mlx5_tx_handle_completion(txq, 0);
2354 used = txq->elts_head - txq->elts_tail;
2356 return RTE_ETH_TX_DESC_FULL;
2357 return RTE_ETH_TX_DESC_DONE;
2361 * Build the Control Segment with specified opcode:
2362 * - MLX5_OPCODE_SEND
2363 * - MLX5_OPCODE_ENHANCED_MPSW
2367 * Pointer to TX queue structure.
2369 * Pointer to burst routine local context.
2371 * Pointer to WQE to fill with built Control Segment.
2373 * Supposed length of WQE in segments.
2375 * SQ WQE opcode to put into Control Segment.
2377 * Configured Tx offloads mask. It is fully defined at
2378 * compile time and may be used for optimization.
2380 static __rte_always_inline void
2381 mlx5_tx_cseg_init(struct mlx5_txq_data *__rte_restrict txq,
2382 struct mlx5_txq_local *__rte_restrict loc __rte_unused,
2383 struct mlx5_wqe *__rte_restrict wqe,
2385 unsigned int opcode,
2386 unsigned int olx __rte_unused)
2388 struct mlx5_wqe_cseg *__rte_restrict cs = &wqe->cseg;
2390 /* For legacy MPW replace the EMPW by TSO with modifier. */
2391 if (MLX5_TXOFF_CONFIG(MPW) && opcode == MLX5_OPCODE_ENHANCED_MPSW)
2392 opcode = MLX5_OPCODE_TSO | MLX5_OPC_MOD_MPW << 24;
2393 cs->opcode = rte_cpu_to_be_32((txq->wqe_ci << 8) | opcode);
2394 cs->sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
2395 cs->flags = RTE_BE32(MLX5_COMP_ONLY_FIRST_ERR <<
2396 MLX5_COMP_MODE_OFFSET);
2397 cs->misc = RTE_BE32(0);
2401 * Build the Synchronize Queue Segment with specified completion index.
2404 * Pointer to TX queue structure.
2406 * Pointer to burst routine local context.
2408 * Pointer to WQE to fill with built Control Segment.
2410 * Completion index in Clock Queue to wait.
2412 * Configured Tx offloads mask. It is fully defined at
2413 * compile time and may be used for optimization.
2415 static __rte_always_inline void
2416 mlx5_tx_wseg_init(struct mlx5_txq_data *restrict txq,
2417 struct mlx5_txq_local *restrict loc __rte_unused,
2418 struct mlx5_wqe *restrict wqe,
2420 unsigned int olx __rte_unused)
2422 struct mlx5_wqe_qseg *qs;
2424 qs = RTE_PTR_ADD(wqe, MLX5_WSEG_SIZE);
2425 qs->max_index = rte_cpu_to_be_32(wci);
2426 qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq->id);
2427 qs->reserved0 = RTE_BE32(0);
2428 qs->reserved1 = RTE_BE32(0);
2432 * Build the Ethernet Segment without inlined data.
2433 * Supports Software Parser, Checksums and VLAN
2434 * insertion Tx offload features.
2437 * Pointer to TX queue structure.
2439 * Pointer to burst routine local context.
2441 * Pointer to WQE to fill with built Ethernet Segment.
2443 * Configured Tx offloads mask. It is fully defined at
2444 * compile time and may be used for optimization.
2446 static __rte_always_inline void
2447 mlx5_tx_eseg_none(struct mlx5_txq_data *__rte_restrict txq __rte_unused,
2448 struct mlx5_txq_local *__rte_restrict loc,
2449 struct mlx5_wqe *__rte_restrict wqe,
2452 struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
2456 * Calculate and set check sum flags first, dword field
2457 * in segment may be shared with Software Parser flags.
2459 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2460 es->flags = rte_cpu_to_le_32(csum);
2462 * Calculate and set Software Parser offsets and flags.
2463 * These flags a set for custom UDP and IP tunnel packets.
2465 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2466 /* Fill metadata field if needed. */
2467 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2468 loc->mbuf->ol_flags & PKT_TX_DYNF_METADATA ?
2469 *RTE_FLOW_DYNF_METADATA(loc->mbuf) : 0 : 0;
2470 /* Engage VLAN tag insertion feature if requested. */
2471 if (MLX5_TXOFF_CONFIG(VLAN) &&
2472 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
2474 * We should get here only if device support
2475 * this feature correctly.
2477 MLX5_ASSERT(txq->vlan_en);
2478 es->inline_hdr = rte_cpu_to_be_32(MLX5_ETH_WQE_VLAN_INSERT |
2479 loc->mbuf->vlan_tci);
2481 es->inline_hdr = RTE_BE32(0);
2486 * Build the Ethernet Segment with minimal inlined data
2487 * of MLX5_ESEG_MIN_INLINE_SIZE bytes length. This is
2488 * used to fill the gap in single WQEBB WQEs.
2489 * Supports Software Parser, Checksums and VLAN
2490 * insertion Tx offload features.
2493 * Pointer to TX queue structure.
2495 * Pointer to burst routine local context.
2497 * Pointer to WQE to fill with built Ethernet Segment.
2499 * Length of VLAN tag insertion if any.
2501 * Configured Tx offloads mask. It is fully defined at
2502 * compile time and may be used for optimization.
2504 static __rte_always_inline void
2505 mlx5_tx_eseg_dmin(struct mlx5_txq_data *__rte_restrict txq __rte_unused,
2506 struct mlx5_txq_local *__rte_restrict loc,
2507 struct mlx5_wqe *__rte_restrict wqe,
2511 struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
2513 uint8_t *psrc, *pdst;
2516 * Calculate and set check sum flags first, dword field
2517 * in segment may be shared with Software Parser flags.
2519 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2520 es->flags = rte_cpu_to_le_32(csum);
2522 * Calculate and set Software Parser offsets and flags.
2523 * These flags a set for custom UDP and IP tunnel packets.
2525 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2526 /* Fill metadata field if needed. */
2527 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2528 loc->mbuf->ol_flags & PKT_TX_DYNF_METADATA ?
2529 *RTE_FLOW_DYNF_METADATA(loc->mbuf) : 0 : 0;
2530 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2532 sizeof(rte_v128u32_t)),
2533 "invalid Ethernet Segment data size");
2534 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2536 sizeof(struct rte_vlan_hdr) +
2537 2 * RTE_ETHER_ADDR_LEN),
2538 "invalid Ethernet Segment data size");
2539 psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2540 es->inline_hdr_sz = RTE_BE16(MLX5_ESEG_MIN_INLINE_SIZE);
2541 es->inline_data = *(unaligned_uint16_t *)psrc;
2542 psrc += sizeof(uint16_t);
2543 pdst = (uint8_t *)(es + 1);
2544 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2545 /* Implement VLAN tag insertion as part inline data. */
2546 memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
2547 pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2548 psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2549 /* Insert VLAN ethertype + VLAN tag. */
2550 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2551 ((RTE_ETHER_TYPE_VLAN << 16) |
2552 loc->mbuf->vlan_tci);
2553 pdst += sizeof(struct rte_vlan_hdr);
2554 /* Copy the rest two bytes from packet data. */
2555 MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
2556 *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
2558 /* Fill the gap in the title WQEBB with inline data. */
2559 rte_mov16(pdst, psrc);
2564 * Build the Ethernet Segment with entire packet
2565 * data inlining. Checks the boundary of WQEBB and
2566 * ring buffer wrapping, supports Software Parser,
2567 * Checksums and VLAN insertion Tx offload features.
2570 * Pointer to TX queue structure.
2572 * Pointer to burst routine local context.
2574 * Pointer to WQE to fill with built Ethernet Segment.
2576 * Length of VLAN tag insertion if any.
2578 * Length of data to inline (VLAN included, if any).
2580 * TSO flag, set mss field from the packet.
2582 * Configured Tx offloads mask. It is fully defined at
2583 * compile time and may be used for optimization.
2586 * Pointer to the next Data Segment (aligned and wrapped around).
2588 static __rte_always_inline struct mlx5_wqe_dseg *
2589 mlx5_tx_eseg_data(struct mlx5_txq_data *__rte_restrict txq,
2590 struct mlx5_txq_local *__rte_restrict loc,
2591 struct mlx5_wqe *__rte_restrict wqe,
2597 struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
2599 uint8_t *psrc, *pdst;
2603 * Calculate and set check sum flags first, dword field
2604 * in segment may be shared with Software Parser flags.
2606 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2609 csum |= loc->mbuf->tso_segsz;
2610 es->flags = rte_cpu_to_be_32(csum);
2612 es->flags = rte_cpu_to_le_32(csum);
2615 * Calculate and set Software Parser offsets and flags.
2616 * These flags a set for custom UDP and IP tunnel packets.
2618 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2619 /* Fill metadata field if needed. */
2620 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2621 loc->mbuf->ol_flags & PKT_TX_DYNF_METADATA ?
2622 *RTE_FLOW_DYNF_METADATA(loc->mbuf) : 0 : 0;
2623 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2625 sizeof(rte_v128u32_t)),
2626 "invalid Ethernet Segment data size");
2627 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2629 sizeof(struct rte_vlan_hdr) +
2630 2 * RTE_ETHER_ADDR_LEN),
2631 "invalid Ethernet Segment data size");
2632 psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2633 es->inline_hdr_sz = rte_cpu_to_be_16(inlen);
2634 es->inline_data = *(unaligned_uint16_t *)psrc;
2635 psrc += sizeof(uint16_t);
2636 pdst = (uint8_t *)(es + 1);
2637 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2638 /* Implement VLAN tag insertion as part inline data. */
2639 memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
2640 pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2641 psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2642 /* Insert VLAN ethertype + VLAN tag. */
2643 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2644 ((RTE_ETHER_TYPE_VLAN << 16) |
2645 loc->mbuf->vlan_tci);
2646 pdst += sizeof(struct rte_vlan_hdr);
2647 /* Copy the rest two bytes from packet data. */
2648 MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
2649 *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
2650 psrc += sizeof(uint16_t);
2652 /* Fill the gap in the title WQEBB with inline data. */
2653 rte_mov16(pdst, psrc);
2654 psrc += sizeof(rte_v128u32_t);
2656 pdst = (uint8_t *)(es + 2);
2657 MLX5_ASSERT(inlen >= MLX5_ESEG_MIN_INLINE_SIZE);
2658 MLX5_ASSERT(pdst < (uint8_t *)txq->wqes_end);
2659 inlen -= MLX5_ESEG_MIN_INLINE_SIZE;
2661 MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
2662 return (struct mlx5_wqe_dseg *)pdst;
2665 * The WQEBB space availability is checked by caller.
2666 * Here we should be aware of WQE ring buffer wraparound only.
2668 part = (uint8_t *)txq->wqes_end - pdst;
2669 part = RTE_MIN(part, inlen);
2671 rte_memcpy(pdst, psrc, part);
2673 if (likely(!inlen)) {
2675 * If return value is not used by the caller
2676 * the code below will be optimized out.
2679 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2680 if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
2681 pdst = (uint8_t *)txq->wqes;
2682 return (struct mlx5_wqe_dseg *)pdst;
2684 pdst = (uint8_t *)txq->wqes;
2691 * Copy data from chain of mbuf to the specified linear buffer.
2692 * Checksums and VLAN insertion Tx offload features. If data
2693 * from some mbuf copied completely this mbuf is freed. Local
2694 * structure is used to keep the byte stream state.
2697 * Pointer to the destination linear buffer.
2699 * Pointer to burst routine local context.
2701 * Length of data to be copied.
2703 * Length of data to be copied ignoring no inline hint.
2705 * Configured Tx offloads mask. It is fully defined at
2706 * compile time and may be used for optimization.
2709 * Number of actual copied data bytes. This is always greater than or
2710 * equal to must parameter and might be lesser than len in no inline
2711 * hint flag is encountered.
2713 static __rte_always_inline unsigned int
2714 mlx5_tx_mseg_memcpy(uint8_t *pdst,
2715 struct mlx5_txq_local *__rte_restrict loc,
2718 unsigned int olx __rte_unused)
2720 struct rte_mbuf *mbuf;
2721 unsigned int part, dlen, copy = 0;
2725 MLX5_ASSERT(must <= len);
2727 /* Allow zero length packets, must check first. */
2728 dlen = rte_pktmbuf_data_len(loc->mbuf);
2729 if (dlen <= loc->mbuf_off) {
2730 /* Exhausted packet, just free. */
2732 loc->mbuf = mbuf->next;
2733 rte_pktmbuf_free_seg(mbuf);
2735 MLX5_ASSERT(loc->mbuf_nseg > 1);
2736 MLX5_ASSERT(loc->mbuf);
2738 if (loc->mbuf->ol_flags & PKT_TX_DYNF_NOINLINE) {
2743 * We already copied the minimal
2744 * requested amount of data.
2749 if (diff <= rte_pktmbuf_data_len(loc->mbuf)) {
2751 * Copy only the minimal required
2752 * part of the data buffer.
2759 dlen -= loc->mbuf_off;
2760 psrc = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
2762 part = RTE_MIN(len, dlen);
2763 rte_memcpy(pdst, psrc, part);
2765 loc->mbuf_off += part;
2768 if (loc->mbuf_off >= rte_pktmbuf_data_len(loc->mbuf)) {
2770 /* Exhausted packet, just free. */
2772 loc->mbuf = mbuf->next;
2773 rte_pktmbuf_free_seg(mbuf);
2775 MLX5_ASSERT(loc->mbuf_nseg >= 1);
2785 * Build the Ethernet Segment with inlined data from
2786 * multi-segment packet. Checks the boundary of WQEBB
2787 * and ring buffer wrapping, supports Software Parser,
2788 * Checksums and VLAN insertion Tx offload features.
2791 * Pointer to TX queue structure.
2793 * Pointer to burst routine local context.
2795 * Pointer to WQE to fill with built Ethernet Segment.
2797 * Length of VLAN tag insertion if any.
2799 * Length of data to inline (VLAN included, if any).
2801 * TSO flag, set mss field from the packet.
2803 * Configured Tx offloads mask. It is fully defined at
2804 * compile time and may be used for optimization.
2807 * Pointer to the next Data Segment (aligned and
2808 * possible NOT wrapped around - caller should do
2809 * wrapping check on its own).
2811 static __rte_always_inline struct mlx5_wqe_dseg *
2812 mlx5_tx_eseg_mdat(struct mlx5_txq_data *__rte_restrict txq,
2813 struct mlx5_txq_local *__rte_restrict loc,
2814 struct mlx5_wqe *__rte_restrict wqe,
2820 struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
2823 unsigned int part, tlen = 0;
2826 * Calculate and set check sum flags first, uint32_t field
2827 * in segment may be shared with Software Parser flags.
2829 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2832 csum |= loc->mbuf->tso_segsz;
2833 es->flags = rte_cpu_to_be_32(csum);
2835 es->flags = rte_cpu_to_le_32(csum);
2838 * Calculate and set Software Parser offsets and flags.
2839 * These flags a set for custom UDP and IP tunnel packets.
2841 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2842 /* Fill metadata field if needed. */
2843 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2844 loc->mbuf->ol_flags & PKT_TX_DYNF_METADATA ?
2845 *RTE_FLOW_DYNF_METADATA(loc->mbuf) : 0 : 0;
2846 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2848 sizeof(rte_v128u32_t)),
2849 "invalid Ethernet Segment data size");
2850 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2852 sizeof(struct rte_vlan_hdr) +
2853 2 * RTE_ETHER_ADDR_LEN),
2854 "invalid Ethernet Segment data size");
2855 MLX5_ASSERT(inlen >= MLX5_ESEG_MIN_INLINE_SIZE);
2856 pdst = (uint8_t *)&es->inline_data;
2857 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2858 /* Implement VLAN tag insertion as part inline data. */
2859 mlx5_tx_mseg_memcpy(pdst, loc,
2860 2 * RTE_ETHER_ADDR_LEN,
2861 2 * RTE_ETHER_ADDR_LEN, olx);
2862 pdst += 2 * RTE_ETHER_ADDR_LEN;
2863 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2864 ((RTE_ETHER_TYPE_VLAN << 16) |
2865 loc->mbuf->vlan_tci);
2866 pdst += sizeof(struct rte_vlan_hdr);
2867 tlen += 2 * RTE_ETHER_ADDR_LEN + sizeof(struct rte_vlan_hdr);
2869 MLX5_ASSERT(pdst < (uint8_t *)txq->wqes_end);
2871 * The WQEBB space availability is checked by caller.
2872 * Here we should be aware of WQE ring buffer wraparound only.
2874 part = (uint8_t *)txq->wqes_end - pdst;
2875 part = RTE_MIN(part, inlen - tlen);
2881 * Copying may be interrupted inside the routine
2882 * if run into no inline hint flag.
2884 copy = tlen >= txq->inlen_mode ? 0 : (txq->inlen_mode - tlen);
2885 copy = mlx5_tx_mseg_memcpy(pdst, loc, part, copy, olx);
2887 if (likely(inlen <= tlen) || copy < part) {
2888 es->inline_hdr_sz = rte_cpu_to_be_16(tlen);
2890 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2891 return (struct mlx5_wqe_dseg *)pdst;
2893 pdst = (uint8_t *)txq->wqes;
2894 part = inlen - tlen;
2899 * Build the Data Segment of pointer type.
2902 * Pointer to TX queue structure.
2904 * Pointer to burst routine local context.
2906 * Pointer to WQE to fill with built Data Segment.
2908 * Data buffer to point.
2910 * Data buffer length.
2912 * Configured Tx offloads mask. It is fully defined at
2913 * compile time and may be used for optimization.
2915 static __rte_always_inline void
2916 mlx5_tx_dseg_ptr(struct mlx5_txq_data *__rte_restrict txq,
2917 struct mlx5_txq_local *__rte_restrict loc,
2918 struct mlx5_wqe_dseg *__rte_restrict dseg,
2921 unsigned int olx __rte_unused)
2925 dseg->bcount = rte_cpu_to_be_32(len);
2926 dseg->lkey = mlx5_tx_mb2mr(txq, loc->mbuf);
2927 dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
2931 * Build the Data Segment of pointer type or inline
2932 * if data length is less than buffer in minimal
2933 * Data Segment size.
2936 * Pointer to TX queue structure.
2938 * Pointer to burst routine local context.
2940 * Pointer to WQE to fill with built Data Segment.
2942 * Data buffer to point.
2944 * Data buffer length.
2946 * Configured Tx offloads mask. It is fully defined at
2947 * compile time and may be used for optimization.
2949 static __rte_always_inline void
2950 mlx5_tx_dseg_iptr(struct mlx5_txq_data *__rte_restrict txq,
2951 struct mlx5_txq_local *__rte_restrict loc,
2952 struct mlx5_wqe_dseg *__rte_restrict dseg,
2955 unsigned int olx __rte_unused)
2961 if (len > MLX5_DSEG_MIN_INLINE_SIZE) {
2962 dseg->bcount = rte_cpu_to_be_32(len);
2963 dseg->lkey = mlx5_tx_mb2mr(txq, loc->mbuf);
2964 dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
2968 dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
2969 /* Unrolled implementation of generic rte_memcpy. */
2970 dst = (uintptr_t)&dseg->inline_data[0];
2971 src = (uintptr_t)buf;
2973 #ifdef RTE_ARCH_STRICT_ALIGN
2974 MLX5_ASSERT(dst == RTE_PTR_ALIGN(dst, sizeof(uint32_t)));
2975 *(uint32_t *)dst = *(unaligned_uint32_t *)src;
2976 dst += sizeof(uint32_t);
2977 src += sizeof(uint32_t);
2978 *(uint32_t *)dst = *(unaligned_uint32_t *)src;
2979 dst += sizeof(uint32_t);
2980 src += sizeof(uint32_t);
2982 *(uint64_t *)dst = *(unaligned_uint64_t *)src;
2983 dst += sizeof(uint64_t);
2984 src += sizeof(uint64_t);
2988 *(uint32_t *)dst = *(unaligned_uint32_t *)src;
2989 dst += sizeof(uint32_t);
2990 src += sizeof(uint32_t);
2993 *(uint16_t *)dst = *(unaligned_uint16_t *)src;
2994 dst += sizeof(uint16_t);
2995 src += sizeof(uint16_t);
2998 *(uint8_t *)dst = *(uint8_t *)src;
3002 * Build the Data Segment of inlined data from single
3003 * segment packet, no VLAN insertion.
3006 * Pointer to TX queue structure.
3008 * Pointer to burst routine local context.
3010 * Pointer to WQE to fill with built Data Segment.
3012 * Data buffer to point.
3014 * Data buffer length.
3016 * Configured Tx offloads mask. It is fully defined at
3017 * compile time and may be used for optimization.
3020 * Pointer to the next Data Segment after inlined data.
3021 * Ring buffer wraparound check is needed. We do not
3022 * do it here because it may not be needed for the
3023 * last packet in the eMPW session.
3025 static __rte_always_inline struct mlx5_wqe_dseg *
3026 mlx5_tx_dseg_empw(struct mlx5_txq_data *__rte_restrict txq,
3027 struct mlx5_txq_local *__rte_restrict loc __rte_unused,
3028 struct mlx5_wqe_dseg *__rte_restrict dseg,
3031 unsigned int olx __rte_unused)
3036 if (!MLX5_TXOFF_CONFIG(MPW)) {
3037 /* Store the descriptor byte counter for eMPW sessions. */
3038 dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
3039 pdst = &dseg->inline_data[0];
3041 /* The entire legacy MPW session counter is stored on close. */
3042 pdst = (uint8_t *)dseg;
3045 * The WQEBB space availability is checked by caller.
3046 * Here we should be aware of WQE ring buffer wraparound only.
3048 part = (uint8_t *)txq->wqes_end - pdst;
3049 part = RTE_MIN(part, len);
3051 rte_memcpy(pdst, buf, part);
3055 if (!MLX5_TXOFF_CONFIG(MPW))
3056 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
3057 /* Note: no final wraparound check here. */
3058 return (struct mlx5_wqe_dseg *)pdst;
3060 pdst = (uint8_t *)txq->wqes;
3067 * Build the Data Segment of inlined data from single
3068 * segment packet with VLAN insertion.
3071 * Pointer to TX queue structure.
3073 * Pointer to burst routine local context.
3075 * Pointer to the dseg fill with built Data Segment.
3077 * Data buffer to point.
3079 * Data buffer length.
3081 * Configured Tx offloads mask. It is fully defined at
3082 * compile time and may be used for optimization.
3085 * Pointer to the next Data Segment after inlined data.
3086 * Ring buffer wraparound check is needed.
3088 static __rte_always_inline struct mlx5_wqe_dseg *
3089 mlx5_tx_dseg_vlan(struct mlx5_txq_data *__rte_restrict txq,
3090 struct mlx5_txq_local *__rte_restrict loc __rte_unused,
3091 struct mlx5_wqe_dseg *__rte_restrict dseg,
3094 unsigned int olx __rte_unused)
3100 MLX5_ASSERT(len > MLX5_ESEG_MIN_INLINE_SIZE);
3101 static_assert(MLX5_DSEG_MIN_INLINE_SIZE ==
3102 (2 * RTE_ETHER_ADDR_LEN),
3103 "invalid Data Segment data size");
3104 if (!MLX5_TXOFF_CONFIG(MPW)) {
3105 /* Store the descriptor byte counter for eMPW sessions. */
3106 dseg->bcount = rte_cpu_to_be_32
3107 ((len + sizeof(struct rte_vlan_hdr)) |
3108 MLX5_ETH_WQE_DATA_INLINE);
3109 pdst = &dseg->inline_data[0];
3111 /* The entire legacy MPW session counter is stored on close. */
3112 pdst = (uint8_t *)dseg;
3114 memcpy(pdst, buf, MLX5_DSEG_MIN_INLINE_SIZE);
3115 buf += MLX5_DSEG_MIN_INLINE_SIZE;
3116 pdst += MLX5_DSEG_MIN_INLINE_SIZE;
3117 len -= MLX5_DSEG_MIN_INLINE_SIZE;
3118 /* Insert VLAN ethertype + VLAN tag. Pointer is aligned. */
3119 MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
3120 if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
3121 pdst = (uint8_t *)txq->wqes;
3122 *(uint32_t *)pdst = rte_cpu_to_be_32((RTE_ETHER_TYPE_VLAN << 16) |
3123 loc->mbuf->vlan_tci);
3124 pdst += sizeof(struct rte_vlan_hdr);
3126 * The WQEBB space availability is checked by caller.
3127 * Here we should be aware of WQE ring buffer wraparound only.
3129 part = (uint8_t *)txq->wqes_end - pdst;
3130 part = RTE_MIN(part, len);
3132 rte_memcpy(pdst, buf, part);
3136 if (!MLX5_TXOFF_CONFIG(MPW))
3137 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
3138 /* Note: no final wraparound check here. */
3139 return (struct mlx5_wqe_dseg *)pdst;
3141 pdst = (uint8_t *)txq->wqes;
3148 * Build the Ethernet Segment with optionally inlined data with
3149 * VLAN insertion and following Data Segments (if any) from
3150 * multi-segment packet. Used by ordinary send and TSO.
3153 * Pointer to TX queue structure.
3155 * Pointer to burst routine local context.
3157 * Pointer to WQE to fill with built Ethernet/Data Segments.
3159 * Length of VLAN header to insert, 0 means no VLAN insertion.
3161 * Data length to inline. For TSO this parameter specifies
3162 * exact value, for ordinary send routine can be aligned by
3163 * caller to provide better WQE space saving and data buffer
3164 * start address alignment. This length includes VLAN header
3167 * Zero means ordinary send, inlined data can be extended,
3168 * otherwise this is TSO, inlined data length is fixed.
3170 * Configured Tx offloads mask. It is fully defined at
3171 * compile time and may be used for optimization.
3174 * Actual size of built WQE in segments.
3176 static __rte_always_inline unsigned int
3177 mlx5_tx_mseg_build(struct mlx5_txq_data *__rte_restrict txq,
3178 struct mlx5_txq_local *__rte_restrict loc,
3179 struct mlx5_wqe *__rte_restrict wqe,
3183 unsigned int olx __rte_unused)
3185 struct mlx5_wqe_dseg *__rte_restrict dseg;
3188 MLX5_ASSERT((rte_pktmbuf_pkt_len(loc->mbuf) + vlan) >= inlen);
3189 loc->mbuf_nseg = NB_SEGS(loc->mbuf);
3192 dseg = mlx5_tx_eseg_mdat(txq, loc, wqe, vlan, inlen, tso, olx);
3193 if (!loc->mbuf_nseg)
3196 * There are still some mbuf remaining, not inlined.
3197 * The first mbuf may be partially inlined and we
3198 * must process the possible non-zero data offset.
3200 if (loc->mbuf_off) {
3205 * Exhausted packets must be dropped before.
3206 * Non-zero offset means there are some data
3207 * remained in the packet.
3209 MLX5_ASSERT(loc->mbuf_off < rte_pktmbuf_data_len(loc->mbuf));
3210 MLX5_ASSERT(rte_pktmbuf_data_len(loc->mbuf));
3211 dptr = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
3213 dlen = rte_pktmbuf_data_len(loc->mbuf) - loc->mbuf_off;
3215 * Build the pointer/minimal data Data Segment.
3216 * Do ring buffer wrapping check in advance.
3218 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3219 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3220 mlx5_tx_dseg_iptr(txq, loc, dseg, dptr, dlen, olx);
3221 /* Store the mbuf to be freed on completion. */
3222 MLX5_ASSERT(loc->elts_free);
3223 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3226 if (--loc->mbuf_nseg == 0)
3228 loc->mbuf = loc->mbuf->next;
3232 if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
3233 struct rte_mbuf *mbuf;
3235 /* Zero length segment found, just skip. */
3237 loc->mbuf = loc->mbuf->next;
3238 rte_pktmbuf_free_seg(mbuf);
3239 if (--loc->mbuf_nseg == 0)
3242 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3243 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3246 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3247 rte_pktmbuf_data_len(loc->mbuf), olx);
3248 MLX5_ASSERT(loc->elts_free);
3249 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3252 if (--loc->mbuf_nseg == 0)
3254 loc->mbuf = loc->mbuf->next;
3259 /* Calculate actual segments used from the dseg pointer. */
3260 if ((uintptr_t)wqe < (uintptr_t)dseg)
3261 ds = ((uintptr_t)dseg - (uintptr_t)wqe) / MLX5_WSEG_SIZE;
3263 ds = (((uintptr_t)dseg - (uintptr_t)wqe) +
3264 txq->wqe_s * MLX5_WQE_SIZE) / MLX5_WSEG_SIZE;
3269 * The routine checks timestamp flag in the current packet,
3270 * and push WAIT WQE into the queue if scheduling is required.
3273 * Pointer to TX queue structure.
3275 * Pointer to burst routine local context.
3277 * Configured Tx offloads mask. It is fully defined at
3278 * compile time and may be used for optimization.
3281 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3282 * MLX5_TXCMP_CODE_SINGLE - continue processing with the packet.
3283 * MLX5_TXCMP_CODE_MULTI - the WAIT inserted, continue processing.
3284 * Local context variables partially updated.
3286 static __rte_always_inline enum mlx5_txcmp_code
3287 mlx5_tx_schedule_send(struct mlx5_txq_data *restrict txq,
3288 struct mlx5_txq_local *restrict loc,
3291 if (MLX5_TXOFF_CONFIG(TXPP) &&
3292 loc->mbuf->ol_flags & txq->ts_mask) {
3293 struct mlx5_wqe *wqe;
3298 * Estimate the required space quickly and roughly.
3299 * We would like to ensure the packet can be pushed
3300 * to the queue and we won't get the orphan WAIT WQE.
3302 if (loc->wqe_free <= MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE ||
3303 loc->elts_free < NB_SEGS(loc->mbuf))
3304 return MLX5_TXCMP_CODE_EXIT;
3305 /* Convert the timestamp into completion to wait. */
3306 ts = *RTE_MBUF_DYNFIELD(loc->mbuf, txq->ts_offset, uint64_t *);
3307 wci = mlx5_txpp_convert_tx_ts(txq->sh, ts);
3308 if (unlikely(wci < 0))
3309 return MLX5_TXCMP_CODE_SINGLE;
3310 /* Build the WAIT WQE with specified completion. */
3311 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3312 mlx5_tx_cseg_init(txq, loc, wqe, 2, MLX5_OPCODE_WAIT, olx);
3313 mlx5_tx_wseg_init(txq, loc, wqe, wci, olx);
3316 return MLX5_TXCMP_CODE_MULTI;
3318 return MLX5_TXCMP_CODE_SINGLE;
3322 * Tx one packet function for multi-segment TSO. Supports all
3323 * types of Tx offloads, uses MLX5_OPCODE_TSO to build WQEs,
3324 * sends one packet per WQE.
3326 * This routine is responsible for storing processed mbuf
3327 * into elts ring buffer and update elts_head.
3330 * Pointer to TX queue structure.
3332 * Pointer to burst routine local context.
3334 * Configured Tx offloads mask. It is fully defined at
3335 * compile time and may be used for optimization.
3338 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3339 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3340 * Local context variables partially updated.
3342 static __rte_always_inline enum mlx5_txcmp_code
3343 mlx5_tx_packet_multi_tso(struct mlx5_txq_data *__rte_restrict txq,
3344 struct mlx5_txq_local *__rte_restrict loc,
3347 struct mlx5_wqe *__rte_restrict wqe;
3348 unsigned int ds, dlen, inlen, ntcp, vlan = 0;
3350 if (MLX5_TXOFF_CONFIG(TXPP)) {
3351 enum mlx5_txcmp_code wret;
3353 /* Generate WAIT for scheduling if requested. */
3354 wret = mlx5_tx_schedule_send(txq, loc, olx);
3355 if (wret == MLX5_TXCMP_CODE_EXIT)
3356 return MLX5_TXCMP_CODE_EXIT;
3357 if (wret == MLX5_TXCMP_CODE_ERROR)
3358 return MLX5_TXCMP_CODE_ERROR;
3361 * Calculate data length to be inlined to estimate
3362 * the required space in WQE ring buffer.
3364 dlen = rte_pktmbuf_pkt_len(loc->mbuf);
3365 if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3366 vlan = sizeof(struct rte_vlan_hdr);
3367 inlen = loc->mbuf->l2_len + vlan +
3368 loc->mbuf->l3_len + loc->mbuf->l4_len;
3369 if (unlikely((!inlen || !loc->mbuf->tso_segsz)))
3370 return MLX5_TXCMP_CODE_ERROR;
3371 if (loc->mbuf->ol_flags & PKT_TX_TUNNEL_MASK)
3372 inlen += loc->mbuf->outer_l2_len + loc->mbuf->outer_l3_len;
3373 /* Packet must contain all TSO headers. */
3374 if (unlikely(inlen > MLX5_MAX_TSO_HEADER ||
3375 inlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
3376 inlen > (dlen + vlan)))
3377 return MLX5_TXCMP_CODE_ERROR;
3378 MLX5_ASSERT(inlen >= txq->inlen_mode);
3380 * Check whether there are enough free WQEBBs:
3382 * - Ethernet Segment
3383 * - First Segment of inlined Ethernet data
3384 * - ... data continued ...
3385 * - Data Segments of pointer/min inline type
3387 ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
3388 MLX5_ESEG_MIN_INLINE_SIZE +
3390 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3391 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3392 return MLX5_TXCMP_CODE_EXIT;
3393 /* Check for maximal WQE size. */
3394 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3395 return MLX5_TXCMP_CODE_ERROR;
3396 #ifdef MLX5_PMD_SOFT_COUNTERS
3397 /* Update sent data bytes/packets counters. */
3398 ntcp = (dlen - (inlen - vlan) + loc->mbuf->tso_segsz - 1) /
3399 loc->mbuf->tso_segsz;
3401 * One will be added for mbuf itself
3402 * at the end of the mlx5_tx_burst from
3403 * loc->pkts_sent field.
3406 txq->stats.opackets += ntcp;
3407 txq->stats.obytes += dlen + vlan + ntcp * inlen;
3409 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3410 loc->wqe_last = wqe;
3411 mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_TSO, olx);
3412 ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 1, olx);
3413 wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3414 txq->wqe_ci += (ds + 3) / 4;
3415 loc->wqe_free -= (ds + 3) / 4;
3416 return MLX5_TXCMP_CODE_MULTI;
3420 * Tx one packet function for multi-segment SEND. Supports all
3421 * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
3422 * sends one packet per WQE, without any data inlining in
3425 * This routine is responsible for storing processed mbuf
3426 * into elts ring buffer and update elts_head.
3429 * Pointer to TX queue structure.
3431 * Pointer to burst routine local context.
3433 * Configured Tx offloads mask. It is fully defined at
3434 * compile time and may be used for optimization.
3437 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3438 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3439 * Local context variables partially updated.
3441 static __rte_always_inline enum mlx5_txcmp_code
3442 mlx5_tx_packet_multi_send(struct mlx5_txq_data *__rte_restrict txq,
3443 struct mlx5_txq_local *__rte_restrict loc,
3446 struct mlx5_wqe_dseg *__rte_restrict dseg;
3447 struct mlx5_wqe *__rte_restrict wqe;
3448 unsigned int ds, nseg;
3450 MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
3451 if (MLX5_TXOFF_CONFIG(TXPP)) {
3452 enum mlx5_txcmp_code wret;
3454 /* Generate WAIT for scheduling if requested. */
3455 wret = mlx5_tx_schedule_send(txq, loc, olx);
3456 if (wret == MLX5_TXCMP_CODE_EXIT)
3457 return MLX5_TXCMP_CODE_EXIT;
3458 if (wret == MLX5_TXCMP_CODE_ERROR)
3459 return MLX5_TXCMP_CODE_ERROR;
3462 * No inline at all, it means the CPU cycles saving
3463 * is prioritized at configuration, we should not
3464 * copy any packet data to WQE.
3466 nseg = NB_SEGS(loc->mbuf);
3468 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3469 return MLX5_TXCMP_CODE_EXIT;
3470 /* Check for maximal WQE size. */
3471 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3472 return MLX5_TXCMP_CODE_ERROR;
3474 * Some Tx offloads may cause an error if
3475 * packet is not long enough, check against
3476 * assumed minimal length.
3478 if (rte_pktmbuf_pkt_len(loc->mbuf) <= MLX5_ESEG_MIN_INLINE_SIZE)
3479 return MLX5_TXCMP_CODE_ERROR;
3480 #ifdef MLX5_PMD_SOFT_COUNTERS
3481 /* Update sent data bytes counter. */
3482 txq->stats.obytes += rte_pktmbuf_pkt_len(loc->mbuf);
3483 if (MLX5_TXOFF_CONFIG(VLAN) &&
3484 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3485 txq->stats.obytes += sizeof(struct rte_vlan_hdr);
3488 * SEND WQE, one WQEBB:
3489 * - Control Segment, SEND opcode
3490 * - Ethernet Segment, optional VLAN, no inline
3491 * - Data Segments, pointer only type
3493 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3494 loc->wqe_last = wqe;
3495 mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_SEND, olx);
3496 mlx5_tx_eseg_none(txq, loc, wqe, olx);
3497 dseg = &wqe->dseg[0];
3499 if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
3500 struct rte_mbuf *mbuf;
3503 * Zero length segment found, have to
3504 * correct total size of WQE in segments.
3505 * It is supposed to be rare occasion, so
3506 * in normal case (no zero length segments)
3507 * we avoid extra writing to the Control
3511 wqe->cseg.sq_ds -= RTE_BE32(1);
3513 loc->mbuf = mbuf->next;
3514 rte_pktmbuf_free_seg(mbuf);
3520 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3521 rte_pktmbuf_data_len(loc->mbuf), olx);
3522 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3527 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3528 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3529 loc->mbuf = loc->mbuf->next;
3532 txq->wqe_ci += (ds + 3) / 4;
3533 loc->wqe_free -= (ds + 3) / 4;
3534 return MLX5_TXCMP_CODE_MULTI;
3538 * Tx one packet function for multi-segment SEND. Supports all
3539 * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
3540 * sends one packet per WQE, with data inlining in
3541 * Ethernet Segment and minimal Data Segments.
3543 * This routine is responsible for storing processed mbuf
3544 * into elts ring buffer and update elts_head.
3547 * Pointer to TX queue structure.
3549 * Pointer to burst routine local context.
3551 * Configured Tx offloads mask. It is fully defined at
3552 * compile time and may be used for optimization.
3555 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3556 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3557 * Local context variables partially updated.
3559 static __rte_always_inline enum mlx5_txcmp_code
3560 mlx5_tx_packet_multi_inline(struct mlx5_txq_data *__rte_restrict txq,
3561 struct mlx5_txq_local *__rte_restrict loc,
3564 struct mlx5_wqe *__rte_restrict wqe;
3565 unsigned int ds, inlen, dlen, vlan = 0;
3567 MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
3568 MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
3569 if (MLX5_TXOFF_CONFIG(TXPP)) {
3570 enum mlx5_txcmp_code wret;
3572 /* Generate WAIT for scheduling if requested. */
3573 wret = mlx5_tx_schedule_send(txq, loc, olx);
3574 if (wret == MLX5_TXCMP_CODE_EXIT)
3575 return MLX5_TXCMP_CODE_EXIT;
3576 if (wret == MLX5_TXCMP_CODE_ERROR)
3577 return MLX5_TXCMP_CODE_ERROR;
3580 * First calculate data length to be inlined
3581 * to estimate the required space for WQE.
3583 dlen = rte_pktmbuf_pkt_len(loc->mbuf);
3584 if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3585 vlan = sizeof(struct rte_vlan_hdr);
3586 inlen = dlen + vlan;
3587 /* Check against minimal length. */
3588 if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
3589 return MLX5_TXCMP_CODE_ERROR;
3590 MLX5_ASSERT(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
3591 if (inlen > txq->inlen_send ||
3592 loc->mbuf->ol_flags & PKT_TX_DYNF_NOINLINE) {
3593 struct rte_mbuf *mbuf;
3598 * Packet length exceeds the allowed inline
3599 * data length, check whether the minimal
3600 * inlining is required.
3602 if (txq->inlen_mode) {
3603 MLX5_ASSERT(txq->inlen_mode >=
3604 MLX5_ESEG_MIN_INLINE_SIZE);
3605 MLX5_ASSERT(txq->inlen_mode <= txq->inlen_send);
3606 inlen = txq->inlen_mode;
3608 if (loc->mbuf->ol_flags & PKT_TX_DYNF_NOINLINE ||
3609 !vlan || txq->vlan_en) {
3611 * VLAN insertion will be done inside by HW.
3612 * It is not utmost effective - VLAN flag is
3613 * checked twice, but we should proceed the
3614 * inlining length correctly and take into
3615 * account the VLAN header being inserted.
3617 return mlx5_tx_packet_multi_send
3620 inlen = MLX5_ESEG_MIN_INLINE_SIZE;
3623 * Now we know the minimal amount of data is requested
3624 * to inline. Check whether we should inline the buffers
3625 * from the chain beginning to eliminate some mbufs.
3628 nxlen = rte_pktmbuf_data_len(mbuf);
3629 if (unlikely(nxlen <= txq->inlen_send)) {
3630 /* We can inline first mbuf at least. */
3631 if (nxlen < inlen) {
3634 /* Scan mbufs till inlen filled. */
3639 nxlen = rte_pktmbuf_data_len(mbuf);
3641 } while (unlikely(nxlen < inlen));
3642 if (unlikely(nxlen > txq->inlen_send)) {
3643 /* We cannot inline entire mbuf. */
3644 smlen = inlen - smlen;
3645 start = rte_pktmbuf_mtod_offset
3646 (mbuf, uintptr_t, smlen);
3653 /* There should be not end of packet. */
3655 nxlen = inlen + rte_pktmbuf_data_len(mbuf);
3656 } while (unlikely(nxlen < txq->inlen_send));
3658 start = rte_pktmbuf_mtod(mbuf, uintptr_t);
3660 * Check whether we can do inline to align start
3661 * address of data buffer to cacheline.
3664 start = (~start + 1) & (RTE_CACHE_LINE_SIZE - 1);
3665 if (unlikely(start)) {
3667 if (start <= txq->inlen_send)
3672 * Check whether there are enough free WQEBBs:
3674 * - Ethernet Segment
3675 * - First Segment of inlined Ethernet data
3676 * - ... data continued ...
3677 * - Data Segments of pointer/min inline type
3679 * Estimate the number of Data Segments conservatively,
3680 * supposing no any mbufs is being freed during inlining.
3682 MLX5_ASSERT(inlen <= txq->inlen_send);
3683 ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
3684 MLX5_ESEG_MIN_INLINE_SIZE +
3686 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3687 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3688 return MLX5_TXCMP_CODE_EXIT;
3689 /* Check for maximal WQE size. */
3690 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3691 return MLX5_TXCMP_CODE_ERROR;
3692 #ifdef MLX5_PMD_SOFT_COUNTERS
3693 /* Update sent data bytes/packets counters. */
3694 txq->stats.obytes += dlen + vlan;
3696 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3697 loc->wqe_last = wqe;
3698 mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_SEND, olx);
3699 ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 0, olx);
3700 wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3701 txq->wqe_ci += (ds + 3) / 4;
3702 loc->wqe_free -= (ds + 3) / 4;
3703 return MLX5_TXCMP_CODE_MULTI;
3707 * Tx burst function for multi-segment packets. Supports all
3708 * types of Tx offloads, uses MLX5_OPCODE_SEND/TSO to build WQEs,
3709 * sends one packet per WQE. Function stops sending if it
3710 * encounters the single-segment packet.
3712 * This routine is responsible for storing processed mbuf
3713 * into elts ring buffer and update elts_head.
3716 * Pointer to TX queue structure.
3718 * Packets to transmit.
3720 * Number of packets in array.
3722 * Pointer to burst routine local context.
3724 * Configured Tx offloads mask. It is fully defined at
3725 * compile time and may be used for optimization.
3728 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3729 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3730 * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
3731 * MLX5_TXCMP_CODE_TSO - TSO single-segment packet encountered.
3732 * Local context variables updated.
3734 static __rte_always_inline enum mlx5_txcmp_code
3735 mlx5_tx_burst_mseg(struct mlx5_txq_data *__rte_restrict txq,
3736 struct rte_mbuf **__rte_restrict pkts,
3737 unsigned int pkts_n,
3738 struct mlx5_txq_local *__rte_restrict loc,
3741 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3742 MLX5_ASSERT(pkts_n > loc->pkts_sent);
3743 pkts += loc->pkts_sent + 1;
3744 pkts_n -= loc->pkts_sent;
3746 enum mlx5_txcmp_code ret;
3748 MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
3750 * Estimate the number of free elts quickly but
3751 * conservatively. Some segment may be fully inlined
3752 * and freed, ignore this here - precise estimation
3755 if (loc->elts_free < NB_SEGS(loc->mbuf))
3756 return MLX5_TXCMP_CODE_EXIT;
3757 if (MLX5_TXOFF_CONFIG(TSO) &&
3758 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)) {
3759 /* Proceed with multi-segment TSO. */
3760 ret = mlx5_tx_packet_multi_tso(txq, loc, olx);
3761 } else if (MLX5_TXOFF_CONFIG(INLINE)) {
3762 /* Proceed with multi-segment SEND with inlining. */
3763 ret = mlx5_tx_packet_multi_inline(txq, loc, olx);
3765 /* Proceed with multi-segment SEND w/o inlining. */
3766 ret = mlx5_tx_packet_multi_send(txq, loc, olx);
3768 if (ret == MLX5_TXCMP_CODE_EXIT)
3769 return MLX5_TXCMP_CODE_EXIT;
3770 if (ret == MLX5_TXCMP_CODE_ERROR)
3771 return MLX5_TXCMP_CODE_ERROR;
3772 /* WQE is built, go to the next packet. */
3775 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3776 return MLX5_TXCMP_CODE_EXIT;
3777 loc->mbuf = *pkts++;
3779 rte_prefetch0(*pkts);
3780 if (likely(NB_SEGS(loc->mbuf) > 1))
3782 /* Here ends the series of multi-segment packets. */
3783 if (MLX5_TXOFF_CONFIG(TSO) &&
3784 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG))
3785 return MLX5_TXCMP_CODE_TSO;
3786 return MLX5_TXCMP_CODE_SINGLE;
3792 * Tx burst function for single-segment packets with TSO.
3793 * Supports all types of Tx offloads, except multi-packets.
3794 * Uses MLX5_OPCODE_TSO to build WQEs, sends one packet per WQE.
3795 * Function stops sending if it encounters the multi-segment
3796 * packet or packet without TSO requested.
3798 * The routine is responsible for storing processed mbuf
3799 * into elts ring buffer and update elts_head if inline
3800 * offloads is requested due to possible early freeing
3801 * of the inlined mbufs (can not store pkts array in elts
3805 * Pointer to TX queue structure.
3807 * Packets to transmit.
3809 * Number of packets in array.
3811 * Pointer to burst routine local context.
3813 * Configured Tx offloads mask. It is fully defined at
3814 * compile time and may be used for optimization.
3817 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3818 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3819 * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
3820 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3821 * Local context variables updated.
3823 static __rte_always_inline enum mlx5_txcmp_code
3824 mlx5_tx_burst_tso(struct mlx5_txq_data *__rte_restrict txq,
3825 struct rte_mbuf **__rte_restrict pkts,
3826 unsigned int pkts_n,
3827 struct mlx5_txq_local *__rte_restrict loc,
3830 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3831 MLX5_ASSERT(pkts_n > loc->pkts_sent);
3832 pkts += loc->pkts_sent + 1;
3833 pkts_n -= loc->pkts_sent;
3835 struct mlx5_wqe_dseg *__rte_restrict dseg;
3836 struct mlx5_wqe *__rte_restrict wqe;
3837 unsigned int ds, dlen, hlen, ntcp, vlan = 0;
3840 MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
3841 if (MLX5_TXOFF_CONFIG(TXPP)) {
3842 enum mlx5_txcmp_code wret;
3844 /* Generate WAIT for scheduling if requested. */
3845 wret = mlx5_tx_schedule_send(txq, loc, olx);
3846 if (wret == MLX5_TXCMP_CODE_EXIT)
3847 return MLX5_TXCMP_CODE_EXIT;
3848 if (wret == MLX5_TXCMP_CODE_ERROR)
3849 return MLX5_TXCMP_CODE_ERROR;
3851 dlen = rte_pktmbuf_data_len(loc->mbuf);
3852 if (MLX5_TXOFF_CONFIG(VLAN) &&
3853 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
3854 vlan = sizeof(struct rte_vlan_hdr);
3857 * First calculate the WQE size to check
3858 * whether we have enough space in ring buffer.
3860 hlen = loc->mbuf->l2_len + vlan +
3861 loc->mbuf->l3_len + loc->mbuf->l4_len;
3862 if (unlikely((!hlen || !loc->mbuf->tso_segsz)))
3863 return MLX5_TXCMP_CODE_ERROR;
3864 if (loc->mbuf->ol_flags & PKT_TX_TUNNEL_MASK)
3865 hlen += loc->mbuf->outer_l2_len +
3866 loc->mbuf->outer_l3_len;
3867 /* Segment must contain all TSO headers. */
3868 if (unlikely(hlen > MLX5_MAX_TSO_HEADER ||
3869 hlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
3870 hlen > (dlen + vlan)))
3871 return MLX5_TXCMP_CODE_ERROR;
3873 * Check whether there are enough free WQEBBs:
3875 * - Ethernet Segment
3876 * - First Segment of inlined Ethernet data
3877 * - ... data continued ...
3878 * - Finishing Data Segment of pointer type
3880 ds = 4 + (hlen - MLX5_ESEG_MIN_INLINE_SIZE +
3881 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3882 if (loc->wqe_free < ((ds + 3) / 4))
3883 return MLX5_TXCMP_CODE_EXIT;
3884 #ifdef MLX5_PMD_SOFT_COUNTERS
3885 /* Update sent data bytes/packets counters. */
3886 ntcp = (dlen + vlan - hlen +
3887 loc->mbuf->tso_segsz - 1) /
3888 loc->mbuf->tso_segsz;
3890 * One will be added for mbuf itself at the end
3891 * of the mlx5_tx_burst from loc->pkts_sent field.
3894 txq->stats.opackets += ntcp;
3895 txq->stats.obytes += dlen + vlan + ntcp * hlen;
3898 * Build the TSO WQE:
3900 * - Ethernet Segment with hlen bytes inlined
3901 * - Data Segment of pointer type
3903 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3904 loc->wqe_last = wqe;
3905 mlx5_tx_cseg_init(txq, loc, wqe, ds,
3906 MLX5_OPCODE_TSO, olx);
3907 dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan, hlen, 1, olx);
3908 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) + hlen - vlan;
3909 dlen -= hlen - vlan;
3910 mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
3912 * WQE is built, update the loop parameters
3913 * and go to the next packet.
3915 txq->wqe_ci += (ds + 3) / 4;
3916 loc->wqe_free -= (ds + 3) / 4;
3917 if (MLX5_TXOFF_CONFIG(INLINE))
3918 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3922 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3923 return MLX5_TXCMP_CODE_EXIT;
3924 loc->mbuf = *pkts++;
3926 rte_prefetch0(*pkts);
3927 if (MLX5_TXOFF_CONFIG(MULTI) &&
3928 unlikely(NB_SEGS(loc->mbuf) > 1))
3929 return MLX5_TXCMP_CODE_MULTI;
3930 if (likely(!(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)))
3931 return MLX5_TXCMP_CODE_SINGLE;
3932 /* Continue with the next TSO packet. */
3938 * Analyze the packet and select the best method to send.
3941 * Pointer to TX queue structure.
3943 * Pointer to burst routine local context.
3945 * Configured Tx offloads mask. It is fully defined at
3946 * compile time and may be used for optimization.
3948 * The predefined flag whether do complete check for
3949 * multi-segment packets and TSO.
3952 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3953 * MLX5_TXCMP_CODE_TSO - TSO required, use TSO/LSO.
3954 * MLX5_TXCMP_CODE_SINGLE - single-segment packet, use SEND.
3955 * MLX5_TXCMP_CODE_EMPW - single-segment packet, use MPW.
3957 static __rte_always_inline enum mlx5_txcmp_code
3958 mlx5_tx_able_to_empw(struct mlx5_txq_data *__rte_restrict txq,
3959 struct mlx5_txq_local *__rte_restrict loc,
3963 /* Check for multi-segment packet. */
3965 MLX5_TXOFF_CONFIG(MULTI) &&
3966 unlikely(NB_SEGS(loc->mbuf) > 1))
3967 return MLX5_TXCMP_CODE_MULTI;
3968 /* Check for TSO packet. */
3970 MLX5_TXOFF_CONFIG(TSO) &&
3971 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG))
3972 return MLX5_TXCMP_CODE_TSO;
3973 /* Check if eMPW is enabled at all. */
3974 if (!MLX5_TXOFF_CONFIG(EMPW))
3975 return MLX5_TXCMP_CODE_SINGLE;
3976 /* Check if eMPW can be engaged. */
3977 if (MLX5_TXOFF_CONFIG(VLAN) &&
3978 unlikely(loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) &&
3979 (!MLX5_TXOFF_CONFIG(INLINE) ||
3980 unlikely((rte_pktmbuf_data_len(loc->mbuf) +
3981 sizeof(struct rte_vlan_hdr)) > txq->inlen_empw))) {
3983 * eMPW does not support VLAN insertion offload,
3984 * we have to inline the entire packet but
3985 * packet is too long for inlining.
3987 return MLX5_TXCMP_CODE_SINGLE;
3989 return MLX5_TXCMP_CODE_EMPW;
3993 * Check the next packet attributes to match with the eMPW batch ones.
3994 * In addition, for legacy MPW the packet length is checked either.
3997 * Pointer to TX queue structure.
3999 * Pointer to Ethernet Segment of eMPW batch.
4001 * Pointer to burst routine local context.
4003 * Length of previous packet in MPW descriptor.
4005 * Configured Tx offloads mask. It is fully defined at
4006 * compile time and may be used for optimization.
4009 * true - packet match with eMPW batch attributes.
4010 * false - no match, eMPW should be restarted.
4012 static __rte_always_inline bool
4013 mlx5_tx_match_empw(struct mlx5_txq_data *__rte_restrict txq,
4014 struct mlx5_wqe_eseg *__rte_restrict es,
4015 struct mlx5_txq_local *__rte_restrict loc,
4019 uint8_t swp_flags = 0;
4021 /* Compare the checksum flags, if any. */
4022 if (MLX5_TXOFF_CONFIG(CSUM) &&
4023 txq_ol_cksum_to_cs(loc->mbuf) != es->cs_flags)
4025 /* Compare the Software Parser offsets and flags. */
4026 if (MLX5_TXOFF_CONFIG(SWP) &&
4027 (es->swp_offs != txq_mbuf_to_swp(loc, &swp_flags, olx) ||
4028 es->swp_flags != swp_flags))
4030 /* Fill metadata field if needed. */
4031 if (MLX5_TXOFF_CONFIG(METADATA) &&
4032 es->metadata != (loc->mbuf->ol_flags & PKT_TX_DYNF_METADATA ?
4033 *RTE_FLOW_DYNF_METADATA(loc->mbuf) : 0))
4035 /* Legacy MPW can send packets with the same lengt only. */
4036 if (MLX5_TXOFF_CONFIG(MPW) &&
4037 dlen != rte_pktmbuf_data_len(loc->mbuf))
4039 /* There must be no VLAN packets in eMPW loop. */
4040 if (MLX5_TXOFF_CONFIG(VLAN))
4041 MLX5_ASSERT(!(loc->mbuf->ol_flags & PKT_TX_VLAN_PKT));
4042 /* Check if the scheduling is requested. */
4043 if (MLX5_TXOFF_CONFIG(TXPP) &&
4044 loc->mbuf->ol_flags & txq->ts_mask)
4050 * Update send loop variables and WQE for eMPW loop
4051 * without data inlining. Number of Data Segments is
4052 * equal to the number of sent packets.
4055 * Pointer to TX queue structure.
4057 * Pointer to burst routine local context.
4059 * Number of packets/Data Segments/Packets.
4061 * Accumulated statistics, bytes sent
4063 * Configured Tx offloads mask. It is fully defined at
4064 * compile time and may be used for optimization.
4067 * true - packet match with eMPW batch attributes.
4068 * false - no match, eMPW should be restarted.
4070 static __rte_always_inline void
4071 mlx5_tx_sdone_empw(struct mlx5_txq_data *__rte_restrict txq,
4072 struct mlx5_txq_local *__rte_restrict loc,
4075 unsigned int olx __rte_unused)
4077 MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
4078 #ifdef MLX5_PMD_SOFT_COUNTERS
4079 /* Update sent data bytes counter. */
4080 txq->stats.obytes += slen;
4084 loc->elts_free -= ds;
4085 loc->pkts_sent += ds;
4087 loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
4088 txq->wqe_ci += (ds + 3) / 4;
4089 loc->wqe_free -= (ds + 3) / 4;
4093 * Update send loop variables and WQE for eMPW loop
4094 * with data inlining. Gets the size of pushed descriptors
4095 * and data to the WQE.
4098 * Pointer to TX queue structure.
4100 * Pointer to burst routine local context.
4102 * Total size of descriptor/data in bytes.
4104 * Accumulated statistics, data bytes sent.
4106 * The base WQE for the eMPW/MPW descriptor.
4108 * Configured Tx offloads mask. It is fully defined at
4109 * compile time and may be used for optimization.
4112 * true - packet match with eMPW batch attributes.
4113 * false - no match, eMPW should be restarted.
4115 static __rte_always_inline void
4116 mlx5_tx_idone_empw(struct mlx5_txq_data *__rte_restrict txq,
4117 struct mlx5_txq_local *__rte_restrict loc,
4120 struct mlx5_wqe *__rte_restrict wqem,
4121 unsigned int olx __rte_unused)
4123 struct mlx5_wqe_dseg *dseg = &wqem->dseg[0];
4125 MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
4126 #ifdef MLX5_PMD_SOFT_COUNTERS
4127 /* Update sent data bytes counter. */
4128 txq->stats.obytes += slen;
4132 if (MLX5_TXOFF_CONFIG(MPW) && dseg->bcount == RTE_BE32(0)) {
4134 * If the legacy MPW session contains the inline packets
4135 * we should set the only inline data segment length
4136 * and align the total length to the segment size.
4138 MLX5_ASSERT(len > sizeof(dseg->bcount));
4139 dseg->bcount = rte_cpu_to_be_32((len - sizeof(dseg->bcount)) |
4140 MLX5_ETH_WQE_DATA_INLINE);
4141 len = (len + MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE + 2;
4144 * The session is not legacy MPW or contains the
4145 * data buffer pointer segments.
4147 MLX5_ASSERT((len % MLX5_WSEG_SIZE) == 0);
4148 len = len / MLX5_WSEG_SIZE + 2;
4150 wqem->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | len);
4151 txq->wqe_ci += (len + 3) / 4;
4152 loc->wqe_free -= (len + 3) / 4;
4153 loc->wqe_last = wqem;
4157 * The set of Tx burst functions for single-segment packets
4158 * without TSO and with Multi-Packet Writing feature support.
4159 * Supports all types of Tx offloads, except multi-packets
4162 * Uses MLX5_OPCODE_EMPW to build WQEs if possible and sends
4163 * as many packet per WQE as it can. If eMPW is not configured
4164 * or packet can not be sent with eMPW (VLAN insertion) the
4165 * ordinary SEND opcode is used and only one packet placed
4168 * Functions stop sending if it encounters the multi-segment
4169 * packet or packet with TSO requested.
4171 * The routines are responsible for storing processed mbuf
4172 * into elts ring buffer and update elts_head if inlining
4173 * offload is requested. Otherwise the copying mbufs to elts
4174 * can be postponed and completed at the end of burst routine.
4177 * Pointer to TX queue structure.
4179 * Packets to transmit.
4181 * Number of packets in array.
4183 * Pointer to burst routine local context.
4185 * Configured Tx offloads mask. It is fully defined at
4186 * compile time and may be used for optimization.
4189 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
4190 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
4191 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
4192 * MLX5_TXCMP_CODE_TSO - TSO packet encountered.
4193 * MLX5_TXCMP_CODE_SINGLE - used inside functions set.
4194 * MLX5_TXCMP_CODE_EMPW - used inside functions set.
4196 * Local context variables updated.
4199 * The routine sends packets with MLX5_OPCODE_EMPW
4200 * without inlining, this is dedicated optimized branch.
4201 * No VLAN insertion is supported.
4203 static __rte_always_inline enum mlx5_txcmp_code
4204 mlx5_tx_burst_empw_simple(struct mlx5_txq_data *__rte_restrict txq,
4205 struct rte_mbuf **__rte_restrict pkts,
4206 unsigned int pkts_n,
4207 struct mlx5_txq_local *__rte_restrict loc,
4211 * Subroutine is the part of mlx5_tx_burst_single()
4212 * and sends single-segment packet with eMPW opcode
4213 * without data inlining.
4215 MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
4216 MLX5_ASSERT(MLX5_TXOFF_CONFIG(EMPW));
4217 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
4218 MLX5_ASSERT(pkts_n > loc->pkts_sent);
4219 static_assert(MLX5_EMPW_MIN_PACKETS >= 2, "invalid min size");
4220 pkts += loc->pkts_sent + 1;
4221 pkts_n -= loc->pkts_sent;
4223 struct mlx5_wqe_dseg *__rte_restrict dseg;
4224 struct mlx5_wqe_eseg *__rte_restrict eseg;
4225 enum mlx5_txcmp_code ret;
4226 unsigned int part, loop;
4227 unsigned int slen = 0;
4230 MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
4231 if (MLX5_TXOFF_CONFIG(TXPP)) {
4232 enum mlx5_txcmp_code wret;
4234 /* Generate WAIT for scheduling if requested. */
4235 wret = mlx5_tx_schedule_send(txq, loc, olx);
4236 if (wret == MLX5_TXCMP_CODE_EXIT)
4237 return MLX5_TXCMP_CODE_EXIT;
4238 if (wret == MLX5_TXCMP_CODE_ERROR)
4239 return MLX5_TXCMP_CODE_ERROR;
4241 part = RTE_MIN(pkts_n, MLX5_TXOFF_CONFIG(MPW) ?
4242 MLX5_MPW_MAX_PACKETS :
4243 MLX5_EMPW_MAX_PACKETS);
4244 if (unlikely(loc->elts_free < part)) {
4245 /* We have no enough elts to save all mbufs. */
4246 if (unlikely(loc->elts_free < MLX5_EMPW_MIN_PACKETS))
4247 return MLX5_TXCMP_CODE_EXIT;
4248 /* But we still able to send at least minimal eMPW. */
4249 part = loc->elts_free;
4251 /* Check whether we have enough WQEs */
4252 if (unlikely(loc->wqe_free < ((2 + part + 3) / 4))) {
4253 if (unlikely(loc->wqe_free <
4254 ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
4255 return MLX5_TXCMP_CODE_EXIT;
4256 part = (loc->wqe_free * 4) - 2;
4258 if (likely(part > 1))
4259 rte_prefetch0(*pkts);
4260 loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4262 * Build eMPW title WQEBB:
4263 * - Control Segment, eMPW opcode
4264 * - Ethernet Segment, no inline
4266 mlx5_tx_cseg_init(txq, loc, loc->wqe_last, part + 2,
4267 MLX5_OPCODE_ENHANCED_MPSW, olx);
4268 mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
4269 olx & ~MLX5_TXOFF_CONFIG_VLAN);
4270 eseg = &loc->wqe_last->eseg;
4271 dseg = &loc->wqe_last->dseg[0];
4273 /* Store the packet length for legacy MPW. */
4274 if (MLX5_TXOFF_CONFIG(MPW))
4275 eseg->mss = rte_cpu_to_be_16
4276 (rte_pktmbuf_data_len(loc->mbuf));
4278 uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
4279 #ifdef MLX5_PMD_SOFT_COUNTERS
4280 /* Update sent data bytes counter. */
4285 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
4287 if (unlikely(--loop == 0))
4289 loc->mbuf = *pkts++;
4290 if (likely(loop > 1))
4291 rte_prefetch0(*pkts);
4292 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4294 * Unroll the completion code to avoid
4295 * returning variable value - it results in
4296 * unoptimized sequent checking in caller.
4298 if (ret == MLX5_TXCMP_CODE_MULTI) {
4300 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
4301 if (unlikely(!loc->elts_free ||
4303 return MLX5_TXCMP_CODE_EXIT;
4304 return MLX5_TXCMP_CODE_MULTI;
4306 MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
4307 if (ret == MLX5_TXCMP_CODE_TSO) {
4309 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
4310 if (unlikely(!loc->elts_free ||
4312 return MLX5_TXCMP_CODE_EXIT;
4313 return MLX5_TXCMP_CODE_TSO;
4315 if (ret == MLX5_TXCMP_CODE_SINGLE) {
4317 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
4318 if (unlikely(!loc->elts_free ||
4320 return MLX5_TXCMP_CODE_EXIT;
4321 return MLX5_TXCMP_CODE_SINGLE;
4323 if (ret != MLX5_TXCMP_CODE_EMPW) {
4326 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
4327 return MLX5_TXCMP_CODE_ERROR;
4330 * Check whether packet parameters coincide
4331 * within assumed eMPW batch:
4332 * - check sum settings
4334 * - software parser settings
4335 * - packets length (legacy MPW only)
4336 * - scheduling is not required
4338 if (!mlx5_tx_match_empw(txq, eseg, loc, dlen, olx)) {
4341 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
4342 if (unlikely(!loc->elts_free ||
4344 return MLX5_TXCMP_CODE_EXIT;
4348 /* Packet attributes match, continue the same eMPW. */
4350 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
4351 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
4353 /* eMPW is built successfully, update loop parameters. */
4355 MLX5_ASSERT(pkts_n >= part);
4356 #ifdef MLX5_PMD_SOFT_COUNTERS
4357 /* Update sent data bytes counter. */
4358 txq->stats.obytes += slen;
4360 loc->elts_free -= part;
4361 loc->pkts_sent += part;
4362 txq->wqe_ci += (2 + part + 3) / 4;
4363 loc->wqe_free -= (2 + part + 3) / 4;
4365 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
4366 return MLX5_TXCMP_CODE_EXIT;
4367 loc->mbuf = *pkts++;
4368 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4369 if (unlikely(ret != MLX5_TXCMP_CODE_EMPW))
4371 /* Continue sending eMPW batches. */
4377 * The routine sends packets with MLX5_OPCODE_EMPW
4378 * with inlining, optionally supports VLAN insertion.
4380 static __rte_always_inline enum mlx5_txcmp_code
4381 mlx5_tx_burst_empw_inline(struct mlx5_txq_data *__rte_restrict txq,
4382 struct rte_mbuf **__rte_restrict pkts,
4383 unsigned int pkts_n,
4384 struct mlx5_txq_local *__rte_restrict loc,
4388 * Subroutine is the part of mlx5_tx_burst_single()
4389 * and sends single-segment packet with eMPW opcode
4390 * with data inlining.
4392 MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
4393 MLX5_ASSERT(MLX5_TXOFF_CONFIG(EMPW));
4394 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
4395 MLX5_ASSERT(pkts_n > loc->pkts_sent);
4396 static_assert(MLX5_EMPW_MIN_PACKETS >= 2, "invalid min size");
4397 pkts += loc->pkts_sent + 1;
4398 pkts_n -= loc->pkts_sent;
4400 struct mlx5_wqe_dseg *__rte_restrict dseg;
4401 struct mlx5_wqe *__rte_restrict wqem;
4402 enum mlx5_txcmp_code ret;
4403 unsigned int room, part, nlim;
4404 unsigned int slen = 0;
4406 MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
4407 if (MLX5_TXOFF_CONFIG(TXPP)) {
4408 enum mlx5_txcmp_code wret;
4410 /* Generate WAIT for scheduling if requested. */
4411 wret = mlx5_tx_schedule_send(txq, loc, olx);
4412 if (wret == MLX5_TXCMP_CODE_EXIT)
4413 return MLX5_TXCMP_CODE_EXIT;
4414 if (wret == MLX5_TXCMP_CODE_ERROR)
4415 return MLX5_TXCMP_CODE_ERROR;
4418 * Limits the amount of packets in one WQE
4419 * to improve CQE latency generation.
4421 nlim = RTE_MIN(pkts_n, MLX5_TXOFF_CONFIG(MPW) ?
4422 MLX5_MPW_INLINE_MAX_PACKETS :
4423 MLX5_EMPW_MAX_PACKETS);
4424 /* Check whether we have minimal amount WQEs */
4425 if (unlikely(loc->wqe_free <
4426 ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
4427 return MLX5_TXCMP_CODE_EXIT;
4428 if (likely(pkts_n > 1))
4429 rte_prefetch0(*pkts);
4430 wqem = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4432 * Build eMPW title WQEBB:
4433 * - Control Segment, eMPW opcode, zero DS
4434 * - Ethernet Segment, no inline
4436 mlx5_tx_cseg_init(txq, loc, wqem, 0,
4437 MLX5_OPCODE_ENHANCED_MPSW, olx);
4438 mlx5_tx_eseg_none(txq, loc, wqem,
4439 olx & ~MLX5_TXOFF_CONFIG_VLAN);
4440 dseg = &wqem->dseg[0];
4441 /* Store the packet length for legacy MPW. */
4442 if (MLX5_TXOFF_CONFIG(MPW))
4443 wqem->eseg.mss = rte_cpu_to_be_16
4444 (rte_pktmbuf_data_len(loc->mbuf));
4445 room = RTE_MIN(MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE,
4446 loc->wqe_free) * MLX5_WQE_SIZE -
4447 MLX5_WQE_CSEG_SIZE -
4449 /* Limit the room for legacy MPW sessions for performance. */
4450 if (MLX5_TXOFF_CONFIG(MPW))
4451 room = RTE_MIN(room,
4452 RTE_MAX(txq->inlen_empw +
4453 sizeof(dseg->bcount) +
4454 (MLX5_TXOFF_CONFIG(VLAN) ?
4455 sizeof(struct rte_vlan_hdr) : 0),
4456 MLX5_MPW_INLINE_MAX_PACKETS *
4457 MLX5_WQE_DSEG_SIZE));
4458 /* Build WQE till we have space, packets and resources. */
4461 uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
4462 uint8_t *dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
4465 MLX5_ASSERT(room >= MLX5_WQE_DSEG_SIZE);
4466 MLX5_ASSERT((room % MLX5_WQE_DSEG_SIZE) == 0);
4467 MLX5_ASSERT((uintptr_t)dseg < (uintptr_t)txq->wqes_end);
4469 * Some Tx offloads may cause an error if
4470 * packet is not long enough, check against
4471 * assumed minimal length.
4473 if (unlikely(dlen <= MLX5_ESEG_MIN_INLINE_SIZE)) {
4475 if (unlikely(!part))
4476 return MLX5_TXCMP_CODE_ERROR;
4478 * We have some successfully built
4479 * packet Data Segments to send.
4481 mlx5_tx_idone_empw(txq, loc, part,
4483 return MLX5_TXCMP_CODE_ERROR;
4485 /* Inline or not inline - that's the Question. */
4486 if (dlen > txq->inlen_empw ||
4487 loc->mbuf->ol_flags & PKT_TX_DYNF_NOINLINE)
4489 if (MLX5_TXOFF_CONFIG(MPW)) {
4490 if (dlen > txq->inlen_send)
4494 /* Open new inline MPW session. */
4495 tlen += sizeof(dseg->bcount);
4496 dseg->bcount = RTE_BE32(0);
4498 (dseg, sizeof(dseg->bcount));
4501 * No pointer and inline descriptor
4502 * intermix for legacy MPW sessions.
4504 if (wqem->dseg[0].bcount)
4508 tlen = sizeof(dseg->bcount) + dlen;
4510 /* Inline entire packet, optional VLAN insertion. */
4511 if (MLX5_TXOFF_CONFIG(VLAN) &&
4512 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
4514 * The packet length must be checked in
4515 * mlx5_tx_able_to_empw() and packet
4516 * fits into inline length guaranteed.
4519 sizeof(struct rte_vlan_hdr)) <=
4521 tlen += sizeof(struct rte_vlan_hdr);
4524 dseg = mlx5_tx_dseg_vlan(txq, loc, dseg,
4526 #ifdef MLX5_PMD_SOFT_COUNTERS
4527 /* Update sent data bytes counter. */
4528 slen += sizeof(struct rte_vlan_hdr);
4533 dseg = mlx5_tx_dseg_empw(txq, loc, dseg,
4536 if (!MLX5_TXOFF_CONFIG(MPW))
4537 tlen = RTE_ALIGN(tlen, MLX5_WSEG_SIZE);
4538 MLX5_ASSERT(room >= tlen);
4541 * Packet data are completely inlined,
4542 * free the packet immediately.
4544 rte_pktmbuf_free_seg(loc->mbuf);
4548 * No pointer and inline descriptor
4549 * intermix for legacy MPW sessions.
4551 if (MLX5_TXOFF_CONFIG(MPW) &&
4553 wqem->dseg[0].bcount == RTE_BE32(0))
4556 * Not inlinable VLAN packets are
4557 * proceeded outside of this routine.
4559 MLX5_ASSERT(room >= MLX5_WQE_DSEG_SIZE);
4560 if (MLX5_TXOFF_CONFIG(VLAN))
4561 MLX5_ASSERT(!(loc->mbuf->ol_flags &
4563 mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
4564 /* We have to store mbuf in elts.*/
4565 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
4566 room -= MLX5_WQE_DSEG_SIZE;
4567 /* Ring buffer wraparound is checked at the loop end.*/
4570 #ifdef MLX5_PMD_SOFT_COUNTERS
4571 /* Update sent data bytes counter. */
4577 if (unlikely(!pkts_n || !loc->elts_free)) {
4579 * We have no resources/packets to
4580 * continue build descriptors.
4583 mlx5_tx_idone_empw(txq, loc, part,
4585 return MLX5_TXCMP_CODE_EXIT;
4587 loc->mbuf = *pkts++;
4588 if (likely(pkts_n > 1))
4589 rte_prefetch0(*pkts);
4590 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4592 * Unroll the completion code to avoid
4593 * returning variable value - it results in
4594 * unoptimized sequent checking in caller.
4596 if (ret == MLX5_TXCMP_CODE_MULTI) {
4598 mlx5_tx_idone_empw(txq, loc, part,
4600 if (unlikely(!loc->elts_free ||
4602 return MLX5_TXCMP_CODE_EXIT;
4603 return MLX5_TXCMP_CODE_MULTI;
4605 MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
4606 if (ret == MLX5_TXCMP_CODE_TSO) {
4608 mlx5_tx_idone_empw(txq, loc, part,
4610 if (unlikely(!loc->elts_free ||
4612 return MLX5_TXCMP_CODE_EXIT;
4613 return MLX5_TXCMP_CODE_TSO;
4615 if (ret == MLX5_TXCMP_CODE_SINGLE) {
4617 mlx5_tx_idone_empw(txq, loc, part,
4619 if (unlikely(!loc->elts_free ||
4621 return MLX5_TXCMP_CODE_EXIT;
4622 return MLX5_TXCMP_CODE_SINGLE;
4624 if (ret != MLX5_TXCMP_CODE_EMPW) {
4627 mlx5_tx_idone_empw(txq, loc, part,
4629 return MLX5_TXCMP_CODE_ERROR;
4631 /* Check if we have minimal room left. */
4633 if (unlikely(!nlim || room < MLX5_WQE_DSEG_SIZE))
4636 * Check whether packet parameters coincide
4637 * within assumed eMPW batch:
4638 * - check sum settings
4640 * - software parser settings
4641 * - packets length (legacy MPW only)
4642 * - scheduling is not required
4644 if (!mlx5_tx_match_empw(txq, &wqem->eseg,
4647 /* Packet attributes match, continue the same eMPW. */
4648 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
4649 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
4652 * We get here to close an existing eMPW
4653 * session and start the new one.
4655 MLX5_ASSERT(pkts_n);
4657 if (unlikely(!part))
4658 return MLX5_TXCMP_CODE_EXIT;
4659 mlx5_tx_idone_empw(txq, loc, part, slen, wqem, olx);
4660 if (unlikely(!loc->elts_free ||
4662 return MLX5_TXCMP_CODE_EXIT;
4663 /* Continue the loop with new eMPW session. */
4669 * The routine sends packets with ordinary MLX5_OPCODE_SEND.
4670 * Data inlining and VLAN insertion are supported.
4672 static __rte_always_inline enum mlx5_txcmp_code
4673 mlx5_tx_burst_single_send(struct mlx5_txq_data *__rte_restrict txq,
4674 struct rte_mbuf **__rte_restrict pkts,
4675 unsigned int pkts_n,
4676 struct mlx5_txq_local *__rte_restrict loc,
4680 * Subroutine is the part of mlx5_tx_burst_single()
4681 * and sends single-segment packet with SEND opcode.
4683 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
4684 MLX5_ASSERT(pkts_n > loc->pkts_sent);
4685 pkts += loc->pkts_sent + 1;
4686 pkts_n -= loc->pkts_sent;
4688 struct mlx5_wqe *__rte_restrict wqe;
4689 enum mlx5_txcmp_code ret;
4691 MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
4692 if (MLX5_TXOFF_CONFIG(TXPP)) {
4693 enum mlx5_txcmp_code wret;
4695 /* Generate WAIT for scheduling if requested. */
4696 wret = mlx5_tx_schedule_send(txq, loc, olx);
4697 if (wret == MLX5_TXCMP_CODE_EXIT)
4698 return MLX5_TXCMP_CODE_EXIT;
4699 if (wret == MLX5_TXCMP_CODE_ERROR)
4700 return MLX5_TXCMP_CODE_ERROR;
4702 if (MLX5_TXOFF_CONFIG(INLINE)) {
4703 unsigned int inlen, vlan = 0;
4705 inlen = rte_pktmbuf_data_len(loc->mbuf);
4706 if (MLX5_TXOFF_CONFIG(VLAN) &&
4707 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
4708 vlan = sizeof(struct rte_vlan_hdr);
4710 static_assert((sizeof(struct rte_vlan_hdr) +
4711 sizeof(struct rte_ether_hdr)) ==
4712 MLX5_ESEG_MIN_INLINE_SIZE,
4713 "invalid min inline data size");
4716 * If inlining is enabled at configuration time
4717 * the limit must be not less than minimal size.
4718 * Otherwise we would do extra check for data
4719 * size to avoid crashes due to length overflow.
4721 MLX5_ASSERT(txq->inlen_send >=
4722 MLX5_ESEG_MIN_INLINE_SIZE);
4723 if (inlen <= txq->inlen_send) {
4724 unsigned int seg_n, wqe_n;
4726 rte_prefetch0(rte_pktmbuf_mtod
4727 (loc->mbuf, uint8_t *));
4728 /* Check against minimal length. */
4729 if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
4730 return MLX5_TXCMP_CODE_ERROR;
4731 if (loc->mbuf->ol_flags &
4732 PKT_TX_DYNF_NOINLINE) {
4734 * The hint flag not to inline packet
4735 * data is set. Check whether we can
4738 if ((!MLX5_TXOFF_CONFIG(EMPW) &&
4740 (MLX5_TXOFF_CONFIG(MPW) &&
4742 if (inlen <= txq->inlen_send)
4745 * The hardware requires the
4746 * minimal inline data header.
4748 goto single_min_inline;
4750 if (MLX5_TXOFF_CONFIG(VLAN) &&
4751 vlan && !txq->vlan_en) {
4753 * We must insert VLAN tag
4754 * by software means.
4756 goto single_part_inline;
4758 goto single_no_inline;
4762 * Completely inlined packet data WQE:
4763 * - Control Segment, SEND opcode
4764 * - Ethernet Segment, no VLAN insertion
4765 * - Data inlined, VLAN optionally inserted
4766 * - Alignment to MLX5_WSEG_SIZE
4767 * Have to estimate amount of WQEBBs
4769 seg_n = (inlen + 3 * MLX5_WSEG_SIZE -
4770 MLX5_ESEG_MIN_INLINE_SIZE +
4771 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
4772 /* Check if there are enough WQEBBs. */
4773 wqe_n = (seg_n + 3) / 4;
4774 if (wqe_n > loc->wqe_free)
4775 return MLX5_TXCMP_CODE_EXIT;
4776 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4777 loc->wqe_last = wqe;
4778 mlx5_tx_cseg_init(txq, loc, wqe, seg_n,
4779 MLX5_OPCODE_SEND, olx);
4780 mlx5_tx_eseg_data(txq, loc, wqe,
4781 vlan, inlen, 0, olx);
4782 txq->wqe_ci += wqe_n;
4783 loc->wqe_free -= wqe_n;
4785 * Packet data are completely inlined,
4786 * free the packet immediately.
4788 rte_pktmbuf_free_seg(loc->mbuf);
4789 } else if ((!MLX5_TXOFF_CONFIG(EMPW) ||
4790 MLX5_TXOFF_CONFIG(MPW)) &&
4793 * If minimal inlining is requested the eMPW
4794 * feature should be disabled due to data is
4795 * inlined into Ethernet Segment, which can
4796 * not contain inlined data for eMPW due to
4797 * segment shared for all packets.
4799 struct mlx5_wqe_dseg *__rte_restrict dseg;
4804 * The inline-mode settings require
4805 * to inline the specified amount of
4806 * data bytes to the Ethernet Segment.
4807 * We should check the free space in
4808 * WQE ring buffer to inline partially.
4811 MLX5_ASSERT(txq->inlen_send >= txq->inlen_mode);
4812 MLX5_ASSERT(inlen > txq->inlen_mode);
4813 MLX5_ASSERT(txq->inlen_mode >=
4814 MLX5_ESEG_MIN_INLINE_SIZE);
4816 * Check whether there are enough free WQEBBs:
4818 * - Ethernet Segment
4819 * - First Segment of inlined Ethernet data
4820 * - ... data continued ...
4821 * - Finishing Data Segment of pointer type
4823 ds = (MLX5_WQE_CSEG_SIZE +
4824 MLX5_WQE_ESEG_SIZE +
4825 MLX5_WQE_DSEG_SIZE +
4827 MLX5_ESEG_MIN_INLINE_SIZE +
4828 MLX5_WQE_DSEG_SIZE +
4829 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
4830 if (loc->wqe_free < ((ds + 3) / 4))
4831 return MLX5_TXCMP_CODE_EXIT;
4833 * Build the ordinary SEND WQE:
4835 * - Ethernet Segment, inline inlen_mode bytes
4836 * - Data Segment of pointer type
4838 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4839 loc->wqe_last = wqe;
4840 mlx5_tx_cseg_init(txq, loc, wqe, ds,
4841 MLX5_OPCODE_SEND, olx);
4842 dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan,
4845 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
4846 txq->inlen_mode - vlan;
4847 inlen -= txq->inlen_mode;
4848 mlx5_tx_dseg_ptr(txq, loc, dseg,
4851 * WQE is built, update the loop parameters
4852 * and got to the next packet.
4854 txq->wqe_ci += (ds + 3) / 4;
4855 loc->wqe_free -= (ds + 3) / 4;
4856 /* We have to store mbuf in elts.*/
4857 MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
4858 txq->elts[txq->elts_head++ & txq->elts_m] =
4866 * Partially inlined packet data WQE, we have
4867 * some space in title WQEBB, we can fill it
4868 * with some packet data. It takes one WQEBB,
4869 * it is available, no extra space check:
4870 * - Control Segment, SEND opcode
4871 * - Ethernet Segment, no VLAN insertion
4872 * - MLX5_ESEG_MIN_INLINE_SIZE bytes of Data
4873 * - Data Segment, pointer type
4875 * We also get here if VLAN insertion is not
4876 * supported by HW, the inline is enabled.
4879 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4880 loc->wqe_last = wqe;
4881 mlx5_tx_cseg_init(txq, loc, wqe, 4,
4882 MLX5_OPCODE_SEND, olx);
4883 mlx5_tx_eseg_dmin(txq, loc, wqe, vlan, olx);
4884 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
4885 MLX5_ESEG_MIN_INLINE_SIZE - vlan;
4887 * The length check is performed above, by
4888 * comparing with txq->inlen_send. We should
4889 * not get overflow here.
4891 MLX5_ASSERT(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
4892 dlen = inlen - MLX5_ESEG_MIN_INLINE_SIZE;
4893 mlx5_tx_dseg_ptr(txq, loc, &wqe->dseg[1],
4897 /* We have to store mbuf in elts.*/
4898 MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
4899 txq->elts[txq->elts_head++ & txq->elts_m] =
4903 #ifdef MLX5_PMD_SOFT_COUNTERS
4904 /* Update sent data bytes counter. */
4905 txq->stats.obytes += vlan +
4906 rte_pktmbuf_data_len(loc->mbuf);
4910 * No inline at all, it means the CPU cycles saving
4911 * is prioritized at configuration, we should not
4912 * copy any packet data to WQE.
4914 * SEND WQE, one WQEBB:
4915 * - Control Segment, SEND opcode
4916 * - Ethernet Segment, optional VLAN, no inline
4917 * - Data Segment, pointer type
4920 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4921 loc->wqe_last = wqe;
4922 mlx5_tx_cseg_init(txq, loc, wqe, 3,
4923 MLX5_OPCODE_SEND, olx);
4924 mlx5_tx_eseg_none(txq, loc, wqe, olx);
4926 (txq, loc, &wqe->dseg[0],
4927 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
4928 rte_pktmbuf_data_len(loc->mbuf), olx);
4932 * We should not store mbuf pointer in elts
4933 * if no inlining is configured, this is done
4934 * by calling routine in a batch copy.
4936 MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
4938 #ifdef MLX5_PMD_SOFT_COUNTERS
4939 /* Update sent data bytes counter. */
4940 txq->stats.obytes += rte_pktmbuf_data_len(loc->mbuf);
4941 if (MLX5_TXOFF_CONFIG(VLAN) &&
4942 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
4943 txq->stats.obytes +=
4944 sizeof(struct rte_vlan_hdr);
4949 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
4950 return MLX5_TXCMP_CODE_EXIT;
4951 loc->mbuf = *pkts++;
4953 rte_prefetch0(*pkts);
4954 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4955 if (unlikely(ret != MLX5_TXCMP_CODE_SINGLE))
4961 static __rte_always_inline enum mlx5_txcmp_code
4962 mlx5_tx_burst_single(struct mlx5_txq_data *__rte_restrict txq,
4963 struct rte_mbuf **__rte_restrict pkts,
4964 unsigned int pkts_n,
4965 struct mlx5_txq_local *__rte_restrict loc,
4968 enum mlx5_txcmp_code ret;
4970 ret = mlx5_tx_able_to_empw(txq, loc, olx, false);
4971 if (ret == MLX5_TXCMP_CODE_SINGLE)
4973 MLX5_ASSERT(ret == MLX5_TXCMP_CODE_EMPW);
4975 /* Optimize for inline/no inline eMPW send. */
4976 ret = (MLX5_TXOFF_CONFIG(INLINE)) ?
4977 mlx5_tx_burst_empw_inline
4978 (txq, pkts, pkts_n, loc, olx) :
4979 mlx5_tx_burst_empw_simple
4980 (txq, pkts, pkts_n, loc, olx);
4981 if (ret != MLX5_TXCMP_CODE_SINGLE)
4983 /* The resources to send one packet should remain. */
4984 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
4986 ret = mlx5_tx_burst_single_send(txq, pkts, pkts_n, loc, olx);
4987 MLX5_ASSERT(ret != MLX5_TXCMP_CODE_SINGLE);
4988 if (ret != MLX5_TXCMP_CODE_EMPW)
4990 /* The resources to send one packet should remain. */
4991 MLX5_ASSERT(loc->elts_free && loc->wqe_free);
4996 * DPDK Tx callback template. This is configured template
4997 * used to generate routines optimized for specified offload setup.
4998 * One of this generated functions is chosen at SQ configuration
5002 * Generic pointer to TX queue structure.
5004 * Packets to transmit.
5006 * Number of packets in array.
5008 * Configured offloads mask, presents the bits of MLX5_TXOFF_CONFIG_xxx
5009 * values. Should be static to take compile time static configuration
5013 * Number of packets successfully transmitted (<= pkts_n).
5015 static __rte_always_inline uint16_t
5016 mlx5_tx_burst_tmpl(struct mlx5_txq_data *__rte_restrict txq,
5017 struct rte_mbuf **__rte_restrict pkts,
5021 struct mlx5_txq_local loc;
5022 enum mlx5_txcmp_code ret;
5025 MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
5026 MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
5027 if (unlikely(!pkts_n))
5031 loc.wqe_last = NULL;
5034 loc.pkts_loop = loc.pkts_sent;
5036 * Check if there are some CQEs, if any:
5037 * - process an encountered errors
5038 * - process the completed WQEs
5039 * - free related mbufs
5040 * - doorbell the NIC about processed CQEs
5042 rte_prefetch0(*(pkts + loc.pkts_sent));
5043 mlx5_tx_handle_completion(txq, olx);
5045 * Calculate the number of available resources - elts and WQEs.
5046 * There are two possible different scenarios:
5047 * - no data inlining into WQEs, one WQEBB may contains up to
5048 * four packets, in this case elts become scarce resource
5049 * - data inlining into WQEs, one packet may require multiple
5050 * WQEBBs, the WQEs become the limiting factor.
5052 MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
5053 loc.elts_free = txq->elts_s -
5054 (uint16_t)(txq->elts_head - txq->elts_tail);
5055 MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
5056 loc.wqe_free = txq->wqe_s -
5057 (uint16_t)(txq->wqe_ci - txq->wqe_pi);
5058 if (unlikely(!loc.elts_free || !loc.wqe_free))
5062 * Fetch the packet from array. Usually this is
5063 * the first packet in series of multi/single
5066 loc.mbuf = *(pkts + loc.pkts_sent);
5067 /* Dedicated branch for multi-segment packets. */
5068 if (MLX5_TXOFF_CONFIG(MULTI) &&
5069 unlikely(NB_SEGS(loc.mbuf) > 1)) {
5071 * Multi-segment packet encountered.
5072 * Hardware is able to process it only
5073 * with SEND/TSO opcodes, one packet
5074 * per WQE, do it in dedicated routine.
5077 MLX5_ASSERT(loc.pkts_sent >= loc.pkts_copy);
5078 part = loc.pkts_sent - loc.pkts_copy;
5079 if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
5081 * There are some single-segment mbufs not
5082 * stored in elts. The mbufs must be in the
5083 * same order as WQEs, so we must copy the
5084 * mbufs to elts here, before the coming
5085 * multi-segment packet mbufs is appended.
5087 mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy,
5089 loc.pkts_copy = loc.pkts_sent;
5091 MLX5_ASSERT(pkts_n > loc.pkts_sent);
5092 ret = mlx5_tx_burst_mseg(txq, pkts, pkts_n, &loc, olx);
5093 if (!MLX5_TXOFF_CONFIG(INLINE))
5094 loc.pkts_copy = loc.pkts_sent;
5096 * These returned code checks are supposed
5097 * to be optimized out due to routine inlining.
5099 if (ret == MLX5_TXCMP_CODE_EXIT) {
5101 * The routine returns this code when
5102 * all packets are sent or there is no
5103 * enough resources to complete request.
5107 if (ret == MLX5_TXCMP_CODE_ERROR) {
5109 * The routine returns this code when
5110 * some error in the incoming packets
5113 txq->stats.oerrors++;
5116 if (ret == MLX5_TXCMP_CODE_SINGLE) {
5118 * The single-segment packet was encountered
5119 * in the array, try to send it with the
5120 * best optimized way, possible engaging eMPW.
5122 goto enter_send_single;
5124 if (MLX5_TXOFF_CONFIG(TSO) &&
5125 ret == MLX5_TXCMP_CODE_TSO) {
5127 * The single-segment TSO packet was
5128 * encountered in the array.
5130 goto enter_send_tso;
5132 /* We must not get here. Something is going wrong. */
5134 txq->stats.oerrors++;
5137 /* Dedicated branch for single-segment TSO packets. */
5138 if (MLX5_TXOFF_CONFIG(TSO) &&
5139 unlikely(loc.mbuf->ol_flags & PKT_TX_TCP_SEG)) {
5141 * TSO might require special way for inlining
5142 * (dedicated parameters) and is sent with
5143 * MLX5_OPCODE_TSO opcode only, provide this
5144 * in dedicated branch.
5147 MLX5_ASSERT(NB_SEGS(loc.mbuf) == 1);
5148 MLX5_ASSERT(pkts_n > loc.pkts_sent);
5149 ret = mlx5_tx_burst_tso(txq, pkts, pkts_n, &loc, olx);
5151 * These returned code checks are supposed
5152 * to be optimized out due to routine inlining.
5154 if (ret == MLX5_TXCMP_CODE_EXIT)
5156 if (ret == MLX5_TXCMP_CODE_ERROR) {
5157 txq->stats.oerrors++;
5160 if (ret == MLX5_TXCMP_CODE_SINGLE)
5161 goto enter_send_single;
5162 if (MLX5_TXOFF_CONFIG(MULTI) &&
5163 ret == MLX5_TXCMP_CODE_MULTI) {
5165 * The multi-segment packet was
5166 * encountered in the array.
5168 goto enter_send_multi;
5170 /* We must not get here. Something is going wrong. */
5172 txq->stats.oerrors++;
5176 * The dedicated branch for the single-segment packets
5177 * without TSO. Often these ones can be sent using
5178 * MLX5_OPCODE_EMPW with multiple packets in one WQE.
5179 * The routine builds the WQEs till it encounters
5180 * the TSO or multi-segment packet (in case if these
5181 * offloads are requested at SQ configuration time).
5184 MLX5_ASSERT(pkts_n > loc.pkts_sent);
5185 ret = mlx5_tx_burst_single(txq, pkts, pkts_n, &loc, olx);
5187 * These returned code checks are supposed
5188 * to be optimized out due to routine inlining.
5190 if (ret == MLX5_TXCMP_CODE_EXIT)
5192 if (ret == MLX5_TXCMP_CODE_ERROR) {
5193 txq->stats.oerrors++;
5196 if (MLX5_TXOFF_CONFIG(MULTI) &&
5197 ret == MLX5_TXCMP_CODE_MULTI) {
5199 * The multi-segment packet was
5200 * encountered in the array.
5202 goto enter_send_multi;
5204 if (MLX5_TXOFF_CONFIG(TSO) &&
5205 ret == MLX5_TXCMP_CODE_TSO) {
5207 * The single-segment TSO packet was
5208 * encountered in the array.
5210 goto enter_send_tso;
5212 /* We must not get here. Something is going wrong. */
5214 txq->stats.oerrors++;
5218 * Main Tx loop is completed, do the rest:
5219 * - set completion request if thresholds are reached
5220 * - doorbell the hardware
5221 * - copy the rest of mbufs to elts (if any)
5223 MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE) ||
5224 loc.pkts_sent >= loc.pkts_copy);
5225 /* Take a shortcut if nothing is sent. */
5226 if (unlikely(loc.pkts_sent == loc.pkts_loop))
5228 /* Request CQE generation if limits are reached. */
5229 mlx5_tx_request_completion(txq, &loc, olx);
5231 * Ring QP doorbell immediately after WQE building completion
5232 * to improve latencies. The pure software related data treatment
5233 * can be completed after doorbell. Tx CQEs for this SQ are
5234 * processed in this thread only by the polling.
5236 * The rdma core library can map doorbell register in two ways,
5237 * depending on the environment variable "MLX5_SHUT_UP_BF":
5239 * - as regular cached memory, the variable is either missing or
5240 * set to zero. This type of mapping may cause the significant
5241 * doorbell register writing latency and requires explicit
5242 * memory write barrier to mitigate this issue and prevent
5245 * - as non-cached memory, the variable is present and set to
5246 * not "0" value. This type of mapping may cause performance
5247 * impact under heavy loading conditions but the explicit write
5248 * memory barrier is not required and it may improve core
5251 * - the legacy behaviour (prior 19.08 release) was to use some
5252 * heuristics to decide whether write memory barrier should
5253 * be performed. This behavior is supported with specifying
5254 * tx_db_nc=2, write barrier is skipped if application
5255 * provides the full recommended burst of packets, it
5256 * supposes the next packets are coming and the write barrier
5257 * will be issued on the next burst (after descriptor writing,
5260 mlx5_tx_dbrec_cond_wmb(txq, loc.wqe_last, !txq->db_nc &&
5261 (!txq->db_heu || pkts_n % MLX5_TX_DEFAULT_BURST));
5262 /* Not all of the mbufs may be stored into elts yet. */
5263 part = MLX5_TXOFF_CONFIG(INLINE) ? 0 : loc.pkts_sent - loc.pkts_copy;
5264 if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
5266 * There are some single-segment mbufs not stored in elts.
5267 * It can be only if the last packet was single-segment.
5268 * The copying is gathered into one place due to it is
5269 * a good opportunity to optimize that with SIMD.
5270 * Unfortunately if inlining is enabled the gaps in
5271 * pointer array may happen due to early freeing of the
5274 mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy, part, olx);
5275 loc.pkts_copy = loc.pkts_sent;
5277 MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
5278 MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
5279 if (pkts_n > loc.pkts_sent) {
5281 * If burst size is large there might be no enough CQE
5282 * fetched from completion queue and no enough resources
5283 * freed to send all the packets.
5288 #ifdef MLX5_PMD_SOFT_COUNTERS
5289 /* Increment sent packets counter. */
5290 txq->stats.opackets += loc.pkts_sent;
5292 return loc.pkts_sent;
5295 /* Generate routines with Enhanced Multi-Packet Write support. */
5296 MLX5_TXOFF_DECL(full_empw,
5297 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_EMPW)
5299 MLX5_TXOFF_DECL(none_empw,
5300 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW)
5302 MLX5_TXOFF_DECL(md_empw,
5303 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5305 MLX5_TXOFF_DECL(mt_empw,
5306 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5307 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5309 MLX5_TXOFF_DECL(mtsc_empw,
5310 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5311 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5312 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5314 MLX5_TXOFF_DECL(mti_empw,
5315 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5316 MLX5_TXOFF_CONFIG_INLINE |
5317 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5319 MLX5_TXOFF_DECL(mtv_empw,
5320 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5321 MLX5_TXOFF_CONFIG_VLAN |
5322 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5324 MLX5_TXOFF_DECL(mtiv_empw,
5325 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5326 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5327 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5329 MLX5_TXOFF_DECL(sc_empw,
5330 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5331 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5333 MLX5_TXOFF_DECL(sci_empw,
5334 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5335 MLX5_TXOFF_CONFIG_INLINE |
5336 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5338 MLX5_TXOFF_DECL(scv_empw,
5339 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5340 MLX5_TXOFF_CONFIG_VLAN |
5341 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5343 MLX5_TXOFF_DECL(sciv_empw,
5344 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5345 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5346 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5348 MLX5_TXOFF_DECL(i_empw,
5349 MLX5_TXOFF_CONFIG_INLINE |
5350 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5352 MLX5_TXOFF_DECL(v_empw,
5353 MLX5_TXOFF_CONFIG_VLAN |
5354 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5356 MLX5_TXOFF_DECL(iv_empw,
5357 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5358 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5360 /* Generate routines without Enhanced Multi-Packet Write support. */
5361 MLX5_TXOFF_DECL(full,
5362 MLX5_TXOFF_CONFIG_FULL)
5364 MLX5_TXOFF_DECL(none,
5365 MLX5_TXOFF_CONFIG_NONE)
5368 MLX5_TXOFF_CONFIG_METADATA)
5371 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5372 MLX5_TXOFF_CONFIG_METADATA)
5374 MLX5_TXOFF_DECL(mtsc,
5375 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5376 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5377 MLX5_TXOFF_CONFIG_METADATA)
5379 MLX5_TXOFF_DECL(mti,
5380 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5381 MLX5_TXOFF_CONFIG_INLINE |
5382 MLX5_TXOFF_CONFIG_METADATA)
5385 MLX5_TXOFF_DECL(mtv,
5386 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5387 MLX5_TXOFF_CONFIG_VLAN |
5388 MLX5_TXOFF_CONFIG_METADATA)
5391 MLX5_TXOFF_DECL(mtiv,
5392 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5393 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5394 MLX5_TXOFF_CONFIG_METADATA)
5397 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5398 MLX5_TXOFF_CONFIG_METADATA)
5400 MLX5_TXOFF_DECL(sci,
5401 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5402 MLX5_TXOFF_CONFIG_INLINE |
5403 MLX5_TXOFF_CONFIG_METADATA)
5406 MLX5_TXOFF_DECL(scv,
5407 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5408 MLX5_TXOFF_CONFIG_VLAN |
5409 MLX5_TXOFF_CONFIG_METADATA)
5412 MLX5_TXOFF_DECL(sciv,
5413 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5414 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5415 MLX5_TXOFF_CONFIG_METADATA)
5418 MLX5_TXOFF_CONFIG_INLINE |
5419 MLX5_TXOFF_CONFIG_METADATA)
5422 MLX5_TXOFF_CONFIG_VLAN |
5423 MLX5_TXOFF_CONFIG_METADATA)
5426 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5427 MLX5_TXOFF_CONFIG_METADATA)
5429 /* Generate routines with timestamp scheduling. */
5430 MLX5_TXOFF_DECL(full_ts_nompw,
5431 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_TXPP)
5433 MLX5_TXOFF_DECL(full_ts_nompwi,
5434 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5435 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5436 MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA |
5437 MLX5_TXOFF_CONFIG_TXPP)
5439 MLX5_TXOFF_DECL(full_ts,
5440 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_TXPP |
5441 MLX5_TXOFF_CONFIG_EMPW)
5443 MLX5_TXOFF_DECL(full_ts_noi,
5444 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5445 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5446 MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA |
5447 MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW)
5449 MLX5_TXOFF_DECL(none_ts,
5450 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_TXPP |
5451 MLX5_TXOFF_CONFIG_EMPW)
5453 MLX5_TXOFF_DECL(mdi_ts,
5454 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_METADATA |
5455 MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW)
5457 MLX5_TXOFF_DECL(mti_ts,
5458 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5459 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_METADATA |
5460 MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW)
5462 MLX5_TXOFF_DECL(mtiv_ts,
5463 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5464 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5465 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_TXPP |
5466 MLX5_TXOFF_CONFIG_EMPW)
5469 * Generate routines with Legacy Multi-Packet Write support.
5470 * This mode is supported by ConnectX-4 Lx only and imposes
5471 * offload limitations, not supported:
5472 * - ACL/Flows (metadata are becoming meaningless)
5473 * - WQE Inline headers
5474 * - SRIOV (E-Switch offloads)
5476 * - tunnel encapsulation/decapsulation
5479 MLX5_TXOFF_DECL(none_mpw,
5480 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW |
5481 MLX5_TXOFF_CONFIG_MPW)
5483 MLX5_TXOFF_DECL(mci_mpw,
5484 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_CSUM |
5485 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_EMPW |
5486 MLX5_TXOFF_CONFIG_MPW)
5488 MLX5_TXOFF_DECL(mc_mpw,
5489 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_CSUM |
5490 MLX5_TXOFF_CONFIG_EMPW | MLX5_TXOFF_CONFIG_MPW)
5492 MLX5_TXOFF_DECL(i_mpw,
5493 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_EMPW |
5494 MLX5_TXOFF_CONFIG_MPW)
5497 * Array of declared and compiled Tx burst function and corresponding
5498 * supported offloads set. The array is used to select the Tx burst
5499 * function for specified offloads set at Tx queue configuration time.
5502 eth_tx_burst_t func;
5505 MLX5_TXOFF_INFO(full_empw,
5506 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5507 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5508 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5509 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5511 MLX5_TXOFF_INFO(none_empw,
5512 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW)
5514 MLX5_TXOFF_INFO(md_empw,
5515 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5517 MLX5_TXOFF_INFO(mt_empw,
5518 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5519 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5521 MLX5_TXOFF_INFO(mtsc_empw,
5522 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5523 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5524 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5526 MLX5_TXOFF_INFO(mti_empw,
5527 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5528 MLX5_TXOFF_CONFIG_INLINE |
5529 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5531 MLX5_TXOFF_INFO(mtv_empw,
5532 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5533 MLX5_TXOFF_CONFIG_VLAN |
5534 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5536 MLX5_TXOFF_INFO(mtiv_empw,
5537 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5538 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5539 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5541 MLX5_TXOFF_INFO(sc_empw,
5542 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5543 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5545 MLX5_TXOFF_INFO(sci_empw,
5546 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5547 MLX5_TXOFF_CONFIG_INLINE |
5548 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5550 MLX5_TXOFF_INFO(scv_empw,
5551 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5552 MLX5_TXOFF_CONFIG_VLAN |
5553 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5555 MLX5_TXOFF_INFO(sciv_empw,
5556 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5557 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5558 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5560 MLX5_TXOFF_INFO(i_empw,
5561 MLX5_TXOFF_CONFIG_INLINE |
5562 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5564 MLX5_TXOFF_INFO(v_empw,
5565 MLX5_TXOFF_CONFIG_VLAN |
5566 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5568 MLX5_TXOFF_INFO(iv_empw,
5569 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5570 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
5572 MLX5_TXOFF_INFO(full_ts_nompw,
5573 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_TXPP)
5575 MLX5_TXOFF_INFO(full_ts_nompwi,
5576 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5577 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5578 MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA |
5579 MLX5_TXOFF_CONFIG_TXPP)
5581 MLX5_TXOFF_INFO(full_ts,
5582 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_TXPP |
5583 MLX5_TXOFF_CONFIG_EMPW)
5585 MLX5_TXOFF_INFO(full_ts_noi,
5586 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5587 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5588 MLX5_TXOFF_CONFIG_VLAN | MLX5_TXOFF_CONFIG_METADATA |
5589 MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW)
5591 MLX5_TXOFF_INFO(none_ts,
5592 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_TXPP |
5593 MLX5_TXOFF_CONFIG_EMPW)
5595 MLX5_TXOFF_INFO(mdi_ts,
5596 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_METADATA |
5597 MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW)
5599 MLX5_TXOFF_INFO(mti_ts,
5600 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5601 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_METADATA |
5602 MLX5_TXOFF_CONFIG_TXPP | MLX5_TXOFF_CONFIG_EMPW)
5604 MLX5_TXOFF_INFO(mtiv_ts,
5605 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5606 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5607 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_TXPP |
5608 MLX5_TXOFF_CONFIG_EMPW)
5610 MLX5_TXOFF_INFO(full,
5611 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5612 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5613 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5614 MLX5_TXOFF_CONFIG_METADATA)
5616 MLX5_TXOFF_INFO(none,
5617 MLX5_TXOFF_CONFIG_NONE)
5620 MLX5_TXOFF_CONFIG_METADATA)
5623 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5624 MLX5_TXOFF_CONFIG_METADATA)
5626 MLX5_TXOFF_INFO(mtsc,
5627 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5628 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5629 MLX5_TXOFF_CONFIG_METADATA)
5631 MLX5_TXOFF_INFO(mti,
5632 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5633 MLX5_TXOFF_CONFIG_INLINE |
5634 MLX5_TXOFF_CONFIG_METADATA)
5636 MLX5_TXOFF_INFO(mtv,
5637 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5638 MLX5_TXOFF_CONFIG_VLAN |
5639 MLX5_TXOFF_CONFIG_METADATA)
5641 MLX5_TXOFF_INFO(mtiv,
5642 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
5643 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5644 MLX5_TXOFF_CONFIG_METADATA)
5647 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5648 MLX5_TXOFF_CONFIG_METADATA)
5650 MLX5_TXOFF_INFO(sci,
5651 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5652 MLX5_TXOFF_CONFIG_INLINE |
5653 MLX5_TXOFF_CONFIG_METADATA)
5655 MLX5_TXOFF_INFO(scv,
5656 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5657 MLX5_TXOFF_CONFIG_VLAN |
5658 MLX5_TXOFF_CONFIG_METADATA)
5660 MLX5_TXOFF_INFO(sciv,
5661 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
5662 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5663 MLX5_TXOFF_CONFIG_METADATA)
5666 MLX5_TXOFF_CONFIG_INLINE |
5667 MLX5_TXOFF_CONFIG_METADATA)
5670 MLX5_TXOFF_CONFIG_VLAN |
5671 MLX5_TXOFF_CONFIG_METADATA)
5674 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
5675 MLX5_TXOFF_CONFIG_METADATA)
5677 MLX5_TXOFF_INFO(none_mpw,
5678 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW |
5679 MLX5_TXOFF_CONFIG_MPW)
5681 MLX5_TXOFF_INFO(mci_mpw,
5682 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_CSUM |
5683 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_EMPW |
5684 MLX5_TXOFF_CONFIG_MPW)
5686 MLX5_TXOFF_INFO(mc_mpw,
5687 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_CSUM |
5688 MLX5_TXOFF_CONFIG_EMPW | MLX5_TXOFF_CONFIG_MPW)
5690 MLX5_TXOFF_INFO(i_mpw,
5691 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_EMPW |
5692 MLX5_TXOFF_CONFIG_MPW)
5696 * Configure the Tx function to use. The routine checks configured
5697 * Tx offloads for the device and selects appropriate Tx burst
5698 * routine. There are multiple Tx burst routines compiled from
5699 * the same template in the most optimal way for the dedicated
5703 * Pointer to private data structure.
5706 * Pointer to selected Tx burst function.
5709 mlx5_select_tx_function(struct rte_eth_dev *dev)
5711 struct mlx5_priv *priv = dev->data->dev_private;
5712 struct mlx5_dev_config *config = &priv->config;
5713 uint64_t tx_offloads = dev->data->dev_conf.txmode.offloads;
5714 unsigned int diff = 0, olx = 0, i, m;
5716 static_assert(MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE <=
5717 MLX5_DSEG_MAX, "invalid WQE max size");
5718 static_assert(MLX5_WQE_CSEG_SIZE == MLX5_WSEG_SIZE,
5719 "invalid WQE Control Segment size");
5720 static_assert(MLX5_WQE_ESEG_SIZE == MLX5_WSEG_SIZE,
5721 "invalid WQE Ethernet Segment size");
5722 static_assert(MLX5_WQE_DSEG_SIZE == MLX5_WSEG_SIZE,
5723 "invalid WQE Data Segment size");
5724 static_assert(MLX5_WQE_SIZE == 4 * MLX5_WSEG_SIZE,
5725 "invalid WQE size");
5727 if (tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS) {
5728 /* We should support Multi-Segment Packets. */
5729 olx |= MLX5_TXOFF_CONFIG_MULTI;
5731 if (tx_offloads & (DEV_TX_OFFLOAD_TCP_TSO |
5732 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5733 DEV_TX_OFFLOAD_GRE_TNL_TSO |
5734 DEV_TX_OFFLOAD_IP_TNL_TSO |
5735 DEV_TX_OFFLOAD_UDP_TNL_TSO)) {
5736 /* We should support TCP Send Offload. */
5737 olx |= MLX5_TXOFF_CONFIG_TSO;
5739 if (tx_offloads & (DEV_TX_OFFLOAD_IP_TNL_TSO |
5740 DEV_TX_OFFLOAD_UDP_TNL_TSO |
5741 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
5742 /* We should support Software Parser for Tunnels. */
5743 olx |= MLX5_TXOFF_CONFIG_SWP;
5745 if (tx_offloads & (DEV_TX_OFFLOAD_IPV4_CKSUM |
5746 DEV_TX_OFFLOAD_UDP_CKSUM |
5747 DEV_TX_OFFLOAD_TCP_CKSUM |
5748 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
5749 /* We should support IP/TCP/UDP Checksums. */
5750 olx |= MLX5_TXOFF_CONFIG_CSUM;
5752 if (tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT) {
5753 /* We should support VLAN insertion. */
5754 olx |= MLX5_TXOFF_CONFIG_VLAN;
5756 if (tx_offloads & DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP &&
5757 rte_mbuf_dynflag_lookup
5758 (RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, NULL) > 0 &&
5759 rte_mbuf_dynfield_lookup
5760 (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL) > 0) {
5761 /* Offload configured, dynamic entities registered. */
5762 olx |= MLX5_TXOFF_CONFIG_TXPP;
5764 if (priv->txqs_n && (*priv->txqs)[0]) {
5765 struct mlx5_txq_data *txd = (*priv->txqs)[0];
5767 if (txd->inlen_send) {
5769 * Check the data inline requirements. Data inline
5770 * is enabled on per device basis, we can check
5771 * the first Tx queue only.
5773 * If device does not support VLAN insertion in WQE
5774 * and some queues are requested to perform VLAN
5775 * insertion offload than inline must be enabled.
5777 olx |= MLX5_TXOFF_CONFIG_INLINE;
5780 if (config->mps == MLX5_MPW_ENHANCED &&
5781 config->txq_inline_min <= 0) {
5783 * The NIC supports Enhanced Multi-Packet Write
5784 * and does not require minimal inline data.
5786 olx |= MLX5_TXOFF_CONFIG_EMPW;
5788 if (rte_flow_dynf_metadata_avail()) {
5789 /* We should support Flow metadata. */
5790 olx |= MLX5_TXOFF_CONFIG_METADATA;
5792 if (config->mps == MLX5_MPW) {
5794 * The NIC supports Legacy Multi-Packet Write.
5795 * The MLX5_TXOFF_CONFIG_MPW controls the
5796 * descriptor building method in combination
5797 * with MLX5_TXOFF_CONFIG_EMPW.
5799 if (!(olx & (MLX5_TXOFF_CONFIG_TSO |
5800 MLX5_TXOFF_CONFIG_SWP |
5801 MLX5_TXOFF_CONFIG_VLAN |
5802 MLX5_TXOFF_CONFIG_METADATA)))
5803 olx |= MLX5_TXOFF_CONFIG_EMPW |
5804 MLX5_TXOFF_CONFIG_MPW;
5807 * Scan the routines table to find the minimal
5808 * satisfying routine with requested offloads.
5810 m = RTE_DIM(txoff_func);
5811 for (i = 0; i < RTE_DIM(txoff_func); i++) {
5814 tmp = txoff_func[i].olx;
5816 /* Meets requested offloads exactly.*/
5820 if ((tmp & olx) != olx) {
5821 /* Does not meet requested offloads at all. */
5824 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_MPW)
5825 /* Do not enable legacy MPW if not configured. */
5827 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_EMPW)
5828 /* Do not enable eMPW if not configured. */
5830 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_INLINE)
5831 /* Do not enable inlining if not configured. */
5833 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_TXPP)
5834 /* Do not enable scheduling if not configured. */
5837 * Some routine meets the requirements.
5838 * Check whether it has minimal amount
5839 * of not requested offloads.
5841 tmp = __builtin_popcountl(tmp & ~olx);
5842 if (m >= RTE_DIM(txoff_func) || tmp < diff) {
5843 /* First or better match, save and continue. */
5849 tmp = txoff_func[i].olx ^ txoff_func[m].olx;
5850 if (__builtin_ffsl(txoff_func[i].olx & ~tmp) <
5851 __builtin_ffsl(txoff_func[m].olx & ~tmp)) {
5852 /* Lighter not requested offload. */
5857 if (m >= RTE_DIM(txoff_func)) {
5858 DRV_LOG(DEBUG, "port %u has no selected Tx function"
5859 " for requested offloads %04X",
5860 dev->data->port_id, olx);
5863 DRV_LOG(DEBUG, "port %u has selected Tx function"
5864 " supporting offloads %04X/%04X",
5865 dev->data->port_id, olx, txoff_func[m].olx);
5866 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_MULTI)
5867 DRV_LOG(DEBUG, "\tMULTI (multi segment)");
5868 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_TSO)
5869 DRV_LOG(DEBUG, "\tTSO (TCP send offload)");
5870 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_SWP)
5871 DRV_LOG(DEBUG, "\tSWP (software parser)");
5872 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_CSUM)
5873 DRV_LOG(DEBUG, "\tCSUM (checksum offload)");
5874 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_INLINE)
5875 DRV_LOG(DEBUG, "\tINLIN (inline data)");
5876 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_VLAN)
5877 DRV_LOG(DEBUG, "\tVLANI (VLAN insertion)");
5878 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_METADATA)
5879 DRV_LOG(DEBUG, "\tMETAD (tx Flow metadata)");
5880 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_TXPP)
5881 DRV_LOG(DEBUG, "\tMETAD (tx Scheduling)");
5882 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_EMPW) {
5883 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_MPW)
5884 DRV_LOG(DEBUG, "\tMPW (Legacy MPW)");
5886 DRV_LOG(DEBUG, "\tEMPW (Enhanced MPW)");
5888 return txoff_func[m].func;
5892 * DPDK callback to get the TX queue information
5895 * Pointer to the device structure.
5897 * @param tx_queue_id
5898 * Tx queue identificator.
5901 * Pointer to the TX queue information structure.
5908 mlx5_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
5909 struct rte_eth_txq_info *qinfo)
5911 struct mlx5_priv *priv = dev->data->dev_private;
5912 struct mlx5_txq_data *txq = (*priv->txqs)[tx_queue_id];
5913 struct mlx5_txq_ctrl *txq_ctrl =
5914 container_of(txq, struct mlx5_txq_ctrl, txq);
5918 qinfo->nb_desc = txq->elts_s;
5919 qinfo->conf.tx_thresh.pthresh = 0;
5920 qinfo->conf.tx_thresh.hthresh = 0;
5921 qinfo->conf.tx_thresh.wthresh = 0;
5922 qinfo->conf.tx_rs_thresh = 0;
5923 qinfo->conf.tx_free_thresh = 0;
5924 qinfo->conf.tx_deferred_start = txq_ctrl ? 0 : 1;
5925 qinfo->conf.offloads = dev->data->dev_conf.txmode.offloads;
5929 * DPDK callback to get the TX packet burst mode information
5932 * Pointer to the device structure.
5934 * @param tx_queue_id
5935 * Tx queue identificatior.
5938 * Pointer to the burts mode information.
5941 * 0 as success, -EINVAL as failure.
5945 mlx5_tx_burst_mode_get(struct rte_eth_dev *dev,
5946 uint16_t tx_queue_id __rte_unused,
5947 struct rte_eth_burst_mode *mode)
5949 eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
5950 unsigned int i, olx;
5952 for (i = 0; i < RTE_DIM(txoff_func); i++) {
5953 if (pkt_burst == txoff_func[i].func) {
5954 olx = txoff_func[i].olx;
5955 snprintf(mode->info, sizeof(mode->info),
5956 "%s%s%s%s%s%s%s%s%s",
5957 (olx & MLX5_TXOFF_CONFIG_EMPW) ?
5958 ((olx & MLX5_TXOFF_CONFIG_MPW) ?
5959 "Legacy MPW" : "Enhanced MPW") : "No MPW",
5960 (olx & MLX5_TXOFF_CONFIG_MULTI) ?
5962 (olx & MLX5_TXOFF_CONFIG_TSO) ?
5964 (olx & MLX5_TXOFF_CONFIG_SWP) ?
5966 (olx & MLX5_TXOFF_CONFIG_CSUM) ?
5968 (olx & MLX5_TXOFF_CONFIG_INLINE) ?
5970 (olx & MLX5_TXOFF_CONFIG_VLAN) ?
5972 (olx & MLX5_TXOFF_CONFIG_METADATA) ?
5974 (olx & MLX5_TXOFF_CONFIG_TXPP) ?