ethdev: remove old ethertype filter
[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         return 0;
915 }
916
917 void
918 rte_eth_dev_stop(uint8_t port_id)
919 {
920         struct rte_eth_dev *dev;
921
922         /* This function is only safe when called from the primary process
923          * in a multi-process setup*/
924         PROC_PRIMARY_OR_RET();
925
926         if (port_id >= nb_ports) {
927                 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
928                 return;
929         }
930         dev = &rte_eth_devices[port_id];
931
932         FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
933
934         if (dev->data->dev_started == 0) {
935                 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
936                         " already stopped\n",
937                         port_id);
938                 return;
939         }
940
941         dev->data->dev_started = 0;
942         (*dev->dev_ops->dev_stop)(dev);
943 }
944
945 int
946 rte_eth_dev_set_link_up(uint8_t port_id)
947 {
948         struct rte_eth_dev *dev;
949
950         /* This function is only safe when called from the primary process
951          * in a multi-process setup*/
952         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
953
954         if (port_id >= nb_ports) {
955                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
956                 return -EINVAL;
957         }
958         dev = &rte_eth_devices[port_id];
959
960         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
961         return (*dev->dev_ops->dev_set_link_up)(dev);
962 }
963
964 int
965 rte_eth_dev_set_link_down(uint8_t port_id)
966 {
967         struct rte_eth_dev *dev;
968
969         /* This function is only safe when called from the primary process
970          * in a multi-process setup*/
971         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
972
973         if (port_id >= nb_ports) {
974                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
975                 return -EINVAL;
976         }
977         dev = &rte_eth_devices[port_id];
978
979         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
980         return (*dev->dev_ops->dev_set_link_down)(dev);
981 }
982
983 void
984 rte_eth_dev_close(uint8_t port_id)
985 {
986         struct rte_eth_dev *dev;
987
988         /* This function is only safe when called from the primary process
989          * in a multi-process setup*/
990         PROC_PRIMARY_OR_RET();
991
992         if (port_id >= nb_ports) {
993                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
994                 return;
995         }
996
997         dev = &rte_eth_devices[port_id];
998
999         FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1000         dev->data->dev_started = 0;
1001         (*dev->dev_ops->dev_close)(dev);
1002 }
1003
1004 int
1005 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1006                        uint16_t nb_rx_desc, unsigned int socket_id,
1007                        const struct rte_eth_rxconf *rx_conf,
1008                        struct rte_mempool *mp)
1009 {
1010         int ret;
1011         uint32_t mbp_buf_size;
1012         struct rte_eth_dev *dev;
1013         struct rte_pktmbuf_pool_private *mbp_priv;
1014         struct rte_eth_dev_info dev_info;
1015
1016         /* This function is only safe when called from the primary process
1017          * in a multi-process setup*/
1018         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1019
1020         if (port_id >= nb_ports) {
1021                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1022                 return (-EINVAL);
1023         }
1024         dev = &rte_eth_devices[port_id];
1025         if (rx_queue_id >= dev->data->nb_rx_queues) {
1026                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1027                 return (-EINVAL);
1028         }
1029
1030         if (dev->data->dev_started) {
1031                 PMD_DEBUG_TRACE(
1032                     "port %d must be stopped to allow configuration\n", port_id);
1033                 return -EBUSY;
1034         }
1035
1036         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1037         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1038
1039         /*
1040          * Check the size of the mbuf data buffer.
1041          * This value must be provided in the private data of the memory pool.
1042          * First check that the memory pool has a valid private data.
1043          */
1044         rte_eth_dev_info_get(port_id, &dev_info);
1045         if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1046                 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1047                                 mp->name, (int) mp->private_data_size,
1048                                 (int) sizeof(struct rte_pktmbuf_pool_private));
1049                 return (-ENOSPC);
1050         }
1051         mbp_priv = rte_mempool_get_priv(mp);
1052         mbp_buf_size = mbp_priv->mbuf_data_room_size;
1053
1054         if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1055                 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1056                                 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1057                                 "=%d)\n",
1058                                 mp->name,
1059                                 (int)mbp_buf_size,
1060                                 (int)(RTE_PKTMBUF_HEADROOM +
1061                                       dev_info.min_rx_bufsize),
1062                                 (int)RTE_PKTMBUF_HEADROOM,
1063                                 (int)dev_info.min_rx_bufsize);
1064                 return (-EINVAL);
1065         }
1066
1067         if (rx_conf == NULL)
1068                 rx_conf = &dev_info.default_rxconf;
1069
1070         ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1071                                               socket_id, rx_conf, mp);
1072         if (!ret) {
1073                 if (!dev->data->min_rx_buf_size ||
1074                     dev->data->min_rx_buf_size > mbp_buf_size)
1075                         dev->data->min_rx_buf_size = mbp_buf_size;
1076         }
1077
1078         return ret;
1079 }
1080
1081 int
1082 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1083                        uint16_t nb_tx_desc, unsigned int socket_id,
1084                        const struct rte_eth_txconf *tx_conf)
1085 {
1086         struct rte_eth_dev *dev;
1087         struct rte_eth_dev_info dev_info;
1088
1089         /* This function is only safe when called from the primary process
1090          * in a multi-process setup*/
1091         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1092
1093         if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1094                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1095                 return (-EINVAL);
1096         }
1097         dev = &rte_eth_devices[port_id];
1098         if (tx_queue_id >= dev->data->nb_tx_queues) {
1099                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1100                 return (-EINVAL);
1101         }
1102
1103         if (dev->data->dev_started) {
1104                 PMD_DEBUG_TRACE(
1105                     "port %d must be stopped to allow configuration\n", port_id);
1106                 return -EBUSY;
1107         }
1108
1109         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1110         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1111
1112         rte_eth_dev_info_get(port_id, &dev_info);
1113
1114         if (tx_conf == NULL)
1115                 tx_conf = &dev_info.default_txconf;
1116
1117         return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1118                                                socket_id, tx_conf);
1119 }
1120
1121 void
1122 rte_eth_promiscuous_enable(uint8_t port_id)
1123 {
1124         struct rte_eth_dev *dev;
1125
1126         if (port_id >= nb_ports) {
1127                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1128                 return;
1129         }
1130         dev = &rte_eth_devices[port_id];
1131
1132         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1133         (*dev->dev_ops->promiscuous_enable)(dev);
1134         dev->data->promiscuous = 1;
1135 }
1136
1137 void
1138 rte_eth_promiscuous_disable(uint8_t port_id)
1139 {
1140         struct rte_eth_dev *dev;
1141
1142         if (port_id >= nb_ports) {
1143                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1144                 return;
1145         }
1146         dev = &rte_eth_devices[port_id];
1147
1148         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1149         dev->data->promiscuous = 0;
1150         (*dev->dev_ops->promiscuous_disable)(dev);
1151 }
1152
1153 int
1154 rte_eth_promiscuous_get(uint8_t port_id)
1155 {
1156         struct rte_eth_dev *dev;
1157
1158         if (port_id >= nb_ports) {
1159                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1160                 return -1;
1161         }
1162
1163         dev = &rte_eth_devices[port_id];
1164         return dev->data->promiscuous;
1165 }
1166
1167 void
1168 rte_eth_allmulticast_enable(uint8_t port_id)
1169 {
1170         struct rte_eth_dev *dev;
1171
1172         if (port_id >= nb_ports) {
1173                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1174                 return;
1175         }
1176         dev = &rte_eth_devices[port_id];
1177
1178         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1179         (*dev->dev_ops->allmulticast_enable)(dev);
1180         dev->data->all_multicast = 1;
1181 }
1182
1183 void
1184 rte_eth_allmulticast_disable(uint8_t port_id)
1185 {
1186         struct rte_eth_dev *dev;
1187
1188         if (port_id >= nb_ports) {
1189                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1190                 return;
1191         }
1192         dev = &rte_eth_devices[port_id];
1193
1194         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1195         dev->data->all_multicast = 0;
1196         (*dev->dev_ops->allmulticast_disable)(dev);
1197 }
1198
1199 int
1200 rte_eth_allmulticast_get(uint8_t port_id)
1201 {
1202         struct rte_eth_dev *dev;
1203
1204         if (port_id >= nb_ports) {
1205                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1206                 return -1;
1207         }
1208
1209         dev = &rte_eth_devices[port_id];
1210         return dev->data->all_multicast;
1211 }
1212
1213 static inline int
1214 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1215                                 struct rte_eth_link *link)
1216 {
1217         struct rte_eth_link *dst = link;
1218         struct rte_eth_link *src = &(dev->data->dev_link);
1219
1220         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1221                                         *(uint64_t *)src) == 0)
1222                 return -1;
1223
1224         return 0;
1225 }
1226
1227 void
1228 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1229 {
1230         struct rte_eth_dev *dev;
1231
1232         if (port_id >= nb_ports) {
1233                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1234                 return;
1235         }
1236         dev = &rte_eth_devices[port_id];
1237
1238         if (dev->data->dev_conf.intr_conf.lsc != 0)
1239                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1240         else {
1241                 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1242                 (*dev->dev_ops->link_update)(dev, 1);
1243                 *eth_link = dev->data->dev_link;
1244         }
1245 }
1246
1247 void
1248 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1249 {
1250         struct rte_eth_dev *dev;
1251
1252         if (port_id >= nb_ports) {
1253                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1254                 return;
1255         }
1256         dev = &rte_eth_devices[port_id];
1257
1258         if (dev->data->dev_conf.intr_conf.lsc != 0)
1259                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1260         else {
1261                 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1262                 (*dev->dev_ops->link_update)(dev, 0);
1263                 *eth_link = dev->data->dev_link;
1264         }
1265 }
1266
1267 void
1268 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1269 {
1270         struct rte_eth_dev *dev;
1271
1272         if (port_id >= nb_ports) {
1273                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1274                 return;
1275         }
1276         dev = &rte_eth_devices[port_id];
1277         memset(stats, 0, sizeof(*stats));
1278
1279         FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1280         (*dev->dev_ops->stats_get)(dev, stats);
1281         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1282 }
1283
1284 void
1285 rte_eth_stats_reset(uint8_t port_id)
1286 {
1287         struct rte_eth_dev *dev;
1288
1289         if (port_id >= nb_ports) {
1290                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1291                 return;
1292         }
1293         dev = &rte_eth_devices[port_id];
1294
1295         FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1296         (*dev->dev_ops->stats_reset)(dev);
1297 }
1298
1299 /* retrieve ethdev extended statistics */
1300 int
1301 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1302         unsigned n)
1303 {
1304         struct rte_eth_stats eth_stats;
1305         struct rte_eth_dev *dev;
1306         unsigned count, i, q;
1307         uint64_t val;
1308         char *stats_ptr;
1309
1310         if (port_id >= nb_ports) {
1311                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1312                 return -1;
1313         }
1314         dev = &rte_eth_devices[port_id];
1315
1316         /* implemented by the driver */
1317         if (dev->dev_ops->xstats_get != NULL)
1318                 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1319
1320         /* else, return generic statistics */
1321         count = RTE_NB_STATS;
1322         count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1323         count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1324         if (n < count)
1325                 return count;
1326
1327         /* now fill the xstats structure */
1328
1329         count = 0;
1330         memset(&eth_stats, 0, sizeof(eth_stats));
1331         rte_eth_stats_get(port_id, &eth_stats);
1332
1333         /* global stats */
1334         for (i = 0; i < RTE_NB_STATS; i++) {
1335                 stats_ptr = (char *)&eth_stats + rte_stats_strings[i].offset;
1336                 val = *(uint64_t *)stats_ptr;
1337                 snprintf(xstats[count].name, sizeof(xstats[count].name),
1338                         "%s", rte_stats_strings[i].name);
1339                 xstats[count++].value = val;
1340         }
1341
1342         /* per-rxq stats */
1343         for (q = 0; q < dev->data->nb_rx_queues; q++) {
1344                 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1345                         stats_ptr = (char *)&eth_stats;
1346                         stats_ptr += rte_rxq_stats_strings[i].offset;
1347                         stats_ptr += q * sizeof(uint64_t);
1348                         val = *(uint64_t *)stats_ptr;
1349                         snprintf(xstats[count].name, sizeof(xstats[count].name),
1350                                 "rx_queue_%u_%s", q,
1351                                 rte_rxq_stats_strings[i].name);
1352                         xstats[count++].value = val;
1353                 }
1354         }
1355
1356         /* per-txq stats */
1357         for (q = 0; q < dev->data->nb_tx_queues; q++) {
1358                 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1359                         stats_ptr = (char *)&eth_stats;
1360                         stats_ptr += rte_txq_stats_strings[i].offset;
1361                         stats_ptr += q * sizeof(uint64_t);
1362                         val = *(uint64_t *)stats_ptr;
1363                         snprintf(xstats[count].name, sizeof(xstats[count].name),
1364                                 "tx_queue_%u_%s", q,
1365                                 rte_txq_stats_strings[i].name);
1366                         xstats[count++].value = val;
1367                 }
1368         }
1369
1370         return count;
1371 }
1372
1373 /* reset ethdev extended statistics */
1374 void
1375 rte_eth_xstats_reset(uint8_t port_id)
1376 {
1377         struct rte_eth_dev *dev;
1378
1379         if (port_id >= nb_ports) {
1380                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1381                 return;
1382         }
1383         dev = &rte_eth_devices[port_id];
1384
1385         /* implemented by the driver */
1386         if (dev->dev_ops->xstats_reset != NULL) {
1387                 (*dev->dev_ops->xstats_reset)(dev);
1388                 return;
1389         }
1390
1391         /* fallback to default */
1392         rte_eth_stats_reset(port_id);
1393 }
1394
1395 static int
1396 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1397                 uint8_t is_rx)
1398 {
1399         struct rte_eth_dev *dev;
1400
1401         if (port_id >= nb_ports) {
1402                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1403                 return -ENODEV;
1404         }
1405         dev = &rte_eth_devices[port_id];
1406
1407         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1408         return (*dev->dev_ops->queue_stats_mapping_set)
1409                         (dev, queue_id, stat_idx, is_rx);
1410 }
1411
1412
1413 int
1414 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1415                 uint8_t stat_idx)
1416 {
1417         return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1418                         STAT_QMAP_TX);
1419 }
1420
1421
1422 int
1423 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1424                 uint8_t stat_idx)
1425 {
1426         return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1427                         STAT_QMAP_RX);
1428 }
1429
1430
1431 void
1432 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1433 {
1434         struct rte_eth_dev *dev;
1435
1436         if (port_id >= nb_ports) {
1437                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1438                 return;
1439         }
1440         dev = &rte_eth_devices[port_id];
1441
1442         memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1443
1444         FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1445         (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1446         dev_info->pci_dev = dev->pci_dev;
1447         if (dev->driver)
1448                 dev_info->driver_name = dev->driver->pci_drv.name;
1449 }
1450
1451 void
1452 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1453 {
1454         struct rte_eth_dev *dev;
1455
1456         if (port_id >= nb_ports) {
1457                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1458                 return;
1459         }
1460         dev = &rte_eth_devices[port_id];
1461         ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1462 }
1463
1464
1465 int
1466 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1467 {
1468         struct rte_eth_dev *dev;
1469
1470         if (port_id >= nb_ports) {
1471                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1472                 return (-ENODEV);
1473         }
1474
1475         dev = &rte_eth_devices[port_id];
1476         *mtu = dev->data->mtu;
1477         return 0;
1478 }
1479
1480 int
1481 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1482 {
1483         int ret;
1484         struct rte_eth_dev *dev;
1485
1486         if (port_id >= nb_ports) {
1487                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1488                 return (-ENODEV);
1489         }
1490
1491         dev = &rte_eth_devices[port_id];
1492         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1493
1494         ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1495         if (!ret)
1496                 dev->data->mtu = mtu;
1497
1498         return ret;
1499 }
1500
1501 int
1502 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1503 {
1504         struct rte_eth_dev *dev;
1505
1506         if (port_id >= nb_ports) {
1507                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1508                 return (-ENODEV);
1509         }
1510         dev = &rte_eth_devices[port_id];
1511         if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1512                 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1513                 return (-ENOSYS);
1514         }
1515
1516         if (vlan_id > 4095) {
1517                 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1518                                 port_id, (unsigned) vlan_id);
1519                 return (-EINVAL);
1520         }
1521         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1522         (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1523         return (0);
1524 }
1525
1526 int
1527 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1528 {
1529         struct rte_eth_dev *dev;
1530
1531         if (port_id >= nb_ports) {
1532                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1533                 return (-ENODEV);
1534         }
1535
1536         dev = &rte_eth_devices[port_id];
1537         if (rx_queue_id >= dev->data->nb_rx_queues) {
1538                 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1539                 return (-EINVAL);
1540         }
1541
1542         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1543         (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1544
1545         return (0);
1546 }
1547
1548 int
1549 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1550 {
1551         struct rte_eth_dev *dev;
1552
1553         if (port_id >= nb_ports) {
1554                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1555                 return (-ENODEV);
1556         }
1557
1558         dev = &rte_eth_devices[port_id];
1559         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1560         (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1561
1562         return (0);
1563 }
1564
1565 int
1566 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1567 {
1568         struct rte_eth_dev *dev;
1569         int ret = 0;
1570         int mask = 0;
1571         int cur, org = 0;
1572
1573         if (port_id >= nb_ports) {
1574                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1575                 return (-ENODEV);
1576         }
1577
1578         dev = &rte_eth_devices[port_id];
1579
1580         /*check which option changed by application*/
1581         cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1582         org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1583         if (cur != org){
1584                 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1585                 mask |= ETH_VLAN_STRIP_MASK;
1586         }
1587
1588         cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1589         org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1590         if (cur != org){
1591                 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1592                 mask |= ETH_VLAN_FILTER_MASK;
1593         }
1594
1595         cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1596         org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1597         if (cur != org){
1598                 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1599                 mask |= ETH_VLAN_EXTEND_MASK;
1600         }
1601
1602         /*no change*/
1603         if(mask == 0)
1604                 return ret;
1605
1606         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1607         (*dev->dev_ops->vlan_offload_set)(dev, mask);
1608
1609         return ret;
1610 }
1611
1612 int
1613 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1614 {
1615         struct rte_eth_dev *dev;
1616         int ret = 0;
1617
1618         if (port_id >= nb_ports) {
1619                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1620                 return (-ENODEV);
1621         }
1622
1623         dev = &rte_eth_devices[port_id];
1624
1625         if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1626                 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1627
1628         if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1629                 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1630
1631         if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1632                 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1633
1634         return ret;
1635 }
1636
1637 int
1638 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1639 {
1640         struct rte_eth_dev *dev;
1641
1642         if (port_id >= nb_ports) {
1643                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1644                 return (-ENODEV);
1645         }
1646         dev = &rte_eth_devices[port_id];
1647         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1648         (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1649
1650         return 0;
1651 }
1652
1653 int
1654 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1655                                       struct rte_fdir_filter *fdir_filter,
1656                                       uint8_t queue)
1657 {
1658         struct rte_eth_dev *dev;
1659
1660         if (port_id >= nb_ports) {
1661                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1662                 return (-ENODEV);
1663         }
1664
1665         dev = &rte_eth_devices[port_id];
1666
1667         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1668                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1669                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1670                 return (-ENOSYS);
1671         }
1672
1673         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1674              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1675             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1676                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1677                                 "None l4type, source & destinations ports " \
1678                                 "should be null!\n");
1679                 return (-EINVAL);
1680         }
1681
1682         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1683         return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1684                                                                 queue);
1685 }
1686
1687 int
1688 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1689                                          struct rte_fdir_filter *fdir_filter,
1690                                          uint8_t queue)
1691 {
1692         struct rte_eth_dev *dev;
1693
1694         if (port_id >= nb_ports) {
1695                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1696                 return (-ENODEV);
1697         }
1698
1699         dev = &rte_eth_devices[port_id];
1700
1701         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1702                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1703                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1704                 return (-ENOSYS);
1705         }
1706
1707         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1708              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1709             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1710                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1711                                 "None l4type, source & destinations ports " \
1712                                 "should be null!\n");
1713                 return (-EINVAL);
1714         }
1715
1716         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1717         return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1718                                                                 queue);
1719
1720 }
1721
1722 int
1723 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1724                                          struct rte_fdir_filter *fdir_filter)
1725 {
1726         struct rte_eth_dev *dev;
1727
1728         if (port_id >= nb_ports) {
1729                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1730                 return (-ENODEV);
1731         }
1732
1733         dev = &rte_eth_devices[port_id];
1734
1735         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1736                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1737                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1738                 return (-ENOSYS);
1739         }
1740
1741         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1742              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1743             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1744                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1745                                 "None l4type source & destinations ports " \
1746                                 "should be null!\n");
1747                 return (-EINVAL);
1748         }
1749
1750         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1751         return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1752 }
1753
1754 int
1755 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1756 {
1757         struct rte_eth_dev *dev;
1758
1759         if (port_id >= nb_ports) {
1760                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1761                 return (-ENODEV);
1762         }
1763
1764         dev = &rte_eth_devices[port_id];
1765         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1766                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1767                 return (-ENOSYS);
1768         }
1769
1770         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1771
1772         (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1773         return (0);
1774 }
1775
1776 int
1777 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1778                                     struct rte_fdir_filter *fdir_filter,
1779                                     uint16_t soft_id, uint8_t queue,
1780                                     uint8_t drop)
1781 {
1782         struct rte_eth_dev *dev;
1783
1784         if (port_id >= nb_ports) {
1785                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1786                 return (-ENODEV);
1787         }
1788
1789         dev = &rte_eth_devices[port_id];
1790
1791         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1792                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1793                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1794                 return (-ENOSYS);
1795         }
1796
1797         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1798              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1799             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1800                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1801                                 "None l4type, source & destinations ports " \
1802                                 "should be null!\n");
1803                 return (-EINVAL);
1804         }
1805
1806         /* For now IPv6 is not supported with perfect filter */
1807         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1808                 return (-ENOTSUP);
1809
1810         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1811         return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1812                                                                 soft_id, queue,
1813                                                                 drop);
1814 }
1815
1816 int
1817 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1818                                        struct rte_fdir_filter *fdir_filter,
1819                                        uint16_t soft_id, uint8_t queue,
1820                                        uint8_t drop)
1821 {
1822         struct rte_eth_dev *dev;
1823
1824         if (port_id >= nb_ports) {
1825                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1826                 return (-ENODEV);
1827         }
1828
1829         dev = &rte_eth_devices[port_id];
1830
1831         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1832                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1833                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1834                 return (-ENOSYS);
1835         }
1836
1837         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1838              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1839             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1840                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1841                                 "None l4type, source & destinations ports " \
1842                                 "should be null!\n");
1843                 return (-EINVAL);
1844         }
1845
1846         /* For now IPv6 is not supported with perfect filter */
1847         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1848                 return (-ENOTSUP);
1849
1850         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1851         return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1852                                                         soft_id, queue, drop);
1853 }
1854
1855 int
1856 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1857                                        struct rte_fdir_filter *fdir_filter,
1858                                        uint16_t soft_id)
1859 {
1860         struct rte_eth_dev *dev;
1861
1862         if (port_id >= nb_ports) {
1863                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1864                 return (-ENODEV);
1865         }
1866
1867         dev = &rte_eth_devices[port_id];
1868
1869         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1870                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1871                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1872                 return (-ENOSYS);
1873         }
1874
1875         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1876              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1877             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1878                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1879                                 "None l4type, source & destinations ports " \
1880                                 "should be null!\n");
1881                 return (-EINVAL);
1882         }
1883
1884         /* For now IPv6 is not supported with perfect filter */
1885         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1886                 return (-ENOTSUP);
1887
1888         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1889         return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1890                                                                 soft_id);
1891 }
1892
1893 int
1894 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1895 {
1896         struct rte_eth_dev *dev;
1897
1898         if (port_id >= nb_ports) {
1899                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1900                 return (-ENODEV);
1901         }
1902
1903         dev = &rte_eth_devices[port_id];
1904         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1905                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1906                 return (-ENOSYS);
1907         }
1908
1909         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1910         return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1911 }
1912
1913 int
1914 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1915 {
1916         struct rte_eth_dev *dev;
1917
1918         if (port_id >= nb_ports) {
1919                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1920                 return (-ENODEV);
1921         }
1922
1923         dev = &rte_eth_devices[port_id];
1924         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1925         memset(fc_conf, 0, sizeof(*fc_conf));
1926         return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1927 }
1928
1929 int
1930 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1931 {
1932         struct rte_eth_dev *dev;
1933
1934         if (port_id >= nb_ports) {
1935                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1936                 return (-ENODEV);
1937         }
1938
1939         if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1940                 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1941                 return (-EINVAL);
1942         }
1943
1944         dev = &rte_eth_devices[port_id];
1945         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1946         return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1947 }
1948
1949 int
1950 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1951 {
1952         struct rte_eth_dev *dev;
1953
1954         if (port_id >= nb_ports) {
1955                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1956                 return (-ENODEV);
1957         }
1958
1959         if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1960                 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1961                 return (-EINVAL);
1962         }
1963
1964         dev = &rte_eth_devices[port_id];
1965         /* High water, low water validation are device specific */
1966         if  (*dev->dev_ops->priority_flow_ctrl_set)
1967                 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1968         return (-ENOTSUP);
1969 }
1970
1971 static inline int
1972 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1973                         uint16_t reta_size)
1974 {
1975         uint16_t i, num;
1976
1977         if (!reta_conf)
1978                 return -EINVAL;
1979
1980         if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1981                 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1982                                                         RTE_RETA_GROUP_SIZE);
1983                 return -EINVAL;
1984         }
1985
1986         num = reta_size / RTE_RETA_GROUP_SIZE;
1987         for (i = 0; i < num; i++) {
1988                 if (reta_conf[i].mask)
1989                         return 0;
1990         }
1991
1992         return -EINVAL;
1993 }
1994
1995 static inline int
1996 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1997                          uint16_t reta_size,
1998                          uint8_t max_rxq)
1999 {
2000         uint16_t i, idx, shift;
2001
2002         if (!reta_conf)
2003                 return -EINVAL;
2004
2005         if (max_rxq == 0) {
2006                 PMD_DEBUG_TRACE("No receive queue is available\n");
2007                 return -EINVAL;
2008         }
2009
2010         for (i = 0; i < reta_size; i++) {
2011                 idx = i / RTE_RETA_GROUP_SIZE;
2012                 shift = i % RTE_RETA_GROUP_SIZE;
2013                 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2014                         (reta_conf[idx].reta[shift] >= max_rxq)) {
2015                         PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2016                                 "the maximum rxq index: %u\n", idx, shift,
2017                                 reta_conf[idx].reta[shift], max_rxq);
2018                         return -EINVAL;
2019                 }
2020         }
2021
2022         return 0;
2023 }
2024
2025 int
2026 rte_eth_dev_rss_reta_update(uint8_t port_id,
2027                             struct rte_eth_rss_reta_entry64 *reta_conf,
2028                             uint16_t reta_size)
2029 {
2030         struct rte_eth_dev *dev;
2031         int ret;
2032
2033         if (port_id >= nb_ports) {
2034                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2035                 return -ENODEV;
2036         }
2037
2038         /* Check mask bits */
2039         ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2040         if (ret < 0)
2041                 return ret;
2042
2043         dev = &rte_eth_devices[port_id];
2044
2045         /* Check entry value */
2046         ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2047                                 dev->data->nb_rx_queues);
2048         if (ret < 0)
2049                 return ret;
2050
2051         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2052         return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2053 }
2054
2055 int
2056 rte_eth_dev_rss_reta_query(uint8_t port_id,
2057                            struct rte_eth_rss_reta_entry64 *reta_conf,
2058                            uint16_t reta_size)
2059 {
2060         struct rte_eth_dev *dev;
2061         int ret;
2062
2063         if (port_id >= nb_ports) {
2064                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2065                 return -ENODEV;
2066         }
2067
2068         /* Check mask bits */
2069         ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2070         if (ret < 0)
2071                 return ret;
2072
2073         dev = &rte_eth_devices[port_id];
2074         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2075         return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2076 }
2077
2078 int
2079 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2080 {
2081         struct rte_eth_dev *dev;
2082         uint16_t rss_hash_protos;
2083
2084         if (port_id >= nb_ports) {
2085                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2086                 return (-ENODEV);
2087         }
2088         rss_hash_protos = rss_conf->rss_hf;
2089         if ((rss_hash_protos != 0) &&
2090             ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2091                 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2092                                 rss_hash_protos);
2093                 return (-EINVAL);
2094         }
2095         dev = &rte_eth_devices[port_id];
2096         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2097         return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2098 }
2099
2100 int
2101 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2102                               struct rte_eth_rss_conf *rss_conf)
2103 {
2104         struct rte_eth_dev *dev;
2105
2106         if (port_id >= nb_ports) {
2107                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2108                 return (-ENODEV);
2109         }
2110         dev = &rte_eth_devices[port_id];
2111         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2112         return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2113 }
2114
2115 int
2116 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2117                            struct rte_eth_udp_tunnel *udp_tunnel)
2118 {
2119         struct rte_eth_dev *dev;
2120
2121         if (port_id >= nb_ports) {
2122                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2123                 return -ENODEV;
2124         }
2125
2126         if (udp_tunnel == NULL) {
2127                 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2128                 return -EINVAL;
2129         }
2130
2131         if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2132                 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2133                 return -EINVAL;
2134         }
2135
2136         dev = &rte_eth_devices[port_id];
2137         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2138         return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2139 }
2140
2141 int
2142 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2143                               struct rte_eth_udp_tunnel *udp_tunnel)
2144 {
2145         struct rte_eth_dev *dev;
2146
2147         if (port_id >= nb_ports) {
2148                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2149                 return -ENODEV;
2150         }
2151         dev = &rte_eth_devices[port_id];
2152
2153         if (udp_tunnel == NULL) {
2154                 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2155                 return -EINVAL;
2156         }
2157
2158         if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2159                 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2160                 return -EINVAL;
2161         }
2162
2163         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2164         return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2165 }
2166
2167 int
2168 rte_eth_led_on(uint8_t port_id)
2169 {
2170         struct rte_eth_dev *dev;
2171
2172         if (port_id >= nb_ports) {
2173                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2174                 return (-ENODEV);
2175         }
2176
2177         dev = &rte_eth_devices[port_id];
2178         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2179         return ((*dev->dev_ops->dev_led_on)(dev));
2180 }
2181
2182 int
2183 rte_eth_led_off(uint8_t port_id)
2184 {
2185         struct rte_eth_dev *dev;
2186
2187         if (port_id >= nb_ports) {
2188                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2189                 return (-ENODEV);
2190         }
2191
2192         dev = &rte_eth_devices[port_id];
2193         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2194         return ((*dev->dev_ops->dev_led_off)(dev));
2195 }
2196
2197 /*
2198  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2199  * an empty spot.
2200  */
2201 static inline int
2202 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2203 {
2204         struct rte_eth_dev_info dev_info;
2205         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2206         unsigned i;
2207
2208         rte_eth_dev_info_get(port_id, &dev_info);
2209
2210         for (i = 0; i < dev_info.max_mac_addrs; i++)
2211                 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2212                         return i;
2213
2214         return -1;
2215 }
2216
2217 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2218
2219 int
2220 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2221                         uint32_t pool)
2222 {
2223         struct rte_eth_dev *dev;
2224         int index;
2225         uint64_t pool_mask;
2226
2227         if (port_id >= nb_ports) {
2228                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2229                 return (-ENODEV);
2230         }
2231         dev = &rte_eth_devices[port_id];
2232         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2233
2234         if (is_zero_ether_addr(addr)) {
2235                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2236                         port_id);
2237                 return (-EINVAL);
2238         }
2239         if (pool >= ETH_64_POOLS) {
2240                 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2241                 return (-EINVAL);
2242         }
2243
2244         index = get_mac_addr_index(port_id, addr);
2245         if (index < 0) {
2246                 index = get_mac_addr_index(port_id, &null_mac_addr);
2247                 if (index < 0) {
2248                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2249                                 port_id);
2250                         return (-ENOSPC);
2251                 }
2252         } else {
2253                 pool_mask = dev->data->mac_pool_sel[index];
2254
2255                 /* Check if both MAC address and pool is alread there, and do nothing */
2256                 if (pool_mask & (1ULL << pool))
2257                         return 0;
2258         }
2259
2260         /* Update NIC */
2261         (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2262
2263         /* Update address in NIC data structure */
2264         ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2265
2266         /* Update pool bitmap in NIC data structure */
2267         dev->data->mac_pool_sel[index] |= (1ULL << pool);
2268
2269         return 0;
2270 }
2271
2272 int
2273 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2274 {
2275         struct rte_eth_dev *dev;
2276         int index;
2277
2278         if (port_id >= nb_ports) {
2279                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2280                 return (-ENODEV);
2281         }
2282         dev = &rte_eth_devices[port_id];
2283         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2284
2285         index = get_mac_addr_index(port_id, addr);
2286         if (index == 0) {
2287                 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2288                 return (-EADDRINUSE);
2289         } else if (index < 0)
2290                 return 0;  /* Do nothing if address wasn't found */
2291
2292         /* Update NIC */
2293         (*dev->dev_ops->mac_addr_remove)(dev, index);
2294
2295         /* Update address in NIC data structure */
2296         ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2297
2298         /* reset pool bitmap */
2299         dev->data->mac_pool_sel[index] = 0;
2300
2301         return 0;
2302 }
2303
2304 int
2305 rte_eth_dev_set_vf_rxmode(uint8_t port_id,  uint16_t vf,
2306                                 uint16_t rx_mode, uint8_t on)
2307 {
2308         uint16_t num_vfs;
2309         struct rte_eth_dev *dev;
2310         struct rte_eth_dev_info dev_info;
2311
2312         if (port_id >= nb_ports) {
2313                 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2314                                 port_id);
2315                 return (-ENODEV);
2316         }
2317
2318         dev = &rte_eth_devices[port_id];
2319         rte_eth_dev_info_get(port_id, &dev_info);
2320
2321         num_vfs = dev_info.max_vfs;
2322         if (vf > num_vfs)
2323         {
2324                 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2325                 return (-EINVAL);
2326         }
2327         if (rx_mode == 0)
2328         {
2329                 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2330                 return (-EINVAL);
2331         }
2332         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2333         return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2334 }
2335
2336 /*
2337  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2338  * an empty spot.
2339  */
2340 static inline int
2341 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2342 {
2343         struct rte_eth_dev_info dev_info;
2344         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2345         unsigned i;
2346
2347         rte_eth_dev_info_get(port_id, &dev_info);
2348         if (!dev->data->hash_mac_addrs)
2349                 return -1;
2350
2351         for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2352                 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2353                         ETHER_ADDR_LEN) == 0)
2354                         return i;
2355
2356         return -1;
2357 }
2358
2359 int
2360 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2361                                 uint8_t on)
2362 {
2363         int index;
2364         int ret;
2365         struct rte_eth_dev *dev;
2366
2367         if (port_id >= nb_ports) {
2368                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2369                         port_id);
2370                 return (-ENODEV);
2371         }
2372
2373         dev = &rte_eth_devices[port_id];
2374         if (is_zero_ether_addr(addr)) {
2375                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2376                         port_id);
2377                 return (-EINVAL);
2378         }
2379
2380         index = get_hash_mac_addr_index(port_id, addr);
2381         /* Check if it's already there, and do nothing */
2382         if ((index >= 0) && (on))
2383                 return 0;
2384
2385         if (index < 0) {
2386                 if (!on) {
2387                         PMD_DEBUG_TRACE("port %d: the MAC address was not"
2388                                 "set in UTA\n", port_id);
2389                         return (-EINVAL);
2390                 }
2391
2392                 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2393                 if (index < 0) {
2394                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2395                                         port_id);
2396                         return (-ENOSPC);
2397                 }
2398         }
2399
2400         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2401         ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2402         if (ret == 0) {
2403                 /* Update address in NIC data structure */
2404                 if (on)
2405                         ether_addr_copy(addr,
2406                                         &dev->data->hash_mac_addrs[index]);
2407                 else
2408                         ether_addr_copy(&null_mac_addr,
2409                                         &dev->data->hash_mac_addrs[index]);
2410         }
2411
2412         return ret;
2413 }
2414
2415 int
2416 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2417 {
2418         struct rte_eth_dev *dev;
2419
2420         if (port_id >= nb_ports) {
2421                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2422                         port_id);
2423                 return (-ENODEV);
2424         }
2425
2426         dev = &rte_eth_devices[port_id];
2427
2428         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2429         return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2430 }
2431
2432 int
2433 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2434 {
2435         uint16_t num_vfs;
2436         struct rte_eth_dev *dev;
2437         struct rte_eth_dev_info dev_info;
2438
2439         if (port_id >= nb_ports) {
2440                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2441                 return (-ENODEV);
2442         }
2443
2444         dev = &rte_eth_devices[port_id];
2445         rte_eth_dev_info_get(port_id, &dev_info);
2446
2447         num_vfs = dev_info.max_vfs;
2448         if (vf > num_vfs)
2449         {
2450                 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2451                 return (-EINVAL);
2452         }
2453
2454         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2455         return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2456 }
2457
2458 int
2459 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2460 {
2461         uint16_t num_vfs;
2462         struct rte_eth_dev *dev;
2463         struct rte_eth_dev_info dev_info;
2464
2465         if (port_id >= nb_ports) {
2466                 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2467                 return (-ENODEV);
2468         }
2469
2470         dev = &rte_eth_devices[port_id];
2471         rte_eth_dev_info_get(port_id, &dev_info);
2472
2473         num_vfs = dev_info.max_vfs;
2474         if (vf > num_vfs)
2475         {
2476                 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2477                 return (-EINVAL);
2478         }
2479
2480         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2481         return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2482 }
2483
2484 int
2485 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2486                                  uint64_t vf_mask,uint8_t vlan_on)
2487 {
2488         struct rte_eth_dev *dev;
2489
2490         if (port_id >= nb_ports) {
2491                 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2492                                 port_id);
2493                 return (-ENODEV);
2494         }
2495         dev = &rte_eth_devices[port_id];
2496
2497         if(vlan_id > ETHER_MAX_VLAN_ID)
2498         {
2499                 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2500                         vlan_id);
2501                 return (-EINVAL);
2502         }
2503         if (vf_mask == 0)
2504         {
2505                 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2506                 return (-EINVAL);
2507         }
2508
2509         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2510         return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2511                                                 vf_mask,vlan_on);
2512 }
2513
2514 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2515                                         uint16_t tx_rate)
2516 {
2517         struct rte_eth_dev *dev;
2518         struct rte_eth_dev_info dev_info;
2519         struct rte_eth_link link;
2520
2521         if (port_id >= nb_ports) {
2522                 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2523                                 port_id);
2524                 return -ENODEV;
2525         }
2526
2527         dev = &rte_eth_devices[port_id];
2528         rte_eth_dev_info_get(port_id, &dev_info);
2529         link = dev->data->dev_link;
2530
2531         if (queue_idx > dev_info.max_tx_queues) {
2532                 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2533                                 "invalid queue id=%d\n", port_id, queue_idx);
2534                 return -EINVAL;
2535         }
2536
2537         if (tx_rate > link.link_speed) {
2538                 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2539                                 "bigger than link speed= %d\n",
2540                         tx_rate, link.link_speed);
2541                 return -EINVAL;
2542         }
2543
2544         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2545         return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2546 }
2547
2548 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2549                                 uint64_t q_msk)
2550 {
2551         struct rte_eth_dev *dev;
2552         struct rte_eth_dev_info dev_info;
2553         struct rte_eth_link link;
2554
2555         if (q_msk == 0)
2556                 return 0;
2557
2558         if (port_id >= nb_ports) {
2559                 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2560                                 port_id);
2561                 return -ENODEV;
2562         }
2563
2564         dev = &rte_eth_devices[port_id];
2565         rte_eth_dev_info_get(port_id, &dev_info);
2566         link = dev->data->dev_link;
2567
2568         if (vf > dev_info.max_vfs) {
2569                 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2570                                 "invalid vf id=%d\n", port_id, vf);
2571                 return -EINVAL;
2572         }
2573
2574         if (tx_rate > link.link_speed) {
2575                 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2576                                 "bigger than link speed= %d\n",
2577                                 tx_rate, link.link_speed);
2578                 return -EINVAL;
2579         }
2580
2581         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2582         return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2583 }
2584
2585 int
2586 rte_eth_mirror_rule_set(uint8_t port_id,
2587                         struct rte_eth_vmdq_mirror_conf *mirror_conf,
2588                         uint8_t rule_id, uint8_t on)
2589 {
2590         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2591
2592         if (port_id >= nb_ports) {
2593                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2594                 return (-ENODEV);
2595         }
2596
2597         if (mirror_conf->rule_type_mask == 0) {
2598                 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2599                 return (-EINVAL);
2600         }
2601
2602         if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2603                 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2604                         "be 0-%d\n",ETH_64_POOLS - 1);
2605                 return (-EINVAL);
2606         }
2607
2608         if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2609                 (mirror_conf->pool_mask == 0)) {
2610                 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2611                                 "be 0.\n");
2612                 return (-EINVAL);
2613         }
2614
2615         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2616         {
2617                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2618                         ETH_VMDQ_NUM_MIRROR_RULE - 1);
2619                 return (-EINVAL);
2620         }
2621
2622         dev = &rte_eth_devices[port_id];
2623         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2624
2625         return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2626 }
2627
2628 int
2629 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2630 {
2631         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2632
2633         if (port_id >= nb_ports) {
2634                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2635                 return (-ENODEV);
2636         }
2637
2638         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2639         {
2640                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2641                         ETH_VMDQ_NUM_MIRROR_RULE-1);
2642                 return (-EINVAL);
2643         }
2644
2645         dev = &rte_eth_devices[port_id];
2646         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2647
2648         return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2649 }
2650
2651 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2652 uint16_t
2653 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2654                  struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2655 {
2656         struct rte_eth_dev *dev;
2657
2658         if (port_id >= nb_ports) {
2659                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2660                 return 0;
2661         }
2662         dev = &rte_eth_devices[port_id];
2663         FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2664         if (queue_id >= dev->data->nb_rx_queues) {
2665                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2666                 return 0;
2667         }
2668         return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2669                                                 rx_pkts, nb_pkts);
2670 }
2671
2672 uint16_t
2673 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2674                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2675 {
2676         struct rte_eth_dev *dev;
2677
2678         if (port_id >= nb_ports) {
2679                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2680                 return 0;
2681         }
2682         dev = &rte_eth_devices[port_id];
2683
2684         FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2685         if (queue_id >= dev->data->nb_tx_queues) {
2686                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2687                 return 0;
2688         }
2689         return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2690                                                 tx_pkts, nb_pkts);
2691 }
2692
2693 uint32_t
2694 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2695 {
2696         struct rte_eth_dev *dev;
2697
2698         if (port_id >= nb_ports) {
2699                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2700                 return 0;
2701         }
2702         dev = &rte_eth_devices[port_id];
2703         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2704         return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2705 }
2706
2707 int
2708 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2709 {
2710         struct rte_eth_dev *dev;
2711
2712         if (port_id >= nb_ports) {
2713                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2714                 return (-ENODEV);
2715         }
2716         dev = &rte_eth_devices[port_id];
2717         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2718         return (*dev->dev_ops->rx_descriptor_done)( \
2719                 dev->data->rx_queues[queue_id], offset);
2720 }
2721 #endif
2722
2723 int
2724 rte_eth_dev_callback_register(uint8_t port_id,
2725                         enum rte_eth_event_type event,
2726                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2727 {
2728         struct rte_eth_dev *dev;
2729         struct rte_eth_dev_callback *user_cb;
2730
2731         if (!cb_fn)
2732                 return (-EINVAL);
2733         if (port_id >= nb_ports) {
2734                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2735                 return (-EINVAL);
2736         }
2737
2738         dev = &rte_eth_devices[port_id];
2739         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2740
2741         TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2742                 if (user_cb->cb_fn == cb_fn &&
2743                         user_cb->cb_arg == cb_arg &&
2744                         user_cb->event == event) {
2745                         break;
2746                 }
2747         }
2748
2749         /* create a new callback. */
2750         if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2751                         sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2752                 user_cb->cb_fn = cb_fn;
2753                 user_cb->cb_arg = cb_arg;
2754                 user_cb->event = event;
2755                 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2756         }
2757
2758         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2759         return ((user_cb == NULL) ? -ENOMEM : 0);
2760 }
2761
2762 int
2763 rte_eth_dev_callback_unregister(uint8_t port_id,
2764                         enum rte_eth_event_type event,
2765                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2766 {
2767         int ret;
2768         struct rte_eth_dev *dev;
2769         struct rte_eth_dev_callback *cb, *next;
2770
2771         if (!cb_fn)
2772                 return (-EINVAL);
2773         if (port_id >= nb_ports) {
2774                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2775                 return (-EINVAL);
2776         }
2777
2778         dev = &rte_eth_devices[port_id];
2779         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2780
2781         ret = 0;
2782         for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2783
2784                 next = TAILQ_NEXT(cb, next);
2785
2786                 if (cb->cb_fn != cb_fn || cb->event != event ||
2787                                 (cb->cb_arg != (void *)-1 &&
2788                                 cb->cb_arg != cb_arg))
2789                         continue;
2790
2791                 /*
2792                  * if this callback is not executing right now,
2793                  * then remove it.
2794                  */
2795                 if (cb->active == 0) {
2796                         TAILQ_REMOVE(&(dev->callbacks), cb, next);
2797                         rte_free(cb);
2798                 } else {
2799                         ret = -EAGAIN;
2800                 }
2801         }
2802
2803         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2804         return (ret);
2805 }
2806
2807 void
2808 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2809         enum rte_eth_event_type event)
2810 {
2811         struct rte_eth_dev_callback *cb_lst;
2812         struct rte_eth_dev_callback dev_cb;
2813
2814         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2815         TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2816                 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2817                         continue;
2818                 dev_cb = *cb_lst;
2819                 cb_lst->active = 1;
2820                 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2821                 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2822                                                 dev_cb.cb_arg);
2823                 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2824                 cb_lst->active = 0;
2825         }
2826         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2827 }
2828 #ifdef RTE_NIC_BYPASS
2829 int rte_eth_dev_bypass_init(uint8_t port_id)
2830 {
2831         struct rte_eth_dev *dev;
2832
2833         if (port_id >= nb_ports) {
2834                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2835                 return (-ENODEV);
2836         }
2837
2838         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2839                 PMD_DEBUG_TRACE("Invalid port device\n");
2840                 return (-ENODEV);
2841         }
2842
2843         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2844         (*dev->dev_ops->bypass_init)(dev);
2845         return 0;
2846 }
2847
2848 int
2849 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2850 {
2851         struct rte_eth_dev *dev;
2852
2853         if (port_id >= nb_ports) {
2854                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2855                 return (-ENODEV);
2856         }
2857
2858         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2859                 PMD_DEBUG_TRACE("Invalid port device\n");
2860                 return (-ENODEV);
2861         }
2862         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2863         (*dev->dev_ops->bypass_state_show)(dev, state);
2864         return 0;
2865 }
2866
2867 int
2868 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2869 {
2870         struct rte_eth_dev *dev;
2871
2872         if (port_id >= nb_ports) {
2873                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2874                 return (-ENODEV);
2875         }
2876
2877         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2878                 PMD_DEBUG_TRACE("Invalid port device\n");
2879                 return (-ENODEV);
2880         }
2881
2882         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2883         (*dev->dev_ops->bypass_state_set)(dev, new_state);
2884         return 0;
2885 }
2886
2887 int
2888 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2889 {
2890         struct rte_eth_dev *dev;
2891
2892         if (port_id >= nb_ports) {
2893                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2894                 return (-ENODEV);
2895         }
2896
2897         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2898                 PMD_DEBUG_TRACE("Invalid port device\n");
2899                 return (-ENODEV);
2900         }
2901
2902         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2903         (*dev->dev_ops->bypass_event_show)(dev, event, state);
2904         return 0;
2905 }
2906
2907 int
2908 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2909 {
2910         struct rte_eth_dev *dev;
2911
2912         if (port_id >= nb_ports) {
2913                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2914                 return (-ENODEV);
2915         }
2916
2917         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2918                 PMD_DEBUG_TRACE("Invalid port device\n");
2919                 return (-ENODEV);
2920         }
2921
2922         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2923         (*dev->dev_ops->bypass_event_set)(dev, event, state);
2924         return 0;
2925 }
2926
2927 int
2928 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2929 {
2930         struct rte_eth_dev *dev;
2931
2932         if (port_id >= nb_ports) {
2933                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2934                 return (-ENODEV);
2935         }
2936
2937         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2938                 PMD_DEBUG_TRACE("Invalid port device\n");
2939                 return (-ENODEV);
2940         }
2941
2942         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2943         (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2944         return 0;
2945 }
2946
2947 int
2948 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2949 {
2950         struct rte_eth_dev *dev;
2951
2952         if (port_id >= nb_ports) {
2953                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2954                 return (-ENODEV);
2955         }
2956
2957         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2958                 PMD_DEBUG_TRACE("Invalid port device\n");
2959                 return (-ENODEV);
2960         }
2961
2962         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2963         (*dev->dev_ops->bypass_ver_show)(dev, ver);
2964         return 0;
2965 }
2966
2967 int
2968 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2969 {
2970         struct rte_eth_dev *dev;
2971
2972         if (port_id >= nb_ports) {
2973                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2974                 return (-ENODEV);
2975         }
2976
2977         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2978                 PMD_DEBUG_TRACE("Invalid port device\n");
2979                 return (-ENODEV);
2980         }
2981
2982         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2983         (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2984         return 0;
2985 }
2986
2987 int
2988 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2989 {
2990         struct rte_eth_dev *dev;
2991
2992         if (port_id >= nb_ports) {
2993                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2994                 return (-ENODEV);
2995         }
2996
2997         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2998                 PMD_DEBUG_TRACE("Invalid port device\n");
2999                 return (-ENODEV);
3000         }
3001
3002         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3003         (*dev->dev_ops->bypass_wd_reset)(dev);
3004         return 0;
3005 }
3006 #endif
3007
3008 int
3009 rte_eth_dev_add_syn_filter(uint8_t port_id,
3010                         struct rte_syn_filter *filter, uint16_t rx_queue)
3011 {
3012         struct rte_eth_dev *dev;
3013
3014         if (port_id >= nb_ports) {
3015                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3016                 return -ENODEV;
3017         }
3018
3019         dev = &rte_eth_devices[port_id];
3020         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_syn_filter, -ENOTSUP);
3021         return (*dev->dev_ops->add_syn_filter)(dev, filter, rx_queue);
3022 }
3023
3024 int
3025 rte_eth_dev_remove_syn_filter(uint8_t port_id)
3026 {
3027         struct rte_eth_dev *dev;
3028
3029         if (port_id >= nb_ports) {
3030                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3031                 return -ENODEV;
3032         }
3033
3034         dev = &rte_eth_devices[port_id];
3035         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_syn_filter, -ENOTSUP);
3036         return (*dev->dev_ops->remove_syn_filter)(dev);
3037 }
3038
3039 int
3040 rte_eth_dev_get_syn_filter(uint8_t port_id,
3041                         struct rte_syn_filter *filter, uint16_t *rx_queue)
3042 {
3043         struct rte_eth_dev *dev;
3044
3045         if (filter == NULL || rx_queue == NULL)
3046                 return -EINVAL;
3047
3048         if (port_id >= nb_ports) {
3049                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3050                 return -ENODEV;
3051         }
3052
3053         dev = &rte_eth_devices[port_id];
3054         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_syn_filter, -ENOTSUP);
3055         return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue);
3056 }
3057
3058 int
3059 rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
3060                         struct rte_2tuple_filter *filter, uint16_t rx_queue)
3061 {
3062         struct rte_eth_dev *dev;
3063
3064         if (port_id >= nb_ports) {
3065                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3066                 return -ENODEV;
3067         }
3068         if (filter->protocol != IPPROTO_TCP &&
3069                 filter->tcp_flags != 0){
3070                 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3071                         " is not TCP\n",
3072                         filter->tcp_flags);
3073                 return -EINVAL;
3074         }
3075
3076         dev = &rte_eth_devices[port_id];
3077         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP);
3078         return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue);
3079 }
3080
3081 int
3082 rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
3083 {
3084         struct rte_eth_dev *dev;
3085
3086         if (port_id >= nb_ports) {
3087                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3088                 return -ENODEV;
3089         }
3090
3091         dev = &rte_eth_devices[port_id];
3092         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP);
3093         return (*dev->dev_ops->remove_2tuple_filter)(dev, index);
3094 }
3095
3096 int
3097 rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
3098                         struct rte_2tuple_filter *filter, uint16_t *rx_queue)
3099 {
3100         struct rte_eth_dev *dev;
3101
3102         if (filter == NULL || rx_queue == NULL)
3103                 return -EINVAL;
3104
3105         if (port_id >= nb_ports) {
3106                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3107                 return -ENODEV;
3108         }
3109
3110         dev = &rte_eth_devices[port_id];
3111         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP);
3112         return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue);
3113 }
3114
3115 int
3116 rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
3117                         struct rte_5tuple_filter *filter, uint16_t rx_queue)
3118 {
3119         struct rte_eth_dev *dev;
3120
3121         if (port_id >= nb_ports) {
3122                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3123                 return -ENODEV;
3124         }
3125
3126         if (filter->protocol != IPPROTO_TCP &&
3127                 filter->tcp_flags != 0){
3128                 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3129                         " is not TCP\n",
3130                         filter->tcp_flags);
3131                 return -EINVAL;
3132         }
3133
3134         dev = &rte_eth_devices[port_id];
3135         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP);
3136         return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue);
3137 }
3138
3139 int
3140 rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
3141 {
3142         struct rte_eth_dev *dev;
3143
3144         if (port_id >= nb_ports) {
3145                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3146                 return -ENODEV;
3147         }
3148
3149         dev = &rte_eth_devices[port_id];
3150         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP);
3151         return (*dev->dev_ops->remove_5tuple_filter)(dev, index);
3152 }
3153
3154 int
3155 rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
3156                         struct rte_5tuple_filter *filter, uint16_t *rx_queue)
3157 {
3158         struct rte_eth_dev *dev;
3159
3160         if (filter == NULL || rx_queue == NULL)
3161                 return -EINVAL;
3162
3163         if (port_id >= nb_ports) {
3164                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3165                 return -ENODEV;
3166         }
3167
3168         dev = &rte_eth_devices[port_id];
3169         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP);
3170         return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter,
3171                                                 rx_queue);
3172 }
3173
3174 int
3175 rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
3176                         struct rte_flex_filter *filter, uint16_t rx_queue)
3177 {
3178         struct rte_eth_dev *dev;
3179
3180         if (port_id >= nb_ports) {
3181                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3182                 return -ENODEV;
3183         }
3184
3185         dev = &rte_eth_devices[port_id];
3186         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP);
3187         return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue);
3188 }
3189
3190 int
3191 rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
3192 {
3193         struct rte_eth_dev *dev;
3194
3195         if (port_id >= nb_ports) {
3196                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3197                 return -ENODEV;
3198         }
3199
3200         dev = &rte_eth_devices[port_id];
3201         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP);
3202         return (*dev->dev_ops->remove_flex_filter)(dev, index);
3203 }
3204
3205 int
3206 rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
3207                         struct rte_flex_filter *filter, uint16_t *rx_queue)
3208 {
3209         struct rte_eth_dev *dev;
3210
3211         if (filter == NULL || rx_queue == NULL)
3212                 return -EINVAL;
3213
3214         if (port_id >= nb_ports) {
3215                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3216                 return -ENODEV;
3217         }
3218
3219         dev = &rte_eth_devices[port_id];
3220         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_flex_filter, -ENOTSUP);
3221         return (*dev->dev_ops->get_flex_filter)(dev, index, filter,
3222                                                 rx_queue);
3223 }
3224
3225 int
3226 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3227 {
3228         struct rte_eth_dev *dev;
3229
3230         if (port_id >= nb_ports) {
3231                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3232                 return -ENODEV;
3233         }
3234
3235         dev = &rte_eth_devices[port_id];
3236         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3237         return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3238                                 RTE_ETH_FILTER_NOP, NULL);
3239 }
3240
3241 int
3242 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3243                        enum rte_filter_op filter_op, void *arg)
3244 {
3245         struct rte_eth_dev *dev;
3246
3247         if (port_id >= nb_ports) {
3248                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3249                 return -ENODEV;
3250         }
3251
3252         dev = &rte_eth_devices[port_id];
3253         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3254         return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3255 }