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_autoconf.h"
66 #include "mlx5_defs.h"
69 * Manage TX completions.
71 * When sending a burst, mlx5_tx_burst() posts several WRs.
72 * To improve performance, a completion event is only required once every
73 * MLX5_PMD_TX_PER_COMP_REQ sends. Doing so discards completion information
74 * for other WRs, but this information would not be used anyway.
77 * Pointer to TX queue structure.
80 * 0 on success, -1 on failure.
83 txq_complete(struct txq *txq)
85 unsigned int elts_comp = txq->elts_comp;
86 unsigned int elts_tail = txq->elts_tail;
87 unsigned int elts_free = 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->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)
115 while (elts_free != elts_tail) {
116 struct txq_elt *elt = &(*txq->elts)[elts_free];
117 unsigned int elts_free_next =
118 (((elts_free + 1) == elts_n) ? 0 : elts_free + 1);
119 struct rte_mbuf *tmp = elt->buf;
120 struct txq_elt *elt_next = &(*txq->elts)[elts_free_next];
122 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
123 /* Faster than rte_pktmbuf_free(). */
125 struct rte_mbuf *next = NEXT(tmp);
127 rte_pktmbuf_free_seg(tmp);
129 } while (tmp != NULL);
130 elts_free = elts_free_next;
133 txq->elts_tail = elts_tail;
134 txq->elts_comp = elts_comp;
139 * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
140 * the cloned mbuf is allocated is returned instead.
146 * Memory pool where data is located for given mbuf.
148 static struct rte_mempool *
149 txq_mb2mp(struct rte_mbuf *buf)
151 if (unlikely(RTE_MBUF_INDIRECT(buf)))
152 return rte_mbuf_from_indirect(buf)->pool;
157 * Get Memory Region (MR) <-> Memory Pool (MP) association from txq->mp2mr[].
158 * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
159 * remove an entry first.
162 * Pointer to TX queue structure.
164 * Memory Pool for which a Memory Region lkey must be returned.
167 * mr->lkey on success, (uint32_t)-1 on failure.
170 txq_mp2mr(struct txq *txq, const struct rte_mempool *mp)
175 for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
176 if (unlikely(txq->mp2mr[i].mp == NULL)) {
177 /* Unknown MP, add a new MR for it. */
180 if (txq->mp2mr[i].mp == mp) {
181 assert(txq->mp2mr[i].lkey != (uint32_t)-1);
182 assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey);
183 return txq->mp2mr[i].lkey;
186 /* Add a new entry, register MR first. */
187 DEBUG("%p: discovered new memory pool \"%s\" (%p)",
188 (void *)txq, mp->name, (const void *)mp);
189 mr = ibv_reg_mr(txq->priv->pd,
190 (void *)mp->elt_va_start,
191 (mp->elt_va_end - mp->elt_va_start),
192 (IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE));
193 if (unlikely(mr == NULL)) {
194 DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.",
198 if (unlikely(i == RTE_DIM(txq->mp2mr))) {
199 /* Table is full, remove oldest entry. */
200 DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
203 claim_zero(ibv_dereg_mr(txq->mp2mr[0].mr));
204 memmove(&txq->mp2mr[0], &txq->mp2mr[1],
205 (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0])));
207 /* Store the new entry. */
208 txq->mp2mr[i].mp = mp;
209 txq->mp2mr[i].mr = mr;
210 txq->mp2mr[i].lkey = mr->lkey;
211 DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32,
212 (void *)txq, mp->name, (const void *)mp, txq->mp2mr[i].lkey);
213 return txq->mp2mr[i].lkey;
216 struct txq_mp2mr_mbuf_check_data {
217 const struct rte_mempool *mp;
222 * Callback function for rte_mempool_obj_iter() to check whether a given
223 * mempool object looks like a mbuf.
225 * @param[in, out] arg
226 * Context data (struct txq_mp2mr_mbuf_check_data). Contains mempool pointer
229 * Object start address.
231 * Object end address.
236 * Nonzero value when object is not a mbuf.
239 txq_mp2mr_mbuf_check(void *arg, void *start, void *end,
240 uint32_t index __rte_unused)
242 struct txq_mp2mr_mbuf_check_data *data = arg;
243 struct rte_mbuf *buf =
244 (void *)((uintptr_t)start + data->mp->header_size);
247 /* Check whether mbuf structure fits element size and whether mempool
248 * pointer is valid. */
249 if (((uintptr_t)end >= (uintptr_t)(buf + 1)) &&
250 (buf->pool == data->mp))
257 * Iterator function for rte_mempool_walk() to register existing mempools and
258 * fill the MP to MR cache of a TX queue.
261 * Memory Pool to register.
263 * Pointer to TX queue structure.
266 txq_mp2mr_iter(const struct rte_mempool *mp, void *arg)
268 struct txq *txq = arg;
269 struct txq_mp2mr_mbuf_check_data data = {
274 /* Discard empty mempools. */
277 /* Register mempool only if the first element looks like a mbuf. */
278 rte_mempool_obj_iter((void *)mp->elt_va_start,
280 mp->header_size + mp->elt_size + mp->trailer_size,
285 txq_mp2mr_mbuf_check,
292 #if MLX5_PMD_SGE_WR_N > 1
295 * Copy scattered mbuf contents to a single linear buffer.
298 * Linear output buffer.
300 * Scattered input buffer.
303 * Number of bytes copied to the output buffer or 0 if not large enough.
306 linearize_mbuf(linear_t *linear, struct rte_mbuf *buf)
308 unsigned int size = 0;
312 unsigned int len = DATA_LEN(buf);
316 if (unlikely(size > sizeof(*linear)))
318 memcpy(&(*linear)[offset],
319 rte_pktmbuf_mtod(buf, uint8_t *),
322 } while (buf != NULL);
327 * Handle scattered buffers for mlx5_tx_burst().
330 * TX queue structure.
332 * Number of segments in buf.
334 * TX queue element to fill.
338 * Index of the linear buffer to use if necessary (normally txq->elts_head).
340 * Array filled with SGEs on success.
343 * A structure containing the processed packet size in bytes and the
344 * number of SGEs. Both fields are set to (unsigned int)-1 in case of
347 static struct tx_burst_sg_ret {
351 tx_burst_sg(struct txq *txq, unsigned int segs, struct txq_elt *elt,
352 struct rte_mbuf *buf, unsigned int elts_head,
353 struct ibv_sge (*sges)[MLX5_PMD_SGE_WR_N])
355 unsigned int sent_size = 0;
359 /* When there are too many segments, extra segments are
360 * linearized in the last SGE. */
361 if (unlikely(segs > RTE_DIM(*sges))) {
362 segs = (RTE_DIM(*sges) - 1);
365 /* Update element. */
367 /* Register segments as SGEs. */
368 for (j = 0; (j != segs); ++j) {
369 struct ibv_sge *sge = &(*sges)[j];
372 /* Retrieve Memory Region key for this memory pool. */
373 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
374 if (unlikely(lkey == (uint32_t)-1)) {
375 /* MR does not exist. */
376 DEBUG("%p: unable to get MP <-> MR association",
378 /* Clean up TX element. */
383 sge->addr = rte_pktmbuf_mtod(buf, uintptr_t);
385 rte_prefetch0((volatile void *)
386 (uintptr_t)sge->addr);
387 sge->length = DATA_LEN(buf);
389 sent_size += sge->length;
392 /* If buf is not NULL here and is not going to be linearized,
393 * nb_segs is not valid. */
395 assert((buf == NULL) || (linearize));
396 /* Linearize extra segments. */
398 struct ibv_sge *sge = &(*sges)[segs];
399 linear_t *linear = &(*txq->elts_linear)[elts_head];
400 unsigned int size = linearize_mbuf(linear, buf);
402 assert(segs == (RTE_DIM(*sges) - 1));
404 /* Invalid packet. */
405 DEBUG("%p: packet too large to be linearized.",
407 /* Clean up TX element. */
411 /* If MLX5_PMD_SGE_WR_N is 1, free mbuf immediately. */
412 if (RTE_DIM(*sges) == 1) {
414 struct rte_mbuf *next = NEXT(buf);
416 rte_pktmbuf_free_seg(buf);
418 } while (buf != NULL);
422 sge->addr = (uintptr_t)&(*linear)[0];
424 sge->lkey = txq->mr_linear->lkey;
426 /* Include last segment. */
429 return (struct tx_burst_sg_ret){
434 return (struct tx_burst_sg_ret){
440 #endif /* MLX5_PMD_SGE_WR_N > 1 */
443 * DPDK callback for TX.
446 * Generic pointer to TX queue structure.
448 * Packets to transmit.
450 * Number of packets in array.
453 * Number of packets successfully transmitted (<= pkts_n).
456 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
458 struct txq *txq = (struct txq *)dpdk_txq;
459 unsigned int elts_head = txq->elts_head;
460 const unsigned int elts_n = txq->elts_n;
461 unsigned int elts_comp_cd = txq->elts_comp_cd;
462 unsigned int elts_comp = 0;
466 struct rte_mbuf *buf = pkts[0];
468 assert(elts_comp_cd != 0);
469 /* Prefetch first packet cacheline. */
472 max = (elts_n - (elts_head - txq->elts_tail));
476 assert(max <= elts_n);
477 /* Always leave one free entry in the ring. */
483 for (i = 0; (i != max); ++i) {
484 struct rte_mbuf *buf_next = pkts[i + 1];
485 unsigned int elts_head_next =
486 (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
487 struct txq_elt *elt = &(*txq->elts)[elts_head];
488 unsigned int segs = NB_SEGS(buf);
489 #ifdef MLX5_PMD_SOFT_COUNTERS
490 unsigned int sent_size = 0;
492 uint32_t send_flags = 0;
495 rte_prefetch0(buf_next);
496 /* Request TX completion. */
497 if (unlikely(--elts_comp_cd == 0)) {
498 elts_comp_cd = txq->elts_comp_cd_init;
500 send_flags |= IBV_EXP_QP_BURST_SIGNALED;
502 /* Should we enable HW CKSUM offload */
504 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
505 send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
506 /* HW does not support checksum offloads at arbitrary
507 * offsets but automatically recognizes the packet
508 * type. For inner L3/L4 checksums, only VXLAN (UDP)
509 * tunnels are currently supported. */
510 if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
511 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
513 if (likely(segs == 1)) {
517 uintptr_t buf_next_addr;
519 /* Retrieve buffer information. */
520 addr = rte_pktmbuf_mtod(buf, uintptr_t);
521 length = DATA_LEN(buf);
522 /* Update element. */
525 rte_prefetch0((volatile void *)
527 /* Prefetch next buffer data. */
530 rte_pktmbuf_mtod(buf_next, uintptr_t);
531 rte_prefetch0((volatile void *)
532 (uintptr_t)buf_next_addr);
534 /* Put packet into send queue. */
535 #if MLX5_PMD_MAX_INLINE > 0
536 if (length <= txq->max_inline)
537 err = txq->send_pending_inline
545 /* Retrieve Memory Region key for this
547 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
548 if (unlikely(lkey == (uint32_t)-1)) {
549 /* MR does not exist. */
550 DEBUG("%p: unable to get MP <-> MR"
551 " association", (void *)txq);
552 /* Clean up TX element. */
556 err = txq->send_pending
565 #ifdef MLX5_PMD_SOFT_COUNTERS
569 #if MLX5_PMD_SGE_WR_N > 1
570 struct ibv_sge sges[MLX5_PMD_SGE_WR_N];
571 struct tx_burst_sg_ret ret;
573 ret = tx_burst_sg(txq, segs, elt, buf, elts_head,
575 if (ret.length == (unsigned int)-1)
577 /* Put SG list into send queue. */
578 err = txq->send_pending_sg_list
585 #ifdef MLX5_PMD_SOFT_COUNTERS
586 sent_size += ret.length;
588 #else /* MLX5_PMD_SGE_WR_N > 1 */
589 DEBUG("%p: TX scattered buffers support not"
590 " compiled in", (void *)txq);
592 #endif /* MLX5_PMD_SGE_WR_N > 1 */
594 elts_head = elts_head_next;
596 #ifdef MLX5_PMD_SOFT_COUNTERS
597 /* Increment sent bytes counter. */
598 txq->stats.obytes += sent_size;
602 /* Take a shortcut if nothing must be sent. */
603 if (unlikely(i == 0))
605 #ifdef MLX5_PMD_SOFT_COUNTERS
606 /* Increment sent packets counter. */
607 txq->stats.opackets += i;
609 /* Ring QP doorbell. */
610 err = txq->send_flush(txq->qp);
612 /* A nonzero value is not supposed to be returned.
613 * Nothing can be done about it. */
614 DEBUG("%p: send_flush() failed with error %d",
617 txq->elts_head = elts_head;
618 txq->elts_comp += elts_comp;
619 txq->elts_comp_cd = elts_comp_cd;
624 * Translate RX completion flags to packet type.
627 * RX completion flags returned by poll_length_flags().
630 * Packet type for struct rte_mbuf.
632 static inline uint32_t
633 rxq_cq_to_pkt_type(uint32_t flags)
637 if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
640 IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
643 IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
646 IBV_EXP_CQ_RX_IPV4_PACKET,
647 RTE_PTYPE_INNER_L3_IPV4) |
649 IBV_EXP_CQ_RX_IPV6_PACKET,
650 RTE_PTYPE_INNER_L3_IPV6);
654 IBV_EXP_CQ_RX_IPV4_PACKET,
657 IBV_EXP_CQ_RX_IPV6_PACKET,
663 * Translate RX completion flags to offload flags.
666 * Pointer to RX queue structure.
668 * RX completion flags returned by poll_length_flags().
671 * Offload flags (ol_flags) for struct rte_mbuf.
673 static inline uint32_t
674 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
676 uint32_t ol_flags = 0;
681 IBV_EXP_CQ_RX_IP_CSUM_OK,
682 PKT_RX_IP_CKSUM_BAD) |
684 IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
685 PKT_RX_L4_CKSUM_BAD);
687 * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
688 * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
691 if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
694 IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
695 PKT_RX_IP_CKSUM_BAD) |
697 IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
698 PKT_RX_L4_CKSUM_BAD);
703 * DPDK callback for RX with scattered packets support.
706 * Generic pointer to RX queue structure.
708 * Array to store received packets.
710 * Maximum number of packets in array.
713 * Number of packets successfully received (<= pkts_n).
716 mlx5_rx_burst_sp(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
718 struct rxq *rxq = (struct rxq *)dpdk_rxq;
719 struct rxq_elt_sp (*elts)[rxq->elts_n] = rxq->elts.sp;
720 const unsigned int elts_n = rxq->elts_n;
721 unsigned int elts_head = rxq->elts_head;
723 unsigned int pkts_ret = 0;
726 if (unlikely(!rxq->sp))
727 return mlx5_rx_burst(dpdk_rxq, pkts, pkts_n);
728 if (unlikely(elts == NULL)) /* See RTE_DEV_CMD_SET_MTU. */
730 for (i = 0; (i != pkts_n); ++i) {
731 struct rxq_elt_sp *elt = &(*elts)[elts_head];
733 unsigned int pkt_buf_len;
734 struct rte_mbuf *pkt_buf = NULL; /* Buffer returned in pkts. */
735 struct rte_mbuf **pkt_buf_next = &pkt_buf;
736 unsigned int seg_headroom = RTE_PKTMBUF_HEADROOM;
742 assert(elts_head < rxq->elts_n);
743 assert(rxq->elts_head < rxq->elts_n);
744 ret = rxq->poll(rxq->cq, NULL, NULL, &flags, &vlan_tci);
745 if (unlikely(ret < 0)) {
749 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
751 /* ibv_poll_cq() must be used in case of failure. */
752 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
753 if (unlikely(wcs_n == 0))
755 if (unlikely(wcs_n < 0)) {
756 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
761 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
762 /* Whatever, just repost the offending WR. */
763 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
764 " completion status (%d): %s",
765 (void *)rxq, wc.wr_id, wc.status,
766 ibv_wc_status_str(wc.status));
767 #ifdef MLX5_PMD_SOFT_COUNTERS
768 /* Increment dropped packets counter. */
769 ++rxq->stats.idropped;
780 * Replace spent segments with new ones, concatenate and
781 * return them as pkt_buf.
784 struct ibv_sge *sge = &elt->sges[j];
785 struct rte_mbuf *seg = elt->bufs[j];
786 struct rte_mbuf *rep;
787 unsigned int seg_tailroom;
791 * Fetch initial bytes of packet descriptor into a
792 * cacheline while allocating rep.
795 rep = __rte_mbuf_raw_alloc(rxq->mp);
796 if (unlikely(rep == NULL)) {
798 * Unable to allocate a replacement mbuf,
801 DEBUG("rxq=%p: can't allocate a new mbuf",
803 if (pkt_buf != NULL) {
804 *pkt_buf_next = NULL;
805 rte_pktmbuf_free(pkt_buf);
807 /* Increment out of memory counters. */
808 ++rxq->stats.rx_nombuf;
809 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
813 /* Poison user-modifiable fields in rep. */
814 NEXT(rep) = (void *)((uintptr_t)-1);
815 SET_DATA_OFF(rep, 0xdead);
816 DATA_LEN(rep) = 0xd00d;
817 PKT_LEN(rep) = 0xdeadd00d;
822 assert(rep->buf_len == seg->buf_len);
823 assert(rep->buf_len == rxq->mb_len);
824 /* Reconfigure sge to use rep instead of seg. */
825 assert(sge->lkey == rxq->mr->lkey);
826 sge->addr = ((uintptr_t)rep->buf_addr + seg_headroom);
829 /* Update pkt_buf if it's the first segment, or link
830 * seg to the previous one and update pkt_buf_next. */
832 pkt_buf_next = &NEXT(seg);
833 /* Update seg information. */
834 seg_tailroom = (seg->buf_len - seg_headroom);
835 assert(sge->length == seg_tailroom);
836 SET_DATA_OFF(seg, seg_headroom);
837 if (likely(len <= seg_tailroom)) {
842 assert(rte_pktmbuf_headroom(seg) ==
844 assert(rte_pktmbuf_tailroom(seg) ==
845 (seg_tailroom - len));
848 DATA_LEN(seg) = seg_tailroom;
849 PKT_LEN(seg) = seg_tailroom;
851 assert(rte_pktmbuf_headroom(seg) == seg_headroom);
852 assert(rte_pktmbuf_tailroom(seg) == 0);
853 /* Fix len and clear headroom for next segments. */
857 /* Update head and tail segments. */
858 *pkt_buf_next = NULL;
859 assert(pkt_buf != NULL);
861 NB_SEGS(pkt_buf) = j;
862 PORT(pkt_buf) = rxq->port_id;
863 PKT_LEN(pkt_buf) = pkt_buf_len;
864 if (rxq->csum | rxq->csum_l2tun | rxq->vlan_strip) {
865 pkt_buf->packet_type = rxq_cq_to_pkt_type(flags);
866 pkt_buf->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
867 #ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
868 if (flags & IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1) {
869 pkt_buf->ol_flags |= PKT_RX_VLAN_PKT;
870 pkt_buf->vlan_tci = vlan_tci;
872 #endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
878 #ifdef MLX5_PMD_SOFT_COUNTERS
879 /* Increment bytes counter. */
880 rxq->stats.ibytes += pkt_buf_len;
883 ret = rxq->recv(rxq->wq, elt->sges, RTE_DIM(elt->sges));
885 /* Inability to repost WRs is fatal. */
886 DEBUG("%p: recv_sg_list(): failed (ret=%d)",
891 if (++elts_head >= elts_n)
895 if (unlikely(i == 0))
897 rxq->elts_head = elts_head;
898 #ifdef MLX5_PMD_SOFT_COUNTERS
899 /* Increment packets counter. */
900 rxq->stats.ipackets += pkts_ret;
906 * DPDK callback for RX.
908 * The following function is the same as mlx5_rx_burst_sp(), except it doesn't
909 * manage scattered packets. Improves performance when MRU is lower than the
910 * size of the first segment.
913 * Generic pointer to RX queue structure.
915 * Array to store received packets.
917 * Maximum number of packets in array.
920 * Number of packets successfully received (<= pkts_n).
923 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
925 struct rxq *rxq = (struct rxq *)dpdk_rxq;
926 struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts.no_sp;
927 const unsigned int elts_n = rxq->elts_n;
928 unsigned int elts_head = rxq->elts_head;
929 struct ibv_sge sges[pkts_n];
931 unsigned int pkts_ret = 0;
934 if (unlikely(rxq->sp))
935 return mlx5_rx_burst_sp(dpdk_rxq, pkts, pkts_n);
936 for (i = 0; (i != pkts_n); ++i) {
937 struct rxq_elt *elt = &(*elts)[elts_head];
939 struct rte_mbuf *seg = elt->buf;
940 struct rte_mbuf *rep;
946 assert(elts_head < rxq->elts_n);
947 assert(rxq->elts_head < rxq->elts_n);
949 * Fetch initial bytes of packet descriptor into a
950 * cacheline while allocating rep.
953 rte_prefetch0(&seg->cacheline1);
954 ret = rxq->poll(rxq->cq, NULL, NULL, &flags, &vlan_tci);
955 if (unlikely(ret < 0)) {
959 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
961 /* ibv_poll_cq() must be used in case of failure. */
962 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
963 if (unlikely(wcs_n == 0))
965 if (unlikely(wcs_n < 0)) {
966 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
971 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
972 /* Whatever, just repost the offending WR. */
973 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
974 " completion status (%d): %s",
975 (void *)rxq, wc.wr_id, wc.status,
976 ibv_wc_status_str(wc.status));
977 #ifdef MLX5_PMD_SOFT_COUNTERS
978 /* Increment dropped packets counter. */
979 ++rxq->stats.idropped;
981 /* Add SGE to array for repost. */
990 rep = __rte_mbuf_raw_alloc(rxq->mp);
991 if (unlikely(rep == NULL)) {
993 * Unable to allocate a replacement mbuf,
996 DEBUG("rxq=%p: can't allocate a new mbuf",
998 /* Increment out of memory counters. */
999 ++rxq->stats.rx_nombuf;
1000 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
1004 /* Reconfigure sge to use rep instead of seg. */
1005 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
1006 assert(elt->sge.lkey == rxq->mr->lkey);
1009 /* Add SGE to array for repost. */
1012 /* Update seg information. */
1013 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
1015 PORT(seg) = rxq->port_id;
1018 DATA_LEN(seg) = len;
1019 if (rxq->csum | rxq->csum_l2tun | rxq->vlan_strip) {
1020 seg->packet_type = rxq_cq_to_pkt_type(flags);
1021 seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
1022 #ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
1023 if (flags & IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1) {
1024 seg->ol_flags |= PKT_RX_VLAN_PKT;
1025 seg->vlan_tci = vlan_tci;
1027 #endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
1029 /* Return packet. */
1032 #ifdef MLX5_PMD_SOFT_COUNTERS
1033 /* Increment bytes counter. */
1034 rxq->stats.ibytes += len;
1037 if (++elts_head >= elts_n)
1041 if (unlikely(i == 0))
1045 DEBUG("%p: reposting %u WRs", (void *)rxq, i);
1047 ret = rxq->recv(rxq->wq, sges, i);
1048 if (unlikely(ret)) {
1049 /* Inability to repost WRs is fatal. */
1050 DEBUG("%p: recv_burst(): failed (ret=%d)",
1055 rxq->elts_head = elts_head;
1056 #ifdef MLX5_PMD_SOFT_COUNTERS
1057 /* Increment packets counter. */
1058 rxq->stats.ipackets += pkts_ret;
1064 * Dummy DPDK callback for TX.
1066 * This function is used to temporarily replace the real callback during
1067 * unsafe control operations on the queue, or in case of error.
1070 * Generic pointer to TX queue structure.
1072 * Packets to transmit.
1074 * Number of packets in array.
1077 * Number of packets successfully transmitted (<= pkts_n).
1080 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
1089 * Dummy DPDK callback for RX.
1091 * This function is used to temporarily replace the real callback during
1092 * unsafe control operations on the queue, or in case of error.
1095 * Generic pointer to RX queue structure.
1097 * Array to store received packets.
1099 * Maximum number of packets in array.
1102 * Number of packets successfully received (<= pkts_n).
1105 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)