add prefix to cache line macros
[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                                   RTE_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                                 RTE_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                                 RTE_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                                 RTE_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                                 RTE_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 static inline int
1931 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1932                         uint16_t reta_size)
1933 {
1934         uint16_t i, num;
1935
1936         if (!reta_conf)
1937                 return -EINVAL;
1938
1939         if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1940                 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1941                                                         RTE_RETA_GROUP_SIZE);
1942                 return -EINVAL;
1943         }
1944
1945         num = reta_size / RTE_RETA_GROUP_SIZE;
1946         for (i = 0; i < num; i++) {
1947                 if (reta_conf[i].mask)
1948                         return 0;
1949         }
1950
1951         return -EINVAL;
1952 }
1953
1954 static inline int
1955 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1956                          uint16_t reta_size,
1957                          uint8_t max_rxq)
1958 {
1959         uint16_t i, idx, shift;
1960
1961         if (!reta_conf)
1962                 return -EINVAL;
1963
1964         if (max_rxq == 0) {
1965                 PMD_DEBUG_TRACE("No receive queue is available\n");
1966                 return -EINVAL;
1967         }
1968
1969         for (i = 0; i < reta_size; i++) {
1970                 idx = i / RTE_RETA_GROUP_SIZE;
1971                 shift = i % RTE_RETA_GROUP_SIZE;
1972                 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1973                         (reta_conf[idx].reta[shift] >= max_rxq)) {
1974                         PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1975                                 "the maximum rxq index: %u\n", idx, shift,
1976                                 reta_conf[idx].reta[shift], max_rxq);
1977                         return -EINVAL;
1978                 }
1979         }
1980
1981         return 0;
1982 }
1983
1984 int
1985 rte_eth_dev_rss_reta_update(uint8_t port_id,
1986                             struct rte_eth_rss_reta_entry64 *reta_conf,
1987                             uint16_t reta_size)
1988 {
1989         struct rte_eth_dev *dev;
1990         int ret;
1991
1992         if (port_id >= nb_ports) {
1993                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1994                 return -ENODEV;
1995         }
1996
1997         /* Check mask bits */
1998         ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1999         if (ret < 0)
2000                 return ret;
2001
2002         dev = &rte_eth_devices[port_id];
2003
2004         /* Check entry value */
2005         ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2006                                 dev->data->nb_rx_queues);
2007         if (ret < 0)
2008                 return ret;
2009
2010         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2011         return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2012 }
2013
2014 int
2015 rte_eth_dev_rss_reta_query(uint8_t port_id,
2016                            struct rte_eth_rss_reta_entry64 *reta_conf,
2017                            uint16_t reta_size)
2018 {
2019         struct rte_eth_dev *dev;
2020         int ret;
2021
2022         if (port_id >= nb_ports) {
2023                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2024                 return -ENODEV;
2025         }
2026
2027         /* Check mask bits */
2028         ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2029         if (ret < 0)
2030                 return ret;
2031
2032         dev = &rte_eth_devices[port_id];
2033         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2034         return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2035 }
2036
2037 int
2038 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2039 {
2040         struct rte_eth_dev *dev;
2041         uint16_t rss_hash_protos;
2042
2043         if (port_id >= nb_ports) {
2044                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2045                 return (-ENODEV);
2046         }
2047         rss_hash_protos = rss_conf->rss_hf;
2048         if ((rss_hash_protos != 0) &&
2049             ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2050                 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2051                                 rss_hash_protos);
2052                 return (-EINVAL);
2053         }
2054         dev = &rte_eth_devices[port_id];
2055         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2056         return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2057 }
2058
2059 int
2060 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2061                               struct rte_eth_rss_conf *rss_conf)
2062 {
2063         struct rte_eth_dev *dev;
2064
2065         if (port_id >= nb_ports) {
2066                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2067                 return (-ENODEV);
2068         }
2069         dev = &rte_eth_devices[port_id];
2070         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2071         return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2072 }
2073
2074 int
2075 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2076                            struct rte_eth_udp_tunnel *udp_tunnel)
2077 {
2078         struct rte_eth_dev *dev;
2079
2080         if (port_id >= nb_ports) {
2081                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2082                 return -ENODEV;
2083         }
2084
2085         if (udp_tunnel == NULL) {
2086                 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2087                 return -EINVAL;
2088         }
2089
2090         if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2091                 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2092                 return -EINVAL;
2093         }
2094
2095         dev = &rte_eth_devices[port_id];
2096         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2097         return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2098 }
2099
2100 int
2101 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2102                               struct rte_eth_udp_tunnel *udp_tunnel)
2103 {
2104         struct rte_eth_dev *dev;
2105
2106         if (port_id >= nb_ports) {
2107                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2108                 return -ENODEV;
2109         }
2110         dev = &rte_eth_devices[port_id];
2111
2112         if (udp_tunnel == NULL) {
2113                 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2114                 return -EINVAL;
2115         }
2116
2117         if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2118                 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2119                 return -EINVAL;
2120         }
2121
2122         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2123         return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2124 }
2125
2126 int
2127 rte_eth_led_on(uint8_t port_id)
2128 {
2129         struct rte_eth_dev *dev;
2130
2131         if (port_id >= nb_ports) {
2132                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2133                 return (-ENODEV);
2134         }
2135
2136         dev = &rte_eth_devices[port_id];
2137         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2138         return ((*dev->dev_ops->dev_led_on)(dev));
2139 }
2140
2141 int
2142 rte_eth_led_off(uint8_t port_id)
2143 {
2144         struct rte_eth_dev *dev;
2145
2146         if (port_id >= nb_ports) {
2147                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2148                 return (-ENODEV);
2149         }
2150
2151         dev = &rte_eth_devices[port_id];
2152         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2153         return ((*dev->dev_ops->dev_led_off)(dev));
2154 }
2155
2156 /*
2157  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2158  * an empty spot.
2159  */
2160 static inline int
2161 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2162 {
2163         struct rte_eth_dev_info dev_info;
2164         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2165         unsigned i;
2166
2167         rte_eth_dev_info_get(port_id, &dev_info);
2168
2169         for (i = 0; i < dev_info.max_mac_addrs; i++)
2170                 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2171                         return i;
2172
2173         return -1;
2174 }
2175
2176 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2177
2178 int
2179 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2180                         uint32_t pool)
2181 {
2182         struct rte_eth_dev *dev;
2183         int index;
2184         uint64_t pool_mask;
2185
2186         if (port_id >= nb_ports) {
2187                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2188                 return (-ENODEV);
2189         }
2190         dev = &rte_eth_devices[port_id];
2191         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2192
2193         if (is_zero_ether_addr(addr)) {
2194                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2195                         port_id);
2196                 return (-EINVAL);
2197         }
2198         if (pool >= ETH_64_POOLS) {
2199                 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2200                 return (-EINVAL);
2201         }
2202
2203         index = get_mac_addr_index(port_id, addr);
2204         if (index < 0) {
2205                 index = get_mac_addr_index(port_id, &null_mac_addr);
2206                 if (index < 0) {
2207                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2208                                 port_id);
2209                         return (-ENOSPC);
2210                 }
2211         } else {
2212                 pool_mask = dev->data->mac_pool_sel[index];
2213
2214                 /* Check if both MAC address and pool is alread there, and do nothing */
2215                 if (pool_mask & (1ULL << pool))
2216                         return 0;
2217         }
2218
2219         /* Update NIC */
2220         (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2221
2222         /* Update address in NIC data structure */
2223         ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2224
2225         /* Update pool bitmap in NIC data structure */
2226         dev->data->mac_pool_sel[index] |= (1ULL << pool);
2227
2228         return 0;
2229 }
2230
2231 int
2232 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2233 {
2234         struct rte_eth_dev *dev;
2235         int index;
2236
2237         if (port_id >= nb_ports) {
2238                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2239                 return (-ENODEV);
2240         }
2241         dev = &rte_eth_devices[port_id];
2242         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2243
2244         index = get_mac_addr_index(port_id, addr);
2245         if (index == 0) {
2246                 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2247                 return (-EADDRINUSE);
2248         } else if (index < 0)
2249                 return 0;  /* Do nothing if address wasn't found */
2250
2251         /* Update NIC */
2252         (*dev->dev_ops->mac_addr_remove)(dev, index);
2253
2254         /* Update address in NIC data structure */
2255         ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2256
2257         /* reset pool bitmap */
2258         dev->data->mac_pool_sel[index] = 0;
2259
2260         return 0;
2261 }
2262
2263 int
2264 rte_eth_dev_set_vf_rxmode(uint8_t port_id,  uint16_t vf,
2265                                 uint16_t rx_mode, uint8_t on)
2266 {
2267         uint16_t num_vfs;
2268         struct rte_eth_dev *dev;
2269         struct rte_eth_dev_info dev_info;
2270
2271         if (port_id >= nb_ports) {
2272                 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2273                                 port_id);
2274                 return (-ENODEV);
2275         }
2276
2277         dev = &rte_eth_devices[port_id];
2278         rte_eth_dev_info_get(port_id, &dev_info);
2279
2280         num_vfs = dev_info.max_vfs;
2281         if (vf > num_vfs)
2282         {
2283                 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2284                 return (-EINVAL);
2285         }
2286         if (rx_mode == 0)
2287         {
2288                 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2289                 return (-EINVAL);
2290         }
2291         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2292         return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2293 }
2294
2295 /*
2296  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2297  * an empty spot.
2298  */
2299 static inline int
2300 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2301 {
2302         struct rte_eth_dev_info dev_info;
2303         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2304         unsigned i;
2305
2306         rte_eth_dev_info_get(port_id, &dev_info);
2307         if (!dev->data->hash_mac_addrs)
2308                 return -1;
2309
2310         for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2311                 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2312                         ETHER_ADDR_LEN) == 0)
2313                         return i;
2314
2315         return -1;
2316 }
2317
2318 int
2319 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2320                                 uint8_t on)
2321 {
2322         int index;
2323         int ret;
2324         struct rte_eth_dev *dev;
2325
2326         if (port_id >= nb_ports) {
2327                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2328                         port_id);
2329                 return (-ENODEV);
2330         }
2331
2332         dev = &rte_eth_devices[port_id];
2333         if (is_zero_ether_addr(addr)) {
2334                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2335                         port_id);
2336                 return (-EINVAL);
2337         }
2338
2339         index = get_hash_mac_addr_index(port_id, addr);
2340         /* Check if it's already there, and do nothing */
2341         if ((index >= 0) && (on))
2342                 return 0;
2343
2344         if (index < 0) {
2345                 if (!on) {
2346                         PMD_DEBUG_TRACE("port %d: the MAC address was not"
2347                                 "set in UTA\n", port_id);
2348                         return (-EINVAL);
2349                 }
2350
2351                 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2352                 if (index < 0) {
2353                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2354                                         port_id);
2355                         return (-ENOSPC);
2356                 }
2357         }
2358
2359         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2360         ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2361         if (ret == 0) {
2362                 /* Update address in NIC data structure */
2363                 if (on)
2364                         ether_addr_copy(addr,
2365                                         &dev->data->hash_mac_addrs[index]);
2366                 else
2367                         ether_addr_copy(&null_mac_addr,
2368                                         &dev->data->hash_mac_addrs[index]);
2369         }
2370
2371         return ret;
2372 }
2373
2374 int
2375 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2376 {
2377         struct rte_eth_dev *dev;
2378
2379         if (port_id >= nb_ports) {
2380                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2381                         port_id);
2382                 return (-ENODEV);
2383         }
2384
2385         dev = &rte_eth_devices[port_id];
2386
2387         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2388         return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2389 }
2390
2391 int
2392 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2393 {
2394         uint16_t num_vfs;
2395         struct rte_eth_dev *dev;
2396         struct rte_eth_dev_info dev_info;
2397
2398         if (port_id >= nb_ports) {
2399                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2400                 return (-ENODEV);
2401         }
2402
2403         dev = &rte_eth_devices[port_id];
2404         rte_eth_dev_info_get(port_id, &dev_info);
2405
2406         num_vfs = dev_info.max_vfs;
2407         if (vf > num_vfs)
2408         {
2409                 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2410                 return (-EINVAL);
2411         }
2412
2413         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2414         return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2415 }
2416
2417 int
2418 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2419 {
2420         uint16_t num_vfs;
2421         struct rte_eth_dev *dev;
2422         struct rte_eth_dev_info dev_info;
2423
2424         if (port_id >= nb_ports) {
2425                 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2426                 return (-ENODEV);
2427         }
2428
2429         dev = &rte_eth_devices[port_id];
2430         rte_eth_dev_info_get(port_id, &dev_info);
2431
2432         num_vfs = dev_info.max_vfs;
2433         if (vf > num_vfs)
2434         {
2435                 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2436                 return (-EINVAL);
2437         }
2438
2439         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2440         return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2441 }
2442
2443 int
2444 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2445                                  uint64_t vf_mask,uint8_t vlan_on)
2446 {
2447         struct rte_eth_dev *dev;
2448
2449         if (port_id >= nb_ports) {
2450                 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2451                                 port_id);
2452                 return (-ENODEV);
2453         }
2454         dev = &rte_eth_devices[port_id];
2455
2456         if(vlan_id > ETHER_MAX_VLAN_ID)
2457         {
2458                 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2459                         vlan_id);
2460                 return (-EINVAL);
2461         }
2462         if (vf_mask == 0)
2463         {
2464                 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2465                 return (-EINVAL);
2466         }
2467
2468         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2469         return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2470                                                 vf_mask,vlan_on);
2471 }
2472
2473 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2474                                         uint16_t tx_rate)
2475 {
2476         struct rte_eth_dev *dev;
2477         struct rte_eth_dev_info dev_info;
2478         struct rte_eth_link link;
2479
2480         if (port_id >= nb_ports) {
2481                 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2482                                 port_id);
2483                 return -ENODEV;
2484         }
2485
2486         dev = &rte_eth_devices[port_id];
2487         rte_eth_dev_info_get(port_id, &dev_info);
2488         link = dev->data->dev_link;
2489
2490         if (queue_idx > dev_info.max_tx_queues) {
2491                 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2492                                 "invalid queue id=%d\n", port_id, queue_idx);
2493                 return -EINVAL;
2494         }
2495
2496         if (tx_rate > link.link_speed) {
2497                 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2498                                 "bigger than link speed= %d\n",
2499                         tx_rate, link.link_speed);
2500                 return -EINVAL;
2501         }
2502
2503         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2504         return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2505 }
2506
2507 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2508                                 uint64_t q_msk)
2509 {
2510         struct rte_eth_dev *dev;
2511         struct rte_eth_dev_info dev_info;
2512         struct rte_eth_link link;
2513
2514         if (q_msk == 0)
2515                 return 0;
2516
2517         if (port_id >= nb_ports) {
2518                 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2519                                 port_id);
2520                 return -ENODEV;
2521         }
2522
2523         dev = &rte_eth_devices[port_id];
2524         rte_eth_dev_info_get(port_id, &dev_info);
2525         link = dev->data->dev_link;
2526
2527         if (vf > dev_info.max_vfs) {
2528                 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2529                                 "invalid vf id=%d\n", port_id, vf);
2530                 return -EINVAL;
2531         }
2532
2533         if (tx_rate > link.link_speed) {
2534                 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2535                                 "bigger than link speed= %d\n",
2536                                 tx_rate, link.link_speed);
2537                 return -EINVAL;
2538         }
2539
2540         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2541         return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2542 }
2543
2544 int
2545 rte_eth_mirror_rule_set(uint8_t port_id,
2546                         struct rte_eth_vmdq_mirror_conf *mirror_conf,
2547                         uint8_t rule_id, uint8_t on)
2548 {
2549         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2550
2551         if (port_id >= nb_ports) {
2552                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2553                 return (-ENODEV);
2554         }
2555
2556         if (mirror_conf->rule_type_mask == 0) {
2557                 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2558                 return (-EINVAL);
2559         }
2560
2561         if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2562                 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2563                         "be 0-%d\n",ETH_64_POOLS - 1);
2564                 return (-EINVAL);
2565         }
2566
2567         if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2568                 (mirror_conf->pool_mask == 0)) {
2569                 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2570                                 "be 0.\n");
2571                 return (-EINVAL);
2572         }
2573
2574         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2575         {
2576                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2577                         ETH_VMDQ_NUM_MIRROR_RULE - 1);
2578                 return (-EINVAL);
2579         }
2580
2581         dev = &rte_eth_devices[port_id];
2582         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2583
2584         return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2585 }
2586
2587 int
2588 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2589 {
2590         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2591
2592         if (port_id >= nb_ports) {
2593                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2594                 return (-ENODEV);
2595         }
2596
2597         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2598         {
2599                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2600                         ETH_VMDQ_NUM_MIRROR_RULE-1);
2601                 return (-EINVAL);
2602         }
2603
2604         dev = &rte_eth_devices[port_id];
2605         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2606
2607         return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2608 }
2609
2610 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2611 uint16_t
2612 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2613                  struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2614 {
2615         struct rte_eth_dev *dev;
2616
2617         if (port_id >= nb_ports) {
2618                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2619                 return 0;
2620         }
2621         dev = &rte_eth_devices[port_id];
2622         FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2623         if (queue_id >= dev->data->nb_rx_queues) {
2624                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2625                 return 0;
2626         }
2627         return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2628                                                 rx_pkts, nb_pkts);
2629 }
2630
2631 uint16_t
2632 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2633                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2634 {
2635         struct rte_eth_dev *dev;
2636
2637         if (port_id >= nb_ports) {
2638                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2639                 return 0;
2640         }
2641         dev = &rte_eth_devices[port_id];
2642
2643         FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2644         if (queue_id >= dev->data->nb_tx_queues) {
2645                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2646                 return 0;
2647         }
2648         return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2649                                                 tx_pkts, nb_pkts);
2650 }
2651
2652 uint32_t
2653 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2654 {
2655         struct rte_eth_dev *dev;
2656
2657         if (port_id >= nb_ports) {
2658                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2659                 return 0;
2660         }
2661         dev = &rte_eth_devices[port_id];
2662         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2663         return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2664 }
2665
2666 int
2667 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2668 {
2669         struct rte_eth_dev *dev;
2670
2671         if (port_id >= nb_ports) {
2672                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2673                 return (-ENODEV);
2674         }
2675         dev = &rte_eth_devices[port_id];
2676         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2677         return (*dev->dev_ops->rx_descriptor_done)( \
2678                 dev->data->rx_queues[queue_id], offset);
2679 }
2680 #endif
2681
2682 int
2683 rte_eth_dev_callback_register(uint8_t port_id,
2684                         enum rte_eth_event_type event,
2685                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2686 {
2687         struct rte_eth_dev *dev;
2688         struct rte_eth_dev_callback *user_cb;
2689
2690         if (!cb_fn)
2691                 return (-EINVAL);
2692         if (port_id >= nb_ports) {
2693                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2694                 return (-EINVAL);
2695         }
2696
2697         dev = &rte_eth_devices[port_id];
2698         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2699
2700         TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2701                 if (user_cb->cb_fn == cb_fn &&
2702                         user_cb->cb_arg == cb_arg &&
2703                         user_cb->event == event) {
2704                         break;
2705                 }
2706         }
2707
2708         /* create a new callback. */
2709         if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2710                         sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2711                 user_cb->cb_fn = cb_fn;
2712                 user_cb->cb_arg = cb_arg;
2713                 user_cb->event = event;
2714                 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2715         }
2716
2717         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2718         return ((user_cb == NULL) ? -ENOMEM : 0);
2719 }
2720
2721 int
2722 rte_eth_dev_callback_unregister(uint8_t port_id,
2723                         enum rte_eth_event_type event,
2724                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2725 {
2726         int ret;
2727         struct rte_eth_dev *dev;
2728         struct rte_eth_dev_callback *cb, *next;
2729
2730         if (!cb_fn)
2731                 return (-EINVAL);
2732         if (port_id >= nb_ports) {
2733                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2734                 return (-EINVAL);
2735         }
2736
2737         dev = &rte_eth_devices[port_id];
2738         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2739
2740         ret = 0;
2741         for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2742
2743                 next = TAILQ_NEXT(cb, next);
2744
2745                 if (cb->cb_fn != cb_fn || cb->event != event ||
2746                                 (cb->cb_arg != (void *)-1 &&
2747                                 cb->cb_arg != cb_arg))
2748                         continue;
2749
2750                 /*
2751                  * if this callback is not executing right now,
2752                  * then remove it.
2753                  */
2754                 if (cb->active == 0) {
2755                         TAILQ_REMOVE(&(dev->callbacks), cb, next);
2756                         rte_free(cb);
2757                 } else {
2758                         ret = -EAGAIN;
2759                 }
2760         }
2761
2762         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2763         return (ret);
2764 }
2765
2766 void
2767 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2768         enum rte_eth_event_type event)
2769 {
2770         struct rte_eth_dev_callback *cb_lst;
2771         struct rte_eth_dev_callback dev_cb;
2772
2773         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2774         TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2775                 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2776                         continue;
2777                 dev_cb = *cb_lst;
2778                 cb_lst->active = 1;
2779                 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2780                 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2781                                                 dev_cb.cb_arg);
2782                 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2783                 cb_lst->active = 0;
2784         }
2785         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2786 }
2787 #ifdef RTE_NIC_BYPASS
2788 int rte_eth_dev_bypass_init(uint8_t port_id)
2789 {
2790         struct rte_eth_dev *dev;
2791
2792         if (port_id >= nb_ports) {
2793                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2794                 return (-ENODEV);
2795         }
2796
2797         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2798                 PMD_DEBUG_TRACE("Invalid port device\n");
2799                 return (-ENODEV);
2800         }
2801
2802         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2803         (*dev->dev_ops->bypass_init)(dev);
2804         return 0;
2805 }
2806
2807 int
2808 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2809 {
2810         struct rte_eth_dev *dev;
2811
2812         if (port_id >= nb_ports) {
2813                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2814                 return (-ENODEV);
2815         }
2816
2817         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2818                 PMD_DEBUG_TRACE("Invalid port device\n");
2819                 return (-ENODEV);
2820         }
2821         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2822         (*dev->dev_ops->bypass_state_show)(dev, state);
2823         return 0;
2824 }
2825
2826 int
2827 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2828 {
2829         struct rte_eth_dev *dev;
2830
2831         if (port_id >= nb_ports) {
2832                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2833                 return (-ENODEV);
2834         }
2835
2836         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2837                 PMD_DEBUG_TRACE("Invalid port device\n");
2838                 return (-ENODEV);
2839         }
2840
2841         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2842         (*dev->dev_ops->bypass_state_set)(dev, new_state);
2843         return 0;
2844 }
2845
2846 int
2847 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2848 {
2849         struct rte_eth_dev *dev;
2850
2851         if (port_id >= nb_ports) {
2852                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2853                 return (-ENODEV);
2854         }
2855
2856         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2857                 PMD_DEBUG_TRACE("Invalid port device\n");
2858                 return (-ENODEV);
2859         }
2860
2861         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2862         (*dev->dev_ops->bypass_event_show)(dev, event, state);
2863         return 0;
2864 }
2865
2866 int
2867 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2868 {
2869         struct rte_eth_dev *dev;
2870
2871         if (port_id >= nb_ports) {
2872                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2873                 return (-ENODEV);
2874         }
2875
2876         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2877                 PMD_DEBUG_TRACE("Invalid port device\n");
2878                 return (-ENODEV);
2879         }
2880
2881         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2882         (*dev->dev_ops->bypass_event_set)(dev, event, state);
2883         return 0;
2884 }
2885
2886 int
2887 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2888 {
2889         struct rte_eth_dev *dev;
2890
2891         if (port_id >= nb_ports) {
2892                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2893                 return (-ENODEV);
2894         }
2895
2896         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2897                 PMD_DEBUG_TRACE("Invalid port device\n");
2898                 return (-ENODEV);
2899         }
2900
2901         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2902         (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2903         return 0;
2904 }
2905
2906 int
2907 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2908 {
2909         struct rte_eth_dev *dev;
2910
2911         if (port_id >= nb_ports) {
2912                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2913                 return (-ENODEV);
2914         }
2915
2916         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2917                 PMD_DEBUG_TRACE("Invalid port device\n");
2918                 return (-ENODEV);
2919         }
2920
2921         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2922         (*dev->dev_ops->bypass_ver_show)(dev, ver);
2923         return 0;
2924 }
2925
2926 int
2927 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2928 {
2929         struct rte_eth_dev *dev;
2930
2931         if (port_id >= nb_ports) {
2932                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2933                 return (-ENODEV);
2934         }
2935
2936         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2937                 PMD_DEBUG_TRACE("Invalid port device\n");
2938                 return (-ENODEV);
2939         }
2940
2941         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2942         (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2943         return 0;
2944 }
2945
2946 int
2947 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2948 {
2949         struct rte_eth_dev *dev;
2950
2951         if (port_id >= nb_ports) {
2952                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2953                 return (-ENODEV);
2954         }
2955
2956         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2957                 PMD_DEBUG_TRACE("Invalid port device\n");
2958                 return (-ENODEV);
2959         }
2960
2961         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2962         (*dev->dev_ops->bypass_wd_reset)(dev);
2963         return 0;
2964 }
2965 #endif
2966
2967 int
2968 rte_eth_dev_add_syn_filter(uint8_t port_id,
2969                         struct rte_syn_filter *filter, uint16_t rx_queue)
2970 {
2971         struct rte_eth_dev *dev;
2972
2973         if (port_id >= nb_ports) {
2974                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2975                 return -ENODEV;
2976         }
2977
2978         dev = &rte_eth_devices[port_id];
2979         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_syn_filter, -ENOTSUP);
2980         return (*dev->dev_ops->add_syn_filter)(dev, filter, rx_queue);
2981 }
2982
2983 int
2984 rte_eth_dev_remove_syn_filter(uint8_t port_id)
2985 {
2986         struct rte_eth_dev *dev;
2987
2988         if (port_id >= nb_ports) {
2989                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2990                 return -ENODEV;
2991         }
2992
2993         dev = &rte_eth_devices[port_id];
2994         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_syn_filter, -ENOTSUP);
2995         return (*dev->dev_ops->remove_syn_filter)(dev);
2996 }
2997
2998 int
2999 rte_eth_dev_get_syn_filter(uint8_t port_id,
3000                         struct rte_syn_filter *filter, uint16_t *rx_queue)
3001 {
3002         struct rte_eth_dev *dev;
3003
3004         if (filter == NULL || rx_queue == NULL)
3005                 return -EINVAL;
3006
3007         if (port_id >= nb_ports) {
3008                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3009                 return -ENODEV;
3010         }
3011
3012         dev = &rte_eth_devices[port_id];
3013         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_syn_filter, -ENOTSUP);
3014         return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue);
3015 }
3016
3017 int
3018 rte_eth_dev_add_ethertype_filter(uint8_t port_id, uint16_t index,
3019                         struct rte_ethertype_filter *filter, uint16_t rx_queue)
3020 {
3021         struct rte_eth_dev *dev;
3022
3023         if (port_id >= nb_ports) {
3024                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3025                 return -ENODEV;
3026         }
3027         if (filter->ethertype == ETHER_TYPE_IPv4 ||
3028                 filter->ethertype == ETHER_TYPE_IPv6){
3029                 PMD_DEBUG_TRACE("IP and IPv6 are not supported"
3030                         " in ethertype filter\n");
3031                 return -EINVAL;
3032         }
3033         dev = &rte_eth_devices[port_id];
3034         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_ethertype_filter, -ENOTSUP);
3035         return (*dev->dev_ops->add_ethertype_filter)(dev, index,
3036                                         filter, rx_queue);
3037 }
3038
3039 int
3040 rte_eth_dev_remove_ethertype_filter(uint8_t port_id,  uint16_t index)
3041 {
3042         struct rte_eth_dev *dev;
3043
3044         if (port_id >= nb_ports) {
3045                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3046                 return -ENODEV;
3047         }
3048
3049         dev = &rte_eth_devices[port_id];
3050         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_ethertype_filter, -ENOTSUP);
3051         return (*dev->dev_ops->remove_ethertype_filter)(dev, index);
3052 }
3053
3054 int
3055 rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index,
3056                         struct rte_ethertype_filter *filter, uint16_t *rx_queue)
3057 {
3058         struct rte_eth_dev *dev;
3059
3060         if (filter == NULL || rx_queue == NULL)
3061                 return -EINVAL;
3062
3063         if (port_id >= nb_ports) {
3064                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3065                 return -ENODEV;
3066         }
3067
3068         dev = &rte_eth_devices[port_id];
3069         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_ethertype_filter, -ENOTSUP);
3070         return (*dev->dev_ops->get_ethertype_filter)(dev, index,
3071                                                 filter, rx_queue);
3072 }
3073
3074 int
3075 rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
3076                         struct rte_2tuple_filter *filter, uint16_t rx_queue)
3077 {
3078         struct rte_eth_dev *dev;
3079
3080         if (port_id >= nb_ports) {
3081                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3082                 return -ENODEV;
3083         }
3084         if (filter->protocol != IPPROTO_TCP &&
3085                 filter->tcp_flags != 0){
3086                 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3087                         " is not TCP\n",
3088                         filter->tcp_flags);
3089                 return -EINVAL;
3090         }
3091
3092         dev = &rte_eth_devices[port_id];
3093         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP);
3094         return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue);
3095 }
3096
3097 int
3098 rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
3099 {
3100         struct rte_eth_dev *dev;
3101
3102         if (port_id >= nb_ports) {
3103                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3104                 return -ENODEV;
3105         }
3106
3107         dev = &rte_eth_devices[port_id];
3108         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP);
3109         return (*dev->dev_ops->remove_2tuple_filter)(dev, index);
3110 }
3111
3112 int
3113 rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
3114                         struct rte_2tuple_filter *filter, uint16_t *rx_queue)
3115 {
3116         struct rte_eth_dev *dev;
3117
3118         if (filter == NULL || rx_queue == NULL)
3119                 return -EINVAL;
3120
3121         if (port_id >= nb_ports) {
3122                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3123                 return -ENODEV;
3124         }
3125
3126         dev = &rte_eth_devices[port_id];
3127         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP);
3128         return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue);
3129 }
3130
3131 int
3132 rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
3133                         struct rte_5tuple_filter *filter, uint16_t rx_queue)
3134 {
3135         struct rte_eth_dev *dev;
3136
3137         if (port_id >= nb_ports) {
3138                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3139                 return -ENODEV;
3140         }
3141
3142         if (filter->protocol != IPPROTO_TCP &&
3143                 filter->tcp_flags != 0){
3144                 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3145                         " is not TCP\n",
3146                         filter->tcp_flags);
3147                 return -EINVAL;
3148         }
3149
3150         dev = &rte_eth_devices[port_id];
3151         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP);
3152         return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue);
3153 }
3154
3155 int
3156 rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
3157 {
3158         struct rte_eth_dev *dev;
3159
3160         if (port_id >= nb_ports) {
3161                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3162                 return -ENODEV;
3163         }
3164
3165         dev = &rte_eth_devices[port_id];
3166         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP);
3167         return (*dev->dev_ops->remove_5tuple_filter)(dev, index);
3168 }
3169
3170 int
3171 rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
3172                         struct rte_5tuple_filter *filter, uint16_t *rx_queue)
3173 {
3174         struct rte_eth_dev *dev;
3175
3176         if (filter == NULL || rx_queue == NULL)
3177                 return -EINVAL;
3178
3179         if (port_id >= nb_ports) {
3180                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3181                 return -ENODEV;
3182         }
3183
3184         dev = &rte_eth_devices[port_id];
3185         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP);
3186         return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter,
3187                                                 rx_queue);
3188 }
3189
3190 int
3191 rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
3192                         struct rte_flex_filter *filter, uint16_t rx_queue)
3193 {
3194         struct rte_eth_dev *dev;
3195
3196         if (port_id >= nb_ports) {
3197                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3198                 return -ENODEV;
3199         }
3200
3201         dev = &rte_eth_devices[port_id];
3202         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP);
3203         return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue);
3204 }
3205
3206 int
3207 rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
3208 {
3209         struct rte_eth_dev *dev;
3210
3211         if (port_id >= nb_ports) {
3212                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3213                 return -ENODEV;
3214         }
3215
3216         dev = &rte_eth_devices[port_id];
3217         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP);
3218         return (*dev->dev_ops->remove_flex_filter)(dev, index);
3219 }
3220
3221 int
3222 rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
3223                         struct rte_flex_filter *filter, uint16_t *rx_queue)
3224 {
3225         struct rte_eth_dev *dev;
3226
3227         if (filter == NULL || rx_queue == NULL)
3228                 return -EINVAL;
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->get_flex_filter, -ENOTSUP);
3237         return (*dev->dev_ops->get_flex_filter)(dev, index, filter,
3238                                                 rx_queue);
3239 }
3240
3241 int
3242 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3243 {
3244         struct rte_eth_dev *dev;
3245
3246         if (port_id >= nb_ports) {
3247                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3248                 return -ENODEV;
3249         }
3250
3251         dev = &rte_eth_devices[port_id];
3252         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3253         return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3254                                 RTE_ETH_FILTER_NOP, NULL);
3255 }
3256
3257 int
3258 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3259                        enum rte_filter_op filter_op, void *arg)
3260 {
3261         struct rte_eth_dev *dev;
3262
3263         if (port_id >= nb_ports) {
3264                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3265                 return -ENODEV;
3266         }
3267
3268         dev = &rte_eth_devices[port_id];
3269         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3270         return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3271 }