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. */
188 uint16_t cq_pi; /* Producer index for completion queue. */
189 uint16_t wqe_ci; /* Consumer index for work queue. */
190 uint16_t wqe_pi; /* Producer index for work queue. */
191 uint16_t elts_n:4; /* (*elts)[] length (in log2). */
192 uint16_t cqe_n:4; /* Number of CQ elements (in log2). */
193 uint16_t wqe_n:4; /* Number of of WQ elements (in log2). */
194 uint16_t inline_en:1; /* When set inline is enabled. */
195 uint16_t tso_en:1; /* When set hardware TSO is enabled. */
196 uint16_t tunnel_en:1;
197 /* When set TX offload for tunneled packets are supported. */
198 uint16_t mpw_hdr_dseg:1; /* Enable DSEGs in the title WQEBB. */
199 uint16_t max_inline; /* Multiple of RTE_CACHE_LINE_SIZE to inline. */
200 uint16_t inline_max_packet_sz; /* Max packet size for inlining. */
201 uint16_t mr_cache_idx; /* Index of last hit entry. */
202 uint32_t qp_num_8s; /* QP number shifted by 8. */
203 uint32_t flags; /* Flags for Tx Queue. */
204 volatile struct mlx5_cqe (*cqes)[]; /* Completion queue. */
205 volatile void *wqes; /* Work queue (use volatile to write into). */
206 volatile uint32_t *qp_db; /* Work queue doorbell. */
207 volatile uint32_t *cq_db; /* Completion queue doorbell. */
208 volatile void *bf_reg; /* Blueflame register remapped. */
209 struct mlx5_mr *mp2mr[MLX5_PMD_TX_MP_CACHE]; /* MR translation table. */
210 struct rte_mbuf *(*elts)[]; /* TX elements. */
211 struct mlx5_txq_stats stats; /* TX queue counters. */
212 } __rte_cache_aligned;
214 /* Verbs Rx queue elements. */
215 struct mlx5_txq_ibv {
216 LIST_ENTRY(mlx5_txq_ibv) next; /* Pointer to the next element. */
217 rte_atomic32_t refcnt; /* Reference counter. */
218 struct mlx5_txq_ctrl *txq_ctrl; /* Pointer to the control queue. */
219 struct ibv_cq *cq; /* Completion Queue. */
220 struct ibv_qp *qp; /* Queue Pair. */
223 /* TX queue control descriptor. */
224 struct mlx5_txq_ctrl {
225 LIST_ENTRY(mlx5_txq_ctrl) next; /* Pointer to the next element. */
226 rte_atomic32_t refcnt; /* Reference counter. */
227 struct priv *priv; /* Back pointer to private data. */
228 unsigned int socket; /* CPU socket ID for allocations. */
229 unsigned int max_inline_data; /* Max inline data. */
230 unsigned int max_tso_header; /* Max TSO header size. */
231 struct mlx5_txq_ibv *ibv; /* Verbs queue object. */
232 struct mlx5_txq_data txq; /* Data path structure. */
233 off_t uar_mmap_offset; /* UAR mmap offset for non-primary process. */
234 volatile void *bf_reg_orig; /* Blueflame register from verbs. */
235 uint16_t idx; /* Queue index. */
240 extern uint8_t rss_hash_default_key[];
241 extern const size_t rss_hash_default_key_len;
243 void mlx5_rxq_cleanup(struct mlx5_rxq_ctrl *rxq_ctrl);
244 int mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
245 unsigned int socket, const struct rte_eth_rxconf *conf,
246 struct rte_mempool *mp);
247 void mlx5_rx_queue_release(void *dpdk_rxq);
248 int mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev);
249 void mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev);
250 int mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
251 int mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
252 struct mlx5_rxq_ibv *mlx5_rxq_ibv_new(struct rte_eth_dev *dev, uint16_t idx);
253 struct mlx5_rxq_ibv *mlx5_rxq_ibv_get(struct rte_eth_dev *dev, uint16_t idx);
254 int mlx5_rxq_ibv_release(struct mlx5_rxq_ibv *rxq_ibv);
255 int mlx5_rxq_ibv_releasable(struct mlx5_rxq_ibv *rxq_ibv);
256 int mlx5_rxq_ibv_verify(struct rte_eth_dev *dev);
257 struct mlx5_rxq_ctrl *mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx,
258 uint16_t desc, unsigned int socket,
259 struct rte_mempool *mp);
260 struct mlx5_rxq_ctrl *mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx);
261 int mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx);
262 int mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx);
263 int mlx5_rxq_verify(struct rte_eth_dev *dev);
264 int rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl);
265 struct mlx5_ind_table_ibv *mlx5_ind_table_ibv_new(struct rte_eth_dev *dev,
268 struct mlx5_ind_table_ibv *mlx5_ind_table_ibv_get(struct rte_eth_dev *dev,
271 int mlx5_ind_table_ibv_release(struct rte_eth_dev *dev,
272 struct mlx5_ind_table_ibv *ind_tbl);
273 int mlx5_ind_table_ibv_verify(struct rte_eth_dev *dev);
274 struct mlx5_hrxq *mlx5_hrxq_new(struct rte_eth_dev *dev, uint8_t *rss_key,
275 uint8_t rss_key_len, uint64_t hash_fields,
276 uint16_t queues[], uint16_t queues_n);
277 struct mlx5_hrxq *mlx5_hrxq_get(struct rte_eth_dev *dev, uint8_t *rss_key,
278 uint8_t rss_key_len, uint64_t hash_fields,
279 uint16_t queues[], uint16_t queues_n);
280 int mlx5_hrxq_release(struct rte_eth_dev *dev, struct mlx5_hrxq *hxrq);
281 int mlx5_hrxq_ibv_verify(struct rte_eth_dev *dev);
285 int mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
286 unsigned int socket, const struct rte_eth_txconf *conf);
287 void mlx5_tx_queue_release(void *dpdk_txq);
288 int mlx5_tx_uar_remap(struct rte_eth_dev *dev, int fd);
289 struct mlx5_txq_ibv *mlx5_txq_ibv_new(struct rte_eth_dev *dev, uint16_t idx);
290 struct mlx5_txq_ibv *mlx5_txq_ibv_get(struct rte_eth_dev *dev, uint16_t idx);
291 int mlx5_txq_ibv_release(struct mlx5_txq_ibv *txq_ibv);
292 int mlx5_txq_ibv_releasable(struct mlx5_txq_ibv *txq_ibv);
293 int mlx5_txq_ibv_verify(struct rte_eth_dev *dev);
294 struct mlx5_txq_ctrl *mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx,
295 uint16_t desc, unsigned int socket,
296 const struct rte_eth_txconf *conf);
297 struct mlx5_txq_ctrl *mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx);
298 int mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx);
299 int mlx5_txq_releasable(struct rte_eth_dev *dev, uint16_t idx);
300 int mlx5_txq_verify(struct rte_eth_dev *dev);
301 void txq_alloc_elts(struct mlx5_txq_ctrl *txq_ctrl);
305 extern uint32_t mlx5_ptype_table[];
307 void mlx5_set_ptype_table(void);
308 uint16_t mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
310 uint16_t mlx5_tx_burst_mpw(void *dpdk_txq, struct rte_mbuf **pkts,
312 uint16_t mlx5_tx_burst_mpw_inline(void *dpdk_txq, struct rte_mbuf **pkts,
314 uint16_t mlx5_tx_burst_empw(void *dpdk_txq, struct rte_mbuf **pkts,
316 uint16_t mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n);
317 uint16_t removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
319 uint16_t removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
321 int mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset);
322 int mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset);
324 /* Vectorized version of mlx5_rxtx.c */
325 int mlx5_check_raw_vec_tx_support(struct rte_eth_dev *dev);
326 int mlx5_check_vec_tx_support(struct rte_eth_dev *dev);
327 int mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq_data);
328 int mlx5_check_vec_rx_support(struct rte_eth_dev *dev);
329 uint16_t mlx5_tx_burst_raw_vec(void *dpdk_txq, struct rte_mbuf **pkts,
331 uint16_t mlx5_tx_burst_vec(void *dpdk_txq, struct rte_mbuf **pkts,
333 uint16_t mlx5_rx_burst_vec(void *dpdk_txq, struct rte_mbuf **pkts,
338 void mlx5_mp2mr_iter(struct rte_mempool *mp, void *arg);
339 struct mlx5_mr *mlx5_txq_mp2mr_reg(struct mlx5_txq_data *txq,
340 struct rte_mempool *mp, unsigned int idx);
344 * Verify or set magic value in CQE.
353 check_cqe_seen(volatile struct mlx5_cqe *cqe)
355 static const uint8_t magic[] = "seen";
356 volatile uint8_t (*buf)[sizeof(cqe->rsvd0)] = &cqe->rsvd0;
360 for (i = 0; i < sizeof(magic) && i < sizeof(*buf); ++i)
361 if (!ret || (*buf)[i] != magic[i]) {
363 (*buf)[i] = magic[i];
370 * Check whether CQE is valid.
375 * Size of completion queue.
380 * 0 on success, 1 on failure.
382 static __rte_always_inline int
383 check_cqe(volatile struct mlx5_cqe *cqe,
384 unsigned int cqes_n, const uint16_t ci)
386 uint16_t idx = ci & cqes_n;
387 uint8_t op_own = cqe->op_own;
388 uint8_t op_owner = MLX5_CQE_OWNER(op_own);
389 uint8_t op_code = MLX5_CQE_OPCODE(op_own);
391 if (unlikely((op_owner != (!!(idx))) || (op_code == MLX5_CQE_INVALID)))
392 return 1; /* No CQE. */
394 if ((op_code == MLX5_CQE_RESP_ERR) ||
395 (op_code == MLX5_CQE_REQ_ERR)) {
396 volatile struct mlx5_err_cqe *err_cqe = (volatile void *)cqe;
397 uint8_t syndrome = err_cqe->syndrome;
399 if ((syndrome == MLX5_CQE_SYNDROME_LOCAL_LENGTH_ERR) ||
400 (syndrome == MLX5_CQE_SYNDROME_REMOTE_ABORTED_ERR))
402 if (!check_cqe_seen(cqe)) {
404 "unexpected CQE error %u (0x%02x) syndrome"
406 op_code, op_code, syndrome);
407 rte_hexdump(stderr, "MLX5 Error CQE:",
408 (const void *)((uintptr_t)err_cqe),
412 } else if ((op_code != MLX5_CQE_RESP_SEND) &&
413 (op_code != MLX5_CQE_REQ)) {
414 if (!check_cqe_seen(cqe)) {
415 DRV_LOG(ERR, "unexpected CQE opcode %u (0x%02x)",
417 rte_hexdump(stderr, "MLX5 CQE:",
418 (const void *)((uintptr_t)cqe),
428 * Return the address of the WQE.
431 * Pointer to TX queue structure.
433 * WQE consumer index.
438 static inline uintptr_t *
439 tx_mlx5_wqe(struct mlx5_txq_data *txq, uint16_t ci)
441 ci &= ((1 << txq->wqe_n) - 1);
442 return (uintptr_t *)((uintptr_t)txq->wqes + ci * MLX5_WQE_SIZE);
446 * Manage TX completions.
448 * When sending a burst, mlx5_tx_burst() posts several WRs.
451 * Pointer to TX queue structure.
453 static __rte_always_inline void
454 mlx5_tx_complete(struct mlx5_txq_data *txq)
456 const uint16_t elts_n = 1 << txq->elts_n;
457 const uint16_t elts_m = elts_n - 1;
458 const unsigned int cqe_n = 1 << txq->cqe_n;
459 const unsigned int cqe_cnt = cqe_n - 1;
460 uint16_t elts_free = txq->elts_tail;
462 uint16_t cq_ci = txq->cq_ci;
463 volatile struct mlx5_cqe *cqe = NULL;
464 volatile struct mlx5_wqe_ctrl *ctrl;
465 struct rte_mbuf *m, *free[elts_n];
466 struct rte_mempool *pool = NULL;
467 unsigned int blk_n = 0;
469 cqe = &(*txq->cqes)[cq_ci & cqe_cnt];
470 if (unlikely(check_cqe(cqe, cqe_n, cq_ci)))
473 if ((MLX5_CQE_OPCODE(cqe->op_own) == MLX5_CQE_RESP_ERR) ||
474 (MLX5_CQE_OPCODE(cqe->op_own) == MLX5_CQE_REQ_ERR)) {
475 if (!check_cqe_seen(cqe)) {
476 DRV_LOG(ERR, "unexpected error CQE, Tx stopped");
477 rte_hexdump(stderr, "MLX5 TXQ:",
478 (const void *)((uintptr_t)txq->wqes),
486 txq->wqe_pi = rte_be_to_cpu_16(cqe->wqe_counter);
487 ctrl = (volatile struct mlx5_wqe_ctrl *)
488 tx_mlx5_wqe(txq, txq->wqe_pi);
489 elts_tail = ctrl->ctrl3;
490 assert((elts_tail & elts_m) < (1 << txq->wqe_n));
492 while (elts_free != elts_tail) {
493 m = rte_pktmbuf_prefree_seg((*txq->elts)[elts_free++ & elts_m]);
494 if (likely(m != NULL)) {
495 if (likely(m->pool == pool)) {
498 if (likely(pool != NULL))
499 rte_mempool_put_bulk(pool,
509 rte_mempool_put_bulk(pool, (void *)free, blk_n);
511 elts_free = txq->elts_tail;
513 while (elts_free != elts_tail) {
514 memset(&(*txq->elts)[elts_free & elts_m],
516 sizeof((*txq->elts)[elts_free & elts_m]));
521 txq->elts_tail = elts_tail;
522 /* Update the consumer index. */
523 rte_compiler_barrier();
524 *txq->cq_db = rte_cpu_to_be_32(cq_ci);
528 * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
529 * the cloned mbuf is allocated is returned instead.
535 * Memory pool where data is located for given mbuf.
537 static struct rte_mempool *
538 mlx5_tx_mb2mp(struct rte_mbuf *buf)
540 if (unlikely(RTE_MBUF_INDIRECT(buf)))
541 return rte_mbuf_from_indirect(buf)->pool;
546 * Get Memory Region (MR) <-> rte_mbuf association from txq->mp2mr[].
547 * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
548 * remove an entry first.
551 * Pointer to TX queue structure.
553 * Memory Pool for which a Memory Region lkey must be returned.
556 * mr->lkey on success, (uint32_t)-1 on failure.
558 static __rte_always_inline uint32_t
559 mlx5_tx_mb2mr(struct mlx5_txq_data *txq, struct rte_mbuf *mb)
561 uint16_t i = txq->mr_cache_idx;
562 uintptr_t addr = rte_pktmbuf_mtod(mb, uintptr_t);
565 assert(i < RTE_DIM(txq->mp2mr));
566 if (likely(txq->mp2mr[i]->start <= addr && txq->mp2mr[i]->end > addr))
567 return txq->mp2mr[i]->lkey;
568 for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
569 if (unlikely(txq->mp2mr[i] == NULL ||
570 txq->mp2mr[i]->mr == NULL)) {
571 /* Unknown MP, add a new MR for it. */
574 if (txq->mp2mr[i]->start <= addr &&
575 txq->mp2mr[i]->end > addr) {
576 assert(txq->mp2mr[i]->lkey != (uint32_t)-1);
577 txq->mr_cache_idx = i;
578 return txq->mp2mr[i]->lkey;
581 mr = mlx5_txq_mp2mr_reg(txq, mlx5_tx_mb2mp(mb), i);
583 * Request the reference to use in this queue, the original one is
584 * kept by the control plane.
587 rte_atomic32_inc(&mr->refcnt);
588 txq->mr_cache_idx = i >= RTE_DIM(txq->mp2mr) ? i - 1 : i;
591 struct rte_mempool *mp = mlx5_tx_mb2mp(mb);
593 DRV_LOG(WARNING, "failed to register mempool 0x%p(%s)",
594 (void *)mp, mp->name);
600 * Ring TX queue doorbell and flush the update if requested.
603 * Pointer to TX queue structure.
605 * Pointer to the last WQE posted in the NIC.
607 * Request for write memory barrier after BlueFlame update.
609 static __rte_always_inline void
610 mlx5_tx_dbrec_cond_wmb(struct mlx5_txq_data *txq, volatile struct mlx5_wqe *wqe,
613 uint64_t *dst = (uint64_t *)((uintptr_t)txq->bf_reg);
614 volatile uint64_t *src = ((volatile uint64_t *)wqe);
617 *txq->qp_db = rte_cpu_to_be_32(txq->wqe_ci);
618 /* Ensure ordering between DB record and BF copy. */
626 * Ring TX queue doorbell and flush the update by write memory barrier.
629 * Pointer to TX queue structure.
631 * Pointer to the last WQE posted in the NIC.
633 static __rte_always_inline void
634 mlx5_tx_dbrec(struct mlx5_txq_data *txq, volatile struct mlx5_wqe *wqe)
636 mlx5_tx_dbrec_cond_wmb(txq, wqe, 1);
640 * Convert the Checksum offloads to Verbs.
643 * Pointer to the Tx queue.
645 * Pointer to the mbuf.
648 * the converted cs_flags.
650 static __rte_always_inline uint8_t
651 txq_ol_cksum_to_cs(struct mlx5_txq_data *txq_data, struct rte_mbuf *buf)
653 uint8_t cs_flags = 0;
655 /* Should we enable HW CKSUM offload */
657 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM |
658 PKT_TX_OUTER_IP_CKSUM)) {
659 if (txq_data->tunnel_en &&
661 (PKT_TX_TUNNEL_GRE | PKT_TX_TUNNEL_VXLAN))) {
662 cs_flags = MLX5_ETH_WQE_L3_INNER_CSUM |
663 MLX5_ETH_WQE_L4_INNER_CSUM;
664 if (buf->ol_flags & PKT_TX_OUTER_IP_CKSUM)
665 cs_flags |= MLX5_ETH_WQE_L3_CSUM;
667 cs_flags = MLX5_ETH_WQE_L3_CSUM |
668 MLX5_ETH_WQE_L4_CSUM;
674 #endif /* RTE_PMD_MLX5_RXTX_H_ */