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, const 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 \"%s\" (%p)",
167 (void *)txq, mp->name, (const void *)mp);
168 mr = ibv_reg_mr(txq->priv->pd,
169 (void *)mp->elt_va_start,
170 (mp->elt_va_end - mp->elt_va_start),
171 (IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE));
172 if (unlikely(mr == NULL)) {
173 DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.",
177 if (unlikely(i == RTE_DIM(txq->mp2mr))) {
178 /* Table is full, remove oldest entry. */
179 DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
182 claim_zero(ibv_dereg_mr(txq->mp2mr[0].mr));
183 memmove(&txq->mp2mr[0], &txq->mp2mr[1],
184 (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0])));
186 /* Store the new entry. */
187 txq->mp2mr[i].mp = mp;
188 txq->mp2mr[i].mr = mr;
189 txq->mp2mr[i].lkey = mr->lkey;
190 DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32,
191 (void *)txq, mp->name, (const void *)mp, txq->mp2mr[i].lkey);
192 return txq->mp2mr[i].lkey;
195 struct txq_mp2mr_mbuf_check_data {
196 const struct rte_mempool *mp;
201 * Callback function for rte_mempool_obj_iter() to check whether a given
202 * mempool object looks like a mbuf.
204 * @param[in, out] arg
205 * Context data (struct txq_mp2mr_mbuf_check_data). Contains mempool pointer
208 * Object start address.
210 * Object end address.
215 * Nonzero value when object is not a mbuf.
218 txq_mp2mr_mbuf_check(void *arg, void *start, void *end,
219 uint32_t index __rte_unused)
221 struct txq_mp2mr_mbuf_check_data *data = arg;
222 struct rte_mbuf *buf =
223 (void *)((uintptr_t)start + data->mp->header_size);
226 /* Check whether mbuf structure fits element size and whether mempool
227 * pointer is valid. */
228 if (((uintptr_t)end >= (uintptr_t)(buf + 1)) &&
229 (buf->pool == data->mp))
236 * Iterator function for rte_mempool_walk() to register existing mempools and
237 * fill the MP to MR cache of a TX queue.
240 * Memory Pool to register.
242 * Pointer to TX queue structure.
245 txq_mp2mr_iter(const struct rte_mempool *mp, void *arg)
247 struct txq *txq = arg;
248 struct txq_mp2mr_mbuf_check_data data = {
253 /* Discard empty mempools. */
256 /* Register mempool only if the first element looks like a mbuf. */
257 rte_mempool_obj_iter((void *)mp->elt_va_start,
259 mp->header_size + mp->elt_size + mp->trailer_size,
264 txq_mp2mr_mbuf_check,
271 #if MLX5_PMD_SGE_WR_N > 1
274 * Copy scattered mbuf contents to a single linear buffer.
277 * Linear output buffer.
279 * Scattered input buffer.
282 * Number of bytes copied to the output buffer or 0 if not large enough.
285 linearize_mbuf(linear_t *linear, struct rte_mbuf *buf)
287 unsigned int size = 0;
291 unsigned int len = DATA_LEN(buf);
295 if (unlikely(size > sizeof(*linear)))
297 memcpy(&(*linear)[offset],
298 rte_pktmbuf_mtod(buf, uint8_t *),
301 } while (buf != NULL);
306 * Handle scattered buffers for mlx5_tx_burst().
309 * TX queue structure.
311 * Number of segments in buf.
313 * TX queue element to fill.
317 * Index of the linear buffer to use if necessary (normally txq->elts_head).
319 * Array filled with SGEs on success.
322 * A structure containing the processed packet size in bytes and the
323 * number of SGEs. Both fields are set to (unsigned int)-1 in case of
326 static struct tx_burst_sg_ret {
330 tx_burst_sg(struct txq *txq, unsigned int segs, struct txq_elt *elt,
331 struct rte_mbuf *buf, unsigned int elts_head,
332 struct ibv_sge (*sges)[MLX5_PMD_SGE_WR_N])
334 unsigned int sent_size = 0;
338 /* When there are too many segments, extra segments are
339 * linearized in the last SGE. */
340 if (unlikely(segs > RTE_DIM(*sges))) {
341 segs = (RTE_DIM(*sges) - 1);
344 /* Update element. */
346 /* Register segments as SGEs. */
347 for (j = 0; (j != segs); ++j) {
348 struct ibv_sge *sge = &(*sges)[j];
351 /* Retrieve Memory Region key for this memory pool. */
352 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
353 if (unlikely(lkey == (uint32_t)-1)) {
354 /* MR does not exist. */
355 DEBUG("%p: unable to get MP <-> MR association",
357 /* Clean up TX element. */
362 sge->addr = rte_pktmbuf_mtod(buf, uintptr_t);
364 rte_prefetch0((volatile void *)
365 (uintptr_t)sge->addr);
366 sge->length = DATA_LEN(buf);
368 sent_size += sge->length;
371 /* If buf is not NULL here and is not going to be linearized,
372 * nb_segs is not valid. */
374 assert((buf == NULL) || (linearize));
375 /* Linearize extra segments. */
377 struct ibv_sge *sge = &(*sges)[segs];
378 linear_t *linear = &(*txq->elts_linear)[elts_head];
379 unsigned int size = linearize_mbuf(linear, buf);
381 assert(segs == (RTE_DIM(*sges) - 1));
383 /* Invalid packet. */
384 DEBUG("%p: packet too large to be linearized.",
386 /* Clean up TX element. */
390 /* If MLX5_PMD_SGE_WR_N is 1, free mbuf immediately. */
391 if (RTE_DIM(*sges) == 1) {
393 struct rte_mbuf *next = NEXT(buf);
395 rte_pktmbuf_free_seg(buf);
397 } while (buf != NULL);
401 sge->addr = (uintptr_t)&(*linear)[0];
403 sge->lkey = txq->mr_linear->lkey;
405 /* Include last segment. */
408 return (struct tx_burst_sg_ret){
413 return (struct tx_burst_sg_ret){
419 #endif /* MLX5_PMD_SGE_WR_N > 1 */
422 * DPDK callback for TX.
425 * Generic pointer to TX queue structure.
427 * Packets to transmit.
429 * Number of packets in array.
432 * Number of packets successfully transmitted (<= pkts_n).
435 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
437 struct txq *txq = (struct txq *)dpdk_txq;
438 unsigned int elts_head = txq->elts_head;
439 const unsigned int elts_n = txq->elts_n;
440 unsigned int elts_comp_cd = txq->elts_comp_cd;
441 unsigned int elts_comp = 0;
446 assert(elts_comp_cd != 0);
448 max = (elts_n - (elts_head - txq->elts_tail));
452 assert(max <= elts_n);
453 /* Always leave one free entry in the ring. */
459 for (i = 0; (i != max); ++i) {
460 struct rte_mbuf *buf = pkts[i];
461 unsigned int elts_head_next =
462 (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
463 struct txq_elt *elt_next = &(*txq->elts)[elts_head_next];
464 struct txq_elt *elt = &(*txq->elts)[elts_head];
465 unsigned int segs = NB_SEGS(buf);
466 #ifdef MLX5_PMD_SOFT_COUNTERS
467 unsigned int sent_size = 0;
469 uint32_t send_flags = 0;
471 /* Clean up old buffer. */
472 if (likely(elt->buf != NULL)) {
473 struct rte_mbuf *tmp = elt->buf;
475 /* Faster than rte_pktmbuf_free(). */
477 struct rte_mbuf *next = NEXT(tmp);
479 rte_pktmbuf_free_seg(tmp);
481 } while (tmp != NULL);
483 /* Request TX completion. */
484 if (unlikely(--elts_comp_cd == 0)) {
485 elts_comp_cd = txq->elts_comp_cd_init;
487 send_flags |= IBV_EXP_QP_BURST_SIGNALED;
489 /* Should we enable HW CKSUM offload */
491 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
492 send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
493 /* HW does not support checksum offloads at arbitrary
494 * offsets but automatically recognizes the packet
495 * type. For inner L3/L4 checksums, only VXLAN (UDP)
496 * tunnels are currently supported. */
497 if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
498 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
500 if (likely(segs == 1)) {
505 /* Retrieve buffer information. */
506 addr = rte_pktmbuf_mtod(buf, uintptr_t);
507 length = DATA_LEN(buf);
508 /* Retrieve Memory Region key for this memory pool. */
509 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
510 if (unlikely(lkey == (uint32_t)-1)) {
511 /* MR does not exist. */
512 DEBUG("%p: unable to get MP <-> MR"
513 " association", (void *)txq);
514 /* Clean up TX element. */
518 /* Update element. */
521 rte_prefetch0((volatile void *)
523 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
524 /* Put packet into send queue. */
525 #if MLX5_PMD_MAX_INLINE > 0
526 if (length <= txq->max_inline)
527 err = txq->if_qp->send_pending_inline
534 err = txq->if_qp->send_pending
542 #ifdef MLX5_PMD_SOFT_COUNTERS
546 #if MLX5_PMD_SGE_WR_N > 1
547 struct ibv_sge sges[MLX5_PMD_SGE_WR_N];
548 struct tx_burst_sg_ret ret;
550 ret = tx_burst_sg(txq, segs, elt, buf, elts_head,
552 if (ret.length == (unsigned int)-1)
554 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
555 /* Put SG list into send queue. */
556 err = txq->if_qp->send_pending_sg_list
563 #ifdef MLX5_PMD_SOFT_COUNTERS
564 sent_size += ret.length;
566 #else /* MLX5_PMD_SGE_WR_N > 1 */
567 DEBUG("%p: TX scattered buffers support not"
568 " compiled in", (void *)txq);
570 #endif /* MLX5_PMD_SGE_WR_N > 1 */
572 elts_head = elts_head_next;
573 #ifdef MLX5_PMD_SOFT_COUNTERS
574 /* Increment sent bytes counter. */
575 txq->stats.obytes += sent_size;
579 /* Take a shortcut if nothing must be sent. */
580 if (unlikely(i == 0))
582 #ifdef MLX5_PMD_SOFT_COUNTERS
583 /* Increment sent packets counter. */
584 txq->stats.opackets += i;
586 /* Ring QP doorbell. */
587 err = txq->if_qp->send_flush(txq->qp);
589 /* A nonzero value is not supposed to be returned.
590 * Nothing can be done about it. */
591 DEBUG("%p: send_flush() failed with error %d",
594 txq->elts_head = elts_head;
595 txq->elts_comp += elts_comp;
596 txq->elts_comp_cd = elts_comp_cd;
601 * Translate RX completion flags to packet type.
604 * RX completion flags returned by poll_length_flags().
607 * Packet type for struct rte_mbuf.
609 static inline uint32_t
610 rxq_cq_to_pkt_type(uint32_t flags)
614 if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
617 IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
620 IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
623 IBV_EXP_CQ_RX_IPV4_PACKET,
624 RTE_PTYPE_INNER_L3_IPV4) |
626 IBV_EXP_CQ_RX_IPV6_PACKET,
627 RTE_PTYPE_INNER_L3_IPV6);
631 IBV_EXP_CQ_RX_IPV4_PACKET,
634 IBV_EXP_CQ_RX_IPV6_PACKET,
640 * Translate RX completion flags to offload flags.
643 * Pointer to RX queue structure.
645 * RX completion flags returned by poll_length_flags().
648 * Offload flags (ol_flags) for struct rte_mbuf.
650 static inline uint32_t
651 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
653 uint32_t ol_flags = 0;
658 IBV_EXP_CQ_RX_IP_CSUM_OK,
659 PKT_RX_IP_CKSUM_BAD) |
661 IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
662 PKT_RX_L4_CKSUM_BAD);
664 * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
665 * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
668 if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
671 IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
672 PKT_RX_IP_CKSUM_BAD) |
674 IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
675 PKT_RX_L4_CKSUM_BAD);
680 * DPDK callback for RX with scattered packets support.
683 * Generic pointer to RX queue structure.
685 * Array to store received packets.
687 * Maximum number of packets in array.
690 * Number of packets successfully received (<= pkts_n).
693 mlx5_rx_burst_sp(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
695 struct rxq *rxq = (struct rxq *)dpdk_rxq;
696 struct rxq_elt_sp (*elts)[rxq->elts_n] = rxq->elts.sp;
697 const unsigned int elts_n = rxq->elts_n;
698 unsigned int elts_head = rxq->elts_head;
700 unsigned int pkts_ret = 0;
703 if (unlikely(!rxq->sp))
704 return mlx5_rx_burst(dpdk_rxq, pkts, pkts_n);
705 if (unlikely(elts == NULL)) /* See RTE_DEV_CMD_SET_MTU. */
707 for (i = 0; (i != pkts_n); ++i) {
708 struct rxq_elt_sp *elt = &(*elts)[elts_head];
710 unsigned int pkt_buf_len;
711 struct rte_mbuf *pkt_buf = NULL; /* Buffer returned in pkts. */
712 struct rte_mbuf **pkt_buf_next = &pkt_buf;
713 unsigned int seg_headroom = RTE_PKTMBUF_HEADROOM;
718 assert(elts_head < rxq->elts_n);
719 assert(rxq->elts_head < rxq->elts_n);
720 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
722 if (unlikely(ret < 0)) {
726 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
728 /* ibv_poll_cq() must be used in case of failure. */
729 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
730 if (unlikely(wcs_n == 0))
732 if (unlikely(wcs_n < 0)) {
733 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
738 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
739 /* Whatever, just repost the offending WR. */
740 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
741 " completion status (%d): %s",
742 (void *)rxq, wc.wr_id, wc.status,
743 ibv_wc_status_str(wc.status));
744 #ifdef MLX5_PMD_SOFT_COUNTERS
745 /* Increment dropped packets counter. */
746 ++rxq->stats.idropped;
757 * Replace spent segments with new ones, concatenate and
758 * return them as pkt_buf.
761 struct ibv_sge *sge = &elt->sges[j];
762 struct rte_mbuf *seg = elt->bufs[j];
763 struct rte_mbuf *rep;
764 unsigned int seg_tailroom;
768 * Fetch initial bytes of packet descriptor into a
769 * cacheline while allocating rep.
772 rep = __rte_mbuf_raw_alloc(rxq->mp);
773 if (unlikely(rep == NULL)) {
775 * Unable to allocate a replacement mbuf,
778 DEBUG("rxq=%p: can't allocate a new mbuf",
780 if (pkt_buf != NULL) {
781 *pkt_buf_next = NULL;
782 rte_pktmbuf_free(pkt_buf);
784 /* Increment out of memory counters. */
785 ++rxq->stats.rx_nombuf;
786 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
790 /* Poison user-modifiable fields in rep. */
791 NEXT(rep) = (void *)((uintptr_t)-1);
792 SET_DATA_OFF(rep, 0xdead);
793 DATA_LEN(rep) = 0xd00d;
794 PKT_LEN(rep) = 0xdeadd00d;
799 assert(rep->buf_len == seg->buf_len);
800 assert(rep->buf_len == rxq->mb_len);
801 /* Reconfigure sge to use rep instead of seg. */
802 assert(sge->lkey == rxq->mr->lkey);
803 sge->addr = ((uintptr_t)rep->buf_addr + seg_headroom);
806 /* Update pkt_buf if it's the first segment, or link
807 * seg to the previous one and update pkt_buf_next. */
809 pkt_buf_next = &NEXT(seg);
810 /* Update seg information. */
811 seg_tailroom = (seg->buf_len - seg_headroom);
812 assert(sge->length == seg_tailroom);
813 SET_DATA_OFF(seg, seg_headroom);
814 if (likely(len <= seg_tailroom)) {
819 assert(rte_pktmbuf_headroom(seg) ==
821 assert(rte_pktmbuf_tailroom(seg) ==
822 (seg_tailroom - len));
825 DATA_LEN(seg) = seg_tailroom;
826 PKT_LEN(seg) = seg_tailroom;
828 assert(rte_pktmbuf_headroom(seg) == seg_headroom);
829 assert(rte_pktmbuf_tailroom(seg) == 0);
830 /* Fix len and clear headroom for next segments. */
834 /* Update head and tail segments. */
835 *pkt_buf_next = NULL;
836 assert(pkt_buf != NULL);
838 NB_SEGS(pkt_buf) = j;
839 PORT(pkt_buf) = rxq->port_id;
840 PKT_LEN(pkt_buf) = pkt_buf_len;
841 pkt_buf->packet_type = rxq_cq_to_pkt_type(flags);
842 pkt_buf->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
847 #ifdef MLX5_PMD_SOFT_COUNTERS
848 /* Increment bytes counter. */
849 rxq->stats.ibytes += pkt_buf_len;
852 ret = rxq->if_wq->recv_sg_list(rxq->wq,
856 /* Inability to repost WRs is fatal. */
857 DEBUG("%p: recv_sg_list(): failed (ret=%d)",
862 if (++elts_head >= elts_n)
866 if (unlikely(i == 0))
868 rxq->elts_head = elts_head;
869 #ifdef MLX5_PMD_SOFT_COUNTERS
870 /* Increment packets counter. */
871 rxq->stats.ipackets += pkts_ret;
877 * DPDK callback for RX.
879 * The following function is the same as mlx5_rx_burst_sp(), except it doesn't
880 * manage scattered packets. Improves performance when MRU is lower than the
881 * size of the first segment.
884 * Generic pointer to RX queue structure.
886 * Array to store received packets.
888 * Maximum number of packets in array.
891 * Number of packets successfully received (<= pkts_n).
894 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
896 struct rxq *rxq = (struct rxq *)dpdk_rxq;
897 struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts.no_sp;
898 const unsigned int elts_n = rxq->elts_n;
899 unsigned int elts_head = rxq->elts_head;
900 struct ibv_sge sges[pkts_n];
902 unsigned int pkts_ret = 0;
905 if (unlikely(rxq->sp))
906 return mlx5_rx_burst_sp(dpdk_rxq, pkts, pkts_n);
907 for (i = 0; (i != pkts_n); ++i) {
908 struct rxq_elt *elt = &(*elts)[elts_head];
910 struct rte_mbuf *seg = elt->buf;
911 struct rte_mbuf *rep;
916 assert(elts_head < rxq->elts_n);
917 assert(rxq->elts_head < rxq->elts_n);
919 * Fetch initial bytes of packet descriptor into a
920 * cacheline while allocating rep.
923 rte_prefetch0(&seg->cacheline1);
924 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
926 if (unlikely(ret < 0)) {
930 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
932 /* ibv_poll_cq() must be used in case of failure. */
933 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
934 if (unlikely(wcs_n == 0))
936 if (unlikely(wcs_n < 0)) {
937 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
942 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
943 /* Whatever, just repost the offending WR. */
944 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
945 " completion status (%d): %s",
946 (void *)rxq, wc.wr_id, wc.status,
947 ibv_wc_status_str(wc.status));
948 #ifdef MLX5_PMD_SOFT_COUNTERS
949 /* Increment dropped packets counter. */
950 ++rxq->stats.idropped;
952 /* Add SGE to array for repost. */
961 rep = __rte_mbuf_raw_alloc(rxq->mp);
962 if (unlikely(rep == NULL)) {
964 * Unable to allocate a replacement mbuf,
967 DEBUG("rxq=%p: can't allocate a new mbuf",
969 /* Increment out of memory counters. */
970 ++rxq->stats.rx_nombuf;
971 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
975 /* Reconfigure sge to use rep instead of seg. */
976 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
977 assert(elt->sge.lkey == rxq->mr->lkey);
980 /* Add SGE to array for repost. */
983 /* Update seg information. */
984 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
986 PORT(seg) = rxq->port_id;
990 seg->packet_type = rxq_cq_to_pkt_type(flags);
991 seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
996 #ifdef MLX5_PMD_SOFT_COUNTERS
997 /* Increment bytes counter. */
998 rxq->stats.ibytes += len;
1001 if (++elts_head >= elts_n)
1005 if (unlikely(i == 0))
1009 DEBUG("%p: reposting %u WRs", (void *)rxq, i);
1011 ret = rxq->if_wq->recv_burst(rxq->wq, sges, i);
1012 if (unlikely(ret)) {
1013 /* Inability to repost WRs is fatal. */
1014 DEBUG("%p: recv_burst(): failed (ret=%d)",
1019 rxq->elts_head = elts_head;
1020 #ifdef MLX5_PMD_SOFT_COUNTERS
1021 /* Increment packets counter. */
1022 rxq->stats.ipackets += pkts_ret;
1028 * Dummy DPDK callback for TX.
1030 * This function is used to temporarily replace the real callback during
1031 * unsafe control operations on the queue, or in case of error.
1034 * Generic pointer to TX queue structure.
1036 * Packets to transmit.
1038 * Number of packets in array.
1041 * Number of packets successfully transmitted (<= pkts_n).
1044 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
1053 * Dummy DPDK callback for RX.
1055 * This function is used to temporarily replace the real callback during
1056 * unsafe control operations on the queue, or in case of error.
1059 * Generic pointer to RX queue structure.
1061 * Array to store received packets.
1063 * Maximum number of packets in array.
1066 * Number of packets successfully received (<= pkts_n).
1069 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)