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