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;
329 return (struct tx_burst_sg_ret){
334 return (struct tx_burst_sg_ret){
340 #endif /* MLX5_PMD_SGE_WR_N > 1 */
343 * DPDK callback for TX.
346 * Generic pointer to TX queue structure.
348 * Packets to transmit.
350 * Number of packets in array.
353 * Number of packets successfully transmitted (<= pkts_n).
356 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
358 struct txq *txq = (struct txq *)dpdk_txq;
359 unsigned int elts_head = txq->elts_head;
360 const unsigned int elts_tail = txq->elts_tail;
361 const unsigned int elts_n = txq->elts_n;
362 unsigned int elts_comp_cd = txq->elts_comp_cd;
363 unsigned int elts_comp = 0;
368 assert(elts_comp_cd != 0);
370 max = (elts_n - (elts_head - elts_tail));
374 assert(max <= elts_n);
375 /* Always leave one free entry in the ring. */
381 for (i = 0; (i != max); ++i) {
382 struct rte_mbuf *buf = pkts[i];
383 unsigned int elts_head_next =
384 (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
385 struct txq_elt *elt_next = &(*txq->elts)[elts_head_next];
386 struct txq_elt *elt = &(*txq->elts)[elts_head];
387 unsigned int segs = NB_SEGS(buf);
388 #ifdef MLX5_PMD_SOFT_COUNTERS
389 unsigned int sent_size = 0;
391 uint32_t send_flags = 0;
393 /* Clean up old buffer. */
394 if (likely(elt->buf != NULL)) {
395 struct rte_mbuf *tmp = elt->buf;
397 /* Faster than rte_pktmbuf_free(). */
399 struct rte_mbuf *next = NEXT(tmp);
401 rte_pktmbuf_free_seg(tmp);
403 } while (tmp != NULL);
405 /* Request TX completion. */
406 if (unlikely(--elts_comp_cd == 0)) {
407 elts_comp_cd = txq->elts_comp_cd_init;
409 send_flags |= IBV_EXP_QP_BURST_SIGNALED;
411 /* Should we enable HW CKSUM offload */
413 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
414 send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
415 /* HW does not support checksum offloads at arbitrary
416 * offsets but automatically recognizes the packet
417 * type. For inner L3/L4 checksums, only VXLAN (UDP)
418 * tunnels are currently supported. */
419 if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
420 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
422 if (likely(segs == 1)) {
427 /* Retrieve buffer information. */
428 addr = rte_pktmbuf_mtod(buf, uintptr_t);
429 length = DATA_LEN(buf);
430 /* Retrieve Memory Region key for this memory pool. */
431 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
432 if (unlikely(lkey == (uint32_t)-1)) {
433 /* MR does not exist. */
434 DEBUG("%p: unable to get MP <-> MR"
435 " association", (void *)txq);
436 /* Clean up TX element. */
440 /* Update element. */
443 rte_prefetch0((volatile void *)
445 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
446 /* Put packet into send queue. */
447 #if MLX5_PMD_MAX_INLINE > 0
448 if (length <= txq->max_inline)
449 err = txq->if_qp->send_pending_inline
456 err = txq->if_qp->send_pending
464 #ifdef MLX5_PMD_SOFT_COUNTERS
468 #if MLX5_PMD_SGE_WR_N > 1
469 struct ibv_sge sges[MLX5_PMD_SGE_WR_N];
470 struct tx_burst_sg_ret ret;
472 ret = tx_burst_sg(txq, segs, elt, buf, elts_head,
474 if (ret.length == (unsigned int)-1)
476 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
477 /* Put SG list into send queue. */
478 err = txq->if_qp->send_pending_sg_list
485 #ifdef MLX5_PMD_SOFT_COUNTERS
486 sent_size += ret.length;
488 #else /* MLX5_PMD_SGE_WR_N > 1 */
489 DEBUG("%p: TX scattered buffers support not"
490 " compiled in", (void *)txq);
492 #endif /* MLX5_PMD_SGE_WR_N > 1 */
494 elts_head = elts_head_next;
495 #ifdef MLX5_PMD_SOFT_COUNTERS
496 /* Increment sent bytes counter. */
497 txq->stats.obytes += sent_size;
501 /* Take a shortcut if nothing must be sent. */
502 if (unlikely(i == 0))
504 #ifdef MLX5_PMD_SOFT_COUNTERS
505 /* Increment sent packets counter. */
506 txq->stats.opackets += i;
508 /* Ring QP doorbell. */
509 err = txq->if_qp->send_flush(txq->qp);
511 /* A nonzero value is not supposed to be returned.
512 * Nothing can be done about it. */
513 DEBUG("%p: send_flush() failed with error %d",
516 txq->elts_head = elts_head;
517 txq->elts_comp += elts_comp;
518 txq->elts_comp_cd = elts_comp_cd;
523 * Translate RX completion flags to packet type.
526 * RX completion flags returned by poll_length_flags().
529 * Packet type for struct rte_mbuf.
531 static inline uint32_t
532 rxq_cq_to_pkt_type(uint32_t flags)
536 if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
539 IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
542 IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
545 IBV_EXP_CQ_RX_IPV4_PACKET,
546 RTE_PTYPE_INNER_L3_IPV4) |
548 IBV_EXP_CQ_RX_IPV6_PACKET,
549 RTE_PTYPE_INNER_L3_IPV6);
553 IBV_EXP_CQ_RX_IPV4_PACKET,
556 IBV_EXP_CQ_RX_IPV6_PACKET,
562 * Translate RX completion flags to offload flags.
565 * Pointer to RX queue structure.
567 * RX completion flags returned by poll_length_flags().
570 * Offload flags (ol_flags) for struct rte_mbuf.
572 static inline uint32_t
573 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
575 uint32_t ol_flags = 0;
580 IBV_EXP_CQ_RX_IP_CSUM_OK,
581 PKT_RX_IP_CKSUM_BAD) |
583 IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
584 PKT_RX_L4_CKSUM_BAD);
586 * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
587 * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
590 if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
593 IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
594 PKT_RX_IP_CKSUM_BAD) |
596 IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
597 PKT_RX_L4_CKSUM_BAD);
602 * DPDK callback for RX with scattered packets support.
605 * Generic pointer to RX queue structure.
607 * Array to store received packets.
609 * Maximum number of packets in array.
612 * Number of packets successfully received (<= pkts_n).
615 mlx5_rx_burst_sp(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
617 struct rxq *rxq = (struct rxq *)dpdk_rxq;
618 struct rxq_elt_sp (*elts)[rxq->elts_n] = rxq->elts.sp;
619 const unsigned int elts_n = rxq->elts_n;
620 unsigned int elts_head = rxq->elts_head;
622 unsigned int pkts_ret = 0;
625 if (unlikely(!rxq->sp))
626 return mlx5_rx_burst(dpdk_rxq, pkts, pkts_n);
627 if (unlikely(elts == NULL)) /* See RTE_DEV_CMD_SET_MTU. */
629 for (i = 0; (i != pkts_n); ++i) {
630 struct rxq_elt_sp *elt = &(*elts)[elts_head];
632 unsigned int pkt_buf_len;
633 struct rte_mbuf *pkt_buf = NULL; /* Buffer returned in pkts. */
634 struct rte_mbuf **pkt_buf_next = &pkt_buf;
635 unsigned int seg_headroom = RTE_PKTMBUF_HEADROOM;
640 assert(elts_head < rxq->elts_n);
641 assert(rxq->elts_head < rxq->elts_n);
642 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
644 if (unlikely(ret < 0)) {
648 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
650 /* ibv_poll_cq() must be used in case of failure. */
651 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
652 if (unlikely(wcs_n == 0))
654 if (unlikely(wcs_n < 0)) {
655 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
660 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
661 /* Whatever, just repost the offending WR. */
662 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
663 " completion status (%d): %s",
664 (void *)rxq, wc.wr_id, wc.status,
665 ibv_wc_status_str(wc.status));
666 #ifdef MLX5_PMD_SOFT_COUNTERS
667 /* Increment dropped packets counter. */
668 ++rxq->stats.idropped;
679 * Replace spent segments with new ones, concatenate and
680 * return them as pkt_buf.
683 struct ibv_sge *sge = &elt->sges[j];
684 struct rte_mbuf *seg = elt->bufs[j];
685 struct rte_mbuf *rep;
686 unsigned int seg_tailroom;
690 * Fetch initial bytes of packet descriptor into a
691 * cacheline while allocating rep.
694 rep = __rte_mbuf_raw_alloc(rxq->mp);
695 if (unlikely(rep == NULL)) {
697 * Unable to allocate a replacement mbuf,
700 DEBUG("rxq=%p: can't allocate a new mbuf",
702 if (pkt_buf != NULL) {
703 *pkt_buf_next = NULL;
704 rte_pktmbuf_free(pkt_buf);
706 /* Increment out of memory counters. */
707 ++rxq->stats.rx_nombuf;
708 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
712 /* Poison user-modifiable fields in rep. */
713 NEXT(rep) = (void *)((uintptr_t)-1);
714 SET_DATA_OFF(rep, 0xdead);
715 DATA_LEN(rep) = 0xd00d;
716 PKT_LEN(rep) = 0xdeadd00d;
721 assert(rep->buf_len == seg->buf_len);
722 assert(rep->buf_len == rxq->mb_len);
723 /* Reconfigure sge to use rep instead of seg. */
724 assert(sge->lkey == rxq->mr->lkey);
725 sge->addr = ((uintptr_t)rep->buf_addr + seg_headroom);
728 /* Update pkt_buf if it's the first segment, or link
729 * seg to the previous one and update pkt_buf_next. */
731 pkt_buf_next = &NEXT(seg);
732 /* Update seg information. */
733 seg_tailroom = (seg->buf_len - seg_headroom);
734 assert(sge->length == seg_tailroom);
735 SET_DATA_OFF(seg, seg_headroom);
736 if (likely(len <= seg_tailroom)) {
741 assert(rte_pktmbuf_headroom(seg) ==
743 assert(rte_pktmbuf_tailroom(seg) ==
744 (seg_tailroom - len));
747 DATA_LEN(seg) = seg_tailroom;
748 PKT_LEN(seg) = seg_tailroom;
750 assert(rte_pktmbuf_headroom(seg) == seg_headroom);
751 assert(rte_pktmbuf_tailroom(seg) == 0);
752 /* Fix len and clear headroom for next segments. */
756 /* Update head and tail segments. */
757 *pkt_buf_next = NULL;
758 assert(pkt_buf != NULL);
760 NB_SEGS(pkt_buf) = j;
761 PORT(pkt_buf) = rxq->port_id;
762 PKT_LEN(pkt_buf) = pkt_buf_len;
763 pkt_buf->packet_type = rxq_cq_to_pkt_type(flags);
764 pkt_buf->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
769 #ifdef MLX5_PMD_SOFT_COUNTERS
770 /* Increment bytes counter. */
771 rxq->stats.ibytes += pkt_buf_len;
774 ret = rxq->if_wq->recv_sg_list(rxq->wq,
778 /* Inability to repost WRs is fatal. */
779 DEBUG("%p: recv_sg_list(): failed (ret=%d)",
784 if (++elts_head >= elts_n)
788 if (unlikely(i == 0))
790 rxq->elts_head = elts_head;
791 #ifdef MLX5_PMD_SOFT_COUNTERS
792 /* Increment packets counter. */
793 rxq->stats.ipackets += pkts_ret;
799 * DPDK callback for RX.
801 * The following function is the same as mlx5_rx_burst_sp(), except it doesn't
802 * manage scattered packets. Improves performance when MRU is lower than the
803 * size of the first segment.
806 * Generic pointer to RX queue structure.
808 * Array to store received packets.
810 * Maximum number of packets in array.
813 * Number of packets successfully received (<= pkts_n).
816 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
818 struct rxq *rxq = (struct rxq *)dpdk_rxq;
819 struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts.no_sp;
820 const unsigned int elts_n = rxq->elts_n;
821 unsigned int elts_head = rxq->elts_head;
822 struct ibv_sge sges[pkts_n];
824 unsigned int pkts_ret = 0;
827 if (unlikely(rxq->sp))
828 return mlx5_rx_burst_sp(dpdk_rxq, pkts, pkts_n);
829 for (i = 0; (i != pkts_n); ++i) {
830 struct rxq_elt *elt = &(*elts)[elts_head];
832 struct rte_mbuf *seg = elt->buf;
833 struct rte_mbuf *rep;
838 assert(elts_head < rxq->elts_n);
839 assert(rxq->elts_head < rxq->elts_n);
841 * Fetch initial bytes of packet descriptor into a
842 * cacheline while allocating rep.
845 rte_prefetch0(&seg->cacheline1);
846 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
848 if (unlikely(ret < 0)) {
852 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
854 /* ibv_poll_cq() must be used in case of failure. */
855 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
856 if (unlikely(wcs_n == 0))
858 if (unlikely(wcs_n < 0)) {
859 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
864 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
865 /* Whatever, just repost the offending WR. */
866 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
867 " completion status (%d): %s",
868 (void *)rxq, wc.wr_id, wc.status,
869 ibv_wc_status_str(wc.status));
870 #ifdef MLX5_PMD_SOFT_COUNTERS
871 /* Increment dropped packets counter. */
872 ++rxq->stats.idropped;
874 /* Add SGE to array for repost. */
883 rep = __rte_mbuf_raw_alloc(rxq->mp);
884 if (unlikely(rep == NULL)) {
886 * Unable to allocate a replacement mbuf,
889 DEBUG("rxq=%p: can't allocate a new mbuf",
891 /* Increment out of memory counters. */
892 ++rxq->stats.rx_nombuf;
893 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
897 /* Reconfigure sge to use rep instead of seg. */
898 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
899 assert(elt->sge.lkey == rxq->mr->lkey);
902 /* Add SGE to array for repost. */
905 /* Update seg information. */
906 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
908 PORT(seg) = rxq->port_id;
912 seg->packet_type = rxq_cq_to_pkt_type(flags);
913 seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
918 #ifdef MLX5_PMD_SOFT_COUNTERS
919 /* Increment bytes counter. */
920 rxq->stats.ibytes += len;
923 if (++elts_head >= elts_n)
927 if (unlikely(i == 0))
931 DEBUG("%p: reposting %u WRs", (void *)rxq, i);
933 ret = rxq->if_wq->recv_burst(rxq->wq, sges, i);
935 /* Inability to repost WRs is fatal. */
936 DEBUG("%p: recv_burst(): failed (ret=%d)",
941 rxq->elts_head = elts_head;
942 #ifdef MLX5_PMD_SOFT_COUNTERS
943 /* Increment packets counter. */
944 rxq->stats.ipackets += pkts_ret;
950 * Dummy DPDK callback for TX.
952 * This function is used to temporarily replace the real callback during
953 * unsafe control operations on the queue, or in case of error.
956 * Generic pointer to TX queue structure.
958 * Packets to transmit.
960 * Number of packets in array.
963 * Number of packets successfully transmitted (<= pkts_n).
966 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
975 * Dummy DPDK callback for RX.
977 * This function is used to temporarily replace the real callback during
978 * unsafe control operations on the queue, or in case of error.
981 * Generic pointer to RX queue structure.
983 * Array to store received packets.
985 * Maximum number of packets in array.
988 * Number of packets successfully received (<= pkts_n).
991 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)