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