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.
41 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
43 #pragma GCC diagnostic ignored "-pedantic"
45 #include <infiniband/verbs.h>
47 #pragma GCC diagnostic error "-pedantic"
50 /* DPDK headers don't like -pedantic. */
52 #pragma GCC diagnostic ignored "-pedantic"
55 #include <rte_mempool.h>
56 #include <rte_prefetch.h>
57 #include <rte_common.h>
58 #include <rte_branch_prediction.h>
60 #pragma GCC diagnostic error "-pedantic"
64 #include "mlx5_autoconf.h"
65 #include "mlx5_utils.h"
66 #include "mlx5_rxtx.h"
67 #include "mlx5_defs.h"
70 * Manage TX completions.
72 * When sending a burst, mlx5_tx_burst() posts several WRs.
73 * To improve performance, a completion event is only required once every
74 * MLX5_PMD_TX_PER_COMP_REQ sends. Doing so discards completion information
75 * for other WRs, but this information would not be used anyway.
78 * Pointer to TX queue structure.
81 * 0 on success, -1 on failure.
84 txq_complete(struct txq *txq)
86 unsigned int elts_comp = txq->elts_comp;
87 unsigned int elts_tail = txq->elts_tail;
88 const unsigned int elts_n = txq->elts_n;
91 if (unlikely(elts_comp == 0))
94 DEBUG("%p: processing %u work requests completions",
95 (void *)txq, elts_comp);
97 wcs_n = txq->if_cq->poll_cnt(txq->cq, elts_comp);
98 if (unlikely(wcs_n == 0))
100 if (unlikely(wcs_n < 0)) {
101 DEBUG("%p: ibv_poll_cq() failed (wcs_n=%d)",
106 assert(elts_comp <= txq->elts_comp);
108 * Assume WC status is successful as nothing can be done about it
111 elts_tail += wcs_n * txq->elts_comp_cd_init;
112 if (elts_tail >= elts_n)
114 txq->elts_tail = elts_tail;
115 txq->elts_comp = elts_comp;
120 * Get Memory Region (MR) <-> Memory Pool (MP) association from txq->mp2mr[].
121 * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
122 * remove an entry first.
125 * Pointer to TX queue structure.
127 * Memory Pool for which a Memory Region lkey must be returned.
130 * mr->lkey on success, (uint32_t)-1 on failure.
133 txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
138 for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
139 if (unlikely(txq->mp2mr[i].mp == NULL)) {
140 /* Unknown MP, add a new MR for it. */
143 if (txq->mp2mr[i].mp == mp) {
144 assert(txq->mp2mr[i].lkey != (uint32_t)-1);
145 assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey);
146 return txq->mp2mr[i].lkey;
149 /* Add a new entry, register MR first. */
150 DEBUG("%p: discovered new memory pool %p", (void *)txq, (void *)mp);
151 mr = ibv_reg_mr(txq->priv->pd,
152 (void *)mp->elt_va_start,
153 (mp->elt_va_end - mp->elt_va_start),
154 (IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE));
155 if (unlikely(mr == NULL)) {
156 DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.",
160 if (unlikely(i == RTE_DIM(txq->mp2mr))) {
161 /* Table is full, remove oldest entry. */
162 DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
165 claim_zero(ibv_dereg_mr(txq->mp2mr[i].mr));
166 memmove(&txq->mp2mr[0], &txq->mp2mr[1],
167 (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0])));
169 /* Store the new entry. */
170 txq->mp2mr[i].mp = mp;
171 txq->mp2mr[i].mr = mr;
172 txq->mp2mr[i].lkey = mr->lkey;
173 DEBUG("%p: new MR lkey for MP %p: 0x%08" PRIu32,
174 (void *)txq, (void *)mp, txq->mp2mr[i].lkey);
175 return txq->mp2mr[i].lkey;
178 #if MLX5_PMD_SGE_WR_N > 1
181 * Copy scattered mbuf contents to a single linear buffer.
184 * Linear output buffer.
186 * Scattered input buffer.
189 * Number of bytes copied to the output buffer or 0 if not large enough.
192 linearize_mbuf(linear_t *linear, struct rte_mbuf *buf)
194 unsigned int size = 0;
198 unsigned int len = DATA_LEN(buf);
202 if (unlikely(size > sizeof(*linear)))
204 memcpy(&(*linear)[offset],
205 rte_pktmbuf_mtod(buf, uint8_t *),
208 } while (buf != NULL);
213 * Handle scattered buffers for mlx5_tx_burst().
216 * TX queue structure.
218 * Number of segments in buf.
220 * TX queue element to fill.
224 * Index of the linear buffer to use if necessary (normally txq->elts_head).
226 * Array filled with SGEs on success.
229 * A structure containing the processed packet size in bytes and the
230 * number of SGEs. Both fields are set to (unsigned int)-1 in case of
233 static struct tx_burst_sg_ret {
237 tx_burst_sg(struct txq *txq, unsigned int segs, struct txq_elt *elt,
238 struct rte_mbuf *buf, unsigned int elts_head,
239 struct ibv_sge (*sges)[MLX5_PMD_SGE_WR_N])
241 unsigned int sent_size = 0;
245 /* When there are too many segments, extra segments are
246 * linearized in the last SGE. */
247 if (unlikely(segs > RTE_DIM(*sges))) {
248 segs = (RTE_DIM(*sges) - 1);
251 /* Update element. */
253 /* Register segments as SGEs. */
254 for (j = 0; (j != segs); ++j) {
255 struct ibv_sge *sge = &(*sges)[j];
258 /* Retrieve Memory Region key for this memory pool. */
259 lkey = txq_mp2mr(txq, buf->pool);
260 if (unlikely(lkey == (uint32_t)-1)) {
261 /* MR does not exist. */
262 DEBUG("%p: unable to get MP <-> MR association",
264 /* Clean up TX element. */
269 sge->addr = rte_pktmbuf_mtod(buf, uintptr_t);
271 rte_prefetch0((volatile void *)
272 (uintptr_t)sge->addr);
273 sge->length = DATA_LEN(buf);
275 sent_size += sge->length;
278 /* If buf is not NULL here and is not going to be linearized,
279 * nb_segs is not valid. */
281 assert((buf == NULL) || (linearize));
282 /* Linearize extra segments. */
284 struct ibv_sge *sge = &(*sges)[segs];
285 linear_t *linear = &(*txq->elts_linear)[elts_head];
286 unsigned int size = linearize_mbuf(linear, buf);
288 assert(segs == (RTE_DIM(*sges) - 1));
290 /* Invalid packet. */
291 DEBUG("%p: packet too large to be linearized.",
293 /* Clean up TX element. */
297 /* If MLX5_PMD_SGE_WR_N is 1, free mbuf immediately. */
298 if (RTE_DIM(*sges) == 1) {
300 struct rte_mbuf *next = NEXT(buf);
302 rte_pktmbuf_free_seg(buf);
304 } while (buf != NULL);
308 sge->addr = (uintptr_t)&(*linear)[0];
310 sge->lkey = txq->mr_linear->lkey;
313 return (struct tx_burst_sg_ret){
318 return (struct tx_burst_sg_ret){
324 #endif /* MLX5_PMD_SGE_WR_N > 1 */
327 * DPDK callback for TX.
330 * Generic pointer to TX queue structure.
332 * Packets to transmit.
334 * Number of packets in array.
337 * Number of packets successfully transmitted (<= pkts_n).
340 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
342 struct txq *txq = (struct txq *)dpdk_txq;
343 unsigned int elts_head = txq->elts_head;
344 const unsigned int elts_tail = txq->elts_tail;
345 const unsigned int elts_n = txq->elts_n;
346 unsigned int elts_comp_cd = txq->elts_comp_cd;
347 unsigned int elts_comp = 0;
352 assert(elts_comp_cd != 0);
354 max = (elts_n - (elts_head - elts_tail));
358 assert(max <= elts_n);
359 /* Always leave one free entry in the ring. */
365 for (i = 0; (i != max); ++i) {
366 struct rte_mbuf *buf = pkts[i];
367 unsigned int elts_head_next =
368 (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
369 struct txq_elt *elt_next = &(*txq->elts)[elts_head_next];
370 struct txq_elt *elt = &(*txq->elts)[elts_head];
371 unsigned int segs = NB_SEGS(buf);
372 #ifdef MLX5_PMD_SOFT_COUNTERS
373 unsigned int sent_size = 0;
375 uint32_t send_flags = 0;
377 /* Clean up old buffer. */
378 if (likely(elt->buf != NULL)) {
379 struct rte_mbuf *tmp = elt->buf;
381 /* Faster than rte_pktmbuf_free(). */
383 struct rte_mbuf *next = NEXT(tmp);
385 rte_pktmbuf_free_seg(tmp);
387 } while (tmp != NULL);
389 /* Request TX completion. */
390 if (unlikely(--elts_comp_cd == 0)) {
391 elts_comp_cd = txq->elts_comp_cd_init;
393 send_flags |= IBV_EXP_QP_BURST_SIGNALED;
395 /* Should we enable HW CKSUM offload */
397 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
398 send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
399 /* HW does not support checksum offloads at arbitrary
400 * offsets but automatically recognizes the packet
401 * type. For inner L3/L4 checksums, only VXLAN (UDP)
402 * tunnels are currently supported. */
403 if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
404 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
406 if (likely(segs == 1)) {
411 /* Retrieve buffer information. */
412 addr = rte_pktmbuf_mtod(buf, uintptr_t);
413 length = DATA_LEN(buf);
414 /* Retrieve Memory Region key for this memory pool. */
415 lkey = txq_mp2mr(txq, buf->pool);
416 if (unlikely(lkey == (uint32_t)-1)) {
417 /* MR does not exist. */
418 DEBUG("%p: unable to get MP <-> MR"
419 " association", (void *)txq);
420 /* Clean up TX element. */
424 /* Update element. */
427 rte_prefetch0((volatile void *)
429 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
430 /* Put packet into send queue. */
431 #if MLX5_PMD_MAX_INLINE > 0
432 if (length <= txq->max_inline)
433 err = txq->if_qp->send_pending_inline
440 err = txq->if_qp->send_pending
448 #ifdef MLX5_PMD_SOFT_COUNTERS
452 #if MLX5_PMD_SGE_WR_N > 1
453 struct ibv_sge sges[MLX5_PMD_SGE_WR_N];
454 struct tx_burst_sg_ret ret;
456 ret = tx_burst_sg(txq, segs, elt, buf, elts_head,
458 if (ret.length == (unsigned int)-1)
460 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
461 /* Put SG list into send queue. */
462 err = txq->if_qp->send_pending_sg_list
469 #ifdef MLX5_PMD_SOFT_COUNTERS
470 sent_size += ret.length;
472 #else /* MLX5_PMD_SGE_WR_N > 1 */
473 DEBUG("%p: TX scattered buffers support not"
474 " compiled in", (void *)txq);
476 #endif /* MLX5_PMD_SGE_WR_N > 1 */
478 elts_head = elts_head_next;
479 #ifdef MLX5_PMD_SOFT_COUNTERS
480 /* Increment sent bytes counter. */
481 txq->stats.obytes += sent_size;
485 /* Take a shortcut if nothing must be sent. */
486 if (unlikely(i == 0))
488 #ifdef MLX5_PMD_SOFT_COUNTERS
489 /* Increment sent packets counter. */
490 txq->stats.opackets += i;
492 /* Ring QP doorbell. */
493 err = txq->if_qp->send_flush(txq->qp);
495 /* A nonzero value is not supposed to be returned.
496 * Nothing can be done about it. */
497 DEBUG("%p: send_flush() failed with error %d",
500 txq->elts_head = elts_head;
501 txq->elts_comp += elts_comp;
502 txq->elts_comp_cd = elts_comp_cd;
507 * Translate RX completion flags to packet type.
510 * RX completion flags returned by poll_length_flags().
513 * Packet type for struct rte_mbuf.
515 static inline uint32_t
516 rxq_cq_to_pkt_type(uint32_t flags)
520 if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
523 IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
526 IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
529 IBV_EXP_CQ_RX_IPV4_PACKET,
530 RTE_PTYPE_INNER_L3_IPV4) |
532 IBV_EXP_CQ_RX_IPV6_PACKET,
533 RTE_PTYPE_INNER_L3_IPV6);
537 IBV_EXP_CQ_RX_IPV4_PACKET,
540 IBV_EXP_CQ_RX_IPV6_PACKET,
546 * Translate RX completion flags to offload flags.
549 * Pointer to RX queue structure.
551 * RX completion flags returned by poll_length_flags().
554 * Offload flags (ol_flags) for struct rte_mbuf.
556 static inline uint32_t
557 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
559 uint32_t ol_flags = 0;
564 IBV_EXP_CQ_RX_IP_CSUM_OK,
565 PKT_RX_IP_CKSUM_BAD) |
567 IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
568 PKT_RX_L4_CKSUM_BAD);
570 * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
571 * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
574 if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
577 IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
578 PKT_RX_IP_CKSUM_BAD) |
580 IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
581 PKT_RX_L4_CKSUM_BAD);
586 * DPDK callback for RX with scattered packets support.
589 * Generic pointer to RX queue structure.
591 * Array to store received packets.
593 * Maximum number of packets in array.
596 * Number of packets successfully received (<= pkts_n).
599 mlx5_rx_burst_sp(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
601 struct rxq *rxq = (struct rxq *)dpdk_rxq;
602 struct rxq_elt_sp (*elts)[rxq->elts_n] = rxq->elts.sp;
603 const unsigned int elts_n = rxq->elts_n;
604 unsigned int elts_head = rxq->elts_head;
606 unsigned int pkts_ret = 0;
609 if (unlikely(!rxq->sp))
610 return mlx5_rx_burst(dpdk_rxq, pkts, pkts_n);
611 if (unlikely(elts == NULL)) /* See RTE_DEV_CMD_SET_MTU. */
613 for (i = 0; (i != pkts_n); ++i) {
614 struct rxq_elt_sp *elt = &(*elts)[elts_head];
616 unsigned int pkt_buf_len;
617 struct rte_mbuf *pkt_buf = NULL; /* Buffer returned in pkts. */
618 struct rte_mbuf **pkt_buf_next = &pkt_buf;
619 unsigned int seg_headroom = RTE_PKTMBUF_HEADROOM;
624 assert(elts_head < rxq->elts_n);
625 assert(rxq->elts_head < rxq->elts_n);
626 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
628 if (unlikely(ret < 0)) {
632 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
634 /* ibv_poll_cq() must be used in case of failure. */
635 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
636 if (unlikely(wcs_n == 0))
638 if (unlikely(wcs_n < 0)) {
639 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
644 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
645 /* Whatever, just repost the offending WR. */
646 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
647 " completion status (%d): %s",
648 (void *)rxq, wc.wr_id, wc.status,
649 ibv_wc_status_str(wc.status));
650 #ifdef MLX5_PMD_SOFT_COUNTERS
651 /* Increment dropped packets counter. */
652 ++rxq->stats.idropped;
663 * Replace spent segments with new ones, concatenate and
664 * return them as pkt_buf.
667 struct ibv_sge *sge = &elt->sges[j];
668 struct rte_mbuf *seg = elt->bufs[j];
669 struct rte_mbuf *rep;
670 unsigned int seg_tailroom;
674 * Fetch initial bytes of packet descriptor into a
675 * cacheline while allocating rep.
678 rep = __rte_mbuf_raw_alloc(rxq->mp);
679 if (unlikely(rep == NULL)) {
681 * Unable to allocate a replacement mbuf,
684 DEBUG("rxq=%p: can't allocate a new mbuf",
686 if (pkt_buf != NULL) {
687 *pkt_buf_next = NULL;
688 rte_pktmbuf_free(pkt_buf);
690 /* Increment out of memory counters. */
691 ++rxq->stats.rx_nombuf;
692 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
696 /* Poison user-modifiable fields in rep. */
697 NEXT(rep) = (void *)((uintptr_t)-1);
698 SET_DATA_OFF(rep, 0xdead);
699 DATA_LEN(rep) = 0xd00d;
700 PKT_LEN(rep) = 0xdeadd00d;
705 assert(rep->buf_len == seg->buf_len);
706 assert(rep->buf_len == rxq->mb_len);
707 /* Reconfigure sge to use rep instead of seg. */
708 assert(sge->lkey == rxq->mr->lkey);
709 sge->addr = ((uintptr_t)rep->buf_addr + seg_headroom);
712 /* Update pkt_buf if it's the first segment, or link
713 * seg to the previous one and update pkt_buf_next. */
715 pkt_buf_next = &NEXT(seg);
716 /* Update seg information. */
717 seg_tailroom = (seg->buf_len - seg_headroom);
718 assert(sge->length == seg_tailroom);
719 SET_DATA_OFF(seg, seg_headroom);
720 if (likely(len <= seg_tailroom)) {
725 assert(rte_pktmbuf_headroom(seg) ==
727 assert(rte_pktmbuf_tailroom(seg) ==
728 (seg_tailroom - len));
731 DATA_LEN(seg) = seg_tailroom;
732 PKT_LEN(seg) = seg_tailroom;
734 assert(rte_pktmbuf_headroom(seg) == seg_headroom);
735 assert(rte_pktmbuf_tailroom(seg) == 0);
736 /* Fix len and clear headroom for next segments. */
740 /* Update head and tail segments. */
741 *pkt_buf_next = NULL;
742 assert(pkt_buf != NULL);
744 NB_SEGS(pkt_buf) = j;
745 PORT(pkt_buf) = rxq->port_id;
746 PKT_LEN(pkt_buf) = pkt_buf_len;
747 pkt_buf->packet_type = rxq_cq_to_pkt_type(flags);
748 pkt_buf->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
753 #ifdef MLX5_PMD_SOFT_COUNTERS
754 /* Increment bytes counter. */
755 rxq->stats.ibytes += pkt_buf_len;
758 #ifdef HAVE_EXP_QP_BURST_RECV_SG_LIST
759 ret = rxq->if_qp->recv_sg_list(rxq->qp,
762 #else /* HAVE_EXP_QP_BURST_RECV_SG_LIST */
765 #endif /* HAVE_EXP_QP_BURST_RECV_SG_LIST */
767 /* Inability to repost WRs is fatal. */
768 DEBUG("%p: recv_sg_list(): failed (ret=%d)",
773 if (++elts_head >= elts_n)
777 if (unlikely(i == 0))
779 rxq->elts_head = elts_head;
780 #ifdef MLX5_PMD_SOFT_COUNTERS
781 /* Increment packets counter. */
782 rxq->stats.ipackets += pkts_ret;
788 * DPDK callback for RX.
790 * The following function is the same as mlx5_rx_burst_sp(), except it doesn't
791 * manage scattered packets. Improves performance when MRU is lower than the
792 * size of the first segment.
795 * Generic pointer to RX queue structure.
797 * Array to store received packets.
799 * Maximum number of packets in array.
802 * Number of packets successfully received (<= pkts_n).
805 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
807 struct rxq *rxq = (struct rxq *)dpdk_rxq;
808 struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts.no_sp;
809 const unsigned int elts_n = rxq->elts_n;
810 unsigned int elts_head = rxq->elts_head;
811 struct ibv_sge sges[pkts_n];
813 unsigned int pkts_ret = 0;
816 if (unlikely(rxq->sp))
817 return mlx5_rx_burst_sp(dpdk_rxq, pkts, pkts_n);
818 for (i = 0; (i != pkts_n); ++i) {
819 struct rxq_elt *elt = &(*elts)[elts_head];
821 struct rte_mbuf *seg = elt->buf;
822 struct rte_mbuf *rep;
827 assert(elts_head < rxq->elts_n);
828 assert(rxq->elts_head < rxq->elts_n);
830 * Fetch initial bytes of packet descriptor into a
831 * cacheline while allocating rep.
834 rte_prefetch0(&seg->cacheline1);
835 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
837 if (unlikely(ret < 0)) {
841 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
843 /* ibv_poll_cq() must be used in case of failure. */
844 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
845 if (unlikely(wcs_n == 0))
847 if (unlikely(wcs_n < 0)) {
848 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
853 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
854 /* Whatever, just repost the offending WR. */
855 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
856 " completion status (%d): %s",
857 (void *)rxq, wc.wr_id, wc.status,
858 ibv_wc_status_str(wc.status));
859 #ifdef MLX5_PMD_SOFT_COUNTERS
860 /* Increment dropped packets counter. */
861 ++rxq->stats.idropped;
863 /* Add SGE to array for repost. */
872 rep = __rte_mbuf_raw_alloc(rxq->mp);
873 if (unlikely(rep == NULL)) {
875 * Unable to allocate a replacement mbuf,
878 DEBUG("rxq=%p: can't allocate a new mbuf",
880 /* Increment out of memory counters. */
881 ++rxq->stats.rx_nombuf;
882 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
886 /* Reconfigure sge to use rep instead of seg. */
887 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
888 assert(elt->sge.lkey == rxq->mr->lkey);
891 /* Add SGE to array for repost. */
894 /* Update seg information. */
895 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
897 PORT(seg) = rxq->port_id;
901 seg->packet_type = rxq_cq_to_pkt_type(flags);
902 seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
907 #ifdef MLX5_PMD_SOFT_COUNTERS
908 /* Increment bytes counter. */
909 rxq->stats.ibytes += len;
912 if (++elts_head >= elts_n)
916 if (unlikely(i == 0))
920 DEBUG("%p: reposting %u WRs", (void *)rxq, i);
922 ret = rxq->if_qp->recv_burst(rxq->qp, sges, i);
924 /* Inability to repost WRs is fatal. */
925 DEBUG("%p: recv_burst(): failed (ret=%d)",
930 rxq->elts_head = elts_head;
931 #ifdef MLX5_PMD_SOFT_COUNTERS
932 /* Increment packets counter. */
933 rxq->stats.ipackets += pkts_ret;
939 * Dummy DPDK callback for TX.
941 * This function is used to temporarily replace the real callback during
942 * unsafe control operations on the queue, or in case of error.
945 * Generic pointer to TX queue structure.
947 * Packets to transmit.
949 * Number of packets in array.
952 * Number of packets successfully transmitted (<= pkts_n).
955 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
964 * Dummy DPDK callback for RX.
966 * This function is used to temporarily replace the real callback during
967 * unsafe control operations on the queue, or in case of error.
970 * Generic pointer to RX queue structure.
972 * Array to store received packets.
974 * Maximum number of packets in array.
977 * Number of packets successfully received (<= pkts_n).
980 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)