1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015-2019 Mellanox Technologies, Ltd
12 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
14 #pragma GCC diagnostic ignored "-Wpedantic"
16 #include <infiniband/verbs.h>
17 #include <infiniband/mlx5dv.h>
19 #pragma GCC diagnostic error "-Wpedantic"
23 #include <rte_mempool.h>
24 #include <rte_prefetch.h>
25 #include <rte_common.h>
26 #include <rte_branch_prediction.h>
27 #include <rte_ether.h>
28 #include <rte_cycles.h>
31 #include "mlx5_utils.h"
32 #include "mlx5_rxtx.h"
33 #include "mlx5_autoconf.h"
34 #include "mlx5_defs.h"
37 /* TX burst subroutines return codes. */
38 enum mlx5_txcmp_code {
39 MLX5_TXCMP_CODE_EXIT = 0,
40 MLX5_TXCMP_CODE_ERROR,
41 MLX5_TXCMP_CODE_SINGLE,
42 MLX5_TXCMP_CODE_MULTI,
48 * These defines are used to configure Tx burst routine option set
49 * supported at compile time. The not specified options are optimized out
50 * out due to if conditions can be explicitly calculated at compile time.
51 * The offloads with bigger runtime check (require more CPU cycles to
52 * skip) overhead should have the bigger index - this is needed to
53 * select the better matching routine function if no exact match and
54 * some offloads are not actually requested.
56 #define MLX5_TXOFF_CONFIG_MULTI (1u << 0) /* Multi-segment packets.*/
57 #define MLX5_TXOFF_CONFIG_TSO (1u << 1) /* TCP send offload supported.*/
58 #define MLX5_TXOFF_CONFIG_SWP (1u << 2) /* Tunnels/SW Parser offloads.*/
59 #define MLX5_TXOFF_CONFIG_CSUM (1u << 3) /* Check Sums offloaded. */
60 #define MLX5_TXOFF_CONFIG_INLINE (1u << 4) /* Data inlining supported. */
61 #define MLX5_TXOFF_CONFIG_VLAN (1u << 5) /* VLAN insertion supported.*/
62 #define MLX5_TXOFF_CONFIG_METADATA (1u << 6) /* Flow metadata. */
63 #define MLX5_TXOFF_CONFIG_EMPW (1u << 8) /* Enhanced MPW supported.*/
65 /* The most common offloads groups. */
66 #define MLX5_TXOFF_CONFIG_NONE 0
67 #define MLX5_TXOFF_CONFIG_FULL (MLX5_TXOFF_CONFIG_MULTI | \
68 MLX5_TXOFF_CONFIG_TSO | \
69 MLX5_TXOFF_CONFIG_SWP | \
70 MLX5_TXOFF_CONFIG_CSUM | \
71 MLX5_TXOFF_CONFIG_INLINE | \
72 MLX5_TXOFF_CONFIG_VLAN | \
73 MLX5_TXOFF_CONFIG_METADATA)
75 #define MLX5_TXOFF_CONFIG(mask) (olx & MLX5_TXOFF_CONFIG_##mask)
77 #define MLX5_TXOFF_DECL(func, olx) \
78 static uint16_t mlx5_tx_burst_##func(void *txq, \
79 struct rte_mbuf **pkts, \
82 return mlx5_tx_burst_tmpl((struct mlx5_txq_data *)txq, \
83 pkts, pkts_n, (olx)); \
86 #define MLX5_TXOFF_INFO(func, olx) {mlx5_tx_burst_##func, olx},
88 static __rte_always_inline uint32_t
89 rxq_cq_to_pkt_type(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe);
91 static __rte_always_inline int
92 mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
93 uint16_t cqe_cnt, volatile struct mlx5_mini_cqe8 **mcqe);
95 static __rte_always_inline uint32_t
96 rxq_cq_to_ol_flags(volatile struct mlx5_cqe *cqe);
98 static __rte_always_inline void
99 rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
100 volatile struct mlx5_cqe *cqe, uint32_t rss_hash_res);
102 static __rte_always_inline void
103 mprq_buf_replace(struct mlx5_rxq_data *rxq, uint16_t rq_idx,
104 const unsigned int strd_n);
107 mlx5_queue_state_modify(struct rte_eth_dev *dev,
108 struct mlx5_mp_arg_queue_state_modify *sm);
111 mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *restrict tcp,
112 volatile struct mlx5_cqe *restrict cqe,
116 mlx5_lro_update_hdr(uint8_t *restrict padd,
117 volatile struct mlx5_cqe *restrict cqe,
120 uint32_t mlx5_ptype_table[] __rte_cache_aligned = {
121 [0xff] = RTE_PTYPE_ALL_MASK, /* Last entry for errored packet. */
124 uint8_t mlx5_cksum_table[1 << 10] __rte_cache_aligned;
125 uint8_t mlx5_swp_types_table[1 << 10] __rte_cache_aligned;
128 * Build a table to translate Rx completion flags to packet type.
130 * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
133 mlx5_set_ptype_table(void)
136 uint32_t (*p)[RTE_DIM(mlx5_ptype_table)] = &mlx5_ptype_table;
138 /* Last entry must not be overwritten, reserved for errored packet. */
139 for (i = 0; i < RTE_DIM(mlx5_ptype_table) - 1; ++i)
140 (*p)[i] = RTE_PTYPE_UNKNOWN;
142 * The index to the array should have:
143 * bit[1:0] = l3_hdr_type
144 * bit[4:2] = l4_hdr_type
147 * bit[7] = outer_l3_type
150 (*p)[0x00] = RTE_PTYPE_L2_ETHER;
152 (*p)[0x01] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
153 RTE_PTYPE_L4_NONFRAG;
154 (*p)[0x02] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
155 RTE_PTYPE_L4_NONFRAG;
157 (*p)[0x21] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
159 (*p)[0x22] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
162 (*p)[0x05] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
164 (*p)[0x06] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
166 (*p)[0x0d] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
168 (*p)[0x0e] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
170 (*p)[0x11] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
172 (*p)[0x12] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
175 (*p)[0x09] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
177 (*p)[0x0a] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
179 /* Repeat with outer_l3_type being set. Just in case. */
180 (*p)[0x81] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
181 RTE_PTYPE_L4_NONFRAG;
182 (*p)[0x82] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
183 RTE_PTYPE_L4_NONFRAG;
184 (*p)[0xa1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
186 (*p)[0xa2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
188 (*p)[0x85] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
190 (*p)[0x86] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
192 (*p)[0x8d] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
194 (*p)[0x8e] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
196 (*p)[0x91] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
198 (*p)[0x92] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
200 (*p)[0x89] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
202 (*p)[0x8a] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
205 (*p)[0x40] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
206 (*p)[0x41] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
207 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
208 RTE_PTYPE_INNER_L4_NONFRAG;
209 (*p)[0x42] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
210 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
211 RTE_PTYPE_INNER_L4_NONFRAG;
212 (*p)[0xc0] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
213 (*p)[0xc1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
214 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
215 RTE_PTYPE_INNER_L4_NONFRAG;
216 (*p)[0xc2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
217 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
218 RTE_PTYPE_INNER_L4_NONFRAG;
219 /* Tunneled - Fragmented */
220 (*p)[0x61] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
221 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
222 RTE_PTYPE_INNER_L4_FRAG;
223 (*p)[0x62] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
224 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
225 RTE_PTYPE_INNER_L4_FRAG;
226 (*p)[0xe1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
227 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
228 RTE_PTYPE_INNER_L4_FRAG;
229 (*p)[0xe2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
230 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
231 RTE_PTYPE_INNER_L4_FRAG;
233 (*p)[0x45] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
234 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
235 RTE_PTYPE_INNER_L4_TCP;
236 (*p)[0x46] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
237 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
238 RTE_PTYPE_INNER_L4_TCP;
239 (*p)[0x4d] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
240 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
241 RTE_PTYPE_INNER_L4_TCP;
242 (*p)[0x4e] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
243 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
244 RTE_PTYPE_INNER_L4_TCP;
245 (*p)[0x51] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
246 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
247 RTE_PTYPE_INNER_L4_TCP;
248 (*p)[0x52] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
249 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
250 RTE_PTYPE_INNER_L4_TCP;
251 (*p)[0xc5] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
252 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
253 RTE_PTYPE_INNER_L4_TCP;
254 (*p)[0xc6] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
255 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
256 RTE_PTYPE_INNER_L4_TCP;
257 (*p)[0xcd] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
258 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
259 RTE_PTYPE_INNER_L4_TCP;
260 (*p)[0xce] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
261 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
262 RTE_PTYPE_INNER_L4_TCP;
263 (*p)[0xd1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
264 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
265 RTE_PTYPE_INNER_L4_TCP;
266 (*p)[0xd2] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
267 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
268 RTE_PTYPE_INNER_L4_TCP;
270 (*p)[0x49] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
271 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
272 RTE_PTYPE_INNER_L4_UDP;
273 (*p)[0x4a] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
274 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
275 RTE_PTYPE_INNER_L4_UDP;
276 (*p)[0xc9] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
277 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
278 RTE_PTYPE_INNER_L4_UDP;
279 (*p)[0xca] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
280 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
281 RTE_PTYPE_INNER_L4_UDP;
285 * Build a table to translate packet to checksum type of Verbs.
288 mlx5_set_cksum_table(void)
294 * The index should have:
295 * bit[0] = PKT_TX_TCP_SEG
296 * bit[2:3] = PKT_TX_UDP_CKSUM, PKT_TX_TCP_CKSUM
297 * bit[4] = PKT_TX_IP_CKSUM
298 * bit[8] = PKT_TX_OUTER_IP_CKSUM
301 for (i = 0; i < RTE_DIM(mlx5_cksum_table); ++i) {
304 /* Tunneled packet. */
305 if (i & (1 << 8)) /* Outer IP. */
306 v |= MLX5_ETH_WQE_L3_CSUM;
307 if (i & (1 << 4)) /* Inner IP. */
308 v |= MLX5_ETH_WQE_L3_INNER_CSUM;
309 if (i & (3 << 2 | 1 << 0)) /* L4 or TSO. */
310 v |= MLX5_ETH_WQE_L4_INNER_CSUM;
313 if (i & (1 << 4)) /* IP. */
314 v |= MLX5_ETH_WQE_L3_CSUM;
315 if (i & (3 << 2 | 1 << 0)) /* L4 or TSO. */
316 v |= MLX5_ETH_WQE_L4_CSUM;
318 mlx5_cksum_table[i] = v;
323 * Build a table to translate packet type of mbuf to SWP type of Verbs.
326 mlx5_set_swp_types_table(void)
332 * The index should have:
333 * bit[0:1] = PKT_TX_L4_MASK
334 * bit[4] = PKT_TX_IPV6
335 * bit[8] = PKT_TX_OUTER_IPV6
336 * bit[9] = PKT_TX_OUTER_UDP
338 for (i = 0; i < RTE_DIM(mlx5_swp_types_table); ++i) {
341 v |= MLX5_ETH_WQE_L3_OUTER_IPV6;
343 v |= MLX5_ETH_WQE_L4_OUTER_UDP;
345 v |= MLX5_ETH_WQE_L3_INNER_IPV6;
346 if ((i & 3) == (PKT_TX_UDP_CKSUM >> 52))
347 v |= MLX5_ETH_WQE_L4_INNER_UDP;
348 mlx5_swp_types_table[i] = v;
353 * Set Software Parser flags and offsets in Ethernet Segment of WQE.
354 * Flags must be preliminary initialized to zero.
357 * Pointer to burst routine local context.
359 * Pointer to store Software Parser flags
361 * Configured Tx offloads mask. It is fully defined at
362 * compile time and may be used for optimization.
365 * Software Parser offsets packed in dword.
366 * Software Parser flags are set by pointer.
368 static __rte_always_inline uint32_t
369 txq_mbuf_to_swp(struct mlx5_txq_local *restrict loc,
374 unsigned int idx, off;
377 if (!MLX5_TXOFF_CONFIG(SWP))
379 ol = loc->mbuf->ol_flags;
380 tunnel = ol & PKT_TX_TUNNEL_MASK;
382 * Check whether Software Parser is required.
383 * Only customized tunnels may ask for.
385 if (likely(tunnel != PKT_TX_TUNNEL_UDP && tunnel != PKT_TX_TUNNEL_IP))
388 * The index should have:
389 * bit[0:1] = PKT_TX_L4_MASK
390 * bit[4] = PKT_TX_IPV6
391 * bit[8] = PKT_TX_OUTER_IPV6
392 * bit[9] = PKT_TX_OUTER_UDP
394 idx = (ol & (PKT_TX_L4_MASK | PKT_TX_IPV6 | PKT_TX_OUTER_IPV6)) >> 52;
395 idx |= (tunnel == PKT_TX_TUNNEL_UDP) ? (1 << 9) : 0;
396 *swp_flags = mlx5_swp_types_table[idx];
398 * Set offsets for SW parser. Since ConnectX-5, SW parser just
399 * complements HW parser. SW parser starts to engage only if HW parser
400 * can't reach a header. For the older devices, HW parser will not kick
401 * in if any of SWP offsets is set. Therefore, all of the L3 offsets
402 * should be set regardless of HW offload.
404 off = loc->mbuf->outer_l2_len;
405 if (MLX5_TXOFF_CONFIG(VLAN) && ol & PKT_TX_VLAN_PKT)
406 off += sizeof(struct rte_vlan_hdr);
407 set = (off >> 1) << 8; /* Outer L3 offset. */
408 off += loc->mbuf->outer_l3_len;
409 if (tunnel == PKT_TX_TUNNEL_UDP)
410 set |= off >> 1; /* Outer L4 offset. */
411 if (ol & (PKT_TX_IPV4 | PKT_TX_IPV6)) { /* Inner IP. */
412 const uint64_t csum = ol & PKT_TX_L4_MASK;
413 off += loc->mbuf->l2_len;
414 set |= (off >> 1) << 24; /* Inner L3 offset. */
415 if (csum == PKT_TX_TCP_CKSUM ||
416 csum == PKT_TX_UDP_CKSUM ||
417 (MLX5_TXOFF_CONFIG(TSO) && ol & PKT_TX_TCP_SEG)) {
418 off += loc->mbuf->l3_len;
419 set |= (off >> 1) << 16; /* Inner L4 offset. */
422 set = rte_cpu_to_le_32(set);
427 * Convert the Checksum offloads to Verbs.
430 * Pointer to the mbuf.
433 * Converted checksum flags.
435 static __rte_always_inline uint8_t
436 txq_ol_cksum_to_cs(struct rte_mbuf *buf)
439 uint8_t is_tunnel = !!(buf->ol_flags & PKT_TX_TUNNEL_MASK);
440 const uint64_t ol_flags_mask = PKT_TX_TCP_SEG | PKT_TX_L4_MASK |
441 PKT_TX_IP_CKSUM | PKT_TX_OUTER_IP_CKSUM;
444 * The index should have:
445 * bit[0] = PKT_TX_TCP_SEG
446 * bit[2:3] = PKT_TX_UDP_CKSUM, PKT_TX_TCP_CKSUM
447 * bit[4] = PKT_TX_IP_CKSUM
448 * bit[8] = PKT_TX_OUTER_IP_CKSUM
451 idx = ((buf->ol_flags & ol_flags_mask) >> 50) | (!!is_tunnel << 9);
452 return mlx5_cksum_table[idx];
456 * Internal function to compute the number of used descriptors in an RX queue
462 * The number of used rx descriptor.
465 rx_queue_count(struct mlx5_rxq_data *rxq)
467 struct rxq_zip *zip = &rxq->zip;
468 volatile struct mlx5_cqe *cqe;
469 const unsigned int cqe_n = (1 << rxq->cqe_n);
470 const unsigned int cqe_cnt = cqe_n - 1;
474 /* if we are processing a compressed cqe */
476 used = zip->cqe_cnt - zip->ca;
482 cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
483 while (check_cqe(cqe, cqe_n, cq_ci) != MLX5_CQE_STATUS_HW_OWN) {
487 op_own = cqe->op_own;
488 if (MLX5_CQE_FORMAT(op_own) == MLX5_COMPRESSED)
489 n = rte_be_to_cpu_32(cqe->byte_cnt);
494 cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
496 used = RTE_MIN(used, (1U << rxq->elts_n) - 1);
501 * DPDK callback to check the status of a rx descriptor.
506 * The index of the descriptor in the ring.
509 * The status of the tx descriptor.
512 mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset)
514 struct mlx5_rxq_data *rxq = rx_queue;
515 struct mlx5_rxq_ctrl *rxq_ctrl =
516 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
517 struct rte_eth_dev *dev = ETH_DEV(rxq_ctrl->priv);
519 if (dev->rx_pkt_burst != mlx5_rx_burst) {
523 if (offset >= (1 << rxq->elts_n)) {
527 if (offset < rx_queue_count(rxq))
528 return RTE_ETH_RX_DESC_DONE;
529 return RTE_ETH_RX_DESC_AVAIL;
533 * DPDK callback to get the number of used descriptors in a RX queue
536 * Pointer to the device structure.
542 * The number of used rx descriptor.
543 * -EINVAL if the queue is invalid
546 mlx5_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
548 struct mlx5_priv *priv = dev->data->dev_private;
549 struct mlx5_rxq_data *rxq;
551 if (dev->rx_pkt_burst != mlx5_rx_burst) {
555 rxq = (*priv->rxqs)[rx_queue_id];
560 return rx_queue_count(rxq);
563 #define MLX5_SYSTEM_LOG_DIR "/var/log"
565 * Dump debug information to log file.
570 * If not NULL this string is printed as a header to the output
571 * and the output will be in hexadecimal view.
573 * This is the buffer address to print out.
575 * The number of bytes to dump out.
578 mlx5_dump_debug_information(const char *fname, const char *hex_title,
579 const void *buf, unsigned int hex_len)
583 MKSTR(path, "%s/%s", MLX5_SYSTEM_LOG_DIR, fname);
584 fd = fopen(path, "a+");
586 DRV_LOG(WARNING, "cannot open %s for debug dump\n",
588 MKSTR(path2, "./%s", fname);
589 fd = fopen(path2, "a+");
591 DRV_LOG(ERR, "cannot open %s for debug dump\n",
595 DRV_LOG(INFO, "New debug dump in file %s\n", path2);
597 DRV_LOG(INFO, "New debug dump in file %s\n", path);
600 rte_hexdump(fd, hex_title, buf, hex_len);
602 fprintf(fd, "%s", (const char *)buf);
603 fprintf(fd, "\n\n\n");
608 * Move QP from error state to running state and initialize indexes.
611 * Pointer to TX queue control structure.
614 * 0 on success, else -1.
617 tx_recover_qp(struct mlx5_txq_ctrl *txq_ctrl)
619 struct mlx5_mp_arg_queue_state_modify sm = {
621 .queue_id = txq_ctrl->txq.idx,
624 if (mlx5_queue_state_modify(ETH_DEV(txq_ctrl->priv), &sm))
626 txq_ctrl->txq.wqe_ci = 0;
627 txq_ctrl->txq.wqe_pi = 0;
628 txq_ctrl->txq.elts_comp = 0;
632 /* Return 1 if the error CQE is signed otherwise, sign it and return 0. */
634 check_err_cqe_seen(volatile struct mlx5_err_cqe *err_cqe)
636 static const uint8_t magic[] = "seen";
640 for (i = 0; i < sizeof(magic); ++i)
641 if (!ret || err_cqe->rsvd1[i] != magic[i]) {
643 err_cqe->rsvd1[i] = magic[i];
652 * Pointer to TX queue structure.
654 * Pointer to the error CQE.
657 * The last Tx buffer element to free.
660 mlx5_tx_error_cqe_handle(struct mlx5_txq_data *restrict txq,
661 volatile struct mlx5_err_cqe *err_cqe)
663 if (err_cqe->syndrome != MLX5_CQE_SYNDROME_WR_FLUSH_ERR) {
664 const uint16_t wqe_m = ((1 << txq->wqe_n) - 1);
665 struct mlx5_txq_ctrl *txq_ctrl =
666 container_of(txq, struct mlx5_txq_ctrl, txq);
667 uint16_t new_wqe_pi = rte_be_to_cpu_16(err_cqe->wqe_counter);
668 int seen = check_err_cqe_seen(err_cqe);
670 if (!seen && txq_ctrl->dump_file_n <
671 txq_ctrl->priv->config.max_dump_files_num) {
672 MKSTR(err_str, "Unexpected CQE error syndrome "
673 "0x%02x CQN = %u SQN = %u wqe_counter = %u "
674 "wq_ci = %u cq_ci = %u", err_cqe->syndrome,
675 txq->cqe_s, txq->qp_num_8s >> 8,
676 rte_be_to_cpu_16(err_cqe->wqe_counter),
677 txq->wqe_ci, txq->cq_ci);
678 MKSTR(name, "dpdk_mlx5_port_%u_txq_%u_index_%u_%u",
679 PORT_ID(txq_ctrl->priv), txq->idx,
680 txq_ctrl->dump_file_n, (uint32_t)rte_rdtsc());
681 mlx5_dump_debug_information(name, NULL, err_str, 0);
682 mlx5_dump_debug_information(name, "MLX5 Error CQ:",
683 (const void *)((uintptr_t)
687 mlx5_dump_debug_information(name, "MLX5 Error SQ:",
688 (const void *)((uintptr_t)
692 txq_ctrl->dump_file_n++;
696 * Count errors in WQEs units.
697 * Later it can be improved to count error packets,
698 * for example, by SQ parsing to find how much packets
699 * should be counted for each WQE.
701 txq->stats.oerrors += ((txq->wqe_ci & wqe_m) -
703 if (tx_recover_qp(txq_ctrl) == 0) {
705 /* Release all the remaining buffers. */
706 return txq->elts_head;
708 /* Recovering failed - try again later on the same WQE. */
712 /* Do not release buffers. */
713 return txq->elts_tail;
717 * Translate RX completion flags to packet type.
720 * Pointer to RX queue structure.
724 * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
727 * Packet type for struct rte_mbuf.
729 static inline uint32_t
730 rxq_cq_to_pkt_type(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe)
733 uint8_t pinfo = cqe->pkt_info;
734 uint16_t ptype = cqe->hdr_type_etc;
737 * The index to the array should have:
738 * bit[1:0] = l3_hdr_type
739 * bit[4:2] = l4_hdr_type
742 * bit[7] = outer_l3_type
744 idx = ((pinfo & 0x3) << 6) | ((ptype & 0xfc00) >> 10);
745 return mlx5_ptype_table[idx] | rxq->tunnel * !!(idx & (1 << 6));
749 * Initialize Rx WQ and indexes.
752 * Pointer to RX queue structure.
755 mlx5_rxq_initialize(struct mlx5_rxq_data *rxq)
757 const unsigned int wqe_n = 1 << rxq->elts_n;
760 for (i = 0; (i != wqe_n); ++i) {
761 volatile struct mlx5_wqe_data_seg *scat;
765 if (mlx5_rxq_mprq_enabled(rxq)) {
766 struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[i];
768 scat = &((volatile struct mlx5_wqe_mprq *)
770 addr = (uintptr_t)mlx5_mprq_buf_addr(buf,
771 1 << rxq->strd_num_n);
772 byte_count = (1 << rxq->strd_sz_n) *
773 (1 << rxq->strd_num_n);
775 struct rte_mbuf *buf = (*rxq->elts)[i];
777 scat = &((volatile struct mlx5_wqe_data_seg *)
779 addr = rte_pktmbuf_mtod(buf, uintptr_t);
780 byte_count = DATA_LEN(buf);
782 /* scat->addr must be able to store a pointer. */
783 assert(sizeof(scat->addr) >= sizeof(uintptr_t));
784 *scat = (struct mlx5_wqe_data_seg){
785 .addr = rte_cpu_to_be_64(addr),
786 .byte_count = rte_cpu_to_be_32(byte_count),
787 .lkey = mlx5_rx_addr2mr(rxq, addr),
790 rxq->consumed_strd = 0;
791 rxq->decompressed = 0;
793 rxq->zip = (struct rxq_zip){
796 /* Update doorbell counter. */
797 rxq->rq_ci = wqe_n >> rxq->sges_n;
799 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
803 * Modify a Verbs/DevX queue state.
804 * This must be called from the primary process.
807 * Pointer to Ethernet device.
809 * State modify request parameters.
812 * 0 in case of success else non-zero value and rte_errno is set.
815 mlx5_queue_state_modify_primary(struct rte_eth_dev *dev,
816 const struct mlx5_mp_arg_queue_state_modify *sm)
819 struct mlx5_priv *priv = dev->data->dev_private;
822 struct mlx5_rxq_data *rxq = (*priv->rxqs)[sm->queue_id];
823 struct mlx5_rxq_ctrl *rxq_ctrl =
824 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
826 if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV) {
827 struct ibv_wq_attr mod = {
828 .attr_mask = IBV_WQ_ATTR_STATE,
829 .wq_state = sm->state,
832 ret = mlx5_glue->modify_wq(rxq_ctrl->obj->wq, &mod);
833 } else { /* rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ. */
834 struct mlx5_devx_modify_rq_attr rq_attr;
836 memset(&rq_attr, 0, sizeof(rq_attr));
837 if (sm->state == IBV_WQS_RESET) {
838 rq_attr.rq_state = MLX5_RQC_STATE_ERR;
839 rq_attr.state = MLX5_RQC_STATE_RST;
840 } else if (sm->state == IBV_WQS_RDY) {
841 rq_attr.rq_state = MLX5_RQC_STATE_RST;
842 rq_attr.state = MLX5_RQC_STATE_RDY;
843 } else if (sm->state == IBV_WQS_ERR) {
844 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
845 rq_attr.state = MLX5_RQC_STATE_ERR;
847 ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq,
851 DRV_LOG(ERR, "Cannot change Rx WQ state to %u - %s\n",
852 sm->state, strerror(errno));
857 struct mlx5_txq_data *txq = (*priv->txqs)[sm->queue_id];
858 struct mlx5_txq_ctrl *txq_ctrl =
859 container_of(txq, struct mlx5_txq_ctrl, txq);
860 struct ibv_qp_attr mod = {
861 .qp_state = IBV_QPS_RESET,
862 .port_num = (uint8_t)priv->ibv_port,
864 struct ibv_qp *qp = txq_ctrl->ibv->qp;
866 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
868 DRV_LOG(ERR, "Cannot change the Tx QP state to RESET "
869 "%s\n", strerror(errno));
873 mod.qp_state = IBV_QPS_INIT;
874 ret = mlx5_glue->modify_qp(qp, &mod,
875 (IBV_QP_STATE | IBV_QP_PORT));
877 DRV_LOG(ERR, "Cannot change Tx QP state to INIT %s\n",
882 mod.qp_state = IBV_QPS_RTR;
883 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
885 DRV_LOG(ERR, "Cannot change Tx QP state to RTR %s\n",
890 mod.qp_state = IBV_QPS_RTS;
891 ret = mlx5_glue->modify_qp(qp, &mod, IBV_QP_STATE);
893 DRV_LOG(ERR, "Cannot change Tx QP state to RTS %s\n",
903 * Modify a Verbs queue state.
906 * Pointer to Ethernet device.
908 * State modify request parameters.
911 * 0 in case of success else non-zero value.
914 mlx5_queue_state_modify(struct rte_eth_dev *dev,
915 struct mlx5_mp_arg_queue_state_modify *sm)
919 switch (rte_eal_process_type()) {
920 case RTE_PROC_PRIMARY:
921 ret = mlx5_queue_state_modify_primary(dev, sm);
923 case RTE_PROC_SECONDARY:
924 ret = mlx5_mp_req_queue_state_modify(dev, sm);
934 * The function inserts the RQ state to reset when the first error CQE is
935 * shown, then drains the CQ by the caller function loop. When the CQ is empty,
936 * it moves the RQ state to ready and initializes the RQ.
937 * Next CQE identification and error counting are in the caller responsibility.
940 * Pointer to RX queue structure.
941 * @param[in] mbuf_prepare
942 * Whether to prepare mbufs for the RQ.
945 * -1 in case of recovery error, otherwise the CQE status.
948 mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t mbuf_prepare)
950 const uint16_t cqe_n = 1 << rxq->cqe_n;
951 const uint16_t cqe_mask = cqe_n - 1;
952 const unsigned int wqe_n = 1 << rxq->elts_n;
953 struct mlx5_rxq_ctrl *rxq_ctrl =
954 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
956 volatile struct mlx5_cqe *cqe;
957 volatile struct mlx5_err_cqe *err_cqe;
959 .cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask],
961 struct mlx5_mp_arg_queue_state_modify sm;
964 switch (rxq->err_state) {
965 case MLX5_RXQ_ERR_STATE_NO_ERROR:
966 rxq->err_state = MLX5_RXQ_ERR_STATE_NEED_RESET;
968 case MLX5_RXQ_ERR_STATE_NEED_RESET:
970 sm.queue_id = rxq->idx;
971 sm.state = IBV_WQS_RESET;
972 if (mlx5_queue_state_modify(ETH_DEV(rxq_ctrl->priv), &sm))
974 if (rxq_ctrl->dump_file_n <
975 rxq_ctrl->priv->config.max_dump_files_num) {
976 MKSTR(err_str, "Unexpected CQE error syndrome "
977 "0x%02x CQN = %u RQN = %u wqe_counter = %u"
978 " rq_ci = %u cq_ci = %u", u.err_cqe->syndrome,
979 rxq->cqn, rxq_ctrl->wqn,
980 rte_be_to_cpu_16(u.err_cqe->wqe_counter),
981 rxq->rq_ci << rxq->sges_n, rxq->cq_ci);
982 MKSTR(name, "dpdk_mlx5_port_%u_rxq_%u_%u",
983 rxq->port_id, rxq->idx, (uint32_t)rte_rdtsc());
984 mlx5_dump_debug_information(name, NULL, err_str, 0);
985 mlx5_dump_debug_information(name, "MLX5 Error CQ:",
986 (const void *)((uintptr_t)
988 sizeof(*u.cqe) * cqe_n);
989 mlx5_dump_debug_information(name, "MLX5 Error RQ:",
990 (const void *)((uintptr_t)
993 rxq_ctrl->dump_file_n++;
995 rxq->err_state = MLX5_RXQ_ERR_STATE_NEED_READY;
997 case MLX5_RXQ_ERR_STATE_NEED_READY:
998 ret = check_cqe(u.cqe, cqe_n, rxq->cq_ci);
999 if (ret == MLX5_CQE_STATUS_HW_OWN) {
1001 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1004 * The RQ consumer index must be zeroed while moving
1005 * from RESET state to RDY state.
1007 *rxq->rq_db = rte_cpu_to_be_32(0);
1010 sm.queue_id = rxq->idx;
1011 sm.state = IBV_WQS_RDY;
1012 if (mlx5_queue_state_modify(ETH_DEV(rxq_ctrl->priv),
1016 const uint16_t q_mask = wqe_n - 1;
1018 struct rte_mbuf **elt;
1020 unsigned int n = wqe_n - (rxq->rq_ci -
1023 for (i = 0; i < (int)n; ++i) {
1024 elt_idx = (rxq->rq_ci + i) & q_mask;
1025 elt = &(*rxq->elts)[elt_idx];
1026 *elt = rte_mbuf_raw_alloc(rxq->mp);
1028 for (i--; i >= 0; --i) {
1029 elt_idx = (rxq->rq_ci +
1033 rte_pktmbuf_free_seg
1040 mlx5_rxq_initialize(rxq);
1041 rxq->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
1050 * Get size of the next packet for a given CQE. For compressed CQEs, the
1051 * consumer index is updated only once all packets of the current one have
1055 * Pointer to RX queue.
1059 * Store pointer to mini-CQE if compressed. Otherwise, the pointer is not
1063 * 0 in case of empty CQE, otherwise the packet size in bytes.
1066 mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
1067 uint16_t cqe_cnt, volatile struct mlx5_mini_cqe8 **mcqe)
1069 struct rxq_zip *zip = &rxq->zip;
1070 uint16_t cqe_n = cqe_cnt + 1;
1076 /* Process compressed data in the CQE and mini arrays. */
1078 volatile struct mlx5_mini_cqe8 (*mc)[8] =
1079 (volatile struct mlx5_mini_cqe8 (*)[8])
1080 (uintptr_t)(&(*rxq->cqes)[zip->ca &
1083 len = rte_be_to_cpu_32((*mc)[zip->ai & 7].byte_cnt);
1084 *mcqe = &(*mc)[zip->ai & 7];
1085 if ((++zip->ai & 7) == 0) {
1086 /* Invalidate consumed CQEs */
1089 while (idx != end) {
1090 (*rxq->cqes)[idx & cqe_cnt].op_own =
1091 MLX5_CQE_INVALIDATE;
1095 * Increment consumer index to skip the number
1096 * of CQEs consumed. Hardware leaves holes in
1097 * the CQ ring for software use.
1102 if (unlikely(rxq->zip.ai == rxq->zip.cqe_cnt)) {
1103 /* Invalidate the rest */
1107 while (idx != end) {
1108 (*rxq->cqes)[idx & cqe_cnt].op_own =
1109 MLX5_CQE_INVALIDATE;
1112 rxq->cq_ci = zip->cq_ci;
1116 * No compressed data, get next CQE and verify if it is
1123 ret = check_cqe(cqe, cqe_n, rxq->cq_ci);
1124 if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
1125 if (unlikely(ret == MLX5_CQE_STATUS_ERR ||
1127 ret = mlx5_rx_err_handle(rxq, 0);
1128 if (ret == MLX5_CQE_STATUS_HW_OWN ||
1136 op_own = cqe->op_own;
1137 if (MLX5_CQE_FORMAT(op_own) == MLX5_COMPRESSED) {
1138 volatile struct mlx5_mini_cqe8 (*mc)[8] =
1139 (volatile struct mlx5_mini_cqe8 (*)[8])
1140 (uintptr_t)(&(*rxq->cqes)
1144 /* Fix endianness. */
1145 zip->cqe_cnt = rte_be_to_cpu_32(cqe->byte_cnt);
1147 * Current mini array position is the one
1148 * returned by check_cqe64().
1150 * If completion comprises several mini arrays,
1151 * as a special case the second one is located
1152 * 7 CQEs after the initial CQE instead of 8
1153 * for subsequent ones.
1155 zip->ca = rxq->cq_ci;
1156 zip->na = zip->ca + 7;
1157 /* Compute the next non compressed CQE. */
1159 zip->cq_ci = rxq->cq_ci + zip->cqe_cnt;
1160 /* Get packet size to return. */
1161 len = rte_be_to_cpu_32((*mc)[0].byte_cnt);
1164 /* Prefetch all to be invalidated */
1167 while (idx != end) {
1168 rte_prefetch0(&(*rxq->cqes)[(idx) &
1173 len = rte_be_to_cpu_32(cqe->byte_cnt);
1176 if (unlikely(rxq->err_state)) {
1177 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_cnt];
1178 ++rxq->stats.idropped;
1186 * Translate RX completion flags to offload flags.
1192 * Offload flags (ol_flags) for struct rte_mbuf.
1194 static inline uint32_t
1195 rxq_cq_to_ol_flags(volatile struct mlx5_cqe *cqe)
1197 uint32_t ol_flags = 0;
1198 uint16_t flags = rte_be_to_cpu_16(cqe->hdr_type_etc);
1202 MLX5_CQE_RX_L3_HDR_VALID,
1203 PKT_RX_IP_CKSUM_GOOD) |
1205 MLX5_CQE_RX_L4_HDR_VALID,
1206 PKT_RX_L4_CKSUM_GOOD);
1211 * Fill in mbuf fields from RX completion flags.
1212 * Note that pkt->ol_flags should be initialized outside of this function.
1215 * Pointer to RX queue.
1220 * @param rss_hash_res
1221 * Packet RSS Hash result.
1224 rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
1225 volatile struct mlx5_cqe *cqe, uint32_t rss_hash_res)
1227 /* Update packet information. */
1228 pkt->packet_type = rxq_cq_to_pkt_type(rxq, cqe);
1229 if (rss_hash_res && rxq->rss_hash) {
1230 pkt->hash.rss = rss_hash_res;
1231 pkt->ol_flags |= PKT_RX_RSS_HASH;
1233 if (rxq->mark && MLX5_FLOW_MARK_IS_VALID(cqe->sop_drop_qpn)) {
1234 pkt->ol_flags |= PKT_RX_FDIR;
1235 if (cqe->sop_drop_qpn !=
1236 rte_cpu_to_be_32(MLX5_FLOW_MARK_DEFAULT)) {
1237 uint32_t mark = cqe->sop_drop_qpn;
1239 pkt->ol_flags |= PKT_RX_FDIR_ID;
1240 pkt->hash.fdir.hi = mlx5_flow_mark_get(mark);
1244 pkt->ol_flags |= rxq_cq_to_ol_flags(cqe);
1245 if (rxq->vlan_strip &&
1246 (cqe->hdr_type_etc & rte_cpu_to_be_16(MLX5_CQE_VLAN_STRIPPED))) {
1247 pkt->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
1248 pkt->vlan_tci = rte_be_to_cpu_16(cqe->vlan_info);
1250 if (rxq->hw_timestamp) {
1251 pkt->timestamp = rte_be_to_cpu_64(cqe->timestamp);
1252 pkt->ol_flags |= PKT_RX_TIMESTAMP;
1257 * DPDK callback for RX.
1260 * Generic pointer to RX queue structure.
1262 * Array to store received packets.
1264 * Maximum number of packets in array.
1267 * Number of packets successfully received (<= pkts_n).
1270 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1272 struct mlx5_rxq_data *rxq = dpdk_rxq;
1273 const unsigned int wqe_cnt = (1 << rxq->elts_n) - 1;
1274 const unsigned int cqe_cnt = (1 << rxq->cqe_n) - 1;
1275 const unsigned int sges_n = rxq->sges_n;
1276 struct rte_mbuf *pkt = NULL;
1277 struct rte_mbuf *seg = NULL;
1278 volatile struct mlx5_cqe *cqe =
1279 &(*rxq->cqes)[rxq->cq_ci & cqe_cnt];
1281 unsigned int rq_ci = rxq->rq_ci << sges_n;
1282 int len = 0; /* keep its value across iterations. */
1285 unsigned int idx = rq_ci & wqe_cnt;
1286 volatile struct mlx5_wqe_data_seg *wqe =
1287 &((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[idx];
1288 struct rte_mbuf *rep = (*rxq->elts)[idx];
1289 volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1290 uint32_t rss_hash_res;
1298 rep = rte_mbuf_raw_alloc(rxq->mp);
1299 if (unlikely(rep == NULL)) {
1300 ++rxq->stats.rx_nombuf;
1303 * no buffers before we even started,
1304 * bail out silently.
1308 while (pkt != seg) {
1309 assert(pkt != (*rxq->elts)[idx]);
1313 rte_mbuf_raw_free(pkt);
1319 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_cnt];
1320 len = mlx5_rx_poll_len(rxq, cqe, cqe_cnt, &mcqe);
1322 rte_mbuf_raw_free(rep);
1326 assert(len >= (rxq->crc_present << 2));
1328 /* If compressed, take hash result from mini-CQE. */
1329 rss_hash_res = rte_be_to_cpu_32(mcqe == NULL ?
1331 mcqe->rx_hash_result);
1332 rxq_cq_to_mbuf(rxq, pkt, cqe, rss_hash_res);
1333 if (rxq->crc_present)
1334 len -= RTE_ETHER_CRC_LEN;
1336 if (cqe->lro_num_seg > 1) {
1338 (rte_pktmbuf_mtod(pkt, uint8_t *), cqe,
1340 pkt->ol_flags |= PKT_RX_LRO;
1341 pkt->tso_segsz = len / cqe->lro_num_seg;
1344 DATA_LEN(rep) = DATA_LEN(seg);
1345 PKT_LEN(rep) = PKT_LEN(seg);
1346 SET_DATA_OFF(rep, DATA_OFF(seg));
1347 PORT(rep) = PORT(seg);
1348 (*rxq->elts)[idx] = rep;
1350 * Fill NIC descriptor with the new buffer. The lkey and size
1351 * of the buffers are already known, only the buffer address
1354 wqe->addr = rte_cpu_to_be_64(rte_pktmbuf_mtod(rep, uintptr_t));
1355 /* If there's only one MR, no need to replace LKey in WQE. */
1356 if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
1357 wqe->lkey = mlx5_rx_mb2mr(rxq, rep);
1358 if (len > DATA_LEN(seg)) {
1359 len -= DATA_LEN(seg);
1364 DATA_LEN(seg) = len;
1365 #ifdef MLX5_PMD_SOFT_COUNTERS
1366 /* Increment bytes counter. */
1367 rxq->stats.ibytes += PKT_LEN(pkt);
1369 /* Return packet. */
1374 /* Align consumer index to the next stride. */
1379 if (unlikely((i == 0) && ((rq_ci >> sges_n) == rxq->rq_ci)))
1381 /* Update the consumer index. */
1382 rxq->rq_ci = rq_ci >> sges_n;
1384 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1386 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1387 #ifdef MLX5_PMD_SOFT_COUNTERS
1388 /* Increment packets counter. */
1389 rxq->stats.ipackets += i;
1395 * Update LRO packet TCP header.
1396 * The HW LRO feature doesn't update the TCP header after coalescing the
1397 * TCP segments but supplies information in CQE to fill it by SW.
1400 * Pointer to the TCP header.
1402 * Pointer to the completion entry..
1404 * The L3 pseudo-header checksum.
1407 mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *restrict tcp,
1408 volatile struct mlx5_cqe *restrict cqe,
1411 uint8_t l4_type = (rte_be_to_cpu_16(cqe->hdr_type_etc) &
1412 MLX5_CQE_L4_TYPE_MASK) >> MLX5_CQE_L4_TYPE_SHIFT;
1414 * The HW calculates only the TCP payload checksum, need to complete
1415 * the TCP header checksum and the L3 pseudo-header checksum.
1417 uint32_t csum = phcsum + cqe->csum;
1419 if (l4_type == MLX5_L4_HDR_TYPE_TCP_EMPTY_ACK ||
1420 l4_type == MLX5_L4_HDR_TYPE_TCP_WITH_ACL) {
1421 tcp->tcp_flags |= RTE_TCP_ACK_FLAG;
1422 tcp->recv_ack = cqe->lro_ack_seq_num;
1423 tcp->rx_win = cqe->lro_tcp_win;
1425 if (cqe->lro_tcppsh_abort_dupack & MLX5_CQE_LRO_PUSH_MASK)
1426 tcp->tcp_flags |= RTE_TCP_PSH_FLAG;
1428 csum += rte_raw_cksum(tcp, (tcp->data_off & 0xF) * 4);
1429 csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
1430 csum = (~csum) & 0xffff;
1437 * Update LRO packet headers.
1438 * The HW LRO feature doesn't update the L3/TCP headers after coalescing the
1439 * TCP segments but supply information in CQE to fill it by SW.
1442 * The packet address.
1444 * Pointer to the completion entry..
1446 * The packet length.
1449 mlx5_lro_update_hdr(uint8_t *restrict padd,
1450 volatile struct mlx5_cqe *restrict cqe,
1454 struct rte_ether_hdr *eth;
1455 struct rte_vlan_hdr *vlan;
1456 struct rte_ipv4_hdr *ipv4;
1457 struct rte_ipv6_hdr *ipv6;
1458 struct rte_tcp_hdr *tcp;
1463 uint16_t proto = h.eth->ether_type;
1467 while (proto == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
1468 proto == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
1469 proto = h.vlan->eth_proto;
1472 if (proto == RTE_BE16(RTE_ETHER_TYPE_IPV4)) {
1473 h.ipv4->time_to_live = cqe->lro_min_ttl;
1474 h.ipv4->total_length = rte_cpu_to_be_16(len - (h.hdr - padd));
1475 h.ipv4->hdr_checksum = 0;
1476 h.ipv4->hdr_checksum = rte_ipv4_cksum(h.ipv4);
1477 phcsum = rte_ipv4_phdr_cksum(h.ipv4, 0);
1480 h.ipv6->hop_limits = cqe->lro_min_ttl;
1481 h.ipv6->payload_len = rte_cpu_to_be_16(len - (h.hdr - padd) -
1483 phcsum = rte_ipv6_phdr_cksum(h.ipv6, 0);
1486 mlx5_lro_update_tcp_hdr(h.tcp, cqe, phcsum);
1490 mlx5_mprq_buf_free_cb(void *addr __rte_unused, void *opaque)
1492 struct mlx5_mprq_buf *buf = opaque;
1494 if (rte_atomic16_read(&buf->refcnt) == 1) {
1495 rte_mempool_put(buf->mp, buf);
1496 } else if (rte_atomic16_add_return(&buf->refcnt, -1) == 0) {
1497 rte_atomic16_set(&buf->refcnt, 1);
1498 rte_mempool_put(buf->mp, buf);
1503 mlx5_mprq_buf_free(struct mlx5_mprq_buf *buf)
1505 mlx5_mprq_buf_free_cb(NULL, buf);
1509 mprq_buf_replace(struct mlx5_rxq_data *rxq, uint16_t rq_idx,
1510 const unsigned int strd_n)
1512 struct mlx5_mprq_buf *rep = rxq->mprq_repl;
1513 volatile struct mlx5_wqe_data_seg *wqe =
1514 &((volatile struct mlx5_wqe_mprq *)rxq->wqes)[rq_idx].dseg;
1517 assert(rep != NULL);
1518 /* Replace MPRQ buf. */
1519 (*rxq->mprq_bufs)[rq_idx] = rep;
1521 addr = mlx5_mprq_buf_addr(rep, strd_n);
1522 wqe->addr = rte_cpu_to_be_64((uintptr_t)addr);
1523 /* If there's only one MR, no need to replace LKey in WQE. */
1524 if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
1525 wqe->lkey = mlx5_rx_addr2mr(rxq, (uintptr_t)addr);
1526 /* Stash a mbuf for next replacement. */
1527 if (likely(!rte_mempool_get(rxq->mprq_mp, (void **)&rep)))
1528 rxq->mprq_repl = rep;
1530 rxq->mprq_repl = NULL;
1534 * DPDK callback for RX with Multi-Packet RQ support.
1537 * Generic pointer to RX queue structure.
1539 * Array to store received packets.
1541 * Maximum number of packets in array.
1544 * Number of packets successfully received (<= pkts_n).
1547 mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1549 struct mlx5_rxq_data *rxq = dpdk_rxq;
1550 const unsigned int strd_n = 1 << rxq->strd_num_n;
1551 const unsigned int strd_sz = 1 << rxq->strd_sz_n;
1552 const unsigned int strd_shift =
1553 MLX5_MPRQ_STRIDE_SHIFT_BYTE * rxq->strd_shift_en;
1554 const unsigned int cq_mask = (1 << rxq->cqe_n) - 1;
1555 const unsigned int wq_mask = (1 << rxq->elts_n) - 1;
1556 volatile struct mlx5_cqe *cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1558 uint32_t rq_ci = rxq->rq_ci;
1559 uint16_t consumed_strd = rxq->consumed_strd;
1560 uint16_t headroom_sz = rxq->strd_headroom_en * RTE_PKTMBUF_HEADROOM;
1561 struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1563 while (i < pkts_n) {
1564 struct rte_mbuf *pkt;
1572 volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1573 uint32_t rss_hash_res = 0;
1574 uint8_t lro_num_seg;
1576 if (consumed_strd == strd_n) {
1577 /* Replace WQE only if the buffer is still in use. */
1578 if (rte_atomic16_read(&buf->refcnt) > 1) {
1579 mprq_buf_replace(rxq, rq_ci & wq_mask, strd_n);
1580 /* Release the old buffer. */
1581 mlx5_mprq_buf_free(buf);
1582 } else if (unlikely(rxq->mprq_repl == NULL)) {
1583 struct mlx5_mprq_buf *rep;
1586 * Currently, the MPRQ mempool is out of buffer
1587 * and doing memcpy regardless of the size of Rx
1588 * packet. Retry allocation to get back to
1591 if (!rte_mempool_get(rxq->mprq_mp,
1593 rxq->mprq_repl = rep;
1595 /* Advance to the next WQE. */
1598 buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1600 cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1601 ret = mlx5_rx_poll_len(rxq, cqe, cq_mask, &mcqe);
1605 strd_cnt = (byte_cnt & MLX5_MPRQ_STRIDE_NUM_MASK) >>
1606 MLX5_MPRQ_STRIDE_NUM_SHIFT;
1608 consumed_strd += strd_cnt;
1609 if (byte_cnt & MLX5_MPRQ_FILLER_MASK)
1612 rss_hash_res = rte_be_to_cpu_32(cqe->rx_hash_res);
1613 strd_idx = rte_be_to_cpu_16(cqe->wqe_counter);
1615 /* mini-CQE for MPRQ doesn't have hash result. */
1616 strd_idx = rte_be_to_cpu_16(mcqe->stride_idx);
1618 assert(strd_idx < strd_n);
1619 assert(!((rte_be_to_cpu_16(cqe->wqe_id) ^ rq_ci) & wq_mask));
1620 lro_num_seg = cqe->lro_num_seg;
1622 * Currently configured to receive a packet per a stride. But if
1623 * MTU is adjusted through kernel interface, device could
1624 * consume multiple strides without raising an error. In this
1625 * case, the packet should be dropped because it is bigger than
1626 * the max_rx_pkt_len.
1628 if (unlikely(!lro_num_seg && strd_cnt > 1)) {
1629 ++rxq->stats.idropped;
1632 pkt = rte_pktmbuf_alloc(rxq->mp);
1633 if (unlikely(pkt == NULL)) {
1634 ++rxq->stats.rx_nombuf;
1637 len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
1638 assert((int)len >= (rxq->crc_present << 2));
1639 if (rxq->crc_present)
1640 len -= RTE_ETHER_CRC_LEN;
1641 offset = strd_idx * strd_sz + strd_shift;
1642 addr = RTE_PTR_ADD(mlx5_mprq_buf_addr(buf, strd_n), offset);
1644 * Memcpy packets to the target mbuf if:
1645 * - The size of packet is smaller than mprq_max_memcpy_len.
1646 * - Out of buffer in the Mempool for Multi-Packet RQ.
1648 if (len <= rxq->mprq_max_memcpy_len || rxq->mprq_repl == NULL) {
1650 * When memcpy'ing packet due to out-of-buffer, the
1651 * packet must be smaller than the target mbuf.
1653 if (unlikely(rte_pktmbuf_tailroom(pkt) < len)) {
1654 rte_pktmbuf_free_seg(pkt);
1655 ++rxq->stats.idropped;
1658 rte_memcpy(rte_pktmbuf_mtod(pkt, void *), addr, len);
1659 DATA_LEN(pkt) = len;
1661 rte_iova_t buf_iova;
1662 struct rte_mbuf_ext_shared_info *shinfo;
1663 uint16_t buf_len = strd_cnt * strd_sz;
1666 /* Increment the refcnt of the whole chunk. */
1667 rte_atomic16_add_return(&buf->refcnt, 1);
1668 assert((uint16_t)rte_atomic16_read(&buf->refcnt) <=
1670 buf_addr = RTE_PTR_SUB(addr, headroom_sz);
1672 * MLX5 device doesn't use iova but it is necessary in a
1673 * case where the Rx packet is transmitted via a
1676 buf_iova = rte_mempool_virt2iova(buf) +
1677 RTE_PTR_DIFF(buf_addr, buf);
1678 shinfo = &buf->shinfos[strd_idx];
1679 rte_mbuf_ext_refcnt_set(shinfo, 1);
1681 * EXT_ATTACHED_MBUF will be set to pkt->ol_flags when
1682 * attaching the stride to mbuf and more offload flags
1683 * will be added below by calling rxq_cq_to_mbuf().
1684 * Other fields will be overwritten.
1686 rte_pktmbuf_attach_extbuf(pkt, buf_addr, buf_iova,
1688 /* Set mbuf head-room. */
1689 pkt->data_off = headroom_sz;
1690 assert(pkt->ol_flags == EXT_ATTACHED_MBUF);
1692 * Prevent potential overflow due to MTU change through
1695 if (unlikely(rte_pktmbuf_tailroom(pkt) < len)) {
1696 rte_pktmbuf_free_seg(pkt);
1697 ++rxq->stats.idropped;
1700 DATA_LEN(pkt) = len;
1702 * LRO packet may consume all the stride memory, in this
1703 * case packet head-room space is not guaranteed so must
1704 * to add an empty mbuf for the head-room.
1706 if (!rxq->strd_headroom_en) {
1707 struct rte_mbuf *headroom_mbuf =
1708 rte_pktmbuf_alloc(rxq->mp);
1710 if (unlikely(headroom_mbuf == NULL)) {
1711 rte_pktmbuf_free_seg(pkt);
1712 ++rxq->stats.rx_nombuf;
1715 PORT(pkt) = rxq->port_id;
1716 NEXT(headroom_mbuf) = pkt;
1717 pkt = headroom_mbuf;
1721 rxq_cq_to_mbuf(rxq, pkt, cqe, rss_hash_res);
1722 if (lro_num_seg > 1) {
1723 mlx5_lro_update_hdr(addr, cqe, len);
1724 pkt->ol_flags |= PKT_RX_LRO;
1725 pkt->tso_segsz = strd_sz;
1728 PORT(pkt) = rxq->port_id;
1729 #ifdef MLX5_PMD_SOFT_COUNTERS
1730 /* Increment bytes counter. */
1731 rxq->stats.ibytes += PKT_LEN(pkt);
1733 /* Return packet. */
1737 /* Update the consumer indexes. */
1738 rxq->consumed_strd = consumed_strd;
1740 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1741 if (rq_ci != rxq->rq_ci) {
1744 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1746 #ifdef MLX5_PMD_SOFT_COUNTERS
1747 /* Increment packets counter. */
1748 rxq->stats.ipackets += i;
1754 * Dummy DPDK callback for TX.
1756 * This function is used to temporarily replace the real callback during
1757 * unsafe control operations on the queue, or in case of error.
1760 * Generic pointer to TX queue structure.
1762 * Packets to transmit.
1764 * Number of packets in array.
1767 * Number of packets successfully transmitted (<= pkts_n).
1770 removed_tx_burst(void *dpdk_txq __rte_unused,
1771 struct rte_mbuf **pkts __rte_unused,
1772 uint16_t pkts_n __rte_unused)
1779 * Dummy DPDK callback for RX.
1781 * This function is used to temporarily replace the real callback during
1782 * unsafe control operations on the queue, or in case of error.
1785 * Generic pointer to RX queue structure.
1787 * Array to store received packets.
1789 * Maximum number of packets in array.
1792 * Number of packets successfully received (<= pkts_n).
1795 removed_rx_burst(void *dpdk_txq __rte_unused,
1796 struct rte_mbuf **pkts __rte_unused,
1797 uint16_t pkts_n __rte_unused)
1804 * Vectorized Rx/Tx routines are not compiled in when required vector
1805 * instructions are not supported on a target architecture. The following null
1806 * stubs are needed for linkage when those are not included outside of this file
1807 * (e.g. mlx5_rxtx_vec_sse.c for x86).
1811 mlx5_rx_burst_vec(void *dpdk_txq __rte_unused,
1812 struct rte_mbuf **pkts __rte_unused,
1813 uint16_t pkts_n __rte_unused)
1819 mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq __rte_unused)
1825 mlx5_check_vec_rx_support(struct rte_eth_dev *dev __rte_unused)
1831 * Free the mbufs from the linear array of pointers.
1834 * Pointer to array of packets to be free.
1836 * Number of packets to be freed.
1838 * Configured Tx offloads mask. It is fully defined at
1839 * compile time and may be used for optimization.
1841 static __rte_always_inline void
1842 mlx5_tx_free_mbuf(struct rte_mbuf **restrict pkts,
1843 unsigned int pkts_n,
1844 unsigned int olx __rte_unused)
1846 struct rte_mempool *pool = NULL;
1847 struct rte_mbuf **p_free = NULL;
1848 struct rte_mbuf *mbuf;
1849 unsigned int n_free = 0;
1852 * The implemented algorithm eliminates
1853 * copying pointers to temporary array
1854 * for rte_mempool_put_bulk() calls.
1861 * Decrement mbuf reference counter, detach
1862 * indirect and external buffers if needed.
1864 mbuf = rte_pktmbuf_prefree_seg(*pkts);
1865 if (likely(mbuf != NULL)) {
1866 assert(mbuf == *pkts);
1867 if (likely(n_free != 0)) {
1868 if (unlikely(pool != mbuf->pool))
1869 /* From different pool. */
1872 /* Start new scan array. */
1879 if (unlikely(pkts_n == 0)) {
1885 * This happens if mbuf is still referenced.
1886 * We can't put it back to the pool, skip.
1890 if (unlikely(n_free != 0))
1891 /* There is some array to free.*/
1893 if (unlikely(pkts_n == 0))
1894 /* Last mbuf, nothing to free. */
1900 * This loop is implemented to avoid multiple
1901 * inlining of rte_mempool_put_bulk().
1907 * Free the array of pre-freed mbufs
1908 * belonging to the same memory pool.
1910 rte_mempool_put_bulk(pool, (void *)p_free, n_free);
1911 if (unlikely(mbuf != NULL)) {
1912 /* There is the request to start new scan. */
1917 if (likely(pkts_n != 0))
1920 * This is the last mbuf to be freed.
1921 * Do one more loop iteration to complete.
1922 * This is rare case of the last unique mbuf.
1927 if (likely(pkts_n == 0))
1936 * Free the mbuf from the elts ring buffer till new tail.
1939 * Pointer to Tx queue structure.
1941 * Index in elts to free up to, becomes new elts tail.
1943 * Configured Tx offloads mask. It is fully defined at
1944 * compile time and may be used for optimization.
1946 static __rte_always_inline void
1947 mlx5_tx_free_elts(struct mlx5_txq_data *restrict txq,
1949 unsigned int olx __rte_unused)
1951 uint16_t n_elts = tail - txq->elts_tail;
1954 assert(n_elts <= txq->elts_s);
1956 * Implement a loop to support ring buffer wraparound
1957 * with single inlining of mlx5_tx_free_mbuf().
1962 part = txq->elts_s - (txq->elts_tail & txq->elts_m);
1963 part = RTE_MIN(part, n_elts);
1965 assert(part <= txq->elts_s);
1966 mlx5_tx_free_mbuf(&txq->elts[txq->elts_tail & txq->elts_m],
1968 txq->elts_tail += part;
1974 * Store the mbuf being sent into elts ring buffer.
1975 * On Tx completion these mbufs will be freed.
1978 * Pointer to Tx queue structure.
1980 * Pointer to array of packets to be stored.
1982 * Number of packets to be stored.
1984 * Configured Tx offloads mask. It is fully defined at
1985 * compile time and may be used for optimization.
1987 static __rte_always_inline void
1988 mlx5_tx_copy_elts(struct mlx5_txq_data *restrict txq,
1989 struct rte_mbuf **restrict pkts,
1990 unsigned int pkts_n,
1991 unsigned int olx __rte_unused)
1994 struct rte_mbuf **elts = (struct rte_mbuf **)txq->elts;
1998 part = txq->elts_s - (txq->elts_head & txq->elts_m);
2000 assert(part <= txq->elts_s);
2001 /* This code is a good candidate for vectorizing with SIMD. */
2002 rte_memcpy((void *)(elts + (txq->elts_head & txq->elts_m)),
2004 RTE_MIN(part, pkts_n) * sizeof(struct rte_mbuf *));
2005 txq->elts_head += pkts_n;
2006 if (unlikely(part < pkts_n))
2007 /* The copy is wrapping around the elts array. */
2008 rte_memcpy((void *)elts, (void *)(pkts + part),
2009 (pkts_n - part) * sizeof(struct rte_mbuf *));
2013 * Manage TX completions. This routine checks the CQ for
2014 * arrived CQEs, deduces the last accomplished WQE in SQ,
2015 * updates SQ producing index and frees all completed mbufs.
2018 * Pointer to TX queue structure.
2020 * Configured Tx offloads mask. It is fully defined at
2021 * compile time and may be used for optimization.
2023 * NOTE: not inlined intentionally, it makes tx_burst
2024 * routine smaller, simple and faster - from experiments.
2027 mlx5_tx_handle_completion(struct mlx5_txq_data *restrict txq,
2028 unsigned int olx __rte_unused)
2030 bool update = false;
2034 volatile struct mlx5_wqe_cseg *cseg;
2035 volatile struct mlx5_cqe *cqe;
2038 cqe = &txq->cqes[txq->cq_ci & txq->cqe_m];
2039 ret = check_cqe(cqe, txq->cqe_s, txq->cq_ci);
2040 if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
2041 if (likely(ret != MLX5_CQE_STATUS_ERR)) {
2042 /* No new CQEs in completion queue. */
2043 assert(ret == MLX5_CQE_STATUS_HW_OWN);
2044 if (likely(update)) {
2045 /* Update the consumer index. */
2046 rte_compiler_barrier();
2048 rte_cpu_to_be_32(txq->cq_ci);
2052 /* Some error occurred, try to restart. */
2054 tail = mlx5_tx_error_cqe_handle
2055 (txq, (volatile struct mlx5_err_cqe *)cqe);
2057 /* Normal transmit completion. */
2060 txq->wqe_pi = rte_be_to_cpu_16(cqe->wqe_counter);
2061 cseg = (volatile struct mlx5_wqe_cseg *)
2062 (txq->wqes + (txq->wqe_pi & txq->wqe_m));
2069 if (likely(tail != txq->elts_tail)) {
2070 /* Free data buffers from elts. */
2071 mlx5_tx_free_elts(txq, tail, olx);
2072 assert(tail == txq->elts_tail);
2079 * Check if the completion request flag should be set in the last WQE.
2080 * Both pushed mbufs and WQEs are monitored and the completion request
2081 * flag is set if any of thresholds is reached.
2084 * Pointer to TX queue structure.
2086 * Number of mbuf not stored yet in elts array.
2088 * Pointer to burst routine local context.
2090 * Configured Tx offloads mask. It is fully defined at
2091 * compile time and may be used for optimization.
2093 static __rte_always_inline void
2094 mlx5_tx_request_completion(struct mlx5_txq_data *restrict txq,
2095 unsigned int n_mbuf,
2096 struct mlx5_txq_local *restrict loc,
2097 unsigned int olx __rte_unused)
2099 uint16_t head = txq->elts_head + n_mbuf;
2101 if ((uint16_t)(head - txq->elts_comp) >= MLX5_TX_COMP_THRESH ||
2102 (uint16_t)(txq->wqe_ci - txq->wqe_comp) >= txq->wqe_thres) {
2103 volatile struct mlx5_wqe *last = loc->wqe_last;
2105 txq->elts_comp = head;
2106 txq->wqe_comp = txq->wqe_ci;
2107 /* Request unconditional completion on last WQE. */
2108 last->cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
2109 MLX5_COMP_MODE_OFFSET);
2110 /* Save elts_head in unused "immediate" field of WQE. */
2111 last->cseg.misc = head;
2113 * A CQE slot must always be available. Count the
2114 * issued CEQ "always" request instead of production
2115 * index due to here can be CQE with errors and
2116 * difference with ci may become inconsistent.
2118 assert(txq->cqe_s > ++txq->cq_pi);
2123 * DPDK callback to check the status of a tx descriptor.
2128 * The index of the descriptor in the ring.
2131 * The status of the tx descriptor.
2134 mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset)
2136 struct mlx5_txq_data *restrict txq = tx_queue;
2139 mlx5_tx_handle_completion(txq, 0);
2140 used = txq->elts_head - txq->elts_tail;
2142 return RTE_ETH_TX_DESC_FULL;
2143 return RTE_ETH_TX_DESC_DONE;
2147 * Build the Control Segment with specified opcode:
2148 * - MLX5_OPCODE_SEND
2149 * - MLX5_OPCODE_ENHANCED_MPSW
2153 * Pointer to TX queue structure.
2155 * Pointer to burst routine local context.
2157 * Pointer to WQE to fill with built Control Segment.
2159 * Supposed length of WQE in segments.
2161 * SQ WQE opcode to put into Control Segment.
2163 * Configured Tx offloads mask. It is fully defined at
2164 * compile time and may be used for optimization.
2166 static __rte_always_inline void
2167 mlx5_tx_cseg_init(struct mlx5_txq_data *restrict txq,
2168 struct mlx5_txq_local *restrict loc __rte_unused,
2169 struct mlx5_wqe *restrict wqe,
2171 unsigned int opcode,
2172 unsigned int olx __rte_unused)
2174 struct mlx5_wqe_cseg *restrict cs = &wqe->cseg;
2176 cs->opcode = rte_cpu_to_be_32((txq->wqe_ci << 8) | opcode);
2177 cs->sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
2178 cs->flags = RTE_BE32(MLX5_COMP_ONLY_FIRST_ERR <<
2179 MLX5_COMP_MODE_OFFSET);
2180 cs->misc = RTE_BE32(0);
2184 * Build the Ethernet Segment without inlined data.
2185 * Supports Software Parser, Checksums and VLAN
2186 * insertion Tx offload features.
2189 * Pointer to TX queue structure.
2191 * Pointer to burst routine local context.
2193 * Pointer to WQE to fill with built Ethernet Segment.
2195 * Configured Tx offloads mask. It is fully defined at
2196 * compile time and may be used for optimization.
2198 static __rte_always_inline void
2199 mlx5_tx_eseg_none(struct mlx5_txq_data *restrict txq __rte_unused,
2200 struct mlx5_txq_local *restrict loc,
2201 struct mlx5_wqe *restrict wqe,
2204 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2208 * Calculate and set check sum flags first, dword field
2209 * in segment may be shared with Software Parser flags.
2211 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2212 es->flags = rte_cpu_to_le_32(csum);
2214 * Calculate and set Software Parser offsets and flags.
2215 * These flags a set for custom UDP and IP tunnel packets.
2217 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2218 /* Fill metadata field if needed. */
2219 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2220 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2221 loc->mbuf->tx_metadata : 0 : 0;
2222 /* Engage VLAN tag insertion feature if requested. */
2223 if (MLX5_TXOFF_CONFIG(VLAN) &&
2224 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
2226 * We should get here only if device support
2227 * this feature correctly.
2229 assert(txq->vlan_en);
2230 es->inline_hdr = rte_cpu_to_be_32(MLX5_ETH_WQE_VLAN_INSERT |
2231 loc->mbuf->vlan_tci);
2233 es->inline_hdr = RTE_BE32(0);
2238 * Build the Ethernet Segment with minimal inlined data
2239 * of MLX5_ESEG_MIN_INLINE_SIZE bytes length. This is
2240 * used to fill the gap in single WQEBB WQEs.
2241 * Supports Software Parser, Checksums and VLAN
2242 * insertion Tx offload features.
2245 * Pointer to TX queue structure.
2247 * Pointer to burst routine local context.
2249 * Pointer to WQE to fill with built Ethernet Segment.
2251 * Length of VLAN tag insertion if any.
2253 * Configured Tx offloads mask. It is fully defined at
2254 * compile time and may be used for optimization.
2256 static __rte_always_inline void
2257 mlx5_tx_eseg_dmin(struct mlx5_txq_data *restrict txq __rte_unused,
2258 struct mlx5_txq_local *restrict loc,
2259 struct mlx5_wqe *restrict wqe,
2263 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2265 uint8_t *psrc, *pdst;
2268 * Calculate and set check sum flags first, dword field
2269 * in segment may be shared with Software Parser flags.
2271 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2272 es->flags = rte_cpu_to_le_32(csum);
2274 * Calculate and set Software Parser offsets and flags.
2275 * These flags a set for custom UDP and IP tunnel packets.
2277 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2278 /* Fill metadata field if needed. */
2279 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2280 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2281 loc->mbuf->tx_metadata : 0 : 0;
2282 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2284 sizeof(rte_v128u32_t)),
2285 "invalid Ethernet Segment data size");
2286 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2288 sizeof(struct rte_vlan_hdr) +
2289 2 * RTE_ETHER_ADDR_LEN),
2290 "invalid Ethernet Segment data size");
2291 psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2292 es->inline_hdr_sz = RTE_BE16(MLX5_ESEG_MIN_INLINE_SIZE);
2293 es->inline_data = *(unaligned_uint16_t *)psrc;
2294 psrc += sizeof(uint16_t);
2295 pdst = (uint8_t *)(es + 1);
2296 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2297 /* Implement VLAN tag insertion as part inline data. */
2298 memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
2299 pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2300 psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2301 /* Insert VLAN ethertype + VLAN tag. */
2302 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2303 ((RTE_ETHER_TYPE_VLAN << 16) |
2304 loc->mbuf->vlan_tci);
2305 pdst += sizeof(struct rte_vlan_hdr);
2306 /* Copy the rest two bytes from packet data. */
2307 assert(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
2308 *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
2310 /* Fill the gap in the title WQEBB with inline data. */
2311 rte_mov16(pdst, psrc);
2316 * Build the Ethernet Segment with entire packet
2317 * data inlining. Checks the boundary of WQEBB and
2318 * ring buffer wrapping, supports Software Parser,
2319 * Checksums and VLAN insertion Tx offload features.
2322 * Pointer to TX queue structure.
2324 * Pointer to burst routine local context.
2326 * Pointer to WQE to fill with built Ethernet Segment.
2328 * Length of VLAN tag insertion if any.
2330 * Length of data to inline (VLAN included, if any).
2332 * TSO flag, set mss field from the packet.
2334 * Configured Tx offloads mask. It is fully defined at
2335 * compile time and may be used for optimization.
2338 * Pointer to the next Data Segment (aligned and wrapped around).
2340 static __rte_always_inline struct mlx5_wqe_dseg *
2341 mlx5_tx_eseg_data(struct mlx5_txq_data *restrict txq,
2342 struct mlx5_txq_local *restrict loc,
2343 struct mlx5_wqe *restrict wqe,
2349 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2351 uint8_t *psrc, *pdst;
2355 * Calculate and set check sum flags first, dword field
2356 * in segment may be shared with Software Parser flags.
2358 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2361 csum |= loc->mbuf->tso_segsz;
2362 es->flags = rte_cpu_to_be_32(csum);
2364 es->flags = rte_cpu_to_le_32(csum);
2367 * Calculate and set Software Parser offsets and flags.
2368 * These flags a set for custom UDP and IP tunnel packets.
2370 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2371 /* Fill metadata field if needed. */
2372 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2373 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2374 loc->mbuf->tx_metadata : 0 : 0;
2375 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2377 sizeof(rte_v128u32_t)),
2378 "invalid Ethernet Segment data size");
2379 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2381 sizeof(struct rte_vlan_hdr) +
2382 2 * RTE_ETHER_ADDR_LEN),
2383 "invalid Ethernet Segment data size");
2384 psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2385 es->inline_hdr_sz = rte_cpu_to_be_16(inlen);
2386 es->inline_data = *(unaligned_uint16_t *)psrc;
2387 psrc += sizeof(uint16_t);
2388 pdst = (uint8_t *)(es + 1);
2389 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2390 /* Implement VLAN tag insertion as part inline data. */
2391 memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
2392 pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2393 psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2394 /* Insert VLAN ethertype + VLAN tag. */
2395 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2396 ((RTE_ETHER_TYPE_VLAN << 16) |
2397 loc->mbuf->vlan_tci);
2398 pdst += sizeof(struct rte_vlan_hdr);
2399 /* Copy the rest two bytes from packet data. */
2400 assert(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
2401 *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
2402 psrc += sizeof(uint16_t);
2404 /* Fill the gap in the title WQEBB with inline data. */
2405 rte_mov16(pdst, psrc);
2406 psrc += sizeof(rte_v128u32_t);
2408 pdst = (uint8_t *)(es + 2);
2409 assert(inlen >= MLX5_ESEG_MIN_INLINE_SIZE);
2410 assert(pdst < (uint8_t *)txq->wqes_end);
2411 inlen -= MLX5_ESEG_MIN_INLINE_SIZE;
2413 assert(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
2414 return (struct mlx5_wqe_dseg *)pdst;
2417 * The WQEBB space availability is checked by caller.
2418 * Here we should be aware of WQE ring buffer wraparound only.
2420 part = (uint8_t *)txq->wqes_end - pdst;
2421 part = RTE_MIN(part, inlen);
2423 rte_memcpy(pdst, psrc, part);
2425 if (likely(!inlen)) {
2427 * If return value is not used by the caller
2428 * the code below will be optimized out.
2431 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2432 if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
2433 pdst = (uint8_t *)txq->wqes;
2434 return (struct mlx5_wqe_dseg *)pdst;
2436 pdst = (uint8_t *)txq->wqes;
2443 * Copy data from chain of mbuf to the specified linear buffer.
2444 * Checksums and VLAN insertion Tx offload features. If data
2445 * from some mbuf copied completely this mbuf is freed. Local
2446 * structure is used to keep the byte stream state.
2449 * Pointer to the destination linear buffer.
2451 * Pointer to burst routine local context.
2453 * Length of data to be copied.
2455 * Configured Tx offloads mask. It is fully defined at
2456 * compile time and may be used for optimization.
2458 static __rte_always_inline void
2459 mlx5_tx_mseg_memcpy(uint8_t *pdst,
2460 struct mlx5_txq_local *restrict loc,
2462 unsigned int olx __rte_unused)
2464 struct rte_mbuf *mbuf;
2465 unsigned int part, dlen;
2470 /* Allow zero length packets, must check first. */
2471 dlen = rte_pktmbuf_data_len(loc->mbuf);
2472 if (dlen <= loc->mbuf_off) {
2473 /* Exhausted packet, just free. */
2475 loc->mbuf = mbuf->next;
2476 rte_pktmbuf_free_seg(mbuf);
2478 assert(loc->mbuf_nseg > 1);
2483 dlen -= loc->mbuf_off;
2484 psrc = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
2486 part = RTE_MIN(len, dlen);
2487 rte_memcpy(pdst, psrc, part);
2488 loc->mbuf_off += part;
2491 if (loc->mbuf_off >= rte_pktmbuf_data_len(loc->mbuf)) {
2493 /* Exhausted packet, just free. */
2495 loc->mbuf = mbuf->next;
2496 rte_pktmbuf_free_seg(mbuf);
2498 assert(loc->mbuf_nseg >= 1);
2508 * Build the Ethernet Segment with inlined data from
2509 * multi-segment packet. Checks the boundary of WQEBB
2510 * and ring buffer wrapping, supports Software Parser,
2511 * Checksums and VLAN insertion Tx offload features.
2514 * Pointer to TX queue structure.
2516 * Pointer to burst routine local context.
2518 * Pointer to WQE to fill with built Ethernet Segment.
2520 * Length of VLAN tag insertion if any.
2522 * Length of data to inline (VLAN included, if any).
2524 * TSO flag, set mss field from the packet.
2526 * Configured Tx offloads mask. It is fully defined at
2527 * compile time and may be used for optimization.
2530 * Pointer to the next Data Segment (aligned and
2531 * possible NOT wrapped around - caller should do
2532 * wrapping check on its own).
2534 static __rte_always_inline struct mlx5_wqe_dseg *
2535 mlx5_tx_eseg_mdat(struct mlx5_txq_data *restrict txq,
2536 struct mlx5_txq_local *restrict loc,
2537 struct mlx5_wqe *restrict wqe,
2543 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2549 * Calculate and set check sum flags first, uint32_t field
2550 * in segment may be shared with Software Parser flags.
2552 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2555 csum |= loc->mbuf->tso_segsz;
2556 es->flags = rte_cpu_to_be_32(csum);
2558 es->flags = rte_cpu_to_le_32(csum);
2561 * Calculate and set Software Parser offsets and flags.
2562 * These flags a set for custom UDP and IP tunnel packets.
2564 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2565 /* Fill metadata field if needed. */
2566 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2567 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2568 loc->mbuf->tx_metadata : 0 : 0;
2569 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2571 sizeof(rte_v128u32_t)),
2572 "invalid Ethernet Segment data size");
2573 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2575 sizeof(struct rte_vlan_hdr) +
2576 2 * RTE_ETHER_ADDR_LEN),
2577 "invalid Ethernet Segment data size");
2578 assert(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
2579 es->inline_hdr_sz = rte_cpu_to_be_16(inlen);
2580 pdst = (uint8_t *)&es->inline_data;
2581 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2582 /* Implement VLAN tag insertion as part inline data. */
2583 mlx5_tx_mseg_memcpy(pdst, loc, 2 * RTE_ETHER_ADDR_LEN, olx);
2584 pdst += 2 * RTE_ETHER_ADDR_LEN;
2585 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2586 ((RTE_ETHER_TYPE_VLAN << 16) |
2587 loc->mbuf->vlan_tci);
2588 pdst += sizeof(struct rte_vlan_hdr);
2589 inlen -= 2 * RTE_ETHER_ADDR_LEN + sizeof(struct rte_vlan_hdr);
2591 assert(pdst < (uint8_t *)txq->wqes_end);
2593 * The WQEBB space availability is checked by caller.
2594 * Here we should be aware of WQE ring buffer wraparound only.
2596 part = (uint8_t *)txq->wqes_end - pdst;
2597 part = RTE_MIN(part, inlen);
2600 mlx5_tx_mseg_memcpy(pdst, loc, part, olx);
2602 if (likely(!inlen)) {
2604 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2605 return (struct mlx5_wqe_dseg *)pdst;
2607 pdst = (uint8_t *)txq->wqes;
2613 * Build the Data Segment of pointer type.
2616 * Pointer to TX queue structure.
2618 * Pointer to burst routine local context.
2620 * Pointer to WQE to fill with built Data Segment.
2622 * Data buffer to point.
2624 * Data buffer length.
2626 * Configured Tx offloads mask. It is fully defined at
2627 * compile time and may be used for optimization.
2629 static __rte_always_inline void
2630 mlx5_tx_dseg_ptr(struct mlx5_txq_data *restrict txq,
2631 struct mlx5_txq_local *restrict loc,
2632 struct mlx5_wqe_dseg *restrict dseg,
2635 unsigned int olx __rte_unused)
2639 dseg->bcount = rte_cpu_to_be_32(len);
2640 dseg->lkey = mlx5_tx_mb2mr(txq, loc->mbuf);
2641 dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
2645 * Build the Data Segment of pointer type or inline
2646 * if data length is less than buffer in minimal
2647 * Data Segment size.
2650 * Pointer to TX queue structure.
2652 * Pointer to burst routine local context.
2654 * Pointer to WQE to fill with built Data Segment.
2656 * Data buffer to point.
2658 * Data buffer length.
2660 * Configured Tx offloads mask. It is fully defined at
2661 * compile time and may be used for optimization.
2663 static __rte_always_inline void
2664 mlx5_tx_dseg_iptr(struct mlx5_txq_data *restrict txq,
2665 struct mlx5_txq_local *restrict loc,
2666 struct mlx5_wqe_dseg *restrict dseg,
2669 unsigned int olx __rte_unused)
2675 if (len > MLX5_DSEG_MIN_INLINE_SIZE) {
2676 dseg->bcount = rte_cpu_to_be_32(len);
2677 dseg->lkey = mlx5_tx_mb2mr(txq, loc->mbuf);
2678 dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
2682 dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
2683 /* Unrolled implementation of generic rte_memcpy. */
2684 dst = (uintptr_t)&dseg->inline_data[0];
2685 src = (uintptr_t)buf;
2686 #ifdef RTE_ARCH_STRICT_ALIGN
2687 memcpy(dst, src, len);
2690 *(uint64_t *)dst = *(uint64_t *)src;
2691 dst += sizeof(uint64_t);
2692 src += sizeof(uint64_t);
2695 *(uint32_t *)dst = *(uint32_t *)src;
2696 dst += sizeof(uint32_t);
2697 src += sizeof(uint32_t);
2700 *(uint16_t *)dst = *(uint16_t *)src;
2701 dst += sizeof(uint16_t);
2702 src += sizeof(uint16_t);
2705 *(uint8_t *)dst = *(uint8_t *)src;
2710 * Build the Data Segment of inlined data from single
2711 * segment packet, no VLAN insertion.
2714 * Pointer to TX queue structure.
2716 * Pointer to burst routine local context.
2718 * Pointer to WQE to fill with built Data Segment.
2720 * Data buffer to point.
2722 * Data buffer length.
2724 * Configured Tx offloads mask. It is fully defined at
2725 * compile time and may be used for optimization.
2728 * Pointer to the next Data Segment after inlined data.
2729 * Ring buffer wraparound check is needed. We do not
2730 * do it here because it may not be needed for the
2731 * last packet in the eMPW session.
2733 static __rte_always_inline struct mlx5_wqe_dseg *
2734 mlx5_tx_dseg_empw(struct mlx5_txq_data *restrict txq,
2735 struct mlx5_txq_local *restrict loc __rte_unused,
2736 struct mlx5_wqe_dseg *restrict dseg,
2739 unsigned int olx __rte_unused)
2744 dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
2745 pdst = &dseg->inline_data[0];
2747 * The WQEBB space availability is checked by caller.
2748 * Here we should be aware of WQE ring buffer wraparound only.
2750 part = (uint8_t *)txq->wqes_end - pdst;
2751 part = RTE_MIN(part, len);
2753 rte_memcpy(pdst, buf, part);
2757 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2758 /* Note: no final wraparound check here. */
2759 return (struct mlx5_wqe_dseg *)pdst;
2761 pdst = (uint8_t *)txq->wqes;
2768 * Build the Data Segment of inlined data from single
2769 * segment packet with VLAN insertion.
2772 * Pointer to TX queue structure.
2774 * Pointer to burst routine local context.
2776 * Pointer to the dseg fill with built Data Segment.
2778 * Data buffer to point.
2780 * Data buffer length.
2782 * Configured Tx offloads mask. It is fully defined at
2783 * compile time and may be used for optimization.
2786 * Pointer to the next Data Segment after inlined data.
2787 * Ring buffer wraparound check is needed.
2789 static __rte_always_inline struct mlx5_wqe_dseg *
2790 mlx5_tx_dseg_vlan(struct mlx5_txq_data *restrict txq,
2791 struct mlx5_txq_local *restrict loc __rte_unused,
2792 struct mlx5_wqe_dseg *restrict dseg,
2795 unsigned int olx __rte_unused)
2801 assert(len > MLX5_ESEG_MIN_INLINE_SIZE);
2802 static_assert(MLX5_DSEG_MIN_INLINE_SIZE ==
2803 (2 * RTE_ETHER_ADDR_LEN),
2804 "invalid Data Segment data size");
2805 dseg->bcount = rte_cpu_to_be_32((len + sizeof(struct rte_vlan_hdr)) |
2806 MLX5_ETH_WQE_DATA_INLINE);
2807 pdst = &dseg->inline_data[0];
2808 memcpy(pdst, buf, MLX5_DSEG_MIN_INLINE_SIZE);
2809 buf += MLX5_DSEG_MIN_INLINE_SIZE;
2810 pdst += MLX5_DSEG_MIN_INLINE_SIZE;
2811 /* Insert VLAN ethertype + VLAN tag. Pointer is aligned. */
2812 assert(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
2813 *(uint32_t *)pdst = rte_cpu_to_be_32((RTE_ETHER_TYPE_VLAN << 16) |
2814 loc->mbuf->vlan_tci);
2815 pdst += sizeof(struct rte_vlan_hdr);
2816 if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
2817 pdst = (uint8_t *)txq->wqes;
2819 * The WQEBB space availability is checked by caller.
2820 * Here we should be aware of WQE ring buffer wraparound only.
2822 part = (uint8_t *)txq->wqes_end - pdst;
2823 part = RTE_MIN(part, len);
2825 rte_memcpy(pdst, buf, part);
2829 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2830 /* Note: no final wraparound check here. */
2831 return (struct mlx5_wqe_dseg *)pdst;
2833 pdst = (uint8_t *)txq->wqes;
2840 * Build the Ethernet Segment with optionally inlined data with
2841 * VLAN insertion and following Data Segments (if any) from
2842 * multi-segment packet. Used by ordinary send and TSO.
2845 * Pointer to TX queue structure.
2847 * Pointer to burst routine local context.
2849 * Pointer to WQE to fill with built Ethernet/Data Segments.
2851 * Length of VLAN header to insert, 0 means no VLAN insertion.
2853 * Data length to inline. For TSO this parameter specifies
2854 * exact value, for ordinary send routine can be aligned by
2855 * caller to provide better WQE space saving and data buffer
2856 * start address alignment. This length includes VLAN header
2859 * Zero means ordinary send, inlined data can be extended,
2860 * otherwise this is TSO, inlined data length is fixed.
2862 * Configured Tx offloads mask. It is fully defined at
2863 * compile time and may be used for optimization.
2866 * Actual size of built WQE in segments.
2868 static __rte_always_inline unsigned int
2869 mlx5_tx_mseg_build(struct mlx5_txq_data *restrict txq,
2870 struct mlx5_txq_local *restrict loc,
2871 struct mlx5_wqe *restrict wqe,
2875 unsigned int olx __rte_unused)
2877 struct mlx5_wqe_dseg *restrict dseg;
2880 assert((rte_pktmbuf_pkt_len(loc->mbuf) + vlan) >= inlen);
2881 loc->mbuf_nseg = NB_SEGS(loc->mbuf);
2884 dseg = mlx5_tx_eseg_mdat(txq, loc, wqe, vlan, inlen, tso, olx);
2885 if (!loc->mbuf_nseg)
2888 * There are still some mbuf remaining, not inlined.
2889 * The first mbuf may be partially inlined and we
2890 * must process the possible non-zero data offset.
2892 if (loc->mbuf_off) {
2897 * Exhausted packets must be dropped before.
2898 * Non-zero offset means there are some data
2899 * remained in the packet.
2901 assert(loc->mbuf_off < rte_pktmbuf_data_len(loc->mbuf));
2902 assert(rte_pktmbuf_data_len(loc->mbuf));
2903 dptr = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
2905 dlen = rte_pktmbuf_data_len(loc->mbuf) - loc->mbuf_off;
2907 * Build the pointer/minimal data Data Segment.
2908 * Do ring buffer wrapping check in advance.
2910 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
2911 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2912 mlx5_tx_dseg_iptr(txq, loc, dseg, dptr, dlen, olx);
2913 /* Store the mbuf to be freed on completion. */
2914 assert(loc->elts_free);
2915 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2918 if (--loc->mbuf_nseg == 0)
2920 loc->mbuf = loc->mbuf->next;
2924 if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
2925 struct rte_mbuf *mbuf;
2927 /* Zero length segment found, just skip. */
2929 loc->mbuf = loc->mbuf->next;
2930 rte_pktmbuf_free_seg(mbuf);
2931 if (--loc->mbuf_nseg == 0)
2934 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
2935 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2938 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
2939 rte_pktmbuf_data_len(loc->mbuf), olx);
2940 assert(loc->elts_free);
2941 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2944 if (--loc->mbuf_nseg == 0)
2946 loc->mbuf = loc->mbuf->next;
2951 /* Calculate actual segments used from the dseg pointer. */
2952 if ((uintptr_t)wqe < (uintptr_t)dseg)
2953 ds = ((uintptr_t)dseg - (uintptr_t)wqe) / MLX5_WSEG_SIZE;
2955 ds = (((uintptr_t)dseg - (uintptr_t)wqe) +
2956 txq->wqe_s * MLX5_WQE_SIZE) / MLX5_WSEG_SIZE;
2961 * Tx one packet function for multi-segment TSO. Supports all
2962 * types of Tx offloads, uses MLX5_OPCODE_TSO to build WQEs,
2963 * sends one packet per WQE.
2965 * This routine is responsible for storing processed mbuf
2966 * into elts ring buffer and update elts_head.
2969 * Pointer to TX queue structure.
2971 * Pointer to burst routine local context.
2973 * Configured Tx offloads mask. It is fully defined at
2974 * compile time and may be used for optimization.
2977 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2978 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2979 * Local context variables partially updated.
2981 static __rte_always_inline enum mlx5_txcmp_code
2982 mlx5_tx_packet_multi_tso(struct mlx5_txq_data *restrict txq,
2983 struct mlx5_txq_local *restrict loc,
2986 struct mlx5_wqe *restrict wqe;
2987 unsigned int ds, dlen, inlen, ntcp, vlan = 0;
2990 * Calculate data length to be inlined to estimate
2991 * the required space in WQE ring buffer.
2993 dlen = rte_pktmbuf_pkt_len(loc->mbuf);
2994 if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
2995 vlan = sizeof(struct rte_vlan_hdr);
2996 inlen = loc->mbuf->l2_len + vlan +
2997 loc->mbuf->l3_len + loc->mbuf->l4_len;
2998 if (unlikely((!inlen || !loc->mbuf->tso_segsz)))
2999 return MLX5_TXCMP_CODE_ERROR;
3000 if (loc->mbuf->ol_flags & PKT_TX_TUNNEL_MASK)
3001 inlen += loc->mbuf->outer_l2_len + loc->mbuf->outer_l3_len;
3002 /* Packet must contain all TSO headers. */
3003 if (unlikely(inlen > MLX5_MAX_TSO_HEADER ||
3004 inlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
3005 inlen > (dlen + vlan)))
3006 return MLX5_TXCMP_CODE_ERROR;
3007 assert(inlen >= txq->inlen_mode);
3009 * Check whether there are enough free WQEBBs:
3011 * - Ethernet Segment
3012 * - First Segment of inlined Ethernet data
3013 * - ... data continued ...
3014 * - Data Segments of pointer/min inline type
3016 ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
3017 MLX5_ESEG_MIN_INLINE_SIZE +
3019 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3020 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3021 return MLX5_TXCMP_CODE_EXIT;
3022 /* Check for maximal WQE size. */
3023 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3024 return MLX5_TXCMP_CODE_ERROR;
3025 #ifdef MLX5_PMD_SOFT_COUNTERS
3026 /* Update sent data bytes/packets counters. */
3027 ntcp = (dlen - (inlen - vlan) + loc->mbuf->tso_segsz - 1) /
3028 loc->mbuf->tso_segsz;
3030 * One will be added for mbuf itself
3031 * at the end of the mlx5_tx_burst from
3032 * loc->pkts_sent field.
3035 txq->stats.opackets += ntcp;
3036 txq->stats.obytes += dlen + vlan + ntcp * inlen;
3038 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3039 loc->wqe_last = wqe;
3040 mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_TSO, olx);
3041 ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 1, olx);
3042 wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3043 txq->wqe_ci += (ds + 3) / 4;
3044 loc->wqe_free -= (ds + 3) / 4;
3045 return MLX5_TXCMP_CODE_MULTI;
3049 * Tx one packet function for multi-segment SEND. Supports all
3050 * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
3051 * sends one packet per WQE, without any data inlining in
3054 * This routine is responsible for storing processed mbuf
3055 * into elts ring buffer and update elts_head.
3058 * Pointer to TX queue structure.
3060 * Pointer to burst routine local context.
3062 * Configured Tx offloads mask. It is fully defined at
3063 * compile time and may be used for optimization.
3066 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3067 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3068 * Local context variables partially updated.
3070 static __rte_always_inline enum mlx5_txcmp_code
3071 mlx5_tx_packet_multi_send(struct mlx5_txq_data *restrict txq,
3072 struct mlx5_txq_local *restrict loc,
3075 struct mlx5_wqe_dseg *restrict dseg;
3076 struct mlx5_wqe *restrict wqe;
3077 unsigned int ds, nseg;
3079 assert(NB_SEGS(loc->mbuf) > 1);
3081 * No inline at all, it means the CPU cycles saving
3082 * is prioritized at configuration, we should not
3083 * copy any packet data to WQE.
3085 nseg = NB_SEGS(loc->mbuf);
3087 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3088 return MLX5_TXCMP_CODE_EXIT;
3089 /* Check for maximal WQE size. */
3090 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3091 return MLX5_TXCMP_CODE_ERROR;
3093 * Some Tx offloads may cause an error if
3094 * packet is not long enough, check against
3095 * assumed minimal length.
3097 if (rte_pktmbuf_pkt_len(loc->mbuf) <= MLX5_ESEG_MIN_INLINE_SIZE)
3098 return MLX5_TXCMP_CODE_ERROR;
3099 #ifdef MLX5_PMD_SOFT_COUNTERS
3100 /* Update sent data bytes counter. */
3101 txq->stats.obytes += rte_pktmbuf_pkt_len(loc->mbuf);
3102 if (MLX5_TXOFF_CONFIG(VLAN) &&
3103 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3104 txq->stats.obytes += sizeof(struct rte_vlan_hdr);
3107 * SEND WQE, one WQEBB:
3108 * - Control Segment, SEND opcode
3109 * - Ethernet Segment, optional VLAN, no inline
3110 * - Data Segments, pointer only type
3112 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3113 loc->wqe_last = wqe;
3114 mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_SEND, olx);
3115 mlx5_tx_eseg_none(txq, loc, wqe, olx);
3116 dseg = &wqe->dseg[0];
3118 if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
3119 struct rte_mbuf *mbuf;
3122 * Zero length segment found, have to
3123 * correct total size of WQE in segments.
3124 * It is supposed to be rare occasion, so
3125 * in normal case (no zero length segments)
3126 * we avoid extra writing to the Control
3130 wqe->cseg.sq_ds -= RTE_BE32(1);
3132 loc->mbuf = mbuf->next;
3133 rte_pktmbuf_free_seg(mbuf);
3139 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3140 rte_pktmbuf_data_len(loc->mbuf), olx);
3141 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3146 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3147 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3148 loc->mbuf = loc->mbuf->next;
3151 txq->wqe_ci += (ds + 3) / 4;
3152 loc->wqe_free -= (ds + 3) / 4;
3153 return MLX5_TXCMP_CODE_MULTI;
3157 * Tx one packet function for multi-segment SEND. Supports all
3158 * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
3159 * sends one packet per WQE, with data inlining in
3160 * Ethernet Segment and minimal Data Segments.
3162 * This routine is responsible for storing processed mbuf
3163 * into elts ring buffer and update elts_head.
3166 * Pointer to TX queue structure.
3168 * Pointer to burst routine local context.
3170 * Configured Tx offloads mask. It is fully defined at
3171 * compile time and may be used for optimization.
3174 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3175 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3176 * Local context variables partially updated.
3178 static __rte_always_inline enum mlx5_txcmp_code
3179 mlx5_tx_packet_multi_inline(struct mlx5_txq_data *restrict txq,
3180 struct mlx5_txq_local *restrict loc,
3183 struct mlx5_wqe *restrict wqe;
3184 unsigned int ds, inlen, dlen, vlan = 0;
3186 assert(MLX5_TXOFF_CONFIG(INLINE));
3187 assert(NB_SEGS(loc->mbuf) > 1);
3189 * First calculate data length to be inlined
3190 * to estimate the required space for WQE.
3192 dlen = rte_pktmbuf_pkt_len(loc->mbuf);
3193 if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3194 vlan = sizeof(struct rte_vlan_hdr);
3195 inlen = dlen + vlan;
3196 /* Check against minimal length. */
3197 if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
3198 return MLX5_TXCMP_CODE_ERROR;
3199 assert(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
3200 if (inlen > txq->inlen_send) {
3201 struct rte_mbuf *mbuf;
3206 * Packet length exceeds the allowed inline
3207 * data length, check whether the minimal
3208 * inlining is required.
3210 if (txq->inlen_mode) {
3211 assert(txq->inlen_mode >= MLX5_ESEG_MIN_INLINE_SIZE);
3212 assert(txq->inlen_mode <= txq->inlen_send);
3213 inlen = txq->inlen_mode;
3215 if (!vlan || txq->vlan_en) {
3217 * VLAN insertion will be done inside by HW.
3218 * It is not utmost effective - VLAN flag is
3219 * checked twice, but we should proceed the
3220 * inlining length correctly and take into
3221 * account the VLAN header being inserted.
3223 return mlx5_tx_packet_multi_send
3226 inlen = MLX5_ESEG_MIN_INLINE_SIZE;
3229 * Now we know the minimal amount of data is requested
3230 * to inline. Check whether we should inline the buffers
3231 * from the chain beginning to eliminate some mbufs.
3234 nxlen = rte_pktmbuf_data_len(mbuf);
3235 if (unlikely(nxlen <= txq->inlen_send)) {
3236 /* We can inline first mbuf at least. */
3237 if (nxlen < inlen) {
3240 /* Scan mbufs till inlen filled. */
3245 nxlen = rte_pktmbuf_data_len(mbuf);
3247 } while (unlikely(nxlen < inlen));
3248 if (unlikely(nxlen > txq->inlen_send)) {
3249 /* We cannot inline entire mbuf. */
3250 smlen = inlen - smlen;
3251 start = rte_pktmbuf_mtod_offset
3252 (mbuf, uintptr_t, smlen);
3259 /* There should be not end of packet. */
3261 nxlen = inlen + rte_pktmbuf_data_len(mbuf);
3262 } while (unlikely(nxlen < txq->inlen_send));
3264 start = rte_pktmbuf_mtod(mbuf, uintptr_t);
3266 * Check whether we can do inline to align start
3267 * address of data buffer to cacheline.
3270 start = (~start + 1) & (RTE_CACHE_LINE_SIZE - 1);
3271 if (unlikely(start)) {
3273 if (start <= txq->inlen_send)
3278 * Check whether there are enough free WQEBBs:
3280 * - Ethernet Segment
3281 * - First Segment of inlined Ethernet data
3282 * - ... data continued ...
3283 * - Data Segments of pointer/min inline type
3285 * Estimate the number of Data Segments conservatively,
3286 * supposing no any mbufs is being freed during inlining.
3288 assert(inlen <= txq->inlen_send);
3289 ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
3290 MLX5_ESEG_MIN_INLINE_SIZE +
3292 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3293 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3294 return MLX5_TXCMP_CODE_EXIT;
3295 /* Check for maximal WQE size. */
3296 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3297 return MLX5_TXCMP_CODE_ERROR;
3298 #ifdef MLX5_PMD_SOFT_COUNTERS
3299 /* Update sent data bytes/packets counters. */
3300 txq->stats.obytes += dlen + vlan;
3302 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3303 loc->wqe_last = wqe;
3304 mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_SEND, olx);
3305 ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 0, olx);
3306 wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3307 txq->wqe_ci += (ds + 3) / 4;
3308 loc->wqe_free -= (ds + 3) / 4;
3309 return MLX5_TXCMP_CODE_MULTI;
3313 * Tx burst function for multi-segment packets. Supports all
3314 * types of Tx offloads, uses MLX5_OPCODE_SEND/TSO to build WQEs,
3315 * sends one packet per WQE. Function stops sending if it
3316 * encounters the single-segment packet.
3318 * This routine is responsible for storing processed mbuf
3319 * into elts ring buffer and update elts_head.
3322 * Pointer to TX queue structure.
3324 * Packets to transmit.
3326 * Number of packets in array.
3328 * Pointer to burst routine local context.
3330 * Configured Tx offloads mask. It is fully defined at
3331 * compile time and may be used for optimization.
3334 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3335 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3336 * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
3337 * MLX5_TXCMP_CODE_TSO - TSO single-segment packet encountered.
3338 * Local context variables updated.
3340 static __rte_always_inline enum mlx5_txcmp_code
3341 mlx5_tx_burst_mseg(struct mlx5_txq_data *restrict txq,
3342 struct rte_mbuf **restrict pkts,
3343 unsigned int pkts_n,
3344 struct mlx5_txq_local *restrict loc,
3347 assert(loc->elts_free && loc->wqe_free);
3348 assert(pkts_n > loc->pkts_sent);
3349 pkts += loc->pkts_sent + 1;
3350 pkts_n -= loc->pkts_sent;
3352 enum mlx5_txcmp_code ret;
3354 assert(NB_SEGS(loc->mbuf) > 1);
3356 * Estimate the number of free elts quickly but
3357 * conservatively. Some segment may be fully inlined
3358 * and freed, ignore this here - precise estimation
3361 if (loc->elts_free < NB_SEGS(loc->mbuf))
3362 return MLX5_TXCMP_CODE_EXIT;
3363 if (MLX5_TXOFF_CONFIG(TSO) &&
3364 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)) {
3365 /* Proceed with multi-segment TSO. */
3366 ret = mlx5_tx_packet_multi_tso(txq, loc, olx);
3367 } else if (MLX5_TXOFF_CONFIG(INLINE)) {
3368 /* Proceed with multi-segment SEND with inlining. */
3369 ret = mlx5_tx_packet_multi_inline(txq, loc, olx);
3371 /* Proceed with multi-segment SEND w/o inlining. */
3372 ret = mlx5_tx_packet_multi_send(txq, loc, olx);
3374 if (ret == MLX5_TXCMP_CODE_EXIT)
3375 return MLX5_TXCMP_CODE_EXIT;
3376 if (ret == MLX5_TXCMP_CODE_ERROR)
3377 return MLX5_TXCMP_CODE_ERROR;
3378 /* WQE is built, go to the next packet. */
3381 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3382 return MLX5_TXCMP_CODE_EXIT;
3383 loc->mbuf = *pkts++;
3385 rte_prefetch0(*pkts);
3386 if (likely(NB_SEGS(loc->mbuf) > 1))
3388 /* Here ends the series of multi-segment packets. */
3389 if (MLX5_TXOFF_CONFIG(TSO) &&
3390 unlikely(!(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)))
3391 return MLX5_TXCMP_CODE_TSO;
3392 return MLX5_TXCMP_CODE_SINGLE;
3398 * Tx burst function for single-segment packets with TSO.
3399 * Supports all types of Tx offloads, except multi-packets.
3400 * Uses MLX5_OPCODE_TSO to build WQEs, sends one packet per WQE.
3401 * Function stops sending if it encounters the multi-segment
3402 * packet or packet without TSO requested.
3404 * The routine is responsible for storing processed mbuf
3405 * into elts ring buffer and update elts_head if inline
3406 * offloads is requested due to possible early freeing
3407 * of the inlined mbufs (can not store pkts array in elts
3411 * Pointer to TX queue structure.
3413 * Packets to transmit.
3415 * Number of packets in array.
3417 * Pointer to burst routine local context.
3419 * Configured Tx offloads mask. It is fully defined at
3420 * compile time and may be used for optimization.
3423 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3424 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3425 * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
3426 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3427 * Local context variables updated.
3429 static __rte_always_inline enum mlx5_txcmp_code
3430 mlx5_tx_burst_tso(struct mlx5_txq_data *restrict txq,
3431 struct rte_mbuf **restrict pkts,
3432 unsigned int pkts_n,
3433 struct mlx5_txq_local *restrict loc,
3436 assert(loc->elts_free && loc->wqe_free);
3437 assert(pkts_n > loc->pkts_sent);
3438 pkts += loc->pkts_sent + 1;
3439 pkts_n -= loc->pkts_sent;
3441 struct mlx5_wqe_dseg *restrict dseg;
3442 struct mlx5_wqe *restrict wqe;
3443 unsigned int ds, dlen, hlen, ntcp, vlan = 0;
3446 assert(NB_SEGS(loc->mbuf) == 1);
3447 dlen = rte_pktmbuf_data_len(loc->mbuf);
3448 if (MLX5_TXOFF_CONFIG(VLAN) &&
3449 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
3450 vlan = sizeof(struct rte_vlan_hdr);
3453 * First calculate the WQE size to check
3454 * whether we have enough space in ring buffer.
3456 hlen = loc->mbuf->l2_len + vlan +
3457 loc->mbuf->l3_len + loc->mbuf->l4_len;
3458 if (unlikely((!hlen || !loc->mbuf->tso_segsz)))
3459 return MLX5_TXCMP_CODE_ERROR;
3460 if (loc->mbuf->ol_flags & PKT_TX_TUNNEL_MASK)
3461 hlen += loc->mbuf->outer_l2_len +
3462 loc->mbuf->outer_l3_len;
3463 /* Segment must contain all TSO headers. */
3464 if (unlikely(hlen > MLX5_MAX_TSO_HEADER ||
3465 hlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
3466 hlen > (dlen + vlan)))
3467 return MLX5_TXCMP_CODE_ERROR;
3469 * Check whether there are enough free WQEBBs:
3471 * - Ethernet Segment
3472 * - First Segment of inlined Ethernet data
3473 * - ... data continued ...
3474 * - Finishing Data Segment of pointer type
3476 ds = 4 + (hlen - MLX5_ESEG_MIN_INLINE_SIZE +
3477 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3478 if (loc->wqe_free < ((ds + 3) / 4))
3479 return MLX5_TXCMP_CODE_EXIT;
3480 #ifdef MLX5_PMD_SOFT_COUNTERS
3481 /* Update sent data bytes/packets counters. */
3482 ntcp = (dlen + vlan - hlen +
3483 loc->mbuf->tso_segsz - 1) /
3484 loc->mbuf->tso_segsz;
3486 * One will be added for mbuf itself at the end
3487 * of the mlx5_tx_burst from loc->pkts_sent field.
3490 txq->stats.opackets += ntcp;
3491 txq->stats.obytes += dlen + vlan + ntcp * hlen;
3494 * Build the TSO WQE:
3496 * - Ethernet Segment with hlen bytes inlined
3497 * - Data Segment of pointer type
3499 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3500 loc->wqe_last = wqe;
3501 mlx5_tx_cseg_init(txq, loc, wqe, ds,
3502 MLX5_OPCODE_TSO, olx);
3503 dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan, hlen, 1, olx);
3504 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) + hlen - vlan;
3505 dlen -= hlen - vlan;
3506 mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
3508 * WQE is built, update the loop parameters
3509 * and go to the next packet.
3511 txq->wqe_ci += (ds + 3) / 4;
3512 loc->wqe_free -= (ds + 3) / 4;
3513 if (MLX5_TXOFF_CONFIG(INLINE))
3514 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3518 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3519 return MLX5_TXCMP_CODE_EXIT;
3520 loc->mbuf = *pkts++;
3522 rte_prefetch0(*pkts);
3523 if (MLX5_TXOFF_CONFIG(MULTI) &&
3524 unlikely(NB_SEGS(loc->mbuf) > 1))
3525 return MLX5_TXCMP_CODE_MULTI;
3526 if (unlikely(!(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)))
3527 return MLX5_TXCMP_CODE_SINGLE;
3528 /* Continue with the next TSO packet. */
3534 * Analyze the packet and select the best method to send.
3537 * Pointer to TX queue structure.
3539 * Pointer to burst routine local context.
3541 * Configured Tx offloads mask. It is fully defined at
3542 * compile time and may be used for optimization.
3544 * The predefined flag whether do complete check for
3545 * multi-segment packets and TSO.
3548 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3549 * MLX5_TXCMP_CODE_TSO - TSO required, use TSO/LSO.
3550 * MLX5_TXCMP_CODE_SINGLE - single-segment packet, use SEND.
3551 * MLX5_TXCMP_CODE_EMPW - single-segment packet, use MPW.
3553 static __rte_always_inline enum mlx5_txcmp_code
3554 mlx5_tx_able_to_empw(struct mlx5_txq_data *restrict txq,
3555 struct mlx5_txq_local *restrict loc,
3559 /* Check for multi-segment packet. */
3561 MLX5_TXOFF_CONFIG(MULTI) &&
3562 unlikely(NB_SEGS(loc->mbuf) > 1))
3563 return MLX5_TXCMP_CODE_MULTI;
3564 /* Check for TSO packet. */
3566 MLX5_TXOFF_CONFIG(TSO) &&
3567 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG))
3568 return MLX5_TXCMP_CODE_TSO;
3569 /* Check if eMPW is enabled at all. */
3570 if (!MLX5_TXOFF_CONFIG(EMPW))
3571 return MLX5_TXCMP_CODE_SINGLE;
3572 /* Check if eMPW can be engaged. */
3573 if (MLX5_TXOFF_CONFIG(VLAN) &&
3574 unlikely(loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) &&
3575 (!MLX5_TXOFF_CONFIG(INLINE) ||
3576 unlikely((rte_pktmbuf_data_len(loc->mbuf) +
3577 sizeof(struct rte_vlan_hdr)) > txq->inlen_empw))) {
3579 * eMPW does not support VLAN insertion offload,
3580 * we have to inline the entire packet but
3581 * packet is too long for inlining.
3583 return MLX5_TXCMP_CODE_SINGLE;
3585 return MLX5_TXCMP_CODE_EMPW;
3589 * Check the next packet attributes to match with the eMPW batch ones.
3592 * Pointer to TX queue structure.
3594 * Pointer to Ethernet Segment of eMPW batch.
3596 * Pointer to burst routine local context.
3598 * Configured Tx offloads mask. It is fully defined at
3599 * compile time and may be used for optimization.
3602 * true - packet match with eMPW batch attributes.
3603 * false - no match, eMPW should be restarted.
3605 static __rte_always_inline bool
3606 mlx5_tx_match_empw(struct mlx5_txq_data *restrict txq __rte_unused,
3607 struct mlx5_wqe_eseg *restrict es,
3608 struct mlx5_txq_local *restrict loc,
3611 uint8_t swp_flags = 0;
3613 /* Compare the checksum flags, if any. */
3614 if (MLX5_TXOFF_CONFIG(CSUM) &&
3615 txq_ol_cksum_to_cs(loc->mbuf) != es->cs_flags)
3617 /* Compare the Software Parser offsets and flags. */
3618 if (MLX5_TXOFF_CONFIG(SWP) &&
3619 (es->swp_offs != txq_mbuf_to_swp(loc, &swp_flags, olx) ||
3620 es->swp_flags != swp_flags))
3622 /* Fill metadata field if needed. */
3623 if (MLX5_TXOFF_CONFIG(METADATA) &&
3624 es->metadata != (loc->mbuf->ol_flags & PKT_TX_METADATA ?
3625 loc->mbuf->tx_metadata : 0))
3627 /* There must be no VLAN packets in eMPW loop. */
3628 if (MLX5_TXOFF_CONFIG(VLAN))
3629 assert(!(loc->mbuf->ol_flags & PKT_TX_VLAN_PKT));
3634 * Update send loop variables and WQE for eMPW loop
3635 * without data inlining. Number of Data Segments is
3636 * equal to the number of sent packets.
3639 * Pointer to TX queue structure.
3641 * Pointer to burst routine local context.
3643 * Number of packets/Data Segments/Packets.
3645 * Accumulated statistics, bytes sent
3647 * Configured Tx offloads mask. It is fully defined at
3648 * compile time and may be used for optimization.
3651 * true - packet match with eMPW batch attributes.
3652 * false - no match, eMPW should be restarted.
3654 static __rte_always_inline void
3655 mlx5_tx_sdone_empw(struct mlx5_txq_data *restrict txq,
3656 struct mlx5_txq_local *restrict loc,
3659 unsigned int olx __rte_unused)
3661 assert(!MLX5_TXOFF_CONFIG(INLINE));
3662 #ifdef MLX5_PMD_SOFT_COUNTERS
3663 /* Update sent data bytes counter. */
3664 txq->stats.obytes += slen;
3668 loc->elts_free -= ds;
3669 loc->pkts_sent += ds;
3671 loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3672 txq->wqe_ci += (ds + 3) / 4;
3673 loc->wqe_free -= (ds + 3) / 4;
3677 * Update send loop variables and WQE for eMPW loop
3678 * with data inlining. Gets the size of pushed descriptors
3679 * and data to the WQE.
3682 * Pointer to TX queue structure.
3684 * Pointer to burst routine local context.
3686 * Total size of descriptor/data in bytes.
3688 * Accumulated statistics, data bytes sent.
3690 * Configured Tx offloads mask. It is fully defined at
3691 * compile time and may be used for optimization.
3694 * true - packet match with eMPW batch attributes.
3695 * false - no match, eMPW should be restarted.
3697 static __rte_always_inline void
3698 mlx5_tx_idone_empw(struct mlx5_txq_data *restrict txq,
3699 struct mlx5_txq_local *restrict loc,
3702 unsigned int olx __rte_unused)
3704 assert(MLX5_TXOFF_CONFIG(INLINE));
3705 assert((len % MLX5_WSEG_SIZE) == 0);
3706 #ifdef MLX5_PMD_SOFT_COUNTERS
3707 /* Update sent data bytes counter. */
3708 txq->stats.obytes += slen;
3712 len = len / MLX5_WSEG_SIZE + 2;
3713 loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | len);
3714 txq->wqe_ci += (len + 3) / 4;
3715 loc->wqe_free -= (len + 3) / 4;
3719 * The set of Tx burst functions for single-segment packets
3720 * without TSO and with Multi-Packet Writing feature support.
3721 * Supports all types of Tx offloads, except multi-packets
3724 * Uses MLX5_OPCODE_EMPW to build WQEs if possible and sends
3725 * as many packet per WQE as it can. If eMPW is not configured
3726 * or packet can not be sent with eMPW (VLAN insertion) the
3727 * ordinary SEND opcode is used and only one packet placed
3730 * Functions stop sending if it encounters the multi-segment
3731 * packet or packet with TSO requested.
3733 * The routines are responsible for storing processed mbuf
3734 * into elts ring buffer and update elts_head if inlining
3735 * offload is requested. Otherwise the copying mbufs to elts
3736 * can be postponed and completed at the end of burst routine.
3739 * Pointer to TX queue structure.
3741 * Packets to transmit.
3743 * Number of packets in array.
3745 * Pointer to burst routine local context.
3747 * Configured Tx offloads mask. It is fully defined at
3748 * compile time and may be used for optimization.
3751 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3752 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3753 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3754 * MLX5_TXCMP_CODE_TSO - TSO packet encountered.
3755 * MLX5_TXCMP_CODE_SINGLE - used inside functions set.
3756 * MLX5_TXCMP_CODE_EMPW - used inside functions set.
3758 * Local context variables updated.
3761 * The routine sends packets with MLX5_OPCODE_EMPW
3762 * without inlining, this is dedicated optimized branch.
3763 * No VLAN insertion is supported.
3765 static __rte_always_inline enum mlx5_txcmp_code
3766 mlx5_tx_burst_empw_simple(struct mlx5_txq_data *restrict txq,
3767 struct rte_mbuf **restrict pkts,
3768 unsigned int pkts_n,
3769 struct mlx5_txq_local *restrict loc,
3773 * Subroutine is the part of mlx5_tx_burst_single()
3774 * and sends single-segment packet with eMPW opcode
3775 * without data inlining.
3777 assert(!MLX5_TXOFF_CONFIG(INLINE));
3778 assert(MLX5_TXOFF_CONFIG(EMPW));
3779 assert(loc->elts_free && loc->wqe_free);
3780 assert(pkts_n > loc->pkts_sent);
3781 static_assert(MLX5_EMPW_MIN_PACKETS >= 2, "invalid min size");
3782 pkts += loc->pkts_sent + 1;
3783 pkts_n -= loc->pkts_sent;
3785 struct mlx5_wqe_dseg *restrict dseg;
3786 struct mlx5_wqe_eseg *restrict eseg;
3787 enum mlx5_txcmp_code ret;
3788 unsigned int part, loop;
3789 unsigned int slen = 0;
3792 part = RTE_MIN(pkts_n, MLX5_EMPW_MAX_PACKETS);
3793 if (unlikely(loc->elts_free < part)) {
3794 /* We have no enough elts to save all mbufs. */
3795 if (unlikely(loc->elts_free < MLX5_EMPW_MIN_PACKETS))
3796 return MLX5_TXCMP_CODE_EXIT;
3797 /* But we still able to send at least minimal eMPW. */
3798 part = loc->elts_free;
3800 /* Check whether we have enough WQEs */
3801 if (unlikely(loc->wqe_free < ((2 + part + 3) / 4))) {
3802 if (unlikely(loc->wqe_free <
3803 ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
3804 return MLX5_TXCMP_CODE_EXIT;
3805 part = (loc->wqe_free * 4) - 2;
3807 if (likely(part > 1))
3808 rte_prefetch0(*pkts);
3809 loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3811 * Build eMPW title WQEBB:
3812 * - Control Segment, eMPW opcode
3813 * - Ethernet Segment, no inline
3815 mlx5_tx_cseg_init(txq, loc, loc->wqe_last, part + 2,
3816 MLX5_OPCODE_ENHANCED_MPSW, olx);
3817 mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
3818 olx & ~MLX5_TXOFF_CONFIG_VLAN);
3819 eseg = &loc->wqe_last->eseg;
3820 dseg = &loc->wqe_last->dseg[0];
3823 uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
3824 #ifdef MLX5_PMD_SOFT_COUNTERS
3825 /* Update sent data bytes counter. */
3830 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3832 if (unlikely(--loop == 0))
3834 loc->mbuf = *pkts++;
3835 if (likely(loop > 1))
3836 rte_prefetch0(*pkts);
3837 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3839 * Unroll the completion code to avoid
3840 * returning variable value - it results in
3841 * unoptimized sequent checking in caller.
3843 if (ret == MLX5_TXCMP_CODE_MULTI) {
3845 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3846 if (unlikely(!loc->elts_free ||
3848 return MLX5_TXCMP_CODE_EXIT;
3849 return MLX5_TXCMP_CODE_MULTI;
3851 if (ret == MLX5_TXCMP_CODE_TSO) {
3853 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3854 if (unlikely(!loc->elts_free ||
3856 return MLX5_TXCMP_CODE_EXIT;
3857 return MLX5_TXCMP_CODE_TSO;
3859 if (ret == MLX5_TXCMP_CODE_SINGLE) {
3861 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3862 if (unlikely(!loc->elts_free ||
3864 return MLX5_TXCMP_CODE_EXIT;
3865 return MLX5_TXCMP_CODE_SINGLE;
3867 if (ret != MLX5_TXCMP_CODE_EMPW) {
3870 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3871 return MLX5_TXCMP_CODE_ERROR;
3874 * Check whether packet parameters coincide
3875 * within assumed eMPW batch:
3876 * - check sum settings
3878 * - software parser settings
3880 if (!mlx5_tx_match_empw(txq, eseg, loc, olx)) {
3883 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3884 if (unlikely(!loc->elts_free ||
3886 return MLX5_TXCMP_CODE_EXIT;
3889 /* Packet attributes match, continue the same eMPW. */
3891 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3892 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3894 /* eMPW is built successfully, update loop parameters. */
3896 assert(pkts_n >= part);
3897 #ifdef MLX5_PMD_SOFT_COUNTERS
3898 /* Update sent data bytes counter. */
3899 txq->stats.obytes += slen;
3901 loc->elts_free -= part;
3902 loc->pkts_sent += part;
3903 txq->wqe_ci += (2 + part + 3) / 4;
3904 loc->wqe_free -= (2 + part + 3) / 4;
3906 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3907 return MLX5_TXCMP_CODE_EXIT;
3908 loc->mbuf = *pkts++;
3909 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3910 if (unlikely(ret != MLX5_TXCMP_CODE_EMPW))
3912 /* Continue sending eMPW batches. */
3918 * The routine sends packets with MLX5_OPCODE_EMPW
3919 * with inlining, optionally supports VLAN insertion.
3921 static __rte_always_inline enum mlx5_txcmp_code
3922 mlx5_tx_burst_empw_inline(struct mlx5_txq_data *restrict txq,
3923 struct rte_mbuf **restrict pkts,
3924 unsigned int pkts_n,
3925 struct mlx5_txq_local *restrict loc,
3929 * Subroutine is the part of mlx5_tx_burst_single()
3930 * and sends single-segment packet with eMPW opcode
3931 * with data inlining.
3933 assert(MLX5_TXOFF_CONFIG(INLINE));
3934 assert(MLX5_TXOFF_CONFIG(EMPW));
3935 assert(loc->elts_free && loc->wqe_free);
3936 assert(pkts_n > loc->pkts_sent);
3937 static_assert(MLX5_EMPW_MIN_PACKETS >= 2, "invalid min size");
3938 pkts += loc->pkts_sent + 1;
3939 pkts_n -= loc->pkts_sent;
3941 struct mlx5_wqe_dseg *restrict dseg;
3942 struct mlx5_wqe_eseg *restrict eseg;
3943 enum mlx5_txcmp_code ret;
3944 unsigned int room, part;
3945 unsigned int slen = 0;
3948 /* Check whether we have minimal amount WQEs */
3949 if (unlikely(loc->wqe_free <
3950 ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
3951 return MLX5_TXCMP_CODE_EXIT;
3952 if (likely(pkts_n > 1))
3953 rte_prefetch0(*pkts);
3954 loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3956 * Build eMPW title WQEBB:
3957 * - Control Segment, eMPW opcode, zero DS
3958 * - Ethernet Segment, no inline
3960 mlx5_tx_cseg_init(txq, loc, loc->wqe_last, 0,
3961 MLX5_OPCODE_ENHANCED_MPSW, olx);
3962 mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
3963 olx & ~MLX5_TXOFF_CONFIG_VLAN);
3964 eseg = &loc->wqe_last->eseg;
3965 dseg = &loc->wqe_last->dseg[0];
3966 room = RTE_MIN(MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE,
3967 loc->wqe_free) * MLX5_WQE_SIZE -
3968 MLX5_WQE_CSEG_SIZE -
3970 /* Build WQE till we have space, packets and resources. */
3973 uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
3974 uint8_t *dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
3977 assert(room >= MLX5_WQE_DSEG_SIZE);
3978 assert((room % MLX5_WQE_DSEG_SIZE) == 0);
3979 assert((uintptr_t)dseg < (uintptr_t)txq->wqes_end);
3981 * Some Tx offloads may cause an error if
3982 * packet is not long enough, check against
3983 * assumed minimal length.
3985 if (unlikely(dlen <= MLX5_ESEG_MIN_INLINE_SIZE)) {
3987 if (unlikely(!part))
3988 return MLX5_TXCMP_CODE_ERROR;
3990 * We have some successfully built
3991 * packet Data Segments to send.
3993 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
3994 return MLX5_TXCMP_CODE_ERROR;
3996 /* Inline or not inline - that's the Question. */
3997 if (dlen > txq->inlen_empw)
3999 /* Inline entire packet, optional VLAN insertion. */
4000 tlen = sizeof(dseg->bcount) + dlen;
4001 if (MLX5_TXOFF_CONFIG(VLAN) &&
4002 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
4004 * The packet length must be checked in
4005 * mlx5_tx_able_to_empw() and packet
4006 * fits into inline length guaranteed.
4008 assert((dlen + sizeof(struct rte_vlan_hdr)) <=
4010 tlen += sizeof(struct rte_vlan_hdr);
4013 dseg = mlx5_tx_dseg_vlan(txq, loc, dseg,
4015 #ifdef MLX5_PMD_SOFT_COUNTERS
4016 /* Update sent data bytes counter. */
4017 slen += sizeof(struct rte_vlan_hdr);
4022 dseg = mlx5_tx_dseg_empw(txq, loc, dseg,
4025 tlen = RTE_ALIGN(tlen, MLX5_WSEG_SIZE);
4026 assert(room >= tlen);
4029 * Packet data are completely inlined,
4030 * free the packet immediately.
4032 rte_pktmbuf_free_seg(loc->mbuf);
4036 * Not inlinable VLAN packets are
4037 * proceeded outside of this routine.
4039 assert(room >= MLX5_WQE_DSEG_SIZE);
4040 if (MLX5_TXOFF_CONFIG(VLAN))
4041 assert(!(loc->mbuf->ol_flags &
4043 mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
4044 /* We have to store mbuf in elts.*/
4045 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
4046 room -= MLX5_WQE_DSEG_SIZE;
4047 /* Ring buffer wraparound is checked at the loop end.*/
4050 #ifdef MLX5_PMD_SOFT_COUNTERS
4051 /* Update sent data bytes counter. */
4057 if (unlikely(!pkts_n || !loc->elts_free)) {
4059 * We have no resources/packets to
4060 * continue build descriptors.
4063 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4064 return MLX5_TXCMP_CODE_EXIT;
4066 /* Check if we have minimal room left. */
4067 if (room < MLX5_WQE_DSEG_SIZE) {
4069 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4072 loc->mbuf = *pkts++;
4073 if (likely(pkts_n > 1))
4074 rte_prefetch0(*pkts);
4075 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4077 * Unroll the completion code to avoid
4078 * returning variable value - it results in
4079 * unoptimized sequent checking in caller.
4081 if (ret == MLX5_TXCMP_CODE_MULTI) {
4083 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4084 if (unlikely(!loc->elts_free ||
4086 return MLX5_TXCMP_CODE_EXIT;
4087 return MLX5_TXCMP_CODE_MULTI;
4089 if (ret == MLX5_TXCMP_CODE_TSO) {
4091 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4092 if (unlikely(!loc->elts_free ||
4094 return MLX5_TXCMP_CODE_EXIT;
4095 return MLX5_TXCMP_CODE_TSO;
4097 if (ret == MLX5_TXCMP_CODE_SINGLE) {
4099 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4100 if (unlikely(!loc->elts_free ||
4102 return MLX5_TXCMP_CODE_EXIT;
4103 return MLX5_TXCMP_CODE_SINGLE;
4105 if (ret != MLX5_TXCMP_CODE_EMPW) {
4108 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4109 return MLX5_TXCMP_CODE_ERROR;
4112 * Check whether packet parameters coincide
4113 * within assumed eMPW batch:
4114 * - check sum settings
4116 * - software parser settings
4118 if (!mlx5_tx_match_empw(txq, eseg, loc, olx))
4120 /* Packet attributes match, continue the same eMPW. */
4121 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
4122 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
4125 * We get here to close an existing eMPW
4126 * session and start the new one.
4130 if (unlikely(!part))
4131 return MLX5_TXCMP_CODE_EXIT;
4132 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4133 if (unlikely(!loc->elts_free ||
4135 return MLX5_TXCMP_CODE_EXIT;
4142 * The routine sends packets with ordinary MLX5_OPCODE_SEND.
4143 * Data inlining and VLAN insertion are supported.
4145 static __rte_always_inline enum mlx5_txcmp_code
4146 mlx5_tx_burst_single_send(struct mlx5_txq_data *restrict txq,
4147 struct rte_mbuf **restrict pkts,
4148 unsigned int pkts_n,
4149 struct mlx5_txq_local *restrict loc,
4153 * Subroutine is the part of mlx5_tx_burst_single()
4154 * and sends single-segment packet with SEND opcode.
4156 assert(loc->elts_free && loc->wqe_free);
4157 assert(pkts_n > loc->pkts_sent);
4158 pkts += loc->pkts_sent + 1;
4159 pkts_n -= loc->pkts_sent;
4161 struct mlx5_wqe *restrict wqe;
4162 enum mlx5_txcmp_code ret;
4164 assert(NB_SEGS(loc->mbuf) == 1);
4165 if (MLX5_TXOFF_CONFIG(INLINE)) {
4166 unsigned int inlen, vlan = 0;
4168 inlen = rte_pktmbuf_data_len(loc->mbuf);
4169 if (MLX5_TXOFF_CONFIG(VLAN) &&
4170 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
4171 vlan = sizeof(struct rte_vlan_hdr);
4173 static_assert((sizeof(struct rte_vlan_hdr) +
4174 sizeof(struct rte_ether_hdr)) ==
4175 MLX5_ESEG_MIN_INLINE_SIZE,
4176 "invalid min inline data size");
4179 * If inlining is enabled at configuration time
4180 * the limit must be not less than minimal size.
4181 * Otherwise we would do extra check for data
4182 * size to avoid crashes due to length overflow.
4184 assert(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
4185 if (inlen <= txq->inlen_send) {
4186 unsigned int seg_n, wqe_n;
4188 rte_prefetch0(rte_pktmbuf_mtod
4189 (loc->mbuf, uint8_t *));
4190 /* Check against minimal length. */
4191 if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
4192 return MLX5_TXCMP_CODE_ERROR;
4194 * Completely inlined packet data WQE:
4195 * - Control Segment, SEND opcode
4196 * - Ethernet Segment, no VLAN insertion
4197 * - Data inlined, VLAN optionally inserted
4198 * - Alignment to MLX5_WSEG_SIZE
4199 * Have to estimate amount of WQEBBs
4201 seg_n = (inlen + 3 * MLX5_WSEG_SIZE -
4202 MLX5_ESEG_MIN_INLINE_SIZE +
4203 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
4204 /* Check if there are enough WQEBBs. */
4205 wqe_n = (seg_n + 3) / 4;
4206 if (wqe_n > loc->wqe_free)
4207 return MLX5_TXCMP_CODE_EXIT;
4208 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4209 loc->wqe_last = wqe;
4210 mlx5_tx_cseg_init(txq, loc, wqe, seg_n,
4211 MLX5_OPCODE_SEND, olx);
4212 mlx5_tx_eseg_data(txq, loc, wqe,
4213 vlan, inlen, 0, olx);
4214 txq->wqe_ci += wqe_n;
4215 loc->wqe_free -= wqe_n;
4217 * Packet data are completely inlined,
4218 * free the packet immediately.
4220 rte_pktmbuf_free_seg(loc->mbuf);
4221 } else if (!MLX5_TXOFF_CONFIG(EMPW) &&
4224 * If minimal inlining is requested the eMPW
4225 * feature should be disabled due to data is
4226 * inlined into Ethernet Segment, which can
4227 * not contain inlined data for eMPW due to
4228 * segment shared for all packets.
4230 struct mlx5_wqe_dseg *restrict dseg;
4235 * The inline-mode settings require
4236 * to inline the specified amount of
4237 * data bytes to the Ethernet Segment.
4238 * We should check the free space in
4239 * WQE ring buffer to inline partially.
4241 assert(txq->inlen_send >= txq->inlen_mode);
4242 assert(inlen > txq->inlen_mode);
4243 assert(txq->inlen_mode >=
4244 MLX5_ESEG_MIN_INLINE_SIZE);
4246 * Check whether there are enough free WQEBBs:
4248 * - Ethernet Segment
4249 * - First Segment of inlined Ethernet data
4250 * - ... data continued ...
4251 * - Finishing Data Segment of pointer type
4253 ds = (MLX5_WQE_CSEG_SIZE +
4254 MLX5_WQE_ESEG_SIZE +
4255 MLX5_WQE_DSEG_SIZE +
4257 MLX5_ESEG_MIN_INLINE_SIZE +
4258 MLX5_WQE_DSEG_SIZE +
4259 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
4260 if (loc->wqe_free < ((ds + 3) / 4))
4261 return MLX5_TXCMP_CODE_EXIT;
4263 * Build the ordinary SEND WQE:
4265 * - Ethernet Segment, inline inlen_mode bytes
4266 * - Data Segment of pointer type
4268 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4269 loc->wqe_last = wqe;
4270 mlx5_tx_cseg_init(txq, loc, wqe, ds,
4271 MLX5_OPCODE_SEND, olx);
4272 dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan,
4275 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
4276 txq->inlen_mode - vlan;
4277 inlen -= txq->inlen_mode;
4278 mlx5_tx_dseg_ptr(txq, loc, dseg,
4281 * WQE is built, update the loop parameters
4282 * and got to the next packet.
4284 txq->wqe_ci += (ds + 3) / 4;
4285 loc->wqe_free -= (ds + 3) / 4;
4286 /* We have to store mbuf in elts.*/
4287 assert(MLX5_TXOFF_CONFIG(INLINE));
4288 txq->elts[txq->elts_head++ & txq->elts_m] =
4296 * Partially inlined packet data WQE, we have
4297 * some space in title WQEBB, we can fill it
4298 * with some packet data. It takes one WQEBB,
4299 * it is available, no extra space check:
4300 * - Control Segment, SEND opcode
4301 * - Ethernet Segment, no VLAN insertion
4302 * - MLX5_ESEG_MIN_INLINE_SIZE bytes of Data
4303 * - Data Segment, pointer type
4305 * We also get here if VLAN insertion is not
4306 * supported by HW, the inline is enabled.
4308 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4309 loc->wqe_last = wqe;
4310 mlx5_tx_cseg_init(txq, loc, wqe, 4,
4311 MLX5_OPCODE_SEND, olx);
4312 mlx5_tx_eseg_dmin(txq, loc, wqe, vlan, olx);
4313 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
4314 MLX5_ESEG_MIN_INLINE_SIZE - vlan;
4316 * The length check is performed above, by
4317 * comparing with txq->inlen_send. We should
4318 * not get overflow here.
4320 assert(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
4321 dlen = inlen - MLX5_ESEG_MIN_INLINE_SIZE;
4322 mlx5_tx_dseg_ptr(txq, loc, &wqe->dseg[1],
4326 /* We have to store mbuf in elts.*/
4327 assert(MLX5_TXOFF_CONFIG(INLINE));
4328 txq->elts[txq->elts_head++ & txq->elts_m] =
4332 #ifdef MLX5_PMD_SOFT_COUNTERS
4333 /* Update sent data bytes counter. */
4334 txq->stats.obytes += vlan +
4335 rte_pktmbuf_data_len(loc->mbuf);
4339 * No inline at all, it means the CPU cycles saving
4340 * is prioritized at configuration, we should not
4341 * copy any packet data to WQE.
4343 * SEND WQE, one WQEBB:
4344 * - Control Segment, SEND opcode
4345 * - Ethernet Segment, optional VLAN, no inline
4346 * - Data Segment, pointer type
4348 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4349 loc->wqe_last = wqe;
4350 mlx5_tx_cseg_init(txq, loc, wqe, 3,
4351 MLX5_OPCODE_SEND, olx);
4352 mlx5_tx_eseg_none(txq, loc, wqe, olx);
4354 (txq, loc, &wqe->dseg[0],
4355 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
4356 rte_pktmbuf_data_len(loc->mbuf), olx);
4360 * We should not store mbuf pointer in elts
4361 * if no inlining is configured, this is done
4362 * by calling routine in a batch copy.
4364 assert(!MLX5_TXOFF_CONFIG(INLINE));
4366 #ifdef MLX5_PMD_SOFT_COUNTERS
4367 /* Update sent data bytes counter. */
4368 txq->stats.obytes += rte_pktmbuf_data_len(loc->mbuf);
4369 if (MLX5_TXOFF_CONFIG(VLAN) &&
4370 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
4371 txq->stats.obytes +=
4372 sizeof(struct rte_vlan_hdr);
4377 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
4378 return MLX5_TXCMP_CODE_EXIT;
4379 loc->mbuf = *pkts++;
4381 rte_prefetch0(*pkts);
4382 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4383 if (unlikely(ret != MLX5_TXCMP_CODE_SINGLE))
4389 static __rte_always_inline enum mlx5_txcmp_code
4390 mlx5_tx_burst_single(struct mlx5_txq_data *restrict txq,
4391 struct rte_mbuf **restrict pkts,
4392 unsigned int pkts_n,
4393 struct mlx5_txq_local *restrict loc,
4396 enum mlx5_txcmp_code ret;
4398 ret = mlx5_tx_able_to_empw(txq, loc, olx, false);
4399 if (ret == MLX5_TXCMP_CODE_SINGLE)
4401 assert(ret == MLX5_TXCMP_CODE_EMPW);
4403 /* Optimize for inline/no inline eMPW send. */
4404 ret = (MLX5_TXOFF_CONFIG(INLINE)) ?
4405 mlx5_tx_burst_empw_inline
4406 (txq, pkts, pkts_n, loc, olx) :
4407 mlx5_tx_burst_empw_simple
4408 (txq, pkts, pkts_n, loc, olx);
4409 if (ret != MLX5_TXCMP_CODE_SINGLE)
4411 /* The resources to send one packet should remain. */
4412 assert(loc->elts_free && loc->wqe_free);
4414 ret = mlx5_tx_burst_single_send(txq, pkts, pkts_n, loc, olx);
4415 assert(ret != MLX5_TXCMP_CODE_SINGLE);
4416 if (ret != MLX5_TXCMP_CODE_EMPW)
4418 /* The resources to send one packet should remain. */
4419 assert(loc->elts_free && loc->wqe_free);
4424 * DPDK Tx callback template. This is configured template
4425 * used to generate routines optimized for specified offload setup.
4426 * One of this generated functions is chosen at SQ configuration
4430 * Generic pointer to TX queue structure.
4432 * Packets to transmit.
4434 * Number of packets in array.
4436 * Configured offloads mask, presents the bits of MLX5_TXOFF_CONFIG_xxx
4437 * values. Should be static to take compile time static configuration
4441 * Number of packets successfully transmitted (<= pkts_n).
4443 static __rte_always_inline uint16_t
4444 mlx5_tx_burst_tmpl(struct mlx5_txq_data *restrict txq,
4445 struct rte_mbuf **restrict pkts,
4449 struct mlx5_txq_local loc;
4450 enum mlx5_txcmp_code ret;
4453 assert(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
4454 assert(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
4456 * Check if there are some CQEs, if any:
4457 * - process an encountered errors
4458 * - process the completed WQEs
4459 * - free related mbufs
4460 * - doorbell the NIC about processed CQEs
4462 if (unlikely(!pkts_n))
4464 rte_prefetch0(*pkts);
4465 mlx5_tx_handle_completion(txq, olx);
4467 * Calculate the number of available resources - elts and WQEs.
4468 * There are two possible different scenarios:
4469 * - no data inlining into WQEs, one WQEBB may contains upto
4470 * four packets, in this case elts become scarce resource
4471 * - data inlining into WQEs, one packet may require multiple
4472 * WQEBBs, the WQEs become the limiting factor.
4474 assert(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
4475 loc.elts_free = txq->elts_s -
4476 (uint16_t)(txq->elts_head - txq->elts_tail);
4477 assert(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
4478 loc.wqe_free = txq->wqe_s -
4479 (uint16_t)(txq->wqe_ci - txq->wqe_pi);
4480 if (unlikely(!loc.elts_free || !loc.wqe_free))
4484 loc.wqe_last = NULL;
4487 * Fetch the packet from array. Usually this is
4488 * the first packet in series of multi/single
4491 loc.mbuf = *(pkts + loc.pkts_sent);
4492 /* Dedicated branch for multi-segment packets. */
4493 if (MLX5_TXOFF_CONFIG(MULTI) &&
4494 unlikely(NB_SEGS(loc.mbuf) > 1)) {
4496 * Multi-segment packet encountered.
4497 * Hardware is able to process it only
4498 * with SEND/TSO opcodes, one packet
4499 * per WQE, do it in dedicated routine.
4502 assert(loc.pkts_sent >= loc.pkts_copy);
4503 part = loc.pkts_sent - loc.pkts_copy;
4504 if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
4506 * There are some single-segment mbufs not
4507 * stored in elts. The mbufs must be in the
4508 * same order as WQEs, so we must copy the
4509 * mbufs to elts here, before the coming
4510 * multi-segment packet mbufs is appended.
4512 mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy,
4514 loc.pkts_copy = loc.pkts_sent;
4516 assert(pkts_n > loc.pkts_sent);
4517 ret = mlx5_tx_burst_mseg(txq, pkts, pkts_n, &loc, olx);
4518 if (!MLX5_TXOFF_CONFIG(INLINE))
4519 loc.pkts_copy = loc.pkts_sent;
4521 * These returned code checks are supposed
4522 * to be optimized out due to routine inlining.
4524 if (ret == MLX5_TXCMP_CODE_EXIT) {
4526 * The routine returns this code when
4527 * all packets are sent or there is no
4528 * enough resources to complete request.
4532 if (ret == MLX5_TXCMP_CODE_ERROR) {
4534 * The routine returns this code when
4535 * some error in the incoming packets
4538 txq->stats.oerrors++;
4541 if (ret == MLX5_TXCMP_CODE_SINGLE) {
4543 * The single-segment packet was encountered
4544 * in the array, try to send it with the
4545 * best optimized way, possible engaging eMPW.
4547 goto enter_send_single;
4549 if (MLX5_TXOFF_CONFIG(TSO) &&
4550 ret == MLX5_TXCMP_CODE_TSO) {
4552 * The single-segment TSO packet was
4553 * encountered in the array.
4555 goto enter_send_tso;
4557 /* We must not get here. Something is going wrong. */
4559 txq->stats.oerrors++;
4562 /* Dedicated branch for single-segment TSO packets. */
4563 if (MLX5_TXOFF_CONFIG(TSO) &&
4564 unlikely(loc.mbuf->ol_flags & PKT_TX_TCP_SEG)) {
4566 * TSO might require special way for inlining
4567 * (dedicated parameters) and is sent with
4568 * MLX5_OPCODE_TSO opcode only, provide this
4569 * in dedicated branch.
4572 assert(NB_SEGS(loc.mbuf) == 1);
4573 assert(pkts_n > loc.pkts_sent);
4574 ret = mlx5_tx_burst_tso(txq, pkts, pkts_n, &loc, olx);
4576 * These returned code checks are supposed
4577 * to be optimized out due to routine inlining.
4579 if (ret == MLX5_TXCMP_CODE_EXIT)
4581 if (ret == MLX5_TXCMP_CODE_ERROR) {
4582 txq->stats.oerrors++;
4585 if (ret == MLX5_TXCMP_CODE_SINGLE)
4586 goto enter_send_single;
4587 if (MLX5_TXOFF_CONFIG(MULTI) &&
4588 ret == MLX5_TXCMP_CODE_MULTI) {
4590 * The multi-segment packet was
4591 * encountered in the array.
4593 goto enter_send_multi;
4595 /* We must not get here. Something is going wrong. */
4597 txq->stats.oerrors++;
4601 * The dedicated branch for the single-segment packets
4602 * without TSO. Often these ones can be sent using
4603 * MLX5_OPCODE_EMPW with multiple packets in one WQE.
4604 * The routine builds the WQEs till it encounters
4605 * the TSO or multi-segment packet (in case if these
4606 * offloads are requested at SQ configuration time).
4609 assert(pkts_n > loc.pkts_sent);
4610 ret = mlx5_tx_burst_single(txq, pkts, pkts_n, &loc, olx);
4612 * These returned code checks are supposed
4613 * to be optimized out due to routine inlining.
4615 if (ret == MLX5_TXCMP_CODE_EXIT)
4617 if (ret == MLX5_TXCMP_CODE_ERROR) {
4618 txq->stats.oerrors++;
4621 if (MLX5_TXOFF_CONFIG(MULTI) &&
4622 ret == MLX5_TXCMP_CODE_MULTI) {
4624 * The multi-segment packet was
4625 * encountered in the array.
4627 goto enter_send_multi;
4629 if (MLX5_TXOFF_CONFIG(TSO) &&
4630 ret == MLX5_TXCMP_CODE_TSO) {
4632 * The single-segment TSO packet was
4633 * encountered in the array.
4635 goto enter_send_tso;
4637 /* We must not get here. Something is going wrong. */
4639 txq->stats.oerrors++;
4643 * Main Tx loop is completed, do the rest:
4644 * - set completion request if thresholds are reached
4645 * - doorbell the hardware
4646 * - copy the rest of mbufs to elts (if any)
4648 assert(MLX5_TXOFF_CONFIG(INLINE) || loc.pkts_sent >= loc.pkts_copy);
4649 /* Take a shortcut if nothing is sent. */
4650 if (unlikely(loc.pkts_sent == 0))
4652 /* Not all of the mbufs may be stored into elts yet. */
4653 part = MLX5_TXOFF_CONFIG(INLINE) ? 0 : loc.pkts_sent - loc.pkts_copy;
4654 mlx5_tx_request_completion(txq, part, &loc, olx);
4656 * Ring QP doorbell immediately after WQE building completion
4657 * to improve latencies. The pure software related data treatment
4658 * can be completed after doorbell. Tx CQEs for this SQ are
4659 * processed in this thread only by the polling.
4661 mlx5_tx_dbrec_cond_wmb(txq, loc.wqe_last, 0);
4662 if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
4664 * There are some single-segment mbufs not stored in elts.
4665 * It can be only if last packet was single-segment.
4666 * The copying is gathered into one place due to it is
4667 * a good opportunity to optimize that with SIMD.
4668 * Unfortunately if inlining is enabled the gaps in
4669 * pointer array may happen due to early freeing of the
4672 mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy, part, olx);
4674 #ifdef MLX5_PMD_SOFT_COUNTERS
4675 /* Increment sent packets counter. */
4676 txq->stats.opackets += loc.pkts_sent;
4678 assert(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
4679 assert(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
4680 return loc.pkts_sent;
4683 /* Generate routines with Enhanced Multi-Packet Write support. */
4684 MLX5_TXOFF_DECL(full_empw,
4685 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_EMPW)
4687 MLX5_TXOFF_DECL(none_empw,
4688 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW)
4690 MLX5_TXOFF_DECL(md_empw,
4691 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4693 MLX5_TXOFF_DECL(mt_empw,
4694 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4695 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4697 MLX5_TXOFF_DECL(mtsc_empw,
4698 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4699 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4700 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4702 MLX5_TXOFF_DECL(mti_empw,
4703 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4704 MLX5_TXOFF_CONFIG_INLINE |
4705 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4707 MLX5_TXOFF_DECL(mtv_empw,
4708 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4709 MLX5_TXOFF_CONFIG_VLAN |
4710 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4712 MLX5_TXOFF_DECL(mtiv_empw,
4713 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4714 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4715 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4717 MLX5_TXOFF_DECL(sc_empw,
4718 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4719 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4721 MLX5_TXOFF_DECL(sci_empw,
4722 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4723 MLX5_TXOFF_CONFIG_INLINE |
4724 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4726 MLX5_TXOFF_DECL(scv_empw,
4727 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4728 MLX5_TXOFF_CONFIG_VLAN |
4729 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4731 MLX5_TXOFF_DECL(sciv_empw,
4732 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4733 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4734 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4736 MLX5_TXOFF_DECL(i_empw,
4737 MLX5_TXOFF_CONFIG_INLINE |
4738 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4740 MLX5_TXOFF_DECL(v_empw,
4741 MLX5_TXOFF_CONFIG_VLAN |
4742 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4744 MLX5_TXOFF_DECL(iv_empw,
4745 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4746 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4748 /* Generate routines without Enhanced Multi-Packet Write support. */
4749 MLX5_TXOFF_DECL(full,
4750 MLX5_TXOFF_CONFIG_FULL)
4752 MLX5_TXOFF_DECL(none,
4753 MLX5_TXOFF_CONFIG_NONE)
4756 MLX5_TXOFF_CONFIG_METADATA)
4759 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4760 MLX5_TXOFF_CONFIG_METADATA)
4762 MLX5_TXOFF_DECL(mtsc,
4763 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4764 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4765 MLX5_TXOFF_CONFIG_METADATA)
4767 MLX5_TXOFF_DECL(mti,
4768 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4769 MLX5_TXOFF_CONFIG_INLINE |
4770 MLX5_TXOFF_CONFIG_METADATA)
4773 MLX5_TXOFF_DECL(mtv,
4774 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4775 MLX5_TXOFF_CONFIG_VLAN |
4776 MLX5_TXOFF_CONFIG_METADATA)
4779 MLX5_TXOFF_DECL(mtiv,
4780 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4781 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4782 MLX5_TXOFF_CONFIG_METADATA)
4785 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4786 MLX5_TXOFF_CONFIG_METADATA)
4788 MLX5_TXOFF_DECL(sci,
4789 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4790 MLX5_TXOFF_CONFIG_INLINE |
4791 MLX5_TXOFF_CONFIG_METADATA)
4794 MLX5_TXOFF_DECL(scv,
4795 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4796 MLX5_TXOFF_CONFIG_VLAN |
4797 MLX5_TXOFF_CONFIG_METADATA)
4800 MLX5_TXOFF_DECL(sciv,
4801 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4802 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4803 MLX5_TXOFF_CONFIG_METADATA)
4806 MLX5_TXOFF_CONFIG_INLINE |
4807 MLX5_TXOFF_CONFIG_METADATA)
4810 MLX5_TXOFF_CONFIG_VLAN |
4811 MLX5_TXOFF_CONFIG_METADATA)
4814 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4815 MLX5_TXOFF_CONFIG_METADATA)
4818 * Array of declared and compiled Tx burst function and corresponding
4819 * supported offloads set. The array is used to select the Tx burst
4820 * function for specified offloads set at Tx queue configuration time.
4823 eth_tx_burst_t func;
4826 MLX5_TXOFF_INFO(full_empw,
4827 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4828 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4829 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4830 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4832 MLX5_TXOFF_INFO(none_empw,
4833 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW)
4835 MLX5_TXOFF_INFO(md_empw,
4836 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4838 MLX5_TXOFF_INFO(mt_empw,
4839 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4840 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4842 MLX5_TXOFF_INFO(mtsc_empw,
4843 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4844 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4845 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4847 MLX5_TXOFF_INFO(mti_empw,
4848 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4849 MLX5_TXOFF_CONFIG_INLINE |
4850 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4852 MLX5_TXOFF_INFO(mtv_empw,
4853 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4854 MLX5_TXOFF_CONFIG_VLAN |
4855 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4857 MLX5_TXOFF_INFO(mtiv_empw,
4858 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4859 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4860 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4862 MLX5_TXOFF_INFO(sc_empw,
4863 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4864 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4866 MLX5_TXOFF_INFO(sci_empw,
4867 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4868 MLX5_TXOFF_CONFIG_INLINE |
4869 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4871 MLX5_TXOFF_INFO(scv_empw,
4872 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4873 MLX5_TXOFF_CONFIG_VLAN |
4874 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4876 MLX5_TXOFF_INFO(sciv_empw,
4877 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4878 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4879 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4881 MLX5_TXOFF_INFO(i_empw,
4882 MLX5_TXOFF_CONFIG_INLINE |
4883 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4885 MLX5_TXOFF_INFO(v_empw,
4886 MLX5_TXOFF_CONFIG_VLAN |
4887 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4889 MLX5_TXOFF_INFO(iv_empw,
4890 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4891 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4893 MLX5_TXOFF_INFO(full,
4894 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4895 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4896 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4897 MLX5_TXOFF_CONFIG_METADATA)
4899 MLX5_TXOFF_INFO(none,
4900 MLX5_TXOFF_CONFIG_NONE)
4903 MLX5_TXOFF_CONFIG_METADATA)
4906 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4907 MLX5_TXOFF_CONFIG_METADATA)
4909 MLX5_TXOFF_INFO(mtsc,
4910 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4911 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4912 MLX5_TXOFF_CONFIG_METADATA)
4914 MLX5_TXOFF_INFO(mti,
4915 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4916 MLX5_TXOFF_CONFIG_INLINE |
4917 MLX5_TXOFF_CONFIG_METADATA)
4920 MLX5_TXOFF_INFO(mtv,
4921 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4922 MLX5_TXOFF_CONFIG_VLAN |
4923 MLX5_TXOFF_CONFIG_METADATA)
4925 MLX5_TXOFF_INFO(mtiv,
4926 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4927 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4928 MLX5_TXOFF_CONFIG_METADATA)
4931 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4932 MLX5_TXOFF_CONFIG_METADATA)
4934 MLX5_TXOFF_INFO(sci,
4935 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4936 MLX5_TXOFF_CONFIG_INLINE |
4937 MLX5_TXOFF_CONFIG_METADATA)
4939 MLX5_TXOFF_INFO(scv,
4940 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4941 MLX5_TXOFF_CONFIG_VLAN |
4942 MLX5_TXOFF_CONFIG_METADATA)
4944 MLX5_TXOFF_INFO(sciv,
4945 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4946 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4947 MLX5_TXOFF_CONFIG_METADATA)
4950 MLX5_TXOFF_CONFIG_INLINE |
4951 MLX5_TXOFF_CONFIG_METADATA)
4954 MLX5_TXOFF_CONFIG_VLAN |
4955 MLX5_TXOFF_CONFIG_METADATA)
4958 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4959 MLX5_TXOFF_CONFIG_METADATA)
4963 * Configure the Tx function to use. The routine checks configured
4964 * Tx offloads for the device and selects appropriate Tx burst
4965 * routine. There are multiple Tx burst routines compiled from
4966 * the same template in the most optimal way for the dedicated
4970 * Pointer to private data structure.
4973 * Pointer to selected Tx burst function.
4976 mlx5_select_tx_function(struct rte_eth_dev *dev)
4978 struct mlx5_priv *priv = dev->data->dev_private;
4979 struct mlx5_dev_config *config = &priv->config;
4980 uint64_t tx_offloads = dev->data->dev_conf.txmode.offloads;
4981 unsigned int diff = 0, olx = 0, i, m;
4983 static_assert(MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE <=
4984 MLX5_DSEG_MAX, "invalid WQE max size");
4985 static_assert(MLX5_WQE_CSEG_SIZE == MLX5_WSEG_SIZE,
4986 "invalid WQE Control Segment size");
4987 static_assert(MLX5_WQE_ESEG_SIZE == MLX5_WSEG_SIZE,
4988 "invalid WQE Ethernet Segment size");
4989 static_assert(MLX5_WQE_DSEG_SIZE == MLX5_WSEG_SIZE,
4990 "invalid WQE Data Segment size");
4991 static_assert(MLX5_WQE_SIZE == 4 * MLX5_WSEG_SIZE,
4992 "invalid WQE size");
4994 if (tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS) {
4995 /* We should support Multi-Segment Packets. */
4996 olx |= MLX5_TXOFF_CONFIG_MULTI;
4998 if (tx_offloads & (DEV_TX_OFFLOAD_TCP_TSO |
4999 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5000 DEV_TX_OFFLOAD_GRE_TNL_TSO |
5001 DEV_TX_OFFLOAD_IP_TNL_TSO |
5002 DEV_TX_OFFLOAD_UDP_TNL_TSO)) {
5003 /* We should support TCP Send Offload. */
5004 olx |= MLX5_TXOFF_CONFIG_TSO;
5006 if (tx_offloads & (DEV_TX_OFFLOAD_IP_TNL_TSO |
5007 DEV_TX_OFFLOAD_UDP_TNL_TSO |
5008 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
5009 /* We should support Software Parser for Tunnels. */
5010 olx |= MLX5_TXOFF_CONFIG_SWP;
5012 if (tx_offloads & (DEV_TX_OFFLOAD_IPV4_CKSUM |
5013 DEV_TX_OFFLOAD_UDP_CKSUM |
5014 DEV_TX_OFFLOAD_TCP_CKSUM |
5015 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
5016 /* We should support IP/TCP/UDP Checksums. */
5017 olx |= MLX5_TXOFF_CONFIG_CSUM;
5019 if (tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT) {
5020 /* We should support VLAN insertion. */
5021 olx |= MLX5_TXOFF_CONFIG_VLAN;
5023 if (priv->txqs_n && (*priv->txqs)[0]) {
5024 struct mlx5_txq_data *txd = (*priv->txqs)[0];
5026 if (txd->inlen_send) {
5028 * Check the data inline requirements. Data inline
5029 * is enabled on per device basis, we can check
5030 * the first Tx queue only.
5032 * If device does not support VLAN insertion in WQE
5033 * and some queues are requested to perform VLAN
5034 * insertion offload than inline must be enabled.
5036 olx |= MLX5_TXOFF_CONFIG_INLINE;
5039 if (config->mps == MLX5_MPW_ENHANCED &&
5040 config->txq_inline_min <= 0) {
5042 * The NIC supports Enhanced Multi-Packet Write.
5043 * We do not support legacy MPW due to its
5044 * hardware related problems, so we just ignore
5045 * legacy MLX5_MPW settings. There should be no
5046 * minimal required inline data.
5048 olx |= MLX5_TXOFF_CONFIG_EMPW;
5050 if (tx_offloads & DEV_TX_OFFLOAD_MATCH_METADATA) {
5051 /* We should support Flow metadata. */
5052 olx |= MLX5_TXOFF_CONFIG_METADATA;
5055 * Scan the routines table to find the minimal
5056 * satisfying routine with requested offloads.
5058 m = RTE_DIM(txoff_func);
5059 for (i = 0; i < RTE_DIM(txoff_func); i++) {
5062 tmp = txoff_func[i].olx;
5064 /* Meets requested offloads exactly.*/
5068 if ((tmp & olx) != olx) {
5069 /* Does not meet requested offloads at all. */
5072 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_EMPW)
5073 /* Do not enable eMPW if not configured. */
5075 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_INLINE)
5076 /* Do not enable inlining if not configured. */
5079 * Some routine meets the requirements.
5080 * Check whether it has minimal amount
5081 * of not requested offloads.
5083 tmp = __builtin_popcountl(tmp & ~olx);
5084 if (m >= RTE_DIM(txoff_func) || tmp < diff) {
5085 /* First or better match, save and continue. */
5091 tmp = txoff_func[i].olx ^ txoff_func[m].olx;
5092 if (__builtin_ffsl(txoff_func[i].olx & ~tmp) <
5093 __builtin_ffsl(txoff_func[m].olx & ~tmp)) {
5094 /* Lighter not requested offload. */
5099 if (m >= RTE_DIM(txoff_func)) {
5100 DRV_LOG(DEBUG, "port %u has no selected Tx function"
5101 " for requested offloads %04X",
5102 dev->data->port_id, olx);
5105 DRV_LOG(DEBUG, "port %u has selected Tx function"
5106 " supporting offloads %04X/%04X",
5107 dev->data->port_id, olx, txoff_func[m].olx);
5108 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_MULTI)
5109 DRV_LOG(DEBUG, "\tMULTI (multi segment)");
5110 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_TSO)
5111 DRV_LOG(DEBUG, "\tTSO (TCP send offload)");
5112 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_SWP)
5113 DRV_LOG(DEBUG, "\tSWP (software parser)");
5114 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_CSUM)
5115 DRV_LOG(DEBUG, "\tCSUM (checksum offload)");
5116 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_INLINE)
5117 DRV_LOG(DEBUG, "\tINLIN (inline data)");
5118 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_VLAN)
5119 DRV_LOG(DEBUG, "\tVLANI (VLAN insertion)");
5120 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_METADATA)
5121 DRV_LOG(DEBUG, "\tMETAD (tx Flow metadata)");
5122 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_EMPW)
5123 DRV_LOG(DEBUG, "\tEMPW (Enhanced MPW)");
5124 return txoff_func[m].func;