remove trailing whitespaces
[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
45 #include <rte_byteorder.h>
46 #include <rte_log.h>
47 #include <rte_debug.h>
48 #include <rte_interrupts.h>
49 #include <rte_pci.h>
50 #include <rte_memory.h>
51 #include <rte_memcpy.h>
52 #include <rte_memzone.h>
53 #include <rte_launch.h>
54 #include <rte_tailq.h>
55 #include <rte_eal.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
61 #include <rte_ring.h>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
64 #include <rte_mbuf.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
67
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
70
71 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
72 #define PMD_DEBUG_TRACE(fmt, args...) do {                        \
73                 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
74         } while (0)
75 #else
76 #define PMD_DEBUG_TRACE(fmt, args...)
77 #endif
78
79 /* Macros for checking for restricting functions to primary instance only */
80 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
81         if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
82                 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
83                 return (retval); \
84         } \
85 } while(0)
86 #define PROC_PRIMARY_OR_RET() do { \
87         if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
88                 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
89                 return; \
90         } \
91 } while(0)
92
93 /* Macros to check for invlaid function pointers in dev_ops structure */
94 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
95         if ((func) == NULL) { \
96                 PMD_DEBUG_TRACE("Function not supported\n"); \
97                 return (retval); \
98         } \
99 } while(0)
100 #define FUNC_PTR_OR_RET(func) do { \
101         if ((func) == NULL) { \
102                 PMD_DEBUG_TRACE("Function not supported\n"); \
103                 return; \
104         } \
105 } while(0)
106
107 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
108 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
109 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
110 static uint8_t nb_ports = 0;
111
112 /* spinlock for eth device callbacks */
113 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
114
115 /**
116  * The user application callback description.
117  *
118  * It contains callback address to be registered by user application,
119  * the pointer to the parameters for callback, and the event type.
120  */
121 struct rte_eth_dev_callback {
122         TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
123         rte_eth_dev_cb_fn cb_fn;                /**< Callback address */
124         void *cb_arg;                           /**< Parameter for callback */
125         enum rte_eth_event_type event;          /**< Interrupt event type */
126         uint32_t active;                        /**< Callback is executing */
127 };
128
129 enum {
130         STAT_QMAP_TX = 0,
131         STAT_QMAP_RX
132 };
133
134 static inline void
135 rte_eth_dev_data_alloc(void)
136 {
137         const unsigned flags = 0;
138         const struct rte_memzone *mz;
139
140         if (rte_eal_process_type() == RTE_PROC_PRIMARY){
141                 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
142                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
143                                 rte_socket_id(), flags);
144         } else
145                 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
146         if (mz == NULL)
147                 rte_panic("Cannot allocate memzone for ethernet port data\n");
148
149         rte_eth_dev_data = mz->addr;
150         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
151                 memset(rte_eth_dev_data, 0,
152                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
153 }
154
155 struct rte_eth_dev *
156 rte_eth_dev_allocate(void)
157 {
158         struct rte_eth_dev *eth_dev;
159
160         if (nb_ports == RTE_MAX_ETHPORTS) {
161                 PMD_DEBUG_TRACE("Reached maximum number of ethernet ports\n");
162                 return NULL;
163         }
164
165         if (rte_eth_dev_data == NULL)
166                 rte_eth_dev_data_alloc();
167
168         eth_dev = &rte_eth_devices[nb_ports];
169         eth_dev->data = &rte_eth_dev_data[nb_ports];
170         eth_dev->data->port_id = nb_ports++;
171         return eth_dev;
172 }
173
174 static int
175 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
176                  struct rte_pci_device *pci_dev)
177 {
178         struct eth_driver    *eth_drv;
179         struct rte_eth_dev *eth_dev;
180         int diag;
181
182         eth_drv = (struct eth_driver *)pci_drv;
183
184         eth_dev = rte_eth_dev_allocate();
185         if (eth_dev == NULL)
186                 return -ENOMEM;
187
188         if (rte_eal_process_type() == RTE_PROC_PRIMARY){
189                 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
190                                   eth_drv->dev_private_size,
191                                   CACHE_LINE_SIZE);
192                 if (eth_dev->data->dev_private == NULL)
193                         rte_panic("Cannot allocate memzone for private port data\n");
194         }
195         eth_dev->pci_dev = pci_dev;
196         eth_dev->driver = eth_drv;
197         eth_dev->data->rx_mbuf_alloc_failed = 0;
198
199         /* init user callbacks */
200         TAILQ_INIT(&(eth_dev->callbacks));
201
202         /*
203          * Set the default maximum frame size.
204          */
205         eth_dev->data->max_frame_size = ETHER_MAX_LEN;
206
207         /* Invoke PMD device initialization function */
208         diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
209         if (diag == 0)
210                 return (0);
211
212         PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
213                         " failed\n", pci_drv->name,
214                         (unsigned) pci_dev->id.vendor_id,
215                         (unsigned) pci_dev->id.device_id);
216         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
217                 rte_free(eth_dev->data->dev_private);
218         nb_ports--;
219         return diag;
220 }
221
222 /**
223  * Register an Ethernet [Poll Mode] driver.
224  *
225  * Function invoked by the initialization function of an Ethernet driver
226  * to simultaneously register itself as a PCI driver and as an Ethernet
227  * Poll Mode Driver.
228  * Invokes the rte_eal_pci_register() function to register the *pci_drv*
229  * structure embedded in the *eth_drv* structure, after having stored the
230  * address of the rte_eth_dev_init() function in the *devinit* field of
231  * the *pci_drv* structure.
232  * During the PCI probing phase, the rte_eth_dev_init() function is
233  * invoked for each PCI [Ethernet device] matching the embedded PCI
234  * identifiers provided by the driver.
235  */
236 void
237 rte_eth_driver_register(struct eth_driver *eth_drv)
238 {
239         eth_drv->pci_drv.devinit = rte_eth_dev_init;
240         rte_eal_pci_register(&eth_drv->pci_drv);
241 }
242
243 int
244 rte_eth_dev_socket_id(uint8_t port_id)
245 {
246         if (port_id >= nb_ports)
247                 return -1;
248         return rte_eth_devices[port_id].pci_dev->numa_node;
249 }
250
251 uint8_t
252 rte_eth_dev_count(void)
253 {
254         return (nb_ports);
255 }
256
257 static int
258 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
259 {
260         uint16_t old_nb_queues = dev->data->nb_rx_queues;
261         void **rxq;
262         unsigned i;
263
264         if (dev->data->rx_queues == NULL) { /* first time configuration */
265                 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
266                                 sizeof(dev->data->rx_queues[0]) * nb_queues,
267                                 CACHE_LINE_SIZE);
268                 if (dev->data->rx_queues == NULL) {
269                         dev->data->nb_rx_queues = 0;
270                         return -(ENOMEM);
271                 }
272         } else { /* re-configure */
273                 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
274
275                 rxq = dev->data->rx_queues;
276
277                 for (i = nb_queues; i < old_nb_queues; i++)
278                         (*dev->dev_ops->rx_queue_release)(rxq[i]);
279                 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
280                                 CACHE_LINE_SIZE);
281                 if (rxq == NULL)
282                         return -(ENOMEM);
283
284                 if (nb_queues > old_nb_queues)
285                         memset(rxq + old_nb_queues, 0,
286                                 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
287
288                 dev->data->rx_queues = rxq;
289
290         }
291         dev->data->nb_rx_queues = nb_queues;
292         return (0);
293 }
294
295 int
296 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
297 {
298         struct rte_eth_dev *dev;
299
300         /* This function is only safe when called from the primary process
301          * in a multi-process setup*/
302         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
303
304         if (port_id >= nb_ports) {
305                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
306                 return -EINVAL;
307         }
308
309         dev = &rte_eth_devices[port_id];
310         if (rx_queue_id >= dev->data->nb_rx_queues) {
311                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
312                 return -EINVAL;
313         }
314
315         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
316
317         return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
318
319 }
320
321 int
322 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
323 {
324         struct rte_eth_dev *dev;
325
326         /* This function is only safe when called from the primary process
327          * in a multi-process setup*/
328         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
329
330         if (port_id >= nb_ports) {
331                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
332                 return -EINVAL;
333         }
334
335         dev = &rte_eth_devices[port_id];
336         if (rx_queue_id >= dev->data->nb_rx_queues) {
337                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
338                 return -EINVAL;
339         }
340
341         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
342
343         return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
344
345 }
346
347 int
348 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
349 {
350         struct rte_eth_dev *dev;
351
352         /* This function is only safe when called from the primary process
353          * in a multi-process setup*/
354         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
355
356         if (port_id >= nb_ports) {
357                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
358                 return -EINVAL;
359         }
360
361         dev = &rte_eth_devices[port_id];
362         if (tx_queue_id >= dev->data->nb_tx_queues) {
363                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
364                 return -EINVAL;
365         }
366
367         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
368
369         return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
370
371 }
372
373 int
374 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
375 {
376         struct rte_eth_dev *dev;
377
378         /* This function is only safe when called from the primary process
379          * in a multi-process setup*/
380         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
381
382         if (port_id >= nb_ports) {
383                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
384                 return -EINVAL;
385         }
386
387         dev = &rte_eth_devices[port_id];
388         if (tx_queue_id >= dev->data->nb_tx_queues) {
389                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
390                 return -EINVAL;
391         }
392
393         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
394
395         return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
396
397 }
398
399 static int
400 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
401 {
402         uint16_t old_nb_queues = dev->data->nb_tx_queues;
403         void **txq;
404         unsigned i;
405
406         if (dev->data->tx_queues == NULL) { /* first time configuration */
407                 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
408                                 sizeof(dev->data->tx_queues[0]) * nb_queues,
409                                 CACHE_LINE_SIZE);
410                 if (dev->data->tx_queues == NULL) {
411                         dev->data->nb_tx_queues = 0;
412                         return -(ENOMEM);
413                 }
414         } else { /* re-configure */
415                 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
416
417                 txq = dev->data->tx_queues;
418
419                 for (i = nb_queues; i < old_nb_queues; i++)
420                         (*dev->dev_ops->tx_queue_release)(txq[i]);
421                 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
422                                 CACHE_LINE_SIZE);
423                 if (txq == NULL)
424                         return -(ENOMEM);
425
426                 if (nb_queues > old_nb_queues)
427                         memset(txq + old_nb_queues, 0,
428                                 sizeof(txq[0]) * (nb_queues - old_nb_queues));
429
430                 dev->data->tx_queues = txq;
431
432         }
433         dev->data->nb_tx_queues = nb_queues;
434         return (0);
435 }
436
437 static int
438 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
439                       const struct rte_eth_conf *dev_conf)
440 {
441         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
442
443         if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
444                 /* check multi-queue mode */
445                 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ||
446                     (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
447                     (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
448                     (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
449                         /* SRIOV only works in VMDq enable mode */
450                         PMD_DEBUG_TRACE("ethdev port_id=%hhu SRIOV active, "
451                                         "wrong VMDQ mq_mode rx %u tx %u\n",
452                                         port_id,
453                                         dev_conf->rxmode.mq_mode,
454                                         dev_conf->txmode.mq_mode);
455                         return (-EINVAL);
456                 }
457
458                 switch (dev_conf->rxmode.mq_mode) {
459                 case ETH_MQ_RX_VMDQ_RSS:
460                 case ETH_MQ_RX_VMDQ_DCB:
461                 case ETH_MQ_RX_VMDQ_DCB_RSS:
462                         /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
463                         PMD_DEBUG_TRACE("ethdev port_id=%hhu SRIOV active, "
464                                         "unsupported VMDQ mq_mode rx %u\n",
465                                         port_id, dev_conf->rxmode.mq_mode);
466                         return (-EINVAL);
467                 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
468                         /* if nothing mq mode configure, use default scheme */
469                         dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
470                         if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
471                                 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
472                         break;
473                 }
474
475                 switch (dev_conf->txmode.mq_mode) {
476                 case ETH_MQ_TX_VMDQ_DCB:
477                         /* DCB VMDQ in SRIOV mode, not implement yet */
478                         PMD_DEBUG_TRACE("ethdev port_id=%hhu SRIOV active, "
479                                         "unsupported VMDQ mq_mode tx %u\n",
480                                         port_id, dev_conf->txmode.mq_mode);
481                         return (-EINVAL);
482                 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
483                         /* if nothing mq mode configure, use default scheme */
484                         dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
485                         if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
486                                 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
487                         break;
488                 }
489
490                 /* check valid queue number */
491                 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
492                     (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
493                         PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
494                                     "queue number must less equal to %d\n",
495                                         port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
496                         return (-EINVAL);
497                 }
498         } else {
499                 /* For vmdb+dcb mode check our configuration before we go further */
500                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
501                         const struct rte_eth_vmdq_dcb_conf *conf;
502
503                         if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
504                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
505                                                 "!= %d\n",
506                                                 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
507                                 return (-EINVAL);
508                         }
509                         conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
510                         if (! (conf->nb_queue_pools == ETH_16_POOLS ||
511                                conf->nb_queue_pools == ETH_32_POOLS)) {
512                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
513                                                 "nb_queue_pools must be %d or %d\n",
514                                                 port_id, ETH_16_POOLS, ETH_32_POOLS);
515                                 return (-EINVAL);
516                         }
517                 }
518                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
519                         const struct rte_eth_vmdq_dcb_tx_conf *conf;
520
521                         if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
522                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
523                                                 "!= %d\n",
524                                                 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
525                                 return (-EINVAL);
526                         }
527                         conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
528                         if (! (conf->nb_queue_pools == ETH_16_POOLS ||
529                                conf->nb_queue_pools == ETH_32_POOLS)) {
530                                 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
531                                                 "nb_queue_pools != %d or nb_queue_pools "
532                                                 "!= %d\n",
533                                                 port_id, ETH_16_POOLS, ETH_32_POOLS);
534                                 return (-EINVAL);
535                         }
536                 }
537
538                 /* For DCB mode check our configuration before we go further */
539                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
540                         const struct rte_eth_dcb_rx_conf *conf;
541
542                         if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
543                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
544                                                 "!= %d\n",
545                                                 port_id, ETH_DCB_NUM_QUEUES);
546                                 return (-EINVAL);
547                         }
548                         conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
549                         if (! (conf->nb_tcs == ETH_4_TCS ||
550                                conf->nb_tcs == ETH_8_TCS)) {
551                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
552                                                 "nb_tcs != %d or nb_tcs "
553                                                 "!= %d\n",
554                                                 port_id, ETH_4_TCS, ETH_8_TCS);
555                                 return (-EINVAL);
556                         }
557                 }
558
559                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
560                         const struct rte_eth_dcb_tx_conf *conf;
561
562                         if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
563                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
564                                                 "!= %d\n",
565                                                 port_id, ETH_DCB_NUM_QUEUES);
566                                 return (-EINVAL);
567                         }
568                         conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
569                         if (! (conf->nb_tcs == ETH_4_TCS ||
570                                conf->nb_tcs == ETH_8_TCS)) {
571                                 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
572                                                 "nb_tcs != %d or nb_tcs "
573                                                 "!= %d\n",
574                                                 port_id, ETH_4_TCS, ETH_8_TCS);
575                                 return (-EINVAL);
576                         }
577                 }
578         }
579         return 0;
580 }
581
582 int
583 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
584                       const struct rte_eth_conf *dev_conf)
585 {
586         struct rte_eth_dev *dev;
587         struct rte_eth_dev_info dev_info;
588         int diag;
589
590         /* This function is only safe when called from the primary process
591          * in a multi-process setup*/
592         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
593
594         if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
595                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
596                 return (-EINVAL);
597         }
598         dev = &rte_eth_devices[port_id];
599
600         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
601         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
602
603         if (dev->data->dev_started) {
604                 PMD_DEBUG_TRACE(
605                     "port %d must be stopped to allow configuration\n", port_id);
606                 return (-EBUSY);
607         }
608
609         /*
610          * Check that the numbers of RX and TX queues are not greater
611          * than the maximum number of RX and TX queues supported by the
612          * configured device.
613          */
614         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
615         if (nb_rx_q > dev_info.max_rx_queues) {
616                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
617                                 port_id, nb_rx_q, dev_info.max_rx_queues);
618                 return (-EINVAL);
619         }
620         if (nb_rx_q == 0) {
621                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
622                 return (-EINVAL);
623         }
624
625         if (nb_tx_q > dev_info.max_tx_queues) {
626                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
627                                 port_id, nb_tx_q, dev_info.max_tx_queues);
628                 return (-EINVAL);
629         }
630         if (nb_tx_q == 0) {
631                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
632                 return (-EINVAL);
633         }
634
635         /* Copy the dev_conf parameter into the dev structure */
636         memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
637
638         /*
639          * If jumbo frames are enabled, check that the maximum RX packet
640          * length is supported by the configured device.
641          */
642         if (dev_conf->rxmode.jumbo_frame == 1) {
643                 if (dev_conf->rxmode.max_rx_pkt_len >
644                     dev_info.max_rx_pktlen) {
645                         PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
646                                 " > max valid value %u\n",
647                                 port_id,
648                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
649                                 (unsigned)dev_info.max_rx_pktlen);
650                         return (-EINVAL);
651                 }
652                 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
653                         PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
654                                 " < min valid value %u\n",
655                                 port_id,
656                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
657                                 (unsigned)ETHER_MIN_LEN);
658                         return (-EINVAL);
659                 }
660         } else
661                 /* Use default value */
662                 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
663
664         /* multipe queue mode checking */
665         diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
666         if (diag != 0) {
667                 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
668                                 port_id, diag);
669                 return diag;
670         }
671
672         /*
673          * Setup new number of RX/TX queues and reconfigure device.
674          */
675         diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
676         if (diag != 0) {
677                 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
678                                 port_id, diag);
679                 return diag;
680         }
681
682         diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
683         if (diag != 0) {
684                 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
685                                 port_id, diag);
686                 rte_eth_dev_rx_queue_config(dev, 0);
687                 return diag;
688         }
689
690         diag = (*dev->dev_ops->dev_configure)(dev);
691         if (diag != 0) {
692                 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
693                                 port_id, diag);
694                 rte_eth_dev_rx_queue_config(dev, 0);
695                 rte_eth_dev_tx_queue_config(dev, 0);
696                 return diag;
697         }
698
699         return 0;
700 }
701
702 static void
703 rte_eth_dev_config_restore(uint8_t port_id)
704 {
705         struct rte_eth_dev *dev;
706         struct rte_eth_dev_info dev_info;
707         struct ether_addr addr;
708         uint16_t i;
709         uint32_t pool = 0;
710
711         dev = &rte_eth_devices[port_id];
712
713         rte_eth_dev_info_get(port_id, &dev_info);
714
715         if (RTE_ETH_DEV_SRIOV(dev).active)
716                 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
717
718         /* replay MAC address configuration */
719         for (i = 0; i < dev_info.max_mac_addrs; i++) {
720                 addr = dev->data->mac_addrs[i];
721
722                 /* skip zero address */
723                 if (is_zero_ether_addr(&addr))
724                         continue;
725
726                 /* add address to the hardware */
727                 if  (*dev->dev_ops->mac_addr_add)
728                         (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
729                 else {
730                         PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
731                                         port_id);
732                         /* exit the loop but not return an error */
733                         break;
734                 }
735         }
736
737         /* replay promiscuous configuration */
738         if (rte_eth_promiscuous_get(port_id) == 1)
739                 rte_eth_promiscuous_enable(port_id);
740         else if (rte_eth_promiscuous_get(port_id) == 0)
741                 rte_eth_promiscuous_disable(port_id);
742
743         /* replay allmulticast configuration */
744         if (rte_eth_allmulticast_get(port_id) == 1)
745                 rte_eth_allmulticast_enable(port_id);
746         else if (rte_eth_allmulticast_get(port_id) == 0)
747                 rte_eth_allmulticast_disable(port_id);
748 }
749
750 int
751 rte_eth_dev_start(uint8_t port_id)
752 {
753         struct rte_eth_dev *dev;
754         int diag;
755
756         /* This function is only safe when called from the primary process
757          * in a multi-process setup*/
758         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
759
760         if (port_id >= nb_ports) {
761                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
762                 return (-EINVAL);
763         }
764         dev = &rte_eth_devices[port_id];
765
766         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
767         diag = (*dev->dev_ops->dev_start)(dev);
768         if (diag == 0)
769                 dev->data->dev_started = 1;
770         else
771                 return diag;
772
773         rte_eth_dev_config_restore(port_id);
774
775         return 0;
776 }
777
778 void
779 rte_eth_dev_stop(uint8_t port_id)
780 {
781         struct rte_eth_dev *dev;
782
783         /* This function is only safe when called from the primary process
784          * in a multi-process setup*/
785         PROC_PRIMARY_OR_RET();
786
787         if (port_id >= nb_ports) {
788                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
789                 return;
790         }
791         dev = &rte_eth_devices[port_id];
792
793         FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
794         dev->data->dev_started = 0;
795         (*dev->dev_ops->dev_stop)(dev);
796 }
797
798 void
799 rte_eth_dev_close(uint8_t port_id)
800 {
801         struct rte_eth_dev *dev;
802
803         /* This function is only safe when called from the primary process
804          * in a multi-process setup*/
805         PROC_PRIMARY_OR_RET();
806
807         if (port_id >= nb_ports) {
808                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
809                 return;
810         }
811
812         dev = &rte_eth_devices[port_id];
813
814         FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
815         dev->data->dev_started = 0;
816         (*dev->dev_ops->dev_close)(dev);
817 }
818
819 int
820 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
821                        uint16_t nb_rx_desc, unsigned int socket_id,
822                        const struct rte_eth_rxconf *rx_conf,
823                        struct rte_mempool *mp)
824 {
825         struct rte_eth_dev *dev;
826         struct rte_pktmbuf_pool_private *mbp_priv;
827         struct rte_eth_dev_info dev_info;
828
829         /* This function is only safe when called from the primary process
830          * in a multi-process setup*/
831         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
832
833         if (port_id >= nb_ports) {
834                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
835                 return (-EINVAL);
836         }
837         dev = &rte_eth_devices[port_id];
838         if (rx_queue_id >= dev->data->nb_rx_queues) {
839                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
840                 return (-EINVAL);
841         }
842
843         if (dev->data->dev_started) {
844                 PMD_DEBUG_TRACE(
845                     "port %d must be stopped to allow configuration\n", port_id);
846                 return -EBUSY;
847         }
848
849         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
850         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
851
852         /*
853          * Check the size of the mbuf data buffer.
854          * This value must be provided in the private data of the memory pool.
855          * First check that the memory pool has a valid private data.
856          */
857         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
858         if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
859                 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
860                                 mp->name, (int) mp->private_data_size,
861                                 (int) sizeof(struct rte_pktmbuf_pool_private));
862                 return (-ENOSPC);
863         }
864         mbp_priv = rte_mempool_get_priv(mp);
865         if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
866             dev_info.min_rx_bufsize) {
867                 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
868                                 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
869                                 "=%d)\n",
870                                 mp->name,
871                                 (int)mbp_priv->mbuf_data_room_size,
872                                 (int)(RTE_PKTMBUF_HEADROOM +
873                                       dev_info.min_rx_bufsize),
874                                 (int)RTE_PKTMBUF_HEADROOM,
875                                 (int)dev_info.min_rx_bufsize);
876                 return (-EINVAL);
877         }
878
879         return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
880                                                socket_id, rx_conf, mp);
881 }
882
883 int
884 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
885                        uint16_t nb_tx_desc, unsigned int socket_id,
886                        const struct rte_eth_txconf *tx_conf)
887 {
888         struct rte_eth_dev *dev;
889
890         /* This function is only safe when called from the primary process
891          * in a multi-process setup*/
892         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
893
894         if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
895                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
896                 return (-EINVAL);
897         }
898         dev = &rte_eth_devices[port_id];
899         if (tx_queue_id >= dev->data->nb_tx_queues) {
900                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
901                 return (-EINVAL);
902         }
903
904         if (dev->data->dev_started) {
905                 PMD_DEBUG_TRACE(
906                     "port %d must be stopped to allow configuration\n", port_id);
907                 return -EBUSY;
908         }
909
910         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
911         return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
912                                                socket_id, tx_conf);
913 }
914
915 void
916 rte_eth_promiscuous_enable(uint8_t port_id)
917 {
918         struct rte_eth_dev *dev;
919
920         if (port_id >= nb_ports) {
921                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
922                 return;
923         }
924         dev = &rte_eth_devices[port_id];
925
926         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
927         (*dev->dev_ops->promiscuous_enable)(dev);
928         dev->data->promiscuous = 1;
929 }
930
931 void
932 rte_eth_promiscuous_disable(uint8_t port_id)
933 {
934         struct rte_eth_dev *dev;
935
936         if (port_id >= nb_ports) {
937                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
938                 return;
939         }
940         dev = &rte_eth_devices[port_id];
941
942         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
943         dev->data->promiscuous = 0;
944         (*dev->dev_ops->promiscuous_disable)(dev);
945 }
946
947 int
948 rte_eth_promiscuous_get(uint8_t port_id)
949 {
950         struct rte_eth_dev *dev;
951
952         if (port_id >= nb_ports) {
953                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
954                 return -1;
955         }
956
957         dev = &rte_eth_devices[port_id];
958         return dev->data->promiscuous;
959 }
960
961 void
962 rte_eth_allmulticast_enable(uint8_t port_id)
963 {
964         struct rte_eth_dev *dev;
965
966         if (port_id >= nb_ports) {
967                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
968                 return;
969         }
970         dev = &rte_eth_devices[port_id];
971
972         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
973         (*dev->dev_ops->allmulticast_enable)(dev);
974         dev->data->all_multicast = 1;
975 }
976
977 void
978 rte_eth_allmulticast_disable(uint8_t port_id)
979 {
980         struct rte_eth_dev *dev;
981
982         if (port_id >= nb_ports) {
983                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
984                 return;
985         }
986         dev = &rte_eth_devices[port_id];
987
988         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
989         dev->data->all_multicast = 0;
990         (*dev->dev_ops->allmulticast_disable)(dev);
991 }
992
993 int
994 rte_eth_allmulticast_get(uint8_t port_id)
995 {
996         struct rte_eth_dev *dev;
997
998         if (port_id >= nb_ports) {
999                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1000                 return -1;
1001         }
1002
1003         dev = &rte_eth_devices[port_id];
1004         return dev->data->all_multicast;
1005 }
1006
1007 static inline int
1008 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1009                                 struct rte_eth_link *link)
1010 {
1011         struct rte_eth_link *dst = link;
1012         struct rte_eth_link *src = &(dev->data->dev_link);
1013
1014         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1015                                         *(uint64_t *)src) == 0)
1016                 return -1;
1017
1018         return 0;
1019 }
1020
1021 void
1022 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1023 {
1024         struct rte_eth_dev *dev;
1025
1026         if (port_id >= nb_ports) {
1027                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1028                 return;
1029         }
1030         dev = &rte_eth_devices[port_id];
1031         FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1032
1033         if (dev->data->dev_conf.intr_conf.lsc != 0)
1034                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1035         else {
1036                 (*dev->dev_ops->link_update)(dev, 1);
1037                 *eth_link = dev->data->dev_link;
1038         }
1039 }
1040
1041 void
1042 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1043 {
1044         struct rte_eth_dev *dev;
1045
1046         if (port_id >= nb_ports) {
1047                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1048                 return;
1049         }
1050         dev = &rte_eth_devices[port_id];
1051         FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1052
1053         if (dev->data->dev_conf.intr_conf.lsc != 0)
1054                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1055         else {
1056                 (*dev->dev_ops->link_update)(dev, 0);
1057                 *eth_link = dev->data->dev_link;
1058         }
1059 }
1060
1061 void
1062 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1063 {
1064         struct rte_eth_dev *dev;
1065
1066         if (port_id >= nb_ports) {
1067                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1068                 return;
1069         }
1070         dev = &rte_eth_devices[port_id];
1071         memset(stats, 0, sizeof(*stats));
1072
1073         FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1074         (*dev->dev_ops->stats_get)(dev, stats);
1075         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1076 }
1077
1078 void
1079 rte_eth_stats_reset(uint8_t port_id)
1080 {
1081         struct rte_eth_dev *dev;
1082
1083         if (port_id >= nb_ports) {
1084                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1085                 return;
1086         }
1087         dev = &rte_eth_devices[port_id];
1088
1089         FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1090         (*dev->dev_ops->stats_reset)(dev);
1091 }
1092
1093
1094 static int
1095 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1096                 uint8_t is_rx)
1097 {
1098         struct rte_eth_dev *dev;
1099
1100         if (port_id >= nb_ports) {
1101                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1102                 return -ENODEV;
1103         }
1104         dev = &rte_eth_devices[port_id];
1105
1106         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1107         return (*dev->dev_ops->queue_stats_mapping_set)
1108                         (dev, queue_id, stat_idx, is_rx);
1109 }
1110
1111
1112 int
1113 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1114                 uint8_t stat_idx)
1115 {
1116         return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1117                         STAT_QMAP_TX);
1118 }
1119
1120
1121 int
1122 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1123                 uint8_t stat_idx)
1124 {
1125         return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1126                         STAT_QMAP_RX);
1127 }
1128
1129
1130 void
1131 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1132 {
1133         struct rte_eth_dev *dev;
1134
1135         if (port_id >= nb_ports) {
1136                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1137                 return;
1138         }
1139         dev = &rte_eth_devices[port_id];
1140
1141         /* Default device offload capabilities to zero */
1142         dev_info->rx_offload_capa = 0;
1143         dev_info->tx_offload_capa = 0;
1144         dev_info->if_index = 0;
1145         FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1146         (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1147         dev_info->pci_dev = dev->pci_dev;
1148         if (dev->driver)
1149                 dev_info->driver_name = dev->driver->pci_drv.name;
1150 }
1151
1152 void
1153 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1154 {
1155         struct rte_eth_dev *dev;
1156
1157         if (port_id >= nb_ports) {
1158                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1159                 return;
1160         }
1161         dev = &rte_eth_devices[port_id];
1162         ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1163 }
1164
1165 int
1166 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1167 {
1168         struct rte_eth_dev *dev;
1169
1170         if (port_id >= nb_ports) {
1171                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1172                 return (-ENODEV);
1173         }
1174         dev = &rte_eth_devices[port_id];
1175         if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1176                 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1177                 return (-ENOSYS);
1178         }
1179
1180         if (vlan_id > 4095) {
1181                 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1182                                 port_id, (unsigned) vlan_id);
1183                 return (-EINVAL);
1184         }
1185         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1186         (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1187         return (0);
1188 }
1189
1190 int
1191 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1192 {
1193         struct rte_eth_dev *dev;
1194
1195         if (port_id >= nb_ports) {
1196                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1197                 return (-ENODEV);
1198         }
1199
1200         dev = &rte_eth_devices[port_id];
1201         if (rx_queue_id >= dev->data->nb_rx_queues) {
1202                 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1203                 return (-EINVAL);
1204         }
1205
1206         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1207         (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1208
1209         return (0);
1210 }
1211
1212 int
1213 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1214 {
1215         struct rte_eth_dev *dev;
1216
1217         if (port_id >= nb_ports) {
1218                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1219                 return (-ENODEV);
1220         }
1221
1222         dev = &rte_eth_devices[port_id];
1223         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1224         (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1225
1226         return (0);
1227 }
1228
1229 int
1230 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1231 {
1232         struct rte_eth_dev *dev;
1233         int ret = 0;
1234         int mask = 0;
1235         int cur, org = 0;
1236
1237         if (port_id >= nb_ports) {
1238                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1239                 return (-ENODEV);
1240         }
1241
1242         dev = &rte_eth_devices[port_id];
1243
1244         /*check which option changed by application*/
1245         cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1246         org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1247         if (cur != org){
1248                 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1249                 mask |= ETH_VLAN_STRIP_MASK;
1250         }
1251
1252         cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1253         org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1254         if (cur != org){
1255                 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1256                 mask |= ETH_VLAN_FILTER_MASK;
1257         }
1258
1259         cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1260         org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1261         if (cur != org){
1262                 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1263                 mask |= ETH_VLAN_EXTEND_MASK;
1264         }
1265
1266         /*no change*/
1267         if(mask == 0)
1268                 return ret;
1269
1270         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1271         (*dev->dev_ops->vlan_offload_set)(dev, mask);
1272
1273         return ret;
1274 }
1275
1276 int
1277 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1278 {
1279         struct rte_eth_dev *dev;
1280         int ret = 0;
1281
1282         if (port_id >= nb_ports) {
1283                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1284                 return (-ENODEV);
1285         }
1286
1287         dev = &rte_eth_devices[port_id];
1288
1289         if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1290                 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1291
1292         if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1293                 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1294
1295         if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1296                 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1297
1298         return ret;
1299 }
1300
1301
1302 int
1303 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1304                                       struct rte_fdir_filter *fdir_filter,
1305                                       uint8_t queue)
1306 {
1307         struct rte_eth_dev *dev;
1308
1309         if (port_id >= nb_ports) {
1310                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1311                 return (-ENODEV);
1312         }
1313
1314         dev = &rte_eth_devices[port_id];
1315
1316         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1317                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1318                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1319                 return (-ENOSYS);
1320         }
1321
1322         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1323              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1324             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1325                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1326                                 "None l4type, source & destinations ports " \
1327                                 "should be null!\n");
1328                 return (-EINVAL);
1329         }
1330
1331         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1332         return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1333                                                                 queue);
1334 }
1335
1336 int
1337 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1338                                          struct rte_fdir_filter *fdir_filter,
1339                                          uint8_t queue)
1340 {
1341         struct rte_eth_dev *dev;
1342
1343         if (port_id >= nb_ports) {
1344                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1345                 return (-ENODEV);
1346         }
1347
1348         dev = &rte_eth_devices[port_id];
1349
1350         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1351                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1352                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1353                 return (-ENOSYS);
1354         }
1355
1356         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1357              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1358             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1359                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1360                                 "None l4type, source & destinations ports " \
1361                                 "should be null!\n");
1362                 return (-EINVAL);
1363         }
1364
1365         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1366         return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1367                                                                 queue);
1368
1369 }
1370
1371 int
1372 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1373                                          struct rte_fdir_filter *fdir_filter)
1374 {
1375         struct rte_eth_dev *dev;
1376
1377         if (port_id >= nb_ports) {
1378                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1379                 return (-ENODEV);
1380         }
1381
1382         dev = &rte_eth_devices[port_id];
1383
1384         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1385                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1386                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1387                 return (-ENOSYS);
1388         }
1389
1390         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1391              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1392             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1393                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1394                                 "None l4type source & destinations ports " \
1395                                 "should be null!\n");
1396                 return (-EINVAL);
1397         }
1398
1399         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1400         return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1401 }
1402
1403 int
1404 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1405 {
1406         struct rte_eth_dev *dev;
1407
1408         if (port_id >= nb_ports) {
1409                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1410                 return (-ENODEV);
1411         }
1412
1413         dev = &rte_eth_devices[port_id];
1414         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1415                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1416                 return (-ENOSYS);
1417         }
1418
1419         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1420
1421         (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1422         return (0);
1423 }
1424
1425 int
1426 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1427                                     struct rte_fdir_filter *fdir_filter,
1428                                     uint16_t soft_id, uint8_t queue,
1429                                     uint8_t drop)
1430 {
1431         struct rte_eth_dev *dev;
1432
1433         if (port_id >= nb_ports) {
1434                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1435                 return (-ENODEV);
1436         }
1437
1438         dev = &rte_eth_devices[port_id];
1439
1440         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1441                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1442                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1443                 return (-ENOSYS);
1444         }
1445
1446         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1447              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1448             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1449                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1450                                 "None l4type, source & destinations ports " \
1451                                 "should be null!\n");
1452                 return (-EINVAL);
1453         }
1454
1455         /* For now IPv6 is not supported with perfect filter */
1456         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1457                 return (-ENOTSUP);
1458
1459         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1460         return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1461                                                                 soft_id, queue,
1462                                                                 drop);
1463 }
1464
1465 int
1466 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1467                                        struct rte_fdir_filter *fdir_filter,
1468                                        uint16_t soft_id, uint8_t queue,
1469                                        uint8_t drop)
1470 {
1471         struct rte_eth_dev *dev;
1472
1473         if (port_id >= nb_ports) {
1474                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1475                 return (-ENODEV);
1476         }
1477
1478         dev = &rte_eth_devices[port_id];
1479
1480         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1481                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1482                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1483                 return (-ENOSYS);
1484         }
1485
1486         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1487              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1488             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1489                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1490                                 "None l4type, source & destinations ports " \
1491                                 "should be null!\n");
1492                 return (-EINVAL);
1493         }
1494
1495         /* For now IPv6 is not supported with perfect filter */
1496         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1497                 return (-ENOTSUP);
1498
1499         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1500         return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1501                                                         soft_id, queue, drop);
1502 }
1503
1504 int
1505 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1506                                        struct rte_fdir_filter *fdir_filter,
1507                                        uint16_t soft_id)
1508 {
1509         struct rte_eth_dev *dev;
1510
1511         if (port_id >= nb_ports) {
1512                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1513                 return (-ENODEV);
1514         }
1515
1516         dev = &rte_eth_devices[port_id];
1517
1518         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1519                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1520                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1521                 return (-ENOSYS);
1522         }
1523
1524         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1525              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1526             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1527                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1528                                 "None l4type, source & destinations ports " \
1529                                 "should be null!\n");
1530                 return (-EINVAL);
1531         }
1532
1533         /* For now IPv6 is not supported with perfect filter */
1534         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1535                 return (-ENOTSUP);
1536
1537         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1538         return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1539                                                                 soft_id);
1540 }
1541
1542 int
1543 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1544 {
1545         struct rte_eth_dev *dev;
1546
1547         if (port_id >= nb_ports) {
1548                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1549                 return (-ENODEV);
1550         }
1551
1552         dev = &rte_eth_devices[port_id];
1553         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1554                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1555                 return (-ENOSYS);
1556         }
1557
1558         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1559         return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1560 }
1561
1562 int
1563 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1564 {
1565         struct rte_eth_dev *dev;
1566
1567         if (port_id >= nb_ports) {
1568                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1569                 return (-ENODEV);
1570         }
1571
1572         if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1573                 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1574                 return (-EINVAL);
1575         }
1576
1577         dev = &rte_eth_devices[port_id];
1578         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1579         return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1580 }
1581
1582 int
1583 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1584 {
1585         struct rte_eth_dev *dev;
1586
1587         if (port_id >= nb_ports) {
1588                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1589                 return (-ENODEV);
1590         }
1591
1592         if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1593                 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1594                 return (-EINVAL);
1595         }
1596
1597         dev = &rte_eth_devices[port_id];
1598         /* High water, low water validation are device specific */
1599         if  (*dev->dev_ops->priority_flow_ctrl_set)
1600                 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1601         return (-ENOTSUP);
1602 }
1603
1604 int
1605 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1606 {
1607         struct rte_eth_dev *dev;
1608         uint16_t max_rxq;
1609         uint8_t i,j;
1610
1611         if (port_id >= nb_ports) {
1612                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1613                 return (-ENODEV);
1614         }
1615
1616         /* Invalid mask bit(s) setting */
1617         if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1618                 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1619                 return (-EINVAL);
1620         }
1621
1622         dev = &rte_eth_devices[port_id];
1623         max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1624                 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1625         if (reta_conf->mask_lo != 0) {
1626                 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1627                         if ((reta_conf->mask_lo & (1ULL << i)) &&
1628                                 (reta_conf->reta[i] >= max_rxq)) {
1629                                 PMD_DEBUG_TRACE("RETA hash index output"
1630                                         "configration for port=%d,invalid"
1631                                         "queue=%d\n",port_id,reta_conf->reta[i]);
1632
1633                                 return (-EINVAL);
1634                         }
1635                 }
1636         }
1637
1638         if (reta_conf->mask_hi != 0) {
1639                 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1640                         j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1641
1642                         /* Check if the max entry >= 128 */
1643                         if ((reta_conf->mask_hi & (1ULL << i)) &&
1644                                 (reta_conf->reta[j] >= max_rxq)) {
1645                                 PMD_DEBUG_TRACE("RETA hash index output"
1646                                         "configration for port=%d,invalid"
1647                                         "queue=%d\n",port_id,reta_conf->reta[j]);
1648
1649                                 return (-EINVAL);
1650                         }
1651                 }
1652         }
1653
1654         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1655         return (*dev->dev_ops->reta_update)(dev, reta_conf);
1656 }
1657
1658 int
1659 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1660 {
1661         struct rte_eth_dev *dev;
1662
1663         if (port_id >= nb_ports) {
1664                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1665                 return (-ENODEV);
1666         }
1667
1668         if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1669                 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1670                 return (-EINVAL);
1671         }
1672
1673         dev = &rte_eth_devices[port_id];
1674         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1675         return (*dev->dev_ops->reta_query)(dev, reta_conf);
1676 }
1677
1678 int
1679 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1680 {
1681         struct rte_eth_dev *dev;
1682         uint16_t rss_hash_protos;
1683
1684         if (port_id >= nb_ports) {
1685                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1686                 return (-ENODEV);
1687         }
1688         rss_hash_protos = rss_conf->rss_hf;
1689         if ((rss_hash_protos != 0) &&
1690             ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1691                 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1692                                 rss_hash_protos);
1693                 return (-EINVAL);
1694         }
1695         dev = &rte_eth_devices[port_id];
1696         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1697         return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1698 }
1699
1700 int
1701 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1702                               struct rte_eth_rss_conf *rss_conf)
1703 {
1704         struct rte_eth_dev *dev;
1705
1706         if (port_id >= nb_ports) {
1707                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1708                 return (-ENODEV);
1709         }
1710         dev = &rte_eth_devices[port_id];
1711         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1712         return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1713 }
1714
1715 int
1716 rte_eth_led_on(uint8_t port_id)
1717 {
1718         struct rte_eth_dev *dev;
1719
1720         if (port_id >= nb_ports) {
1721                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1722                 return (-ENODEV);
1723         }
1724
1725         dev = &rte_eth_devices[port_id];
1726         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1727         return ((*dev->dev_ops->dev_led_on)(dev));
1728 }
1729
1730 int
1731 rte_eth_led_off(uint8_t port_id)
1732 {
1733         struct rte_eth_dev *dev;
1734
1735         if (port_id >= nb_ports) {
1736                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1737                 return (-ENODEV);
1738         }
1739
1740         dev = &rte_eth_devices[port_id];
1741         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1742         return ((*dev->dev_ops->dev_led_off)(dev));
1743 }
1744
1745 /*
1746  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1747  * an empty spot.
1748  */
1749 static inline int
1750 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1751 {
1752         struct rte_eth_dev_info dev_info;
1753         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1754         unsigned i;
1755
1756         rte_eth_dev_info_get(port_id, &dev_info);
1757
1758         for (i = 0; i < dev_info.max_mac_addrs; i++)
1759                 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1760                         return i;
1761
1762         return -1;
1763 }
1764
1765 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1766
1767 int
1768 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1769                         uint32_t pool)
1770 {
1771         struct rte_eth_dev *dev;
1772         int index;
1773         uint64_t pool_mask;
1774
1775         if (port_id >= nb_ports) {
1776                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1777                 return (-ENODEV);
1778         }
1779         dev = &rte_eth_devices[port_id];
1780         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1781
1782         if (is_zero_ether_addr(addr)) {
1783                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1784                         port_id);
1785                 return (-EINVAL);
1786         }
1787         if (pool >= ETH_64_POOLS) {
1788                 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
1789                 return (-EINVAL);
1790         }
1791
1792         index = get_mac_addr_index(port_id, addr);
1793         if (index < 0) {
1794                 index = get_mac_addr_index(port_id, &null_mac_addr);
1795                 if (index < 0) {
1796                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1797                                 port_id);
1798                         return (-ENOSPC);
1799                 }
1800         } else {
1801                 pool_mask = dev->data->mac_pool_sel[index];
1802
1803                 /* Check if both MAC address and pool is alread there, and do nothing */
1804                 if (pool_mask & (1ULL << pool))
1805                         return 0;
1806         }
1807
1808         /* Update NIC */
1809         (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1810
1811         /* Update address in NIC data structure */
1812         ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1813
1814         /* Update pool bitmap in NIC data structure */
1815         dev->data->mac_pool_sel[index] |= (1ULL << pool);
1816
1817         return 0;
1818 }
1819
1820 int
1821 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1822 {
1823         struct rte_eth_dev *dev;
1824         int index;
1825
1826         if (port_id >= nb_ports) {
1827                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1828                 return (-ENODEV);
1829         }
1830         dev = &rte_eth_devices[port_id];
1831         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1832
1833         index = get_mac_addr_index(port_id, addr);
1834         if (index == 0) {
1835                 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1836                 return (-EADDRINUSE);
1837         } else if (index < 0)
1838                 return 0;  /* Do nothing if address wasn't found */
1839
1840         /* Update NIC */
1841         (*dev->dev_ops->mac_addr_remove)(dev, index);
1842
1843         /* Update address in NIC data structure */
1844         ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1845
1846         return 0;
1847 }
1848
1849 int
1850 rte_eth_dev_set_vf_rxmode(uint8_t port_id,  uint16_t vf,
1851                                 uint16_t rx_mode, uint8_t on)
1852 {
1853         uint16_t num_vfs;
1854         struct rte_eth_dev *dev;
1855         struct rte_eth_dev_info dev_info;
1856
1857         if (port_id >= nb_ports) {
1858                 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
1859                                 port_id);
1860                 return (-ENODEV);
1861         }
1862
1863         dev = &rte_eth_devices[port_id];
1864         rte_eth_dev_info_get(port_id, &dev_info);
1865
1866         num_vfs = dev_info.max_vfs;
1867         if (vf > num_vfs)
1868         {
1869                 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
1870                 return (-EINVAL);
1871         }
1872         if (rx_mode == 0)
1873         {
1874                 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
1875                 return (-EINVAL);
1876         }
1877         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
1878         return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
1879 }
1880
1881 /*
1882  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1883  * an empty spot.
1884  */
1885 static inline int
1886 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1887 {
1888         struct rte_eth_dev_info dev_info;
1889         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1890         unsigned i;
1891
1892         rte_eth_dev_info_get(port_id, &dev_info);
1893         if (!dev->data->hash_mac_addrs)
1894                 return -1;
1895
1896         for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
1897                 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
1898                         ETHER_ADDR_LEN) == 0)
1899                         return i;
1900
1901         return -1;
1902 }
1903
1904 int
1905 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
1906                                 uint8_t on)
1907 {
1908         int index;
1909         int ret;
1910         struct rte_eth_dev *dev;
1911
1912         if (port_id >= nb_ports) {
1913                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1914                         port_id);
1915                 return (-ENODEV);
1916         }
1917
1918         dev = &rte_eth_devices[port_id];
1919         if (is_zero_ether_addr(addr)) {
1920                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1921                         port_id);
1922                 return (-EINVAL);
1923         }
1924
1925         index = get_hash_mac_addr_index(port_id, addr);
1926         /* Check if it's already there, and do nothing */
1927         if ((index >= 0) && (on))
1928                 return 0;
1929
1930         if (index < 0) {
1931                 if (!on) {
1932                         PMD_DEBUG_TRACE("port %d: the MAC address was not"
1933                                 "set in UTA\n", port_id);
1934                         return (-EINVAL);
1935                 }
1936
1937                 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
1938                 if (index < 0) {
1939                         PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1940                                         port_id);
1941                         return (-ENOSPC);
1942                 }
1943         }
1944
1945         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
1946         ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
1947         if (ret == 0) {
1948                 /* Update address in NIC data structure */
1949                 if (on)
1950                         ether_addr_copy(addr,
1951                                         &dev->data->hash_mac_addrs[index]);
1952                 else
1953                         ether_addr_copy(&null_mac_addr,
1954                                         &dev->data->hash_mac_addrs[index]);
1955         }
1956
1957         return ret;
1958 }
1959
1960 int
1961 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
1962 {
1963         struct rte_eth_dev *dev;
1964
1965         if (port_id >= nb_ports) {
1966                 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1967                         port_id);
1968                 return (-ENODEV);
1969         }
1970
1971         dev = &rte_eth_devices[port_id];
1972
1973         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
1974         return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
1975 }
1976
1977 int
1978 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
1979 {
1980         uint16_t num_vfs;
1981         struct rte_eth_dev *dev;
1982         struct rte_eth_dev_info dev_info;
1983
1984         if (port_id >= nb_ports) {
1985                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1986                 return (-ENODEV);
1987         }
1988
1989         dev = &rte_eth_devices[port_id];
1990         rte_eth_dev_info_get(port_id, &dev_info);
1991
1992         num_vfs = dev_info.max_vfs;
1993         if (vf > num_vfs)
1994         {
1995                 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
1996                 return (-EINVAL);
1997         }
1998
1999         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2000         return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2001 }
2002
2003 int
2004 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2005 {
2006         uint16_t num_vfs;
2007         struct rte_eth_dev *dev;
2008         struct rte_eth_dev_info dev_info;
2009
2010         if (port_id >= nb_ports) {
2011                 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2012                 return (-ENODEV);
2013         }
2014
2015         dev = &rte_eth_devices[port_id];
2016         rte_eth_dev_info_get(port_id, &dev_info);
2017
2018         num_vfs = dev_info.max_vfs;
2019         if (vf > num_vfs)
2020         {
2021                 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2022                 return (-EINVAL);
2023         }
2024
2025         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2026         return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2027 }
2028
2029 int
2030 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2031                                  uint64_t vf_mask,uint8_t vlan_on)
2032 {
2033         struct rte_eth_dev *dev;
2034
2035         if (port_id >= nb_ports) {
2036                 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2037                                 port_id);
2038                 return (-ENODEV);
2039         }
2040         dev = &rte_eth_devices[port_id];
2041
2042         if(vlan_id > ETHER_MAX_VLAN_ID)
2043         {
2044                 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2045                         vlan_id);
2046                 return (-EINVAL);
2047         }
2048         if (vf_mask == 0)
2049         {
2050                 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2051                 return (-EINVAL);
2052         }
2053
2054         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2055         return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2056                                                 vf_mask,vlan_on);
2057 }
2058
2059 int
2060 rte_eth_mirror_rule_set(uint8_t port_id,
2061                         struct rte_eth_vmdq_mirror_conf *mirror_conf,
2062                         uint8_t rule_id, uint8_t on)
2063 {
2064         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2065
2066         if (port_id >= nb_ports) {
2067                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2068                 return (-ENODEV);
2069         }
2070
2071         if (mirror_conf->rule_type_mask == 0) {
2072                 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2073                 return (-EINVAL);
2074         }
2075
2076         if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2077                 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2078                         "be 0-%d\n",ETH_64_POOLS - 1);
2079                 return (-EINVAL);
2080         }
2081
2082         if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2083                 (mirror_conf->pool_mask == 0)) {
2084                 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2085                                 "be 0.\n");
2086                 return (-EINVAL);
2087         }
2088
2089         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2090         {
2091                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2092                         ETH_VMDQ_NUM_MIRROR_RULE - 1);
2093                 return (-EINVAL);
2094         }
2095
2096         dev = &rte_eth_devices[port_id];
2097         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2098
2099         return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2100 }
2101
2102 int
2103 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2104 {
2105         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2106
2107         if (port_id >= nb_ports) {
2108                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2109                 return (-ENODEV);
2110         }
2111
2112         if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2113         {
2114                 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2115                         ETH_VMDQ_NUM_MIRROR_RULE-1);
2116                 return (-EINVAL);
2117         }
2118
2119         dev = &rte_eth_devices[port_id];
2120         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2121
2122         return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2123 }
2124
2125 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2126 uint16_t
2127 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2128                  struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2129 {
2130         struct rte_eth_dev *dev;
2131
2132         if (port_id >= nb_ports) {
2133                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2134                 return 0;
2135         }
2136         dev = &rte_eth_devices[port_id];
2137         FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2138         if (queue_id >= dev->data->nb_rx_queues) {
2139                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2140                 return 0;
2141         }
2142         return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2143                                                 rx_pkts, nb_pkts);
2144 }
2145
2146 uint16_t
2147 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2148                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2149 {
2150         struct rte_eth_dev *dev;
2151
2152         if (port_id >= nb_ports) {
2153                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2154                 return 0;
2155         }
2156         dev = &rte_eth_devices[port_id];
2157
2158         FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2159         if (queue_id >= dev->data->nb_tx_queues) {
2160                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2161                 return 0;
2162         }
2163         return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2164                                                 tx_pkts, nb_pkts);
2165 }
2166
2167 uint32_t
2168 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_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 0;
2175         }
2176         dev = &rte_eth_devices[port_id];
2177         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2178         return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2179 }
2180
2181 int
2182 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2183 {
2184         struct rte_eth_dev *dev;
2185
2186         if (port_id >= nb_ports) {
2187                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2188                 return (-ENODEV);
2189         }
2190         dev = &rte_eth_devices[port_id];
2191         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2192         return (*dev->dev_ops->rx_descriptor_done)( \
2193                 dev->data->rx_queues[queue_id], offset);
2194 }
2195 #endif
2196
2197 int
2198 rte_eth_dev_callback_register(uint8_t port_id,
2199                         enum rte_eth_event_type event,
2200                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2201 {
2202         struct rte_eth_dev *dev;
2203         struct rte_eth_dev_callback *user_cb;
2204
2205         if (!cb_fn)
2206                 return (-EINVAL);
2207         if (port_id >= nb_ports) {
2208                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2209                 return (-EINVAL);
2210         }
2211
2212         dev = &rte_eth_devices[port_id];
2213         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2214
2215         TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2216                 if (user_cb->cb_fn == cb_fn &&
2217                         user_cb->cb_arg == cb_arg &&
2218                         user_cb->event == event) {
2219                         break;
2220                 }
2221         }
2222
2223         /* create a new callback. */
2224         if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2225                         sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2226                 user_cb->cb_fn = cb_fn;
2227                 user_cb->cb_arg = cb_arg;
2228                 user_cb->event = event;
2229                 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2230         }
2231
2232         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2233         return ((user_cb == NULL) ? -ENOMEM : 0);
2234 }
2235
2236 int
2237 rte_eth_dev_callback_unregister(uint8_t port_id,
2238                         enum rte_eth_event_type event,
2239                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2240 {
2241         int ret;
2242         struct rte_eth_dev *dev;
2243         struct rte_eth_dev_callback *cb, *next;
2244
2245         if (!cb_fn)
2246                 return (-EINVAL);
2247         if (port_id >= nb_ports) {
2248                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2249                 return (-EINVAL);
2250         }
2251
2252         dev = &rte_eth_devices[port_id];
2253         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2254
2255         ret = 0;
2256         for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2257
2258                 next = TAILQ_NEXT(cb, next);
2259
2260                 if (cb->cb_fn != cb_fn || cb->event != event ||
2261                                 (cb->cb_arg != (void *)-1 &&
2262                                 cb->cb_arg != cb_arg))
2263                         continue;
2264
2265                 /*
2266                  * if this callback is not executing right now,
2267                  * then remove it.
2268                  */
2269                 if (cb->active == 0) {
2270                         TAILQ_REMOVE(&(dev->callbacks), cb, next);
2271                         rte_free(cb);
2272                 } else {
2273                         ret = -EAGAIN;
2274                 }
2275         }
2276
2277         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2278         return (ret);
2279 }
2280
2281 void
2282 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2283         enum rte_eth_event_type event)
2284 {
2285         struct rte_eth_dev_callback *cb_lst;
2286         struct rte_eth_dev_callback dev_cb;
2287
2288         rte_spinlock_lock(&rte_eth_dev_cb_lock);
2289         TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2290                 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2291                         continue;
2292                 dev_cb = *cb_lst;
2293                 cb_lst->active = 1;
2294                 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2295                 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2296                                                 dev_cb.cb_arg);
2297                 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2298                 cb_lst->active = 0;
2299         }
2300         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2301 }
2302 #ifdef RTE_NIC_BYPASS
2303 int rte_eth_dev_bypass_init(uint8_t port_id)
2304 {
2305         struct rte_eth_dev *dev;
2306
2307         if (port_id >= nb_ports) {
2308                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2309                 return (-ENODEV);
2310         }
2311
2312         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2313                 PMD_DEBUG_TRACE("Invalid port device\n");
2314                 return (-ENODEV);
2315         }
2316
2317         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2318         (*dev->dev_ops->bypass_init)(dev);
2319         return 0;
2320 }
2321
2322 int
2323 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2324 {
2325         struct rte_eth_dev *dev;
2326
2327         if (port_id >= nb_ports) {
2328                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2329                 return (-ENODEV);
2330         }
2331
2332         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2333                 PMD_DEBUG_TRACE("Invalid port device\n");
2334                 return (-ENODEV);
2335         }
2336         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2337         (*dev->dev_ops->bypass_state_show)(dev, state);
2338         return 0;
2339 }
2340
2341 int
2342 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2343 {
2344         struct rte_eth_dev *dev;
2345
2346         if (port_id >= nb_ports) {
2347                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2348                 return (-ENODEV);
2349         }
2350
2351         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2352                 PMD_DEBUG_TRACE("Invalid port device\n");
2353                 return (-ENODEV);
2354         }
2355
2356         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2357         (*dev->dev_ops->bypass_state_set)(dev, new_state);
2358         return 0;
2359 }
2360
2361 int
2362 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2363 {
2364         struct rte_eth_dev *dev;
2365
2366         if (port_id >= nb_ports) {
2367                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2368                 return (-ENODEV);
2369         }
2370
2371         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2372                 PMD_DEBUG_TRACE("Invalid port device\n");
2373                 return (-ENODEV);
2374         }
2375
2376         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2377         (*dev->dev_ops->bypass_event_show)(dev, event, state);
2378         return 0;
2379 }
2380
2381 int
2382 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2383 {
2384         struct rte_eth_dev *dev;
2385
2386         if (port_id >= nb_ports) {
2387                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2388                 return (-ENODEV);
2389         }
2390
2391         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2392                 PMD_DEBUG_TRACE("Invalid port device\n");
2393                 return (-ENODEV);
2394         }
2395
2396         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2397         (*dev->dev_ops->bypass_event_set)(dev, event, state);
2398         return 0;
2399 }
2400
2401 int
2402 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2403 {
2404         struct rte_eth_dev *dev;
2405
2406         if (port_id >= nb_ports) {
2407                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2408                 return (-ENODEV);
2409         }
2410
2411         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2412                 PMD_DEBUG_TRACE("Invalid port device\n");
2413                 return (-ENODEV);
2414         }
2415
2416         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2417         (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2418         return 0;
2419 }
2420
2421 int
2422 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2423 {
2424         struct rte_eth_dev *dev;
2425
2426         if (port_id >= nb_ports) {
2427                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2428                 return (-ENODEV);
2429         }
2430
2431         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2432                 PMD_DEBUG_TRACE("Invalid port device\n");
2433                 return (-ENODEV);
2434         }
2435
2436         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2437         (*dev->dev_ops->bypass_ver_show)(dev, ver);
2438         return 0;
2439 }
2440
2441 int
2442 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2443 {
2444         struct rte_eth_dev *dev;
2445
2446         if (port_id >= nb_ports) {
2447                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2448                 return (-ENODEV);
2449         }
2450
2451         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2452                 PMD_DEBUG_TRACE("Invalid port device\n");
2453                 return (-ENODEV);
2454         }
2455
2456         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2457         (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2458         return 0;
2459 }
2460
2461 int
2462 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2463 {
2464         struct rte_eth_dev *dev;
2465
2466         if (port_id >= nb_ports) {
2467                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2468                 return (-ENODEV);
2469         }
2470
2471         if ((dev= &rte_eth_devices[port_id]) == NULL) {
2472                 PMD_DEBUG_TRACE("Invalid port device\n");
2473                 return (-ENODEV);
2474         }
2475
2476         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2477         (*dev->dev_ops->bypass_wd_reset)(dev);
2478         return 0;
2479 }
2480 #endif