ethdev: fix build of Tx rate limitation debug
[dpdk.git] / lib / librte_ether / rte_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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_tailq.h>
56 #include <rte_eal.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_common.h>
62 #include <rte_ring.h>
63 #include <rte_mempool.h>
64 #include <rte_malloc.h>
65 #include <rte_mbuf.h>
66 #include <rte_errno.h>
67 #include <rte_spinlock.h>
68 #include <rte_string_fns.h>
69
70 #include "rte_ether.h"
71 #include "rte_ethdev.h"
72
73 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
74 #define PMD_DEBUG_TRACE(fmt, args...) do {                        \
75                 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
76         } while (0)
77 #else
78 #define PMD_DEBUG_TRACE(fmt, args...)
79 #endif
80
81 /* Macros for checking for restricting functions to primary instance only */
82 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
83         if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
84                 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
85                 return (retval); \
86         } \
87 } while(0)
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 invlaid 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 #define FUNC_PTR_OR_RET(func) do { \
103         if ((func) == NULL) { \
104                 PMD_DEBUG_TRACE("Function not supported\n"); \
105                 return; \
106         } \
107 } while(0)
108
109 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
110 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
111 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
112 static uint8_t nb_ports = 0;
113
114 /* spinlock for eth device callbacks */
115 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
116
117 /**
118  * The user application callback description.
119  *
120  * It contains callback address to be registered by user application,
121  * the pointer to the parameters for callback, and the event type.
122  */
123 struct rte_eth_dev_callback {
124         TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
125         rte_eth_dev_cb_fn cb_fn;                /**< Callback address */
126         void *cb_arg;                           /**< Parameter for callback */
127         enum rte_eth_event_type event;          /**< Interrupt event type */
128         uint32_t active;                        /**< Callback is executing */
129 };
130
131 enum {
132         STAT_QMAP_TX = 0,
133         STAT_QMAP_RX
134 };
135
136 static inline void
137 rte_eth_dev_data_alloc(void)
138 {
139         const unsigned flags = 0;
140         const struct rte_memzone *mz;
141
142         if (rte_eal_process_type() == RTE_PROC_PRIMARY){
143                 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
144                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
145                                 rte_socket_id(), flags);
146         } else
147                 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
148         if (mz == NULL)
149                 rte_panic("Cannot allocate memzone for ethernet port data\n");
150
151         rte_eth_dev_data = mz->addr;
152         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
153                 memset(rte_eth_dev_data, 0,
154                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
155 }
156
157 static struct rte_eth_dev *
158 rte_eth_dev_allocated(const char *name)
159 {
160         unsigned i;
161
162         for (i = 0; i < nb_ports; i++) {
163                 if (strcmp(rte_eth_devices[i].data->name, name) == 0)
164                         return &rte_eth_devices[i];
165         }
166         return NULL;
167 }
168
169 struct rte_eth_dev *
170 rte_eth_dev_allocate(const char *name)
171 {
172         struct rte_eth_dev *eth_dev;
173
174         if (nb_ports == RTE_MAX_ETHPORTS) {
175                 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
176                 return NULL;
177         }
178
179         if (rte_eth_dev_data == NULL)
180                 rte_eth_dev_data_alloc();
181
182         if (rte_eth_dev_allocated(name) != NULL) {
183                 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n");
184                 return NULL;
185         }
186
187         eth_dev = &rte_eth_devices[nb_ports];
188         eth_dev->data = &rte_eth_dev_data[nb_ports];
189         snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
190         eth_dev->data->port_id = nb_ports++;
191         return eth_dev;
192 }
193
194 static int
195 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
196                  struct rte_pci_device *pci_dev)
197 {
198         struct eth_driver    *eth_drv;
199         struct rte_eth_dev *eth_dev;
200         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
201
202         int diag;
203
204         eth_drv = (struct eth_driver *)pci_drv;
205
206         /* Create unique Ethernet device name using PCI address */
207         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d",
208                         pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function);
209
210         eth_dev = rte_eth_dev_allocate(ethdev_name);
211         if (eth_dev == NULL)
212                 return -ENOMEM;
213
214         if (rte_eal_process_type() == RTE_PROC_PRIMARY){
215                 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
216                                   eth_drv->dev_private_size,
217                                   CACHE_LINE_SIZE);
218                 if (eth_dev->data->dev_private == NULL)
219                         rte_panic("Cannot allocate memzone for private port data\n");
220         }
221         eth_dev->pci_dev = pci_dev;
222         eth_dev->driver = eth_drv;
223         eth_dev->data->rx_mbuf_alloc_failed = 0;
224
225         /* init user callbacks */
226         TAILQ_INIT(&(eth_dev->callbacks));
227
228         /*
229          * Set the default MTU.
230          */
231         eth_dev->data->mtu = ETHER_MTU;
232
233         /* Invoke PMD device initialization function */
234         diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
235         if (diag == 0)
236                 return (0);
237
238         PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
239                         " failed\n", pci_drv->name,
240                         (unsigned) pci_dev->id.vendor_id,
241                         (unsigned) pci_dev->id.device_id);
242         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
243                 rte_free(eth_dev->data->dev_private);
244         nb_ports--;
245         return diag;
246 }
247
248 /**
249  * Register an Ethernet [Poll Mode] driver.
250  *
251  * Function invoked by the initialization function of an Ethernet driver
252  * to simultaneously register itself as a PCI driver and as an Ethernet
253  * Poll Mode Driver.
254  * Invokes the rte_eal_pci_register() function to register the *pci_drv*
255  * structure embedded in the *eth_drv* structure, after having stored the
256  * address of the rte_eth_dev_init() function in the *devinit* field of
257  * the *pci_drv* structure.
258  * During the PCI probing phase, the rte_eth_dev_init() function is
259  * invoked for each PCI [Ethernet device] matching the embedded PCI
260  * identifiers provided by the driver.
261  */
262 void
263 rte_eth_driver_register(struct eth_driver *eth_drv)
264 {
265         eth_drv->pci_drv.devinit = rte_eth_dev_init;
266         rte_eal_pci_register(&eth_drv->pci_drv);
267 }
268
269 int
270 rte_eth_dev_socket_id(uint8_t port_id)
271 {
272         if (port_id >= nb_ports)
273                 return -1;
274         return rte_eth_devices[port_id].pci_dev->numa_node;
275 }
276
277 uint8_t
278 rte_eth_dev_count(void)
279 {
280         return (nb_ports);
281 }
282
283 static int
284 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
285 {
286         uint16_t old_nb_queues = dev->data->nb_rx_queues;
287         void **rxq;
288         unsigned i;
289
290         if (dev->data->rx_queues == NULL) { /* first time configuration */
291                 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
292                                 sizeof(dev->data->rx_queues[0]) * nb_queues,
293                                 CACHE_LINE_SIZE);
294                 if (dev->data->rx_queues == NULL) {
295                         dev->data->nb_rx_queues = 0;
296                         return -(ENOMEM);
297                 }
298         } else { /* re-configure */
299                 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
300
301                 rxq = dev->data->rx_queues;
302
303                 for (i = nb_queues; i < old_nb_queues; i++)
304                         (*dev->dev_ops->rx_queue_release)(rxq[i]);
305                 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
306                                 CACHE_LINE_SIZE);
307                 if (rxq == NULL)
308                         return -(ENOMEM);
309
310                 if (nb_queues > old_nb_queues)
311                         memset(rxq + old_nb_queues, 0,
312                                 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
313
314                 dev->data->rx_queues = rxq;
315
316         }
317         dev->data->nb_rx_queues = nb_queues;
318         return (0);
319 }
320
321 int
322 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
323 {
324         struct rte_eth_dev *dev;
325
326         /* This function is only safe when called from the primary process
327          * in a multi-process setup*/
328         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
329
330         if (port_id >= nb_ports) {
331                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
332                 return -EINVAL;
333         }
334
335         dev = &rte_eth_devices[port_id];
336         if (rx_queue_id >= dev->data->nb_rx_queues) {
337                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
338                 return -EINVAL;
339         }
340
341         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
342
343         return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
344
345 }
346
347 int
348 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
349 {
350         struct rte_eth_dev *dev;
351
352         /* This function is only safe when called from the primary process
353          * in a multi-process setup*/
354         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
355
356         if (port_id >= nb_ports) {
357                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
358                 return -EINVAL;
359         }
360
361         dev = &rte_eth_devices[port_id];
362         if (rx_queue_id >= dev->data->nb_rx_queues) {
363                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
364                 return -EINVAL;
365         }
366
367         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
368
369         return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
370
371 }
372
373 int
374 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
375 {
376         struct rte_eth_dev *dev;
377
378         /* This function is only safe when called from the primary process
379          * in a multi-process setup*/
380         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
381
382         if (port_id >= nb_ports) {
383                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
384                 return -EINVAL;
385         }
386
387         dev = &rte_eth_devices[port_id];
388         if (tx_queue_id >= dev->data->nb_tx_queues) {
389                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
390                 return -EINVAL;
391         }
392
393         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
394
395         return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
396
397 }
398
399 int
400 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
401 {
402         struct rte_eth_dev *dev;
403
404         /* This function is only safe when called from the primary process
405          * in a multi-process setup*/
406         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
407
408         if (port_id >= nb_ports) {
409                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
410                 return -EINVAL;
411         }
412
413         dev = &rte_eth_devices[port_id];
414         if (tx_queue_id >= dev->data->nb_tx_queues) {
415                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
416                 return -EINVAL;
417         }
418
419         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
420
421         return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
422
423 }
424
425 static int
426 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
427 {
428         uint16_t old_nb_queues = dev->data->nb_tx_queues;
429         void **txq;
430         unsigned i;
431
432         if (dev->data->tx_queues == NULL) { /* first time configuration */
433                 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
434                                 sizeof(dev->data->tx_queues[0]) * nb_queues,
435                                 CACHE_LINE_SIZE);
436                 if (dev->data->tx_queues == NULL) {
437                         dev->data->nb_tx_queues = 0;
438                         return -(ENOMEM);
439                 }
440         } else { /* re-configure */
441                 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
442
443                 txq = dev->data->tx_queues;
444
445                 for (i = nb_queues; i < old_nb_queues; i++)
446                         (*dev->dev_ops->tx_queue_release)(txq[i]);
447                 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
448                                 CACHE_LINE_SIZE);
449                 if (txq == NULL)
450                         return -(ENOMEM);
451
452                 if (nb_queues > old_nb_queues)
453                         memset(txq + old_nb_queues, 0,
454                                 sizeof(txq[0]) * (nb_queues - old_nb_queues));
455
456                 dev->data->tx_queues = txq;
457
458         }
459         dev->data->nb_tx_queues = nb_queues;
460         return (0);
461 }
462
463 static int
464 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
465                       const struct rte_eth_conf *dev_conf)
466 {
467         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
468
469         if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
470                 /* check multi-queue mode */
471                 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ||
472                     (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
473                     (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
474                     (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
475                         /* SRIOV only works in VMDq enable mode */
476                         PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
477                                         " SRIOV active, "
478                                         "wrong VMDQ mq_mode rx %u tx %u\n",
479                                         port_id,
480                                         dev_conf->rxmode.mq_mode,
481                                         dev_conf->txmode.mq_mode);
482                         return (-EINVAL);
483                 }
484
485                 switch (dev_conf->rxmode.mq_mode) {
486                 case ETH_MQ_RX_VMDQ_RSS:
487                 case ETH_MQ_RX_VMDQ_DCB:
488                 case ETH_MQ_RX_VMDQ_DCB_RSS:
489                         /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
490                         PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
491                                         " SRIOV active, "
492                                         "unsupported VMDQ mq_mode rx %u\n",
493                                         port_id, dev_conf->rxmode.mq_mode);
494                         return (-EINVAL);
495                 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
496                         /* if nothing mq mode configure, use default scheme */
497                         dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
498                         if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
499                                 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
500                         break;
501                 }
502
503                 switch (dev_conf->txmode.mq_mode) {
504                 case ETH_MQ_TX_VMDQ_DCB:
505                         /* DCB VMDQ in SRIOV mode, not implement yet */
506                         PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
507                                         " SRIOV active, "
508                                         "unsupported VMDQ mq_mode tx %u\n",
509                                         port_id, dev_conf->txmode.mq_mode);
510                         return (-EINVAL);
511                 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
512                         /* if nothing mq mode configure, use default scheme */
513                         dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
514                         if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
515                                 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
516                         break;
517                 }
518
519                 /* check valid queue number */
520                 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
521                     (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
522                         PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
523                                     "queue number must less equal to %d\n",
524                                         port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
525                         return (-EINVAL);
526                 }
527         } else {
528                 /* For vmdb+dcb mode check our configuration before we go further */
529                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
530                         const struct rte_eth_vmdq_dcb_conf *conf;
531
532                         if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
533                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
534                                                 "!= %d\n",
535                                                 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
536                                 return (-EINVAL);
537                         }
538                         conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
539                         if (! (conf->nb_queue_pools == ETH_16_POOLS ||
540                                conf->nb_queue_pools == ETH_32_POOLS)) {
541                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
542                                                 "nb_queue_pools must be %d or %d\n",
543                                                 port_id, ETH_16_POOLS, ETH_32_POOLS);
544                                 return (-EINVAL);
545                         }
546                 }
547                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
548                         const struct rte_eth_vmdq_dcb_tx_conf *conf;
549
550                         if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
551                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
552                                                 "!= %d\n",
553                                                 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
554                                 return (-EINVAL);
555                         }
556                         conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
557                         if (! (conf->nb_queue_pools == ETH_16_POOLS ||
558                                conf->nb_queue_pools == ETH_32_POOLS)) {
559                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
560                                                 "nb_queue_pools != %d or nb_queue_pools "
561                                                 "!= %d\n",
562                                                 port_id, ETH_16_POOLS, ETH_32_POOLS);
563                                 return (-EINVAL);
564                         }
565                 }
566
567                 /* For DCB mode check our configuration before we go further */
568                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
569                         const struct rte_eth_dcb_rx_conf *conf;
570
571                         if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
572                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
573                                                 "!= %d\n",
574                                                 port_id, ETH_DCB_NUM_QUEUES);
575                                 return (-EINVAL);
576                         }
577                         conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
578                         if (! (conf->nb_tcs == ETH_4_TCS ||
579                                conf->nb_tcs == ETH_8_TCS)) {
580                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
581                                                 "nb_tcs != %d or nb_tcs "
582                                                 "!= %d\n",
583                                                 port_id, ETH_4_TCS, ETH_8_TCS);
584                                 return (-EINVAL);
585                         }
586                 }
587
588                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
589                         const struct rte_eth_dcb_tx_conf *conf;
590
591                         if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
592                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
593                                                 "!= %d\n",
594                                                 port_id, ETH_DCB_NUM_QUEUES);
595                                 return (-EINVAL);
596                         }
597                         conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
598                         if (! (conf->nb_tcs == ETH_4_TCS ||
599                                conf->nb_tcs == ETH_8_TCS)) {
600                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
601                                                 "nb_tcs != %d or nb_tcs "
602                                                 "!= %d\n",
603                                                 port_id, ETH_4_TCS, ETH_8_TCS);
604                                 return (-EINVAL);
605                         }
606                 }
607         }
608         return 0;
609 }
610
611 int
612 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
613                       const struct rte_eth_conf *dev_conf)
614 {
615         struct rte_eth_dev *dev;
616         struct rte_eth_dev_info dev_info;
617         int diag;
618
619         /* This function is only safe when called from the primary process
620          * in a multi-process setup*/
621         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
622
623         if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
624                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
625                 return (-EINVAL);
626         }
627         dev = &rte_eth_devices[port_id];
628
629         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
630         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
631
632         if (dev->data->dev_started) {
633                 PMD_DEBUG_TRACE(
634                     "port %d must be stopped to allow configuration\n", port_id);
635                 return (-EBUSY);
636         }
637
638         /*
639          * Check that the numbers of RX and TX queues are not greater
640          * than the maximum number of RX and TX queues supported by the
641          * configured device.
642          */
643         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
644         if (nb_rx_q > dev_info.max_rx_queues) {
645                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
646                                 port_id, nb_rx_q, dev_info.max_rx_queues);
647                 return (-EINVAL);
648         }
649         if (nb_rx_q == 0) {
650                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
651                 return (-EINVAL);
652         }
653
654         if (nb_tx_q > dev_info.max_tx_queues) {
655                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
656                                 port_id, nb_tx_q, dev_info.max_tx_queues);
657                 return (-EINVAL);
658         }
659         if (nb_tx_q == 0) {
660                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
661                 return (-EINVAL);
662         }
663
664         /* Copy the dev_conf parameter into the dev structure */
665         memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
666
667         /*
668          * If link state interrupt is enabled, check that the
669          * device supports it.
670          */
671         if (dev_conf->intr_conf.lsc == 1) {
672                 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
673
674                 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
675                         PMD_DEBUG_TRACE("driver %s does not support lsc\n",
676                                         pci_drv->name);
677                         return (-EINVAL);
678                 }
679         }
680
681         /*
682          * If jumbo frames are enabled, check that the maximum RX packet
683          * length is supported by the configured device.
684          */
685         if (dev_conf->rxmode.jumbo_frame == 1) {
686                 if (dev_conf->rxmode.max_rx_pkt_len >
687                     dev_info.max_rx_pktlen) {
688                         PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
689                                 " > max valid value %u\n",
690                                 port_id,
691                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
692                                 (unsigned)dev_info.max_rx_pktlen);
693                         return (-EINVAL);
694                 }
695                 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
696                         PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
697                                 " < min valid value %u\n",
698                                 port_id,
699                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
700                                 (unsigned)ETHER_MIN_LEN);
701                         return (-EINVAL);
702                 }
703         } else {
704                 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
705                         dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
706                         /* Use default value */
707                         dev->data->dev_conf.rxmode.max_rx_pkt_len =
708                                                         ETHER_MAX_LEN;
709         }
710
711         /* multipe queue mode checking */
712         diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
713         if (diag != 0) {
714                 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
715                                 port_id, diag);
716                 return diag;
717         }
718
719         /*
720          * Setup new number of RX/TX queues and reconfigure device.
721          */
722         diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
723         if (diag != 0) {
724                 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
725                                 port_id, diag);
726                 return diag;
727         }
728
729         diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
730         if (diag != 0) {
731                 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
732                                 port_id, diag);
733                 rte_eth_dev_rx_queue_config(dev, 0);
734                 return diag;
735         }
736
737         diag = (*dev->dev_ops->dev_configure)(dev);
738         if (diag != 0) {
739                 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
740                                 port_id, diag);
741                 rte_eth_dev_rx_queue_config(dev, 0);
742                 rte_eth_dev_tx_queue_config(dev, 0);
743                 return diag;
744         }
745
746         return 0;
747 }
748
749 static void
750 rte_eth_dev_config_restore(uint8_t port_id)
751 {
752         struct rte_eth_dev *dev;
753         struct rte_eth_dev_info dev_info;
754         struct ether_addr addr;
755         uint16_t i;
756         uint32_t pool = 0;
757
758         dev = &rte_eth_devices[port_id];
759
760         rte_eth_dev_info_get(port_id, &dev_info);
761
762         if (RTE_ETH_DEV_SRIOV(dev).active)
763                 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
764
765         /* replay MAC address configuration */
766         for (i = 0; i < dev_info.max_mac_addrs; i++) {
767                 addr = dev->data->mac_addrs[i];
768
769                 /* skip zero address */
770                 if (is_zero_ether_addr(&addr))
771                         continue;
772
773                 /* add address to the hardware */
774                 if  (*dev->dev_ops->mac_addr_add)
775                         (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
776                 else {
777                         PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
778                                         port_id);
779                         /* exit the loop but not return an error */
780                         break;
781                 }
782         }
783
784         /* replay promiscuous configuration */
785         if (rte_eth_promiscuous_get(port_id) == 1)
786                 rte_eth_promiscuous_enable(port_id);
787         else if (rte_eth_promiscuous_get(port_id) == 0)
788                 rte_eth_promiscuous_disable(port_id);
789
790         /* replay allmulticast configuration */
791         if (rte_eth_allmulticast_get(port_id) == 1)
792                 rte_eth_allmulticast_enable(port_id);
793         else if (rte_eth_allmulticast_get(port_id) == 0)
794                 rte_eth_allmulticast_disable(port_id);
795 }
796
797 int
798 rte_eth_dev_start(uint8_t port_id)
799 {
800         struct rte_eth_dev *dev;
801         int diag;
802
803         /* This function is only safe when called from the primary process
804          * in a multi-process setup*/
805         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
806
807         if (port_id >= nb_ports) {
808                 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
809                 return (-EINVAL);
810         }
811         dev = &rte_eth_devices[port_id];
812
813         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
814
815         if (dev->data->dev_started != 0) {
816                 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
817                         " already started\n",
818                         port_id);
819                 return (0);
820         }
821
822         diag = (*dev->dev_ops->dev_start)(dev);
823         if (diag == 0)
824                 dev->data->dev_started = 1;
825         else
826                 return diag;
827
828         rte_eth_dev_config_restore(port_id);
829
830         return 0;
831 }
832
833 void
834 rte_eth_dev_stop(uint8_t port_id)
835 {
836         struct rte_eth_dev *dev;
837
838         /* This function is only safe when called from the primary process
839          * in a multi-process setup*/
840         PROC_PRIMARY_OR_RET();
841
842         if (port_id >= nb_ports) {
843                 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
844                 return;
845         }
846         dev = &rte_eth_devices[port_id];
847
848         FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
849
850         if (dev->data->dev_started == 0) {
851                 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
852                         " already stopped\n",
853                         port_id);
854                 return;
855         }
856
857         dev->data->dev_started = 0;
858         (*dev->dev_ops->dev_stop)(dev);
859 }
860
861 int
862 rte_eth_dev_set_link_up(uint8_t port_id)
863 {
864         struct rte_eth_dev *dev;
865
866         /* This function is only safe when called from the primary process
867          * in a multi-process setup*/
868         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
869
870         if (port_id >= nb_ports) {
871                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
872                 return -EINVAL;
873         }
874         dev = &rte_eth_devices[port_id];
875
876         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
877         return (*dev->dev_ops->dev_set_link_up)(dev);
878 }
879
880 int
881 rte_eth_dev_set_link_down(uint8_t port_id)
882 {
883         struct rte_eth_dev *dev;
884
885         /* This function is only safe when called from the primary process
886          * in a multi-process setup*/
887         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
888
889         if (port_id >= nb_ports) {
890                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
891                 return -EINVAL;
892         }
893         dev = &rte_eth_devices[port_id];
894
895         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
896         return (*dev->dev_ops->dev_set_link_down)(dev);
897 }
898
899 void
900 rte_eth_dev_close(uint8_t port_id)
901 {
902         struct rte_eth_dev *dev;
903
904         /* This function is only safe when called from the primary process
905          * in a multi-process setup*/
906         PROC_PRIMARY_OR_RET();
907
908         if (port_id >= nb_ports) {
909                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
910                 return;
911         }
912
913         dev = &rte_eth_devices[port_id];
914
915         FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
916         dev->data->dev_started = 0;
917         (*dev->dev_ops->dev_close)(dev);
918 }
919
920 int
921 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
922                        uint16_t nb_rx_desc, unsigned int socket_id,
923                        const struct rte_eth_rxconf *rx_conf,
924                        struct rte_mempool *mp)
925 {
926         int ret;
927         uint32_t mbp_buf_size;
928         struct rte_eth_dev *dev;
929         struct rte_pktmbuf_pool_private *mbp_priv;
930         struct rte_eth_dev_info dev_info;
931
932         /* This function is only safe when called from the primary process
933          * in a multi-process setup*/
934         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
935
936         if (port_id >= nb_ports) {
937                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
938                 return (-EINVAL);
939         }
940         dev = &rte_eth_devices[port_id];
941         if (rx_queue_id >= dev->data->nb_rx_queues) {
942                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
943                 return (-EINVAL);
944         }
945
946         if (dev->data->dev_started) {
947                 PMD_DEBUG_TRACE(
948                     "port %d must be stopped to allow configuration\n", port_id);
949                 return -EBUSY;
950         }
951
952         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
953         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
954
955         /*
956          * Check the size of the mbuf data buffer.
957          * This value must be provided in the private data of the memory pool.
958          * First check that the memory pool has a valid private data.
959          */
960         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
961         if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
962                 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
963                                 mp->name, (int) mp->private_data_size,
964                                 (int) sizeof(struct rte_pktmbuf_pool_private));
965                 return (-ENOSPC);
966         }
967         mbp_priv = rte_mempool_get_priv(mp);
968         mbp_buf_size = mbp_priv->mbuf_data_room_size;
969
970         if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
971                 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
972                                 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
973                                 "=%d)\n",
974                                 mp->name,
975                                 (int)mbp_buf_size,
976                                 (int)(RTE_PKTMBUF_HEADROOM +
977                                       dev_info.min_rx_bufsize),
978                                 (int)RTE_PKTMBUF_HEADROOM,
979                                 (int)dev_info.min_rx_bufsize);
980                 return (-EINVAL);
981         }
982
983         ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
984                                               socket_id, rx_conf, mp);
985         if (!ret) {
986                 if (!dev->data->min_rx_buf_size ||
987                     dev->data->min_rx_buf_size > mbp_buf_size)
988                         dev->data->min_rx_buf_size = mbp_buf_size;
989         }
990
991         return ret;
992 }
993
994 int
995 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
996                        uint16_t nb_tx_desc, unsigned int socket_id,
997                        const struct rte_eth_txconf *tx_conf)
998 {
999         struct rte_eth_dev *dev;
1000
1001         /* This function is only safe when called from the primary process
1002          * in a multi-process setup*/
1003         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1004
1005         if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1006                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1007                 return (-EINVAL);
1008         }
1009         dev = &rte_eth_devices[port_id];
1010         if (tx_queue_id >= dev->data->nb_tx_queues) {
1011                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1012                 return (-EINVAL);
1013         }
1014
1015         if (dev->data->dev_started) {
1016                 PMD_DEBUG_TRACE(
1017                     "port %d must be stopped to allow configuration\n", port_id);
1018                 return -EBUSY;
1019         }
1020
1021         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1022         return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1023                                                socket_id, tx_conf);
1024 }
1025
1026 void
1027 rte_eth_promiscuous_enable(uint8_t port_id)
1028 {
1029         struct rte_eth_dev *dev;
1030
1031         if (port_id >= nb_ports) {
1032                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1033                 return;
1034         }
1035         dev = &rte_eth_devices[port_id];
1036
1037         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1038         (*dev->dev_ops->promiscuous_enable)(dev);
1039         dev->data->promiscuous = 1;
1040 }
1041
1042 void
1043 rte_eth_promiscuous_disable(uint8_t port_id)
1044 {
1045         struct rte_eth_dev *dev;
1046
1047         if (port_id >= nb_ports) {
1048                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1049                 return;
1050         }
1051         dev = &rte_eth_devices[port_id];
1052
1053         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1054         dev->data->promiscuous = 0;
1055         (*dev->dev_ops->promiscuous_disable)(dev);
1056 }
1057
1058 int
1059 rte_eth_promiscuous_get(uint8_t port_id)
1060 {
1061         struct rte_eth_dev *dev;
1062
1063         if (port_id >= nb_ports) {
1064                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1065                 return -1;
1066         }
1067
1068         dev = &rte_eth_devices[port_id];
1069         return dev->data->promiscuous;
1070 }
1071
1072 void
1073 rte_eth_allmulticast_enable(uint8_t port_id)
1074 {
1075         struct rte_eth_dev *dev;
1076
1077         if (port_id >= nb_ports) {
1078                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1079                 return;
1080         }
1081         dev = &rte_eth_devices[port_id];
1082
1083         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1084         (*dev->dev_ops->allmulticast_enable)(dev);
1085         dev->data->all_multicast = 1;
1086 }
1087
1088 void
1089 rte_eth_allmulticast_disable(uint8_t port_id)
1090 {
1091         struct rte_eth_dev *dev;
1092
1093         if (port_id >= nb_ports) {
1094                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1095                 return;
1096         }
1097         dev = &rte_eth_devices[port_id];
1098
1099         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1100         dev->data->all_multicast = 0;
1101         (*dev->dev_ops->allmulticast_disable)(dev);
1102 }
1103
1104 int
1105 rte_eth_allmulticast_get(uint8_t port_id)
1106 {
1107         struct rte_eth_dev *dev;
1108
1109         if (port_id >= nb_ports) {
1110                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1111                 return -1;
1112         }
1113
1114         dev = &rte_eth_devices[port_id];
1115         return dev->data->all_multicast;
1116 }
1117
1118 static inline int
1119 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1120                                 struct rte_eth_link *link)
1121 {
1122         struct rte_eth_link *dst = link;
1123         struct rte_eth_link *src = &(dev->data->dev_link);
1124
1125         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1126                                         *(uint64_t *)src) == 0)
1127                 return -1;
1128
1129         return 0;
1130 }
1131
1132 void
1133 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1134 {
1135         struct rte_eth_dev *dev;
1136
1137         if (port_id >= nb_ports) {
1138                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1139                 return;
1140         }
1141         dev = &rte_eth_devices[port_id];
1142
1143         if (dev->data->dev_conf.intr_conf.lsc != 0)
1144                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1145         else {
1146                 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1147                 (*dev->dev_ops->link_update)(dev, 1);
1148                 *eth_link = dev->data->dev_link;
1149         }
1150 }
1151
1152 void
1153 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1154 {
1155         struct rte_eth_dev *dev;
1156
1157         if (port_id >= nb_ports) {
1158                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1159                 return;
1160         }
1161         dev = &rte_eth_devices[port_id];
1162
1163         if (dev->data->dev_conf.intr_conf.lsc != 0)
1164                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1165         else {
1166                 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1167                 (*dev->dev_ops->link_update)(dev, 0);
1168                 *eth_link = dev->data->dev_link;
1169         }
1170 }
1171
1172 void
1173 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1174 {
1175         struct rte_eth_dev *dev;
1176
1177         if (port_id >= nb_ports) {
1178                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1179                 return;
1180         }
1181         dev = &rte_eth_devices[port_id];
1182         memset(stats, 0, sizeof(*stats));
1183
1184         FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1185         (*dev->dev_ops->stats_get)(dev, stats);
1186         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1187 }
1188
1189 void
1190 rte_eth_stats_reset(uint8_t port_id)
1191 {
1192         struct rte_eth_dev *dev;
1193
1194         if (port_id >= nb_ports) {
1195                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1196                 return;
1197         }
1198         dev = &rte_eth_devices[port_id];
1199
1200         FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1201         (*dev->dev_ops->stats_reset)(dev);
1202 }
1203
1204
1205 static int
1206 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1207                 uint8_t is_rx)
1208 {
1209         struct rte_eth_dev *dev;
1210
1211         if (port_id >= nb_ports) {
1212                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1213                 return -ENODEV;
1214         }
1215         dev = &rte_eth_devices[port_id];
1216
1217         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1218         return (*dev->dev_ops->queue_stats_mapping_set)
1219                         (dev, queue_id, stat_idx, is_rx);
1220 }
1221
1222
1223 int
1224 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1225                 uint8_t stat_idx)
1226 {
1227         return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1228                         STAT_QMAP_TX);
1229 }
1230
1231
1232 int
1233 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1234                 uint8_t stat_idx)
1235 {
1236         return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1237                         STAT_QMAP_RX);
1238 }
1239
1240
1241 void
1242 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1243 {
1244         struct rte_eth_dev *dev;
1245
1246         if (port_id >= nb_ports) {
1247                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1248                 return;
1249         }
1250         dev = &rte_eth_devices[port_id];
1251
1252         /* Default device offload capabilities to zero */
1253         dev_info->rx_offload_capa = 0;
1254         dev_info->tx_offload_capa = 0;
1255         dev_info->if_index = 0;
1256         FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1257         (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1258         dev_info->pci_dev = dev->pci_dev;
1259         if (dev->driver)
1260                 dev_info->driver_name = dev->driver->pci_drv.name;
1261 }
1262
1263 void
1264 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1265 {
1266         struct rte_eth_dev *dev;
1267
1268         if (port_id >= nb_ports) {
1269                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1270                 return;
1271         }
1272         dev = &rte_eth_devices[port_id];
1273         ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1274 }
1275
1276
1277 int
1278 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1279 {
1280         struct rte_eth_dev *dev;
1281
1282         if (port_id >= nb_ports) {
1283                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1284                 return (-ENODEV);
1285         }
1286
1287         dev = &rte_eth_devices[port_id];
1288         *mtu = dev->data->mtu;
1289         return 0;
1290 }
1291
1292 int
1293 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1294 {
1295         int ret;
1296         struct rte_eth_dev *dev;
1297
1298         if (port_id >= nb_ports) {
1299                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1300                 return (-ENODEV);
1301         }
1302
1303         dev = &rte_eth_devices[port_id];
1304         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1305
1306         ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1307         if (!ret)
1308                 dev->data->mtu = mtu;
1309
1310         return ret;
1311 }
1312
1313 int
1314 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1315 {
1316         struct rte_eth_dev *dev;
1317
1318         if (port_id >= nb_ports) {
1319                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1320                 return (-ENODEV);
1321         }
1322         dev = &rte_eth_devices[port_id];
1323         if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1324                 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1325                 return (-ENOSYS);
1326         }
1327
1328         if (vlan_id > 4095) {
1329                 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1330                                 port_id, (unsigned) vlan_id);
1331                 return (-EINVAL);
1332         }
1333         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1334         (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1335         return (0);
1336 }
1337
1338 int
1339 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1340 {
1341         struct rte_eth_dev *dev;
1342
1343         if (port_id >= nb_ports) {
1344                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1345                 return (-ENODEV);
1346         }
1347
1348         dev = &rte_eth_devices[port_id];
1349         if (rx_queue_id >= dev->data->nb_rx_queues) {
1350                 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1351                 return (-EINVAL);
1352         }
1353
1354         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1355         (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1356
1357         return (0);
1358 }
1359
1360 int
1361 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1362 {
1363         struct rte_eth_dev *dev;
1364
1365         if (port_id >= nb_ports) {
1366                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1367                 return (-ENODEV);
1368         }
1369
1370         dev = &rte_eth_devices[port_id];
1371         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1372         (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1373
1374         return (0);
1375 }
1376
1377 int
1378 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1379 {
1380         struct rte_eth_dev *dev;
1381         int ret = 0;
1382         int mask = 0;
1383         int cur, org = 0;
1384
1385         if (port_id >= nb_ports) {
1386                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1387                 return (-ENODEV);
1388         }
1389
1390         dev = &rte_eth_devices[port_id];
1391
1392         /*check which option changed by application*/
1393         cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1394         org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1395         if (cur != org){
1396                 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1397                 mask |= ETH_VLAN_STRIP_MASK;
1398         }
1399
1400         cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1401         org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1402         if (cur != org){
1403                 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1404                 mask |= ETH_VLAN_FILTER_MASK;
1405         }
1406
1407         cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1408         org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1409         if (cur != org){
1410                 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1411                 mask |= ETH_VLAN_EXTEND_MASK;
1412         }
1413
1414         /*no change*/
1415         if(mask == 0)
1416                 return ret;
1417
1418         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1419         (*dev->dev_ops->vlan_offload_set)(dev, mask);
1420
1421         return ret;
1422 }
1423
1424 int
1425 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1426 {
1427         struct rte_eth_dev *dev;
1428         int ret = 0;
1429
1430         if (port_id >= nb_ports) {
1431                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1432                 return (-ENODEV);
1433         }
1434
1435         dev = &rte_eth_devices[port_id];
1436
1437         if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1438                 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1439
1440         if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1441                 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1442
1443         if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1444                 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1445
1446         return ret;
1447 }
1448
1449 int
1450 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1451 {
1452         struct rte_eth_dev *dev;
1453
1454         if (port_id >= nb_ports) {
1455                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1456                 return (-ENODEV);
1457         }
1458         dev = &rte_eth_devices[port_id];
1459         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1460         (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1461
1462         return 0;
1463 }
1464
1465 int
1466 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1467                                       struct rte_fdir_filter *fdir_filter,
1468                                       uint8_t queue)
1469 {
1470         struct rte_eth_dev *dev;
1471
1472         if (port_id >= nb_ports) {
1473                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1474                 return (-ENODEV);
1475         }
1476
1477         dev = &rte_eth_devices[port_id];
1478
1479         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1480                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1481                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1482                 return (-ENOSYS);
1483         }
1484
1485         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1486              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1487             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1488                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1489                                 "None l4type, source & destinations ports " \
1490                                 "should be null!\n");
1491                 return (-EINVAL);
1492         }
1493
1494         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1495         return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1496                                                                 queue);
1497 }
1498
1499 int
1500 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1501                                          struct rte_fdir_filter *fdir_filter,
1502                                          uint8_t queue)
1503 {
1504         struct rte_eth_dev *dev;
1505
1506         if (port_id >= nb_ports) {
1507                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1508                 return (-ENODEV);
1509         }
1510
1511         dev = &rte_eth_devices[port_id];
1512
1513         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1514                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1515                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1516                 return (-ENOSYS);
1517         }
1518
1519         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1520              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1521             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1522                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1523                                 "None l4type, source & destinations ports " \
1524                                 "should be null!\n");
1525                 return (-EINVAL);
1526         }
1527
1528         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1529         return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1530                                                                 queue);
1531
1532 }
1533
1534 int
1535 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1536                                          struct rte_fdir_filter *fdir_filter)
1537 {
1538         struct rte_eth_dev *dev;
1539
1540         if (port_id >= nb_ports) {
1541                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1542                 return (-ENODEV);
1543         }
1544
1545         dev = &rte_eth_devices[port_id];
1546
1547         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1548                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1549                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1550                 return (-ENOSYS);
1551         }
1552
1553         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1554              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1555             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1556                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1557                                 "None l4type source & destinations ports " \
1558                                 "should be null!\n");
1559                 return (-EINVAL);
1560         }
1561
1562         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1563         return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1564 }
1565
1566 int
1567 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1568 {
1569         struct rte_eth_dev *dev;
1570
1571         if (port_id >= nb_ports) {
1572                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1573                 return (-ENODEV);
1574         }
1575
1576         dev = &rte_eth_devices[port_id];
1577         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1578                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1579                 return (-ENOSYS);
1580         }
1581
1582         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1583
1584         (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1585         return (0);
1586 }
1587
1588 int
1589 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1590                                     struct rte_fdir_filter *fdir_filter,
1591                                     uint16_t soft_id, uint8_t queue,
1592                                     uint8_t drop)
1593 {
1594         struct rte_eth_dev *dev;
1595
1596         if (port_id >= nb_ports) {
1597                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1598                 return (-ENODEV);
1599         }
1600
1601         dev = &rte_eth_devices[port_id];
1602
1603         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1604                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1605                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1606                 return (-ENOSYS);
1607         }
1608
1609         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1610              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1611             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1612                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1613                                 "None l4type, source & destinations ports " \
1614                                 "should be null!\n");
1615                 return (-EINVAL);
1616         }
1617
1618         /* For now IPv6 is not supported with perfect filter */
1619         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1620                 return (-ENOTSUP);
1621
1622         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1623         return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1624                                                                 soft_id, queue,
1625                                                                 drop);
1626 }
1627
1628 int
1629 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1630                                        struct rte_fdir_filter *fdir_filter,
1631                                        uint16_t soft_id, uint8_t queue,
1632                                        uint8_t drop)
1633 {
1634         struct rte_eth_dev *dev;
1635
1636         if (port_id >= nb_ports) {
1637                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1638                 return (-ENODEV);
1639         }
1640
1641         dev = &rte_eth_devices[port_id];
1642
1643         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1644                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1645                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1646                 return (-ENOSYS);
1647         }
1648
1649         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1650              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1651             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1652                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1653                                 "None l4type, source & destinations ports " \
1654                                 "should be null!\n");
1655                 return (-EINVAL);
1656         }
1657
1658         /* For now IPv6 is not supported with perfect filter */
1659         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1660                 return (-ENOTSUP);
1661
1662         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1663         return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1664                                                         soft_id, queue, drop);
1665 }
1666
1667 int
1668 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1669                                        struct rte_fdir_filter *fdir_filter,
1670                                        uint16_t soft_id)
1671 {
1672         struct rte_eth_dev *dev;
1673
1674         if (port_id >= nb_ports) {
1675                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1676                 return (-ENODEV);
1677         }
1678
1679         dev = &rte_eth_devices[port_id];
1680
1681         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1682                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1683                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1684                 return (-ENOSYS);
1685         }
1686
1687         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1688              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1689             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1690                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1691                                 "None l4type, source & destinations ports " \
1692                                 "should be null!\n");
1693                 return (-EINVAL);
1694         }
1695
1696         /* For now IPv6 is not supported with perfect filter */
1697         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1698                 return (-ENOTSUP);
1699
1700         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1701         return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1702                                                                 soft_id);
1703 }
1704
1705 int
1706 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1707 {
1708         struct rte_eth_dev *dev;
1709
1710         if (port_id >= nb_ports) {
1711                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1712                 return (-ENODEV);
1713         }
1714
1715         dev = &rte_eth_devices[port_id];
1716         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1717                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1718                 return (-ENOSYS);
1719         }
1720
1721         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1722         return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1723 }
1724
1725 int
1726 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1727 {
1728         struct rte_eth_dev *dev;
1729
1730         if (port_id >= nb_ports) {
1731                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1732                 return (-ENODEV);
1733         }
1734
1735         dev = &rte_eth_devices[port_id];
1736         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1737         memset(fc_conf, 0, sizeof(*fc_conf));
1738         return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1739 }
1740
1741 int
1742 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1743 {
1744         struct rte_eth_dev *dev;
1745
1746         if (port_id >= nb_ports) {
1747                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1748                 return (-ENODEV);
1749         }
1750
1751         if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1752                 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1753                 return (-EINVAL);
1754         }
1755
1756         dev = &rte_eth_devices[port_id];
1757         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1758         return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1759 }
1760
1761 int
1762 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1763 {
1764         struct rte_eth_dev *dev;
1765
1766         if (port_id >= nb_ports) {
1767                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1768                 return (-ENODEV);
1769         }
1770
1771         if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1772                 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1773                 return (-EINVAL);
1774         }
1775
1776         dev = &rte_eth_devices[port_id];
1777         /* High water, low water validation are device specific */
1778         if  (*dev->dev_ops->priority_flow_ctrl_set)
1779                 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1780         return (-ENOTSUP);
1781 }
1782
1783 int
1784 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1785 {
1786         struct rte_eth_dev *dev;
1787         uint16_t max_rxq;
1788         uint8_t i,j;
1789
1790         if (port_id >= nb_ports) {
1791                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1792                 return (-ENODEV);
1793         }
1794
1795         /* Invalid mask bit(s) setting */
1796         if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1797                 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1798                 return (-EINVAL);
1799         }
1800
1801         dev = &rte_eth_devices[port_id];
1802         max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1803                 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1804         if (reta_conf->mask_lo != 0) {
1805                 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1806                         if ((reta_conf->mask_lo & (1ULL << i)) &&
1807                                 (reta_conf->reta[i] >= max_rxq)) {
1808                                 PMD_DEBUG_TRACE("RETA hash index output"
1809                                         "configration for port=%d,invalid"
1810                                         "queue=%d\n",port_id,reta_conf->reta[i]);
1811
1812                                 return (-EINVAL);
1813                         }
1814                 }
1815         }
1816
1817         if (reta_conf->mask_hi != 0) {
1818                 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1819                         j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1820
1821                         /* Check if the max entry >= 128 */
1822                         if ((reta_conf->mask_hi & (1ULL << i)) &&
1823                                 (reta_conf->reta[j] >= max_rxq)) {
1824                                 PMD_DEBUG_TRACE("RETA hash index output"
1825                                         "configration for port=%d,invalid"
1826                                         "queue=%d\n",port_id,reta_conf->reta[j]);
1827
1828                                 return (-EINVAL);
1829                         }
1830                 }
1831         }
1832
1833         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1834         return (*dev->dev_ops->reta_update)(dev, reta_conf);
1835 }
1836
1837 int
1838 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1839 {
1840         struct rte_eth_dev *dev;
1841
1842         if (port_id >= nb_ports) {
1843                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1844                 return (-ENODEV);
1845         }
1846
1847         if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1848                 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1849                 return (-EINVAL);
1850         }
1851
1852         dev = &rte_eth_devices[port_id];
1853         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1854         return (*dev->dev_ops->reta_query)(dev, reta_conf);
1855 }
1856
1857 int
1858 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1859 {
1860         struct rte_eth_dev *dev;
1861         uint16_t rss_hash_protos;
1862
1863         if (port_id >= nb_ports) {
1864                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1865                 return (-ENODEV);
1866         }
1867         rss_hash_protos = rss_conf->rss_hf;
1868         if ((rss_hash_protos != 0) &&
1869             ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1870                 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1871                                 rss_hash_protos);
1872                 return (-EINVAL);
1873         }
1874         dev = &rte_eth_devices[port_id];
1875         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1876         return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1877 }
1878
1879 int
1880 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1881                               struct rte_eth_rss_conf *rss_conf)
1882 {
1883         struct rte_eth_dev *dev;
1884
1885         if (port_id >= nb_ports) {
1886                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1887                 return (-ENODEV);
1888         }
1889         dev = &rte_eth_devices[port_id];
1890         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1891         return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1892 }
1893
1894 int
1895 rte_eth_led_on(uint8_t port_id)
1896 {
1897         struct rte_eth_dev *dev;
1898
1899         if (port_id >= nb_ports) {
1900                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1901                 return (-ENODEV);
1902         }
1903
1904         dev = &rte_eth_devices[port_id];
1905         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1906         return ((*dev->dev_ops->dev_led_on)(dev));
1907 }
1908
1909 int
1910 rte_eth_led_off(uint8_t port_id)
1911 {
1912         struct rte_eth_dev *dev;
1913
1914         if (port_id >= nb_ports) {
1915                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1916                 return (-ENODEV);
1917         }
1918
1919         dev = &rte_eth_devices[port_id];
1920         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1921         return ((*dev->dev_ops->dev_led_off)(dev));
1922 }
1923
1924 /*
1925  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1926  * an empty spot.
1927  */
1928 static inline int
1929 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1930 {
1931         struct rte_eth_dev_info dev_info;
1932         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1933         unsigned i;
1934
1935         rte_eth_dev_info_get(port_id, &dev_info);
1936
1937         for (i = 0; i < dev_info.max_mac_addrs; i++)
1938                 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1939                         return i;
1940
1941         return -1;
1942 }
1943
1944 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1945
1946 int
1947 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1948                         uint32_t pool)
1949 {
1950         struct rte_eth_dev *dev;
1951         int index;
1952         uint64_t pool_mask;
1953
1954         if (port_id >= nb_ports) {
1955                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1956                 return (-ENODEV);
1957         }
1958         dev = &rte_eth_devices[port_id];
1959         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1960
1961         if (is_zero_ether_addr(addr)) {
1962                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1963                         port_id);
1964                 return (-EINVAL);
1965         }
1966         if (pool >= ETH_64_POOLS) {
1967                 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
1968                 return (-EINVAL);
1969         }
1970
1971         index = get_mac_addr_index(port_id, addr);
1972         if (index < 0) {
1973                 index = get_mac_addr_index(port_id, &null_mac_addr);
1974                 if (index < 0) {
1975                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1976                                 port_id);
1977                         return (-ENOSPC);
1978                 }
1979         } else {
1980                 pool_mask = dev->data->mac_pool_sel[index];
1981
1982                 /* Check if both MAC address and pool is alread there, and do nothing */
1983                 if (pool_mask & (1ULL << pool))
1984                         return 0;
1985         }
1986
1987         /* Update NIC */
1988         (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1989
1990         /* Update address in NIC data structure */
1991         ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1992
1993         /* Update pool bitmap in NIC data structure */
1994         dev->data->mac_pool_sel[index] |= (1ULL << pool);
1995
1996         return 0;
1997 }
1998
1999 int
2000 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2001 {
2002         struct rte_eth_dev *dev;
2003         int index;
2004
2005         if (port_id >= nb_ports) {
2006                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2007                 return (-ENODEV);
2008         }
2009         dev = &rte_eth_devices[port_id];
2010         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2011
2012         index = get_mac_addr_index(port_id, addr);
2013         if (index == 0) {
2014                 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2015                 return (-EADDRINUSE);
2016         } else if (index < 0)
2017                 return 0;  /* Do nothing if address wasn't found */
2018
2019         /* Update NIC */
2020         (*dev->dev_ops->mac_addr_remove)(dev, index);
2021
2022         /* Update address in NIC data structure */
2023         ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2024
2025         return 0;
2026 }
2027
2028 int
2029 rte_eth_dev_set_vf_rxmode(uint8_t port_id,  uint16_t vf,
2030                                 uint16_t rx_mode, uint8_t on)
2031 {
2032         uint16_t num_vfs;
2033         struct rte_eth_dev *dev;
2034         struct rte_eth_dev_info dev_info;
2035
2036         if (port_id >= nb_ports) {
2037                 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2038                                 port_id);
2039                 return (-ENODEV);
2040         }
2041
2042         dev = &rte_eth_devices[port_id];
2043         rte_eth_dev_info_get(port_id, &dev_info);
2044
2045         num_vfs = dev_info.max_vfs;
2046         if (vf > num_vfs)
2047         {
2048                 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2049                 return (-EINVAL);
2050         }
2051         if (rx_mode == 0)
2052         {
2053                 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2054                 return (-EINVAL);
2055         }
2056         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2057         return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2058 }
2059
2060 /*
2061  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2062  * an empty spot.
2063  */
2064 static inline int
2065 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2066 {
2067         struct rte_eth_dev_info dev_info;
2068         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2069         unsigned i;
2070
2071         rte_eth_dev_info_get(port_id, &dev_info);
2072         if (!dev->data->hash_mac_addrs)
2073                 return -1;
2074
2075         for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2076                 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2077                         ETHER_ADDR_LEN) == 0)
2078                         return i;
2079
2080         return -1;
2081 }
2082
2083 int
2084 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2085                                 uint8_t on)
2086 {
2087         int index;
2088         int ret;
2089         struct rte_eth_dev *dev;
2090
2091         if (port_id >= nb_ports) {
2092                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2093                         port_id);
2094                 return (-ENODEV);
2095         }
2096
2097         dev = &rte_eth_devices[port_id];
2098         if (is_zero_ether_addr(addr)) {
2099                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2100                         port_id);
2101                 return (-EINVAL);
2102         }
2103
2104         index = get_hash_mac_addr_index(port_id, addr);
2105         /* Check if it's already there, and do nothing */
2106         if ((index >= 0) && (on))
2107                 return 0;
2108
2109         if (index < 0) {
2110                 if (!on) {
2111                         PMD_DEBUG_TRACE("port %d: the MAC address was not"
2112                                 "set in UTA\n", port_id);
2113                         return (-EINVAL);
2114                 }
2115
2116                 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2117                 if (index < 0) {
2118                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2119                                         port_id);
2120                         return (-ENOSPC);
2121                 }
2122         }
2123
2124         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2125         ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2126         if (ret == 0) {
2127                 /* Update address in NIC data structure */
2128                 if (on)
2129                         ether_addr_copy(addr,
2130                                         &dev->data->hash_mac_addrs[index]);
2131                 else
2132                         ether_addr_copy(&null_mac_addr,
2133                                         &dev->data->hash_mac_addrs[index]);
2134         }
2135
2136         return ret;
2137 }
2138
2139 int
2140 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2141 {
2142         struct rte_eth_dev *dev;
2143
2144         if (port_id >= nb_ports) {
2145                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2146                         port_id);
2147                 return (-ENODEV);
2148         }
2149
2150         dev = &rte_eth_devices[port_id];
2151
2152         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2153         return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2154 }
2155
2156 int
2157 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2158 {
2159         uint16_t num_vfs;
2160         struct rte_eth_dev *dev;
2161         struct rte_eth_dev_info dev_info;
2162
2163         if (port_id >= nb_ports) {
2164                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2165                 return (-ENODEV);
2166         }
2167
2168         dev = &rte_eth_devices[port_id];
2169         rte_eth_dev_info_get(port_id, &dev_info);
2170
2171         num_vfs = dev_info.max_vfs;
2172         if (vf > num_vfs)
2173         {
2174                 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2175                 return (-EINVAL);
2176         }
2177
2178         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2179         return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2180 }
2181
2182 int
2183 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2184 {
2185         uint16_t num_vfs;
2186         struct rte_eth_dev *dev;
2187         struct rte_eth_dev_info dev_info;
2188
2189         if (port_id >= nb_ports) {
2190                 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2191                 return (-ENODEV);
2192         }
2193
2194         dev = &rte_eth_devices[port_id];
2195         rte_eth_dev_info_get(port_id, &dev_info);
2196
2197         num_vfs = dev_info.max_vfs;
2198         if (vf > num_vfs)
2199         {
2200                 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2201                 return (-EINVAL);
2202         }
2203
2204         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2205         return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2206 }
2207
2208 int
2209 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2210                                  uint64_t vf_mask,uint8_t vlan_on)
2211 {
2212         struct rte_eth_dev *dev;
2213
2214         if (port_id >= nb_ports) {
2215                 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2216                                 port_id);
2217                 return (-ENODEV);
2218         }
2219         dev = &rte_eth_devices[port_id];
2220
2221         if(vlan_id > ETHER_MAX_VLAN_ID)
2222         {
2223                 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2224                         vlan_id);
2225                 return (-EINVAL);
2226         }
2227         if (vf_mask == 0)
2228         {
2229                 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2230                 return (-EINVAL);
2231         }
2232
2233         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2234         return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2235                                                 vf_mask,vlan_on);
2236 }
2237
2238 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2239                                         uint16_t tx_rate)
2240 {
2241         struct rte_eth_dev *dev;
2242         struct rte_eth_dev_info dev_info;
2243         struct rte_eth_link link;
2244
2245         if (port_id >= nb_ports) {
2246                 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2247                                 port_id);
2248                 return -ENODEV;
2249         }
2250
2251         dev = &rte_eth_devices[port_id];
2252         rte_eth_dev_info_get(port_id, &dev_info);
2253         link = dev->data->dev_link;
2254
2255         if (queue_idx > dev_info.max_tx_queues) {
2256                 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2257                                 "invalid queue id=%d\n", port_id, queue_idx);
2258                 return -EINVAL;
2259         }
2260
2261         if (tx_rate > link.link_speed) {
2262                 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2263                                 "bigger than link speed= %d\n",
2264                         tx_rate, link.link_speed);
2265                 return -EINVAL;
2266         }
2267
2268         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2269         return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2270 }
2271
2272 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2273                                 uint64_t q_msk)
2274 {
2275         struct rte_eth_dev *dev;
2276         struct rte_eth_dev_info dev_info;
2277         struct rte_eth_link link;
2278
2279         if (q_msk == 0)
2280                 return 0;
2281
2282         if (port_id >= nb_ports) {
2283                 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2284                                 port_id);
2285                 return -ENODEV;
2286         }
2287
2288         dev = &rte_eth_devices[port_id];
2289         rte_eth_dev_info_get(port_id, &dev_info);
2290         link = dev->data->dev_link;
2291
2292         if (vf > dev_info.max_vfs) {
2293                 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2294                                 "invalid vf id=%d\n", port_id, vf);
2295                 return -EINVAL;
2296         }
2297
2298         if (tx_rate > link.link_speed) {
2299                 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2300                                 "bigger than link speed= %d\n",
2301                                 tx_rate, link.link_speed);
2302                 return -EINVAL;
2303         }
2304
2305         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2306         return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2307 }
2308
2309 int
2310 rte_eth_mirror_rule_set(uint8_t port_id,
2311                         struct rte_eth_vmdq_mirror_conf *mirror_conf,
2312                         uint8_t rule_id, uint8_t on)
2313 {
2314         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2315
2316         if (port_id >= nb_ports) {
2317                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2318                 return (-ENODEV);
2319         }
2320
2321         if (mirror_conf->rule_type_mask == 0) {
2322                 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2323                 return (-EINVAL);
2324         }
2325
2326         if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2327                 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2328                         "be 0-%d\n",ETH_64_POOLS - 1);
2329                 return (-EINVAL);
2330         }
2331
2332         if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2333                 (mirror_conf->pool_mask == 0)) {
2334                 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2335                                 "be 0.\n");
2336                 return (-EINVAL);
2337         }
2338
2339         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2340         {
2341                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2342                         ETH_VMDQ_NUM_MIRROR_RULE - 1);
2343                 return (-EINVAL);
2344         }
2345
2346         dev = &rte_eth_devices[port_id];
2347         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2348
2349         return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2350 }
2351
2352 int
2353 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2354 {
2355         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2356
2357         if (port_id >= nb_ports) {
2358                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2359                 return (-ENODEV);
2360         }
2361
2362         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2363         {
2364                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2365                         ETH_VMDQ_NUM_MIRROR_RULE-1);
2366                 return (-EINVAL);
2367         }
2368
2369         dev = &rte_eth_devices[port_id];
2370         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2371
2372         return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2373 }
2374
2375 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2376 uint16_t
2377 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2378                  struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2379 {
2380         struct rte_eth_dev *dev;
2381
2382         if (port_id >= nb_ports) {
2383                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2384                 return 0;
2385         }
2386         dev = &rte_eth_devices[port_id];
2387         FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2388         if (queue_id >= dev->data->nb_rx_queues) {
2389                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2390                 return 0;
2391         }
2392         return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2393                                                 rx_pkts, nb_pkts);
2394 }
2395
2396 uint16_t
2397 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2398                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2399 {
2400         struct rte_eth_dev *dev;
2401
2402         if (port_id >= nb_ports) {
2403                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2404                 return 0;
2405         }
2406         dev = &rte_eth_devices[port_id];
2407
2408         FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2409         if (queue_id >= dev->data->nb_tx_queues) {
2410                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2411                 return 0;
2412         }
2413         return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2414                                                 tx_pkts, nb_pkts);
2415 }
2416
2417 uint32_t
2418 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2419 {
2420         struct rte_eth_dev *dev;
2421
2422         if (port_id >= nb_ports) {
2423                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2424                 return 0;
2425         }
2426         dev = &rte_eth_devices[port_id];
2427         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2428         return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2429 }
2430
2431 int
2432 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2433 {
2434         struct rte_eth_dev *dev;
2435
2436         if (port_id >= nb_ports) {
2437                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2438                 return (-ENODEV);
2439         }
2440         dev = &rte_eth_devices[port_id];
2441         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2442         return (*dev->dev_ops->rx_descriptor_done)( \
2443                 dev->data->rx_queues[queue_id], offset);
2444 }
2445 #endif
2446
2447 int
2448 rte_eth_dev_callback_register(uint8_t port_id,
2449                         enum rte_eth_event_type event,
2450                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2451 {
2452         struct rte_eth_dev *dev;
2453         struct rte_eth_dev_callback *user_cb;
2454
2455         if (!cb_fn)
2456                 return (-EINVAL);
2457         if (port_id >= nb_ports) {
2458                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2459                 return (-EINVAL);
2460         }
2461
2462         dev = &rte_eth_devices[port_id];
2463         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2464
2465         TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2466                 if (user_cb->cb_fn == cb_fn &&
2467                         user_cb->cb_arg == cb_arg &&
2468                         user_cb->event == event) {
2469                         break;
2470                 }
2471         }
2472
2473         /* create a new callback. */
2474         if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2475                         sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2476                 user_cb->cb_fn = cb_fn;
2477                 user_cb->cb_arg = cb_arg;
2478                 user_cb->event = event;
2479                 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2480         }
2481
2482         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2483         return ((user_cb == NULL) ? -ENOMEM : 0);
2484 }
2485
2486 int
2487 rte_eth_dev_callback_unregister(uint8_t port_id,
2488                         enum rte_eth_event_type event,
2489                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2490 {
2491         int ret;
2492         struct rte_eth_dev *dev;
2493         struct rte_eth_dev_callback *cb, *next;
2494
2495         if (!cb_fn)
2496                 return (-EINVAL);
2497         if (port_id >= nb_ports) {
2498                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2499                 return (-EINVAL);
2500         }
2501
2502         dev = &rte_eth_devices[port_id];
2503         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2504
2505         ret = 0;
2506         for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2507
2508                 next = TAILQ_NEXT(cb, next);
2509
2510                 if (cb->cb_fn != cb_fn || cb->event != event ||
2511                                 (cb->cb_arg != (void *)-1 &&
2512                                 cb->cb_arg != cb_arg))
2513                         continue;
2514
2515                 /*
2516                  * if this callback is not executing right now,
2517                  * then remove it.
2518                  */
2519                 if (cb->active == 0) {
2520                         TAILQ_REMOVE(&(dev->callbacks), cb, next);
2521                         rte_free(cb);
2522                 } else {
2523                         ret = -EAGAIN;
2524                 }
2525         }
2526
2527         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2528         return (ret);
2529 }
2530
2531 void
2532 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2533         enum rte_eth_event_type event)
2534 {
2535         struct rte_eth_dev_callback *cb_lst;
2536         struct rte_eth_dev_callback dev_cb;
2537
2538         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2539         TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2540                 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2541                         continue;
2542                 dev_cb = *cb_lst;
2543                 cb_lst->active = 1;
2544                 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2545                 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2546                                                 dev_cb.cb_arg);
2547                 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2548                 cb_lst->active = 0;
2549         }
2550         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2551 }
2552 #ifdef RTE_NIC_BYPASS
2553 int rte_eth_dev_bypass_init(uint8_t port_id)
2554 {
2555         struct rte_eth_dev *dev;
2556
2557         if (port_id >= nb_ports) {
2558                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2559                 return (-ENODEV);
2560         }
2561
2562         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2563                 PMD_DEBUG_TRACE("Invalid port device\n");
2564                 return (-ENODEV);
2565         }
2566
2567         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2568         (*dev->dev_ops->bypass_init)(dev);
2569         return 0;
2570 }
2571
2572 int
2573 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2574 {
2575         struct rte_eth_dev *dev;
2576
2577         if (port_id >= nb_ports) {
2578                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2579                 return (-ENODEV);
2580         }
2581
2582         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2583                 PMD_DEBUG_TRACE("Invalid port device\n");
2584                 return (-ENODEV);
2585         }
2586         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2587         (*dev->dev_ops->bypass_state_show)(dev, state);
2588         return 0;
2589 }
2590
2591 int
2592 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2593 {
2594         struct rte_eth_dev *dev;
2595
2596         if (port_id >= nb_ports) {
2597                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2598                 return (-ENODEV);
2599         }
2600
2601         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2602                 PMD_DEBUG_TRACE("Invalid port device\n");
2603                 return (-ENODEV);
2604         }
2605
2606         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2607         (*dev->dev_ops->bypass_state_set)(dev, new_state);
2608         return 0;
2609 }
2610
2611 int
2612 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2613 {
2614         struct rte_eth_dev *dev;
2615
2616         if (port_id >= nb_ports) {
2617                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2618                 return (-ENODEV);
2619         }
2620
2621         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2622                 PMD_DEBUG_TRACE("Invalid port device\n");
2623                 return (-ENODEV);
2624         }
2625
2626         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2627         (*dev->dev_ops->bypass_event_show)(dev, event, state);
2628         return 0;
2629 }
2630
2631 int
2632 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2633 {
2634         struct rte_eth_dev *dev;
2635
2636         if (port_id >= nb_ports) {
2637                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2638                 return (-ENODEV);
2639         }
2640
2641         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2642                 PMD_DEBUG_TRACE("Invalid port device\n");
2643                 return (-ENODEV);
2644         }
2645
2646         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2647         (*dev->dev_ops->bypass_event_set)(dev, event, state);
2648         return 0;
2649 }
2650
2651 int
2652 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2653 {
2654         struct rte_eth_dev *dev;
2655
2656         if (port_id >= nb_ports) {
2657                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2658                 return (-ENODEV);
2659         }
2660
2661         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2662                 PMD_DEBUG_TRACE("Invalid port device\n");
2663                 return (-ENODEV);
2664         }
2665
2666         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2667         (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2668         return 0;
2669 }
2670
2671 int
2672 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2673 {
2674         struct rte_eth_dev *dev;
2675
2676         if (port_id >= nb_ports) {
2677                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2678                 return (-ENODEV);
2679         }
2680
2681         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2682                 PMD_DEBUG_TRACE("Invalid port device\n");
2683                 return (-ENODEV);
2684         }
2685
2686         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2687         (*dev->dev_ops->bypass_ver_show)(dev, ver);
2688         return 0;
2689 }
2690
2691 int
2692 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2693 {
2694         struct rte_eth_dev *dev;
2695
2696         if (port_id >= nb_ports) {
2697                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2698                 return (-ENODEV);
2699         }
2700
2701         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2702                 PMD_DEBUG_TRACE("Invalid port device\n");
2703                 return (-ENODEV);
2704         }
2705
2706         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2707         (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2708         return 0;
2709 }
2710
2711 int
2712 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2713 {
2714         struct rte_eth_dev *dev;
2715
2716         if (port_id >= nb_ports) {
2717                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2718                 return (-ENODEV);
2719         }
2720
2721         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2722                 PMD_DEBUG_TRACE("Invalid port device\n");
2723                 return (-ENODEV);
2724         }
2725
2726         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2727         (*dev->dev_ops->bypass_wd_reset)(dev);
2728         return 0;
2729 }
2730 #endif
2731
2732 int
2733 rte_eth_dev_add_syn_filter(uint8_t port_id,
2734                         struct rte_syn_filter *filter, uint16_t rx_queue)
2735 {
2736         struct rte_eth_dev *dev;
2737
2738         if (port_id >= nb_ports) {
2739                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2740                 return -ENODEV;
2741         }
2742
2743         dev = &rte_eth_devices[port_id];
2744         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_syn_filter, -ENOTSUP);
2745         return (*dev->dev_ops->add_syn_filter)(dev, filter, rx_queue);
2746 }
2747
2748 int
2749 rte_eth_dev_remove_syn_filter(uint8_t port_id)
2750 {
2751         struct rte_eth_dev *dev;
2752
2753         if (port_id >= nb_ports) {
2754                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2755                 return -ENODEV;
2756         }
2757
2758         dev = &rte_eth_devices[port_id];
2759         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_syn_filter, -ENOTSUP);
2760         return (*dev->dev_ops->remove_syn_filter)(dev);
2761 }
2762
2763 int
2764 rte_eth_dev_get_syn_filter(uint8_t port_id,
2765                         struct rte_syn_filter *filter, uint16_t *rx_queue)
2766 {
2767         struct rte_eth_dev *dev;
2768
2769         if (filter == NULL || rx_queue == NULL)
2770                 return -EINVAL;
2771
2772         if (port_id >= nb_ports) {
2773                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2774                 return -ENODEV;
2775         }
2776
2777         dev = &rte_eth_devices[port_id];
2778         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_syn_filter, -ENOTSUP);
2779         return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue);
2780 }
2781
2782 int
2783 rte_eth_dev_add_ethertype_filter(uint8_t port_id, uint16_t index,
2784                         struct rte_ethertype_filter *filter, uint16_t rx_queue)
2785 {
2786         struct rte_eth_dev *dev;
2787
2788         if (port_id >= nb_ports) {
2789                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2790                 return -ENODEV;
2791         }
2792         if (filter->ethertype == ETHER_TYPE_IPv4 ||
2793                 filter->ethertype == ETHER_TYPE_IPv6){
2794                 PMD_DEBUG_TRACE("IP and IPv6 are not supported"
2795                         " in ethertype filter\n");
2796                 return -EINVAL;
2797         }
2798         dev = &rte_eth_devices[port_id];
2799         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_ethertype_filter, -ENOTSUP);
2800         return (*dev->dev_ops->add_ethertype_filter)(dev, index,
2801                                         filter, rx_queue);
2802 }
2803
2804 int
2805 rte_eth_dev_remove_ethertype_filter(uint8_t port_id,  uint16_t index)
2806 {
2807         struct rte_eth_dev *dev;
2808
2809         if (port_id >= nb_ports) {
2810                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2811                 return -ENODEV;
2812         }
2813
2814         dev = &rte_eth_devices[port_id];
2815         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_ethertype_filter, -ENOTSUP);
2816         return (*dev->dev_ops->remove_ethertype_filter)(dev, index);
2817 }
2818
2819 int
2820 rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index,
2821                         struct rte_ethertype_filter *filter, uint16_t *rx_queue)
2822 {
2823         struct rte_eth_dev *dev;
2824
2825         if (filter == NULL || rx_queue == NULL)
2826                 return -EINVAL;
2827
2828         if (port_id >= nb_ports) {
2829                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2830                 return -ENODEV;
2831         }
2832
2833         dev = &rte_eth_devices[port_id];
2834         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_ethertype_filter, -ENOTSUP);
2835         return (*dev->dev_ops->get_ethertype_filter)(dev, index,
2836                                                 filter, rx_queue);
2837 }
2838
2839 int
2840 rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
2841                         struct rte_2tuple_filter *filter, uint16_t rx_queue)
2842 {
2843         struct rte_eth_dev *dev;
2844
2845         if (port_id >= nb_ports) {
2846                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2847                 return -ENODEV;
2848         }
2849         if (filter->protocol != IPPROTO_TCP &&
2850                 filter->tcp_flags != 0){
2851                 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
2852                         " is not TCP\n",
2853                         filter->tcp_flags);
2854                 return -EINVAL;
2855         }
2856
2857         dev = &rte_eth_devices[port_id];
2858         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP);
2859         return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue);
2860 }
2861
2862 int
2863 rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
2864 {
2865         struct rte_eth_dev *dev;
2866
2867         if (port_id >= nb_ports) {
2868                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2869                 return -ENODEV;
2870         }
2871
2872         dev = &rte_eth_devices[port_id];
2873         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP);
2874         return (*dev->dev_ops->remove_2tuple_filter)(dev, index);
2875 }
2876
2877 int
2878 rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
2879                         struct rte_2tuple_filter *filter, uint16_t *rx_queue)
2880 {
2881         struct rte_eth_dev *dev;
2882
2883         if (filter == NULL || rx_queue == NULL)
2884                 return -EINVAL;
2885
2886         if (port_id >= nb_ports) {
2887                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2888                 return -ENODEV;
2889         }
2890
2891         dev = &rte_eth_devices[port_id];
2892         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP);
2893         return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue);
2894 }
2895
2896 int
2897 rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
2898                         struct rte_5tuple_filter *filter, uint16_t rx_queue)
2899 {
2900         struct rte_eth_dev *dev;
2901
2902         if (port_id >= nb_ports) {
2903                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2904                 return -ENODEV;
2905         }
2906
2907         if (filter->protocol != IPPROTO_TCP &&
2908                 filter->tcp_flags != 0){
2909                 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
2910                         " is not TCP\n",
2911                         filter->tcp_flags);
2912                 return -EINVAL;
2913         }
2914
2915         dev = &rte_eth_devices[port_id];
2916         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP);
2917         return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue);
2918 }
2919
2920 int
2921 rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
2922 {
2923         struct rte_eth_dev *dev;
2924
2925         if (port_id >= nb_ports) {
2926                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2927                 return -ENODEV;
2928         }
2929
2930         dev = &rte_eth_devices[port_id];
2931         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP);
2932         return (*dev->dev_ops->remove_5tuple_filter)(dev, index);
2933 }
2934
2935 int
2936 rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
2937                         struct rte_5tuple_filter *filter, uint16_t *rx_queue)
2938 {
2939         struct rte_eth_dev *dev;
2940
2941         if (filter == NULL || rx_queue == NULL)
2942                 return -EINVAL;
2943
2944         if (port_id >= nb_ports) {
2945                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2946                 return -ENODEV;
2947         }
2948
2949         dev = &rte_eth_devices[port_id];
2950         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP);
2951         return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter,
2952                                                 rx_queue);
2953 }
2954
2955 int
2956 rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
2957                         struct rte_flex_filter *filter, uint16_t rx_queue)
2958 {
2959         struct rte_eth_dev *dev;
2960
2961         if (port_id >= nb_ports) {
2962                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2963                 return -ENODEV;
2964         }
2965
2966         dev = &rte_eth_devices[port_id];
2967         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP);
2968         return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue);
2969 }
2970
2971 int
2972 rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
2973 {
2974         struct rte_eth_dev *dev;
2975
2976         if (port_id >= nb_ports) {
2977                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2978                 return -ENODEV;
2979         }
2980
2981         dev = &rte_eth_devices[port_id];
2982         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP);
2983         return (*dev->dev_ops->remove_flex_filter)(dev, index);
2984 }
2985
2986 int
2987 rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
2988                         struct rte_flex_filter *filter, uint16_t *rx_queue)
2989 {
2990         struct rte_eth_dev *dev;
2991
2992         if (filter == NULL || rx_queue == NULL)
2993                 return -EINVAL;
2994
2995         if (port_id >= nb_ports) {
2996                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2997                 return -ENODEV;
2998         }
2999
3000         dev = &rte_eth_devices[port_id];
3001         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_flex_filter, -ENOTSUP);
3002         return (*dev->dev_ops->get_flex_filter)(dev, index, filter,
3003                                                 rx_queue);
3004 }