ethdev: retrieve RX available descriptors
[dpdk.git] / lib / librte_ether / rte_ethdev.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 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
35 #include <sys/types.h>
36 #include <sys/queue.h>
37 #include <ctype.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <stdarg.h>
42 #include <errno.h>
43 #include <stdint.h>
44 #include <inttypes.h>
45
46 #include <rte_byteorder.h>
47 #include <rte_log.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
50 #include <rte_pci.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
55 #include <rte_tailq.h>
56 #include <rte_eal.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_common.h>
62 #include <rte_ring.h>
63 #include <rte_mempool.h>
64 #include <rte_malloc.h>
65 #include <rte_mbuf.h>
66 #include <rte_errno.h>
67 #include <rte_spinlock.h>
68
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
71
72 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
73 #define PMD_DEBUG_TRACE(fmt, args...) do {                        \
74                 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
75         } while (0)
76 #else
77 #define PMD_DEBUG_TRACE(fmt, args...)
78 #endif
79
80 /* Macros for checking for restricting functions to primary instance only */
81 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
82         if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83                 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
84                 return (retval); \
85         } \
86 } while(0)
87 #define PROC_PRIMARY_OR_RET() do { \
88         if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
89                 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
90                 return; \
91         } \
92 } while(0)
93
94 /* Macros to check for invlaid function pointers in dev_ops structure */
95 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
96         if ((func) == NULL) { \
97                 PMD_DEBUG_TRACE("Function not supported\n"); \
98                 return (retval); \
99         } \
100 } while(0)
101 #define FUNC_PTR_OR_RET(func) do { \
102         if ((func) == NULL) { \
103                 PMD_DEBUG_TRACE("Function not supported\n"); \
104                 return; \
105         } \
106 } while(0)
107
108 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
109 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
110 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
111 static uint8_t nb_ports = 0;
112
113 /* spinlock for eth device callbacks */
114 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
115
116 /**
117  * The user application callback description.
118  *
119  * It contains callback address to be registered by user application,
120  * the pointer to the parameters for callback, and the event type.
121  */
122 struct rte_eth_dev_callback {
123         TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
124         rte_eth_dev_cb_fn cb_fn;                /**< Callback address */
125         void *cb_arg;                           /**< Parameter for callback */
126         enum rte_eth_event_type event;          /**< Interrupt event type */
127         uint32_t active;                        /**< Callback is executing */
128 };
129
130 enum {
131         STAT_QMAP_TX = 0,
132         STAT_QMAP_RX
133 };
134
135 static inline void
136 rte_eth_dev_data_alloc(void)
137 {
138         const unsigned flags = 0;
139         const struct rte_memzone *mz;
140
141         if (rte_eal_process_type() == RTE_PROC_PRIMARY){
142                 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
143                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
144                                 rte_socket_id(), flags);
145         } else
146                 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
147         if (mz == NULL)
148                 rte_panic("Cannot allocate memzone for ethernet port data\n");
149
150         rte_eth_dev_data = mz->addr;
151         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
152                 memset(rte_eth_dev_data, 0,
153                                 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
154 }
155
156 static inline struct rte_eth_dev *
157 rte_eth_dev_allocate(void)
158 {
159         struct rte_eth_dev *eth_dev;
160
161         if (nb_ports == RTE_MAX_ETHPORTS) {
162                 PMD_DEBUG_TRACE("Reached maximum number of ethernet ports\n");
163                 return NULL;
164         }
165
166         if (rte_eth_dev_data == NULL)
167                 rte_eth_dev_data_alloc();
168
169         eth_dev = &rte_eth_devices[nb_ports];
170         eth_dev->data = &rte_eth_dev_data[nb_ports];
171         eth_dev->data->port_id = nb_ports++;
172         return eth_dev;
173 }
174
175 static int
176 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
177                  struct rte_pci_device *pci_dev)
178 {
179         struct eth_driver    *eth_drv;
180         struct rte_eth_dev *eth_dev;
181         int diag;
182
183         eth_drv = (struct eth_driver *)pci_drv;
184
185         eth_dev = rte_eth_dev_allocate();
186         if (eth_dev == NULL)
187                 return -ENOMEM;
188
189         if (rte_eal_process_type() == RTE_PROC_PRIMARY){
190                 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
191                                   eth_drv->dev_private_size,
192                                   CACHE_LINE_SIZE);
193                 if (eth_dev->data->dev_private == NULL)
194                         rte_panic("Cannot allocate memzone for private port data\n");
195         }
196         eth_dev->pci_dev = pci_dev;
197         eth_dev->driver = eth_drv;
198         eth_dev->data->rx_mbuf_alloc_failed = 0;
199
200         /* init user callbacks */
201         TAILQ_INIT(&(eth_dev->callbacks));
202
203         /*
204          * Set the default maximum frame size.
205          */
206         eth_dev->data->max_frame_size = ETHER_MAX_LEN;
207
208         /* Invoke PMD device initialization function */
209         diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
210         if (diag == 0)
211                 return (0);
212
213         PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
214                         " failed\n", pci_drv->name,
215                         (unsigned) pci_dev->id.vendor_id,
216                         (unsigned) pci_dev->id.device_id);
217         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
218                 rte_free(eth_dev->data->dev_private);
219         nb_ports--;
220         return diag;
221 }
222
223 /**
224  * Register an Ethernet [Poll Mode] driver.
225  *
226  * Function invoked by the initialization function of an Ethernet driver
227  * to simultaneously register itself as a PCI driver and as an Ethernet
228  * Poll Mode Driver.
229  * Invokes the rte_eal_pci_register() function to register the *pci_drv*
230  * structure embedded in the *eth_drv* structure, after having stored the
231  * address of the rte_eth_dev_init() function in the *devinit* field of
232  * the *pci_drv* structure.
233  * During the PCI probing phase, the rte_eth_dev_init() function is
234  * invoked for each PCI [Ethernet device] matching the embedded PCI
235  * identifiers provided by the driver.
236  */
237 void
238 rte_eth_driver_register(struct eth_driver *eth_drv)
239 {
240         eth_drv->pci_drv.devinit = rte_eth_dev_init;
241         rte_eal_pci_register(&eth_drv->pci_drv);
242 }
243
244 int
245 rte_eth_dev_socket_id(uint8_t port_id)
246 {
247         if (port_id >= nb_ports)
248                 return -1;
249         return rte_eth_devices[port_id].pci_dev->numa_node;
250 }
251
252 uint8_t
253 rte_eth_dev_count(void)
254 {
255         return (nb_ports);
256 }
257
258 static int
259 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
260 {
261         uint16_t old_nb_queues = dev->data->nb_rx_queues;
262         void **rxq;
263         unsigned i;
264
265         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
266
267         if (dev->data->rx_queues == NULL) {
268                 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
269                                 sizeof(dev->data->rx_queues[0]) * nb_queues,
270                                 CACHE_LINE_SIZE);
271                 if (dev->data->rx_queues == NULL) {
272                         dev->data->nb_rx_queues = 0;
273                         return -(ENOMEM);
274                 }
275         } else {
276                 rxq = dev->data->rx_queues;
277
278                 for (i = nb_queues; i < old_nb_queues; i++)
279                         (*dev->dev_ops->rx_queue_release)(rxq[i]);
280                 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
281                                 CACHE_LINE_SIZE);
282                 if (rxq == NULL)
283                         return -(ENOMEM);
284
285                 if (nb_queues > old_nb_queues)
286                         memset(rxq + old_nb_queues, 0,
287                                 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
288
289                 dev->data->rx_queues = rxq;
290
291         }
292         dev->data->nb_rx_queues = nb_queues;
293         return (0);
294 }
295
296 static int
297 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
298 {
299         uint16_t old_nb_queues = dev->data->nb_tx_queues;
300         void **txq;
301         unsigned i;
302
303         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
304
305         if (dev->data->tx_queues == NULL) {
306                 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
307                                 sizeof(dev->data->tx_queues[0]) * nb_queues,
308                                 CACHE_LINE_SIZE);
309                 if (dev->data->tx_queues == NULL) {
310                         dev->data->nb_tx_queues = 0;
311                         return -(ENOMEM);
312                 }
313         } else {
314                 txq = dev->data->tx_queues;
315
316                 for (i = nb_queues; i < old_nb_queues; i++)
317                         (*dev->dev_ops->tx_queue_release)(txq[i]);
318                 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
319                                 CACHE_LINE_SIZE);
320                 if (txq == NULL)
321                         return -(ENOMEM);
322
323                 if (nb_queues > old_nb_queues)
324                         memset(txq + old_nb_queues, 0,
325                                 sizeof(txq[0]) * (nb_queues - old_nb_queues));
326
327                 dev->data->tx_queues = txq;
328
329         }
330         dev->data->nb_tx_queues = nb_queues;
331         return (0);
332 }
333
334 int
335 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
336                       const struct rte_eth_conf *dev_conf)
337 {
338         struct rte_eth_dev *dev;
339         struct rte_eth_dev_info dev_info;
340         int diag;
341
342         /* This function is only safe when called from the primary process
343          * in a multi-process setup*/
344         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
345
346         if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
347                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
348                 return (-EINVAL);
349         }
350         dev = &rte_eth_devices[port_id];
351
352         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
353         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
354
355         if (dev->data->dev_started) {
356                 PMD_DEBUG_TRACE(
357                     "port %d must be stopped to allow configuration\n", port_id);
358                 return (-EBUSY);
359         }
360
361         /*
362          * Check that the numbers of RX and TX queues are not greater
363          * than the maximum number of RX and TX queues supported by the
364          * configured device.
365          */
366         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
367         if (nb_rx_q > dev_info.max_rx_queues) {
368                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
369                                 port_id, nb_rx_q, dev_info.max_rx_queues);
370                 return (-EINVAL);
371         }
372         if (nb_rx_q == 0) {
373                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
374                 return (-EINVAL);
375         }
376
377         if (nb_tx_q > dev_info.max_tx_queues) {
378                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
379                                 port_id, nb_tx_q, dev_info.max_tx_queues);
380                 return (-EINVAL);
381         }
382         if (nb_tx_q == 0) {
383                 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
384                 return (-EINVAL);
385         }
386
387         /* Copy the dev_conf parameter into the dev structure */
388         memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
389
390         /*
391          * If jumbo frames are enabled, check that the maximum RX packet
392          * length is supported by the configured device.
393          */
394         if (dev_conf->rxmode.jumbo_frame == 1) {
395                 if (dev_conf->rxmode.max_rx_pkt_len >
396                     dev_info.max_rx_pktlen) {
397                         PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
398                                 " > max valid value %u\n",
399                                 port_id,
400                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
401                                 (unsigned)dev_info.max_rx_pktlen);
402                         return (-EINVAL);
403                 }
404                 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
405                         PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
406                                 " < min valid value %u\n",
407                                 port_id,
408                                 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
409                                 (unsigned)ETHER_MIN_LEN);
410                         return (-EINVAL);
411                 }
412         } else
413                 /* Use default value */
414                 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
415
416         /* For vmdb+dcb mode check our configuration before we go further */
417         if (dev_conf->rxmode.mq_mode == ETH_VMDQ_DCB) {
418                 const struct rte_eth_vmdq_dcb_conf *conf;
419
420                 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
421                         PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
422                                         "!= %d\n",
423                                         port_id, ETH_VMDQ_DCB_NUM_QUEUES);
424                         return (-EINVAL);
425                 }
426                 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
427                 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
428                        conf->nb_queue_pools == ETH_32_POOLS)) {
429                     PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
430                                     "nb_queue_pools must be %d or %d\n",
431                                     port_id, ETH_16_POOLS, ETH_32_POOLS);
432                     return (-EINVAL);
433                 }
434         }
435         if (dev_conf->txmode.mq_mode == ETH_VMDQ_DCB_TX) {
436                 const struct rte_eth_vmdq_dcb_tx_conf *conf;
437
438                 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
439                         PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
440                                         "!= %d\n",
441                                         port_id, ETH_VMDQ_DCB_NUM_QUEUES);
442                         return (-EINVAL);
443                 }
444                 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
445                 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
446                        conf->nb_queue_pools == ETH_32_POOLS)) {
447                         PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
448                                     "nb_queue_pools != %d or nb_queue_pools "
449                                     "!= %d\n",
450                                     port_id, ETH_16_POOLS, ETH_32_POOLS);
451                         return (-EINVAL);
452                 }
453         }
454         
455         /* For DCB mode check our configuration before we go further */
456         if (dev_conf->rxmode.mq_mode == ETH_DCB_RX) {
457                 const struct rte_eth_dcb_rx_conf *conf;
458
459                 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
460                         PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
461                                         "!= %d\n",
462                                         port_id, ETH_DCB_NUM_QUEUES);
463                         return (-EINVAL);
464                 }
465                 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
466                 if (! (conf->nb_tcs == ETH_4_TCS ||
467                        conf->nb_tcs == ETH_8_TCS)) {
468                         PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
469                                     "nb_tcs != %d or nb_tcs "
470                                     "!= %d\n",
471                                     port_id, ETH_4_TCS, ETH_8_TCS);
472                         return (-EINVAL);
473                 }
474         }
475
476         if (dev_conf->txmode.mq_mode == ETH_DCB_TX) {
477                 const struct rte_eth_dcb_tx_conf *conf;
478
479                 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
480                         PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
481                                         "!= %d\n",
482                                         port_id, ETH_DCB_NUM_QUEUES);
483                         return (-EINVAL);
484                 }
485                 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
486                 if (! (conf->nb_tcs == ETH_4_TCS ||
487                        conf->nb_tcs == ETH_8_TCS)) {
488                         PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
489                                     "nb_tcs != %d or nb_tcs "
490                                     "!= %d\n",
491                                     port_id, ETH_4_TCS, ETH_8_TCS);
492                         return (-EINVAL);
493                 }
494         }
495
496         /*
497          * Setup new number of RX/TX queues and reconfigure device.
498          */
499         diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
500         if (diag != 0) {
501                 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
502                                 port_id, diag);
503                 return diag;
504         }
505
506         diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
507         if (diag != 0) {
508                 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
509                                 port_id, diag);
510                 rte_eth_dev_rx_queue_config(dev, 0);
511                 return diag;
512         }
513
514         diag = (*dev->dev_ops->dev_configure)(dev);
515         if (diag != 0) {
516                 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
517                                 port_id, diag);
518                 rte_eth_dev_rx_queue_config(dev, 0);
519                 rte_eth_dev_tx_queue_config(dev, 0);
520                 return diag;
521         }
522
523         return 0;
524 }
525
526 static void
527 rte_eth_dev_config_restore(uint8_t port_id)
528 {
529         struct rte_eth_dev *dev;
530         struct rte_eth_dev_info dev_info;
531         struct ether_addr addr;
532         uint16_t i;
533
534         dev = &rte_eth_devices[port_id];
535
536         rte_eth_dev_info_get(port_id, &dev_info);
537
538         /* replay MAC address configuration */
539         for (i = 0; i < dev_info.max_mac_addrs; i++) {
540                 addr = dev->data->mac_addrs[i];
541
542                 /* skip zero address */
543                 if (is_zero_ether_addr(&addr))
544                         continue;
545
546                 /* add address to the hardware */
547                 if  (*dev->dev_ops->mac_addr_add)
548                         (*dev->dev_ops->mac_addr_add)(dev, &addr, i, 0);
549                 else {
550                         PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
551                                         port_id);
552                         /* exit the loop but not return an error */
553                         break;
554                 }
555         }
556
557         /* replay promiscuous configuration */
558         if (rte_eth_promiscuous_get(port_id) == 1)
559                 rte_eth_promiscuous_enable(port_id);
560         else if (rte_eth_promiscuous_get(port_id) == 0)
561                 rte_eth_promiscuous_disable(port_id);
562
563         /* replay allmulticast configuration */
564         if (rte_eth_allmulticast_get(port_id) == 1)
565                 rte_eth_allmulticast_enable(port_id);
566         else if (rte_eth_allmulticast_get(port_id) == 0)
567                 rte_eth_allmulticast_disable(port_id);
568 }
569
570 int
571 rte_eth_dev_start(uint8_t port_id)
572 {
573         struct rte_eth_dev *dev;
574         int diag;
575
576         /* This function is only safe when called from the primary process
577          * in a multi-process setup*/
578         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
579
580         if (port_id >= nb_ports) {
581                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
582                 return (-EINVAL);
583         }
584         dev = &rte_eth_devices[port_id];
585
586         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
587         diag = (*dev->dev_ops->dev_start)(dev);
588         if (diag == 0)
589                 dev->data->dev_started = 1;
590         else
591                 return diag;
592
593         rte_eth_dev_config_restore(port_id);
594
595         return 0;
596 }
597
598 void
599 rte_eth_dev_stop(uint8_t port_id)
600 {
601         struct rte_eth_dev *dev;
602
603         /* This function is only safe when called from the primary process
604          * in a multi-process setup*/
605         PROC_PRIMARY_OR_RET();
606
607         if (port_id >= nb_ports) {
608                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
609                 return;
610         }
611         dev = &rte_eth_devices[port_id];
612
613         FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
614         dev->data->dev_started = 0;
615         (*dev->dev_ops->dev_stop)(dev);
616 }
617
618 void
619 rte_eth_dev_close(uint8_t port_id)
620 {
621         struct rte_eth_dev *dev;
622
623         /* This function is only safe when called from the primary process
624          * in a multi-process setup*/
625         PROC_PRIMARY_OR_RET();
626
627         if (port_id >= nb_ports) {
628                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
629                 return;
630         }
631
632         dev = &rte_eth_devices[port_id];
633
634         FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
635         dev->data->dev_started = 0;
636         (*dev->dev_ops->dev_close)(dev);
637 }
638
639 int
640 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
641                        uint16_t nb_rx_desc, unsigned int socket_id,
642                        const struct rte_eth_rxconf *rx_conf,
643                        struct rte_mempool *mp)
644 {
645         struct rte_eth_dev *dev;
646         struct rte_pktmbuf_pool_private *mbp_priv;
647         struct rte_eth_dev_info dev_info;
648
649         /* This function is only safe when called from the primary process
650          * in a multi-process setup*/
651         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
652
653         if (port_id >= nb_ports) {
654                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
655                 return (-EINVAL);
656         }
657         dev = &rte_eth_devices[port_id];
658         if (rx_queue_id >= dev->data->nb_rx_queues) {
659                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
660                 return (-EINVAL);
661         }
662
663         if (dev->data->dev_started) {
664                 PMD_DEBUG_TRACE(
665                     "port %d must be stopped to allow configuration\n", port_id);
666                 return -EBUSY;
667         }
668
669         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
670         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
671
672         /*
673          * Check the size of the mbuf data buffer.
674          * This value must be provided in the private data of the memory pool.
675          * First check that the memory pool has a valid private data.
676          */
677         (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
678         if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
679                 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
680                                 mp->name, (int) mp->private_data_size,
681                                 (int) sizeof(struct rte_pktmbuf_pool_private));
682                 return (-ENOSPC);
683         }
684         mbp_priv = (struct rte_pktmbuf_pool_private *)
685                 ((char *)mp + sizeof(struct rte_mempool));
686         if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
687             dev_info.min_rx_bufsize) {
688                 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
689                                 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
690                                 "=%d)\n",
691                                 mp->name,
692                                 (int)mbp_priv->mbuf_data_room_size,
693                                 (int)(RTE_PKTMBUF_HEADROOM +
694                                       dev_info.min_rx_bufsize),
695                                 (int)RTE_PKTMBUF_HEADROOM,
696                                 (int)dev_info.min_rx_bufsize);
697                 return (-EINVAL);
698         }
699
700         return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
701                                                socket_id, rx_conf, mp);
702 }
703
704 int
705 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
706                        uint16_t nb_tx_desc, unsigned int socket_id,
707                        const struct rte_eth_txconf *tx_conf)
708 {
709         struct rte_eth_dev *dev;
710
711         /* This function is only safe when called from the primary process
712          * in a multi-process setup*/
713         PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
714
715         if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
716                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
717                 return (-EINVAL);
718         }
719         dev = &rte_eth_devices[port_id];
720         if (tx_queue_id >= dev->data->nb_tx_queues) {
721                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
722                 return (-EINVAL);
723         }
724
725         if (dev->data->dev_started) {
726                 PMD_DEBUG_TRACE(
727                     "port %d must be stopped to allow configuration\n", port_id);
728                 return -EBUSY;
729         }
730
731         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
732         return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
733                                                socket_id, tx_conf);
734 }
735
736 void
737 rte_eth_promiscuous_enable(uint8_t port_id)
738 {
739         struct rte_eth_dev *dev;
740
741         if (port_id >= nb_ports) {
742                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
743                 return;
744         }
745         dev = &rte_eth_devices[port_id];
746
747         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
748         (*dev->dev_ops->promiscuous_enable)(dev);
749         dev->data->promiscuous = 1;
750 }
751
752 void
753 rte_eth_promiscuous_disable(uint8_t port_id)
754 {
755         struct rte_eth_dev *dev;
756
757         if (port_id >= nb_ports) {
758                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
759                 return;
760         }
761         dev = &rte_eth_devices[port_id];
762
763         FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
764         dev->data->promiscuous = 0;
765         (*dev->dev_ops->promiscuous_disable)(dev);
766 }
767
768 int
769 rte_eth_promiscuous_get(uint8_t port_id)
770 {
771         struct rte_eth_dev *dev;
772
773         if (port_id >= nb_ports) {
774                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
775                 return -1;
776         }
777
778         dev = &rte_eth_devices[port_id];
779         return dev->data->promiscuous;
780 }
781
782 void
783 rte_eth_allmulticast_enable(uint8_t port_id)
784 {
785         struct rte_eth_dev *dev;
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->allmulticast_enable);
794         (*dev->dev_ops->allmulticast_enable)(dev);
795         dev->data->all_multicast = 1;
796 }
797
798 void
799 rte_eth_allmulticast_disable(uint8_t port_id)
800 {
801         struct rte_eth_dev *dev;
802
803         if (port_id >= nb_ports) {
804                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
805                 return;
806         }
807         dev = &rte_eth_devices[port_id];
808
809         FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
810         dev->data->all_multicast = 0;
811         (*dev->dev_ops->allmulticast_disable)(dev);
812 }
813
814 int
815 rte_eth_allmulticast_get(uint8_t port_id)
816 {
817         struct rte_eth_dev *dev;
818
819         if (port_id >= nb_ports) {
820                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
821                 return -1;
822         }
823
824         dev = &rte_eth_devices[port_id];
825         return dev->data->all_multicast;
826 }
827
828 static inline int
829 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
830                                 struct rte_eth_link *link)
831 {
832         struct rte_eth_link *dst = link;
833         struct rte_eth_link *src = &(dev->data->dev_link);
834
835         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
836                                         *(uint64_t *)src) == 0)
837                 return -1;
838
839         return 0;
840 }
841
842 void
843 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
844 {
845         struct rte_eth_dev *dev;
846
847         if (port_id >= nb_ports) {
848                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
849                 return;
850         }
851         dev = &rte_eth_devices[port_id];
852         FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
853
854         if (dev->data->dev_conf.intr_conf.lsc != 0)
855                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
856         else {
857                 (*dev->dev_ops->link_update)(dev, 1);
858                 *eth_link = dev->data->dev_link;
859         }
860 }
861
862 void
863 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
864 {
865         struct rte_eth_dev *dev;
866
867         if (port_id >= nb_ports) {
868                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
869                 return;
870         }
871         dev = &rte_eth_devices[port_id];
872         FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
873
874         if (dev->data->dev_conf.intr_conf.lsc != 0)
875                 rte_eth_dev_atomic_read_link_status(dev, eth_link);
876         else {
877                 (*dev->dev_ops->link_update)(dev, 0);
878                 *eth_link = dev->data->dev_link;
879         }
880 }
881
882 void
883 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
884 {
885         struct rte_eth_dev *dev;
886
887         if (port_id >= nb_ports) {
888                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
889                 return;
890         }
891         dev = &rte_eth_devices[port_id];
892
893         FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
894         (*dev->dev_ops->stats_get)(dev, stats);
895         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
896 }
897
898 void
899 rte_eth_stats_reset(uint8_t port_id)
900 {
901         struct rte_eth_dev *dev;
902
903         if (port_id >= nb_ports) {
904                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
905                 return;
906         }
907         dev = &rte_eth_devices[port_id];
908
909         FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
910         (*dev->dev_ops->stats_reset)(dev);
911 }
912
913
914 static int
915 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
916                 uint8_t is_rx)
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 -ENODEV;
923         }
924         dev = &rte_eth_devices[port_id];
925
926         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
927         return (*dev->dev_ops->queue_stats_mapping_set)
928                         (dev, queue_id, stat_idx, is_rx);
929 }
930
931
932 int
933 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
934                 uint8_t stat_idx)
935 {
936         return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
937                         STAT_QMAP_TX);
938 }
939
940
941 int
942 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
943                 uint8_t stat_idx)
944 {
945         return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
946                         STAT_QMAP_RX);
947 }
948
949
950 void
951 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
952 {
953         struct rte_eth_dev *dev;
954
955         if (port_id >= nb_ports) {
956                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
957                 return;
958         }
959         dev = &rte_eth_devices[port_id];
960
961         FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
962         (*dev->dev_ops->dev_infos_get)(dev, dev_info);
963         dev_info->pci_dev = dev->pci_dev;
964         dev_info->driver_name = dev->driver->pci_drv.name;
965 }
966
967 void
968 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
969 {
970         struct rte_eth_dev *dev;
971
972         if (port_id >= nb_ports) {
973                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
974                 return;
975         }
976         dev = &rte_eth_devices[port_id];
977         ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
978 }
979
980 int
981 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
982 {
983         struct rte_eth_dev *dev;
984
985         if (port_id >= nb_ports) {
986                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
987                 return (-ENODEV);
988         }
989         dev = &rte_eth_devices[port_id];
990         if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
991                 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
992                 return (-ENOSYS);
993         }
994
995         if (vlan_id > 4095) {
996                 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
997                                 port_id, (unsigned) vlan_id);
998                 return (-EINVAL);
999         }
1000         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1001         (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1002         return (0);
1003 }
1004
1005 int
1006 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1007 {
1008         struct rte_eth_dev *dev;
1009
1010         if (port_id >= nb_ports) {
1011                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1012                 return (-ENODEV);
1013         }
1014
1015         dev = &rte_eth_devices[port_id];
1016         if (rx_queue_id >= dev->data->nb_rx_queues) {
1017                 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1018                 return (-EINVAL);
1019         }
1020
1021         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1022         (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1023
1024         return (0);
1025 }
1026
1027 int
1028 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1029 {
1030         struct rte_eth_dev *dev;
1031
1032         if (port_id >= nb_ports) {
1033                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1034                 return (-ENODEV);
1035         }
1036
1037         dev = &rte_eth_devices[port_id];
1038         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1039         (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1040
1041         return (0);
1042 }
1043
1044 int
1045 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1046 {
1047         struct rte_eth_dev *dev;
1048         int ret = 0;
1049         int mask = 0;
1050         int cur, org = 0;
1051         
1052         if (port_id >= nb_ports) {
1053                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1054                 return (-ENODEV);
1055         }
1056
1057         dev = &rte_eth_devices[port_id];
1058
1059         /*check which option changed by application*/
1060         cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1061         org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1062         if (cur != org){
1063                 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1064                 mask |= ETH_VLAN_STRIP_MASK;
1065         }
1066         
1067         cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1068         org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1069         if (cur != org){
1070                 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1071                 mask |= ETH_VLAN_FILTER_MASK;
1072         }
1073
1074         cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1075         org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1076         if (cur != org){
1077                 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1078                 mask |= ETH_VLAN_EXTEND_MASK;
1079         }
1080
1081         /*no change*/
1082         if(mask == 0)
1083                 return ret;
1084         
1085         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1086         (*dev->dev_ops->vlan_offload_set)(dev, mask);
1087
1088         return ret;
1089 }
1090
1091 int
1092 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1093 {
1094         struct rte_eth_dev *dev;
1095         int ret = 0;
1096
1097         if (port_id >= nb_ports) {
1098                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1099                 return (-ENODEV);
1100         }
1101
1102         dev = &rte_eth_devices[port_id];
1103
1104         if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1105                 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1106
1107         if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1108                 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1109
1110         if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1111                 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1112
1113         return ret;
1114 }
1115
1116
1117 int
1118 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1119                                       struct rte_fdir_filter *fdir_filter,
1120                                       uint8_t queue)
1121 {
1122         struct rte_eth_dev *dev;
1123
1124         if (port_id >= nb_ports) {
1125                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1126                 return (-ENODEV);
1127         }
1128
1129         dev = &rte_eth_devices[port_id];
1130
1131         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1132                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1133                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1134                 return (-ENOSYS);
1135         }
1136
1137         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1138              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1139             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1140                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1141                                 "None l4type, source & destinations ports " \
1142                                 "should be null!\n");
1143                 return (-EINVAL);
1144         }
1145
1146         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1147         return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1148                                                                 queue);
1149 }
1150
1151 int
1152 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1153                                          struct rte_fdir_filter *fdir_filter,
1154                                          uint8_t queue)
1155 {
1156         struct rte_eth_dev *dev;
1157
1158         if (port_id >= nb_ports) {
1159                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1160                 return (-ENODEV);
1161         }
1162
1163         dev = &rte_eth_devices[port_id];
1164
1165         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1166                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1167                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1168                 return (-ENOSYS);
1169         }
1170
1171         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1172              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1173             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1174                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1175                                 "None l4type, source & destinations ports " \
1176                                 "should be null!\n");
1177                 return (-EINVAL);
1178         }
1179
1180         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1181         return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1182                                                                 queue);
1183
1184 }
1185
1186 int
1187 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1188                                          struct rte_fdir_filter *fdir_filter)
1189 {
1190         struct rte_eth_dev *dev;
1191
1192         if (port_id >= nb_ports) {
1193                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1194                 return (-ENODEV);
1195         }
1196
1197         dev = &rte_eth_devices[port_id];
1198
1199         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1200                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1201                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1202                 return (-ENOSYS);
1203         }
1204
1205         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1206              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1207             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1208                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1209                                 "None l4type source & destinations ports " \
1210                                 "should be null!\n");
1211                 return (-EINVAL);
1212         }
1213
1214         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1215         return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1216 }
1217
1218 int
1219 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1220 {
1221         struct rte_eth_dev *dev;
1222
1223         if (port_id >= nb_ports) {
1224                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1225                 return (-ENODEV);
1226         }
1227
1228         dev = &rte_eth_devices[port_id];
1229         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1230                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1231                 return (-ENOSYS);
1232         }
1233
1234         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1235
1236         (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1237         return (0);
1238 }
1239
1240 int
1241 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1242                                     struct rte_fdir_filter *fdir_filter,
1243                                     uint16_t soft_id, uint8_t queue,
1244                                     uint8_t drop)
1245 {
1246         struct rte_eth_dev *dev;
1247
1248         if (port_id >= nb_ports) {
1249                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1250                 return (-ENODEV);
1251         }
1252
1253         dev = &rte_eth_devices[port_id];
1254
1255         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1256                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1257                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1258                 return (-ENOSYS);
1259         }
1260
1261         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1262              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1263             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1264                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1265                                 "None l4type, source & destinations ports " \
1266                                 "should be null!\n");
1267                 return (-EINVAL);
1268         }
1269
1270         /* For now IPv6 is not supported with perfect filter */
1271         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1272                 return (-ENOTSUP);
1273
1274         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1275         return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1276                                                                 soft_id, queue,
1277                                                                 drop);
1278 }
1279
1280 int
1281 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1282                                        struct rte_fdir_filter *fdir_filter,
1283                                        uint16_t soft_id, uint8_t queue,
1284                                        uint8_t drop)
1285 {
1286         struct rte_eth_dev *dev;
1287
1288         if (port_id >= nb_ports) {
1289                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1290                 return (-ENODEV);
1291         }
1292
1293         dev = &rte_eth_devices[port_id];
1294
1295         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1296                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1297                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1298                 return (-ENOSYS);
1299         }
1300
1301         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1302              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1303             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1304                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1305                                 "None l4type, source & destinations ports " \
1306                                 "should be null!\n");
1307                 return (-EINVAL);
1308         }
1309
1310         /* For now IPv6 is not supported with perfect filter */
1311         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1312                 return (-ENOTSUP);
1313
1314         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1315         return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1316                                                         soft_id, queue, drop);
1317 }
1318
1319 int
1320 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1321                                        struct rte_fdir_filter *fdir_filter,
1322                                        uint16_t soft_id)
1323 {
1324         struct rte_eth_dev *dev;
1325
1326         if (port_id >= nb_ports) {
1327                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1328                 return (-ENODEV);
1329         }
1330
1331         dev = &rte_eth_devices[port_id];
1332
1333         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1334                 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1335                                 port_id, dev->data->dev_conf.fdir_conf.mode);
1336                 return (-ENOSYS);
1337         }
1338
1339         if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1340              || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1341             && (fdir_filter->port_src || fdir_filter->port_dst)) {
1342                 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1343                                 "None l4type, source & destinations ports " \
1344                                 "should be null!\n");
1345                 return (-EINVAL);
1346         }
1347
1348         /* For now IPv6 is not supported with perfect filter */
1349         if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1350                 return (-ENOTSUP);
1351
1352         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1353         return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1354                                                                 soft_id);
1355 }
1356
1357 int
1358 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1359 {
1360         struct rte_eth_dev *dev;
1361
1362         if (port_id >= nb_ports) {
1363                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1364                 return (-ENODEV);
1365         }
1366
1367         dev = &rte_eth_devices[port_id];
1368         if (! (dev->data->dev_conf.fdir_conf.mode)) {
1369                 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1370                 return (-ENOSYS);
1371         }
1372
1373         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1374         return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1375 }
1376
1377 int
1378 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1379 {
1380         struct rte_eth_dev *dev;
1381
1382         if (port_id >= nb_ports) {
1383                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1384                 return (-ENODEV);
1385         }
1386
1387         if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1388                 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1389                 return (-EINVAL);
1390         }
1391
1392         dev = &rte_eth_devices[port_id];
1393         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1394         return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1395 }
1396
1397 int
1398 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1399 {
1400         struct rte_eth_dev *dev;
1401
1402         if (port_id >= nb_ports) {
1403                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1404                 return (-ENODEV);
1405         }
1406
1407         if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1408                 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1409                 return (-EINVAL);
1410         }
1411
1412         dev = &rte_eth_devices[port_id];
1413         /* High water, low water validation are device specific */
1414         if  (*dev->dev_ops->priority_flow_ctrl_set)
1415                 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1416         return (-ENOTSUP);
1417 }
1418
1419 int
1420 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1421 {
1422         struct rte_eth_dev *dev;
1423         uint8_t i,j;
1424
1425         if (port_id >= nb_ports) {
1426                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1427                 return (-ENODEV);
1428         }
1429
1430         /* Invalid mask bit(s) setting */
1431         if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1432                 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1433                 return (-EINVAL);
1434         }
1435
1436         if (reta_conf->mask_lo != 0) {
1437                 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1438                         if ((reta_conf->mask_lo & (1ULL << i)) &&
1439                                 (reta_conf->reta[i] >= ETH_RSS_RETA_MAX_QUEUE)) {
1440                                 PMD_DEBUG_TRACE("RETA hash index output"
1441                                         "configration for port=%d,invalid"
1442                                         "queue=%d\n",port_id,reta_conf->reta[i]);
1443
1444                                 return (-EINVAL);
1445                         } 
1446                 }
1447         }
1448
1449         if (reta_conf->mask_hi != 0) {
1450                 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {       
1451                         j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1452
1453                         /* Check if the max entry >= 128 */
1454                         if ((reta_conf->mask_hi & (1ULL << i)) && 
1455                                 (reta_conf->reta[j] >= ETH_RSS_RETA_MAX_QUEUE)) {
1456                                 PMD_DEBUG_TRACE("RETA hash index output"
1457                                         "configration for port=%d,invalid"
1458                                         "queue=%d\n",port_id,reta_conf->reta[j]);
1459
1460                                 return (-EINVAL);
1461                         }
1462                 }
1463         }
1464
1465         dev = &rte_eth_devices[port_id];
1466
1467         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1468         return (*dev->dev_ops->reta_update)(dev, reta_conf);
1469 }
1470
1471 int 
1472 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1473 {
1474         struct rte_eth_dev *dev;
1475         
1476         if (port_id >= nb_ports) {
1477                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1478                 return (-ENODEV);
1479         }
1480
1481         if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1482                 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1483                 return (-EINVAL);
1484         }
1485
1486         dev = &rte_eth_devices[port_id];
1487         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1488         return (*dev->dev_ops->reta_query)(dev, reta_conf);
1489 }
1490
1491 int
1492 rte_eth_led_on(uint8_t port_id)
1493 {
1494         struct rte_eth_dev *dev;
1495
1496         if (port_id >= nb_ports) {
1497                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1498                 return (-ENODEV);
1499         }
1500
1501         dev = &rte_eth_devices[port_id];
1502         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1503         return ((*dev->dev_ops->dev_led_on)(dev));
1504 }
1505
1506 int
1507 rte_eth_led_off(uint8_t port_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         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1518         return ((*dev->dev_ops->dev_led_off)(dev));
1519 }
1520
1521 /*
1522  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1523  * an empty spot.
1524  */
1525 static inline int
1526 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1527 {
1528         struct rte_eth_dev_info dev_info;
1529         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1530         unsigned i;
1531
1532         rte_eth_dev_info_get(port_id, &dev_info);
1533
1534         for (i = 0; i < dev_info.max_mac_addrs; i++)
1535                 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1536                         return i;
1537
1538         return -1;
1539 }
1540
1541 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1542
1543 int
1544 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1545                 uint32_t pool)
1546 {
1547         struct rte_eth_dev *dev;
1548         int index;
1549
1550         if (port_id >= nb_ports) {
1551                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1552                 return (-ENODEV);
1553         }
1554         dev = &rte_eth_devices[port_id];
1555         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1556
1557         if (is_zero_ether_addr(addr)) {
1558                 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
1559                 return (-EINVAL);
1560         }
1561
1562         /* Check if it's already there, and do nothing */
1563         index = get_mac_addr_index(port_id, addr);
1564         if (index >= 0)
1565                 return 0;
1566
1567         index = get_mac_addr_index(port_id, &null_mac_addr);
1568         if (index < 0) {
1569                 PMD_DEBUG_TRACE("port %d: MAC address array full\n", port_id);
1570                 return (-ENOSPC);
1571         }
1572
1573         /* Update NIC */
1574         (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1575
1576         /* Update address in NIC data structure */
1577         ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1578
1579         return 0;
1580 }
1581
1582 int
1583 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1584 {
1585         struct rte_eth_dev *dev;
1586         int index;
1587
1588         if (port_id >= nb_ports) {
1589                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1590                 return (-ENODEV);
1591         }
1592         dev = &rte_eth_devices[port_id];
1593         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1594
1595         index = get_mac_addr_index(port_id, addr);
1596         if (index == 0) {
1597                 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1598                 return (-EADDRINUSE);
1599         } else if (index < 0)
1600                 return 0;  /* Do nothing if address wasn't found */
1601
1602         /* Update NIC */
1603         (*dev->dev_ops->mac_addr_remove)(dev, index);
1604
1605         /* Update address in NIC data structure */
1606         ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1607
1608         return 0;
1609 }
1610
1611 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1612 uint16_t
1613 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
1614                  struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1615 {
1616         struct rte_eth_dev *dev;
1617
1618         if (port_id >= nb_ports) {
1619                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1620                 return 0;
1621         }
1622         dev = &rte_eth_devices[port_id];
1623         FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
1624         if (queue_id >= dev->data->nb_rx_queues) {
1625                 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
1626                 return 0;
1627         }
1628         return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
1629                                                 rx_pkts, nb_pkts);
1630 }
1631
1632 uint16_t
1633 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
1634                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1635 {
1636         struct rte_eth_dev *dev;
1637
1638         if (port_id >= nb_ports) {
1639                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1640                 return 0;
1641         }
1642         dev = &rte_eth_devices[port_id];
1643
1644         FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
1645         if (queue_id >= dev->data->nb_tx_queues) {
1646                 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
1647                 return 0;
1648         }
1649         return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
1650                                                 tx_pkts, nb_pkts);
1651 }
1652
1653 uint32_t
1654 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
1655 {
1656         struct rte_eth_dev *dev;
1657
1658         if (port_id >= nb_ports) {
1659                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1660                 return 0;
1661         }
1662         dev = &rte_eth_devices[port_id];
1663         FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
1664         return (*dev->dev_ops->rx_queue_count)(dev, queue_id);  
1665 }
1666 #endif
1667
1668 int
1669 rte_eth_dev_callback_register(uint8_t port_id,
1670                         enum rte_eth_event_type event,
1671                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1672 {
1673         struct rte_eth_dev *dev;
1674         struct rte_eth_dev_callback *user_cb;
1675
1676         if (!cb_fn)
1677                 return (-EINVAL);
1678         if (port_id >= nb_ports) {
1679                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1680                 return (-EINVAL);
1681         }
1682
1683         dev = &rte_eth_devices[port_id];
1684         rte_spinlock_lock(&rte_eth_dev_cb_lock);
1685
1686         TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
1687                 if (user_cb->cb_fn == cb_fn &&
1688                         user_cb->cb_arg == cb_arg &&
1689                         user_cb->event == event) {
1690                         break;
1691                 }
1692         }
1693
1694         /* create a new callback. */
1695         if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1696                         sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
1697                 user_cb->cb_fn = cb_fn;
1698                 user_cb->cb_arg = cb_arg;
1699                 user_cb->event = event;
1700                 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
1701         }
1702
1703         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1704         return ((user_cb == NULL) ? -ENOMEM : 0);
1705 }
1706
1707 int
1708 rte_eth_dev_callback_unregister(uint8_t port_id,
1709                         enum rte_eth_event_type event,
1710                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1711 {
1712         int ret;
1713         struct rte_eth_dev *dev;
1714         struct rte_eth_dev_callback *cb, *next;
1715
1716         if (!cb_fn)
1717                 return (-EINVAL);
1718         if (port_id >= nb_ports) {
1719                 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1720                 return (-EINVAL);
1721         }
1722
1723         dev = &rte_eth_devices[port_id];
1724         rte_spinlock_lock(&rte_eth_dev_cb_lock);
1725
1726         ret = 0;
1727         for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
1728
1729                 next = TAILQ_NEXT(cb, next);
1730
1731                 if (cb->cb_fn != cb_fn || cb->event != event ||
1732                                 (cb->cb_arg != (void *)-1 &&
1733                                 cb->cb_arg != cb_arg))
1734                         continue;
1735
1736                 /*
1737                  * if this callback is not executing right now,
1738                  * then remove it.
1739                  */
1740                 if (cb->active == 0) {
1741                         TAILQ_REMOVE(&(dev->callbacks), cb, next);
1742                         rte_free(cb);
1743                 } else {
1744                         ret = -EAGAIN;
1745                 }
1746         }
1747
1748         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1749         return (ret);
1750 }
1751
1752 void
1753 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
1754         enum rte_eth_event_type event)
1755 {
1756         struct rte_eth_dev_callback *cb_lst;
1757         struct rte_eth_dev_callback dev_cb;
1758
1759         rte_spinlock_lock(&rte_eth_dev_cb_lock);
1760         TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1761                 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1762                         continue;
1763                 dev_cb = *cb_lst;
1764                 cb_lst->active = 1;
1765                 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1766                 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
1767                                                 dev_cb.cb_arg);
1768                 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1769                 cb_lst->active = 0;
1770         }
1771         rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1772 }