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