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 unsigned int count = MLX5_TX_COMP_MAX_CQE;
2031 bool update = false;
2032 uint16_t tail = txq->elts_tail;
2036 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);
2046 /* Some error occurred, try to restart. */
2048 tail = mlx5_tx_error_cqe_handle
2049 (txq, (volatile struct mlx5_err_cqe *)cqe);
2050 if (likely(tail != txq->elts_tail)) {
2051 mlx5_tx_free_elts(txq, tail, olx);
2052 assert(tail == txq->elts_tail);
2054 /* Allow flushing all CQEs from the queue. */
2057 volatile struct mlx5_wqe_cseg *cseg;
2059 /* Normal transmit completion. */
2062 txq->wqe_pi = rte_be_to_cpu_16(cqe->wqe_counter);
2063 cseg = (volatile struct mlx5_wqe_cseg *)
2064 (txq->wqes + (txq->wqe_pi & txq->wqe_m));
2073 * We have to restrict the amount of processed CQEs
2074 * in one tx_burst routine call. The CQ may be large
2075 * and many CQEs may be updated by the NIC in one
2076 * transaction. Buffers freeing is time consuming,
2077 * multiple iterations may introduce significant
2081 if (likely(tail != txq->elts_tail)) {
2082 /* Free data buffers from elts. */
2083 mlx5_tx_free_elts(txq, tail, olx);
2084 assert(tail == txq->elts_tail);
2086 if (likely(update)) {
2087 /* Update the consumer index. */
2088 rte_compiler_barrier();
2090 rte_cpu_to_be_32(txq->cq_ci);
2095 * Check if the completion request flag should be set in the last WQE.
2096 * Both pushed mbufs and WQEs are monitored and the completion request
2097 * flag is set if any of thresholds is reached.
2100 * Pointer to TX queue structure.
2102 * Number of mbuf not stored yet in elts array.
2104 * Pointer to burst routine local context.
2106 * Configured Tx offloads mask. It is fully defined at
2107 * compile time and may be used for optimization.
2109 static __rte_always_inline void
2110 mlx5_tx_request_completion(struct mlx5_txq_data *restrict txq,
2111 unsigned int n_mbuf,
2112 struct mlx5_txq_local *restrict loc,
2113 unsigned int olx __rte_unused)
2115 uint16_t head = txq->elts_head + n_mbuf;
2117 if ((uint16_t)(head - txq->elts_comp) >= MLX5_TX_COMP_THRESH ||
2118 (uint16_t)(txq->wqe_ci - txq->wqe_comp) >= txq->wqe_thres) {
2119 volatile struct mlx5_wqe *last = loc->wqe_last;
2121 txq->elts_comp = head;
2122 txq->wqe_comp = txq->wqe_ci;
2123 /* Request unconditional completion on last WQE. */
2124 last->cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
2125 MLX5_COMP_MODE_OFFSET);
2126 /* Save elts_head in unused "immediate" field of WQE. */
2127 last->cseg.misc = head;
2129 * A CQE slot must always be available. Count the
2130 * issued CEQ "always" request instead of production
2131 * index due to here can be CQE with errors and
2132 * difference with ci may become inconsistent.
2134 assert(txq->cqe_s > ++txq->cq_pi);
2139 * DPDK callback to check the status of a tx descriptor.
2144 * The index of the descriptor in the ring.
2147 * The status of the tx descriptor.
2150 mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset)
2152 struct mlx5_txq_data *restrict txq = tx_queue;
2155 mlx5_tx_handle_completion(txq, 0);
2156 used = txq->elts_head - txq->elts_tail;
2158 return RTE_ETH_TX_DESC_FULL;
2159 return RTE_ETH_TX_DESC_DONE;
2163 * Build the Control Segment with specified opcode:
2164 * - MLX5_OPCODE_SEND
2165 * - MLX5_OPCODE_ENHANCED_MPSW
2169 * Pointer to TX queue structure.
2171 * Pointer to burst routine local context.
2173 * Pointer to WQE to fill with built Control Segment.
2175 * Supposed length of WQE in segments.
2177 * SQ WQE opcode to put into Control Segment.
2179 * Configured Tx offloads mask. It is fully defined at
2180 * compile time and may be used for optimization.
2182 static __rte_always_inline void
2183 mlx5_tx_cseg_init(struct mlx5_txq_data *restrict txq,
2184 struct mlx5_txq_local *restrict loc __rte_unused,
2185 struct mlx5_wqe *restrict wqe,
2187 unsigned int opcode,
2188 unsigned int olx __rte_unused)
2190 struct mlx5_wqe_cseg *restrict cs = &wqe->cseg;
2192 cs->opcode = rte_cpu_to_be_32((txq->wqe_ci << 8) | opcode);
2193 cs->sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
2194 cs->flags = RTE_BE32(MLX5_COMP_ONLY_FIRST_ERR <<
2195 MLX5_COMP_MODE_OFFSET);
2196 cs->misc = RTE_BE32(0);
2200 * Build the Ethernet Segment without inlined data.
2201 * Supports Software Parser, Checksums and VLAN
2202 * insertion Tx offload features.
2205 * Pointer to TX queue structure.
2207 * Pointer to burst routine local context.
2209 * Pointer to WQE to fill with built Ethernet Segment.
2211 * Configured Tx offloads mask. It is fully defined at
2212 * compile time and may be used for optimization.
2214 static __rte_always_inline void
2215 mlx5_tx_eseg_none(struct mlx5_txq_data *restrict txq __rte_unused,
2216 struct mlx5_txq_local *restrict loc,
2217 struct mlx5_wqe *restrict wqe,
2220 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2224 * Calculate and set check sum flags first, dword field
2225 * in segment may be shared with Software Parser flags.
2227 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2228 es->flags = rte_cpu_to_le_32(csum);
2230 * Calculate and set Software Parser offsets and flags.
2231 * These flags a set for custom UDP and IP tunnel packets.
2233 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2234 /* Fill metadata field if needed. */
2235 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2236 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2237 loc->mbuf->tx_metadata : 0 : 0;
2238 /* Engage VLAN tag insertion feature if requested. */
2239 if (MLX5_TXOFF_CONFIG(VLAN) &&
2240 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
2242 * We should get here only if device support
2243 * this feature correctly.
2245 assert(txq->vlan_en);
2246 es->inline_hdr = rte_cpu_to_be_32(MLX5_ETH_WQE_VLAN_INSERT |
2247 loc->mbuf->vlan_tci);
2249 es->inline_hdr = RTE_BE32(0);
2254 * Build the Ethernet Segment with minimal inlined data
2255 * of MLX5_ESEG_MIN_INLINE_SIZE bytes length. This is
2256 * used to fill the gap in single WQEBB WQEs.
2257 * Supports Software Parser, Checksums and VLAN
2258 * insertion Tx offload features.
2261 * Pointer to TX queue structure.
2263 * Pointer to burst routine local context.
2265 * Pointer to WQE to fill with built Ethernet Segment.
2267 * Length of VLAN tag insertion if any.
2269 * Configured Tx offloads mask. It is fully defined at
2270 * compile time and may be used for optimization.
2272 static __rte_always_inline void
2273 mlx5_tx_eseg_dmin(struct mlx5_txq_data *restrict txq __rte_unused,
2274 struct mlx5_txq_local *restrict loc,
2275 struct mlx5_wqe *restrict wqe,
2279 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2281 uint8_t *psrc, *pdst;
2284 * Calculate and set check sum flags first, dword field
2285 * in segment may be shared with Software Parser flags.
2287 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2288 es->flags = rte_cpu_to_le_32(csum);
2290 * Calculate and set Software Parser offsets and flags.
2291 * These flags a set for custom UDP and IP tunnel packets.
2293 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2294 /* Fill metadata field if needed. */
2295 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2296 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2297 loc->mbuf->tx_metadata : 0 : 0;
2298 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2300 sizeof(rte_v128u32_t)),
2301 "invalid Ethernet Segment data size");
2302 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2304 sizeof(struct rte_vlan_hdr) +
2305 2 * RTE_ETHER_ADDR_LEN),
2306 "invalid Ethernet Segment data size");
2307 psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2308 es->inline_hdr_sz = RTE_BE16(MLX5_ESEG_MIN_INLINE_SIZE);
2309 es->inline_data = *(unaligned_uint16_t *)psrc;
2310 psrc += sizeof(uint16_t);
2311 pdst = (uint8_t *)(es + 1);
2312 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2313 /* Implement VLAN tag insertion as part inline data. */
2314 memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
2315 pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2316 psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2317 /* Insert VLAN ethertype + VLAN tag. */
2318 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2319 ((RTE_ETHER_TYPE_VLAN << 16) |
2320 loc->mbuf->vlan_tci);
2321 pdst += sizeof(struct rte_vlan_hdr);
2322 /* Copy the rest two bytes from packet data. */
2323 assert(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
2324 *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
2326 /* Fill the gap in the title WQEBB with inline data. */
2327 rte_mov16(pdst, psrc);
2332 * Build the Ethernet Segment with entire packet
2333 * data inlining. Checks the boundary of WQEBB and
2334 * ring buffer wrapping, supports Software Parser,
2335 * Checksums and VLAN insertion Tx offload features.
2338 * Pointer to TX queue structure.
2340 * Pointer to burst routine local context.
2342 * Pointer to WQE to fill with built Ethernet Segment.
2344 * Length of VLAN tag insertion if any.
2346 * Length of data to inline (VLAN included, if any).
2348 * TSO flag, set mss field from the packet.
2350 * Configured Tx offloads mask. It is fully defined at
2351 * compile time and may be used for optimization.
2354 * Pointer to the next Data Segment (aligned and wrapped around).
2356 static __rte_always_inline struct mlx5_wqe_dseg *
2357 mlx5_tx_eseg_data(struct mlx5_txq_data *restrict txq,
2358 struct mlx5_txq_local *restrict loc,
2359 struct mlx5_wqe *restrict wqe,
2365 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2367 uint8_t *psrc, *pdst;
2371 * Calculate and set check sum flags first, dword field
2372 * in segment may be shared with Software Parser flags.
2374 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2377 csum |= loc->mbuf->tso_segsz;
2378 es->flags = rte_cpu_to_be_32(csum);
2380 es->flags = rte_cpu_to_le_32(csum);
2383 * Calculate and set Software Parser offsets and flags.
2384 * These flags a set for custom UDP and IP tunnel packets.
2386 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2387 /* Fill metadata field if needed. */
2388 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2389 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2390 loc->mbuf->tx_metadata : 0 : 0;
2391 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2393 sizeof(rte_v128u32_t)),
2394 "invalid Ethernet Segment data size");
2395 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2397 sizeof(struct rte_vlan_hdr) +
2398 2 * RTE_ETHER_ADDR_LEN),
2399 "invalid Ethernet Segment data size");
2400 psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2401 es->inline_hdr_sz = rte_cpu_to_be_16(inlen);
2402 es->inline_data = *(unaligned_uint16_t *)psrc;
2403 psrc += sizeof(uint16_t);
2404 pdst = (uint8_t *)(es + 1);
2405 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2406 /* Implement VLAN tag insertion as part inline data. */
2407 memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
2408 pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2409 psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
2410 /* Insert VLAN ethertype + VLAN tag. */
2411 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2412 ((RTE_ETHER_TYPE_VLAN << 16) |
2413 loc->mbuf->vlan_tci);
2414 pdst += sizeof(struct rte_vlan_hdr);
2415 /* Copy the rest two bytes from packet data. */
2416 assert(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
2417 *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
2418 psrc += sizeof(uint16_t);
2420 /* Fill the gap in the title WQEBB with inline data. */
2421 rte_mov16(pdst, psrc);
2422 psrc += sizeof(rte_v128u32_t);
2424 pdst = (uint8_t *)(es + 2);
2425 assert(inlen >= MLX5_ESEG_MIN_INLINE_SIZE);
2426 assert(pdst < (uint8_t *)txq->wqes_end);
2427 inlen -= MLX5_ESEG_MIN_INLINE_SIZE;
2429 assert(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
2430 return (struct mlx5_wqe_dseg *)pdst;
2433 * The WQEBB space availability is checked by caller.
2434 * Here we should be aware of WQE ring buffer wraparound only.
2436 part = (uint8_t *)txq->wqes_end - pdst;
2437 part = RTE_MIN(part, inlen);
2439 rte_memcpy(pdst, psrc, part);
2441 if (likely(!inlen)) {
2443 * If return value is not used by the caller
2444 * the code below will be optimized out.
2447 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2448 if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
2449 pdst = (uint8_t *)txq->wqes;
2450 return (struct mlx5_wqe_dseg *)pdst;
2452 pdst = (uint8_t *)txq->wqes;
2459 * Copy data from chain of mbuf to the specified linear buffer.
2460 * Checksums and VLAN insertion Tx offload features. If data
2461 * from some mbuf copied completely this mbuf is freed. Local
2462 * structure is used to keep the byte stream state.
2465 * Pointer to the destination linear buffer.
2467 * Pointer to burst routine local context.
2469 * Length of data to be copied.
2471 * Configured Tx offloads mask. It is fully defined at
2472 * compile time and may be used for optimization.
2474 static __rte_always_inline void
2475 mlx5_tx_mseg_memcpy(uint8_t *pdst,
2476 struct mlx5_txq_local *restrict loc,
2478 unsigned int olx __rte_unused)
2480 struct rte_mbuf *mbuf;
2481 unsigned int part, dlen;
2486 /* Allow zero length packets, must check first. */
2487 dlen = rte_pktmbuf_data_len(loc->mbuf);
2488 if (dlen <= loc->mbuf_off) {
2489 /* Exhausted packet, just free. */
2491 loc->mbuf = mbuf->next;
2492 rte_pktmbuf_free_seg(mbuf);
2494 assert(loc->mbuf_nseg > 1);
2499 dlen -= loc->mbuf_off;
2500 psrc = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
2502 part = RTE_MIN(len, dlen);
2503 rte_memcpy(pdst, psrc, part);
2504 loc->mbuf_off += part;
2507 if (loc->mbuf_off >= rte_pktmbuf_data_len(loc->mbuf)) {
2509 /* Exhausted packet, just free. */
2511 loc->mbuf = mbuf->next;
2512 rte_pktmbuf_free_seg(mbuf);
2514 assert(loc->mbuf_nseg >= 1);
2524 * Build the Ethernet Segment with inlined data from
2525 * multi-segment packet. Checks the boundary of WQEBB
2526 * and ring buffer wrapping, supports Software Parser,
2527 * Checksums and VLAN insertion Tx offload features.
2530 * Pointer to TX queue structure.
2532 * Pointer to burst routine local context.
2534 * Pointer to WQE to fill with built Ethernet Segment.
2536 * Length of VLAN tag insertion if any.
2538 * Length of data to inline (VLAN included, if any).
2540 * TSO flag, set mss field from the packet.
2542 * Configured Tx offloads mask. It is fully defined at
2543 * compile time and may be used for optimization.
2546 * Pointer to the next Data Segment (aligned and
2547 * possible NOT wrapped around - caller should do
2548 * wrapping check on its own).
2550 static __rte_always_inline struct mlx5_wqe_dseg *
2551 mlx5_tx_eseg_mdat(struct mlx5_txq_data *restrict txq,
2552 struct mlx5_txq_local *restrict loc,
2553 struct mlx5_wqe *restrict wqe,
2559 struct mlx5_wqe_eseg *restrict es = &wqe->eseg;
2565 * Calculate and set check sum flags first, uint32_t field
2566 * in segment may be shared with Software Parser flags.
2568 csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
2571 csum |= loc->mbuf->tso_segsz;
2572 es->flags = rte_cpu_to_be_32(csum);
2574 es->flags = rte_cpu_to_le_32(csum);
2577 * Calculate and set Software Parser offsets and flags.
2578 * These flags a set for custom UDP and IP tunnel packets.
2580 es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
2581 /* Fill metadata field if needed. */
2582 es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
2583 loc->mbuf->ol_flags & PKT_TX_METADATA ?
2584 loc->mbuf->tx_metadata : 0 : 0;
2585 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2587 sizeof(rte_v128u32_t)),
2588 "invalid Ethernet Segment data size");
2589 static_assert(MLX5_ESEG_MIN_INLINE_SIZE ==
2591 sizeof(struct rte_vlan_hdr) +
2592 2 * RTE_ETHER_ADDR_LEN),
2593 "invalid Ethernet Segment data size");
2594 assert(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
2595 es->inline_hdr_sz = rte_cpu_to_be_16(inlen);
2596 pdst = (uint8_t *)&es->inline_data;
2597 if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
2598 /* Implement VLAN tag insertion as part inline data. */
2599 mlx5_tx_mseg_memcpy(pdst, loc, 2 * RTE_ETHER_ADDR_LEN, olx);
2600 pdst += 2 * RTE_ETHER_ADDR_LEN;
2601 *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
2602 ((RTE_ETHER_TYPE_VLAN << 16) |
2603 loc->mbuf->vlan_tci);
2604 pdst += sizeof(struct rte_vlan_hdr);
2605 inlen -= 2 * RTE_ETHER_ADDR_LEN + sizeof(struct rte_vlan_hdr);
2607 assert(pdst < (uint8_t *)txq->wqes_end);
2609 * The WQEBB space availability is checked by caller.
2610 * Here we should be aware of WQE ring buffer wraparound only.
2612 part = (uint8_t *)txq->wqes_end - pdst;
2613 part = RTE_MIN(part, inlen);
2616 mlx5_tx_mseg_memcpy(pdst, loc, part, olx);
2618 if (likely(!inlen)) {
2620 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2621 return (struct mlx5_wqe_dseg *)pdst;
2623 pdst = (uint8_t *)txq->wqes;
2629 * Build the Data Segment of pointer type.
2632 * Pointer to TX queue structure.
2634 * Pointer to burst routine local context.
2636 * Pointer to WQE to fill with built Data Segment.
2638 * Data buffer to point.
2640 * Data buffer length.
2642 * Configured Tx offloads mask. It is fully defined at
2643 * compile time and may be used for optimization.
2645 static __rte_always_inline void
2646 mlx5_tx_dseg_ptr(struct mlx5_txq_data *restrict txq,
2647 struct mlx5_txq_local *restrict loc,
2648 struct mlx5_wqe_dseg *restrict dseg,
2651 unsigned int olx __rte_unused)
2655 dseg->bcount = rte_cpu_to_be_32(len);
2656 dseg->lkey = mlx5_tx_mb2mr(txq, loc->mbuf);
2657 dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
2661 * Build the Data Segment of pointer type or inline
2662 * if data length is less than buffer in minimal
2663 * Data Segment size.
2666 * Pointer to TX queue structure.
2668 * Pointer to burst routine local context.
2670 * Pointer to WQE to fill with built Data Segment.
2672 * Data buffer to point.
2674 * Data buffer length.
2676 * Configured Tx offloads mask. It is fully defined at
2677 * compile time and may be used for optimization.
2679 static __rte_always_inline void
2680 mlx5_tx_dseg_iptr(struct mlx5_txq_data *restrict txq,
2681 struct mlx5_txq_local *restrict loc,
2682 struct mlx5_wqe_dseg *restrict dseg,
2685 unsigned int olx __rte_unused)
2691 if (len > MLX5_DSEG_MIN_INLINE_SIZE) {
2692 dseg->bcount = rte_cpu_to_be_32(len);
2693 dseg->lkey = mlx5_tx_mb2mr(txq, loc->mbuf);
2694 dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
2698 dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
2699 /* Unrolled implementation of generic rte_memcpy. */
2700 dst = (uintptr_t)&dseg->inline_data[0];
2701 src = (uintptr_t)buf;
2702 #ifdef RTE_ARCH_STRICT_ALIGN
2703 memcpy(dst, src, len);
2706 *(uint64_t *)dst = *(uint64_t *)src;
2707 dst += sizeof(uint64_t);
2708 src += sizeof(uint64_t);
2711 *(uint32_t *)dst = *(uint32_t *)src;
2712 dst += sizeof(uint32_t);
2713 src += sizeof(uint32_t);
2716 *(uint16_t *)dst = *(uint16_t *)src;
2717 dst += sizeof(uint16_t);
2718 src += sizeof(uint16_t);
2721 *(uint8_t *)dst = *(uint8_t *)src;
2726 * Build the Data Segment of inlined data from single
2727 * segment packet, no VLAN insertion.
2730 * Pointer to TX queue structure.
2732 * Pointer to burst routine local context.
2734 * Pointer to WQE to fill with built Data Segment.
2736 * Data buffer to point.
2738 * Data buffer length.
2740 * Configured Tx offloads mask. It is fully defined at
2741 * compile time and may be used for optimization.
2744 * Pointer to the next Data Segment after inlined data.
2745 * Ring buffer wraparound check is needed. We do not
2746 * do it here because it may not be needed for the
2747 * last packet in the eMPW session.
2749 static __rte_always_inline struct mlx5_wqe_dseg *
2750 mlx5_tx_dseg_empw(struct mlx5_txq_data *restrict txq,
2751 struct mlx5_txq_local *restrict loc __rte_unused,
2752 struct mlx5_wqe_dseg *restrict dseg,
2755 unsigned int olx __rte_unused)
2760 dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
2761 pdst = &dseg->inline_data[0];
2763 * The WQEBB space availability is checked by caller.
2764 * Here we should be aware of WQE ring buffer wraparound only.
2766 part = (uint8_t *)txq->wqes_end - pdst;
2767 part = RTE_MIN(part, len);
2769 rte_memcpy(pdst, buf, part);
2773 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2774 /* Note: no final wraparound check here. */
2775 return (struct mlx5_wqe_dseg *)pdst;
2777 pdst = (uint8_t *)txq->wqes;
2784 * Build the Data Segment of inlined data from single
2785 * segment packet with VLAN insertion.
2788 * Pointer to TX queue structure.
2790 * Pointer to burst routine local context.
2792 * Pointer to the dseg fill with built Data Segment.
2794 * Data buffer to point.
2796 * Data buffer length.
2798 * Configured Tx offloads mask. It is fully defined at
2799 * compile time and may be used for optimization.
2802 * Pointer to the next Data Segment after inlined data.
2803 * Ring buffer wraparound check is needed.
2805 static __rte_always_inline struct mlx5_wqe_dseg *
2806 mlx5_tx_dseg_vlan(struct mlx5_txq_data *restrict txq,
2807 struct mlx5_txq_local *restrict loc __rte_unused,
2808 struct mlx5_wqe_dseg *restrict dseg,
2811 unsigned int olx __rte_unused)
2817 assert(len > MLX5_ESEG_MIN_INLINE_SIZE);
2818 static_assert(MLX5_DSEG_MIN_INLINE_SIZE ==
2819 (2 * RTE_ETHER_ADDR_LEN),
2820 "invalid Data Segment data size");
2821 dseg->bcount = rte_cpu_to_be_32((len + sizeof(struct rte_vlan_hdr)) |
2822 MLX5_ETH_WQE_DATA_INLINE);
2823 pdst = &dseg->inline_data[0];
2824 memcpy(pdst, buf, MLX5_DSEG_MIN_INLINE_SIZE);
2825 buf += MLX5_DSEG_MIN_INLINE_SIZE;
2826 pdst += MLX5_DSEG_MIN_INLINE_SIZE;
2827 /* Insert VLAN ethertype + VLAN tag. Pointer is aligned. */
2828 assert(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
2829 *(uint32_t *)pdst = rte_cpu_to_be_32((RTE_ETHER_TYPE_VLAN << 16) |
2830 loc->mbuf->vlan_tci);
2831 pdst += sizeof(struct rte_vlan_hdr);
2832 if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
2833 pdst = (uint8_t *)txq->wqes;
2835 * The WQEBB space availability is checked by caller.
2836 * Here we should be aware of WQE ring buffer wraparound only.
2838 part = (uint8_t *)txq->wqes_end - pdst;
2839 part = RTE_MIN(part, len);
2841 rte_memcpy(pdst, buf, part);
2845 pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
2846 /* Note: no final wraparound check here. */
2847 return (struct mlx5_wqe_dseg *)pdst;
2849 pdst = (uint8_t *)txq->wqes;
2856 * Build the Ethernet Segment with optionally inlined data with
2857 * VLAN insertion and following Data Segments (if any) from
2858 * multi-segment packet. Used by ordinary send and TSO.
2861 * Pointer to TX queue structure.
2863 * Pointer to burst routine local context.
2865 * Pointer to WQE to fill with built Ethernet/Data Segments.
2867 * Length of VLAN header to insert, 0 means no VLAN insertion.
2869 * Data length to inline. For TSO this parameter specifies
2870 * exact value, for ordinary send routine can be aligned by
2871 * caller to provide better WQE space saving and data buffer
2872 * start address alignment. This length includes VLAN header
2875 * Zero means ordinary send, inlined data can be extended,
2876 * otherwise this is TSO, inlined data length is fixed.
2878 * Configured Tx offloads mask. It is fully defined at
2879 * compile time and may be used for optimization.
2882 * Actual size of built WQE in segments.
2884 static __rte_always_inline unsigned int
2885 mlx5_tx_mseg_build(struct mlx5_txq_data *restrict txq,
2886 struct mlx5_txq_local *restrict loc,
2887 struct mlx5_wqe *restrict wqe,
2891 unsigned int olx __rte_unused)
2893 struct mlx5_wqe_dseg *restrict dseg;
2896 assert((rte_pktmbuf_pkt_len(loc->mbuf) + vlan) >= inlen);
2897 loc->mbuf_nseg = NB_SEGS(loc->mbuf);
2900 dseg = mlx5_tx_eseg_mdat(txq, loc, wqe, vlan, inlen, tso, olx);
2901 if (!loc->mbuf_nseg)
2904 * There are still some mbuf remaining, not inlined.
2905 * The first mbuf may be partially inlined and we
2906 * must process the possible non-zero data offset.
2908 if (loc->mbuf_off) {
2913 * Exhausted packets must be dropped before.
2914 * Non-zero offset means there are some data
2915 * remained in the packet.
2917 assert(loc->mbuf_off < rte_pktmbuf_data_len(loc->mbuf));
2918 assert(rte_pktmbuf_data_len(loc->mbuf));
2919 dptr = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
2921 dlen = rte_pktmbuf_data_len(loc->mbuf) - loc->mbuf_off;
2923 * Build the pointer/minimal data Data Segment.
2924 * Do ring buffer wrapping check in advance.
2926 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
2927 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2928 mlx5_tx_dseg_iptr(txq, loc, dseg, dptr, dlen, olx);
2929 /* Store the mbuf to be freed on completion. */
2930 assert(loc->elts_free);
2931 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2934 if (--loc->mbuf_nseg == 0)
2936 loc->mbuf = loc->mbuf->next;
2940 if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
2941 struct rte_mbuf *mbuf;
2943 /* Zero length segment found, just skip. */
2945 loc->mbuf = loc->mbuf->next;
2946 rte_pktmbuf_free_seg(mbuf);
2947 if (--loc->mbuf_nseg == 0)
2950 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
2951 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2954 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
2955 rte_pktmbuf_data_len(loc->mbuf), olx);
2956 assert(loc->elts_free);
2957 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2960 if (--loc->mbuf_nseg == 0)
2962 loc->mbuf = loc->mbuf->next;
2967 /* Calculate actual segments used from the dseg pointer. */
2968 if ((uintptr_t)wqe < (uintptr_t)dseg)
2969 ds = ((uintptr_t)dseg - (uintptr_t)wqe) / MLX5_WSEG_SIZE;
2971 ds = (((uintptr_t)dseg - (uintptr_t)wqe) +
2972 txq->wqe_s * MLX5_WQE_SIZE) / MLX5_WSEG_SIZE;
2977 * Tx one packet function for multi-segment TSO. Supports all
2978 * types of Tx offloads, uses MLX5_OPCODE_TSO to build WQEs,
2979 * sends one packet per WQE.
2981 * This routine is responsible for storing processed mbuf
2982 * into elts ring buffer and update elts_head.
2985 * Pointer to TX queue structure.
2987 * Pointer to burst routine local context.
2989 * Configured Tx offloads mask. It is fully defined at
2990 * compile time and may be used for optimization.
2993 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2994 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2995 * Local context variables partially updated.
2997 static __rte_always_inline enum mlx5_txcmp_code
2998 mlx5_tx_packet_multi_tso(struct mlx5_txq_data *restrict txq,
2999 struct mlx5_txq_local *restrict loc,
3002 struct mlx5_wqe *restrict wqe;
3003 unsigned int ds, dlen, inlen, ntcp, vlan = 0;
3006 * Calculate data length to be inlined to estimate
3007 * the required space in WQE ring buffer.
3009 dlen = rte_pktmbuf_pkt_len(loc->mbuf);
3010 if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3011 vlan = sizeof(struct rte_vlan_hdr);
3012 inlen = loc->mbuf->l2_len + vlan +
3013 loc->mbuf->l3_len + loc->mbuf->l4_len;
3014 if (unlikely((!inlen || !loc->mbuf->tso_segsz)))
3015 return MLX5_TXCMP_CODE_ERROR;
3016 if (loc->mbuf->ol_flags & PKT_TX_TUNNEL_MASK)
3017 inlen += loc->mbuf->outer_l2_len + loc->mbuf->outer_l3_len;
3018 /* Packet must contain all TSO headers. */
3019 if (unlikely(inlen > MLX5_MAX_TSO_HEADER ||
3020 inlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
3021 inlen > (dlen + vlan)))
3022 return MLX5_TXCMP_CODE_ERROR;
3023 assert(inlen >= txq->inlen_mode);
3025 * Check whether there are enough free WQEBBs:
3027 * - Ethernet Segment
3028 * - First Segment of inlined Ethernet data
3029 * - ... data continued ...
3030 * - Data Segments of pointer/min inline type
3032 ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
3033 MLX5_ESEG_MIN_INLINE_SIZE +
3035 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3036 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3037 return MLX5_TXCMP_CODE_EXIT;
3038 /* Check for maximal WQE size. */
3039 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3040 return MLX5_TXCMP_CODE_ERROR;
3041 #ifdef MLX5_PMD_SOFT_COUNTERS
3042 /* Update sent data bytes/packets counters. */
3043 ntcp = (dlen - (inlen - vlan) + loc->mbuf->tso_segsz - 1) /
3044 loc->mbuf->tso_segsz;
3046 * One will be added for mbuf itself
3047 * at the end of the mlx5_tx_burst from
3048 * loc->pkts_sent field.
3051 txq->stats.opackets += ntcp;
3052 txq->stats.obytes += dlen + vlan + ntcp * inlen;
3054 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3055 loc->wqe_last = wqe;
3056 mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_TSO, olx);
3057 ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 1, olx);
3058 wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3059 txq->wqe_ci += (ds + 3) / 4;
3060 loc->wqe_free -= (ds + 3) / 4;
3061 return MLX5_TXCMP_CODE_MULTI;
3065 * Tx one packet function for multi-segment SEND. Supports all
3066 * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
3067 * sends one packet per WQE, without any data inlining in
3070 * This routine is responsible for storing processed mbuf
3071 * into elts ring buffer and update elts_head.
3074 * Pointer to TX queue structure.
3076 * Pointer to burst routine local context.
3078 * Configured Tx offloads mask. It is fully defined at
3079 * compile time and may be used for optimization.
3082 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3083 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3084 * Local context variables partially updated.
3086 static __rte_always_inline enum mlx5_txcmp_code
3087 mlx5_tx_packet_multi_send(struct mlx5_txq_data *restrict txq,
3088 struct mlx5_txq_local *restrict loc,
3091 struct mlx5_wqe_dseg *restrict dseg;
3092 struct mlx5_wqe *restrict wqe;
3093 unsigned int ds, nseg;
3095 assert(NB_SEGS(loc->mbuf) > 1);
3097 * No inline at all, it means the CPU cycles saving
3098 * is prioritized at configuration, we should not
3099 * copy any packet data to WQE.
3101 nseg = NB_SEGS(loc->mbuf);
3103 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3104 return MLX5_TXCMP_CODE_EXIT;
3105 /* Check for maximal WQE size. */
3106 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3107 return MLX5_TXCMP_CODE_ERROR;
3109 * Some Tx offloads may cause an error if
3110 * packet is not long enough, check against
3111 * assumed minimal length.
3113 if (rte_pktmbuf_pkt_len(loc->mbuf) <= MLX5_ESEG_MIN_INLINE_SIZE)
3114 return MLX5_TXCMP_CODE_ERROR;
3115 #ifdef MLX5_PMD_SOFT_COUNTERS
3116 /* Update sent data bytes counter. */
3117 txq->stats.obytes += rte_pktmbuf_pkt_len(loc->mbuf);
3118 if (MLX5_TXOFF_CONFIG(VLAN) &&
3119 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3120 txq->stats.obytes += sizeof(struct rte_vlan_hdr);
3123 * SEND WQE, one WQEBB:
3124 * - Control Segment, SEND opcode
3125 * - Ethernet Segment, optional VLAN, no inline
3126 * - Data Segments, pointer only type
3128 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3129 loc->wqe_last = wqe;
3130 mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_SEND, olx);
3131 mlx5_tx_eseg_none(txq, loc, wqe, olx);
3132 dseg = &wqe->dseg[0];
3134 if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
3135 struct rte_mbuf *mbuf;
3138 * Zero length segment found, have to
3139 * correct total size of WQE in segments.
3140 * It is supposed to be rare occasion, so
3141 * in normal case (no zero length segments)
3142 * we avoid extra writing to the Control
3146 wqe->cseg.sq_ds -= RTE_BE32(1);
3148 loc->mbuf = mbuf->next;
3149 rte_pktmbuf_free_seg(mbuf);
3155 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3156 rte_pktmbuf_data_len(loc->mbuf), olx);
3157 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3162 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3163 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3164 loc->mbuf = loc->mbuf->next;
3167 txq->wqe_ci += (ds + 3) / 4;
3168 loc->wqe_free -= (ds + 3) / 4;
3169 return MLX5_TXCMP_CODE_MULTI;
3173 * Tx one packet function for multi-segment SEND. Supports all
3174 * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
3175 * sends one packet per WQE, with data inlining in
3176 * Ethernet Segment and minimal Data Segments.
3178 * This routine is responsible for storing processed mbuf
3179 * into elts ring buffer and update elts_head.
3182 * Pointer to TX queue structure.
3184 * Pointer to burst routine local context.
3186 * Configured Tx offloads mask. It is fully defined at
3187 * compile time and may be used for optimization.
3190 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3191 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3192 * Local context variables partially updated.
3194 static __rte_always_inline enum mlx5_txcmp_code
3195 mlx5_tx_packet_multi_inline(struct mlx5_txq_data *restrict txq,
3196 struct mlx5_txq_local *restrict loc,
3199 struct mlx5_wqe *restrict wqe;
3200 unsigned int ds, inlen, dlen, vlan = 0;
3202 assert(MLX5_TXOFF_CONFIG(INLINE));
3203 assert(NB_SEGS(loc->mbuf) > 1);
3205 * First calculate data length to be inlined
3206 * to estimate the required space for WQE.
3208 dlen = rte_pktmbuf_pkt_len(loc->mbuf);
3209 if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
3210 vlan = sizeof(struct rte_vlan_hdr);
3211 inlen = dlen + vlan;
3212 /* Check against minimal length. */
3213 if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
3214 return MLX5_TXCMP_CODE_ERROR;
3215 assert(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
3216 if (inlen > txq->inlen_send) {
3217 struct rte_mbuf *mbuf;
3222 * Packet length exceeds the allowed inline
3223 * data length, check whether the minimal
3224 * inlining is required.
3226 if (txq->inlen_mode) {
3227 assert(txq->inlen_mode >= MLX5_ESEG_MIN_INLINE_SIZE);
3228 assert(txq->inlen_mode <= txq->inlen_send);
3229 inlen = txq->inlen_mode;
3231 if (!vlan || txq->vlan_en) {
3233 * VLAN insertion will be done inside by HW.
3234 * It is not utmost effective - VLAN flag is
3235 * checked twice, but we should proceed the
3236 * inlining length correctly and take into
3237 * account the VLAN header being inserted.
3239 return mlx5_tx_packet_multi_send
3242 inlen = MLX5_ESEG_MIN_INLINE_SIZE;
3245 * Now we know the minimal amount of data is requested
3246 * to inline. Check whether we should inline the buffers
3247 * from the chain beginning to eliminate some mbufs.
3250 nxlen = rte_pktmbuf_data_len(mbuf);
3251 if (unlikely(nxlen <= txq->inlen_send)) {
3252 /* We can inline first mbuf at least. */
3253 if (nxlen < inlen) {
3256 /* Scan mbufs till inlen filled. */
3261 nxlen = rte_pktmbuf_data_len(mbuf);
3263 } while (unlikely(nxlen < inlen));
3264 if (unlikely(nxlen > txq->inlen_send)) {
3265 /* We cannot inline entire mbuf. */
3266 smlen = inlen - smlen;
3267 start = rte_pktmbuf_mtod_offset
3268 (mbuf, uintptr_t, smlen);
3275 /* There should be not end of packet. */
3277 nxlen = inlen + rte_pktmbuf_data_len(mbuf);
3278 } while (unlikely(nxlen < txq->inlen_send));
3280 start = rte_pktmbuf_mtod(mbuf, uintptr_t);
3282 * Check whether we can do inline to align start
3283 * address of data buffer to cacheline.
3286 start = (~start + 1) & (RTE_CACHE_LINE_SIZE - 1);
3287 if (unlikely(start)) {
3289 if (start <= txq->inlen_send)
3294 * Check whether there are enough free WQEBBs:
3296 * - Ethernet Segment
3297 * - First Segment of inlined Ethernet data
3298 * - ... data continued ...
3299 * - Data Segments of pointer/min inline type
3301 * Estimate the number of Data Segments conservatively,
3302 * supposing no any mbufs is being freed during inlining.
3304 assert(inlen <= txq->inlen_send);
3305 ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
3306 MLX5_ESEG_MIN_INLINE_SIZE +
3308 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3309 if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
3310 return MLX5_TXCMP_CODE_EXIT;
3311 /* Check for maximal WQE size. */
3312 if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ((ds + 3) / 4)))
3313 return MLX5_TXCMP_CODE_ERROR;
3314 #ifdef MLX5_PMD_SOFT_COUNTERS
3315 /* Update sent data bytes/packets counters. */
3316 txq->stats.obytes += dlen + vlan;
3318 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3319 loc->wqe_last = wqe;
3320 mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_SEND, olx);
3321 ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 0, olx);
3322 wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3323 txq->wqe_ci += (ds + 3) / 4;
3324 loc->wqe_free -= (ds + 3) / 4;
3325 return MLX5_TXCMP_CODE_MULTI;
3329 * Tx burst function for multi-segment packets. Supports all
3330 * types of Tx offloads, uses MLX5_OPCODE_SEND/TSO to build WQEs,
3331 * sends one packet per WQE. Function stops sending if it
3332 * encounters the single-segment packet.
3334 * This routine is responsible for storing processed mbuf
3335 * into elts ring buffer and update elts_head.
3338 * Pointer to TX queue structure.
3340 * Packets to transmit.
3342 * Number of packets in array.
3344 * Pointer to burst routine local context.
3346 * Configured Tx offloads mask. It is fully defined at
3347 * compile time and may be used for optimization.
3350 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3351 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3352 * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
3353 * MLX5_TXCMP_CODE_TSO - TSO single-segment packet encountered.
3354 * Local context variables updated.
3356 static __rte_always_inline enum mlx5_txcmp_code
3357 mlx5_tx_burst_mseg(struct mlx5_txq_data *restrict txq,
3358 struct rte_mbuf **restrict pkts,
3359 unsigned int pkts_n,
3360 struct mlx5_txq_local *restrict loc,
3363 assert(loc->elts_free && loc->wqe_free);
3364 assert(pkts_n > loc->pkts_sent);
3365 pkts += loc->pkts_sent + 1;
3366 pkts_n -= loc->pkts_sent;
3368 enum mlx5_txcmp_code ret;
3370 assert(NB_SEGS(loc->mbuf) > 1);
3372 * Estimate the number of free elts quickly but
3373 * conservatively. Some segment may be fully inlined
3374 * and freed, ignore this here - precise estimation
3377 if (loc->elts_free < NB_SEGS(loc->mbuf))
3378 return MLX5_TXCMP_CODE_EXIT;
3379 if (MLX5_TXOFF_CONFIG(TSO) &&
3380 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)) {
3381 /* Proceed with multi-segment TSO. */
3382 ret = mlx5_tx_packet_multi_tso(txq, loc, olx);
3383 } else if (MLX5_TXOFF_CONFIG(INLINE)) {
3384 /* Proceed with multi-segment SEND with inlining. */
3385 ret = mlx5_tx_packet_multi_inline(txq, loc, olx);
3387 /* Proceed with multi-segment SEND w/o inlining. */
3388 ret = mlx5_tx_packet_multi_send(txq, loc, olx);
3390 if (ret == MLX5_TXCMP_CODE_EXIT)
3391 return MLX5_TXCMP_CODE_EXIT;
3392 if (ret == MLX5_TXCMP_CODE_ERROR)
3393 return MLX5_TXCMP_CODE_ERROR;
3394 /* WQE is built, go to the next packet. */
3397 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3398 return MLX5_TXCMP_CODE_EXIT;
3399 loc->mbuf = *pkts++;
3401 rte_prefetch0(*pkts);
3402 if (likely(NB_SEGS(loc->mbuf) > 1))
3404 /* Here ends the series of multi-segment packets. */
3405 if (MLX5_TXOFF_CONFIG(TSO) &&
3406 unlikely(!(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)))
3407 return MLX5_TXCMP_CODE_TSO;
3408 return MLX5_TXCMP_CODE_SINGLE;
3414 * Tx burst function for single-segment packets with TSO.
3415 * Supports all types of Tx offloads, except multi-packets.
3416 * Uses MLX5_OPCODE_TSO to build WQEs, sends one packet per WQE.
3417 * Function stops sending if it encounters the multi-segment
3418 * packet or packet without TSO requested.
3420 * The routine is responsible for storing processed mbuf
3421 * into elts ring buffer and update elts_head if inline
3422 * offloads is requested due to possible early freeing
3423 * of the inlined mbufs (can not store pkts array in elts
3427 * Pointer to TX queue structure.
3429 * Packets to transmit.
3431 * Number of packets in array.
3433 * Pointer to burst routine local context.
3435 * Configured Tx offloads mask. It is fully defined at
3436 * compile time and may be used for optimization.
3439 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3440 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3441 * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
3442 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3443 * Local context variables updated.
3445 static __rte_always_inline enum mlx5_txcmp_code
3446 mlx5_tx_burst_tso(struct mlx5_txq_data *restrict txq,
3447 struct rte_mbuf **restrict pkts,
3448 unsigned int pkts_n,
3449 struct mlx5_txq_local *restrict loc,
3452 assert(loc->elts_free && loc->wqe_free);
3453 assert(pkts_n > loc->pkts_sent);
3454 pkts += loc->pkts_sent + 1;
3455 pkts_n -= loc->pkts_sent;
3457 struct mlx5_wqe_dseg *restrict dseg;
3458 struct mlx5_wqe *restrict wqe;
3459 unsigned int ds, dlen, hlen, ntcp, vlan = 0;
3462 assert(NB_SEGS(loc->mbuf) == 1);
3463 dlen = rte_pktmbuf_data_len(loc->mbuf);
3464 if (MLX5_TXOFF_CONFIG(VLAN) &&
3465 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
3466 vlan = sizeof(struct rte_vlan_hdr);
3469 * First calculate the WQE size to check
3470 * whether we have enough space in ring buffer.
3472 hlen = loc->mbuf->l2_len + vlan +
3473 loc->mbuf->l3_len + loc->mbuf->l4_len;
3474 if (unlikely((!hlen || !loc->mbuf->tso_segsz)))
3475 return MLX5_TXCMP_CODE_ERROR;
3476 if (loc->mbuf->ol_flags & PKT_TX_TUNNEL_MASK)
3477 hlen += loc->mbuf->outer_l2_len +
3478 loc->mbuf->outer_l3_len;
3479 /* Segment must contain all TSO headers. */
3480 if (unlikely(hlen > MLX5_MAX_TSO_HEADER ||
3481 hlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
3482 hlen > (dlen + vlan)))
3483 return MLX5_TXCMP_CODE_ERROR;
3485 * Check whether there are enough free WQEBBs:
3487 * - Ethernet Segment
3488 * - First Segment of inlined Ethernet data
3489 * - ... data continued ...
3490 * - Finishing Data Segment of pointer type
3492 ds = 4 + (hlen - MLX5_ESEG_MIN_INLINE_SIZE +
3493 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3494 if (loc->wqe_free < ((ds + 3) / 4))
3495 return MLX5_TXCMP_CODE_EXIT;
3496 #ifdef MLX5_PMD_SOFT_COUNTERS
3497 /* Update sent data bytes/packets counters. */
3498 ntcp = (dlen + vlan - hlen +
3499 loc->mbuf->tso_segsz - 1) /
3500 loc->mbuf->tso_segsz;
3502 * One will be added for mbuf itself at the end
3503 * of the mlx5_tx_burst from loc->pkts_sent field.
3506 txq->stats.opackets += ntcp;
3507 txq->stats.obytes += dlen + vlan + ntcp * hlen;
3510 * Build the TSO WQE:
3512 * - Ethernet Segment with hlen bytes inlined
3513 * - Data Segment of pointer type
3515 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3516 loc->wqe_last = wqe;
3517 mlx5_tx_cseg_init(txq, loc, wqe, ds,
3518 MLX5_OPCODE_TSO, olx);
3519 dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan, hlen, 1, olx);
3520 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) + hlen - vlan;
3521 dlen -= hlen - vlan;
3522 mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
3524 * WQE is built, update the loop parameters
3525 * and go to the next packet.
3527 txq->wqe_ci += (ds + 3) / 4;
3528 loc->wqe_free -= (ds + 3) / 4;
3529 if (MLX5_TXOFF_CONFIG(INLINE))
3530 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3534 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3535 return MLX5_TXCMP_CODE_EXIT;
3536 loc->mbuf = *pkts++;
3538 rte_prefetch0(*pkts);
3539 if (MLX5_TXOFF_CONFIG(MULTI) &&
3540 unlikely(NB_SEGS(loc->mbuf) > 1))
3541 return MLX5_TXCMP_CODE_MULTI;
3542 if (unlikely(!(loc->mbuf->ol_flags & PKT_TX_TCP_SEG)))
3543 return MLX5_TXCMP_CODE_SINGLE;
3544 /* Continue with the next TSO packet. */
3550 * Analyze the packet and select the best method to send.
3553 * Pointer to TX queue structure.
3555 * Pointer to burst routine local context.
3557 * Configured Tx offloads mask. It is fully defined at
3558 * compile time and may be used for optimization.
3560 * The predefined flag whether do complete check for
3561 * multi-segment packets and TSO.
3564 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3565 * MLX5_TXCMP_CODE_TSO - TSO required, use TSO/LSO.
3566 * MLX5_TXCMP_CODE_SINGLE - single-segment packet, use SEND.
3567 * MLX5_TXCMP_CODE_EMPW - single-segment packet, use MPW.
3569 static __rte_always_inline enum mlx5_txcmp_code
3570 mlx5_tx_able_to_empw(struct mlx5_txq_data *restrict txq,
3571 struct mlx5_txq_local *restrict loc,
3575 /* Check for multi-segment packet. */
3577 MLX5_TXOFF_CONFIG(MULTI) &&
3578 unlikely(NB_SEGS(loc->mbuf) > 1))
3579 return MLX5_TXCMP_CODE_MULTI;
3580 /* Check for TSO packet. */
3582 MLX5_TXOFF_CONFIG(TSO) &&
3583 unlikely(loc->mbuf->ol_flags & PKT_TX_TCP_SEG))
3584 return MLX5_TXCMP_CODE_TSO;
3585 /* Check if eMPW is enabled at all. */
3586 if (!MLX5_TXOFF_CONFIG(EMPW))
3587 return MLX5_TXCMP_CODE_SINGLE;
3588 /* Check if eMPW can be engaged. */
3589 if (MLX5_TXOFF_CONFIG(VLAN) &&
3590 unlikely(loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) &&
3591 (!MLX5_TXOFF_CONFIG(INLINE) ||
3592 unlikely((rte_pktmbuf_data_len(loc->mbuf) +
3593 sizeof(struct rte_vlan_hdr)) > txq->inlen_empw))) {
3595 * eMPW does not support VLAN insertion offload,
3596 * we have to inline the entire packet but
3597 * packet is too long for inlining.
3599 return MLX5_TXCMP_CODE_SINGLE;
3601 return MLX5_TXCMP_CODE_EMPW;
3605 * Check the next packet attributes to match with the eMPW batch ones.
3608 * Pointer to TX queue structure.
3610 * Pointer to Ethernet Segment of eMPW batch.
3612 * Pointer to burst routine local context.
3614 * Configured Tx offloads mask. It is fully defined at
3615 * compile time and may be used for optimization.
3618 * true - packet match with eMPW batch attributes.
3619 * false - no match, eMPW should be restarted.
3621 static __rte_always_inline bool
3622 mlx5_tx_match_empw(struct mlx5_txq_data *restrict txq __rte_unused,
3623 struct mlx5_wqe_eseg *restrict es,
3624 struct mlx5_txq_local *restrict loc,
3627 uint8_t swp_flags = 0;
3629 /* Compare the checksum flags, if any. */
3630 if (MLX5_TXOFF_CONFIG(CSUM) &&
3631 txq_ol_cksum_to_cs(loc->mbuf) != es->cs_flags)
3633 /* Compare the Software Parser offsets and flags. */
3634 if (MLX5_TXOFF_CONFIG(SWP) &&
3635 (es->swp_offs != txq_mbuf_to_swp(loc, &swp_flags, olx) ||
3636 es->swp_flags != swp_flags))
3638 /* Fill metadata field if needed. */
3639 if (MLX5_TXOFF_CONFIG(METADATA) &&
3640 es->metadata != (loc->mbuf->ol_flags & PKT_TX_METADATA ?
3641 loc->mbuf->tx_metadata : 0))
3643 /* There must be no VLAN packets in eMPW loop. */
3644 if (MLX5_TXOFF_CONFIG(VLAN))
3645 assert(!(loc->mbuf->ol_flags & PKT_TX_VLAN_PKT));
3650 * Update send loop variables and WQE for eMPW loop
3651 * without data inlining. Number of Data Segments is
3652 * equal to the number of sent packets.
3655 * Pointer to TX queue structure.
3657 * Pointer to burst routine local context.
3659 * Number of packets/Data Segments/Packets.
3661 * Accumulated statistics, bytes sent
3663 * Configured Tx offloads mask. It is fully defined at
3664 * compile time and may be used for optimization.
3667 * true - packet match with eMPW batch attributes.
3668 * false - no match, eMPW should be restarted.
3670 static __rte_always_inline void
3671 mlx5_tx_sdone_empw(struct mlx5_txq_data *restrict txq,
3672 struct mlx5_txq_local *restrict loc,
3675 unsigned int olx __rte_unused)
3677 assert(!MLX5_TXOFF_CONFIG(INLINE));
3678 #ifdef MLX5_PMD_SOFT_COUNTERS
3679 /* Update sent data bytes counter. */
3680 txq->stats.obytes += slen;
3684 loc->elts_free -= ds;
3685 loc->pkts_sent += ds;
3687 loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
3688 txq->wqe_ci += (ds + 3) / 4;
3689 loc->wqe_free -= (ds + 3) / 4;
3693 * Update send loop variables and WQE for eMPW loop
3694 * with data inlining. Gets the size of pushed descriptors
3695 * and data to the WQE.
3698 * Pointer to TX queue structure.
3700 * Pointer to burst routine local context.
3702 * Total size of descriptor/data in bytes.
3704 * Accumulated statistics, data bytes sent.
3706 * Configured Tx offloads mask. It is fully defined at
3707 * compile time and may be used for optimization.
3710 * true - packet match with eMPW batch attributes.
3711 * false - no match, eMPW should be restarted.
3713 static __rte_always_inline void
3714 mlx5_tx_idone_empw(struct mlx5_txq_data *restrict txq,
3715 struct mlx5_txq_local *restrict loc,
3718 unsigned int olx __rte_unused)
3720 assert(MLX5_TXOFF_CONFIG(INLINE));
3721 assert((len % MLX5_WSEG_SIZE) == 0);
3722 #ifdef MLX5_PMD_SOFT_COUNTERS
3723 /* Update sent data bytes counter. */
3724 txq->stats.obytes += slen;
3728 len = len / MLX5_WSEG_SIZE + 2;
3729 loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | len);
3730 txq->wqe_ci += (len + 3) / 4;
3731 loc->wqe_free -= (len + 3) / 4;
3735 * The set of Tx burst functions for single-segment packets
3736 * without TSO and with Multi-Packet Writing feature support.
3737 * Supports all types of Tx offloads, except multi-packets
3740 * Uses MLX5_OPCODE_EMPW to build WQEs if possible and sends
3741 * as many packet per WQE as it can. If eMPW is not configured
3742 * or packet can not be sent with eMPW (VLAN insertion) the
3743 * ordinary SEND opcode is used and only one packet placed
3746 * Functions stop sending if it encounters the multi-segment
3747 * packet or packet with TSO requested.
3749 * The routines are responsible for storing processed mbuf
3750 * into elts ring buffer and update elts_head if inlining
3751 * offload is requested. Otherwise the copying mbufs to elts
3752 * can be postponed and completed at the end of burst routine.
3755 * Pointer to TX queue structure.
3757 * Packets to transmit.
3759 * Number of packets in array.
3761 * Pointer to burst routine local context.
3763 * Configured Tx offloads mask. It is fully defined at
3764 * compile time and may be used for optimization.
3767 * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
3768 * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
3769 * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
3770 * MLX5_TXCMP_CODE_TSO - TSO packet encountered.
3771 * MLX5_TXCMP_CODE_SINGLE - used inside functions set.
3772 * MLX5_TXCMP_CODE_EMPW - used inside functions set.
3774 * Local context variables updated.
3777 * The routine sends packets with MLX5_OPCODE_EMPW
3778 * without inlining, this is dedicated optimized branch.
3779 * No VLAN insertion is supported.
3781 static __rte_always_inline enum mlx5_txcmp_code
3782 mlx5_tx_burst_empw_simple(struct mlx5_txq_data *restrict txq,
3783 struct rte_mbuf **restrict pkts,
3784 unsigned int pkts_n,
3785 struct mlx5_txq_local *restrict loc,
3789 * Subroutine is the part of mlx5_tx_burst_single()
3790 * and sends single-segment packet with eMPW opcode
3791 * without data inlining.
3793 assert(!MLX5_TXOFF_CONFIG(INLINE));
3794 assert(MLX5_TXOFF_CONFIG(EMPW));
3795 assert(loc->elts_free && loc->wqe_free);
3796 assert(pkts_n > loc->pkts_sent);
3797 static_assert(MLX5_EMPW_MIN_PACKETS >= 2, "invalid min size");
3798 pkts += loc->pkts_sent + 1;
3799 pkts_n -= loc->pkts_sent;
3801 struct mlx5_wqe_dseg *restrict dseg;
3802 struct mlx5_wqe_eseg *restrict eseg;
3803 enum mlx5_txcmp_code ret;
3804 unsigned int part, loop;
3805 unsigned int slen = 0;
3808 part = RTE_MIN(pkts_n, MLX5_EMPW_MAX_PACKETS);
3809 if (unlikely(loc->elts_free < part)) {
3810 /* We have no enough elts to save all mbufs. */
3811 if (unlikely(loc->elts_free < MLX5_EMPW_MIN_PACKETS))
3812 return MLX5_TXCMP_CODE_EXIT;
3813 /* But we still able to send at least minimal eMPW. */
3814 part = loc->elts_free;
3816 /* Check whether we have enough WQEs */
3817 if (unlikely(loc->wqe_free < ((2 + part + 3) / 4))) {
3818 if (unlikely(loc->wqe_free <
3819 ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
3820 return MLX5_TXCMP_CODE_EXIT;
3821 part = (loc->wqe_free * 4) - 2;
3823 if (likely(part > 1))
3824 rte_prefetch0(*pkts);
3825 loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3827 * Build eMPW title WQEBB:
3828 * - Control Segment, eMPW opcode
3829 * - Ethernet Segment, no inline
3831 mlx5_tx_cseg_init(txq, loc, loc->wqe_last, part + 2,
3832 MLX5_OPCODE_ENHANCED_MPSW, olx);
3833 mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
3834 olx & ~MLX5_TXOFF_CONFIG_VLAN);
3835 eseg = &loc->wqe_last->eseg;
3836 dseg = &loc->wqe_last->dseg[0];
3839 uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
3840 #ifdef MLX5_PMD_SOFT_COUNTERS
3841 /* Update sent data bytes counter. */
3846 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3848 if (unlikely(--loop == 0))
3850 loc->mbuf = *pkts++;
3851 if (likely(loop > 1))
3852 rte_prefetch0(*pkts);
3853 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3855 * Unroll the completion code to avoid
3856 * returning variable value - it results in
3857 * unoptimized sequent checking in caller.
3859 if (ret == MLX5_TXCMP_CODE_MULTI) {
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_MULTI;
3867 if (ret == MLX5_TXCMP_CODE_TSO) {
3869 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3870 if (unlikely(!loc->elts_free ||
3872 return MLX5_TXCMP_CODE_EXIT;
3873 return MLX5_TXCMP_CODE_TSO;
3875 if (ret == MLX5_TXCMP_CODE_SINGLE) {
3877 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3878 if (unlikely(!loc->elts_free ||
3880 return MLX5_TXCMP_CODE_EXIT;
3881 return MLX5_TXCMP_CODE_SINGLE;
3883 if (ret != MLX5_TXCMP_CODE_EMPW) {
3886 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3887 return MLX5_TXCMP_CODE_ERROR;
3890 * Check whether packet parameters coincide
3891 * within assumed eMPW batch:
3892 * - check sum settings
3894 * - software parser settings
3896 if (!mlx5_tx_match_empw(txq, eseg, loc, olx)) {
3899 mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
3900 if (unlikely(!loc->elts_free ||
3902 return MLX5_TXCMP_CODE_EXIT;
3905 /* Packet attributes match, continue the same eMPW. */
3907 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
3908 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3910 /* eMPW is built successfully, update loop parameters. */
3912 assert(pkts_n >= part);
3913 #ifdef MLX5_PMD_SOFT_COUNTERS
3914 /* Update sent data bytes counter. */
3915 txq->stats.obytes += slen;
3917 loc->elts_free -= part;
3918 loc->pkts_sent += part;
3919 txq->wqe_ci += (2 + part + 3) / 4;
3920 loc->wqe_free -= (2 + part + 3) / 4;
3922 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
3923 return MLX5_TXCMP_CODE_EXIT;
3924 loc->mbuf = *pkts++;
3925 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3926 if (unlikely(ret != MLX5_TXCMP_CODE_EMPW))
3928 /* Continue sending eMPW batches. */
3934 * The routine sends packets with MLX5_OPCODE_EMPW
3935 * with inlining, optionally supports VLAN insertion.
3937 static __rte_always_inline enum mlx5_txcmp_code
3938 mlx5_tx_burst_empw_inline(struct mlx5_txq_data *restrict txq,
3939 struct rte_mbuf **restrict pkts,
3940 unsigned int pkts_n,
3941 struct mlx5_txq_local *restrict loc,
3945 * Subroutine is the part of mlx5_tx_burst_single()
3946 * and sends single-segment packet with eMPW opcode
3947 * with data inlining.
3949 assert(MLX5_TXOFF_CONFIG(INLINE));
3950 assert(MLX5_TXOFF_CONFIG(EMPW));
3951 assert(loc->elts_free && loc->wqe_free);
3952 assert(pkts_n > loc->pkts_sent);
3953 static_assert(MLX5_EMPW_MIN_PACKETS >= 2, "invalid min size");
3954 pkts += loc->pkts_sent + 1;
3955 pkts_n -= loc->pkts_sent;
3957 struct mlx5_wqe_dseg *restrict dseg;
3958 struct mlx5_wqe_eseg *restrict eseg;
3959 enum mlx5_txcmp_code ret;
3960 unsigned int room, part;
3961 unsigned int slen = 0;
3964 /* Check whether we have minimal amount WQEs */
3965 if (unlikely(loc->wqe_free <
3966 ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
3967 return MLX5_TXCMP_CODE_EXIT;
3968 if (likely(pkts_n > 1))
3969 rte_prefetch0(*pkts);
3970 loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
3972 * Build eMPW title WQEBB:
3973 * - Control Segment, eMPW opcode, zero DS
3974 * - Ethernet Segment, no inline
3976 mlx5_tx_cseg_init(txq, loc, loc->wqe_last, 0,
3977 MLX5_OPCODE_ENHANCED_MPSW, olx);
3978 mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
3979 olx & ~MLX5_TXOFF_CONFIG_VLAN);
3980 eseg = &loc->wqe_last->eseg;
3981 dseg = &loc->wqe_last->dseg[0];
3982 room = RTE_MIN(MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE,
3983 loc->wqe_free) * MLX5_WQE_SIZE -
3984 MLX5_WQE_CSEG_SIZE -
3986 /* Build WQE till we have space, packets and resources. */
3989 uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
3990 uint8_t *dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
3993 assert(room >= MLX5_WQE_DSEG_SIZE);
3994 assert((room % MLX5_WQE_DSEG_SIZE) == 0);
3995 assert((uintptr_t)dseg < (uintptr_t)txq->wqes_end);
3997 * Some Tx offloads may cause an error if
3998 * packet is not long enough, check against
3999 * assumed minimal length.
4001 if (unlikely(dlen <= MLX5_ESEG_MIN_INLINE_SIZE)) {
4003 if (unlikely(!part))
4004 return MLX5_TXCMP_CODE_ERROR;
4006 * We have some successfully built
4007 * packet Data Segments to send.
4009 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4010 return MLX5_TXCMP_CODE_ERROR;
4012 /* Inline or not inline - that's the Question. */
4013 if (dlen > txq->inlen_empw)
4015 /* Inline entire packet, optional VLAN insertion. */
4016 tlen = sizeof(dseg->bcount) + dlen;
4017 if (MLX5_TXOFF_CONFIG(VLAN) &&
4018 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
4020 * The packet length must be checked in
4021 * mlx5_tx_able_to_empw() and packet
4022 * fits into inline length guaranteed.
4024 assert((dlen + sizeof(struct rte_vlan_hdr)) <=
4026 tlen += sizeof(struct rte_vlan_hdr);
4029 dseg = mlx5_tx_dseg_vlan(txq, loc, dseg,
4031 #ifdef MLX5_PMD_SOFT_COUNTERS
4032 /* Update sent data bytes counter. */
4033 slen += sizeof(struct rte_vlan_hdr);
4038 dseg = mlx5_tx_dseg_empw(txq, loc, dseg,
4041 tlen = RTE_ALIGN(tlen, MLX5_WSEG_SIZE);
4042 assert(room >= tlen);
4045 * Packet data are completely inlined,
4046 * free the packet immediately.
4048 rte_pktmbuf_free_seg(loc->mbuf);
4052 * Not inlinable VLAN packets are
4053 * proceeded outside of this routine.
4055 assert(room >= MLX5_WQE_DSEG_SIZE);
4056 if (MLX5_TXOFF_CONFIG(VLAN))
4057 assert(!(loc->mbuf->ol_flags &
4059 mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
4060 /* We have to store mbuf in elts.*/
4061 txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
4062 room -= MLX5_WQE_DSEG_SIZE;
4063 /* Ring buffer wraparound is checked at the loop end.*/
4066 #ifdef MLX5_PMD_SOFT_COUNTERS
4067 /* Update sent data bytes counter. */
4073 if (unlikely(!pkts_n || !loc->elts_free)) {
4075 * We have no resources/packets to
4076 * continue build descriptors.
4079 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4080 return MLX5_TXCMP_CODE_EXIT;
4082 /* Check if we have minimal room left. */
4083 if (room < MLX5_WQE_DSEG_SIZE) {
4085 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4088 loc->mbuf = *pkts++;
4089 if (likely(pkts_n > 1))
4090 rte_prefetch0(*pkts);
4091 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4093 * Unroll the completion code to avoid
4094 * returning variable value - it results in
4095 * unoptimized sequent checking in caller.
4097 if (ret == MLX5_TXCMP_CODE_MULTI) {
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_MULTI;
4105 if (ret == MLX5_TXCMP_CODE_TSO) {
4107 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4108 if (unlikely(!loc->elts_free ||
4110 return MLX5_TXCMP_CODE_EXIT;
4111 return MLX5_TXCMP_CODE_TSO;
4113 if (ret == MLX5_TXCMP_CODE_SINGLE) {
4115 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4116 if (unlikely(!loc->elts_free ||
4118 return MLX5_TXCMP_CODE_EXIT;
4119 return MLX5_TXCMP_CODE_SINGLE;
4121 if (ret != MLX5_TXCMP_CODE_EMPW) {
4124 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4125 return MLX5_TXCMP_CODE_ERROR;
4128 * Check whether packet parameters coincide
4129 * within assumed eMPW batch:
4130 * - check sum settings
4132 * - software parser settings
4134 if (!mlx5_tx_match_empw(txq, eseg, loc, olx))
4136 /* Packet attributes match, continue the same eMPW. */
4137 if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
4138 dseg = (struct mlx5_wqe_dseg *)txq->wqes;
4141 * We get here to close an existing eMPW
4142 * session and start the new one.
4146 if (unlikely(!part))
4147 return MLX5_TXCMP_CODE_EXIT;
4148 mlx5_tx_idone_empw(txq, loc, part, slen, olx);
4149 if (unlikely(!loc->elts_free ||
4151 return MLX5_TXCMP_CODE_EXIT;
4158 * The routine sends packets with ordinary MLX5_OPCODE_SEND.
4159 * Data inlining and VLAN insertion are supported.
4161 static __rte_always_inline enum mlx5_txcmp_code
4162 mlx5_tx_burst_single_send(struct mlx5_txq_data *restrict txq,
4163 struct rte_mbuf **restrict pkts,
4164 unsigned int pkts_n,
4165 struct mlx5_txq_local *restrict loc,
4169 * Subroutine is the part of mlx5_tx_burst_single()
4170 * and sends single-segment packet with SEND opcode.
4172 assert(loc->elts_free && loc->wqe_free);
4173 assert(pkts_n > loc->pkts_sent);
4174 pkts += loc->pkts_sent + 1;
4175 pkts_n -= loc->pkts_sent;
4177 struct mlx5_wqe *restrict wqe;
4178 enum mlx5_txcmp_code ret;
4180 assert(NB_SEGS(loc->mbuf) == 1);
4181 if (MLX5_TXOFF_CONFIG(INLINE)) {
4182 unsigned int inlen, vlan = 0;
4184 inlen = rte_pktmbuf_data_len(loc->mbuf);
4185 if (MLX5_TXOFF_CONFIG(VLAN) &&
4186 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
4187 vlan = sizeof(struct rte_vlan_hdr);
4189 static_assert((sizeof(struct rte_vlan_hdr) +
4190 sizeof(struct rte_ether_hdr)) ==
4191 MLX5_ESEG_MIN_INLINE_SIZE,
4192 "invalid min inline data size");
4195 * If inlining is enabled at configuration time
4196 * the limit must be not less than minimal size.
4197 * Otherwise we would do extra check for data
4198 * size to avoid crashes due to length overflow.
4200 assert(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
4201 if (inlen <= txq->inlen_send) {
4202 unsigned int seg_n, wqe_n;
4204 rte_prefetch0(rte_pktmbuf_mtod
4205 (loc->mbuf, uint8_t *));
4206 /* Check against minimal length. */
4207 if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
4208 return MLX5_TXCMP_CODE_ERROR;
4210 * Completely inlined packet data WQE:
4211 * - Control Segment, SEND opcode
4212 * - Ethernet Segment, no VLAN insertion
4213 * - Data inlined, VLAN optionally inserted
4214 * - Alignment to MLX5_WSEG_SIZE
4215 * Have to estimate amount of WQEBBs
4217 seg_n = (inlen + 3 * MLX5_WSEG_SIZE -
4218 MLX5_ESEG_MIN_INLINE_SIZE +
4219 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
4220 /* Check if there are enough WQEBBs. */
4221 wqe_n = (seg_n + 3) / 4;
4222 if (wqe_n > loc->wqe_free)
4223 return MLX5_TXCMP_CODE_EXIT;
4224 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4225 loc->wqe_last = wqe;
4226 mlx5_tx_cseg_init(txq, loc, wqe, seg_n,
4227 MLX5_OPCODE_SEND, olx);
4228 mlx5_tx_eseg_data(txq, loc, wqe,
4229 vlan, inlen, 0, olx);
4230 txq->wqe_ci += wqe_n;
4231 loc->wqe_free -= wqe_n;
4233 * Packet data are completely inlined,
4234 * free the packet immediately.
4236 rte_pktmbuf_free_seg(loc->mbuf);
4237 } else if (!MLX5_TXOFF_CONFIG(EMPW) &&
4240 * If minimal inlining is requested the eMPW
4241 * feature should be disabled due to data is
4242 * inlined into Ethernet Segment, which can
4243 * not contain inlined data for eMPW due to
4244 * segment shared for all packets.
4246 struct mlx5_wqe_dseg *restrict dseg;
4251 * The inline-mode settings require
4252 * to inline the specified amount of
4253 * data bytes to the Ethernet Segment.
4254 * We should check the free space in
4255 * WQE ring buffer to inline partially.
4257 assert(txq->inlen_send >= txq->inlen_mode);
4258 assert(inlen > txq->inlen_mode);
4259 assert(txq->inlen_mode >=
4260 MLX5_ESEG_MIN_INLINE_SIZE);
4262 * Check whether there are enough free WQEBBs:
4264 * - Ethernet Segment
4265 * - First Segment of inlined Ethernet data
4266 * - ... data continued ...
4267 * - Finishing Data Segment of pointer type
4269 ds = (MLX5_WQE_CSEG_SIZE +
4270 MLX5_WQE_ESEG_SIZE +
4271 MLX5_WQE_DSEG_SIZE +
4273 MLX5_ESEG_MIN_INLINE_SIZE +
4274 MLX5_WQE_DSEG_SIZE +
4275 MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
4276 if (loc->wqe_free < ((ds + 3) / 4))
4277 return MLX5_TXCMP_CODE_EXIT;
4279 * Build the ordinary SEND WQE:
4281 * - Ethernet Segment, inline inlen_mode bytes
4282 * - Data Segment of pointer type
4284 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4285 loc->wqe_last = wqe;
4286 mlx5_tx_cseg_init(txq, loc, wqe, ds,
4287 MLX5_OPCODE_SEND, olx);
4288 dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan,
4291 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
4292 txq->inlen_mode - vlan;
4293 inlen -= txq->inlen_mode;
4294 mlx5_tx_dseg_ptr(txq, loc, dseg,
4297 * WQE is built, update the loop parameters
4298 * and got to the next packet.
4300 txq->wqe_ci += (ds + 3) / 4;
4301 loc->wqe_free -= (ds + 3) / 4;
4302 /* We have to store mbuf in elts.*/
4303 assert(MLX5_TXOFF_CONFIG(INLINE));
4304 txq->elts[txq->elts_head++ & txq->elts_m] =
4312 * Partially inlined packet data WQE, we have
4313 * some space in title WQEBB, we can fill it
4314 * with some packet data. It takes one WQEBB,
4315 * it is available, no extra space check:
4316 * - Control Segment, SEND opcode
4317 * - Ethernet Segment, no VLAN insertion
4318 * - MLX5_ESEG_MIN_INLINE_SIZE bytes of Data
4319 * - Data Segment, pointer type
4321 * We also get here if VLAN insertion is not
4322 * supported by HW, the inline is enabled.
4324 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4325 loc->wqe_last = wqe;
4326 mlx5_tx_cseg_init(txq, loc, wqe, 4,
4327 MLX5_OPCODE_SEND, olx);
4328 mlx5_tx_eseg_dmin(txq, loc, wqe, vlan, olx);
4329 dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
4330 MLX5_ESEG_MIN_INLINE_SIZE - vlan;
4332 * The length check is performed above, by
4333 * comparing with txq->inlen_send. We should
4334 * not get overflow here.
4336 assert(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
4337 dlen = inlen - MLX5_ESEG_MIN_INLINE_SIZE;
4338 mlx5_tx_dseg_ptr(txq, loc, &wqe->dseg[1],
4342 /* We have to store mbuf in elts.*/
4343 assert(MLX5_TXOFF_CONFIG(INLINE));
4344 txq->elts[txq->elts_head++ & txq->elts_m] =
4348 #ifdef MLX5_PMD_SOFT_COUNTERS
4349 /* Update sent data bytes counter. */
4350 txq->stats.obytes += vlan +
4351 rte_pktmbuf_data_len(loc->mbuf);
4355 * No inline at all, it means the CPU cycles saving
4356 * is prioritized at configuration, we should not
4357 * copy any packet data to WQE.
4359 * SEND WQE, one WQEBB:
4360 * - Control Segment, SEND opcode
4361 * - Ethernet Segment, optional VLAN, no inline
4362 * - Data Segment, pointer type
4364 wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
4365 loc->wqe_last = wqe;
4366 mlx5_tx_cseg_init(txq, loc, wqe, 3,
4367 MLX5_OPCODE_SEND, olx);
4368 mlx5_tx_eseg_none(txq, loc, wqe, olx);
4370 (txq, loc, &wqe->dseg[0],
4371 rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
4372 rte_pktmbuf_data_len(loc->mbuf), olx);
4376 * We should not store mbuf pointer in elts
4377 * if no inlining is configured, this is done
4378 * by calling routine in a batch copy.
4380 assert(!MLX5_TXOFF_CONFIG(INLINE));
4382 #ifdef MLX5_PMD_SOFT_COUNTERS
4383 /* Update sent data bytes counter. */
4384 txq->stats.obytes += rte_pktmbuf_data_len(loc->mbuf);
4385 if (MLX5_TXOFF_CONFIG(VLAN) &&
4386 loc->mbuf->ol_flags & PKT_TX_VLAN_PKT)
4387 txq->stats.obytes +=
4388 sizeof(struct rte_vlan_hdr);
4393 if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
4394 return MLX5_TXCMP_CODE_EXIT;
4395 loc->mbuf = *pkts++;
4397 rte_prefetch0(*pkts);
4398 ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
4399 if (unlikely(ret != MLX5_TXCMP_CODE_SINGLE))
4405 static __rte_always_inline enum mlx5_txcmp_code
4406 mlx5_tx_burst_single(struct mlx5_txq_data *restrict txq,
4407 struct rte_mbuf **restrict pkts,
4408 unsigned int pkts_n,
4409 struct mlx5_txq_local *restrict loc,
4412 enum mlx5_txcmp_code ret;
4414 ret = mlx5_tx_able_to_empw(txq, loc, olx, false);
4415 if (ret == MLX5_TXCMP_CODE_SINGLE)
4417 assert(ret == MLX5_TXCMP_CODE_EMPW);
4419 /* Optimize for inline/no inline eMPW send. */
4420 ret = (MLX5_TXOFF_CONFIG(INLINE)) ?
4421 mlx5_tx_burst_empw_inline
4422 (txq, pkts, pkts_n, loc, olx) :
4423 mlx5_tx_burst_empw_simple
4424 (txq, pkts, pkts_n, loc, olx);
4425 if (ret != MLX5_TXCMP_CODE_SINGLE)
4427 /* The resources to send one packet should remain. */
4428 assert(loc->elts_free && loc->wqe_free);
4430 ret = mlx5_tx_burst_single_send(txq, pkts, pkts_n, loc, olx);
4431 assert(ret != MLX5_TXCMP_CODE_SINGLE);
4432 if (ret != MLX5_TXCMP_CODE_EMPW)
4434 /* The resources to send one packet should remain. */
4435 assert(loc->elts_free && loc->wqe_free);
4440 * DPDK Tx callback template. This is configured template
4441 * used to generate routines optimized for specified offload setup.
4442 * One of this generated functions is chosen at SQ configuration
4446 * Generic pointer to TX queue structure.
4448 * Packets to transmit.
4450 * Number of packets in array.
4452 * Configured offloads mask, presents the bits of MLX5_TXOFF_CONFIG_xxx
4453 * values. Should be static to take compile time static configuration
4457 * Number of packets successfully transmitted (<= pkts_n).
4459 static __rte_always_inline uint16_t
4460 mlx5_tx_burst_tmpl(struct mlx5_txq_data *restrict txq,
4461 struct rte_mbuf **restrict pkts,
4465 struct mlx5_txq_local loc;
4466 enum mlx5_txcmp_code ret;
4469 assert(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
4470 assert(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
4472 * Check if there are some CQEs, if any:
4473 * - process an encountered errors
4474 * - process the completed WQEs
4475 * - free related mbufs
4476 * - doorbell the NIC about processed CQEs
4478 if (unlikely(!pkts_n))
4480 rte_prefetch0(*pkts);
4481 mlx5_tx_handle_completion(txq, olx);
4483 * Calculate the number of available resources - elts and WQEs.
4484 * There are two possible different scenarios:
4485 * - no data inlining into WQEs, one WQEBB may contains upto
4486 * four packets, in this case elts become scarce resource
4487 * - data inlining into WQEs, one packet may require multiple
4488 * WQEBBs, the WQEs become the limiting factor.
4490 assert(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
4491 loc.elts_free = txq->elts_s -
4492 (uint16_t)(txq->elts_head - txq->elts_tail);
4493 assert(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
4494 loc.wqe_free = txq->wqe_s -
4495 (uint16_t)(txq->wqe_ci - txq->wqe_pi);
4496 if (unlikely(!loc.elts_free || !loc.wqe_free))
4500 loc.wqe_last = NULL;
4503 * Fetch the packet from array. Usually this is
4504 * the first packet in series of multi/single
4507 loc.mbuf = *(pkts + loc.pkts_sent);
4508 /* Dedicated branch for multi-segment packets. */
4509 if (MLX5_TXOFF_CONFIG(MULTI) &&
4510 unlikely(NB_SEGS(loc.mbuf) > 1)) {
4512 * Multi-segment packet encountered.
4513 * Hardware is able to process it only
4514 * with SEND/TSO opcodes, one packet
4515 * per WQE, do it in dedicated routine.
4518 assert(loc.pkts_sent >= loc.pkts_copy);
4519 part = loc.pkts_sent - loc.pkts_copy;
4520 if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
4522 * There are some single-segment mbufs not
4523 * stored in elts. The mbufs must be in the
4524 * same order as WQEs, so we must copy the
4525 * mbufs to elts here, before the coming
4526 * multi-segment packet mbufs is appended.
4528 mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy,
4530 loc.pkts_copy = loc.pkts_sent;
4532 assert(pkts_n > loc.pkts_sent);
4533 ret = mlx5_tx_burst_mseg(txq, pkts, pkts_n, &loc, olx);
4534 if (!MLX5_TXOFF_CONFIG(INLINE))
4535 loc.pkts_copy = loc.pkts_sent;
4537 * These returned code checks are supposed
4538 * to be optimized out due to routine inlining.
4540 if (ret == MLX5_TXCMP_CODE_EXIT) {
4542 * The routine returns this code when
4543 * all packets are sent or there is no
4544 * enough resources to complete request.
4548 if (ret == MLX5_TXCMP_CODE_ERROR) {
4550 * The routine returns this code when
4551 * some error in the incoming packets
4554 txq->stats.oerrors++;
4557 if (ret == MLX5_TXCMP_CODE_SINGLE) {
4559 * The single-segment packet was encountered
4560 * in the array, try to send it with the
4561 * best optimized way, possible engaging eMPW.
4563 goto enter_send_single;
4565 if (MLX5_TXOFF_CONFIG(TSO) &&
4566 ret == MLX5_TXCMP_CODE_TSO) {
4568 * The single-segment TSO packet was
4569 * encountered in the array.
4571 goto enter_send_tso;
4573 /* We must not get here. Something is going wrong. */
4575 txq->stats.oerrors++;
4578 /* Dedicated branch for single-segment TSO packets. */
4579 if (MLX5_TXOFF_CONFIG(TSO) &&
4580 unlikely(loc.mbuf->ol_flags & PKT_TX_TCP_SEG)) {
4582 * TSO might require special way for inlining
4583 * (dedicated parameters) and is sent with
4584 * MLX5_OPCODE_TSO opcode only, provide this
4585 * in dedicated branch.
4588 assert(NB_SEGS(loc.mbuf) == 1);
4589 assert(pkts_n > loc.pkts_sent);
4590 ret = mlx5_tx_burst_tso(txq, pkts, pkts_n, &loc, olx);
4592 * These returned code checks are supposed
4593 * to be optimized out due to routine inlining.
4595 if (ret == MLX5_TXCMP_CODE_EXIT)
4597 if (ret == MLX5_TXCMP_CODE_ERROR) {
4598 txq->stats.oerrors++;
4601 if (ret == MLX5_TXCMP_CODE_SINGLE)
4602 goto enter_send_single;
4603 if (MLX5_TXOFF_CONFIG(MULTI) &&
4604 ret == MLX5_TXCMP_CODE_MULTI) {
4606 * The multi-segment packet was
4607 * encountered in the array.
4609 goto enter_send_multi;
4611 /* We must not get here. Something is going wrong. */
4613 txq->stats.oerrors++;
4617 * The dedicated branch for the single-segment packets
4618 * without TSO. Often these ones can be sent using
4619 * MLX5_OPCODE_EMPW with multiple packets in one WQE.
4620 * The routine builds the WQEs till it encounters
4621 * the TSO or multi-segment packet (in case if these
4622 * offloads are requested at SQ configuration time).
4625 assert(pkts_n > loc.pkts_sent);
4626 ret = mlx5_tx_burst_single(txq, pkts, pkts_n, &loc, olx);
4628 * These returned code checks are supposed
4629 * to be optimized out due to routine inlining.
4631 if (ret == MLX5_TXCMP_CODE_EXIT)
4633 if (ret == MLX5_TXCMP_CODE_ERROR) {
4634 txq->stats.oerrors++;
4637 if (MLX5_TXOFF_CONFIG(MULTI) &&
4638 ret == MLX5_TXCMP_CODE_MULTI) {
4640 * The multi-segment packet was
4641 * encountered in the array.
4643 goto enter_send_multi;
4645 if (MLX5_TXOFF_CONFIG(TSO) &&
4646 ret == MLX5_TXCMP_CODE_TSO) {
4648 * The single-segment TSO packet was
4649 * encountered in the array.
4651 goto enter_send_tso;
4653 /* We must not get here. Something is going wrong. */
4655 txq->stats.oerrors++;
4659 * Main Tx loop is completed, do the rest:
4660 * - set completion request if thresholds are reached
4661 * - doorbell the hardware
4662 * - copy the rest of mbufs to elts (if any)
4664 assert(MLX5_TXOFF_CONFIG(INLINE) || loc.pkts_sent >= loc.pkts_copy);
4665 /* Take a shortcut if nothing is sent. */
4666 if (unlikely(loc.pkts_sent == 0))
4668 /* Not all of the mbufs may be stored into elts yet. */
4669 part = MLX5_TXOFF_CONFIG(INLINE) ? 0 : loc.pkts_sent - loc.pkts_copy;
4670 mlx5_tx_request_completion(txq, part, &loc, olx);
4672 * Ring QP doorbell immediately after WQE building completion
4673 * to improve latencies. The pure software related data treatment
4674 * can be completed after doorbell. Tx CQEs for this SQ are
4675 * processed in this thread only by the polling.
4677 mlx5_tx_dbrec_cond_wmb(txq, loc.wqe_last, 0);
4678 if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
4680 * There are some single-segment mbufs not stored in elts.
4681 * It can be only if last packet was single-segment.
4682 * The copying is gathered into one place due to it is
4683 * a good opportunity to optimize that with SIMD.
4684 * Unfortunately if inlining is enabled the gaps in
4685 * pointer array may happen due to early freeing of the
4688 mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy, part, olx);
4690 #ifdef MLX5_PMD_SOFT_COUNTERS
4691 /* Increment sent packets counter. */
4692 txq->stats.opackets += loc.pkts_sent;
4694 assert(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
4695 assert(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
4696 return loc.pkts_sent;
4699 /* Generate routines with Enhanced Multi-Packet Write support. */
4700 MLX5_TXOFF_DECL(full_empw,
4701 MLX5_TXOFF_CONFIG_FULL | MLX5_TXOFF_CONFIG_EMPW)
4703 MLX5_TXOFF_DECL(none_empw,
4704 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW)
4706 MLX5_TXOFF_DECL(md_empw,
4707 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4709 MLX5_TXOFF_DECL(mt_empw,
4710 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4711 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4713 MLX5_TXOFF_DECL(mtsc_empw,
4714 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4715 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4716 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4718 MLX5_TXOFF_DECL(mti_empw,
4719 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4720 MLX5_TXOFF_CONFIG_INLINE |
4721 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4723 MLX5_TXOFF_DECL(mtv_empw,
4724 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4725 MLX5_TXOFF_CONFIG_VLAN |
4726 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4728 MLX5_TXOFF_DECL(mtiv_empw,
4729 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4730 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4731 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4733 MLX5_TXOFF_DECL(sc_empw,
4734 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4735 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4737 MLX5_TXOFF_DECL(sci_empw,
4738 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4739 MLX5_TXOFF_CONFIG_INLINE |
4740 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4742 MLX5_TXOFF_DECL(scv_empw,
4743 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4744 MLX5_TXOFF_CONFIG_VLAN |
4745 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4747 MLX5_TXOFF_DECL(sciv_empw,
4748 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4749 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4750 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4752 MLX5_TXOFF_DECL(i_empw,
4753 MLX5_TXOFF_CONFIG_INLINE |
4754 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4756 MLX5_TXOFF_DECL(v_empw,
4757 MLX5_TXOFF_CONFIG_VLAN |
4758 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4760 MLX5_TXOFF_DECL(iv_empw,
4761 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4762 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4764 /* Generate routines without Enhanced Multi-Packet Write support. */
4765 MLX5_TXOFF_DECL(full,
4766 MLX5_TXOFF_CONFIG_FULL)
4768 MLX5_TXOFF_DECL(none,
4769 MLX5_TXOFF_CONFIG_NONE)
4772 MLX5_TXOFF_CONFIG_METADATA)
4775 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4776 MLX5_TXOFF_CONFIG_METADATA)
4778 MLX5_TXOFF_DECL(mtsc,
4779 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4780 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4781 MLX5_TXOFF_CONFIG_METADATA)
4783 MLX5_TXOFF_DECL(mti,
4784 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4785 MLX5_TXOFF_CONFIG_INLINE |
4786 MLX5_TXOFF_CONFIG_METADATA)
4789 MLX5_TXOFF_DECL(mtv,
4790 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4791 MLX5_TXOFF_CONFIG_VLAN |
4792 MLX5_TXOFF_CONFIG_METADATA)
4795 MLX5_TXOFF_DECL(mtiv,
4796 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4797 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4798 MLX5_TXOFF_CONFIG_METADATA)
4801 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4802 MLX5_TXOFF_CONFIG_METADATA)
4804 MLX5_TXOFF_DECL(sci,
4805 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4806 MLX5_TXOFF_CONFIG_INLINE |
4807 MLX5_TXOFF_CONFIG_METADATA)
4810 MLX5_TXOFF_DECL(scv,
4811 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4812 MLX5_TXOFF_CONFIG_VLAN |
4813 MLX5_TXOFF_CONFIG_METADATA)
4816 MLX5_TXOFF_DECL(sciv,
4817 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4818 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4819 MLX5_TXOFF_CONFIG_METADATA)
4822 MLX5_TXOFF_CONFIG_INLINE |
4823 MLX5_TXOFF_CONFIG_METADATA)
4826 MLX5_TXOFF_CONFIG_VLAN |
4827 MLX5_TXOFF_CONFIG_METADATA)
4830 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4831 MLX5_TXOFF_CONFIG_METADATA)
4834 * Array of declared and compiled Tx burst function and corresponding
4835 * supported offloads set. The array is used to select the Tx burst
4836 * function for specified offloads set at Tx queue configuration time.
4839 eth_tx_burst_t func;
4842 MLX5_TXOFF_INFO(full_empw,
4843 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4844 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4845 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4846 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4848 MLX5_TXOFF_INFO(none_empw,
4849 MLX5_TXOFF_CONFIG_NONE | MLX5_TXOFF_CONFIG_EMPW)
4851 MLX5_TXOFF_INFO(md_empw,
4852 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4854 MLX5_TXOFF_INFO(mt_empw,
4855 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4856 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4858 MLX5_TXOFF_INFO(mtsc_empw,
4859 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4860 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4861 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4863 MLX5_TXOFF_INFO(mti_empw,
4864 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4865 MLX5_TXOFF_CONFIG_INLINE |
4866 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4868 MLX5_TXOFF_INFO(mtv_empw,
4869 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4870 MLX5_TXOFF_CONFIG_VLAN |
4871 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4873 MLX5_TXOFF_INFO(mtiv_empw,
4874 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4875 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4876 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4878 MLX5_TXOFF_INFO(sc_empw,
4879 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4880 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4882 MLX5_TXOFF_INFO(sci_empw,
4883 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4884 MLX5_TXOFF_CONFIG_INLINE |
4885 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4887 MLX5_TXOFF_INFO(scv_empw,
4888 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4889 MLX5_TXOFF_CONFIG_VLAN |
4890 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4892 MLX5_TXOFF_INFO(sciv_empw,
4893 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4894 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4895 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4897 MLX5_TXOFF_INFO(i_empw,
4898 MLX5_TXOFF_CONFIG_INLINE |
4899 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4901 MLX5_TXOFF_INFO(v_empw,
4902 MLX5_TXOFF_CONFIG_VLAN |
4903 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4905 MLX5_TXOFF_INFO(iv_empw,
4906 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4907 MLX5_TXOFF_CONFIG_METADATA | MLX5_TXOFF_CONFIG_EMPW)
4909 MLX5_TXOFF_INFO(full,
4910 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4911 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4912 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4913 MLX5_TXOFF_CONFIG_METADATA)
4915 MLX5_TXOFF_INFO(none,
4916 MLX5_TXOFF_CONFIG_NONE)
4919 MLX5_TXOFF_CONFIG_METADATA)
4922 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4923 MLX5_TXOFF_CONFIG_METADATA)
4925 MLX5_TXOFF_INFO(mtsc,
4926 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4927 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4928 MLX5_TXOFF_CONFIG_METADATA)
4930 MLX5_TXOFF_INFO(mti,
4931 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4932 MLX5_TXOFF_CONFIG_INLINE |
4933 MLX5_TXOFF_CONFIG_METADATA)
4936 MLX5_TXOFF_INFO(mtv,
4937 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4938 MLX5_TXOFF_CONFIG_VLAN |
4939 MLX5_TXOFF_CONFIG_METADATA)
4941 MLX5_TXOFF_INFO(mtiv,
4942 MLX5_TXOFF_CONFIG_MULTI | MLX5_TXOFF_CONFIG_TSO |
4943 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4944 MLX5_TXOFF_CONFIG_METADATA)
4947 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4948 MLX5_TXOFF_CONFIG_METADATA)
4950 MLX5_TXOFF_INFO(sci,
4951 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4952 MLX5_TXOFF_CONFIG_INLINE |
4953 MLX5_TXOFF_CONFIG_METADATA)
4955 MLX5_TXOFF_INFO(scv,
4956 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4957 MLX5_TXOFF_CONFIG_VLAN |
4958 MLX5_TXOFF_CONFIG_METADATA)
4960 MLX5_TXOFF_INFO(sciv,
4961 MLX5_TXOFF_CONFIG_SWP | MLX5_TXOFF_CONFIG_CSUM |
4962 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4963 MLX5_TXOFF_CONFIG_METADATA)
4966 MLX5_TXOFF_CONFIG_INLINE |
4967 MLX5_TXOFF_CONFIG_METADATA)
4970 MLX5_TXOFF_CONFIG_VLAN |
4971 MLX5_TXOFF_CONFIG_METADATA)
4974 MLX5_TXOFF_CONFIG_INLINE | MLX5_TXOFF_CONFIG_VLAN |
4975 MLX5_TXOFF_CONFIG_METADATA)
4979 * Configure the Tx function to use. The routine checks configured
4980 * Tx offloads for the device and selects appropriate Tx burst
4981 * routine. There are multiple Tx burst routines compiled from
4982 * the same template in the most optimal way for the dedicated
4986 * Pointer to private data structure.
4989 * Pointer to selected Tx burst function.
4992 mlx5_select_tx_function(struct rte_eth_dev *dev)
4994 struct mlx5_priv *priv = dev->data->dev_private;
4995 struct mlx5_dev_config *config = &priv->config;
4996 uint64_t tx_offloads = dev->data->dev_conf.txmode.offloads;
4997 unsigned int diff = 0, olx = 0, i, m;
4999 static_assert(MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE <=
5000 MLX5_DSEG_MAX, "invalid WQE max size");
5001 static_assert(MLX5_WQE_CSEG_SIZE == MLX5_WSEG_SIZE,
5002 "invalid WQE Control Segment size");
5003 static_assert(MLX5_WQE_ESEG_SIZE == MLX5_WSEG_SIZE,
5004 "invalid WQE Ethernet Segment size");
5005 static_assert(MLX5_WQE_DSEG_SIZE == MLX5_WSEG_SIZE,
5006 "invalid WQE Data Segment size");
5007 static_assert(MLX5_WQE_SIZE == 4 * MLX5_WSEG_SIZE,
5008 "invalid WQE size");
5010 if (tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS) {
5011 /* We should support Multi-Segment Packets. */
5012 olx |= MLX5_TXOFF_CONFIG_MULTI;
5014 if (tx_offloads & (DEV_TX_OFFLOAD_TCP_TSO |
5015 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5016 DEV_TX_OFFLOAD_GRE_TNL_TSO |
5017 DEV_TX_OFFLOAD_IP_TNL_TSO |
5018 DEV_TX_OFFLOAD_UDP_TNL_TSO)) {
5019 /* We should support TCP Send Offload. */
5020 olx |= MLX5_TXOFF_CONFIG_TSO;
5022 if (tx_offloads & (DEV_TX_OFFLOAD_IP_TNL_TSO |
5023 DEV_TX_OFFLOAD_UDP_TNL_TSO |
5024 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
5025 /* We should support Software Parser for Tunnels. */
5026 olx |= MLX5_TXOFF_CONFIG_SWP;
5028 if (tx_offloads & (DEV_TX_OFFLOAD_IPV4_CKSUM |
5029 DEV_TX_OFFLOAD_UDP_CKSUM |
5030 DEV_TX_OFFLOAD_TCP_CKSUM |
5031 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
5032 /* We should support IP/TCP/UDP Checksums. */
5033 olx |= MLX5_TXOFF_CONFIG_CSUM;
5035 if (tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT) {
5036 /* We should support VLAN insertion. */
5037 olx |= MLX5_TXOFF_CONFIG_VLAN;
5039 if (priv->txqs_n && (*priv->txqs)[0]) {
5040 struct mlx5_txq_data *txd = (*priv->txqs)[0];
5042 if (txd->inlen_send) {
5044 * Check the data inline requirements. Data inline
5045 * is enabled on per device basis, we can check
5046 * the first Tx queue only.
5048 * If device does not support VLAN insertion in WQE
5049 * and some queues are requested to perform VLAN
5050 * insertion offload than inline must be enabled.
5052 olx |= MLX5_TXOFF_CONFIG_INLINE;
5055 if (config->mps == MLX5_MPW_ENHANCED &&
5056 config->txq_inline_min <= 0) {
5058 * The NIC supports Enhanced Multi-Packet Write.
5059 * We do not support legacy MPW due to its
5060 * hardware related problems, so we just ignore
5061 * legacy MLX5_MPW settings. There should be no
5062 * minimal required inline data.
5064 olx |= MLX5_TXOFF_CONFIG_EMPW;
5066 if (tx_offloads & DEV_TX_OFFLOAD_MATCH_METADATA) {
5067 /* We should support Flow metadata. */
5068 olx |= MLX5_TXOFF_CONFIG_METADATA;
5071 * Scan the routines table to find the minimal
5072 * satisfying routine with requested offloads.
5074 m = RTE_DIM(txoff_func);
5075 for (i = 0; i < RTE_DIM(txoff_func); i++) {
5078 tmp = txoff_func[i].olx;
5080 /* Meets requested offloads exactly.*/
5084 if ((tmp & olx) != olx) {
5085 /* Does not meet requested offloads at all. */
5088 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_EMPW)
5089 /* Do not enable eMPW if not configured. */
5091 if ((olx ^ tmp) & MLX5_TXOFF_CONFIG_INLINE)
5092 /* Do not enable inlining if not configured. */
5095 * Some routine meets the requirements.
5096 * Check whether it has minimal amount
5097 * of not requested offloads.
5099 tmp = __builtin_popcountl(tmp & ~olx);
5100 if (m >= RTE_DIM(txoff_func) || tmp < diff) {
5101 /* First or better match, save and continue. */
5107 tmp = txoff_func[i].olx ^ txoff_func[m].olx;
5108 if (__builtin_ffsl(txoff_func[i].olx & ~tmp) <
5109 __builtin_ffsl(txoff_func[m].olx & ~tmp)) {
5110 /* Lighter not requested offload. */
5115 if (m >= RTE_DIM(txoff_func)) {
5116 DRV_LOG(DEBUG, "port %u has no selected Tx function"
5117 " for requested offloads %04X",
5118 dev->data->port_id, olx);
5121 DRV_LOG(DEBUG, "port %u has selected Tx function"
5122 " supporting offloads %04X/%04X",
5123 dev->data->port_id, olx, txoff_func[m].olx);
5124 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_MULTI)
5125 DRV_LOG(DEBUG, "\tMULTI (multi segment)");
5126 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_TSO)
5127 DRV_LOG(DEBUG, "\tTSO (TCP send offload)");
5128 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_SWP)
5129 DRV_LOG(DEBUG, "\tSWP (software parser)");
5130 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_CSUM)
5131 DRV_LOG(DEBUG, "\tCSUM (checksum offload)");
5132 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_INLINE)
5133 DRV_LOG(DEBUG, "\tINLIN (inline data)");
5134 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_VLAN)
5135 DRV_LOG(DEBUG, "\tVLANI (VLAN insertion)");
5136 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_METADATA)
5137 DRV_LOG(DEBUG, "\tMETAD (tx Flow metadata)");
5138 if (txoff_func[m].olx & MLX5_TXOFF_CONFIG_EMPW)
5139 DRV_LOG(DEBUG, "\tEMPW (Enhanced MPW)");
5140 return txoff_func[m].func;