ethdev: check more errors in xstats retrieval
[dpdk.git] / lib / librte_ether / rte_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
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 Intel Corporation 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 <sys/types.h>
35 #include <sys/queue.h>
36 #include <ctype.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <stdarg.h>
41 #include <errno.h>
42 #include <stdint.h>
43 #include <inttypes.h>
44 #include <netinet/in.h>
45
46 #include <rte_byteorder.h>
47 #include <rte_log.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
50 #include <rte_pci.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
55 #include <rte_eal.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
61 #include <rte_mempool.h>
62 #include <rte_malloc.h>
63 #include <rte_mbuf.h>
64 #include <rte_errno.h>
65 #include <rte_spinlock.h>
66 #include <rte_string_fns.h>
67
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
70 #include "ethdev_profile.h"
71
72 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
73 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
74 static struct rte_eth_dev_data *rte_eth_dev_data;
75 static uint8_t eth_dev_last_created_port;
76
77 /* spinlock for eth device callbacks */
78 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
79
80 /* spinlock for add/remove rx callbacks */
81 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
82
83 /* spinlock for add/remove tx callbacks */
84 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
85
86 /* store statistics names and its offset in stats structure  */
87 struct rte_eth_xstats_name_off {
88         char name[RTE_ETH_XSTATS_NAME_SIZE];
89         unsigned offset;
90 };
91
92 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
93         {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
94         {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
95         {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
96         {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
97         {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
98         {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
99         {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
100                 rx_nombuf)},
101 };
102
103 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
104
105 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
106         {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
107         {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
108         {"errors", offsetof(struct rte_eth_stats, q_errors)},
109 };
110
111 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) /       \
112                 sizeof(rte_rxq_stats_strings[0]))
113
114 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
115         {"packets", offsetof(struct rte_eth_stats, q_opackets)},
116         {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
117 };
118 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) /       \
119                 sizeof(rte_txq_stats_strings[0]))
120
121
122 /**
123  * The user application callback description.
124  *
125  * It contains callback address to be registered by user application,
126  * the pointer to the parameters for callback, and the event type.
127  */
128 struct rte_eth_dev_callback {
129         TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
130         rte_eth_dev_cb_fn cb_fn;                /**< Callback address */
131         void *cb_arg;                           /**< Parameter for callback */
132         void *ret_param;                        /**< Return parameter */
133         enum rte_eth_event_type event;          /**< Interrupt event type */
134         uint32_t active;                        /**< Callback is executing */
135 };
136
137 enum {
138         STAT_QMAP_TX = 0,
139         STAT_QMAP_RX
140 };
141
142 uint16_t
143 rte_eth_find_next(uint16_t port_id)
144 {
145         while (port_id < RTE_MAX_ETHPORTS &&
146                rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
147                 port_id++;
148
149         if (port_id >= RTE_MAX_ETHPORTS)
150                 return RTE_MAX_ETHPORTS;
151
152         return port_id;
153 }
154
155 static void
156 rte_eth_dev_data_alloc(void)
157 {
158         const unsigned flags = 0;
159         const struct rte_memzone *mz;
160
161         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
162                 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
163                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
164                                 rte_socket_id(), flags);
165         } else
166                 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
167         if (mz == NULL)
168                 rte_panic("Cannot allocate memzone for ethernet port data\n");
169
170         rte_eth_dev_data = mz->addr;
171         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172                 memset(rte_eth_dev_data, 0,
173                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
174 }
175
176 struct rte_eth_dev *
177 rte_eth_dev_allocated(const char *name)
178 {
179         unsigned i;
180
181         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
182                 if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
183                     strcmp(rte_eth_devices[i].data->name, name) == 0)
184                         return &rte_eth_devices[i];
185         }
186         return NULL;
187 }
188
189 static uint16_t
190 rte_eth_dev_find_free_port(void)
191 {
192         unsigned i;
193
194         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
195                 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
196                         return i;
197         }
198         return RTE_MAX_ETHPORTS;
199 }
200
201 static struct rte_eth_dev *
202 eth_dev_get(uint16_t port_id)
203 {
204         struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
205
206         eth_dev->data = &rte_eth_dev_data[port_id];
207         eth_dev->state = RTE_ETH_DEV_ATTACHED;
208         TAILQ_INIT(&(eth_dev->link_intr_cbs));
209
210         eth_dev_last_created_port = port_id;
211
212         return eth_dev;
213 }
214
215 struct rte_eth_dev *
216 rte_eth_dev_allocate(const char *name)
217 {
218         uint16_t port_id;
219         struct rte_eth_dev *eth_dev;
220
221         port_id = rte_eth_dev_find_free_port();
222         if (port_id == RTE_MAX_ETHPORTS) {
223                 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
224                 return NULL;
225         }
226
227         if (rte_eth_dev_data == NULL)
228                 rte_eth_dev_data_alloc();
229
230         if (rte_eth_dev_allocated(name) != NULL) {
231                 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
232                                 name);
233                 return NULL;
234         }
235
236         memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
237         eth_dev = eth_dev_get(port_id);
238         snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
239         eth_dev->data->port_id = port_id;
240         eth_dev->data->mtu = ETHER_MTU;
241
242         return eth_dev;
243 }
244
245 /*
246  * Attach to a port already registered by the primary process, which
247  * makes sure that the same device would have the same port id both
248  * in the primary and secondary process.
249  */
250 struct rte_eth_dev *
251 rte_eth_dev_attach_secondary(const char *name)
252 {
253         uint16_t i;
254         struct rte_eth_dev *eth_dev;
255
256         if (rte_eth_dev_data == NULL)
257                 rte_eth_dev_data_alloc();
258
259         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
260                 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
261                         break;
262         }
263         if (i == RTE_MAX_ETHPORTS) {
264                 RTE_PMD_DEBUG_TRACE(
265                         "device %s is not driven by the primary process\n",
266                         name);
267                 return NULL;
268         }
269
270         eth_dev = eth_dev_get(i);
271         RTE_ASSERT(eth_dev->data->port_id == i);
272
273         return eth_dev;
274 }
275
276 int
277 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
278 {
279         if (eth_dev == NULL)
280                 return -EINVAL;
281
282         eth_dev->state = RTE_ETH_DEV_UNUSED;
283         return 0;
284 }
285
286 int
287 rte_eth_dev_is_valid_port(uint16_t port_id)
288 {
289         if (port_id >= RTE_MAX_ETHPORTS ||
290             (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
291              rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
292                 return 0;
293         else
294                 return 1;
295 }
296
297 int
298 rte_eth_dev_socket_id(uint16_t port_id)
299 {
300         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
301         return rte_eth_devices[port_id].data->numa_node;
302 }
303
304 void *
305 rte_eth_dev_get_sec_ctx(uint8_t port_id)
306 {
307         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
308         return rte_eth_devices[port_id].security_ctx;
309 }
310
311 uint16_t
312 rte_eth_dev_count(void)
313 {
314         uint16_t p;
315         uint16_t count;
316
317         count = 0;
318
319         RTE_ETH_FOREACH_DEV(p)
320                 count++;
321
322         return count;
323 }
324
325 int
326 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
327 {
328         char *tmp;
329
330         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
331
332         if (name == NULL) {
333                 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
334                 return -EINVAL;
335         }
336
337         /* shouldn't check 'rte_eth_devices[i].data',
338          * because it might be overwritten by VDEV PMD */
339         tmp = rte_eth_dev_data[port_id].name;
340         strcpy(name, tmp);
341         return 0;
342 }
343
344 int
345 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
346 {
347         int i;
348
349         if (name == NULL) {
350                 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
351                 return -EINVAL;
352         }
353
354         RTE_ETH_FOREACH_DEV(i) {
355                 if (!strncmp(name,
356                         rte_eth_dev_data[i].name, strlen(name))) {
357
358                         *port_id = i;
359
360                         return 0;
361                 }
362         }
363         return -ENODEV;
364 }
365
366 static int
367 rte_eth_dev_is_detachable(uint16_t port_id)
368 {
369         uint32_t dev_flags;
370
371         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
372
373         dev_flags = rte_eth_devices[port_id].data->dev_flags;
374         if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
375                 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
376                 return 0;
377         else
378                 return 1;
379 }
380
381 /* attach the new device, then store port_id of the device */
382 int
383 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
384 {
385         int ret = -1;
386         int current = rte_eth_dev_count();
387         char *name = NULL;
388         char *args = NULL;
389
390         if ((devargs == NULL) || (port_id == NULL)) {
391                 ret = -EINVAL;
392                 goto err;
393         }
394
395         /* parse devargs, then retrieve device name and args */
396         if (rte_eal_parse_devargs_str(devargs, &name, &args))
397                 goto err;
398
399         ret = rte_eal_dev_attach(name, args);
400         if (ret < 0)
401                 goto err;
402
403         /* no point looking at the port count if no port exists */
404         if (!rte_eth_dev_count()) {
405                 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
406                 ret = -1;
407                 goto err;
408         }
409
410         /* if nothing happened, there is a bug here, since some driver told us
411          * it did attach a device, but did not create a port.
412          */
413         if (current == rte_eth_dev_count()) {
414                 ret = -1;
415                 goto err;
416         }
417
418         *port_id = eth_dev_last_created_port;
419         ret = 0;
420
421 err:
422         free(name);
423         free(args);
424         return ret;
425 }
426
427 /* detach the device, then store the name of the device */
428 int
429 rte_eth_dev_detach(uint16_t port_id, char *name)
430 {
431         int ret = -1;
432
433         if (name == NULL) {
434                 ret = -EINVAL;
435                 goto err;
436         }
437
438         /* FIXME: move this to eal, once device flags are relocated there */
439         if (rte_eth_dev_is_detachable(port_id))
440                 goto err;
441
442         snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
443                  "%s", rte_eth_devices[port_id].data->name);
444
445         ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
446         if (ret < 0)
447                 goto err;
448
449         rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
450         return 0;
451
452 err:
453         return ret;
454 }
455
456 static int
457 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
458 {
459         uint16_t old_nb_queues = dev->data->nb_rx_queues;
460         void **rxq;
461         unsigned i;
462
463         if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
464                 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
465                                 sizeof(dev->data->rx_queues[0]) * nb_queues,
466                                 RTE_CACHE_LINE_SIZE);
467                 if (dev->data->rx_queues == NULL) {
468                         dev->data->nb_rx_queues = 0;
469                         return -(ENOMEM);
470                 }
471         } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
472                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
473
474                 rxq = dev->data->rx_queues;
475
476                 for (i = nb_queues; i < old_nb_queues; i++)
477                         (*dev->dev_ops->rx_queue_release)(rxq[i]);
478                 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
479                                 RTE_CACHE_LINE_SIZE);
480                 if (rxq == NULL)
481                         return -(ENOMEM);
482                 if (nb_queues > old_nb_queues) {
483                         uint16_t new_qs = nb_queues - old_nb_queues;
484
485                         memset(rxq + old_nb_queues, 0,
486                                 sizeof(rxq[0]) * new_qs);
487                 }
488
489                 dev->data->rx_queues = rxq;
490
491         } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
492                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
493
494                 rxq = dev->data->rx_queues;
495
496                 for (i = nb_queues; i < old_nb_queues; i++)
497                         (*dev->dev_ops->rx_queue_release)(rxq[i]);
498
499                 rte_free(dev->data->rx_queues);
500                 dev->data->rx_queues = NULL;
501         }
502         dev->data->nb_rx_queues = nb_queues;
503         return 0;
504 }
505
506 int
507 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
508 {
509         struct rte_eth_dev *dev;
510
511         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
512
513         dev = &rte_eth_devices[port_id];
514         if (rx_queue_id >= dev->data->nb_rx_queues) {
515                 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
516                 return -EINVAL;
517         }
518
519         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
520
521         if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
522                 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
523                         " already started\n",
524                         rx_queue_id, port_id);
525                 return 0;
526         }
527
528         return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
529
530 }
531
532 int
533 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
534 {
535         struct rte_eth_dev *dev;
536
537         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
538
539         dev = &rte_eth_devices[port_id];
540         if (rx_queue_id >= dev->data->nb_rx_queues) {
541                 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
542                 return -EINVAL;
543         }
544
545         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
546
547         if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
548                 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
549                         " already stopped\n",
550                         rx_queue_id, port_id);
551                 return 0;
552         }
553
554         return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
555
556 }
557
558 int
559 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
560 {
561         struct rte_eth_dev *dev;
562
563         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
564
565         dev = &rte_eth_devices[port_id];
566         if (tx_queue_id >= dev->data->nb_tx_queues) {
567                 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
568                 return -EINVAL;
569         }
570
571         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
572
573         if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
574                 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
575                         " already started\n",
576                         tx_queue_id, port_id);
577                 return 0;
578         }
579
580         return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
581
582 }
583
584 int
585 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
586 {
587         struct rte_eth_dev *dev;
588
589         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
590
591         dev = &rte_eth_devices[port_id];
592         if (tx_queue_id >= dev->data->nb_tx_queues) {
593                 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
594                 return -EINVAL;
595         }
596
597         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
598
599         if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
600                 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
601                         " already stopped\n",
602                         tx_queue_id, port_id);
603                 return 0;
604         }
605
606         return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
607
608 }
609
610 static int
611 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
612 {
613         uint16_t old_nb_queues = dev->data->nb_tx_queues;
614         void **txq;
615         unsigned i;
616
617         if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
618                 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
619                                                    sizeof(dev->data->tx_queues[0]) * nb_queues,
620                                                    RTE_CACHE_LINE_SIZE);
621                 if (dev->data->tx_queues == NULL) {
622                         dev->data->nb_tx_queues = 0;
623                         return -(ENOMEM);
624                 }
625         } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
626                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
627
628                 txq = dev->data->tx_queues;
629
630                 for (i = nb_queues; i < old_nb_queues; i++)
631                         (*dev->dev_ops->tx_queue_release)(txq[i]);
632                 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
633                                   RTE_CACHE_LINE_SIZE);
634                 if (txq == NULL)
635                         return -ENOMEM;
636                 if (nb_queues > old_nb_queues) {
637                         uint16_t new_qs = nb_queues - old_nb_queues;
638
639                         memset(txq + old_nb_queues, 0,
640                                sizeof(txq[0]) * new_qs);
641                 }
642
643                 dev->data->tx_queues = txq;
644
645         } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
646                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
647
648                 txq = dev->data->tx_queues;
649
650                 for (i = nb_queues; i < old_nb_queues; i++)
651                         (*dev->dev_ops->tx_queue_release)(txq[i]);
652
653                 rte_free(dev->data->tx_queues);
654                 dev->data->tx_queues = NULL;
655         }
656         dev->data->nb_tx_queues = nb_queues;
657         return 0;
658 }
659
660 uint32_t
661 rte_eth_speed_bitflag(uint32_t speed, int duplex)
662 {
663         switch (speed) {
664         case ETH_SPEED_NUM_10M:
665                 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
666         case ETH_SPEED_NUM_100M:
667                 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
668         case ETH_SPEED_NUM_1G:
669                 return ETH_LINK_SPEED_1G;
670         case ETH_SPEED_NUM_2_5G:
671                 return ETH_LINK_SPEED_2_5G;
672         case ETH_SPEED_NUM_5G:
673                 return ETH_LINK_SPEED_5G;
674         case ETH_SPEED_NUM_10G:
675                 return ETH_LINK_SPEED_10G;
676         case ETH_SPEED_NUM_20G:
677                 return ETH_LINK_SPEED_20G;
678         case ETH_SPEED_NUM_25G:
679                 return ETH_LINK_SPEED_25G;
680         case ETH_SPEED_NUM_40G:
681                 return ETH_LINK_SPEED_40G;
682         case ETH_SPEED_NUM_50G:
683                 return ETH_LINK_SPEED_50G;
684         case ETH_SPEED_NUM_56G:
685                 return ETH_LINK_SPEED_56G;
686         case ETH_SPEED_NUM_100G:
687                 return ETH_LINK_SPEED_100G;
688         default:
689                 return 0;
690         }
691 }
692
693 /**
694  * A conversion function from rxmode bitfield API.
695  */
696 static void
697 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
698                                     uint64_t *rx_offloads)
699 {
700         uint64_t offloads = 0;
701
702         if (rxmode->header_split == 1)
703                 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
704         if (rxmode->hw_ip_checksum == 1)
705                 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
706         if (rxmode->hw_vlan_filter == 1)
707                 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
708         if (rxmode->hw_vlan_strip == 1)
709                 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
710         if (rxmode->hw_vlan_extend == 1)
711                 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
712         if (rxmode->jumbo_frame == 1)
713                 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
714         if (rxmode->hw_strip_crc == 1)
715                 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
716         if (rxmode->enable_scatter == 1)
717                 offloads |= DEV_RX_OFFLOAD_SCATTER;
718         if (rxmode->enable_lro == 1)
719                 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
720         if (rxmode->hw_timestamp == 1)
721                 offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
722         if (rxmode->security == 1)
723                 offloads |= DEV_RX_OFFLOAD_SECURITY;
724
725         *rx_offloads = offloads;
726 }
727
728 /**
729  * A conversion function from rxmode offloads API.
730  */
731 static void
732 rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
733                             struct rte_eth_rxmode *rxmode)
734 {
735
736         if (rx_offloads & DEV_RX_OFFLOAD_HEADER_SPLIT)
737                 rxmode->header_split = 1;
738         else
739                 rxmode->header_split = 0;
740         if (rx_offloads & DEV_RX_OFFLOAD_CHECKSUM)
741                 rxmode->hw_ip_checksum = 1;
742         else
743                 rxmode->hw_ip_checksum = 0;
744         if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
745                 rxmode->hw_vlan_filter = 1;
746         else
747                 rxmode->hw_vlan_filter = 0;
748         if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
749                 rxmode->hw_vlan_strip = 1;
750         else
751                 rxmode->hw_vlan_strip = 0;
752         if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
753                 rxmode->hw_vlan_extend = 1;
754         else
755                 rxmode->hw_vlan_extend = 0;
756         if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
757                 rxmode->jumbo_frame = 1;
758         else
759                 rxmode->jumbo_frame = 0;
760         if (rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP)
761                 rxmode->hw_strip_crc = 1;
762         else
763                 rxmode->hw_strip_crc = 0;
764         if (rx_offloads & DEV_RX_OFFLOAD_SCATTER)
765                 rxmode->enable_scatter = 1;
766         else
767                 rxmode->enable_scatter = 0;
768         if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
769                 rxmode->enable_lro = 1;
770         else
771                 rxmode->enable_lro = 0;
772         if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
773                 rxmode->hw_timestamp = 1;
774         else
775                 rxmode->hw_timestamp = 0;
776         if (rx_offloads & DEV_RX_OFFLOAD_SECURITY)
777                 rxmode->security = 1;
778         else
779                 rxmode->security = 0;
780 }
781
782 int
783 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
784                       const struct rte_eth_conf *dev_conf)
785 {
786         struct rte_eth_dev *dev;
787         struct rte_eth_dev_info dev_info;
788         struct rte_eth_conf local_conf = *dev_conf;
789         int diag;
790
791         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
792
793         if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
794                 RTE_PMD_DEBUG_TRACE(
795                         "Number of RX queues requested (%u) is greater than max supported(%d)\n",
796                         nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
797                 return -EINVAL;
798         }
799
800         if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
801                 RTE_PMD_DEBUG_TRACE(
802                         "Number of TX queues requested (%u) is greater than max supported(%d)\n",
803                         nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
804                 return -EINVAL;
805         }
806
807         dev = &rte_eth_devices[port_id];
808
809         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
810         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
811
812         if (dev->data->dev_started) {
813                 RTE_PMD_DEBUG_TRACE(
814                     "port %d must be stopped to allow configuration\n", port_id);
815                 return -EBUSY;
816         }
817
818         /*
819          * Convert between the offloads API to enable PMDs to support
820          * only one of them.
821          */
822         if ((dev_conf->rxmode.ignore_offload_bitfield == 0)) {
823                 rte_eth_convert_rx_offload_bitfield(
824                                 &dev_conf->rxmode, &local_conf.rxmode.offloads);
825         } else {
826                 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
827                                             &local_conf.rxmode);
828         }
829
830         /* Copy the dev_conf parameter into the dev structure */
831         memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
832
833         /*
834          * Check that the numbers of RX and TX queues are not greater
835          * than the maximum number of RX and TX queues supported by the
836          * configured device.
837          */
838         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
839
840         if (nb_rx_q == 0 && nb_tx_q == 0) {
841                 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
842                 return -EINVAL;
843         }
844
845         if (nb_rx_q > dev_info.max_rx_queues) {
846                 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
847                                 port_id, nb_rx_q, dev_info.max_rx_queues);
848                 return -EINVAL;
849         }
850
851         if (nb_tx_q > dev_info.max_tx_queues) {
852                 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
853                                 port_id, nb_tx_q, dev_info.max_tx_queues);
854                 return -EINVAL;
855         }
856
857         /* Check that the device supports requested interrupts */
858         if ((dev_conf->intr_conf.lsc == 1) &&
859                 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
860                         RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
861                                         dev->device->driver->name);
862                         return -EINVAL;
863         }
864         if ((dev_conf->intr_conf.rmv == 1) &&
865             (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
866                 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
867                                     dev->device->driver->name);
868                 return -EINVAL;
869         }
870
871         /*
872          * If jumbo frames are enabled, check that the maximum RX packet
873          * length is supported by the configured device.
874          */
875         if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
876                 if (dev_conf->rxmode.max_rx_pkt_len >
877                     dev_info.max_rx_pktlen) {
878                         RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
879                                 " > max valid value %u\n",
880                                 port_id,
881                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
882                                 (unsigned)dev_info.max_rx_pktlen);
883                         return -EINVAL;
884                 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
885                         RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
886                                 " < min valid value %u\n",
887                                 port_id,
888                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
889                                 (unsigned)ETHER_MIN_LEN);
890                         return -EINVAL;
891                 }
892         } else {
893                 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
894                         dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
895                         /* Use default value */
896                         dev->data->dev_conf.rxmode.max_rx_pkt_len =
897                                                         ETHER_MAX_LEN;
898         }
899
900         /*
901          * Setup new number of RX/TX queues and reconfigure device.
902          */
903         diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
904         if (diag != 0) {
905                 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
906                                 port_id, diag);
907                 return diag;
908         }
909
910         diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
911         if (diag != 0) {
912                 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
913                                 port_id, diag);
914                 rte_eth_dev_rx_queue_config(dev, 0);
915                 return diag;
916         }
917
918         diag = (*dev->dev_ops->dev_configure)(dev);
919         if (diag != 0) {
920                 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
921                                 port_id, diag);
922                 rte_eth_dev_rx_queue_config(dev, 0);
923                 rte_eth_dev_tx_queue_config(dev, 0);
924                 return diag;
925         }
926
927         /* Initialize Rx profiling if enabled at compilation time. */
928         diag = __rte_eth_profile_rx_init(port_id, dev);
929         if (diag != 0) {
930                 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
931                                 port_id, diag);
932                 rte_eth_dev_rx_queue_config(dev, 0);
933                 rte_eth_dev_tx_queue_config(dev, 0);
934                 return diag;
935         }
936
937         return 0;
938 }
939
940 void
941 _rte_eth_dev_reset(struct rte_eth_dev *dev)
942 {
943         if (dev->data->dev_started) {
944                 RTE_PMD_DEBUG_TRACE(
945                         "port %d must be stopped to allow reset\n",
946                         dev->data->port_id);
947                 return;
948         }
949
950         rte_eth_dev_rx_queue_config(dev, 0);
951         rte_eth_dev_tx_queue_config(dev, 0);
952
953         memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
954 }
955
956 static void
957 rte_eth_dev_config_restore(uint16_t port_id)
958 {
959         struct rte_eth_dev *dev;
960         struct rte_eth_dev_info dev_info;
961         struct ether_addr *addr;
962         uint16_t i;
963         uint32_t pool = 0;
964         uint64_t pool_mask;
965
966         dev = &rte_eth_devices[port_id];
967
968         rte_eth_dev_info_get(port_id, &dev_info);
969
970         /* replay MAC address configuration including default MAC */
971         addr = &dev->data->mac_addrs[0];
972         if (*dev->dev_ops->mac_addr_set != NULL)
973                 (*dev->dev_ops->mac_addr_set)(dev, addr);
974         else if (*dev->dev_ops->mac_addr_add != NULL)
975                 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
976
977         if (*dev->dev_ops->mac_addr_add != NULL) {
978                 for (i = 1; i < dev_info.max_mac_addrs; i++) {
979                         addr = &dev->data->mac_addrs[i];
980
981                         /* skip zero address */
982                         if (is_zero_ether_addr(addr))
983                                 continue;
984
985                         pool = 0;
986                         pool_mask = dev->data->mac_pool_sel[i];
987
988                         do {
989                                 if (pool_mask & 1ULL)
990                                         (*dev->dev_ops->mac_addr_add)(dev,
991                                                 addr, i, pool);
992                                 pool_mask >>= 1;
993                                 pool++;
994                         } while (pool_mask);
995                 }
996         }
997
998         /* replay promiscuous configuration */
999         if (rte_eth_promiscuous_get(port_id) == 1)
1000                 rte_eth_promiscuous_enable(port_id);
1001         else if (rte_eth_promiscuous_get(port_id) == 0)
1002                 rte_eth_promiscuous_disable(port_id);
1003
1004         /* replay all multicast configuration */
1005         if (rte_eth_allmulticast_get(port_id) == 1)
1006                 rte_eth_allmulticast_enable(port_id);
1007         else if (rte_eth_allmulticast_get(port_id) == 0)
1008                 rte_eth_allmulticast_disable(port_id);
1009 }
1010
1011 int
1012 rte_eth_dev_start(uint16_t port_id)
1013 {
1014         struct rte_eth_dev *dev;
1015         int diag;
1016
1017         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1018
1019         dev = &rte_eth_devices[port_id];
1020
1021         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1022
1023         if (dev->data->dev_started != 0) {
1024                 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1025                         " already started\n",
1026                         port_id);
1027                 return 0;
1028         }
1029
1030         diag = (*dev->dev_ops->dev_start)(dev);
1031         if (diag == 0)
1032                 dev->data->dev_started = 1;
1033         else
1034                 return diag;
1035
1036         rte_eth_dev_config_restore(port_id);
1037
1038         if (dev->data->dev_conf.intr_conf.lsc == 0) {
1039                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1040                 (*dev->dev_ops->link_update)(dev, 0);
1041         }
1042         return 0;
1043 }
1044
1045 void
1046 rte_eth_dev_stop(uint16_t port_id)
1047 {
1048         struct rte_eth_dev *dev;
1049
1050         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1051         dev = &rte_eth_devices[port_id];
1052
1053         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1054
1055         if (dev->data->dev_started == 0) {
1056                 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1057                         " already stopped\n",
1058                         port_id);
1059                 return;
1060         }
1061
1062         dev->data->dev_started = 0;
1063         (*dev->dev_ops->dev_stop)(dev);
1064 }
1065
1066 int
1067 rte_eth_dev_set_link_up(uint16_t port_id)
1068 {
1069         struct rte_eth_dev *dev;
1070
1071         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1072
1073         dev = &rte_eth_devices[port_id];
1074
1075         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1076         return (*dev->dev_ops->dev_set_link_up)(dev);
1077 }
1078
1079 int
1080 rte_eth_dev_set_link_down(uint16_t port_id)
1081 {
1082         struct rte_eth_dev *dev;
1083
1084         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1085
1086         dev = &rte_eth_devices[port_id];
1087
1088         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1089         return (*dev->dev_ops->dev_set_link_down)(dev);
1090 }
1091
1092 void
1093 rte_eth_dev_close(uint16_t port_id)
1094 {
1095         struct rte_eth_dev *dev;
1096
1097         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1098         dev = &rte_eth_devices[port_id];
1099
1100         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1101         dev->data->dev_started = 0;
1102         (*dev->dev_ops->dev_close)(dev);
1103
1104         dev->data->nb_rx_queues = 0;
1105         rte_free(dev->data->rx_queues);
1106         dev->data->rx_queues = NULL;
1107         dev->data->nb_tx_queues = 0;
1108         rte_free(dev->data->tx_queues);
1109         dev->data->tx_queues = NULL;
1110 }
1111
1112 int
1113 rte_eth_dev_reset(uint16_t port_id)
1114 {
1115         struct rte_eth_dev *dev;
1116         int ret;
1117
1118         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1119         dev = &rte_eth_devices[port_id];
1120
1121         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1122
1123         rte_eth_dev_stop(port_id);
1124         ret = dev->dev_ops->dev_reset(dev);
1125
1126         return ret;
1127 }
1128
1129 int
1130 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1131                        uint16_t nb_rx_desc, unsigned int socket_id,
1132                        const struct rte_eth_rxconf *rx_conf,
1133                        struct rte_mempool *mp)
1134 {
1135         int ret;
1136         uint32_t mbp_buf_size;
1137         struct rte_eth_dev *dev;
1138         struct rte_eth_dev_info dev_info;
1139         struct rte_eth_rxconf local_conf;
1140         void **rxq;
1141
1142         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1143
1144         dev = &rte_eth_devices[port_id];
1145         if (rx_queue_id >= dev->data->nb_rx_queues) {
1146                 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1147                 return -EINVAL;
1148         }
1149
1150         if (dev->data->dev_started) {
1151                 RTE_PMD_DEBUG_TRACE(
1152                     "port %d must be stopped to allow configuration\n", port_id);
1153                 return -EBUSY;
1154         }
1155
1156         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1157         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1158
1159         /*
1160          * Check the size of the mbuf data buffer.
1161          * This value must be provided in the private data of the memory pool.
1162          * First check that the memory pool has a valid private data.
1163          */
1164         rte_eth_dev_info_get(port_id, &dev_info);
1165         if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1166                 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1167                                 mp->name, (int) mp->private_data_size,
1168                                 (int) sizeof(struct rte_pktmbuf_pool_private));
1169                 return -ENOSPC;
1170         }
1171         mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1172
1173         if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1174                 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1175                                 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1176                                 "=%d)\n",
1177                                 mp->name,
1178                                 (int)mbp_buf_size,
1179                                 (int)(RTE_PKTMBUF_HEADROOM +
1180                                       dev_info.min_rx_bufsize),
1181                                 (int)RTE_PKTMBUF_HEADROOM,
1182                                 (int)dev_info.min_rx_bufsize);
1183                 return -EINVAL;
1184         }
1185
1186         if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1187                         nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1188                         nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1189
1190                 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1191                         "should be: <= %hu, = %hu, and a product of %hu\n",
1192                         nb_rx_desc,
1193                         dev_info.rx_desc_lim.nb_max,
1194                         dev_info.rx_desc_lim.nb_min,
1195                         dev_info.rx_desc_lim.nb_align);
1196                 return -EINVAL;
1197         }
1198
1199         rxq = dev->data->rx_queues;
1200         if (rxq[rx_queue_id]) {
1201                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1202                                         -ENOTSUP);
1203                 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1204                 rxq[rx_queue_id] = NULL;
1205         }
1206
1207         if (rx_conf == NULL)
1208                 rx_conf = &dev_info.default_rxconf;
1209
1210         local_conf = *rx_conf;
1211         if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1212                 /**
1213                  * Reflect port offloads to queue offloads in order for
1214                  * offloads to not be discarded.
1215                  */
1216                 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1217                                                     &local_conf.offloads);
1218         }
1219
1220         ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1221                                               socket_id, &local_conf, mp);
1222         if (!ret) {
1223                 if (!dev->data->min_rx_buf_size ||
1224                     dev->data->min_rx_buf_size > mbp_buf_size)
1225                         dev->data->min_rx_buf_size = mbp_buf_size;
1226         }
1227
1228         return ret;
1229 }
1230
1231 /**
1232  * A conversion function from txq_flags API.
1233  */
1234 static void
1235 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1236 {
1237         uint64_t offloads = 0;
1238
1239         if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1240                 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1241         if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1242                 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1243         if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1244                 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1245         if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1246                 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1247         if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1248                 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1249         if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1250             (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1251                 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1252
1253         *tx_offloads = offloads;
1254 }
1255
1256 /**
1257  * A conversion function from offloads API.
1258  */
1259 static void
1260 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1261 {
1262         uint32_t flags = 0;
1263
1264         if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1265                 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1266         if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1267                 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1268         if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1269                 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1270         if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1271                 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1272         if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1273                 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1274         if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1275                 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1276
1277         *txq_flags = flags;
1278 }
1279
1280 int
1281 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1282                        uint16_t nb_tx_desc, unsigned int socket_id,
1283                        const struct rte_eth_txconf *tx_conf)
1284 {
1285         struct rte_eth_dev *dev;
1286         struct rte_eth_dev_info dev_info;
1287         struct rte_eth_txconf local_conf;
1288         void **txq;
1289
1290         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1291
1292         dev = &rte_eth_devices[port_id];
1293         if (tx_queue_id >= dev->data->nb_tx_queues) {
1294                 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1295                 return -EINVAL;
1296         }
1297
1298         if (dev->data->dev_started) {
1299                 RTE_PMD_DEBUG_TRACE(
1300                     "port %d must be stopped to allow configuration\n", port_id);
1301                 return -EBUSY;
1302         }
1303
1304         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1305         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1306
1307         rte_eth_dev_info_get(port_id, &dev_info);
1308
1309         if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1310             nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1311             nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1312                 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1313                                 "should be: <= %hu, = %hu, and a product of %hu\n",
1314                                 nb_tx_desc,
1315                                 dev_info.tx_desc_lim.nb_max,
1316                                 dev_info.tx_desc_lim.nb_min,
1317                                 dev_info.tx_desc_lim.nb_align);
1318                 return -EINVAL;
1319         }
1320
1321         txq = dev->data->tx_queues;
1322         if (txq[tx_queue_id]) {
1323                 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1324                                         -ENOTSUP);
1325                 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1326                 txq[tx_queue_id] = NULL;
1327         }
1328
1329         if (tx_conf == NULL)
1330                 tx_conf = &dev_info.default_txconf;
1331
1332         /*
1333          * Convert between the offloads API to enable PMDs to support
1334          * only one of them.
1335          */
1336         local_conf = *tx_conf;
1337         if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1338                 rte_eth_convert_txq_offloads(tx_conf->offloads,
1339                                              &local_conf.txq_flags);
1340                 /* Keep the ignore flag. */
1341                 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1342         } else {
1343                 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1344                                           &local_conf.offloads);
1345         }
1346
1347         return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1348                                                socket_id, &local_conf);
1349 }
1350
1351 void
1352 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1353                 void *userdata __rte_unused)
1354 {
1355         unsigned i;
1356
1357         for (i = 0; i < unsent; i++)
1358                 rte_pktmbuf_free(pkts[i]);
1359 }
1360
1361 void
1362 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1363                 void *userdata)
1364 {
1365         uint64_t *count = userdata;
1366         unsigned i;
1367
1368         for (i = 0; i < unsent; i++)
1369                 rte_pktmbuf_free(pkts[i]);
1370
1371         *count += unsent;
1372 }
1373
1374 int
1375 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1376                 buffer_tx_error_fn cbfn, void *userdata)
1377 {
1378         buffer->error_callback = cbfn;
1379         buffer->error_userdata = userdata;
1380         return 0;
1381 }
1382
1383 int
1384 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1385 {
1386         int ret = 0;
1387
1388         if (buffer == NULL)
1389                 return -EINVAL;
1390
1391         buffer->size = size;
1392         if (buffer->error_callback == NULL) {
1393                 ret = rte_eth_tx_buffer_set_err_callback(
1394                         buffer, rte_eth_tx_buffer_drop_callback, NULL);
1395         }
1396
1397         return ret;
1398 }
1399
1400 int
1401 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1402 {
1403         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1404
1405         /* Validate Input Data. Bail if not valid or not supported. */
1406         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1407         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1408
1409         /* Call driver to free pending mbufs. */
1410         return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1411                         free_cnt);
1412 }
1413
1414 void
1415 rte_eth_promiscuous_enable(uint16_t port_id)
1416 {
1417         struct rte_eth_dev *dev;
1418
1419         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1420         dev = &rte_eth_devices[port_id];
1421
1422         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1423         (*dev->dev_ops->promiscuous_enable)(dev);
1424         dev->data->promiscuous = 1;
1425 }
1426
1427 void
1428 rte_eth_promiscuous_disable(uint16_t port_id)
1429 {
1430         struct rte_eth_dev *dev;
1431
1432         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1433         dev = &rte_eth_devices[port_id];
1434
1435         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1436         dev->data->promiscuous = 0;
1437         (*dev->dev_ops->promiscuous_disable)(dev);
1438 }
1439
1440 int
1441 rte_eth_promiscuous_get(uint16_t port_id)
1442 {
1443         struct rte_eth_dev *dev;
1444
1445         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1446
1447         dev = &rte_eth_devices[port_id];
1448         return dev->data->promiscuous;
1449 }
1450
1451 void
1452 rte_eth_allmulticast_enable(uint16_t port_id)
1453 {
1454         struct rte_eth_dev *dev;
1455
1456         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1457         dev = &rte_eth_devices[port_id];
1458
1459         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1460         (*dev->dev_ops->allmulticast_enable)(dev);
1461         dev->data->all_multicast = 1;
1462 }
1463
1464 void
1465 rte_eth_allmulticast_disable(uint16_t port_id)
1466 {
1467         struct rte_eth_dev *dev;
1468
1469         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1470         dev = &rte_eth_devices[port_id];
1471
1472         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1473         dev->data->all_multicast = 0;
1474         (*dev->dev_ops->allmulticast_disable)(dev);
1475 }
1476
1477 int
1478 rte_eth_allmulticast_get(uint16_t port_id)
1479 {
1480         struct rte_eth_dev *dev;
1481
1482         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1483
1484         dev = &rte_eth_devices[port_id];
1485         return dev->data->all_multicast;
1486 }
1487
1488 static inline int
1489 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1490                                 struct rte_eth_link *link)
1491 {
1492         struct rte_eth_link *dst = link;
1493         struct rte_eth_link *src = &(dev->data->dev_link);
1494
1495         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1496                                         *(uint64_t *)src) == 0)
1497                 return -1;
1498
1499         return 0;
1500 }
1501
1502 void
1503 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
1504 {
1505         struct rte_eth_dev *dev;
1506
1507         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1508         dev = &rte_eth_devices[port_id];
1509
1510         if (dev->data->dev_conf.intr_conf.lsc != 0)
1511                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1512         else {
1513                 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1514                 (*dev->dev_ops->link_update)(dev, 1);
1515                 *eth_link = dev->data->dev_link;
1516         }
1517 }
1518
1519 void
1520 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
1521 {
1522         struct rte_eth_dev *dev;
1523
1524         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1525         dev = &rte_eth_devices[port_id];
1526
1527         if (dev->data->dev_conf.intr_conf.lsc != 0)
1528                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1529         else {
1530                 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1531                 (*dev->dev_ops->link_update)(dev, 0);
1532                 *eth_link = dev->data->dev_link;
1533         }
1534 }
1535
1536 int
1537 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
1538 {
1539         struct rte_eth_dev *dev;
1540
1541         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1542
1543         dev = &rte_eth_devices[port_id];
1544         memset(stats, 0, sizeof(*stats));
1545
1546         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1547         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1548         return (*dev->dev_ops->stats_get)(dev, stats);
1549 }
1550
1551 int
1552 rte_eth_stats_reset(uint16_t port_id)
1553 {
1554         struct rte_eth_dev *dev;
1555
1556         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1557         dev = &rte_eth_devices[port_id];
1558
1559         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
1560         (*dev->dev_ops->stats_reset)(dev);
1561         dev->data->rx_mbuf_alloc_failed = 0;
1562
1563         return 0;
1564 }
1565
1566 static inline int
1567 get_xstats_basic_count(struct rte_eth_dev *dev)
1568 {
1569         uint16_t nb_rxqs, nb_txqs;
1570         int count;
1571
1572         nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1573         nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1574
1575         count = RTE_NB_STATS;
1576         count += nb_rxqs * RTE_NB_RXQ_STATS;
1577         count += nb_txqs * RTE_NB_TXQ_STATS;
1578
1579         return count;
1580 }
1581
1582 static int
1583 get_xstats_count(uint16_t port_id)
1584 {
1585         struct rte_eth_dev *dev;
1586         int count;
1587
1588         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1589         dev = &rte_eth_devices[port_id];
1590         if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1591                 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1592                                 NULL, 0);
1593                 if (count < 0)
1594                         return count;
1595         }
1596         if (dev->dev_ops->xstats_get_names != NULL) {
1597                 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1598                 if (count < 0)
1599                         return count;
1600         } else
1601                 count = 0;
1602
1603
1604         count += get_xstats_basic_count(dev);
1605
1606         return count;
1607 }
1608
1609 int
1610 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
1611                 uint64_t *id)
1612 {
1613         int cnt_xstats, idx_xstat;
1614
1615         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1616
1617         if (!id) {
1618                 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1619                 return -ENOMEM;
1620         }
1621
1622         if (!xstat_name) {
1623                 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1624                 return -ENOMEM;
1625         }
1626
1627         /* Get count */
1628         cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1629         if (cnt_xstats  < 0) {
1630                 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1631                 return -ENODEV;
1632         }
1633
1634         /* Get id-name lookup table */
1635         struct rte_eth_xstat_name xstats_names[cnt_xstats];
1636
1637         if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1638                         port_id, xstats_names, cnt_xstats, NULL)) {
1639                 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1640                 return -1;
1641         }
1642
1643         for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1644                 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1645                         *id = idx_xstat;
1646                         return 0;
1647                 };
1648         }
1649
1650         return -EINVAL;
1651 }
1652
1653 /* retrieve ethdev extended statistics names */
1654 int
1655 rte_eth_xstats_get_names_by_id(uint16_t port_id,
1656         struct rte_eth_xstat_name *xstats_names, unsigned int size,
1657         uint64_t *ids)
1658 {
1659         struct rte_eth_xstat_name *xstats_names_copy;
1660         unsigned int no_basic_stat_requested = 1;
1661         unsigned int expected_entries;
1662         struct rte_eth_dev *dev;
1663         unsigned int i;
1664         int ret;
1665
1666         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1667         dev = &rte_eth_devices[port_id];
1668
1669         ret = get_xstats_count(port_id);
1670         if (ret < 0)
1671                 return ret;
1672         expected_entries = (unsigned int)ret;
1673
1674         /* Return max number of stats if no ids given */
1675         if (!ids) {
1676                 if (!xstats_names)
1677                         return expected_entries;
1678                 else if (xstats_names && size < expected_entries)
1679                         return expected_entries;
1680         }
1681
1682         if (ids && !xstats_names)
1683                 return -EINVAL;
1684
1685         if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
1686                 unsigned int basic_count = get_xstats_basic_count(dev);
1687                 uint64_t ids_copy[size];
1688
1689                 for (i = 0; i < size; i++) {
1690                         if (ids[i] < basic_count) {
1691                                 no_basic_stat_requested = 0;
1692                                 break;
1693                         }
1694
1695                         /*
1696                          * Convert ids to xstats ids that PMD knows.
1697                          * ids known by user are basic + extended stats.
1698                          */
1699                         ids_copy[i] = ids[i] - basic_count;
1700                 }
1701
1702                 if (no_basic_stat_requested)
1703                         return (*dev->dev_ops->xstats_get_names_by_id)(dev,
1704                                         xstats_names, ids_copy, size);
1705         }
1706
1707         /* Retrieve all stats */
1708         if (!ids) {
1709                 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
1710                                 expected_entries);
1711                 if (num_stats < 0 || num_stats > (int)expected_entries)
1712                         return num_stats;
1713                 else
1714                         return expected_entries;
1715         }
1716
1717         xstats_names_copy = calloc(expected_entries,
1718                 sizeof(struct rte_eth_xstat_name));
1719
1720         if (!xstats_names_copy) {
1721                 RTE_PMD_DEBUG_TRACE("ERROR: can't allocate memory");
1722                 return -ENOMEM;
1723         }
1724
1725         /* Fill xstats_names_copy structure */
1726         rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries);
1727
1728         /* Filter stats */
1729         for (i = 0; i < size; i++) {
1730                 if (ids[i] >= expected_entries) {
1731                         RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1732                         free(xstats_names_copy);
1733                         return -1;
1734                 }
1735                 xstats_names[i] = xstats_names_copy[ids[i]];
1736         }
1737
1738         free(xstats_names_copy);
1739         return size;
1740 }
1741
1742 int
1743 rte_eth_xstats_get_names(uint16_t port_id,
1744         struct rte_eth_xstat_name *xstats_names,
1745         unsigned int size)
1746 {
1747         struct rte_eth_dev *dev;
1748         int cnt_used_entries;
1749         int cnt_expected_entries;
1750         int cnt_driver_entries;
1751         uint32_t idx, id_queue;
1752         uint16_t num_q;
1753
1754         cnt_expected_entries = get_xstats_count(port_id);
1755         if (xstats_names == NULL || cnt_expected_entries < 0 ||
1756                         (int)size < cnt_expected_entries)
1757                 return cnt_expected_entries;
1758
1759         /* port_id checked in get_xstats_count() */
1760         dev = &rte_eth_devices[port_id];
1761         cnt_used_entries = 0;
1762
1763         for (idx = 0; idx < RTE_NB_STATS; idx++) {
1764                 snprintf(xstats_names[cnt_used_entries].name,
1765                         sizeof(xstats_names[0].name),
1766                         "%s", rte_stats_strings[idx].name);
1767                 cnt_used_entries++;
1768         }
1769         num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1770         for (id_queue = 0; id_queue < num_q; id_queue++) {
1771                 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1772                         snprintf(xstats_names[cnt_used_entries].name,
1773                                 sizeof(xstats_names[0].name),
1774                                 "rx_q%u%s",
1775                                 id_queue, rte_rxq_stats_strings[idx].name);
1776                         cnt_used_entries++;
1777                 }
1778
1779         }
1780         num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1781         for (id_queue = 0; id_queue < num_q; id_queue++) {
1782                 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1783                         snprintf(xstats_names[cnt_used_entries].name,
1784                                 sizeof(xstats_names[0].name),
1785                                 "tx_q%u%s",
1786                                 id_queue, rte_txq_stats_strings[idx].name);
1787                         cnt_used_entries++;
1788                 }
1789         }
1790
1791         if (dev->dev_ops->xstats_get_names != NULL) {
1792                 /* If there are any driver-specific xstats, append them
1793                  * to end of list.
1794                  */
1795                 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1796                         dev,
1797                         xstats_names + cnt_used_entries,
1798                         size - cnt_used_entries);
1799                 if (cnt_driver_entries < 0)
1800                         return cnt_driver_entries;
1801                 cnt_used_entries += cnt_driver_entries;
1802         }
1803
1804         return cnt_used_entries;
1805 }
1806
1807 /* retrieve ethdev extended statistics */
1808 int
1809 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
1810                          uint64_t *values, unsigned int size)
1811 {
1812         unsigned int no_basic_stat_requested = 1;
1813         unsigned int num_xstats_filled;
1814         uint16_t expected_entries;
1815         struct rte_eth_dev *dev;
1816         unsigned int i;
1817         int ret;
1818
1819         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1820         expected_entries = get_xstats_count(port_id);
1821         struct rte_eth_xstat xstats[expected_entries];
1822         dev = &rte_eth_devices[port_id];
1823
1824         /* Return max number of stats if no ids given */
1825         if (!ids) {
1826                 if (!values)
1827                         return expected_entries;
1828                 else if (values && size < expected_entries)
1829                         return expected_entries;
1830         }
1831
1832         if (ids && !values)
1833                 return -EINVAL;
1834
1835         if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
1836                 unsigned int basic_count = get_xstats_basic_count(dev);
1837                 uint64_t ids_copy[size];
1838
1839                 for (i = 0; i < size; i++) {
1840                         if (ids[i] < basic_count) {
1841                                 no_basic_stat_requested = 0;
1842                                 break;
1843                         }
1844
1845                         /*
1846                          * Convert ids to xstats ids that PMD knows.
1847                          * ids known by user are basic + extended stats.
1848                          */
1849                         ids_copy[i] = ids[i] - basic_count;
1850                 }
1851
1852                 if (no_basic_stat_requested)
1853                         return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
1854                                         values, size);
1855         }
1856
1857         /* Fill the xstats structure */
1858         ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
1859         if (ret < 0)
1860                 return ret;
1861         num_xstats_filled = (unsigned int)ret;
1862
1863         /* Return all stats */
1864         if (!ids) {
1865                 for (i = 0; i < num_xstats_filled; i++)
1866                         values[i] = xstats[i].value;
1867                 return expected_entries;
1868         }
1869
1870         /* Filter stats */
1871         for (i = 0; i < size; i++) {
1872                 if (ids[i] >= expected_entries) {
1873                         RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1874                         return -1;
1875                 }
1876                 values[i] = xstats[ids[i]].value;
1877         }
1878         return size;
1879 }
1880
1881 int
1882 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
1883         unsigned int n)
1884 {
1885         struct rte_eth_stats eth_stats;
1886         struct rte_eth_dev *dev;
1887         unsigned int count = 0, i, q;
1888         signed int xcount = 0;
1889         uint64_t val, *stats_ptr;
1890         uint16_t nb_rxqs, nb_txqs;
1891
1892         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1893
1894         dev = &rte_eth_devices[port_id];
1895
1896         nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1897         nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1898
1899         /* Return generic statistics */
1900         count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1901                 (nb_txqs * RTE_NB_TXQ_STATS);
1902
1903         /* implemented by the driver */
1904         if (dev->dev_ops->xstats_get != NULL) {
1905                 /* Retrieve the xstats from the driver at the end of the
1906                  * xstats struct.
1907                  */
1908                 xcount = (*dev->dev_ops->xstats_get)(dev,
1909                                      xstats ? xstats + count : NULL,
1910                                      (n > count) ? n - count : 0);
1911
1912                 if (xcount < 0)
1913                         return xcount;
1914         }
1915
1916         if (n < count + xcount || xstats == NULL)
1917                 return count + xcount;
1918
1919         /* now fill the xstats structure */
1920         count = 0;
1921         rte_eth_stats_get(port_id, &eth_stats);
1922
1923         /* global stats */
1924         for (i = 0; i < RTE_NB_STATS; i++) {
1925                 stats_ptr = RTE_PTR_ADD(&eth_stats,
1926                                         rte_stats_strings[i].offset);
1927                 val = *stats_ptr;
1928                 xstats[count++].value = val;
1929         }
1930
1931         /* per-rxq stats */
1932         for (q = 0; q < nb_rxqs; q++) {
1933                 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1934                         stats_ptr = RTE_PTR_ADD(&eth_stats,
1935                                         rte_rxq_stats_strings[i].offset +
1936                                         q * sizeof(uint64_t));
1937                         val = *stats_ptr;
1938                         xstats[count++].value = val;
1939                 }
1940         }
1941
1942         /* per-txq stats */
1943         for (q = 0; q < nb_txqs; q++) {
1944                 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1945                         stats_ptr = RTE_PTR_ADD(&eth_stats,
1946                                         rte_txq_stats_strings[i].offset +
1947                                         q * sizeof(uint64_t));
1948                         val = *stats_ptr;
1949                         xstats[count++].value = val;
1950                 }
1951         }
1952
1953         for (i = 0; i < count; i++)
1954                 xstats[i].id = i;
1955         /* add an offset to driver-specific stats */
1956         for ( ; i < count + xcount; i++)
1957                 xstats[i].id += count;
1958
1959         return count + xcount;
1960 }
1961
1962 /* reset ethdev extended statistics */
1963 void
1964 rte_eth_xstats_reset(uint16_t port_id)
1965 {
1966         struct rte_eth_dev *dev;
1967
1968         RTE_ETH_VALID_PORTID_OR_RET(port_id);
1969         dev = &rte_eth_devices[port_id];
1970
1971         /* implemented by the driver */
1972         if (dev->dev_ops->xstats_reset != NULL) {
1973                 (*dev->dev_ops->xstats_reset)(dev);
1974                 return;
1975         }
1976
1977         /* fallback to default */
1978         rte_eth_stats_reset(port_id);
1979 }
1980
1981 static int
1982 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
1983                 uint8_t is_rx)
1984 {
1985         struct rte_eth_dev *dev;
1986
1987         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1988
1989         dev = &rte_eth_devices[port_id];
1990
1991         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1992         return (*dev->dev_ops->queue_stats_mapping_set)
1993                         (dev, queue_id, stat_idx, is_rx);
1994 }
1995
1996
1997 int
1998 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
1999                 uint8_t stat_idx)
2000 {
2001         return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
2002                         STAT_QMAP_TX);
2003 }
2004
2005
2006 int
2007 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
2008                 uint8_t stat_idx)
2009 {
2010         return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
2011                         STAT_QMAP_RX);
2012 }
2013
2014 int
2015 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
2016 {
2017         struct rte_eth_dev *dev;
2018
2019         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2020         dev = &rte_eth_devices[port_id];
2021
2022         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2023         return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
2024 }
2025
2026 void
2027 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
2028 {
2029         struct rte_eth_dev *dev;
2030         const struct rte_eth_desc_lim lim = {
2031                 .nb_max = UINT16_MAX,
2032                 .nb_min = 0,
2033                 .nb_align = 1,
2034         };
2035
2036         RTE_ETH_VALID_PORTID_OR_RET(port_id);
2037         dev = &rte_eth_devices[port_id];
2038
2039         memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2040         dev_info->rx_desc_lim = lim;
2041         dev_info->tx_desc_lim = lim;
2042
2043         RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
2044         (*dev->dev_ops->dev_infos_get)(dev, dev_info);
2045         dev_info->driver_name = dev->device->driver->name;
2046         dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2047         dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2048 }
2049
2050 int
2051 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
2052                                  uint32_t *ptypes, int num)
2053 {
2054         int i, j;
2055         struct rte_eth_dev *dev;
2056         const uint32_t *all_ptypes;
2057
2058         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2059         dev = &rte_eth_devices[port_id];
2060         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2061         all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2062
2063         if (!all_ptypes)
2064                 return 0;
2065
2066         for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2067                 if (all_ptypes[i] & ptype_mask) {
2068                         if (j < num)
2069                                 ptypes[j] = all_ptypes[i];
2070                         j++;
2071                 }
2072
2073         return j;
2074 }
2075
2076 void
2077 rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
2078 {
2079         struct rte_eth_dev *dev;
2080
2081         RTE_ETH_VALID_PORTID_OR_RET(port_id);
2082         dev = &rte_eth_devices[port_id];
2083         ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2084 }
2085
2086
2087 int
2088 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2089 {
2090         struct rte_eth_dev *dev;
2091
2092         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2093
2094         dev = &rte_eth_devices[port_id];
2095         *mtu = dev->data->mtu;
2096         return 0;
2097 }
2098
2099 int
2100 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2101 {
2102         int ret;
2103         struct rte_eth_dev *dev;
2104
2105         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2106         dev = &rte_eth_devices[port_id];
2107         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2108
2109         ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2110         if (!ret)
2111                 dev->data->mtu = mtu;
2112
2113         return ret;
2114 }
2115
2116 int
2117 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2118 {
2119         struct rte_eth_dev *dev;
2120         int ret;
2121
2122         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2123         dev = &rte_eth_devices[port_id];
2124         if (!(dev->data->dev_conf.rxmode.offloads &
2125               DEV_RX_OFFLOAD_VLAN_FILTER)) {
2126                 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2127                 return -ENOSYS;
2128         }
2129
2130         if (vlan_id > 4095) {
2131                 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2132                                 port_id, (unsigned) vlan_id);
2133                 return -EINVAL;
2134         }
2135         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2136
2137         ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2138         if (ret == 0) {
2139                 struct rte_vlan_filter_conf *vfc;
2140                 int vidx;
2141                 int vbit;
2142
2143                 vfc = &dev->data->vlan_filter_conf;
2144                 vidx = vlan_id / 64;
2145                 vbit = vlan_id % 64;
2146
2147                 if (on)
2148                         vfc->ids[vidx] |= UINT64_C(1) << vbit;
2149                 else
2150                         vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2151         }
2152
2153         return ret;
2154 }
2155
2156 int
2157 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2158                                     int on)
2159 {
2160         struct rte_eth_dev *dev;
2161
2162         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2163         dev = &rte_eth_devices[port_id];
2164         if (rx_queue_id >= dev->data->nb_rx_queues) {
2165                 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2166                 return -EINVAL;
2167         }
2168
2169         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2170         (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2171
2172         return 0;
2173 }
2174
2175 int
2176 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2177                                 enum rte_vlan_type vlan_type,
2178                                 uint16_t tpid)
2179 {
2180         struct rte_eth_dev *dev;
2181
2182         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2183         dev = &rte_eth_devices[port_id];
2184         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2185
2186         return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2187 }
2188
2189 int
2190 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2191 {
2192         struct rte_eth_dev *dev;
2193         int ret = 0;
2194         int mask = 0;
2195         int cur, org = 0;
2196
2197         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2198         dev = &rte_eth_devices[port_id];
2199
2200         /*check which option changed by application*/
2201         cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2202         org = !!(dev->data->dev_conf.rxmode.offloads &
2203                  DEV_RX_OFFLOAD_VLAN_STRIP);
2204         if (cur != org) {
2205                 if (cur)
2206                         dev->data->dev_conf.rxmode.offloads |=
2207                                 DEV_RX_OFFLOAD_VLAN_STRIP;
2208                 else
2209                         dev->data->dev_conf.rxmode.offloads &=
2210                                 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2211                 mask |= ETH_VLAN_STRIP_MASK;
2212         }
2213
2214         cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2215         org = !!(dev->data->dev_conf.rxmode.offloads &
2216                  DEV_RX_OFFLOAD_VLAN_FILTER);
2217         if (cur != org) {
2218                 if (cur)
2219                         dev->data->dev_conf.rxmode.offloads |=
2220                                 DEV_RX_OFFLOAD_VLAN_FILTER;
2221                 else
2222                         dev->data->dev_conf.rxmode.offloads &=
2223                                 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2224                 mask |= ETH_VLAN_FILTER_MASK;
2225         }
2226
2227         cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2228         org = !!(dev->data->dev_conf.rxmode.offloads &
2229                  DEV_RX_OFFLOAD_VLAN_EXTEND);
2230         if (cur != org) {
2231                 if (cur)
2232                         dev->data->dev_conf.rxmode.offloads |=
2233                                 DEV_RX_OFFLOAD_VLAN_EXTEND;
2234                 else
2235                         dev->data->dev_conf.rxmode.offloads &=
2236                                 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2237                 mask |= ETH_VLAN_EXTEND_MASK;
2238         }
2239
2240         /*no change*/
2241         if (mask == 0)
2242                 return ret;
2243
2244         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2245
2246         /*
2247          * Convert to the offload bitfield API just in case the underlying PMD
2248          * still supporting it.
2249          */
2250         rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2251                                     &dev->data->dev_conf.rxmode);
2252         (*dev->dev_ops->vlan_offload_set)(dev, mask);
2253
2254         return ret;
2255 }
2256
2257 int
2258 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2259 {
2260         struct rte_eth_dev *dev;
2261         int ret = 0;
2262
2263         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2264         dev = &rte_eth_devices[port_id];
2265
2266         if (dev->data->dev_conf.rxmode.offloads &
2267             DEV_RX_OFFLOAD_VLAN_STRIP)
2268                 ret |= ETH_VLAN_STRIP_OFFLOAD;
2269
2270         if (dev->data->dev_conf.rxmode.offloads &
2271             DEV_RX_OFFLOAD_VLAN_FILTER)
2272                 ret |= ETH_VLAN_FILTER_OFFLOAD;
2273
2274         if (dev->data->dev_conf.rxmode.offloads &
2275             DEV_RX_OFFLOAD_VLAN_EXTEND)
2276                 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2277
2278         return ret;
2279 }
2280
2281 int
2282 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2283 {
2284         struct rte_eth_dev *dev;
2285
2286         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2287         dev = &rte_eth_devices[port_id];
2288         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2289         (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2290
2291         return 0;
2292 }
2293
2294 int
2295 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2296 {
2297         struct rte_eth_dev *dev;
2298
2299         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2300         dev = &rte_eth_devices[port_id];
2301         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2302         memset(fc_conf, 0, sizeof(*fc_conf));
2303         return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2304 }
2305
2306 int
2307 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2308 {
2309         struct rte_eth_dev *dev;
2310
2311         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2312         if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2313                 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2314                 return -EINVAL;
2315         }
2316
2317         dev = &rte_eth_devices[port_id];
2318         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2319         return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2320 }
2321
2322 int
2323 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
2324                                    struct rte_eth_pfc_conf *pfc_conf)
2325 {
2326         struct rte_eth_dev *dev;
2327
2328         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2329         if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2330                 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2331                 return -EINVAL;
2332         }
2333
2334         dev = &rte_eth_devices[port_id];
2335         /* High water, low water validation are device specific */
2336         if  (*dev->dev_ops->priority_flow_ctrl_set)
2337                 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2338         return -ENOTSUP;
2339 }
2340
2341 static int
2342 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2343                         uint16_t reta_size)
2344 {
2345         uint16_t i, num;
2346
2347         if (!reta_conf)
2348                 return -EINVAL;
2349
2350         num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2351         for (i = 0; i < num; i++) {
2352                 if (reta_conf[i].mask)
2353                         return 0;
2354         }
2355
2356         return -EINVAL;
2357 }
2358
2359 static int
2360 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2361                          uint16_t reta_size,
2362                          uint16_t max_rxq)
2363 {
2364         uint16_t i, idx, shift;
2365
2366         if (!reta_conf)
2367                 return -EINVAL;
2368
2369         if (max_rxq == 0) {
2370                 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2371                 return -EINVAL;
2372         }
2373
2374         for (i = 0; i < reta_size; i++) {
2375                 idx = i / RTE_RETA_GROUP_SIZE;
2376                 shift = i % RTE_RETA_GROUP_SIZE;
2377                 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2378                         (reta_conf[idx].reta[shift] >= max_rxq)) {
2379                         RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2380                                 "the maximum rxq index: %u\n", idx, shift,
2381                                 reta_conf[idx].reta[shift], max_rxq);
2382                         return -EINVAL;
2383                 }
2384         }
2385
2386         return 0;
2387 }
2388
2389 int
2390 rte_eth_dev_rss_reta_update(uint16_t port_id,
2391                             struct rte_eth_rss_reta_entry64 *reta_conf,
2392                             uint16_t reta_size)
2393 {
2394         struct rte_eth_dev *dev;
2395         int ret;
2396
2397         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2398         /* Check mask bits */
2399         ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2400         if (ret < 0)
2401                 return ret;
2402
2403         dev = &rte_eth_devices[port_id];
2404
2405         /* Check entry value */
2406         ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2407                                 dev->data->nb_rx_queues);
2408         if (ret < 0)
2409                 return ret;
2410
2411         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2412         return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2413 }
2414
2415 int
2416 rte_eth_dev_rss_reta_query(uint16_t port_id,
2417                            struct rte_eth_rss_reta_entry64 *reta_conf,
2418                            uint16_t reta_size)
2419 {
2420         struct rte_eth_dev *dev;
2421         int ret;
2422
2423         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2424
2425         /* Check mask bits */
2426         ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2427         if (ret < 0)
2428                 return ret;
2429
2430         dev = &rte_eth_devices[port_id];
2431         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2432         return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2433 }
2434
2435 int
2436 rte_eth_dev_rss_hash_update(uint16_t port_id,
2437                             struct rte_eth_rss_conf *rss_conf)
2438 {
2439         struct rte_eth_dev *dev;
2440
2441         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2442         dev = &rte_eth_devices[port_id];
2443         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2444         return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2445 }
2446
2447 int
2448 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
2449                               struct rte_eth_rss_conf *rss_conf)
2450 {
2451         struct rte_eth_dev *dev;
2452
2453         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2454         dev = &rte_eth_devices[port_id];
2455         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2456         return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2457 }
2458
2459 int
2460 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
2461                                 struct rte_eth_udp_tunnel *udp_tunnel)
2462 {
2463         struct rte_eth_dev *dev;
2464
2465         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2466         if (udp_tunnel == NULL) {
2467                 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2468                 return -EINVAL;
2469         }
2470
2471         if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2472                 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2473                 return -EINVAL;
2474         }
2475
2476         dev = &rte_eth_devices[port_id];
2477         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2478         return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2479 }
2480
2481 int
2482 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
2483                                    struct rte_eth_udp_tunnel *udp_tunnel)
2484 {
2485         struct rte_eth_dev *dev;
2486
2487         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2488         dev = &rte_eth_devices[port_id];
2489
2490         if (udp_tunnel == NULL) {
2491                 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2492                 return -EINVAL;
2493         }
2494
2495         if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2496                 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2497                 return -EINVAL;
2498         }
2499
2500         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2501         return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2502 }
2503
2504 int
2505 rte_eth_led_on(uint16_t port_id)
2506 {
2507         struct rte_eth_dev *dev;
2508
2509         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2510         dev = &rte_eth_devices[port_id];
2511         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2512         return (*dev->dev_ops->dev_led_on)(dev);
2513 }
2514
2515 int
2516 rte_eth_led_off(uint16_t port_id)
2517 {
2518         struct rte_eth_dev *dev;
2519
2520         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2521         dev = &rte_eth_devices[port_id];
2522         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2523         return (*dev->dev_ops->dev_led_off)(dev);
2524 }
2525
2526 /*
2527  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2528  * an empty spot.
2529  */
2530 static int
2531 get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2532 {
2533         struct rte_eth_dev_info dev_info;
2534         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2535         unsigned i;
2536
2537         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2538         rte_eth_dev_info_get(port_id, &dev_info);
2539
2540         for (i = 0; i < dev_info.max_mac_addrs; i++)
2541                 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2542                         return i;
2543
2544         return -1;
2545 }
2546
2547 static const struct ether_addr null_mac_addr;
2548
2549 int
2550 rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
2551                         uint32_t pool)
2552 {
2553         struct rte_eth_dev *dev;
2554         int index;
2555         uint64_t pool_mask;
2556         int ret;
2557
2558         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2559         dev = &rte_eth_devices[port_id];
2560         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2561
2562         if (is_zero_ether_addr(addr)) {
2563                 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2564                         port_id);
2565                 return -EINVAL;
2566         }
2567         if (pool >= ETH_64_POOLS) {
2568                 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2569                 return -EINVAL;
2570         }
2571
2572         index = get_mac_addr_index(port_id, addr);
2573         if (index < 0) {
2574                 index = get_mac_addr_index(port_id, &null_mac_addr);
2575                 if (index < 0) {
2576                         RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2577                                 port_id);
2578                         return -ENOSPC;
2579                 }
2580         } else {
2581                 pool_mask = dev->data->mac_pool_sel[index];
2582
2583                 /* Check if both MAC address and pool is already there, and do nothing */
2584                 if (pool_mask & (1ULL << pool))
2585                         return 0;
2586         }
2587
2588         /* Update NIC */
2589         ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2590
2591         if (ret == 0) {
2592                 /* Update address in NIC data structure */
2593                 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2594
2595                 /* Update pool bitmap in NIC data structure */
2596                 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2597         }
2598
2599         return ret;
2600 }
2601
2602 int
2603 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
2604 {
2605         struct rte_eth_dev *dev;
2606         int index;
2607
2608         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2609         dev = &rte_eth_devices[port_id];
2610         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2611
2612         index = get_mac_addr_index(port_id, addr);
2613         if (index == 0) {
2614                 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2615                 return -EADDRINUSE;
2616         } else if (index < 0)
2617                 return 0;  /* Do nothing if address wasn't found */
2618
2619         /* Update NIC */
2620         (*dev->dev_ops->mac_addr_remove)(dev, index);
2621
2622         /* Update address in NIC data structure */
2623         ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2624
2625         /* reset pool bitmap */
2626         dev->data->mac_pool_sel[index] = 0;
2627
2628         return 0;
2629 }
2630
2631 int
2632 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
2633 {
2634         struct rte_eth_dev *dev;
2635
2636         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2637
2638         if (!is_valid_assigned_ether_addr(addr))
2639                 return -EINVAL;
2640
2641         dev = &rte_eth_devices[port_id];
2642         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2643
2644         /* Update default address in NIC data structure */
2645         ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2646
2647         (*dev->dev_ops->mac_addr_set)(dev, addr);
2648
2649         return 0;
2650 }
2651
2652
2653 /*
2654  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2655  * an empty spot.
2656  */
2657 static int
2658 get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2659 {
2660         struct rte_eth_dev_info dev_info;
2661         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2662         unsigned i;
2663
2664         rte_eth_dev_info_get(port_id, &dev_info);
2665         if (!dev->data->hash_mac_addrs)
2666                 return -1;
2667
2668         for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2669                 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2670                         ETHER_ADDR_LEN) == 0)
2671                         return i;
2672
2673         return -1;
2674 }
2675
2676 int
2677 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
2678                                 uint8_t on)
2679 {
2680         int index;
2681         int ret;
2682         struct rte_eth_dev *dev;
2683
2684         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2685
2686         dev = &rte_eth_devices[port_id];
2687         if (is_zero_ether_addr(addr)) {
2688                 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2689                         port_id);
2690                 return -EINVAL;
2691         }
2692
2693         index = get_hash_mac_addr_index(port_id, addr);
2694         /* Check if it's already there, and do nothing */
2695         if ((index >= 0) && (on))
2696                 return 0;
2697
2698         if (index < 0) {
2699                 if (!on) {
2700                         RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2701                                 "set in UTA\n", port_id);
2702                         return -EINVAL;
2703                 }
2704
2705                 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2706                 if (index < 0) {
2707                         RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2708                                         port_id);
2709                         return -ENOSPC;
2710                 }
2711         }
2712
2713         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2714         ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2715         if (ret == 0) {
2716                 /* Update address in NIC data structure */
2717                 if (on)
2718                         ether_addr_copy(addr,
2719                                         &dev->data->hash_mac_addrs[index]);
2720                 else
2721                         ether_addr_copy(&null_mac_addr,
2722                                         &dev->data->hash_mac_addrs[index]);
2723         }
2724
2725         return ret;
2726 }
2727
2728 int
2729 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
2730 {
2731         struct rte_eth_dev *dev;
2732
2733         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2734
2735         dev = &rte_eth_devices[port_id];
2736
2737         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2738         return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2739 }
2740
2741 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
2742                                         uint16_t tx_rate)
2743 {
2744         struct rte_eth_dev *dev;
2745         struct rte_eth_dev_info dev_info;
2746         struct rte_eth_link link;
2747
2748         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2749
2750         dev = &rte_eth_devices[port_id];
2751         rte_eth_dev_info_get(port_id, &dev_info);
2752         link = dev->data->dev_link;
2753
2754         if (queue_idx > dev_info.max_tx_queues) {
2755                 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2756                                 "invalid queue id=%d\n", port_id, queue_idx);
2757                 return -EINVAL;
2758         }
2759
2760         if (tx_rate > link.link_speed) {
2761                 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2762                                 "bigger than link speed= %d\n",
2763                         tx_rate, link.link_speed);
2764                 return -EINVAL;
2765         }
2766
2767         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2768         return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2769 }
2770
2771 int
2772 rte_eth_mirror_rule_set(uint16_t port_id,
2773                         struct rte_eth_mirror_conf *mirror_conf,
2774                         uint8_t rule_id, uint8_t on)
2775 {
2776         struct rte_eth_dev *dev;
2777
2778         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2779         if (mirror_conf->rule_type == 0) {
2780                 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2781                 return -EINVAL;
2782         }
2783
2784         if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2785                 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2786                                 ETH_64_POOLS - 1);
2787                 return -EINVAL;
2788         }
2789
2790         if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2791              ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2792             (mirror_conf->pool_mask == 0)) {
2793                 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2794                 return -EINVAL;
2795         }
2796
2797         if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2798             mirror_conf->vlan.vlan_mask == 0) {
2799                 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2800                 return -EINVAL;
2801         }
2802
2803         dev = &rte_eth_devices[port_id];
2804         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2805
2806         return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2807 }
2808
2809 int
2810 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
2811 {
2812         struct rte_eth_dev *dev;
2813
2814         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2815
2816         dev = &rte_eth_devices[port_id];
2817         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2818
2819         return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2820 }
2821
2822 int
2823 rte_eth_dev_callback_register(uint16_t port_id,
2824                         enum rte_eth_event_type event,
2825                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2826 {
2827         struct rte_eth_dev *dev;
2828         struct rte_eth_dev_callback *user_cb;
2829
2830         if (!cb_fn)
2831                 return -EINVAL;
2832
2833         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2834
2835         dev = &rte_eth_devices[port_id];
2836         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2837
2838         TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2839                 if (user_cb->cb_fn == cb_fn &&
2840                         user_cb->cb_arg == cb_arg &&
2841                         user_cb->event == event) {
2842                         break;
2843                 }
2844         }
2845
2846         /* create a new callback. */
2847         if (user_cb == NULL) {
2848                 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2849                                         sizeof(struct rte_eth_dev_callback), 0);
2850                 if (user_cb != NULL) {
2851                         user_cb->cb_fn = cb_fn;
2852                         user_cb->cb_arg = cb_arg;
2853                         user_cb->event = event;
2854                         TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2855                 }
2856         }
2857
2858         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2859         return (user_cb == NULL) ? -ENOMEM : 0;
2860 }
2861
2862 int
2863 rte_eth_dev_callback_unregister(uint16_t port_id,
2864                         enum rte_eth_event_type event,
2865                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2866 {
2867         int ret;
2868         struct rte_eth_dev *dev;
2869         struct rte_eth_dev_callback *cb, *next;
2870
2871         if (!cb_fn)
2872                 return -EINVAL;
2873
2874         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2875
2876         dev = &rte_eth_devices[port_id];
2877         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2878
2879         ret = 0;
2880         for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2881
2882                 next = TAILQ_NEXT(cb, next);
2883
2884                 if (cb->cb_fn != cb_fn || cb->event != event ||
2885                                 (cb->cb_arg != (void *)-1 &&
2886                                 cb->cb_arg != cb_arg))
2887                         continue;
2888
2889                 /*
2890                  * if this callback is not executing right now,
2891                  * then remove it.
2892                  */
2893                 if (cb->active == 0) {
2894                         TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2895                         rte_free(cb);
2896                 } else {
2897                         ret = -EAGAIN;
2898                 }
2899         }
2900
2901         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2902         return ret;
2903 }
2904
2905 int
2906 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2907         enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2908 {
2909         struct rte_eth_dev_callback *cb_lst;
2910         struct rte_eth_dev_callback dev_cb;
2911         int rc = 0;
2912
2913         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2914         TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2915                 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2916                         continue;
2917                 dev_cb = *cb_lst;
2918                 cb_lst->active = 1;
2919                 if (cb_arg != NULL)
2920                         dev_cb.cb_arg = cb_arg;
2921                 if (ret_param != NULL)
2922                         dev_cb.ret_param = ret_param;
2923
2924                 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2925                 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2926                                 dev_cb.cb_arg, dev_cb.ret_param);
2927                 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2928                 cb_lst->active = 0;
2929         }
2930         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2931         return rc;
2932 }
2933
2934 int
2935 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
2936 {
2937         uint32_t vec;
2938         struct rte_eth_dev *dev;
2939         struct rte_intr_handle *intr_handle;
2940         uint16_t qid;
2941         int rc;
2942
2943         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2944
2945         dev = &rte_eth_devices[port_id];
2946
2947         if (!dev->intr_handle) {
2948                 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2949                 return -ENOTSUP;
2950         }
2951
2952         intr_handle = dev->intr_handle;
2953         if (!intr_handle->intr_vec) {
2954                 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2955                 return -EPERM;
2956         }
2957
2958         for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2959                 vec = intr_handle->intr_vec[qid];
2960                 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2961                 if (rc && rc != -EEXIST) {
2962                         RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2963                                         " op %d epfd %d vec %u\n",
2964                                         port_id, qid, op, epfd, vec);
2965                 }
2966         }
2967
2968         return 0;
2969 }
2970
2971 const struct rte_memzone *
2972 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2973                          uint16_t queue_id, size_t size, unsigned align,
2974                          int socket_id)
2975 {
2976         char z_name[RTE_MEMZONE_NAMESIZE];
2977         const struct rte_memzone *mz;
2978
2979         snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2980                  dev->device->driver->name, ring_name,
2981                  dev->data->port_id, queue_id);
2982
2983         mz = rte_memzone_lookup(z_name);
2984         if (mz)
2985                 return mz;
2986
2987         return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align);
2988 }
2989
2990 int
2991 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
2992                           int epfd, int op, void *data)
2993 {
2994         uint32_t vec;
2995         struct rte_eth_dev *dev;
2996         struct rte_intr_handle *intr_handle;
2997         int rc;
2998
2999         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3000
3001         dev = &rte_eth_devices[port_id];
3002         if (queue_id >= dev->data->nb_rx_queues) {
3003                 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
3004                 return -EINVAL;
3005         }
3006
3007         if (!dev->intr_handle) {
3008                 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3009                 return -ENOTSUP;
3010         }
3011
3012         intr_handle = dev->intr_handle;
3013         if (!intr_handle->intr_vec) {
3014                 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3015                 return -EPERM;
3016         }
3017
3018         vec = intr_handle->intr_vec[queue_id];
3019         rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3020         if (rc && rc != -EEXIST) {
3021                 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3022                                 " op %d epfd %d vec %u\n",
3023                                 port_id, queue_id, op, epfd, vec);
3024                 return rc;
3025         }
3026
3027         return 0;
3028 }
3029
3030 int
3031 rte_eth_dev_rx_intr_enable(uint16_t port_id,
3032                            uint16_t queue_id)
3033 {
3034         struct rte_eth_dev *dev;
3035
3036         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3037
3038         dev = &rte_eth_devices[port_id];
3039
3040         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3041         return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
3042 }
3043
3044 int
3045 rte_eth_dev_rx_intr_disable(uint16_t port_id,
3046                             uint16_t queue_id)
3047 {
3048         struct rte_eth_dev *dev;
3049
3050         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3051
3052         dev = &rte_eth_devices[port_id];
3053
3054         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3055         return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
3056 }
3057
3058
3059 int
3060 rte_eth_dev_filter_supported(uint16_t port_id,
3061                              enum rte_filter_type filter_type)
3062 {
3063         struct rte_eth_dev *dev;
3064
3065         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3066
3067         dev = &rte_eth_devices[port_id];
3068         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3069         return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3070                                 RTE_ETH_FILTER_NOP, NULL);
3071 }
3072
3073 int
3074 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3075                        enum rte_filter_op filter_op, void *arg)
3076 {
3077         struct rte_eth_dev *dev;
3078
3079         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3080
3081         dev = &rte_eth_devices[port_id];
3082         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3083         return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3084 }
3085
3086 void *
3087 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
3088                 rte_rx_callback_fn fn, void *user_param)
3089 {
3090 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3091         rte_errno = ENOTSUP;
3092         return NULL;
3093 #endif
3094         /* check input parameters */
3095         if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3096                     queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3097                 rte_errno = EINVAL;
3098                 return NULL;
3099         }
3100         struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3101
3102         if (cb == NULL) {
3103                 rte_errno = ENOMEM;
3104                 return NULL;
3105         }
3106
3107         cb->fn.rx = fn;
3108         cb->param = user_param;
3109
3110         rte_spinlock_lock(&rte_eth_rx_cb_lock);
3111         /* Add the callbacks in fifo order. */
3112         struct rte_eth_rxtx_callback *tail =
3113                 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3114
3115         if (!tail) {
3116                 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3117
3118         } else {
3119                 while (tail->next)
3120                         tail = tail->next;
3121                 tail->next = cb;
3122         }
3123         rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3124
3125         return cb;
3126 }
3127
3128 void *
3129 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
3130                 rte_rx_callback_fn fn, void *user_param)
3131 {
3132 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3133         rte_errno = ENOTSUP;
3134         return NULL;
3135 #endif
3136         /* check input parameters */
3137         if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3138                 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3139                 rte_errno = EINVAL;
3140                 return NULL;
3141         }
3142
3143         struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3144
3145         if (cb == NULL) {
3146                 rte_errno = ENOMEM;
3147                 return NULL;
3148         }
3149
3150         cb->fn.rx = fn;
3151         cb->param = user_param;
3152
3153         rte_spinlock_lock(&rte_eth_rx_cb_lock);
3154         /* Add the callbacks at fisrt position*/
3155         cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3156         rte_smp_wmb();
3157         rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3158         rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3159
3160         return cb;
3161 }
3162
3163 void *
3164 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
3165                 rte_tx_callback_fn fn, void *user_param)
3166 {
3167 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3168         rte_errno = ENOTSUP;
3169         return NULL;
3170 #endif
3171         /* check input parameters */
3172         if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3173                     queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3174                 rte_errno = EINVAL;
3175                 return NULL;
3176         }
3177
3178         struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3179
3180         if (cb == NULL) {
3181                 rte_errno = ENOMEM;
3182                 return NULL;
3183         }
3184
3185         cb->fn.tx = fn;
3186         cb->param = user_param;
3187
3188         rte_spinlock_lock(&rte_eth_tx_cb_lock);
3189         /* Add the callbacks in fifo order. */
3190         struct rte_eth_rxtx_callback *tail =
3191                 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3192
3193         if (!tail) {
3194                 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3195
3196         } else {
3197                 while (tail->next)
3198                         tail = tail->next;
3199                 tail->next = cb;
3200         }
3201         rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3202
3203         return cb;
3204 }
3205
3206 int
3207 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
3208                 struct rte_eth_rxtx_callback *user_cb)
3209 {
3210 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3211         return -ENOTSUP;
3212 #endif
3213         /* Check input parameters. */
3214         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3215         if (user_cb == NULL ||
3216                         queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3217                 return -EINVAL;
3218
3219         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3220         struct rte_eth_rxtx_callback *cb;
3221         struct rte_eth_rxtx_callback **prev_cb;
3222         int ret = -EINVAL;
3223
3224         rte_spinlock_lock(&rte_eth_rx_cb_lock);
3225         prev_cb = &dev->post_rx_burst_cbs[queue_id];
3226         for (; *prev_cb != NULL; prev_cb = &cb->next) {
3227                 cb = *prev_cb;
3228                 if (cb == user_cb) {
3229                         /* Remove the user cb from the callback list. */
3230                         *prev_cb = cb->next;
3231                         ret = 0;
3232                         break;
3233                 }
3234         }
3235         rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3236
3237         return ret;
3238 }
3239
3240 int
3241 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
3242                 struct rte_eth_rxtx_callback *user_cb)
3243 {
3244 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3245         return -ENOTSUP;
3246 #endif
3247         /* Check input parameters. */
3248         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3249         if (user_cb == NULL ||
3250                         queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3251                 return -EINVAL;
3252
3253         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3254         int ret = -EINVAL;
3255         struct rte_eth_rxtx_callback *cb;
3256         struct rte_eth_rxtx_callback **prev_cb;
3257
3258         rte_spinlock_lock(&rte_eth_tx_cb_lock);
3259         prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3260         for (; *prev_cb != NULL; prev_cb = &cb->next) {
3261                 cb = *prev_cb;
3262                 if (cb == user_cb) {
3263                         /* Remove the user cb from the callback list. */
3264                         *prev_cb = cb->next;
3265                         ret = 0;
3266                         break;
3267                 }
3268         }
3269         rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3270
3271         return ret;
3272 }
3273
3274 int
3275 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3276         struct rte_eth_rxq_info *qinfo)
3277 {
3278         struct rte_eth_dev *dev;
3279
3280         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3281
3282         if (qinfo == NULL)
3283                 return -EINVAL;
3284
3285         dev = &rte_eth_devices[port_id];
3286         if (queue_id >= dev->data->nb_rx_queues) {
3287                 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3288                 return -EINVAL;
3289         }
3290
3291         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3292
3293         memset(qinfo, 0, sizeof(*qinfo));
3294         dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3295         return 0;
3296 }
3297
3298 int
3299 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3300         struct rte_eth_txq_info *qinfo)
3301 {
3302         struct rte_eth_dev *dev;
3303
3304         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3305
3306         if (qinfo == NULL)
3307                 return -EINVAL;
3308
3309         dev = &rte_eth_devices[port_id];
3310         if (queue_id >= dev->data->nb_tx_queues) {
3311                 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3312                 return -EINVAL;
3313         }
3314
3315         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3316
3317         memset(qinfo, 0, sizeof(*qinfo));
3318         dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3319         return 0;
3320 }
3321
3322 int
3323 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
3324                              struct ether_addr *mc_addr_set,
3325                              uint32_t nb_mc_addr)
3326 {
3327         struct rte_eth_dev *dev;
3328
3329         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3330
3331         dev = &rte_eth_devices[port_id];
3332         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3333         return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3334 }
3335
3336 int
3337 rte_eth_timesync_enable(uint16_t port_id)
3338 {
3339         struct rte_eth_dev *dev;
3340
3341         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3342         dev = &rte_eth_devices[port_id];
3343
3344         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3345         return (*dev->dev_ops->timesync_enable)(dev);
3346 }
3347
3348 int
3349 rte_eth_timesync_disable(uint16_t port_id)
3350 {
3351         struct rte_eth_dev *dev;
3352
3353         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3354         dev = &rte_eth_devices[port_id];
3355
3356         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3357         return (*dev->dev_ops->timesync_disable)(dev);
3358 }
3359
3360 int
3361 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
3362                                    uint32_t flags)
3363 {
3364         struct rte_eth_dev *dev;
3365
3366         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3367         dev = &rte_eth_devices[port_id];
3368
3369         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3370         return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3371 }
3372
3373 int
3374 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
3375                                    struct timespec *timestamp)
3376 {
3377         struct rte_eth_dev *dev;
3378
3379         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3380         dev = &rte_eth_devices[port_id];
3381
3382         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3383         return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3384 }
3385
3386 int
3387 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
3388 {
3389         struct rte_eth_dev *dev;
3390
3391         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3392         dev = &rte_eth_devices[port_id];
3393
3394         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3395         return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3396 }
3397
3398 int
3399 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
3400 {
3401         struct rte_eth_dev *dev;
3402
3403         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3404         dev = &rte_eth_devices[port_id];
3405
3406         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3407         return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3408 }
3409
3410 int
3411 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
3412 {
3413         struct rte_eth_dev *dev;
3414
3415         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3416         dev = &rte_eth_devices[port_id];
3417
3418         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3419         return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3420 }
3421
3422 int
3423 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
3424 {
3425         struct rte_eth_dev *dev;
3426
3427         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3428
3429         dev = &rte_eth_devices[port_id];
3430         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3431         return (*dev->dev_ops->get_reg)(dev, info);
3432 }
3433
3434 int
3435 rte_eth_dev_get_eeprom_length(uint16_t port_id)
3436 {
3437         struct rte_eth_dev *dev;
3438
3439         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3440
3441         dev = &rte_eth_devices[port_id];
3442         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3443         return (*dev->dev_ops->get_eeprom_length)(dev);
3444 }
3445
3446 int
3447 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3448 {
3449         struct rte_eth_dev *dev;
3450
3451         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3452
3453         dev = &rte_eth_devices[port_id];
3454         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3455         return (*dev->dev_ops->get_eeprom)(dev, info);
3456 }
3457
3458 int
3459 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3460 {
3461         struct rte_eth_dev *dev;
3462
3463         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3464
3465         dev = &rte_eth_devices[port_id];
3466         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3467         return (*dev->dev_ops->set_eeprom)(dev, info);
3468 }
3469
3470 int
3471 rte_eth_dev_get_dcb_info(uint16_t port_id,
3472                              struct rte_eth_dcb_info *dcb_info)
3473 {
3474         struct rte_eth_dev *dev;
3475
3476         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3477
3478         dev = &rte_eth_devices[port_id];
3479         memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3480
3481         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3482         return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3483 }
3484
3485 int
3486 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
3487                                     struct rte_eth_l2_tunnel_conf *l2_tunnel)
3488 {
3489         struct rte_eth_dev *dev;
3490
3491         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3492         if (l2_tunnel == NULL) {
3493                 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3494                 return -EINVAL;
3495         }
3496
3497         if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3498                 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3499                 return -EINVAL;
3500         }
3501
3502         dev = &rte_eth_devices[port_id];
3503         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3504                                 -ENOTSUP);
3505         return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3506 }
3507
3508 int
3509 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
3510                                   struct rte_eth_l2_tunnel_conf *l2_tunnel,
3511                                   uint32_t mask,
3512                                   uint8_t en)
3513 {
3514         struct rte_eth_dev *dev;
3515
3516         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3517
3518         if (l2_tunnel == NULL) {
3519                 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3520                 return -EINVAL;
3521         }
3522
3523         if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3524                 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3525                 return -EINVAL;
3526         }
3527
3528         if (mask == 0) {
3529                 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3530                 return -EINVAL;
3531         }
3532
3533         dev = &rte_eth_devices[port_id];
3534         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3535                                 -ENOTSUP);
3536         return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3537 }
3538
3539 static void
3540 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3541                            const struct rte_eth_desc_lim *desc_lim)
3542 {
3543         if (desc_lim->nb_align != 0)
3544                 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3545
3546         if (desc_lim->nb_max != 0)
3547                 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3548
3549         *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3550 }
3551
3552 int
3553 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
3554                                  uint16_t *nb_rx_desc,
3555                                  uint16_t *nb_tx_desc)
3556 {
3557         struct rte_eth_dev *dev;
3558         struct rte_eth_dev_info dev_info;
3559
3560         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3561
3562         dev = &rte_eth_devices[port_id];
3563         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3564
3565         rte_eth_dev_info_get(port_id, &dev_info);
3566
3567         if (nb_rx_desc != NULL)
3568                 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3569
3570         if (nb_tx_desc != NULL)
3571                 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
3572
3573         return 0;
3574 }
3575
3576 int
3577 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
3578 {
3579         struct rte_eth_dev *dev;
3580
3581         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3582
3583         if (pool == NULL)
3584                 return -EINVAL;
3585
3586         dev = &rte_eth_devices[port_id];
3587
3588         if (*dev->dev_ops->pool_ops_supported == NULL)
3589                 return 1; /* all pools are supported */
3590
3591         return (*dev->dev_ops->pool_ops_supported)(dev, pool);
3592 }