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