net/ark: add Rx initial version
[dpdk.git] / drivers / net / ark / ark_ethdev_rx.c
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright (c) 2015-2017 Atomic Rules LLC
5  * All rights reserved.
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 copyright holder 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 <unistd.h>
35
36 #include "ark_ethdev_rx.h"
37 #include "ark_global.h"
38 #include "ark_logs.h"
39 #include "ark_ethdev.h"
40 #include "ark_mpu.h"
41 #include "ark_udm.h"
42
43 #define ARK_RX_META_SIZE 32
44 #define ARK_RX_META_OFFSET (RTE_PKTMBUF_HEADROOM - ARK_RX_META_SIZE)
45 #define ARK_RX_MAX_NOCHAIN (RTE_MBUF_DEFAULT_DATAROOM)
46
47 /* Forward declarations */
48 struct ark_rx_queue;
49 struct ark_rx_meta;
50
51 static void dump_mbuf_data(struct rte_mbuf *mbuf, uint16_t lo, uint16_t hi);
52 static void ark_ethdev_rx_dump(const char *name, struct ark_rx_queue *queue);
53 static uint32_t eth_ark_rx_jumbo(struct ark_rx_queue *queue,
54                                  struct ark_rx_meta *meta,
55                                  struct rte_mbuf *mbuf0,
56                                  uint32_t cons_index);
57 static inline int eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue);
58
59 /* ************************************************************************* */
60 struct ark_rx_queue {
61         /* array of mbufs to populate */
62         struct rte_mbuf **reserve_q;
63         /* array of physical addresses of the mbuf data pointer */
64         /* This point is a virtual address */
65         phys_addr_t *paddress_q;
66         struct rte_mempool *mb_pool;
67
68         struct ark_udm_t *udm;
69         struct ark_mpu_t *mpu;
70
71         uint32_t queue_size;
72         uint32_t queue_mask;
73
74         uint32_t seed_index;            /* step 1 set with empty mbuf */
75         uint32_t cons_index;            /* step 3 consumed by driver */
76
77         /* The queue Id is used to identify the HW Q */
78         uint16_t phys_qid;
79
80         /* The queue Index is used within the dpdk device structures */
81         uint16_t queue_index;
82
83         uint32_t pad1;
84
85         /* separate cache line */
86         /* second cache line - fields only used in slow path */
87         MARKER cacheline1 __rte_cache_min_aligned;
88
89         volatile uint32_t prod_index;   /* step 2 filled by FPGA */
90 } __rte_cache_aligned;
91
92
93 /* ************************************************************************* */
94 static int
95 eth_ark_rx_hw_setup(struct rte_eth_dev *dev,
96                     struct ark_rx_queue *queue,
97                     uint16_t rx_queue_id __rte_unused, uint16_t rx_queue_idx)
98 {
99         phys_addr_t queue_base;
100         phys_addr_t phys_addr_q_base;
101         phys_addr_t phys_addr_prod_index;
102
103         queue_base = rte_malloc_virt2phy(queue);
104         phys_addr_prod_index = queue_base +
105                 offsetof(struct ark_rx_queue, prod_index);
106
107         phys_addr_q_base = rte_malloc_virt2phy(queue->paddress_q);
108
109         /* Verify HW */
110         if (ark_mpu_verify(queue->mpu, sizeof(phys_addr_t))) {
111                 PMD_DRV_LOG(ERR, "Illegal configuration rx queue\n");
112                 return -1;
113         }
114
115         /* Stop and Reset and configure MPU */
116         ark_mpu_configure(queue->mpu, phys_addr_q_base, queue->queue_size, 0);
117
118         ark_udm_write_addr(queue->udm, phys_addr_prod_index);
119
120         /* advance the valid pointer, but don't start until the queue starts */
121         ark_mpu_reset_stats(queue->mpu);
122
123         /* The seed is the producer index for the HW */
124         ark_mpu_set_producer(queue->mpu, queue->seed_index);
125         dev->data->rx_queue_state[rx_queue_idx] = RTE_ETH_QUEUE_STATE_STOPPED;
126
127         return 0;
128 }
129
130 static inline void
131 eth_ark_rx_update_cons_index(struct ark_rx_queue *queue, uint32_t cons_index)
132 {
133         queue->cons_index = cons_index;
134         eth_ark_rx_seed_mbufs(queue);
135         ark_mpu_set_producer(queue->mpu, queue->seed_index);
136 }
137
138 /* ************************************************************************* */
139 int
140 eth_ark_dev_rx_queue_setup(struct rte_eth_dev *dev,
141                            uint16_t queue_idx,
142                            uint16_t nb_desc,
143                            unsigned int socket_id,
144                            const struct rte_eth_rxconf *rx_conf,
145                            struct rte_mempool *mb_pool)
146 {
147         static int warning1;            /* = 0 */
148         struct ark_adapter *ark = (struct ark_adapter *)dev->data->dev_private;
149
150         struct ark_rx_queue *queue;
151         uint32_t i;
152         int status;
153
154         /* Future works: divide the Q's evenly with multi-ports */
155         int port = dev->data->port_id;
156         int qidx = port + queue_idx;
157
158         /* We may already be setup, free memory prior to re-allocation */
159         if (dev->data->rx_queues[queue_idx] != NULL) {
160                 eth_ark_dev_rx_queue_release(dev->data->rx_queues[queue_idx]);
161                 dev->data->rx_queues[queue_idx] = NULL;
162         }
163
164         if (rx_conf != NULL && warning1 == 0) {
165                 warning1 = 1;
166                 PMD_DRV_LOG(INFO,
167                             "Arkville ignores rte_eth_rxconf argument.\n");
168         }
169
170         if (RTE_PKTMBUF_HEADROOM < ARK_RX_META_SIZE) {
171                 PMD_DRV_LOG(ERR,
172                             "Error: DPDK Arkville requires head room > %d bytes (%s)\n",
173                             ARK_RX_META_SIZE, __func__);
174                 return -1;              /* ERROR CODE */
175         }
176
177         if (!rte_is_power_of_2(nb_desc)) {
178                 PMD_DRV_LOG(ERR,
179                             "DPDK Arkville configuration queue size must be power of two %u (%s)\n",
180                             nb_desc, __func__);
181                 return -1;              /* ERROR CODE */
182         }
183
184         /* Allocate queue struct */
185         queue = rte_zmalloc_socket("Ark_rxqueue",
186                                    sizeof(struct ark_rx_queue),
187                                    64,
188                                    socket_id);
189         if (queue == 0) {
190                 PMD_DRV_LOG(ERR, "Failed to allocate memory in %s\n", __func__);
191                 return -ENOMEM;
192         }
193
194         /* NOTE zmalloc is used, no need to 0 indexes, etc. */
195         queue->mb_pool = mb_pool;
196         queue->phys_qid = qidx;
197         queue->queue_index = queue_idx;
198         queue->queue_size = nb_desc;
199         queue->queue_mask = nb_desc - 1;
200
201         queue->reserve_q =
202                 rte_zmalloc_socket("Ark_rx_queue mbuf",
203                                    nb_desc * sizeof(struct rte_mbuf *),
204                                    64,
205                                    socket_id);
206         queue->paddress_q =
207                 rte_zmalloc_socket("Ark_rx_queue paddr",
208                                    nb_desc * sizeof(phys_addr_t),
209                                    64,
210                                    socket_id);
211
212         if (queue->reserve_q == 0 || queue->paddress_q == 0) {
213                 PMD_DRV_LOG(ERR,
214                             "Failed to allocate queue memory in %s\n",
215                             __func__);
216                 rte_free(queue->reserve_q);
217                 rte_free(queue->paddress_q);
218                 rte_free(queue);
219                 return -ENOMEM;
220         }
221
222         dev->data->rx_queues[queue_idx] = queue;
223         queue->udm = RTE_PTR_ADD(ark->udm.v, qidx * ARK_UDM_QOFFSET);
224         queue->mpu = RTE_PTR_ADD(ark->mpurx.v, qidx * ARK_MPU_QOFFSET);
225
226         /* populate mbuf reserve */
227         status = eth_ark_rx_seed_mbufs(queue);
228
229         /* MPU Setup */
230         if (status == 0)
231                 status = eth_ark_rx_hw_setup(dev, queue, qidx, queue_idx);
232
233         if (unlikely(status != 0)) {
234                 struct rte_mbuf *mbuf;
235
236                 PMD_DRV_LOG(ERR, "Failed to initialize RX queue %d %s\n",
237                             qidx,
238                             __func__);
239                 /* Free the mbufs allocated */
240                 for (i = 0, mbuf = queue->reserve_q[0];
241                      i < nb_desc; ++i, mbuf++) {
242                         rte_pktmbuf_free(mbuf);
243                 }
244                 rte_free(queue->reserve_q);
245                 rte_free(queue->paddress_q);
246                 rte_free(queue);
247                 return -1;              /* ERROR CODE */
248         }
249
250         return 0;
251 }
252
253 /* ************************************************************************* */
254 uint16_t
255 eth_ark_recv_pkts_noop(void *rx_queue __rte_unused,
256                        struct rte_mbuf **rx_pkts __rte_unused,
257                        uint16_t nb_pkts __rte_unused)
258 {
259         return 0;
260 }
261
262 /* ************************************************************************* */
263 uint16_t
264 eth_ark_recv_pkts(void *rx_queue,
265                   struct rte_mbuf **rx_pkts,
266                   uint16_t nb_pkts)
267 {
268         struct ark_rx_queue *queue;
269         register uint32_t cons_index, prod_index;
270         uint16_t nb;
271         struct rte_mbuf *mbuf;
272         struct ark_rx_meta *meta;
273
274         queue = (struct ark_rx_queue *)rx_queue;
275         if (unlikely(queue == 0))
276                 return 0;
277         if (unlikely(nb_pkts == 0))
278                 return 0;
279         prod_index = queue->prod_index;
280         cons_index = queue->cons_index;
281         nb = 0;
282
283         while (prod_index != cons_index) {
284                 mbuf = queue->reserve_q[cons_index & queue->queue_mask];
285                 /* prefetch mbuf */
286                 rte_mbuf_prefetch_part1(mbuf);
287                 rte_mbuf_prefetch_part2(mbuf);
288
289                 /* META DATA embedded in headroom */
290                 meta = RTE_PTR_ADD(mbuf->buf_addr, ARK_RX_META_OFFSET);
291
292                 mbuf->port = meta->port;
293                 mbuf->pkt_len = meta->pkt_len;
294                 mbuf->data_len = meta->pkt_len;
295                 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
296                 mbuf->udata64 = meta->user_data;
297
298                 if (ARK_RX_DEBUG) {     /* debug sanity checks */
299                         if ((meta->pkt_len > (1024 * 16)) ||
300                             (meta->pkt_len == 0)) {
301                                 PMD_RX_LOG(DEBUG, "RX: Bad Meta Q: %u"
302                                            " cons: %" PRIU32
303                                            " prod: %" PRIU32
304                                            " seed_index %" PRIU32
305                                            "\n",
306                                            queue->phys_qid,
307                                            cons_index,
308                                            queue->prod_index,
309                                            queue->seed_index);
310
311
312                                 PMD_RX_LOG(DEBUG, "       :  UDM"
313                                            " prod: %" PRIU32
314                                            " len: %u\n",
315                                            queue->udm->rt_cfg.prod_idx,
316                                            meta->pkt_len);
317                                 ark_mpu_dump(queue->mpu,
318                                              "    ",
319                                              queue->phys_qid);
320                                 dump_mbuf_data(mbuf, 0, 256);
321                                 /* its FUBAR so fix it */
322                                 mbuf->pkt_len = 63;
323                                 meta->pkt_len = 63;
324                         }
325                         mbuf->seqn = cons_index;
326                 }
327
328                 if (unlikely(meta->pkt_len > ARK_RX_MAX_NOCHAIN))
329                         cons_index = eth_ark_rx_jumbo
330                                 (queue, meta, mbuf, cons_index + 1);
331                 else
332                         cons_index += 1;
333
334                 rx_pkts[nb] = mbuf;
335                 nb++;
336                 if (nb >= nb_pkts)
337                         break;
338         }
339
340         if (unlikely(nb != 0))
341                 /* report next free to FPGA */
342                 eth_ark_rx_update_cons_index(queue, cons_index);
343
344         return nb;
345 }
346
347 /* ************************************************************************* */
348 static uint32_t
349 eth_ark_rx_jumbo(struct ark_rx_queue *queue,
350                  struct ark_rx_meta *meta,
351                  struct rte_mbuf *mbuf0,
352                  uint32_t cons_index)
353 {
354         struct rte_mbuf *mbuf_prev;
355         struct rte_mbuf *mbuf;
356
357         uint16_t remaining;
358         uint16_t data_len;
359         uint8_t segments;
360
361         /* first buf populated by called */
362         mbuf_prev = mbuf0;
363         segments = 1;
364         data_len = RTE_MIN(meta->pkt_len, RTE_MBUF_DEFAULT_DATAROOM);
365         remaining = meta->pkt_len - data_len;
366         mbuf0->data_len = data_len;
367
368         /* HW guarantees that the data does not exceed prod_index! */
369         while (remaining != 0) {
370                 data_len = RTE_MIN(remaining,
371                                    RTE_MBUF_DEFAULT_DATAROOM +
372                                    RTE_PKTMBUF_HEADROOM);
373
374                 remaining -= data_len;
375                 segments += 1;
376
377                 mbuf = queue->reserve_q[cons_index & queue->queue_mask];
378                 mbuf_prev->next = mbuf;
379                 mbuf_prev = mbuf;
380                 mbuf->data_len = data_len;
381                 mbuf->data_off = 0;
382                 if (ARK_RX_DEBUG)
383                         mbuf->seqn = cons_index;        /* for debug only */
384
385                 cons_index += 1;
386         }
387
388         mbuf0->nb_segs = segments;
389         return cons_index;
390 }
391
392 /* Drain the internal queue allowing hw to clear out. */
393 static void
394 eth_ark_rx_queue_drain(struct ark_rx_queue *queue)
395 {
396         register uint32_t cons_index;
397         struct rte_mbuf *mbuf;
398
399         cons_index = queue->cons_index;
400
401         /* NOT performance optimized, since this is a one-shot call */
402         while ((cons_index ^ queue->prod_index) & queue->queue_mask) {
403                 mbuf = queue->reserve_q[cons_index & queue->queue_mask];
404                 rte_pktmbuf_free(mbuf);
405                 cons_index++;
406                 eth_ark_rx_update_cons_index(queue, cons_index);
407         }
408 }
409
410 uint32_t
411 eth_ark_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_id)
412 {
413         struct ark_rx_queue *queue;
414
415         queue = dev->data->rx_queues[queue_id];
416         return (queue->prod_index - queue->cons_index); /* mod arith */
417 }
418
419 /* ************************************************************************* */
420 int
421 eth_ark_rx_start_queue(struct rte_eth_dev *dev, uint16_t queue_id)
422 {
423         struct ark_rx_queue *queue;
424
425         queue = dev->data->rx_queues[queue_id];
426         if (queue == 0)
427                 return -1;
428
429         dev->data->rx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
430
431         ark_mpu_set_producer(queue->mpu, queue->seed_index);
432         ark_mpu_start(queue->mpu);
433
434         ark_udm_queue_enable(queue->udm, 1);
435
436         return 0;
437 }
438
439 /* ************************************************************************* */
440
441 /* Queue can be restarted.   data remains
442  */
443 int
444 eth_ark_rx_stop_queue(struct rte_eth_dev *dev, uint16_t queue_id)
445 {
446         struct ark_rx_queue *queue;
447
448         queue = dev->data->rx_queues[queue_id];
449         if (queue == 0)
450                 return -1;
451
452         ark_udm_queue_enable(queue->udm, 0);
453
454         dev->data->rx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
455
456         return 0;
457 }
458
459 /* ************************************************************************* */
460 static inline int
461 eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue)
462 {
463         uint32_t limit = queue->cons_index + queue->queue_size;
464         uint32_t seed_index = queue->seed_index;
465
466         uint32_t count = 0;
467         uint32_t seed_m = queue->seed_index & queue->queue_mask;
468
469         uint32_t nb = limit - seed_index;
470
471         /* Handle wrap around -- remainder is filled on the next call */
472         if (unlikely(seed_m + nb > queue->queue_size))
473                 nb = queue->queue_size - seed_m;
474
475         struct rte_mbuf **mbufs = &queue->reserve_q[seed_m];
476         int status = rte_pktmbuf_alloc_bulk(queue->mb_pool, mbufs, nb);
477
478         if (unlikely(status != 0))
479                 return -1;
480
481         if (ARK_RX_DEBUG) {             /* DEBUG */
482                 while (count != nb) {
483                         struct rte_mbuf *mbuf_init =
484                                 queue->reserve_q[seed_m + count];
485
486                         memset(mbuf_init->buf_addr, -1, 512);
487                         *((uint32_t *)mbuf_init->buf_addr) =
488                                 seed_index + count;
489                         *(uint16_t *)RTE_PTR_ADD(mbuf_init->buf_addr, 4) =
490                                 queue->phys_qid;
491                         count++;
492                 }
493                 count = 0;
494         } /* DEBUG */
495         queue->seed_index += nb;
496
497         /* Duff's device https://en.wikipedia.org/wiki/Duff's_device */
498         switch (nb % 4) {
499         case 0:
500                 while (count != nb) {
501                         queue->paddress_q[seed_m++] =
502                                 (*mbufs++)->buf_physaddr;
503                         count++;
504                 /* FALLTHROUGH */
505         case 3:
506                 queue->paddress_q[seed_m++] =
507                         (*mbufs++)->buf_physaddr;
508                 count++;
509                 /* FALLTHROUGH */
510         case 2:
511                 queue->paddress_q[seed_m++] =
512                         (*mbufs++)->buf_physaddr;
513                 count++;
514                 /* FALLTHROUGH */
515         case 1:
516                 queue->paddress_q[seed_m++] =
517                         (*mbufs++)->buf_physaddr;
518                 count++;
519                 /* FALLTHROUGH */
520
521                 } /* while (count != nb) */
522         } /* switch */
523
524         return 0;
525 }
526
527 void
528 eth_ark_rx_dump_queue(struct rte_eth_dev *dev, uint16_t queue_id,
529                       const char *msg)
530 {
531         struct ark_rx_queue *queue;
532
533         queue = dev->data->rx_queues[queue_id];
534
535         ark_ethdev_rx_dump(msg, queue);
536 }
537
538 /* ************************************************************************* */
539 /* Call on device closed no user API, queue is stopped */
540 void
541 eth_ark_dev_rx_queue_release(void *vqueue)
542 {
543         struct ark_rx_queue *queue;
544         uint32_t i;
545
546         queue = (struct ark_rx_queue *)vqueue;
547         if (queue == 0)
548                 return;
549
550         ark_udm_queue_enable(queue->udm, 0);
551         /* Stop the MPU since pointer are going away */
552         ark_mpu_stop(queue->mpu);
553
554         /* Need to clear out mbufs here, dropping packets along the way */
555         eth_ark_rx_queue_drain(queue);
556
557         for (i = 0; i < queue->queue_size; ++i)
558                 rte_pktmbuf_free(queue->reserve_q[i]);
559
560         rte_free(queue->reserve_q);
561         rte_free(queue->paddress_q);
562         rte_free(queue);
563 }
564
565 void
566 eth_rx_queue_stats_get(void *vqueue, struct rte_eth_stats *stats)
567 {
568         struct ark_rx_queue *queue;
569         struct ark_udm_t *udm;
570
571         queue = vqueue;
572         if (queue == 0)
573                 return;
574         udm = queue->udm;
575
576         uint64_t ibytes = ark_udm_bytes(udm);
577         uint64_t ipackets = ark_udm_packets(udm);
578         uint64_t idropped = ark_udm_dropped(queue->udm);
579
580         stats->q_ipackets[queue->queue_index] = ipackets;
581         stats->q_ibytes[queue->queue_index] = ibytes;
582         stats->q_errors[queue->queue_index] = idropped;
583         stats->ipackets += ipackets;
584         stats->ibytes += ibytes;
585         stats->imissed += idropped;
586 }
587
588 void
589 eth_rx_queue_stats_reset(void *vqueue)
590 {
591         struct ark_rx_queue *queue;
592
593         queue = vqueue;
594         if (queue == 0)
595                 return;
596
597         ark_mpu_reset_stats(queue->mpu);
598         ark_udm_queue_stats_reset(queue->udm);
599 }
600
601 void
602 eth_ark_udm_force_close(struct rte_eth_dev *dev)
603 {
604         struct ark_adapter *ark = (struct ark_adapter *)dev->data->dev_private;
605         struct ark_rx_queue *queue;
606         uint32_t index;
607         uint16_t i;
608
609         if (!ark_udm_is_flushed(ark->udm.v)) {
610                 /* restart the MPUs */
611                 PMD_DRV_LOG(ERR, "ARK: %s UDM not flushed\n", __func__);
612                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
613                         queue = (struct ark_rx_queue *)dev->data->rx_queues[i];
614                         if (queue == 0)
615                                 continue;
616
617                         ark_mpu_start(queue->mpu);
618                         /* Add some buffers */
619                         index = 100000 + queue->seed_index;
620                         ark_mpu_set_producer(queue->mpu, index);
621                 }
622                 /* Wait to allow data to pass */
623                 usleep(100);
624
625                 PMD_DEBUG_LOG(DEBUG, "UDM forced flush attempt, stopped = %d\n",
626                                 ark_udm_is_flushed(ark->udm.v));
627         }
628         ark_udm_reset(ark->udm.v);
629 }
630
631 static void
632 ark_ethdev_rx_dump(const char *name, struct ark_rx_queue *queue)
633 {
634         if (queue == NULL)
635                 return;
636         PMD_DEBUG_LOG(DEBUG, "RX QUEUE %d -- %s", queue->phys_qid, name);
637         PMD_DEBUG_LOG(DEBUG, ARK_SU32 ARK_SU32 ARK_SU32 ARK_SU32 "\n",
638                         "queue_size", queue->queue_size,
639                         "seed_index", queue->seed_index,
640                         "prod_index", queue->prod_index,
641                         "cons_index", queue->cons_index);
642
643         ark_mpu_dump(queue->mpu, name, queue->phys_qid);
644         ark_mpu_dump_setup(queue->mpu, queue->phys_qid);
645         ark_udm_dump(queue->udm, name);
646         ark_udm_dump_setup(queue->udm, queue->phys_qid);
647 }
648
649 /* Only used in debug.
650  * This function is a raw memory dump of a portion of an mbuf's memory
651  * region.  The usual function, rte_pktmbuf_dump() only shows data
652  * with respect to the data_off field.  This function show data
653  * anywhere in the mbuf's buffer.  This is useful for examining
654  * data in the headroom or tailroom portion of an mbuf.
655  */
656 static void
657 dump_mbuf_data(struct rte_mbuf *mbuf, uint16_t lo, uint16_t hi)
658 {
659         uint16_t i, j;
660
661         PMD_DRV_LOG(INFO, " MBUF: %p len %d, off: %d, seq: %" PRIU32 "\n", mbuf,
662                 mbuf->pkt_len, mbuf->data_off, mbuf->seqn);
663         for (i = lo; i < hi; i += 16) {
664                 uint8_t *dp = RTE_PTR_ADD(mbuf->buf_addr, i);
665
666                 PMD_DRV_LOG(INFO, "  %6d:  ", i);
667                 for (j = 0; j < 16; j++)
668                         PMD_DRV_LOG(INFO, " %02x", dp[j]);
669
670                 PMD_DRV_LOG(INFO, "\n");
671         }
672 }