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