4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef RTE_PMD_MLX5_RXTX_H_
35 #define RTE_PMD_MLX5_RXTX_H_
39 #include <sys/queue.h>
42 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
44 #pragma GCC diagnostic ignored "-Wpedantic"
46 #include <infiniband/verbs.h>
47 #include <infiniband/mlx5dv.h>
49 #pragma GCC diagnostic error "-Wpedantic"
53 #include <rte_mempool.h>
54 #include <rte_common.h>
55 #include <rte_hexdump.h>
56 #include <rte_atomic.h>
58 #include "mlx5_utils.h"
60 #include "mlx5_autoconf.h"
61 #include "mlx5_defs.h"
64 struct mlx5_rxq_stats {
65 unsigned int idx; /**< Mapping index. */
66 #ifdef MLX5_PMD_SOFT_COUNTERS
67 uint64_t ipackets; /**< Total of successfully received packets. */
68 uint64_t ibytes; /**< Total of successfully received bytes. */
70 uint64_t idropped; /**< Total of packets dropped when RX ring full. */
71 uint64_t rx_nombuf; /**< Total of RX mbuf allocation failures. */
74 struct mlx5_txq_stats {
75 unsigned int idx; /**< Mapping index. */
76 #ifdef MLX5_PMD_SOFT_COUNTERS
77 uint64_t opackets; /**< Total of successfully sent packets. */
78 uint64_t obytes; /**< Total of successfully sent bytes. */
80 uint64_t oerrors; /**< Total number of failed transmitted packets. */
85 /* Memory region queue object. */
87 LIST_ENTRY(mlx5_mr) next; /**< Pointer to the next element. */
88 rte_atomic32_t refcnt; /*<< Reference counter. */
89 uint32_t lkey; /*<< rte_cpu_to_be_32(mr->lkey) */
90 uintptr_t start; /* Start address of MR */
91 uintptr_t end; /* End address of MR */
92 struct ibv_mr *mr; /*<< Memory Region. */
93 struct rte_mempool *mp; /*<< Memory Pool. */
96 /* Compressed CQE context. */
98 uint16_t ai; /* Array index. */
99 uint16_t ca; /* Current array index. */
100 uint16_t na; /* Next array index. */
101 uint16_t cq_ci; /* The next CQE. */
102 uint32_t cqe_cnt; /* Number of CQEs. */
105 /* RX queue descriptor. */
106 struct mlx5_rxq_data {
107 unsigned int csum:1; /* Enable checksum offloading. */
108 unsigned int csum_l2tun:1; /* Same for L2 tunnels. */
109 unsigned int hw_timestamp:1; /* Enable HW timestamp. */
110 unsigned int vlan_strip:1; /* Enable VLAN stripping. */
111 unsigned int crc_present:1; /* CRC must be subtracted. */
112 unsigned int sges_n:2; /* Log 2 of SGEs (max buffers per packet). */
113 unsigned int cqe_n:4; /* Log 2 of CQ elements. */
114 unsigned int elts_n:4; /* Log 2 of Mbufs. */
115 unsigned int rss_hash:1; /* RSS hash result is enabled. */
116 unsigned int mark:1; /* Marked flow available on the queue. */
117 unsigned int :15; /* Remaining bits. */
118 volatile uint32_t *rq_db;
119 volatile uint32_t *cq_db;
124 volatile struct mlx5_wqe_data_seg(*wqes)[];
125 volatile struct mlx5_cqe(*cqes)[];
126 struct rxq_zip zip; /* Compressed context. */
127 struct rte_mbuf *(*elts)[];
128 struct rte_mempool *mp;
129 struct mlx5_rxq_stats stats;
130 uint64_t mbuf_initializer; /* Default rearm_data for vectorized Rx. */
131 struct rte_mbuf fake_mbuf; /* elts padding for vectorized Rx. */
132 void *cq_uar; /* CQ user access region. */
133 uint32_t cqn; /* CQ number. */
134 uint8_t cq_arm_sn; /* CQ arm seq number. */
135 } __rte_cache_aligned;
137 /* Verbs Rx queue elements. */
138 struct mlx5_rxq_ibv {
139 LIST_ENTRY(mlx5_rxq_ibv) next; /* Pointer to the next element. */
140 rte_atomic32_t refcnt; /* Reference counter. */
141 struct mlx5_rxq_ctrl *rxq_ctrl; /* Back pointer to parent. */
142 struct ibv_cq *cq; /* Completion Queue. */
143 struct ibv_wq *wq; /* Work Queue. */
144 struct ibv_comp_channel *channel;
145 struct mlx5_mr *mr; /* Memory Region (for mp). */
148 /* RX queue control descriptor. */
149 struct mlx5_rxq_ctrl {
150 LIST_ENTRY(mlx5_rxq_ctrl) next; /* Pointer to the next element. */
151 rte_atomic32_t refcnt; /* Reference counter. */
152 struct priv *priv; /* Back pointer to private data. */
153 struct mlx5_rxq_ibv *ibv; /* Verbs elements. */
154 struct mlx5_rxq_data rxq; /* Data path structure. */
155 unsigned int socket; /* CPU socket ID for allocations. */
156 unsigned int irq:1; /* Whether IRQ is enabled. */
157 uint16_t idx; /* Queue index. */
160 /* Indirection table. */
161 struct mlx5_ind_table_ibv {
162 LIST_ENTRY(mlx5_ind_table_ibv) next; /* Pointer to the next element. */
163 rte_atomic32_t refcnt; /* Reference counter. */
164 struct ibv_rwq_ind_table *ind_table; /**< Indirection table. */
165 uint16_t queues_n; /**< Number of queues in the list. */
166 uint16_t queues[]; /**< Queue list. */
171 LIST_ENTRY(mlx5_hrxq) next; /* Pointer to the next element. */
172 rte_atomic32_t refcnt; /* Reference counter. */
173 struct mlx5_ind_table_ibv *ind_table; /* Indirection table. */
174 struct ibv_qp *qp; /* Verbs queue pair. */
175 uint64_t hash_fields; /* Verbs Hash fields. */
176 uint8_t rss_key_len; /* Hash key length in bytes. */
177 uint8_t rss_key[]; /* Hash key. */
180 /* TX queue descriptor. */
182 struct mlx5_txq_data {
183 uint16_t elts_head; /* Current counter in (*elts)[]. */
184 uint16_t elts_tail; /* Counter of first element awaiting completion. */
185 uint16_t elts_comp; /* Counter since last completion request. */
186 uint16_t mpw_comp; /* WQ index since last completion request. */
187 uint16_t cq_ci; /* Consumer index for completion queue. */
189 uint16_t cq_pi; /* Producer index for completion queue. */
191 uint16_t wqe_ci; /* Consumer index for work queue. */
192 uint16_t wqe_pi; /* Producer index for work queue. */
193 uint16_t elts_n:4; /* (*elts)[] length (in log2). */
194 uint16_t cqe_n:4; /* Number of CQ elements (in log2). */
195 uint16_t wqe_n:4; /* Number of of WQ elements (in log2). */
196 uint16_t inline_en:1; /* When set inline is enabled. */
197 uint16_t tso_en:1; /* When set hardware TSO is enabled. */
198 uint16_t tunnel_en:1;
199 /* When set TX offload for tunneled packets are supported. */
200 uint16_t mpw_hdr_dseg:1; /* Enable DSEGs in the title WQEBB. */
201 uint16_t max_inline; /* Multiple of RTE_CACHE_LINE_SIZE to inline. */
202 uint16_t inline_max_packet_sz; /* Max packet size for inlining. */
203 uint16_t mr_cache_idx; /* Index of last hit entry. */
204 uint32_t qp_num_8s; /* QP number shifted by 8. */
205 uint32_t flags; /* Flags for Tx Queue. */
206 volatile struct mlx5_cqe (*cqes)[]; /* Completion queue. */
207 volatile void *wqes; /* Work queue (use volatile to write into). */
208 volatile uint32_t *qp_db; /* Work queue doorbell. */
209 volatile uint32_t *cq_db; /* Completion queue doorbell. */
210 volatile void *bf_reg; /* Blueflame register remapped. */
211 struct mlx5_mr *mp2mr[MLX5_PMD_TX_MP_CACHE]; /* MR translation table. */
212 struct rte_mbuf *(*elts)[]; /* TX elements. */
213 struct mlx5_txq_stats stats; /* TX queue counters. */
214 } __rte_cache_aligned;
216 /* Verbs Rx queue elements. */
217 struct mlx5_txq_ibv {
218 LIST_ENTRY(mlx5_txq_ibv) next; /* Pointer to the next element. */
219 rte_atomic32_t refcnt; /* Reference counter. */
220 struct mlx5_txq_ctrl *txq_ctrl; /* Pointer to the control queue. */
221 struct ibv_cq *cq; /* Completion Queue. */
222 struct ibv_qp *qp; /* Queue Pair. */
225 /* TX queue control descriptor. */
226 struct mlx5_txq_ctrl {
227 LIST_ENTRY(mlx5_txq_ctrl) next; /* Pointer to the next element. */
228 rte_atomic32_t refcnt; /* Reference counter. */
229 struct priv *priv; /* Back pointer to private data. */
230 unsigned int socket; /* CPU socket ID for allocations. */
231 unsigned int max_inline_data; /* Max inline data. */
232 unsigned int max_tso_header; /* Max TSO header size. */
233 struct mlx5_txq_ibv *ibv; /* Verbs queue object. */
234 struct mlx5_txq_data txq; /* Data path structure. */
235 off_t uar_mmap_offset; /* UAR mmap offset for non-primary process. */
236 volatile void *bf_reg_orig; /* Blueflame register from verbs. */
237 uint16_t idx; /* Queue index. */
242 extern uint8_t rss_hash_default_key[];
243 extern const size_t rss_hash_default_key_len;
245 void mlx5_rxq_cleanup(struct mlx5_rxq_ctrl *rxq_ctrl);
246 int mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
247 unsigned int socket, const struct rte_eth_rxconf *conf,
248 struct rte_mempool *mp);
249 void mlx5_rx_queue_release(void *dpdk_rxq);
250 int mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev);
251 void mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev);
252 int mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
253 int mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
254 struct mlx5_rxq_ibv *mlx5_rxq_ibv_new(struct rte_eth_dev *dev, uint16_t idx);
255 struct mlx5_rxq_ibv *mlx5_rxq_ibv_get(struct rte_eth_dev *dev, uint16_t idx);
256 int mlx5_rxq_ibv_release(struct mlx5_rxq_ibv *rxq_ibv);
257 int mlx5_rxq_ibv_releasable(struct mlx5_rxq_ibv *rxq_ibv);
258 int mlx5_rxq_ibv_verify(struct rte_eth_dev *dev);
259 struct mlx5_rxq_ctrl *mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx,
260 uint16_t desc, unsigned int socket,
261 struct rte_mempool *mp);
262 struct mlx5_rxq_ctrl *mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx);
263 int mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx);
264 int mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx);
265 int mlx5_rxq_verify(struct rte_eth_dev *dev);
266 int rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl);
267 struct mlx5_ind_table_ibv *mlx5_ind_table_ibv_new(struct rte_eth_dev *dev,
270 struct mlx5_ind_table_ibv *mlx5_ind_table_ibv_get(struct rte_eth_dev *dev,
273 int mlx5_ind_table_ibv_release(struct rte_eth_dev *dev,
274 struct mlx5_ind_table_ibv *ind_tbl);
275 int mlx5_ind_table_ibv_verify(struct rte_eth_dev *dev);
276 struct mlx5_hrxq *mlx5_hrxq_new(struct rte_eth_dev *dev, uint8_t *rss_key,
277 uint8_t rss_key_len, uint64_t hash_fields,
278 uint16_t queues[], uint16_t queues_n);
279 struct mlx5_hrxq *mlx5_hrxq_get(struct rte_eth_dev *dev, uint8_t *rss_key,
280 uint8_t rss_key_len, uint64_t hash_fields,
281 uint16_t queues[], uint16_t queues_n);
282 int mlx5_hrxq_release(struct rte_eth_dev *dev, struct mlx5_hrxq *hxrq);
283 int mlx5_hrxq_ibv_verify(struct rte_eth_dev *dev);
287 int mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
288 unsigned int socket, const struct rte_eth_txconf *conf);
289 void mlx5_tx_queue_release(void *dpdk_txq);
290 int mlx5_tx_uar_remap(struct rte_eth_dev *dev, int fd);
291 struct mlx5_txq_ibv *mlx5_txq_ibv_new(struct rte_eth_dev *dev, uint16_t idx);
292 struct mlx5_txq_ibv *mlx5_txq_ibv_get(struct rte_eth_dev *dev, uint16_t idx);
293 int mlx5_txq_ibv_release(struct mlx5_txq_ibv *txq_ibv);
294 int mlx5_txq_ibv_releasable(struct mlx5_txq_ibv *txq_ibv);
295 int mlx5_txq_ibv_verify(struct rte_eth_dev *dev);
296 struct mlx5_txq_ctrl *mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx,
297 uint16_t desc, unsigned int socket,
298 const struct rte_eth_txconf *conf);
299 struct mlx5_txq_ctrl *mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx);
300 int mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx);
301 int mlx5_txq_releasable(struct rte_eth_dev *dev, uint16_t idx);
302 int mlx5_txq_verify(struct rte_eth_dev *dev);
303 void txq_alloc_elts(struct mlx5_txq_ctrl *txq_ctrl);
307 extern uint32_t mlx5_ptype_table[];
309 void mlx5_set_ptype_table(void);
310 uint16_t mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
312 uint16_t mlx5_tx_burst_mpw(void *dpdk_txq, struct rte_mbuf **pkts,
314 uint16_t mlx5_tx_burst_mpw_inline(void *dpdk_txq, struct rte_mbuf **pkts,
316 uint16_t mlx5_tx_burst_empw(void *dpdk_txq, struct rte_mbuf **pkts,
318 uint16_t mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n);
319 uint16_t removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
321 uint16_t removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
323 int mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset);
324 int mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset);
326 /* Vectorized version of mlx5_rxtx.c */
327 int mlx5_check_raw_vec_tx_support(struct rte_eth_dev *dev);
328 int mlx5_check_vec_tx_support(struct rte_eth_dev *dev);
329 int mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq_data);
330 int mlx5_check_vec_rx_support(struct rte_eth_dev *dev);
331 uint16_t mlx5_tx_burst_raw_vec(void *dpdk_txq, struct rte_mbuf **pkts,
333 uint16_t mlx5_tx_burst_vec(void *dpdk_txq, struct rte_mbuf **pkts,
335 uint16_t mlx5_rx_burst_vec(void *dpdk_txq, struct rte_mbuf **pkts,
340 void mlx5_mp2mr_iter(struct rte_mempool *mp, void *arg);
341 struct mlx5_mr *mlx5_txq_mp2mr_reg(struct mlx5_txq_data *txq,
342 struct rte_mempool *mp, unsigned int idx);
346 * Verify or set magic value in CQE.
355 check_cqe_seen(volatile struct mlx5_cqe *cqe)
357 static const uint8_t magic[] = "seen";
358 volatile uint8_t (*buf)[sizeof(cqe->rsvd0)] = &cqe->rsvd0;
362 for (i = 0; i < sizeof(magic) && i < sizeof(*buf); ++i)
363 if (!ret || (*buf)[i] != magic[i]) {
365 (*buf)[i] = magic[i];
372 * Check whether CQE is valid.
377 * Size of completion queue.
382 * 0 on success, 1 on failure.
384 static __rte_always_inline int
385 check_cqe(volatile struct mlx5_cqe *cqe,
386 unsigned int cqes_n, const uint16_t ci)
388 uint16_t idx = ci & cqes_n;
389 uint8_t op_own = cqe->op_own;
390 uint8_t op_owner = MLX5_CQE_OWNER(op_own);
391 uint8_t op_code = MLX5_CQE_OPCODE(op_own);
393 if (unlikely((op_owner != (!!(idx))) || (op_code == MLX5_CQE_INVALID)))
394 return 1; /* No CQE. */
396 if ((op_code == MLX5_CQE_RESP_ERR) ||
397 (op_code == MLX5_CQE_REQ_ERR)) {
398 volatile struct mlx5_err_cqe *err_cqe = (volatile void *)cqe;
399 uint8_t syndrome = err_cqe->syndrome;
401 if ((syndrome == MLX5_CQE_SYNDROME_LOCAL_LENGTH_ERR) ||
402 (syndrome == MLX5_CQE_SYNDROME_REMOTE_ABORTED_ERR))
404 if (!check_cqe_seen(cqe)) {
406 "unexpected CQE error %u (0x%02x) syndrome"
408 op_code, op_code, syndrome);
409 rte_hexdump(stderr, "MLX5 Error CQE:",
410 (const void *)((uintptr_t)err_cqe),
414 } else if ((op_code != MLX5_CQE_RESP_SEND) &&
415 (op_code != MLX5_CQE_REQ)) {
416 if (!check_cqe_seen(cqe)) {
417 DRV_LOG(ERR, "unexpected CQE opcode %u (0x%02x)",
419 rte_hexdump(stderr, "MLX5 CQE:",
420 (const void *)((uintptr_t)cqe),
430 * Return the address of the WQE.
433 * Pointer to TX queue structure.
435 * WQE consumer index.
440 static inline uintptr_t *
441 tx_mlx5_wqe(struct mlx5_txq_data *txq, uint16_t ci)
443 ci &= ((1 << txq->wqe_n) - 1);
444 return (uintptr_t *)((uintptr_t)txq->wqes + ci * MLX5_WQE_SIZE);
448 * Manage TX completions.
450 * When sending a burst, mlx5_tx_burst() posts several WRs.
453 * Pointer to TX queue structure.
455 static __rte_always_inline void
456 mlx5_tx_complete(struct mlx5_txq_data *txq)
458 const uint16_t elts_n = 1 << txq->elts_n;
459 const uint16_t elts_m = elts_n - 1;
460 const unsigned int cqe_n = 1 << txq->cqe_n;
461 const unsigned int cqe_cnt = cqe_n - 1;
462 uint16_t elts_free = txq->elts_tail;
464 uint16_t cq_ci = txq->cq_ci;
465 volatile struct mlx5_cqe *cqe = NULL;
466 volatile struct mlx5_wqe_ctrl *ctrl;
467 struct rte_mbuf *m, *free[elts_n];
468 struct rte_mempool *pool = NULL;
469 unsigned int blk_n = 0;
471 cqe = &(*txq->cqes)[cq_ci & cqe_cnt];
472 if (unlikely(check_cqe(cqe, cqe_n, cq_ci)))
475 if ((MLX5_CQE_OPCODE(cqe->op_own) == MLX5_CQE_RESP_ERR) ||
476 (MLX5_CQE_OPCODE(cqe->op_own) == MLX5_CQE_REQ_ERR)) {
477 if (!check_cqe_seen(cqe)) {
478 DRV_LOG(ERR, "unexpected error CQE, Tx stopped");
479 rte_hexdump(stderr, "MLX5 TXQ:",
480 (const void *)((uintptr_t)txq->wqes),
488 txq->wqe_pi = rte_be_to_cpu_16(cqe->wqe_counter);
489 ctrl = (volatile struct mlx5_wqe_ctrl *)
490 tx_mlx5_wqe(txq, txq->wqe_pi);
491 elts_tail = ctrl->ctrl3;
492 assert((elts_tail & elts_m) < (1 << txq->wqe_n));
494 while (elts_free != elts_tail) {
495 m = rte_pktmbuf_prefree_seg((*txq->elts)[elts_free++ & elts_m]);
496 if (likely(m != NULL)) {
497 if (likely(m->pool == pool)) {
500 if (likely(pool != NULL))
501 rte_mempool_put_bulk(pool,
511 rte_mempool_put_bulk(pool, (void *)free, blk_n);
513 elts_free = txq->elts_tail;
515 while (elts_free != elts_tail) {
516 memset(&(*txq->elts)[elts_free & elts_m],
518 sizeof((*txq->elts)[elts_free & elts_m]));
523 txq->elts_tail = elts_tail;
524 /* Update the consumer index. */
525 rte_compiler_barrier();
526 *txq->cq_db = rte_cpu_to_be_32(cq_ci);
530 * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
531 * the cloned mbuf is allocated is returned instead.
537 * Memory pool where data is located for given mbuf.
539 static struct rte_mempool *
540 mlx5_tx_mb2mp(struct rte_mbuf *buf)
542 if (unlikely(RTE_MBUF_INDIRECT(buf)))
543 return rte_mbuf_from_indirect(buf)->pool;
548 * Get Memory Region (MR) <-> rte_mbuf association from txq->mp2mr[].
549 * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
550 * remove an entry first.
553 * Pointer to TX queue structure.
555 * Memory Pool for which a Memory Region lkey must be returned.
558 * mr->lkey on success, (uint32_t)-1 on failure.
560 static __rte_always_inline uint32_t
561 mlx5_tx_mb2mr(struct mlx5_txq_data *txq, struct rte_mbuf *mb)
563 uint16_t i = txq->mr_cache_idx;
564 uintptr_t addr = rte_pktmbuf_mtod(mb, uintptr_t);
567 assert(i < RTE_DIM(txq->mp2mr));
568 if (likely(txq->mp2mr[i]->start <= addr && txq->mp2mr[i]->end > addr))
569 return txq->mp2mr[i]->lkey;
570 for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
571 if (unlikely(txq->mp2mr[i] == NULL ||
572 txq->mp2mr[i]->mr == NULL)) {
573 /* Unknown MP, add a new MR for it. */
576 if (txq->mp2mr[i]->start <= addr &&
577 txq->mp2mr[i]->end > addr) {
578 assert(txq->mp2mr[i]->lkey != (uint32_t)-1);
579 txq->mr_cache_idx = i;
580 return txq->mp2mr[i]->lkey;
583 mr = mlx5_txq_mp2mr_reg(txq, mlx5_tx_mb2mp(mb), i);
585 * Request the reference to use in this queue, the original one is
586 * kept by the control plane.
589 rte_atomic32_inc(&mr->refcnt);
590 txq->mr_cache_idx = i >= RTE_DIM(txq->mp2mr) ? i - 1 : i;
593 struct rte_mempool *mp = mlx5_tx_mb2mp(mb);
595 DRV_LOG(WARNING, "failed to register mempool 0x%p(%s)",
596 (void *)mp, mp->name);
602 * Ring TX queue doorbell and flush the update if requested.
605 * Pointer to TX queue structure.
607 * Pointer to the last WQE posted in the NIC.
609 * Request for write memory barrier after BlueFlame update.
611 static __rte_always_inline void
612 mlx5_tx_dbrec_cond_wmb(struct mlx5_txq_data *txq, volatile struct mlx5_wqe *wqe,
615 uint64_t *dst = (uint64_t *)((uintptr_t)txq->bf_reg);
616 volatile uint64_t *src = ((volatile uint64_t *)wqe);
619 *txq->qp_db = rte_cpu_to_be_32(txq->wqe_ci);
620 /* Ensure ordering between DB record and BF copy. */
628 * Ring TX queue doorbell and flush the update by write memory barrier.
631 * Pointer to TX queue structure.
633 * Pointer to the last WQE posted in the NIC.
635 static __rte_always_inline void
636 mlx5_tx_dbrec(struct mlx5_txq_data *txq, volatile struct mlx5_wqe *wqe)
638 mlx5_tx_dbrec_cond_wmb(txq, wqe, 1);
642 * Convert the Checksum offloads to Verbs.
645 * Pointer to the Tx queue.
647 * Pointer to the mbuf.
650 * the converted cs_flags.
652 static __rte_always_inline uint8_t
653 txq_ol_cksum_to_cs(struct mlx5_txq_data *txq_data, struct rte_mbuf *buf)
655 uint8_t cs_flags = 0;
657 /* Should we enable HW CKSUM offload */
659 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM |
660 PKT_TX_OUTER_IP_CKSUM)) {
661 if (txq_data->tunnel_en &&
663 (PKT_TX_TUNNEL_GRE | PKT_TX_TUNNEL_VXLAN))) {
664 cs_flags = MLX5_ETH_WQE_L3_INNER_CSUM |
665 MLX5_ETH_WQE_L4_INNER_CSUM;
666 if (buf->ol_flags & PKT_TX_OUTER_IP_CKSUM)
667 cs_flags |= MLX5_ETH_WQE_L3_CSUM;
669 cs_flags = MLX5_ETH_WQE_L3_CSUM |
670 MLX5_ETH_WQE_L4_CSUM;
676 #endif /* RTE_PMD_MLX5_RXTX_H_ */