mempool: store memory chunks in a list
[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 /* For best performance, this function should not be inlined. */
144 struct ibv_mr *mlx5_mp2mr(struct ibv_pd *, const struct rte_mempool *)
145         __attribute__((noinline));
146
147 /**
148  * Register mempool as a memory region.
149  *
150  * @param pd
151  *   Pointer to protection domain.
152  * @param mp
153  *   Pointer to memory pool.
154  *
155  * @return
156  *   Memory region pointer, NULL in case of error.
157  */
158 struct ibv_mr *
159 mlx5_mp2mr(struct ibv_pd *pd, const struct rte_mempool *mp)
160 {
161         const struct rte_memseg *ms = rte_eal_get_physmem_layout();
162         uintptr_t start = (uintptr_t)STAILQ_FIRST(&mp->mem_list)->addr;
163         uintptr_t end = start + STAILQ_FIRST(&mp->mem_list)->len;
164         unsigned int i;
165
166         DEBUG("mempool %p area start=%p end=%p size=%zu",
167               (const void *)mp, (void *)start, (void *)end,
168               (size_t)(end - start));
169         /* Round start and end to page boundary if found in memory segments. */
170         for (i = 0; (i < RTE_MAX_MEMSEG) && (ms[i].addr != NULL); ++i) {
171                 uintptr_t addr = (uintptr_t)ms[i].addr;
172                 size_t len = ms[i].len;
173                 unsigned int align = ms[i].hugepage_sz;
174
175                 if ((start > addr) && (start < addr + len))
176                         start = RTE_ALIGN_FLOOR(start, align);
177                 if ((end > addr) && (end < addr + len))
178                         end = RTE_ALIGN_CEIL(end, align);
179         }
180         DEBUG("mempool %p using start=%p end=%p size=%zu for MR",
181               (const void *)mp, (void *)start, (void *)end,
182               (size_t)(end - start));
183         return ibv_reg_mr(pd,
184                           (void *)start,
185                           end - start,
186                           IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE);
187 }
188
189 /**
190  * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
191  * the cloned mbuf is allocated is returned instead.
192  *
193  * @param buf
194  *   Pointer to mbuf.
195  *
196  * @return
197  *   Memory pool where data is located for given mbuf.
198  */
199 static struct rte_mempool *
200 txq_mb2mp(struct rte_mbuf *buf)
201 {
202         if (unlikely(RTE_MBUF_INDIRECT(buf)))
203                 return rte_mbuf_from_indirect(buf)->pool;
204         return buf->pool;
205 }
206
207 /**
208  * Get Memory Region (MR) <-> Memory Pool (MP) association from txq->mp2mr[].
209  * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
210  * remove an entry first.
211  *
212  * @param txq
213  *   Pointer to TX queue structure.
214  * @param[in] mp
215  *   Memory Pool for which a Memory Region lkey must be returned.
216  *
217  * @return
218  *   mr->lkey on success, (uint32_t)-1 on failure.
219  */
220 static uint32_t
221 txq_mp2mr(struct txq *txq, const struct rte_mempool *mp)
222 {
223         unsigned int i;
224         struct ibv_mr *mr;
225
226         for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
227                 if (unlikely(txq->mp2mr[i].mp == NULL)) {
228                         /* Unknown MP, add a new MR for it. */
229                         break;
230                 }
231                 if (txq->mp2mr[i].mp == mp) {
232                         assert(txq->mp2mr[i].lkey != (uint32_t)-1);
233                         assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey);
234                         return txq->mp2mr[i].lkey;
235                 }
236         }
237         /* Add a new entry, register MR first. */
238         DEBUG("%p: discovered new memory pool \"%s\" (%p)",
239               (void *)txq, mp->name, (const void *)mp);
240         mr = mlx5_mp2mr(txq->priv->pd, mp);
241         if (unlikely(mr == NULL)) {
242                 DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.",
243                       (void *)txq);
244                 return (uint32_t)-1;
245         }
246         if (unlikely(i == RTE_DIM(txq->mp2mr))) {
247                 /* Table is full, remove oldest entry. */
248                 DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
249                       (void *)txq);
250                 --i;
251                 claim_zero(ibv_dereg_mr(txq->mp2mr[0].mr));
252                 memmove(&txq->mp2mr[0], &txq->mp2mr[1],
253                         (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0])));
254         }
255         /* Store the new entry. */
256         txq->mp2mr[i].mp = mp;
257         txq->mp2mr[i].mr = mr;
258         txq->mp2mr[i].lkey = mr->lkey;
259         DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32,
260               (void *)txq, mp->name, (const void *)mp, txq->mp2mr[i].lkey);
261         return txq->mp2mr[i].lkey;
262 }
263
264 struct txq_mp2mr_mbuf_check_data {
265         int ret;
266 };
267
268 /**
269  * Callback function for rte_mempool_obj_iter() to check whether a given
270  * mempool object looks like a mbuf.
271  *
272  * @param[in] mp
273  *   The mempool pointer
274  * @param[in] arg
275  *   Context data (struct txq_mp2mr_mbuf_check_data). Contains the
276  *   return value.
277  * @param[in] obj
278  *   Object address.
279  * @param index
280  *   Object index, unused.
281  */
282 static void
283 txq_mp2mr_mbuf_check(struct rte_mempool *mp, void *arg, void *obj,
284         uint32_t index __rte_unused)
285 {
286         struct txq_mp2mr_mbuf_check_data *data = arg;
287         struct rte_mbuf *buf = obj;
288
289         /* Check whether mbuf structure fits element size and whether mempool
290          * pointer is valid. */
291         if (sizeof(*buf) > mp->elt_size || buf->pool != mp)
292                 data->ret = -1;
293 }
294
295 /**
296  * Iterator function for rte_mempool_walk() to register existing mempools and
297  * fill the MP to MR cache of a TX queue.
298  *
299  * @param[in] mp
300  *   Memory Pool to register.
301  * @param *arg
302  *   Pointer to TX queue structure.
303  */
304 void
305 txq_mp2mr_iter(struct rte_mempool *mp, void *arg)
306 {
307         struct txq *txq = arg;
308         struct txq_mp2mr_mbuf_check_data data = {
309                 .ret = 0,
310         };
311
312         /* Register mempool only if the first element looks like a mbuf. */
313         if (rte_mempool_obj_iter(mp, txq_mp2mr_mbuf_check, &data) == 0 ||
314                         data.ret == -1)
315                 return;
316         txq_mp2mr(txq, mp);
317 }
318
319 /**
320  * Insert VLAN using mbuf headroom space.
321  *
322  * @param buf
323  *   Buffer for VLAN insertion.
324  *
325  * @return
326  *   0 on success, errno value on failure.
327  */
328 static inline int
329 insert_vlan_sw(struct rte_mbuf *buf)
330 {
331         uintptr_t addr;
332         uint32_t vlan;
333         uint16_t head_room_len = rte_pktmbuf_headroom(buf);
334
335         if (head_room_len < 4)
336                 return EINVAL;
337
338         addr = rte_pktmbuf_mtod(buf, uintptr_t);
339         vlan = htonl(0x81000000 | buf->vlan_tci);
340         memmove((void *)(addr - 4), (void *)addr, 12);
341         memcpy((void *)(addr + 8), &vlan, sizeof(vlan));
342
343         SET_DATA_OFF(buf, head_room_len - 4);
344         DATA_LEN(buf) += 4;
345
346         return 0;
347 }
348
349 #if MLX5_PMD_SGE_WR_N > 1
350
351 /**
352  * Copy scattered mbuf contents to a single linear buffer.
353  *
354  * @param[out] linear
355  *   Linear output buffer.
356  * @param[in] buf
357  *   Scattered input buffer.
358  *
359  * @return
360  *   Number of bytes copied to the output buffer or 0 if not large enough.
361  */
362 static unsigned int
363 linearize_mbuf(linear_t *linear, struct rte_mbuf *buf)
364 {
365         unsigned int size = 0;
366         unsigned int offset;
367
368         do {
369                 unsigned int len = DATA_LEN(buf);
370
371                 offset = size;
372                 size += len;
373                 if (unlikely(size > sizeof(*linear)))
374                         return 0;
375                 memcpy(&(*linear)[offset],
376                        rte_pktmbuf_mtod(buf, uint8_t *),
377                        len);
378                 buf = NEXT(buf);
379         } while (buf != NULL);
380         return size;
381 }
382
383 /**
384  * Handle scattered buffers for mlx5_tx_burst().
385  *
386  * @param txq
387  *   TX queue structure.
388  * @param segs
389  *   Number of segments in buf.
390  * @param elt
391  *   TX queue element to fill.
392  * @param[in] buf
393  *   Buffer to process.
394  * @param elts_head
395  *   Index of the linear buffer to use if necessary (normally txq->elts_head).
396  * @param[out] sges
397  *   Array filled with SGEs on success.
398  *
399  * @return
400  *   A structure containing the processed packet size in bytes and the
401  *   number of SGEs. Both fields are set to (unsigned int)-1 in case of
402  *   failure.
403  */
404 static struct tx_burst_sg_ret {
405         unsigned int length;
406         unsigned int num;
407 }
408 tx_burst_sg(struct txq *txq, unsigned int segs, struct txq_elt *elt,
409             struct rte_mbuf *buf, unsigned int elts_head,
410             struct ibv_sge (*sges)[MLX5_PMD_SGE_WR_N])
411 {
412         unsigned int sent_size = 0;
413         unsigned int j;
414         int linearize = 0;
415
416         /* When there are too many segments, extra segments are
417          * linearized in the last SGE. */
418         if (unlikely(segs > RTE_DIM(*sges))) {
419                 segs = (RTE_DIM(*sges) - 1);
420                 linearize = 1;
421         }
422         /* Update element. */
423         elt->buf = buf;
424         /* Register segments as SGEs. */
425         for (j = 0; (j != segs); ++j) {
426                 struct ibv_sge *sge = &(*sges)[j];
427                 uint32_t lkey;
428
429                 /* Retrieve Memory Region key for this memory pool. */
430                 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
431                 if (unlikely(lkey == (uint32_t)-1)) {
432                         /* MR does not exist. */
433                         DEBUG("%p: unable to get MP <-> MR association",
434                               (void *)txq);
435                         /* Clean up TX element. */
436                         elt->buf = NULL;
437                         goto stop;
438                 }
439                 /* Update SGE. */
440                 sge->addr = rte_pktmbuf_mtod(buf, uintptr_t);
441                 if (txq->priv->vf)
442                         rte_prefetch0((volatile void *)
443                                       (uintptr_t)sge->addr);
444                 sge->length = DATA_LEN(buf);
445                 sge->lkey = lkey;
446                 sent_size += sge->length;
447                 buf = NEXT(buf);
448         }
449         /* If buf is not NULL here and is not going to be linearized,
450          * nb_segs is not valid. */
451         assert(j == segs);
452         assert((buf == NULL) || (linearize));
453         /* Linearize extra segments. */
454         if (linearize) {
455                 struct ibv_sge *sge = &(*sges)[segs];
456                 linear_t *linear = &(*txq->elts_linear)[elts_head];
457                 unsigned int size = linearize_mbuf(linear, buf);
458
459                 assert(segs == (RTE_DIM(*sges) - 1));
460                 if (size == 0) {
461                         /* Invalid packet. */
462                         DEBUG("%p: packet too large to be linearized.",
463                               (void *)txq);
464                         /* Clean up TX element. */
465                         elt->buf = NULL;
466                         goto stop;
467                 }
468                 /* If MLX5_PMD_SGE_WR_N is 1, free mbuf immediately. */
469                 if (RTE_DIM(*sges) == 1) {
470                         do {
471                                 struct rte_mbuf *next = NEXT(buf);
472
473                                 rte_pktmbuf_free_seg(buf);
474                                 buf = next;
475                         } while (buf != NULL);
476                         elt->buf = NULL;
477                 }
478                 /* Update SGE. */
479                 sge->addr = (uintptr_t)&(*linear)[0];
480                 sge->length = size;
481                 sge->lkey = txq->mr_linear->lkey;
482                 sent_size += size;
483                 /* Include last segment. */
484                 segs++;
485         }
486         return (struct tx_burst_sg_ret){
487                 .length = sent_size,
488                 .num = segs,
489         };
490 stop:
491         return (struct tx_burst_sg_ret){
492                 .length = -1,
493                 .num = -1,
494         };
495 }
496
497 #endif /* MLX5_PMD_SGE_WR_N > 1 */
498
499 /**
500  * DPDK callback for TX.
501  *
502  * @param dpdk_txq
503  *   Generic pointer to TX queue structure.
504  * @param[in] pkts
505  *   Packets to transmit.
506  * @param pkts_n
507  *   Number of packets in array.
508  *
509  * @return
510  *   Number of packets successfully transmitted (<= pkts_n).
511  */
512 uint16_t
513 mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
514 {
515         struct txq *txq = (struct txq *)dpdk_txq;
516         unsigned int elts_head = txq->elts_head;
517         const unsigned int elts_n = txq->elts_n;
518         unsigned int elts_comp_cd = txq->elts_comp_cd;
519         unsigned int elts_comp = 0;
520         unsigned int i;
521         unsigned int max;
522         int err;
523         struct rte_mbuf *buf = pkts[0];
524
525         assert(elts_comp_cd != 0);
526         /* Prefetch first packet cacheline. */
527         rte_prefetch0(buf);
528         txq_complete(txq);
529         max = (elts_n - (elts_head - txq->elts_tail));
530         if (max > elts_n)
531                 max -= elts_n;
532         assert(max >= 1);
533         assert(max <= elts_n);
534         /* Always leave one free entry in the ring. */
535         --max;
536         if (max == 0)
537                 return 0;
538         if (max > pkts_n)
539                 max = pkts_n;
540         for (i = 0; (i != max); ++i) {
541                 struct rte_mbuf *buf_next = pkts[i + 1];
542                 unsigned int elts_head_next =
543                         (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
544                 struct txq_elt *elt = &(*txq->elts)[elts_head];
545                 unsigned int segs = NB_SEGS(buf);
546 #ifdef MLX5_PMD_SOFT_COUNTERS
547                 unsigned int sent_size = 0;
548 #endif
549                 uint32_t send_flags = 0;
550 #ifdef HAVE_VERBS_VLAN_INSERTION
551                 int insert_vlan = 0;
552 #endif /* HAVE_VERBS_VLAN_INSERTION */
553
554                 if (i + 1 < max)
555                         rte_prefetch0(buf_next);
556                 /* Request TX completion. */
557                 if (unlikely(--elts_comp_cd == 0)) {
558                         elts_comp_cd = txq->elts_comp_cd_init;
559                         ++elts_comp;
560                         send_flags |= IBV_EXP_QP_BURST_SIGNALED;
561                 }
562                 /* Should we enable HW CKSUM offload */
563                 if (buf->ol_flags &
564                     (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
565                         send_flags |= IBV_EXP_QP_BURST_IP_CSUM;
566                         /* HW does not support checksum offloads at arbitrary
567                          * offsets but automatically recognizes the packet
568                          * type. For inner L3/L4 checksums, only VXLAN (UDP)
569                          * tunnels are currently supported. */
570                         if (RTE_ETH_IS_TUNNEL_PKT(buf->packet_type))
571                                 send_flags |= IBV_EXP_QP_BURST_TUNNEL;
572                 }
573                 if (buf->ol_flags & PKT_TX_VLAN_PKT) {
574 #ifdef HAVE_VERBS_VLAN_INSERTION
575                         if (!txq->priv->mps)
576                                 insert_vlan = 1;
577                         else
578 #endif /* HAVE_VERBS_VLAN_INSERTION */
579                         {
580                                 err = insert_vlan_sw(buf);
581                                 if (unlikely(err))
582                                         goto stop;
583                         }
584                 }
585                 if (likely(segs == 1)) {
586                         uintptr_t addr;
587                         uint32_t length;
588                         uint32_t lkey;
589                         uintptr_t buf_next_addr;
590
591                         /* Retrieve buffer information. */
592                         addr = rte_pktmbuf_mtod(buf, uintptr_t);
593                         length = DATA_LEN(buf);
594                         /* Update element. */
595                         elt->buf = buf;
596                         if (txq->priv->vf)
597                                 rte_prefetch0((volatile void *)
598                                               (uintptr_t)addr);
599                         /* Prefetch next buffer data. */
600                         if (i + 1 < max) {
601                                 buf_next_addr =
602                                         rte_pktmbuf_mtod(buf_next, uintptr_t);
603                                 rte_prefetch0((volatile void *)
604                                               (uintptr_t)buf_next_addr);
605                         }
606                         /* Put packet into send queue. */
607 #if MLX5_PMD_MAX_INLINE > 0
608                         if (length <= txq->max_inline) {
609 #ifdef HAVE_VERBS_VLAN_INSERTION
610                                 if (insert_vlan)
611                                         err = txq->send_pending_inline_vlan
612                                                 (txq->qp,
613                                                  (void *)addr,
614                                                  length,
615                                                  send_flags,
616                                                  &buf->vlan_tci);
617                                 else
618 #endif /* HAVE_VERBS_VLAN_INSERTION */
619                                         err = txq->send_pending_inline
620                                                 (txq->qp,
621                                                  (void *)addr,
622                                                  length,
623                                                  send_flags);
624                         } else
625 #endif
626                         {
627                                 /* Retrieve Memory Region key for this
628                                  * memory pool. */
629                                 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
630                                 if (unlikely(lkey == (uint32_t)-1)) {
631                                         /* MR does not exist. */
632                                         DEBUG("%p: unable to get MP <-> MR"
633                                               " association", (void *)txq);
634                                         /* Clean up TX element. */
635                                         elt->buf = NULL;
636                                         goto stop;
637                                 }
638 #ifdef HAVE_VERBS_VLAN_INSERTION
639                                 if (insert_vlan)
640                                         err = txq->send_pending_vlan
641                                                 (txq->qp,
642                                                  addr,
643                                                  length,
644                                                  lkey,
645                                                  send_flags,
646                                                  &buf->vlan_tci);
647                                 else
648 #endif /* HAVE_VERBS_VLAN_INSERTION */
649                                         err = txq->send_pending
650                                                 (txq->qp,
651                                                  addr,
652                                                  length,
653                                                  lkey,
654                                                  send_flags);
655                         }
656                         if (unlikely(err))
657                                 goto stop;
658 #ifdef MLX5_PMD_SOFT_COUNTERS
659                         sent_size += length;
660 #endif
661                 } else {
662 #if MLX5_PMD_SGE_WR_N > 1
663                         struct ibv_sge sges[MLX5_PMD_SGE_WR_N];
664                         struct tx_burst_sg_ret ret;
665
666                         ret = tx_burst_sg(txq, segs, elt, buf, elts_head,
667                                           &sges);
668                         if (ret.length == (unsigned int)-1)
669                                 goto stop;
670                         /* Put SG list into send queue. */
671 #ifdef HAVE_VERBS_VLAN_INSERTION
672                         if (insert_vlan)
673                                 err = txq->send_pending_sg_list_vlan
674                                         (txq->qp,
675                                          sges,
676                                          ret.num,
677                                          send_flags,
678                                          &buf->vlan_tci);
679                         else
680 #endif /* HAVE_VERBS_VLAN_INSERTION */
681                                 err = txq->send_pending_sg_list
682                                         (txq->qp,
683                                          sges,
684                                          ret.num,
685                                          send_flags);
686                         if (unlikely(err))
687                                 goto stop;
688 #ifdef MLX5_PMD_SOFT_COUNTERS
689                         sent_size += ret.length;
690 #endif
691 #else /* MLX5_PMD_SGE_WR_N > 1 */
692                         DEBUG("%p: TX scattered buffers support not"
693                               " compiled in", (void *)txq);
694                         goto stop;
695 #endif /* MLX5_PMD_SGE_WR_N > 1 */
696                 }
697                 elts_head = elts_head_next;
698                 buf = buf_next;
699 #ifdef MLX5_PMD_SOFT_COUNTERS
700                 /* Increment sent bytes counter. */
701                 txq->stats.obytes += sent_size;
702 #endif
703         }
704 stop:
705         /* Take a shortcut if nothing must be sent. */
706         if (unlikely(i == 0))
707                 return 0;
708 #ifdef MLX5_PMD_SOFT_COUNTERS
709         /* Increment sent packets counter. */
710         txq->stats.opackets += i;
711 #endif
712         /* Ring QP doorbell. */
713         err = txq->send_flush(txq->qp);
714         if (unlikely(err)) {
715                 /* A nonzero value is not supposed to be returned.
716                  * Nothing can be done about it. */
717                 DEBUG("%p: send_flush() failed with error %d",
718                       (void *)txq, err);
719         }
720         txq->elts_head = elts_head;
721         txq->elts_comp += elts_comp;
722         txq->elts_comp_cd = elts_comp_cd;
723         return i;
724 }
725
726 /**
727  * Translate RX completion flags to packet type.
728  *
729  * @param flags
730  *   RX completion flags returned by poll_length_flags().
731  *
732  * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
733  *
734  * @return
735  *   Packet type for struct rte_mbuf.
736  */
737 static inline uint32_t
738 rxq_cq_to_pkt_type(uint32_t flags)
739 {
740         uint32_t pkt_type;
741
742         if (flags & IBV_EXP_CQ_RX_TUNNEL_PACKET)
743                 pkt_type =
744                         TRANSPOSE(flags,
745                                   IBV_EXP_CQ_RX_OUTER_IPV4_PACKET,
746                                   RTE_PTYPE_L3_IPV4) |
747                         TRANSPOSE(flags,
748                                   IBV_EXP_CQ_RX_OUTER_IPV6_PACKET,
749                                   RTE_PTYPE_L3_IPV6) |
750                         TRANSPOSE(flags,
751                                   IBV_EXP_CQ_RX_IPV4_PACKET,
752                                   RTE_PTYPE_INNER_L3_IPV4) |
753                         TRANSPOSE(flags,
754                                   IBV_EXP_CQ_RX_IPV6_PACKET,
755                                   RTE_PTYPE_INNER_L3_IPV6);
756         else
757                 pkt_type =
758                         TRANSPOSE(flags,
759                                   IBV_EXP_CQ_RX_IPV4_PACKET,
760                                   RTE_PTYPE_L3_IPV4) |
761                         TRANSPOSE(flags,
762                                   IBV_EXP_CQ_RX_IPV6_PACKET,
763                                   RTE_PTYPE_L3_IPV6);
764         return pkt_type;
765 }
766
767 /**
768  * Translate RX completion flags to offload flags.
769  *
770  * @param[in] rxq
771  *   Pointer to RX queue structure.
772  * @param flags
773  *   RX completion flags returned by poll_length_flags().
774  *
775  * @return
776  *   Offload flags (ol_flags) for struct rte_mbuf.
777  */
778 static inline uint32_t
779 rxq_cq_to_ol_flags(const struct rxq *rxq, uint32_t flags)
780 {
781         uint32_t ol_flags = 0;
782
783         if (rxq->csum) {
784                 /* Set IP checksum flag only for IPv4/IPv6 packets. */
785                 if (flags &
786                     (IBV_EXP_CQ_RX_IPV4_PACKET | IBV_EXP_CQ_RX_IPV6_PACKET))
787                         ol_flags |=
788                                 TRANSPOSE(~flags,
789                                         IBV_EXP_CQ_RX_IP_CSUM_OK,
790                                         PKT_RX_IP_CKSUM_BAD);
791 #ifdef HAVE_EXP_CQ_RX_TCP_PACKET
792                 /* Set L4 checksum flag only for TCP/UDP packets. */
793                 if (flags &
794                     (IBV_EXP_CQ_RX_TCP_PACKET | IBV_EXP_CQ_RX_UDP_PACKET))
795 #endif /* HAVE_EXP_CQ_RX_TCP_PACKET */
796                         ol_flags |=
797                                 TRANSPOSE(~flags,
798                                         IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK,
799                                         PKT_RX_L4_CKSUM_BAD);
800         }
801         /*
802          * PKT_RX_IP_CKSUM_BAD and PKT_RX_L4_CKSUM_BAD are used in place
803          * of PKT_RX_EIP_CKSUM_BAD because the latter is not functional
804          * (its value is 0).
805          */
806         if ((flags & IBV_EXP_CQ_RX_TUNNEL_PACKET) && (rxq->csum_l2tun))
807                 ol_flags |=
808                         TRANSPOSE(~flags,
809                                   IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK,
810                                   PKT_RX_IP_CKSUM_BAD) |
811                         TRANSPOSE(~flags,
812                                   IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK,
813                                   PKT_RX_L4_CKSUM_BAD);
814         return ol_flags;
815 }
816
817 /**
818  * DPDK callback for RX with scattered packets support.
819  *
820  * @param dpdk_rxq
821  *   Generic pointer to RX queue structure.
822  * @param[out] pkts
823  *   Array to store received packets.
824  * @param pkts_n
825  *   Maximum number of packets in array.
826  *
827  * @return
828  *   Number of packets successfully received (<= pkts_n).
829  */
830 uint16_t
831 mlx5_rx_burst_sp(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
832 {
833         struct rxq *rxq = (struct rxq *)dpdk_rxq;
834         struct rxq_elt_sp (*elts)[rxq->elts_n] = rxq->elts.sp;
835         const unsigned int elts_n = rxq->elts_n;
836         unsigned int elts_head = rxq->elts_head;
837         unsigned int i;
838         unsigned int pkts_ret = 0;
839         int ret;
840
841         if (unlikely(!rxq->sp))
842                 return mlx5_rx_burst(dpdk_rxq, pkts, pkts_n);
843         if (unlikely(elts == NULL)) /* See RTE_DEV_CMD_SET_MTU. */
844                 return 0;
845         for (i = 0; (i != pkts_n); ++i) {
846                 struct rxq_elt_sp *elt = &(*elts)[elts_head];
847                 unsigned int len;
848                 unsigned int pkt_buf_len;
849                 struct rte_mbuf *pkt_buf = NULL; /* Buffer returned in pkts. */
850                 struct rte_mbuf **pkt_buf_next = &pkt_buf;
851                 unsigned int seg_headroom = RTE_PKTMBUF_HEADROOM;
852                 unsigned int j = 0;
853                 uint32_t flags;
854                 uint16_t vlan_tci;
855
856                 /* Sanity checks. */
857                 assert(elts_head < rxq->elts_n);
858                 assert(rxq->elts_head < rxq->elts_n);
859                 ret = rxq->poll(rxq->cq, NULL, NULL, &flags, &vlan_tci);
860                 if (unlikely(ret < 0)) {
861                         struct ibv_wc wc;
862                         int wcs_n;
863
864                         DEBUG("rxq=%p, poll_length() failed (ret=%d)",
865                               (void *)rxq, ret);
866                         /* ibv_poll_cq() must be used in case of failure. */
867                         wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
868                         if (unlikely(wcs_n == 0))
869                                 break;
870                         if (unlikely(wcs_n < 0)) {
871                                 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
872                                       (void *)rxq, wcs_n);
873                                 break;
874                         }
875                         assert(wcs_n == 1);
876                         if (unlikely(wc.status != IBV_WC_SUCCESS)) {
877                                 /* Whatever, just repost the offending WR. */
878                                 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
879                                       " completion status (%d): %s",
880                                       (void *)rxq, wc.wr_id, wc.status,
881                                       ibv_wc_status_str(wc.status));
882 #ifdef MLX5_PMD_SOFT_COUNTERS
883                                 /* Increment dropped packets counter. */
884                                 ++rxq->stats.idropped;
885 #endif
886                                 goto repost;
887                         }
888                         ret = wc.byte_len;
889                 }
890                 if (ret == 0)
891                         break;
892                 assert(ret >= (rxq->crc_present << 2));
893                 len = ret - (rxq->crc_present << 2);
894                 pkt_buf_len = len;
895                 /*
896                  * Replace spent segments with new ones, concatenate and
897                  * return them as pkt_buf.
898                  */
899                 while (1) {
900                         struct ibv_sge *sge = &elt->sges[j];
901                         struct rte_mbuf *seg = elt->bufs[j];
902                         struct rte_mbuf *rep;
903                         unsigned int seg_tailroom;
904
905                         assert(seg != NULL);
906                         /*
907                          * Fetch initial bytes of packet descriptor into a
908                          * cacheline while allocating rep.
909                          */
910                         rte_prefetch0(seg);
911                         rep = rte_mbuf_raw_alloc(rxq->mp);
912                         if (unlikely(rep == NULL)) {
913                                 /*
914                                  * Unable to allocate a replacement mbuf,
915                                  * repost WR.
916                                  */
917                                 DEBUG("rxq=%p: can't allocate a new mbuf",
918                                       (void *)rxq);
919                                 if (pkt_buf != NULL) {
920                                         *pkt_buf_next = NULL;
921                                         rte_pktmbuf_free(pkt_buf);
922                                 }
923                                 /* Increment out of memory counters. */
924                                 ++rxq->stats.rx_nombuf;
925                                 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
926                                 goto repost;
927                         }
928 #ifndef NDEBUG
929                         /* Poison user-modifiable fields in rep. */
930                         NEXT(rep) = (void *)((uintptr_t)-1);
931                         SET_DATA_OFF(rep, 0xdead);
932                         DATA_LEN(rep) = 0xd00d;
933                         PKT_LEN(rep) = 0xdeadd00d;
934                         NB_SEGS(rep) = 0x2a;
935                         PORT(rep) = 0x2a;
936                         rep->ol_flags = -1;
937 #endif
938                         assert(rep->buf_len == seg->buf_len);
939                         assert(rep->buf_len == rxq->mb_len);
940                         /* Reconfigure sge to use rep instead of seg. */
941                         assert(sge->lkey == rxq->mr->lkey);
942                         sge->addr = ((uintptr_t)rep->buf_addr + seg_headroom);
943                         elt->bufs[j] = rep;
944                         ++j;
945                         /* Update pkt_buf if it's the first segment, or link
946                          * seg to the previous one and update pkt_buf_next. */
947                         *pkt_buf_next = seg;
948                         pkt_buf_next = &NEXT(seg);
949                         /* Update seg information. */
950                         seg_tailroom = (seg->buf_len - seg_headroom);
951                         assert(sge->length == seg_tailroom);
952                         SET_DATA_OFF(seg, seg_headroom);
953                         if (likely(len <= seg_tailroom)) {
954                                 /* Last segment. */
955                                 DATA_LEN(seg) = len;
956                                 PKT_LEN(seg) = len;
957                                 /* Sanity check. */
958                                 assert(rte_pktmbuf_headroom(seg) ==
959                                        seg_headroom);
960                                 assert(rte_pktmbuf_tailroom(seg) ==
961                                        (seg_tailroom - len));
962                                 break;
963                         }
964                         DATA_LEN(seg) = seg_tailroom;
965                         PKT_LEN(seg) = seg_tailroom;
966                         /* Sanity check. */
967                         assert(rte_pktmbuf_headroom(seg) == seg_headroom);
968                         assert(rte_pktmbuf_tailroom(seg) == 0);
969                         /* Fix len and clear headroom for next segments. */
970                         len -= seg_tailroom;
971                         seg_headroom = 0;
972                 }
973                 /* Update head and tail segments. */
974                 *pkt_buf_next = NULL;
975                 assert(pkt_buf != NULL);
976                 assert(j != 0);
977                 NB_SEGS(pkt_buf) = j;
978                 PORT(pkt_buf) = rxq->port_id;
979                 PKT_LEN(pkt_buf) = pkt_buf_len;
980                 if (rxq->csum | rxq->csum_l2tun | rxq->vlan_strip) {
981                         pkt_buf->packet_type = rxq_cq_to_pkt_type(flags);
982                         pkt_buf->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
983 #ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
984                         if (flags & IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1) {
985                                 pkt_buf->ol_flags |= PKT_RX_VLAN_PKT;
986                                 pkt_buf->vlan_tci = vlan_tci;
987                         }
988 #endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
989                 }
990
991                 /* Return packet. */
992                 *(pkts++) = pkt_buf;
993                 ++pkts_ret;
994 #ifdef MLX5_PMD_SOFT_COUNTERS
995                 /* Increment bytes counter. */
996                 rxq->stats.ibytes += pkt_buf_len;
997 #endif
998 repost:
999                 ret = rxq->recv(rxq->wq, elt->sges, RTE_DIM(elt->sges));
1000                 if (unlikely(ret)) {
1001                         /* Inability to repost WRs is fatal. */
1002                         DEBUG("%p: recv_sg_list(): failed (ret=%d)",
1003                               (void *)rxq->priv,
1004                               ret);
1005                         abort();
1006                 }
1007                 if (++elts_head >= elts_n)
1008                         elts_head = 0;
1009                 continue;
1010         }
1011         if (unlikely(i == 0))
1012                 return 0;
1013         rxq->elts_head = elts_head;
1014 #ifdef MLX5_PMD_SOFT_COUNTERS
1015         /* Increment packets counter. */
1016         rxq->stats.ipackets += pkts_ret;
1017 #endif
1018         return pkts_ret;
1019 }
1020
1021 /**
1022  * DPDK callback for RX.
1023  *
1024  * The following function is the same as mlx5_rx_burst_sp(), except it doesn't
1025  * manage scattered packets. Improves performance when MRU is lower than the
1026  * size of the first segment.
1027  *
1028  * @param dpdk_rxq
1029  *   Generic pointer to RX queue structure.
1030  * @param[out] pkts
1031  *   Array to store received packets.
1032  * @param pkts_n
1033  *   Maximum number of packets in array.
1034  *
1035  * @return
1036  *   Number of packets successfully received (<= pkts_n).
1037  */
1038 uint16_t
1039 mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1040 {
1041         struct rxq *rxq = (struct rxq *)dpdk_rxq;
1042         struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts.no_sp;
1043         const unsigned int elts_n = rxq->elts_n;
1044         unsigned int elts_head = rxq->elts_head;
1045         struct ibv_sge sges[pkts_n];
1046         unsigned int i;
1047         unsigned int pkts_ret = 0;
1048         int ret;
1049
1050         if (unlikely(rxq->sp))
1051                 return mlx5_rx_burst_sp(dpdk_rxq, pkts, pkts_n);
1052         for (i = 0; (i != pkts_n); ++i) {
1053                 struct rxq_elt *elt = &(*elts)[elts_head];
1054                 unsigned int len;
1055                 struct rte_mbuf *seg = elt->buf;
1056                 struct rte_mbuf *rep;
1057                 uint32_t flags;
1058                 uint16_t vlan_tci;
1059
1060                 /* Sanity checks. */
1061                 assert(seg != NULL);
1062                 assert(elts_head < rxq->elts_n);
1063                 assert(rxq->elts_head < rxq->elts_n);
1064                 /*
1065                  * Fetch initial bytes of packet descriptor into a
1066                  * cacheline while allocating rep.
1067                  */
1068                 rte_prefetch0(seg);
1069                 rte_prefetch0(&seg->cacheline1);
1070                 ret = rxq->poll(rxq->cq, NULL, NULL, &flags, &vlan_tci);
1071                 if (unlikely(ret < 0)) {
1072                         struct ibv_wc wc;
1073                         int wcs_n;
1074
1075                         DEBUG("rxq=%p, poll_length() failed (ret=%d)",
1076                               (void *)rxq, ret);
1077                         /* ibv_poll_cq() must be used in case of failure. */
1078                         wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
1079                         if (unlikely(wcs_n == 0))
1080                                 break;
1081                         if (unlikely(wcs_n < 0)) {
1082                                 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
1083                                       (void *)rxq, wcs_n);
1084                                 break;
1085                         }
1086                         assert(wcs_n == 1);
1087                         if (unlikely(wc.status != IBV_WC_SUCCESS)) {
1088                                 /* Whatever, just repost the offending WR. */
1089                                 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
1090                                       " completion status (%d): %s",
1091                                       (void *)rxq, wc.wr_id, wc.status,
1092                                       ibv_wc_status_str(wc.status));
1093 #ifdef MLX5_PMD_SOFT_COUNTERS
1094                                 /* Increment dropped packets counter. */
1095                                 ++rxq->stats.idropped;
1096 #endif
1097                                 /* Add SGE to array for repost. */
1098                                 sges[i] = elt->sge;
1099                                 goto repost;
1100                         }
1101                         ret = wc.byte_len;
1102                 }
1103                 if (ret == 0)
1104                         break;
1105                 assert(ret >= (rxq->crc_present << 2));
1106                 len = ret - (rxq->crc_present << 2);
1107                 rep = rte_mbuf_raw_alloc(rxq->mp);
1108                 if (unlikely(rep == NULL)) {
1109                         /*
1110                          * Unable to allocate a replacement mbuf,
1111                          * repost WR.
1112                          */
1113                         DEBUG("rxq=%p: can't allocate a new mbuf",
1114                               (void *)rxq);
1115                         /* Increment out of memory counters. */
1116                         ++rxq->stats.rx_nombuf;
1117                         ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
1118                         goto repost;
1119                 }
1120
1121                 /* Reconfigure sge to use rep instead of seg. */
1122                 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
1123                 assert(elt->sge.lkey == rxq->mr->lkey);
1124                 elt->buf = rep;
1125
1126                 /* Add SGE to array for repost. */
1127                 sges[i] = elt->sge;
1128
1129                 /* Update seg information. */
1130                 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
1131                 NB_SEGS(seg) = 1;
1132                 PORT(seg) = rxq->port_id;
1133                 NEXT(seg) = NULL;
1134                 PKT_LEN(seg) = len;
1135                 DATA_LEN(seg) = len;
1136                 if (rxq->csum | rxq->csum_l2tun | rxq->vlan_strip) {
1137                         seg->packet_type = rxq_cq_to_pkt_type(flags);
1138                         seg->ol_flags = rxq_cq_to_ol_flags(rxq, flags);
1139 #ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
1140                         if (flags & IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1) {
1141                                 seg->ol_flags |= PKT_RX_VLAN_PKT;
1142                                 seg->vlan_tci = vlan_tci;
1143                         }
1144 #endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
1145                 }
1146                 /* Return packet. */
1147                 *(pkts++) = seg;
1148                 ++pkts_ret;
1149 #ifdef MLX5_PMD_SOFT_COUNTERS
1150                 /* Increment bytes counter. */
1151                 rxq->stats.ibytes += len;
1152 #endif
1153 repost:
1154                 if (++elts_head >= elts_n)
1155                         elts_head = 0;
1156                 continue;
1157         }
1158         if (unlikely(i == 0))
1159                 return 0;
1160         /* Repost WRs. */
1161 #ifdef DEBUG_RECV
1162         DEBUG("%p: reposting %u WRs", (void *)rxq, i);
1163 #endif
1164         ret = rxq->recv(rxq->wq, sges, i);
1165         if (unlikely(ret)) {
1166                 /* Inability to repost WRs is fatal. */
1167                 DEBUG("%p: recv_burst(): failed (ret=%d)",
1168                       (void *)rxq->priv,
1169                       ret);
1170                 abort();
1171         }
1172         rxq->elts_head = elts_head;
1173 #ifdef MLX5_PMD_SOFT_COUNTERS
1174         /* Increment packets counter. */
1175         rxq->stats.ipackets += pkts_ret;
1176 #endif
1177         return pkts_ret;
1178 }
1179
1180 /**
1181  * Dummy DPDK callback for TX.
1182  *
1183  * This function is used to temporarily replace the real callback during
1184  * unsafe control operations on the queue, or in case of error.
1185  *
1186  * @param dpdk_txq
1187  *   Generic pointer to TX queue structure.
1188  * @param[in] pkts
1189  *   Packets to transmit.
1190  * @param pkts_n
1191  *   Number of packets in array.
1192  *
1193  * @return
1194  *   Number of packets successfully transmitted (<= pkts_n).
1195  */
1196 uint16_t
1197 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
1198 {
1199         (void)dpdk_txq;
1200         (void)pkts;
1201         (void)pkts_n;
1202         return 0;
1203 }
1204
1205 /**
1206  * Dummy DPDK callback for RX.
1207  *
1208  * This function is used to temporarily replace the real callback during
1209  * unsafe control operations on the queue, or in case of error.
1210  *
1211  * @param dpdk_rxq
1212  *   Generic pointer to RX queue structure.
1213  * @param[out] pkts
1214  *   Array to store received packets.
1215  * @param pkts_n
1216  *   Maximum number of packets in array.
1217  *
1218  * @return
1219  *   Number of packets successfully received (<= pkts_n).
1220  */
1221 uint16_t
1222 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1223 {
1224         (void)dpdk_rxq;
1225         (void)pkts;
1226         (void)pkts_n;
1227         return 0;
1228 }