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.
40 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
42 #pragma GCC diagnostic ignored "-pedantic"
44 #include <infiniband/verbs.h>
46 #pragma GCC diagnostic error "-pedantic"
49 /* DPDK headers don't like -pedantic. */
51 #pragma GCC diagnostic ignored "-pedantic"
54 #include <rte_mempool.h>
55 #include <rte_prefetch.h>
56 #include <rte_common.h>
57 #include <rte_branch_prediction.h>
59 #pragma GCC diagnostic error "-pedantic"
63 #include "mlx5_utils.h"
64 #include "mlx5_rxtx.h"
65 #include "mlx5_defs.h"
68 * Manage TX completions.
70 * When sending a burst, mlx5_tx_burst() posts several WRs.
71 * To improve performance, a completion event is only required once every
72 * MLX5_PMD_TX_PER_COMP_REQ sends. Doing so discards completion information
73 * for other WRs, but this information would not be used anyway.
76 * Pointer to TX queue structure.
79 * 0 on success, -1 on failure.
82 txq_complete(struct txq *txq)
84 unsigned int elts_comp = txq->elts_comp;
85 unsigned int elts_tail = txq->elts_tail;
86 const unsigned int elts_n = txq->elts_n;
89 if (unlikely(elts_comp == 0))
92 DEBUG("%p: processing %u work requests completions",
93 (void *)txq, elts_comp);
95 wcs_n = txq->if_cq->poll_cnt(txq->cq, elts_comp);
96 if (unlikely(wcs_n == 0))
98 if (unlikely(wcs_n < 0)) {
99 DEBUG("%p: ibv_poll_cq() failed (wcs_n=%d)",
104 assert(elts_comp <= txq->elts_comp);
106 * Assume WC status is successful as nothing can be done about it
109 elts_tail += wcs_n * txq->elts_comp_cd_init;
110 if (elts_tail >= elts_n)
112 txq->elts_tail = elts_tail;
113 txq->elts_comp = elts_comp;
118 * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
119 * the cloned mbuf is allocated is returned instead.
125 * Memory pool where data is located for given mbuf.
127 static struct rte_mempool *
128 txq_mb2mp(struct rte_mbuf *buf)
130 if (unlikely(RTE_MBUF_INDIRECT(buf)))
131 return rte_mbuf_from_indirect(buf)->pool;
136 * Get Memory Region (MR) <-> Memory Pool (MP) association from txq->mp2mr[].
137 * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
138 * remove an entry first.
141 * Pointer to TX queue structure.
143 * Memory Pool for which a Memory Region lkey must be returned.
146 * mr->lkey on success, (uint32_t)-1 on failure.
149 txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
154 for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
155 if (unlikely(txq->mp2mr[i].mp == NULL)) {
156 /* Unknown MP, add a new MR for it. */
159 if (txq->mp2mr[i].mp == mp) {
160 assert(txq->mp2mr[i].lkey != (uint32_t)-1);
161 assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey);
162 return txq->mp2mr[i].lkey;
165 /* Add a new entry, register MR first. */
166 DEBUG("%p: discovered new memory pool %p", (void *)txq, (void *)mp);
167 mr = ibv_reg_mr(txq->priv->pd,
168 (void *)mp->elt_va_start,
169 (mp->elt_va_end - mp->elt_va_start),
170 (IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE));
171 if (unlikely(mr == NULL)) {
172 DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.",
176 if (unlikely(i == RTE_DIM(txq->mp2mr))) {
177 /* Table is full, remove oldest entry. */
178 DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
181 claim_zero(ibv_dereg_mr(txq->mp2mr[i].mr));
182 memmove(&txq->mp2mr[0], &txq->mp2mr[1],
183 (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0])));
185 /* Store the new entry. */
186 txq->mp2mr[i].mp = mp;
187 txq->mp2mr[i].mr = mr;
188 txq->mp2mr[i].lkey = mr->lkey;
189 DEBUG("%p: new MR lkey for MP %p: 0x%08" PRIu32,
190 (void *)txq, (void *)mp, txq->mp2mr[i].lkey);
191 return txq->mp2mr[i].lkey;
194 #if MLX5_PMD_SGE_WR_N > 1
197 * Copy scattered mbuf contents to a single linear buffer.
200 * Linear output buffer.
202 * Scattered input buffer.
205 * Number of bytes copied to the output buffer or 0 if not large enough.
208 linearize_mbuf(linear_t *linear, struct rte_mbuf *buf)
210 unsigned int size = 0;
214 unsigned int len = DATA_LEN(buf);
218 if (unlikely(size > sizeof(*linear)))
220 memcpy(&(*linear)[offset],
221 rte_pktmbuf_mtod(buf, uint8_t *),
224 } while (buf != NULL);
229 * Handle scattered buffers for mlx5_tx_burst().
232 * TX queue structure.
234 * Number of segments in buf.
236 * TX queue element to fill.
240 * Index of the linear buffer to use if necessary (normally txq->elts_head).
242 * Array filled with SGEs on success.
245 * A structure containing the processed packet size in bytes and the
246 * number of SGEs. Both fields are set to (unsigned int)-1 in case of
249 static struct tx_burst_sg_ret {
253 tx_burst_sg(struct txq *txq, unsigned int segs, struct txq_elt *elt,
254 struct rte_mbuf *buf, unsigned int elts_head,
255 struct ibv_sge (*sges)[MLX5_PMD_SGE_WR_N])
257 unsigned int sent_size = 0;
261 /* When there are too many segments, extra segments are
262 * linearized in the last SGE. */
263 if (unlikely(segs > RTE_DIM(*sges))) {
264 segs = (RTE_DIM(*sges) - 1);
267 /* Update element. */
269 /* Register segments as SGEs. */
270 for (j = 0; (j != segs); ++j) {
271 struct ibv_sge *sge = &(*sges)[j];
274 /* Retrieve Memory Region key for this memory pool. */
275 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
276 if (unlikely(lkey == (uint32_t)-1)) {
277 /* MR does not exist. */
278 DEBUG("%p: unable to get MP <-> MR association",
280 /* Clean up TX element. */
285 sge->addr = rte_pktmbuf_mtod(buf, uintptr_t);
287 rte_prefetch0((volatile void *)
288 (uintptr_t)sge->addr);
289 sge->length = DATA_LEN(buf);
291 sent_size += sge->length;
294 /* If buf is not NULL here and is not going to be linearized,
295 * nb_segs is not valid. */
297 assert((buf == NULL) || (linearize));
298 /* Linearize extra segments. */
300 struct ibv_sge *sge = &(*sges)[segs];
301 linear_t *linear = &(*txq->elts_linear)[elts_head];
302 unsigned int size = linearize_mbuf(linear, buf);
304 assert(segs == (RTE_DIM(*sges) - 1));
306 /* Invalid packet. */
307 DEBUG("%p: packet too large to be linearized.",
309 /* Clean up TX element. */
313 /* If MLX5_PMD_SGE_WR_N is 1, free mbuf immediately. */
314 if (RTE_DIM(*sges) == 1) {
316 struct rte_mbuf *next = NEXT(buf);
318 rte_pktmbuf_free_seg(buf);
320 } while (buf != NULL);
324 sge->addr = (uintptr_t)&(*linear)[0];
326 sge->lkey = txq->mr_linear->lkey;
328 /* Include last segment. */
331 return (struct tx_burst_sg_ret){
336 return (struct tx_burst_sg_ret){
342 #endif /* MLX5_PMD_SGE_WR_N > 1 */
345 * DPDK callback for TX.
348 * Generic pointer to TX queue structure.
350 * Packets to transmit.
352 * Number of packets in array.
355 * Number of packets successfully transmitted (<= pkts_n).
358 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
360 struct txq *txq = (struct txq *)dpdk_txq;
361 unsigned int elts_head = txq->elts_head;
362 const unsigned int elts_tail = txq->elts_tail;
363 const unsigned int elts_n = txq->elts_n;
364 unsigned int elts_comp_cd = txq->elts_comp_cd;
365 unsigned int elts_comp = 0;
370 assert(elts_comp_cd != 0);
372 max = (elts_n - (elts_head - elts_tail));
376 assert(max <= elts_n);
377 /* Always leave one free entry in the ring. */
383 for (i = 0; (i != max); ++i) {
384 struct rte_mbuf *buf = pkts[i];
385 unsigned int elts_head_next =
386 (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
387 struct txq_elt *elt_next = &(*txq->elts)[elts_head_next];
388 struct txq_elt *elt = &(*txq->elts)[elts_head];
389 unsigned int segs = NB_SEGS(buf);
390 #ifdef MLX5_PMD_SOFT_COUNTERS
391 unsigned int sent_size = 0;
393 uint32_t send_flags = 0;
395 /* Clean up old buffer. */
396 if (likely(elt->buf != NULL)) {
397 struct rte_mbuf *tmp = elt->buf;
399 /* Faster than rte_pktmbuf_free(). */
401 struct rte_mbuf *next = NEXT(tmp);
403 rte_pktmbuf_free_seg(tmp);
405 } while (tmp != NULL);
407 /* Request TX completion. */
408 if (unlikely(--elts_comp_cd == 0)) {
409 elts_comp_cd = txq->elts_comp_cd_init;
411 send_flags |= IBV_EXP_QP_BURST_SIGNALED;
413 /* Should we enable HW CKSUM offload */
415 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
416 send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
417 /* HW does not support checksum offloads at arbitrary
418 * offsets but automatically recognizes the packet
419 * type. For inner L3/L4 checksums, only VXLAN (UDP)
420 * tunnels are currently supported. */
421 if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
422 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
424 if (likely(segs == 1)) {
429 /* Retrieve buffer information. */
430 addr = rte_pktmbuf_mtod(buf, uintptr_t);
431 length = DATA_LEN(buf);
432 /* Retrieve Memory Region key for this memory pool. */
433 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
434 if (unlikely(lkey == (uint32_t)-1)) {
435 /* MR does not exist. */
436 DEBUG("%p: unable to get MP <-> MR"
437 " association", (void *)txq);
438 /* Clean up TX element. */
442 /* Update element. */
445 rte_prefetch0((volatile void *)
447 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
448 /* Put packet into send queue. */
449 #if MLX5_PMD_MAX_INLINE > 0
450 if (length <= txq->max_inline)
451 err = txq->if_qp->send_pending_inline
458 err = txq->if_qp->send_pending
466 #ifdef MLX5_PMD_SOFT_COUNTERS
470 #if MLX5_PMD_SGE_WR_N > 1
471 struct ibv_sge sges[MLX5_PMD_SGE_WR_N];
472 struct tx_burst_sg_ret ret;
474 ret = tx_burst_sg(txq, segs, elt, buf, elts_head,
476 if (ret.length == (unsigned int)-1)
478 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
479 /* Put SG list into send queue. */
480 err = txq->if_qp->send_pending_sg_list
487 #ifdef MLX5_PMD_SOFT_COUNTERS
488 sent_size += ret.length;
490 #else /* MLX5_PMD_SGE_WR_N > 1 */
491 DEBUG("%p: TX scattered buffers support not"
492 " compiled in", (void *)txq);
494 #endif /* MLX5_PMD_SGE_WR_N > 1 */
496 elts_head = elts_head_next;
497 #ifdef MLX5_PMD_SOFT_COUNTERS
498 /* Increment sent bytes counter. */
499 txq->stats.obytes += sent_size;
503 /* Take a shortcut if nothing must be sent. */
504 if (unlikely(i == 0))
506 #ifdef MLX5_PMD_SOFT_COUNTERS
507 /* Increment sent packets counter. */
508 txq->stats.opackets += i;
510 /* Ring QP doorbell. */
511 err = txq->if_qp->send_flush(txq->qp);
513 /* A nonzero value is not supposed to be returned.
514 * Nothing can be done about it. */
515 DEBUG("%p: send_flush() failed with error %d",
518 txq->elts_head = elts_head;
519 txq->elts_comp += elts_comp;
520 txq->elts_comp_cd = elts_comp_cd;
525 * Translate RX completion flags to packet type.
528 * RX completion flags returned by poll_length_flags().
531 * Packet type for struct rte_mbuf.
533 static inline uint32_t
534 rxq_cq_to_pkt_type(uint32_t flags)
538 if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
541 IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
544 IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
547 IBV_EXP_CQ_RX_IPV4_PACKET,
548 RTE_PTYPE_INNER_L3_IPV4) |
550 IBV_EXP_CQ_RX_IPV6_PACKET,
551 RTE_PTYPE_INNER_L3_IPV6);
555 IBV_EXP_CQ_RX_IPV4_PACKET,
558 IBV_EXP_CQ_RX_IPV6_PACKET,
564 * Translate RX completion flags to offload flags.
567 * Pointer to RX queue structure.
569 * RX completion flags returned by poll_length_flags().
572 * Offload flags (ol_flags) for struct rte_mbuf.
574 static inline uint32_t
575 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
577 uint32_t ol_flags = 0;
582 IBV_EXP_CQ_RX_IP_CSUM_OK,
583 PKT_RX_IP_CKSUM_BAD) |
585 IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
586 PKT_RX_L4_CKSUM_BAD);
588 * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
589 * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
592 if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
595 IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
596 PKT_RX_IP_CKSUM_BAD) |
598 IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
599 PKT_RX_L4_CKSUM_BAD);
604 * DPDK callback for RX with scattered packets support.
607 * Generic pointer to RX queue structure.
609 * Array to store received packets.
611 * Maximum number of packets in array.
614 * Number of packets successfully received (<= pkts_n).
617 mlx5_rx_burst_sp(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
619 struct rxq *rxq = (struct rxq *)dpdk_rxq;
620 struct rxq_elt_sp (*elts)[rxq->elts_n] = rxq->elts.sp;
621 const unsigned int elts_n = rxq->elts_n;
622 unsigned int elts_head = rxq->elts_head;
624 unsigned int pkts_ret = 0;
627 if (unlikely(!rxq->sp))
628 return mlx5_rx_burst(dpdk_rxq, pkts, pkts_n);
629 if (unlikely(elts == NULL)) /* See RTE_DEV_CMD_SET_MTU. */
631 for (i = 0; (i != pkts_n); ++i) {
632 struct rxq_elt_sp *elt = &(*elts)[elts_head];
634 unsigned int pkt_buf_len;
635 struct rte_mbuf *pkt_buf = NULL; /* Buffer returned in pkts. */
636 struct rte_mbuf **pkt_buf_next = &pkt_buf;
637 unsigned int seg_headroom = RTE_PKTMBUF_HEADROOM;
642 assert(elts_head < rxq->elts_n);
643 assert(rxq->elts_head < rxq->elts_n);
644 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
646 if (unlikely(ret < 0)) {
650 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
652 /* ibv_poll_cq() must be used in case of failure. */
653 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
654 if (unlikely(wcs_n == 0))
656 if (unlikely(wcs_n < 0)) {
657 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
662 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
663 /* Whatever, just repost the offending WR. */
664 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
665 " completion status (%d): %s",
666 (void *)rxq, wc.wr_id, wc.status,
667 ibv_wc_status_str(wc.status));
668 #ifdef MLX5_PMD_SOFT_COUNTERS
669 /* Increment dropped packets counter. */
670 ++rxq->stats.idropped;
681 * Replace spent segments with new ones, concatenate and
682 * return them as pkt_buf.
685 struct ibv_sge *sge = &elt->sges[j];
686 struct rte_mbuf *seg = elt->bufs[j];
687 struct rte_mbuf *rep;
688 unsigned int seg_tailroom;
692 * Fetch initial bytes of packet descriptor into a
693 * cacheline while allocating rep.
696 rep = __rte_mbuf_raw_alloc(rxq->mp);
697 if (unlikely(rep == NULL)) {
699 * Unable to allocate a replacement mbuf,
702 DEBUG("rxq=%p: can't allocate a new mbuf",
704 if (pkt_buf != NULL) {
705 *pkt_buf_next = NULL;
706 rte_pktmbuf_free(pkt_buf);
708 /* Increment out of memory counters. */
709 ++rxq->stats.rx_nombuf;
710 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
714 /* Poison user-modifiable fields in rep. */
715 NEXT(rep) = (void *)((uintptr_t)-1);
716 SET_DATA_OFF(rep, 0xdead);
717 DATA_LEN(rep) = 0xd00d;
718 PKT_LEN(rep) = 0xdeadd00d;
723 assert(rep->buf_len == seg->buf_len);
724 assert(rep->buf_len == rxq->mb_len);
725 /* Reconfigure sge to use rep instead of seg. */
726 assert(sge->lkey == rxq->mr->lkey);
727 sge->addr = ((uintptr_t)rep->buf_addr + seg_headroom);
730 /* Update pkt_buf if it's the first segment, or link
731 * seg to the previous one and update pkt_buf_next. */
733 pkt_buf_next = &NEXT(seg);
734 /* Update seg information. */
735 seg_tailroom = (seg->buf_len - seg_headroom);
736 assert(sge->length == seg_tailroom);
737 SET_DATA_OFF(seg, seg_headroom);
738 if (likely(len <= seg_tailroom)) {
743 assert(rte_pktmbuf_headroom(seg) ==
745 assert(rte_pktmbuf_tailroom(seg) ==
746 (seg_tailroom - len));
749 DATA_LEN(seg) = seg_tailroom;
750 PKT_LEN(seg) = seg_tailroom;
752 assert(rte_pktmbuf_headroom(seg) == seg_headroom);
753 assert(rte_pktmbuf_tailroom(seg) == 0);
754 /* Fix len and clear headroom for next segments. */
758 /* Update head and tail segments. */
759 *pkt_buf_next = NULL;
760 assert(pkt_buf != NULL);
762 NB_SEGS(pkt_buf) = j;
763 PORT(pkt_buf) = rxq->port_id;
764 PKT_LEN(pkt_buf) = pkt_buf_len;
765 pkt_buf->packet_type = rxq_cq_to_pkt_type(flags);
766 pkt_buf->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
771 #ifdef MLX5_PMD_SOFT_COUNTERS
772 /* Increment bytes counter. */
773 rxq->stats.ibytes += pkt_buf_len;
776 ret = rxq->if_wq->recv_sg_list(rxq->wq,
780 /* Inability to repost WRs is fatal. */
781 DEBUG("%p: recv_sg_list(): failed (ret=%d)",
786 if (++elts_head >= elts_n)
790 if (unlikely(i == 0))
792 rxq->elts_head = elts_head;
793 #ifdef MLX5_PMD_SOFT_COUNTERS
794 /* Increment packets counter. */
795 rxq->stats.ipackets += pkts_ret;
801 * DPDK callback for RX.
803 * The following function is the same as mlx5_rx_burst_sp(), except it doesn't
804 * manage scattered packets. Improves performance when MRU is lower than the
805 * size of the first segment.
808 * Generic pointer to RX queue structure.
810 * Array to store received packets.
812 * Maximum number of packets in array.
815 * Number of packets successfully received (<= pkts_n).
818 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
820 struct rxq *rxq = (struct rxq *)dpdk_rxq;
821 struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts.no_sp;
822 const unsigned int elts_n = rxq->elts_n;
823 unsigned int elts_head = rxq->elts_head;
824 struct ibv_sge sges[pkts_n];
826 unsigned int pkts_ret = 0;
829 if (unlikely(rxq->sp))
830 return mlx5_rx_burst_sp(dpdk_rxq, pkts, pkts_n);
831 for (i = 0; (i != pkts_n); ++i) {
832 struct rxq_elt *elt = &(*elts)[elts_head];
834 struct rte_mbuf *seg = elt->buf;
835 struct rte_mbuf *rep;
840 assert(elts_head < rxq->elts_n);
841 assert(rxq->elts_head < rxq->elts_n);
843 * Fetch initial bytes of packet descriptor into a
844 * cacheline while allocating rep.
847 rte_prefetch0(&seg->cacheline1);
848 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
850 if (unlikely(ret < 0)) {
854 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
856 /* ibv_poll_cq() must be used in case of failure. */
857 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
858 if (unlikely(wcs_n == 0))
860 if (unlikely(wcs_n < 0)) {
861 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
866 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
867 /* Whatever, just repost the offending WR. */
868 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
869 " completion status (%d): %s",
870 (void *)rxq, wc.wr_id, wc.status,
871 ibv_wc_status_str(wc.status));
872 #ifdef MLX5_PMD_SOFT_COUNTERS
873 /* Increment dropped packets counter. */
874 ++rxq->stats.idropped;
876 /* Add SGE to array for repost. */
885 rep = __rte_mbuf_raw_alloc(rxq->mp);
886 if (unlikely(rep == NULL)) {
888 * Unable to allocate a replacement mbuf,
891 DEBUG("rxq=%p: can't allocate a new mbuf",
893 /* Increment out of memory counters. */
894 ++rxq->stats.rx_nombuf;
895 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
899 /* Reconfigure sge to use rep instead of seg. */
900 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
901 assert(elt->sge.lkey == rxq->mr->lkey);
904 /* Add SGE to array for repost. */
907 /* Update seg information. */
908 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
910 PORT(seg) = rxq->port_id;
914 seg->packet_type = rxq_cq_to_pkt_type(flags);
915 seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
920 #ifdef MLX5_PMD_SOFT_COUNTERS
921 /* Increment bytes counter. */
922 rxq->stats.ibytes += len;
925 if (++elts_head >= elts_n)
929 if (unlikely(i == 0))
933 DEBUG("%p: reposting %u WRs", (void *)rxq, i);
935 ret = rxq->if_wq->recv_burst(rxq->wq, sges, i);
937 /* Inability to repost WRs is fatal. */
938 DEBUG("%p: recv_burst(): failed (ret=%d)",
943 rxq->elts_head = elts_head;
944 #ifdef MLX5_PMD_SOFT_COUNTERS
945 /* Increment packets counter. */
946 rxq->stats.ipackets += pkts_ret;
952 * Dummy DPDK callback for TX.
954 * This function is used to temporarily replace the real callback during
955 * unsafe control operations on the queue, or in case of error.
958 * Generic pointer to TX queue structure.
960 * Packets to transmit.
962 * Number of packets in array.
965 * Number of packets successfully transmitted (<= pkts_n).
968 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
977 * Dummy DPDK callback for RX.
979 * This function is used to temporarily replace the real callback during
980 * unsafe control operations on the queue, or in case of error.
983 * Generic pointer to RX queue structure.
985 * Array to store received packets.
987 * Maximum number of packets in array.
990 * Number of packets successfully received (<= pkts_n).
993 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)