net/mlx5: remove Rx scatter support
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2015 6WIND S.A.
5  *   Copyright 2015 Mellanox.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <assert.h>
35 #include <stdint.h>
36 #include <string.h>
37 #include <stdlib.h>
38
39 /* Verbs header. */
40 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
41 #ifdef PEDANTIC
42 #pragma GCC diagnostic ignored "-pedantic"
43 #endif
44 #include <infiniband/verbs.h>
45 #ifdef PEDANTIC
46 #pragma GCC diagnostic error "-pedantic"
47 #endif
48
49 /* DPDK headers don't like -pedantic. */
50 #ifdef PEDANTIC
51 #pragma GCC diagnostic ignored "-pedantic"
52 #endif
53 #include <rte_mbuf.h>
54 #include <rte_mempool.h>
55 #include <rte_prefetch.h>
56 #include <rte_common.h>
57 #include <rte_branch_prediction.h>
58 #include <rte_memory.h>
59 #ifdef PEDANTIC
60 #pragma GCC diagnostic error "-pedantic"
61 #endif
62
63 #include "mlx5.h"
64 #include "mlx5_utils.h"
65 #include "mlx5_rxtx.h"
66 #include "mlx5_autoconf.h"
67 #include "mlx5_defs.h"
68
69 /**
70  * Manage TX completions.
71  *
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.
76  *
77  * @param txq
78  *   Pointer to TX queue structure.
79  *
80  * @return
81  *   0 on success, -1 on failure.
82  */
83 static int
84 txq_complete(struct txq *txq)
85 {
86         unsigned int elts_comp = txq->elts_comp;
87         unsigned int elts_tail = txq->elts_tail;
88         unsigned int elts_free = txq->elts_tail;
89         const unsigned int elts_n = txq->elts_n;
90         int wcs_n;
91
92         if (unlikely(elts_comp == 0))
93                 return 0;
94 #ifdef DEBUG_SEND
95         DEBUG("%p: processing %u work requests completions",
96               (void *)txq, elts_comp);
97 #endif
98         wcs_n = txq->poll_cnt(txq->cq, elts_comp);
99         if (unlikely(wcs_n == 0))
100                 return 0;
101         if (unlikely(wcs_n < 0)) {
102                 DEBUG("%p: ibv_poll_cq() failed (wcs_n=%d)",
103                       (void *)txq, wcs_n);
104                 return -1;
105         }
106         elts_comp -= wcs_n;
107         assert(elts_comp <= txq->elts_comp);
108         /*
109          * Assume WC status is successful as nothing can be done about it
110          * anyway.
111          */
112         elts_tail += wcs_n * txq->elts_comp_cd_init;
113         if (elts_tail >= elts_n)
114                 elts_tail -= elts_n;
115
116         while (elts_free != elts_tail) {
117                 struct txq_elt *elt = &(*txq->elts)[elts_free];
118                 unsigned int elts_free_next =
119                         (((elts_free + 1) == elts_n) ? 0 : elts_free + 1);
120                 struct rte_mbuf *tmp = elt->buf;
121                 struct txq_elt *elt_next = &(*txq->elts)[elts_free_next];
122
123 #ifndef NDEBUG
124                 /* Poisoning. */
125                 memset(elt, 0x66, sizeof(*elt));
126 #endif
127                 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
128                 /* Faster than rte_pktmbuf_free(). */
129                 do {
130                         struct rte_mbuf *next = NEXT(tmp);
131
132                         rte_pktmbuf_free_seg(tmp);
133                         tmp = next;
134                 } while (tmp != NULL);
135                 elts_free = elts_free_next;
136         }
137
138         txq->elts_tail = elts_tail;
139         txq->elts_comp = elts_comp;
140         return 0;
141 }
142
143 /**
144  * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
145  * the cloned mbuf is allocated is returned instead.
146  *
147  * @param buf
148  *   Pointer to mbuf.
149  *
150  * @return
151  *   Memory pool where data is located for given mbuf.
152  */
153 static struct rte_mempool *
154 txq_mb2mp(struct rte_mbuf *buf)
155 {
156         if (unlikely(RTE_MBUF_INDIRECT(buf)))
157                 return rte_mbuf_from_indirect(buf)->pool;
158         return buf->pool;
159 }
160
161 static inline uint32_t
162 txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
163         __attribute__((always_inline));
164
165 /**
166  * Get Memory Region (MR) <-> Memory Pool (MP) association from txq->mp2mr[].
167  * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
168  * remove an entry first.
169  *
170  * @param txq
171  *   Pointer to TX queue structure.
172  * @param[in] mp
173  *   Memory Pool for which a Memory Region lkey must be returned.
174  *
175  * @return
176  *   mr->lkey on success, (uint32_t)-1 on failure.
177  */
178 static inline uint32_t
179 txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
180 {
181         unsigned int i;
182         uint32_t lkey = (uint32_t)-1;
183
184         for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
185                 if (unlikely(txq->mp2mr[i].mp == NULL)) {
186                         /* Unknown MP, add a new MR for it. */
187                         break;
188                 }
189                 if (txq->mp2mr[i].mp == mp) {
190                         assert(txq->mp2mr[i].lkey != (uint32_t)-1);
191                         assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey);
192                         lkey = txq->mp2mr[i].lkey;
193                         break;
194                 }
195         }
196         if (unlikely(lkey == (uint32_t)-1))
197                 lkey = txq_mp2mr_reg(txq, mp, i);
198         return lkey;
199 }
200
201 /**
202  * Insert VLAN using mbuf headroom space.
203  *
204  * @param buf
205  *   Buffer for VLAN insertion.
206  *
207  * @return
208  *   0 on success, errno value on failure.
209  */
210 static inline int
211 insert_vlan_sw(struct rte_mbuf *buf)
212 {
213         uintptr_t addr;
214         uint32_t vlan;
215         uint16_t head_room_len = rte_pktmbuf_headroom(buf);
216
217         if (head_room_len < 4)
218                 return EINVAL;
219
220         addr = rte_pktmbuf_mtod(buf, uintptr_t);
221         vlan = htonl(0x81000000 | buf->vlan_tci);
222         memmove((void *)(addr - 4), (void *)addr, 12);
223         memcpy((void *)(addr + 8), &vlan, sizeof(vlan));
224
225         SET_DATA_OFF(buf, head_room_len - 4);
226         DATA_LEN(buf) += 4;
227
228         return 0;
229 }
230
231 /**
232  * DPDK callback for TX.
233  *
234  * @param dpdk_txq
235  *   Generic pointer to TX queue structure.
236  * @param[in] pkts
237  *   Packets to transmit.
238  * @param pkts_n
239  *   Number of packets in array.
240  *
241  * @return
242  *   Number of packets successfully transmitted (<= pkts_n).
243  */
244 uint16_t
245 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
246 {
247         struct txq *txq = (struct txq *)dpdk_txq;
248         unsigned int elts_head = txq->elts_head;
249         const unsigned int elts_n = txq->elts_n;
250         unsigned int elts_comp_cd = txq->elts_comp_cd;
251         unsigned int elts_comp = 0;
252         unsigned int i;
253         unsigned int max;
254         int err;
255         struct rte_mbuf *buf = pkts[0];
256
257         assert(elts_comp_cd != 0);
258         /* Prefetch first packet cacheline. */
259         rte_prefetch0(buf);
260         txq_complete(txq);
261         max = (elts_n - (elts_head - txq->elts_tail));
262         if (max > elts_n)
263                 max -= elts_n;
264         assert(max >= 1);
265         assert(max <= elts_n);
266         /* Always leave one free entry in the ring. */
267         --max;
268         if (max == 0)
269                 return 0;
270         if (max > pkts_n)
271                 max = pkts_n;
272         for (i = 0; (i != max); ++i) {
273                 struct rte_mbuf *buf_next = pkts[i + 1];
274                 unsigned int elts_head_next =
275                         (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
276                 struct txq_elt *elt = &(*txq->elts)[elts_head];
277                 uint32_t send_flags = 0;
278 #ifdef HAVE_VERBS_VLAN_INSERTION
279                 int insert_vlan = 0;
280 #endif /* HAVE_VERBS_VLAN_INSERTION */
281                 uintptr_t addr;
282                 uint32_t length;
283                 uint32_t lkey;
284                 uintptr_t buf_next_addr;
285
286                 if (i + 1 < max)
287                         rte_prefetch0(buf_next);
288                 /* Request TX completion. */
289                 if (unlikely(--elts_comp_cd == 0)) {
290                         elts_comp_cd = txq->elts_comp_cd_init;
291                         ++elts_comp;
292                         send_flags |= IBV_EXP_QP_BURST_SIGNALED;
293                 }
294                 /* Should we enable HW CKSUM offload */
295                 if (buf->ol_flags &
296                     (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
297                         send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
298                         /* HW does not support checksum offloads at arbitrary
299                          * offsets but automatically recognizes the packet
300                          * type. For inner L3/L4 checksums, only VXLAN (UDP)
301                          * tunnels are currently supported. */
302                         if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
303                                 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
304                 }
305                 if (buf->ol_flags & PKT_TX_VLAN_PKT) {
306 #ifdef HAVE_VERBS_VLAN_INSERTION
307                         if (!txq->priv->mps)
308                                 insert_vlan = 1;
309                         else
310 #endif /* HAVE_VERBS_VLAN_INSERTION */
311                         {
312                                 err = insert_vlan_sw(buf);
313                                 if (unlikely(err))
314                                         goto stop;
315                         }
316                 }
317                 /* Retrieve buffer information. */
318                 addr = rte_pktmbuf_mtod(buf, uintptr_t);
319                 length = DATA_LEN(buf);
320                 /* Update element. */
321                 elt->buf = buf;
322                 if (txq->priv->sriov)
323                         rte_prefetch0((volatile void *)
324                                       (uintptr_t)addr);
325                 /* Prefetch next buffer data. */
326                 if (i + 1 < max) {
327                         buf_next_addr =
328                                 rte_pktmbuf_mtod(buf_next, uintptr_t);
329                         rte_prefetch0((volatile void *)
330                                       (uintptr_t)buf_next_addr);
331                 }
332                 /* Put packet into send queue. */
333 #if MLX5_PMD_MAX_INLINE > 0
334                 if (length <= txq->max_inline) {
335 #ifdef HAVE_VERBS_VLAN_INSERTION
336                         if (insert_vlan)
337                                 err = txq->send_pending_inline_vlan
338                                         (txq->qp,
339                                          (void *)addr,
340                                          length,
341                                          send_flags,
342                                          &buf->vlan_tci);
343                         else
344 #endif /* HAVE_VERBS_VLAN_INSERTION */
345                                 err = txq->send_pending_inline
346                                         (txq->qp,
347                                          (void *)addr,
348                                          length,
349                                          send_flags);
350                 } else
351 #endif
352                 {
353                         /*
354                          * Retrieve Memory Region key for this
355                          * memory pool.
356                          */
357                         lkey = txq_mp2mr(txq, txq_mb2mp(buf));
358                         if (unlikely(lkey == (uint32_t)-1)) {
359                                 /* MR does not exist. */
360                                 DEBUG("%p: unable to get MP <-> MR"
361                                       " association", (void *)txq);
362                                 /* Clean up TX element. */
363                                 elt->buf = NULL;
364                                 goto stop;
365                         }
366 #ifdef HAVE_VERBS_VLAN_INSERTION
367                         if (insert_vlan)
368                                 err = txq->send_pending_vlan
369                                         (txq->qp,
370                                          addr,
371                                          length,
372                                          lkey,
373                                          send_flags,
374                                          &buf->vlan_tci);
375                         else
376 #endif /* HAVE_VERBS_VLAN_INSERTION */
377                                 err = txq->send_pending
378                                         (txq->qp,
379                                          addr,
380                                          length,
381                                          lkey,
382                                          send_flags);
383                 }
384                 if (unlikely(err))
385                         goto stop;
386 #ifdef MLX5_PMD_SOFT_COUNTERS
387                 /* Increment sent bytes counter. */
388                 txq->stats.obytes += length;
389 #endif
390 stop:
391                 elts_head = elts_head_next;
392                 buf = buf_next;
393         }
394         /* Take a shortcut if nothing must be sent. */
395         if (unlikely(i == 0))
396                 return 0;
397 #ifdef MLX5_PMD_SOFT_COUNTERS
398         /* Increment sent packets counter. */
399         txq->stats.opackets += i;
400 #endif
401         /* Ring QP doorbell. */
402         err = txq->send_flush(txq->qp);
403         if (unlikely(err)) {
404                 /* A nonzero value is not supposed to be returned.
405                  * Nothing can be done about it. */
406                 DEBUG("%p: send_flush() failed with error %d",
407                       (void *)txq, err);
408         }
409         txq->elts_head = elts_head;
410         txq->elts_comp += elts_comp;
411         txq->elts_comp_cd = elts_comp_cd;
412         return i;
413 }
414
415 /**
416  * Translate RX completion flags to packet type.
417  *
418  * @param flags
419  *   RX completion flags returned by poll_length_flags().
420  *
421  * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
422  *
423  * @return
424  *   Packet type for struct rte_mbuf.
425  */
426 static inline uint32_t
427 rxq_cq_to_pkt_type(uint32_t flags)
428 {
429         uint32_t pkt_type;
430
431         if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
432                 pkt_type =
433                         TRANSPOSE(flags,
434                                   IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
435                                   RTE_PTYPE_L3_IPV4) |
436                         TRANSPOSE(flags,
437                                   IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
438                                   RTE_PTYPE_L3_IPV6) |
439                         TRANSPOSE(flags,
440                                   IBV_EXP_CQ_RX_IPV4_PACKET,
441                                   RTE_PTYPE_INNER_L3_IPV4) |
442                         TRANSPOSE(flags,
443                                   IBV_EXP_CQ_RX_IPV6_PACKET,
444                                   RTE_PTYPE_INNER_L3_IPV6);
445         else
446                 pkt_type =
447                         TRANSPOSE(flags,
448                                   IBV_EXP_CQ_RX_IPV4_PACKET,
449                                   RTE_PTYPE_L3_IPV4) |
450                         TRANSPOSE(flags,
451                                   IBV_EXP_CQ_RX_IPV6_PACKET,
452                                   RTE_PTYPE_L3_IPV6);
453         return pkt_type;
454 }
455
456 /**
457  * Translate RX completion flags to offload flags.
458  *
459  * @param[in] rxq
460  *   Pointer to RX queue structure.
461  * @param flags
462  *   RX completion flags returned by poll_length_flags().
463  *
464  * @return
465  *   Offload flags (ol_flags) for struct rte_mbuf.
466  */
467 static inline uint32_t
468 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
469 {
470         uint32_t ol_flags = 0;
471
472         if (rxq->csum) {
473                 /* Set IP checksum flag only for IPv4/IPv6 packets. */
474                 if (flags &
475                     (IBV_EXP_CQ_RX_IPV4_PACKET | IBV_EXP_CQ_RX_IPV6_PACKET))
476                         ol_flags |=
477                                 TRANSPOSE(~flags,
478                                         IBV_EXP_CQ_RX_IP_CSUM_OK,
479                                         PKT_RX_IP_CKSUM_BAD);
480 #ifdef HAVE_EXP_CQ_RX_TCP_PACKET
481                 /* Set L4 checksum flag only for TCP/UDP packets. */
482                 if (flags &
483                     (IBV_EXP_CQ_RX_TCP_PACKET | IBV_EXP_CQ_RX_UDP_PACKET))
484 #endif /* HAVE_EXP_CQ_RX_TCP_PACKET */
485                         ol_flags |=
486                                 TRANSPOSE(~flags,
487                                         IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
488                                         PKT_RX_L4_CKSUM_BAD);
489         }
490         /*
491          * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
492          * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
493          * (its value is 0).
494          */
495         if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
496                 ol_flags |=
497                         TRANSPOSE(~flags,
498                                   IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
499                                   PKT_RX_IP_CKSUM_BAD) |
500                         TRANSPOSE(~flags,
501                                   IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
502                                   PKT_RX_L4_CKSUM_BAD);
503         return ol_flags;
504 }
505
506 /**
507  * DPDK callback for RX.
508  *
509  * @param dpdk_rxq
510  *   Generic pointer to RX queue structure.
511  * @param[out] pkts
512  *   Array to store received packets.
513  * @param pkts_n
514  *   Maximum number of packets in array.
515  *
516  * @return
517  *   Number of packets successfully received (<= pkts_n).
518  */
519 uint16_t
520 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
521 {
522         struct rxq *rxq = (struct rxq *)dpdk_rxq;
523         struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts;
524         const unsigned int elts_n = rxq->elts_n;
525         unsigned int elts_head = rxq->elts_head;
526         struct ibv_sge sges[pkts_n];
527         unsigned int i;
528         unsigned int pkts_ret = 0;
529         int ret;
530
531         for (i = 0; (i != pkts_n); ++i) {
532                 struct rxq_elt *elt = &(*elts)[elts_head];
533                 unsigned int len;
534                 struct rte_mbuf *seg = elt->buf;
535                 struct rte_mbuf *rep;
536                 uint32_t flags;
537                 uint16_t vlan_tci;
538
539                 /* Sanity checks. */
540                 assert(seg != NULL);
541                 assert(elts_head < rxq->elts_n);
542                 assert(rxq->elts_head < rxq->elts_n);
543                 /*
544                  * Fetch initial bytes of packet descriptor into a
545                  * cacheline while allocating rep.
546                  */
547                 rte_mbuf_prefetch_part1(seg);
548                 rte_mbuf_prefetch_part2(seg);
549                 ret = rxq->poll(rxq->cq, NULL, NULL, &flags, &vlan_tci);
550                 if (unlikely(ret < 0)) {
551                         struct ibv_wc wc;
552                         int wcs_n;
553
554                         DEBUG("rxq=%p, poll_length() failed (ret=%d)",
555                               (void *)rxq, ret);
556                         /* ibv_poll_cq() must be used in case of failure. */
557                         wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
558                         if (unlikely(wcs_n == 0))
559                                 break;
560                         if (unlikely(wcs_n < 0)) {
561                                 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
562                                       (void *)rxq, wcs_n);
563                                 break;
564                         }
565                         assert(wcs_n == 1);
566                         if (unlikely(wc.status != IBV_WC_SUCCESS)) {
567                                 /* Whatever, just repost the offending WR. */
568                                 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
569                                       " completion status (%d): %s",
570                                       (void *)rxq, wc.wr_id, wc.status,
571                                       ibv_wc_status_str(wc.status));
572 #ifdef MLX5_PMD_SOFT_COUNTERS
573                                 /* Increment dropped packets counter. */
574                                 ++rxq->stats.idropped;
575 #endif
576                                 /* Add SGE to array for repost. */
577                                 sges[i] = elt->sge;
578                                 goto repost;
579                         }
580                         ret = wc.byte_len;
581                 }
582                 if (ret == 0)
583                         break;
584                 assert(ret >= (rxq->crc_present << 2));
585                 len = ret - (rxq->crc_present << 2);
586                 rep = rte_mbuf_raw_alloc(rxq->mp);
587                 if (unlikely(rep == NULL)) {
588                         /*
589                          * Unable to allocate a replacement mbuf,
590                          * repost WR.
591                          */
592                         DEBUG("rxq=%p: can't allocate a new mbuf",
593                               (void *)rxq);
594                         /* Increment out of memory counters. */
595                         ++rxq->stats.rx_nombuf;
596                         ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
597                         goto repost;
598                 }
599
600                 /* Reconfigure sge to use rep instead of seg. */
601                 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
602                 assert(elt->sge.lkey == rxq->mr->lkey);
603                 elt->buf = rep;
604
605                 /* Add SGE to array for repost. */
606                 sges[i] = elt->sge;
607
608                 /* Update seg information. */
609                 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
610                 NB_SEGS(seg) = 1;
611                 PORT(seg) = rxq->port_id;
612                 NEXT(seg) = NULL;
613                 PKT_LEN(seg) = len;
614                 DATA_LEN(seg) = len;
615                 if (rxq->csum | rxq->csum_l2tun | rxq->vlan_strip) {
616                         seg->packet_type = rxq_cq_to_pkt_type(flags);
617                         seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
618 #ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
619                         if (flags & IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1) {
620                                 seg->ol_flags |= PKT_RX_VLAN_PKT |
621                                         PKT_RX_VLAN_STRIPPED;
622                                 seg->vlan_tci = vlan_tci;
623                         }
624 #endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
625                 }
626                 /* Return packet. */
627                 *(pkts++) = seg;
628                 ++pkts_ret;
629 #ifdef MLX5_PMD_SOFT_COUNTERS
630                 /* Increment bytes counter. */
631                 rxq->stats.ibytes += len;
632 #endif
633 repost:
634                 if (++elts_head >= elts_n)
635                         elts_head = 0;
636                 continue;
637         }
638         if (unlikely(i == 0))
639                 return 0;
640         /* Repost WRs. */
641 #ifdef DEBUG_RECV
642         DEBUG("%p: reposting %u WRs", (void *)rxq, i);
643 #endif
644         ret = rxq->recv(rxq->wq, sges, i);
645         if (unlikely(ret)) {
646                 /* Inability to repost WRs is fatal. */
647                 DEBUG("%p: recv_burst(): failed (ret=%d)",
648                       (void *)rxq->priv,
649                       ret);
650                 abort();
651         }
652         rxq->elts_head = elts_head;
653 #ifdef MLX5_PMD_SOFT_COUNTERS
654         /* Increment packets counter. */
655         rxq->stats.ipackets += pkts_ret;
656 #endif
657         return pkts_ret;
658 }
659
660 /**
661  * Dummy DPDK callback for TX.
662  *
663  * This function is used to temporarily replace the real callback during
664  * unsafe control operations on the queue, or in case of error.
665  *
666  * @param dpdk_txq
667  *   Generic pointer to TX queue structure.
668  * @param[in] pkts
669  *   Packets to transmit.
670  * @param pkts_n
671  *   Number of packets in array.
672  *
673  * @return
674  *   Number of packets successfully transmitted (<= pkts_n).
675  */
676 uint16_t
677 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
678 {
679         (void)dpdk_txq;
680         (void)pkts;
681         (void)pkts_n;
682         return 0;
683 }
684
685 /**
686  * Dummy DPDK callback for RX.
687  *
688  * This function is used to temporarily replace the real callback during
689  * unsafe control operations on the queue, or in case of error.
690  *
691  * @param dpdk_rxq
692  *   Generic pointer to RX queue structure.
693  * @param[out] pkts
694  *   Array to store received packets.
695  * @param pkts_n
696  *   Maximum number of packets in array.
697  *
698  * @return
699  *   Number of packets successfully received (<= pkts_n).
700  */
701 uint16_t
702 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
703 {
704         (void)dpdk_rxq;
705         (void)pkts;
706         (void)pkts_n;
707         return 0;
708 }