New upstream version 16.11.8
[deb_dpdk.git] / app / test / virtual_pmd.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 <rte_mbuf.h>
35 #include <rte_ethdev.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38 #include <rte_memory.h>
39 #include <rte_ring.h>
40
41 #include "virtual_pmd.h"
42
43 #define MAX_PKT_BURST 512
44
45 static const char *virtual_ethdev_driver_name = "Virtual PMD";
46
47 struct virtual_ethdev_private {
48         struct eth_dev_ops dev_ops;
49         struct rte_eth_stats eth_stats;
50
51         struct rte_ring *rx_queue;
52         struct rte_ring *tx_queue;
53
54         int tx_burst_fail_count;
55 };
56
57 struct virtual_ethdev_queue {
58         int port_id;
59         int queue_id;
60 };
61
62 static int
63 virtual_ethdev_start_success(struct rte_eth_dev *eth_dev __rte_unused)
64 {
65         eth_dev->data->dev_started = 1;
66
67         return 0;
68 }
69
70 static int
71 virtual_ethdev_start_fail(struct rte_eth_dev *eth_dev __rte_unused)
72 {
73         eth_dev->data->dev_started = 0;
74
75         return -1;
76 }
77 static void  virtual_ethdev_stop(struct rte_eth_dev *eth_dev __rte_unused)
78 {
79         void *pkt = NULL;
80         struct virtual_ethdev_private *prv = eth_dev->data->dev_private;
81
82         eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
83         eth_dev->data->dev_started = 0;
84         while (rte_ring_dequeue(prv->rx_queue, &pkt) != -ENOENT)
85                 rte_pktmbuf_free(pkt);
86
87         while (rte_ring_dequeue(prv->tx_queue, &pkt) != -ENOENT)
88                 rte_pktmbuf_free(pkt);
89 }
90
91 static void
92 virtual_ethdev_close(struct rte_eth_dev *dev __rte_unused)
93 {}
94
95 static int
96 virtual_ethdev_configure_success(struct rte_eth_dev *dev __rte_unused)
97 {
98         return 0;
99 }
100
101 static int
102 virtual_ethdev_configure_fail(struct rte_eth_dev *dev __rte_unused)
103 {
104         return -1;
105 }
106
107 static void
108 virtual_ethdev_info_get(struct rte_eth_dev *dev __rte_unused,
109                 struct rte_eth_dev_info *dev_info)
110 {
111         dev_info->driver_name = virtual_ethdev_driver_name;
112         dev_info->max_mac_addrs = 1;
113
114         dev_info->max_rx_pktlen = (uint32_t)2048;
115
116         dev_info->max_rx_queues = (uint16_t)128;
117         dev_info->max_tx_queues = (uint16_t)512;
118
119         dev_info->min_rx_bufsize = 0;
120         dev_info->pci_dev = NULL;
121 }
122
123 static int
124 virtual_ethdev_rx_queue_setup_success(struct rte_eth_dev *dev,
125                 uint16_t rx_queue_id, uint16_t nb_rx_desc __rte_unused,
126                 unsigned int socket_id,
127                 const struct rte_eth_rxconf *rx_conf __rte_unused,
128                 struct rte_mempool *mb_pool __rte_unused)
129 {
130         struct virtual_ethdev_queue *rx_q;
131
132         rx_q = (struct virtual_ethdev_queue *)rte_zmalloc_socket(NULL,
133                         sizeof(struct virtual_ethdev_queue), 0, socket_id);
134
135         if (rx_q == NULL)
136                 return -1;
137
138         rx_q->port_id = dev->data->port_id;
139         rx_q->queue_id = rx_queue_id;
140
141         dev->data->rx_queues[rx_queue_id] = rx_q;
142
143         return 0;
144 }
145
146 static int
147 virtual_ethdev_rx_queue_setup_fail(struct rte_eth_dev *dev __rte_unused,
148                 uint16_t rx_queue_id __rte_unused, uint16_t nb_rx_desc __rte_unused,
149                 unsigned int socket_id __rte_unused,
150                 const struct rte_eth_rxconf *rx_conf __rte_unused,
151                 struct rte_mempool *mb_pool __rte_unused)
152 {
153         return -1;
154 }
155
156 static int
157 virtual_ethdev_tx_queue_setup_success(struct rte_eth_dev *dev,
158                 uint16_t tx_queue_id, uint16_t nb_tx_desc __rte_unused,
159                 unsigned int socket_id,
160                 const struct rte_eth_txconf *tx_conf __rte_unused)
161 {
162         struct virtual_ethdev_queue *tx_q;
163
164         tx_q = (struct virtual_ethdev_queue *)rte_zmalloc_socket(NULL,
165                         sizeof(struct virtual_ethdev_queue), 0, socket_id);
166
167         if (tx_q == NULL)
168                 return -1;
169
170         tx_q->port_id = dev->data->port_id;
171         tx_q->queue_id = tx_queue_id;
172
173         dev->data->tx_queues[tx_queue_id] = tx_q;
174
175         return 0;
176 }
177
178 static int
179 virtual_ethdev_tx_queue_setup_fail(struct rte_eth_dev *dev __rte_unused,
180                 uint16_t tx_queue_id __rte_unused, uint16_t nb_tx_desc __rte_unused,
181                 unsigned int socket_id __rte_unused,
182                 const struct rte_eth_txconf *tx_conf __rte_unused)
183 {
184         return -1;
185 }
186
187 static void
188 virtual_ethdev_rx_queue_release(void *q __rte_unused)
189 {
190 }
191
192 static void
193 virtual_ethdev_tx_queue_release(void *q __rte_unused)
194 {
195 }
196
197 static int
198 virtual_ethdev_link_update_success(struct rte_eth_dev *bonded_eth_dev,
199                 int wait_to_complete __rte_unused)
200 {
201         if (!bonded_eth_dev->data->dev_started)
202                 bonded_eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
203
204         return 0;
205 }
206
207 static int
208 virtual_ethdev_link_update_fail(struct rte_eth_dev *bonded_eth_dev __rte_unused,
209                 int wait_to_complete __rte_unused)
210 {
211         return -1;
212 }
213
214 static void
215 virtual_ethdev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
216 {
217         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
218
219         if (stats)
220                 rte_memcpy(stats, &dev_private->eth_stats, sizeof(*stats));
221 }
222
223 static void
224 virtual_ethdev_stats_reset(struct rte_eth_dev *dev)
225 {
226         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
227         void *pkt = NULL;
228
229         while (rte_ring_dequeue(dev_private->tx_queue, &pkt) == -ENOBUFS)
230                         rte_pktmbuf_free(pkt);
231
232         /* Reset internal statistics */
233         memset(&dev_private->eth_stats, 0, sizeof(dev_private->eth_stats));
234 }
235
236 static void
237 virtual_ethdev_promiscuous_mode_enable(struct rte_eth_dev *dev __rte_unused)
238 {}
239
240 static void
241 virtual_ethdev_promiscuous_mode_disable(struct rte_eth_dev *dev __rte_unused)
242 {}
243
244 static void
245 virtual_ethdev_mac_address_set(__rte_unused struct rte_eth_dev *dev,
246                                __rte_unused struct ether_addr *addr)
247 {
248 }
249
250 static const struct eth_dev_ops virtual_ethdev_default_dev_ops = {
251         .dev_configure = virtual_ethdev_configure_success,
252         .dev_start = virtual_ethdev_start_success,
253         .dev_stop = virtual_ethdev_stop,
254         .dev_close = virtual_ethdev_close,
255         .dev_infos_get = virtual_ethdev_info_get,
256         .rx_queue_setup = virtual_ethdev_rx_queue_setup_success,
257         .tx_queue_setup = virtual_ethdev_tx_queue_setup_success,
258         .rx_queue_release = virtual_ethdev_rx_queue_release,
259         .tx_queue_release = virtual_ethdev_tx_queue_release,
260         .link_update = virtual_ethdev_link_update_success,
261         .mac_addr_set = virtual_ethdev_mac_address_set,
262         .stats_get = virtual_ethdev_stats_get,
263         .stats_reset = virtual_ethdev_stats_reset,
264         .promiscuous_enable = virtual_ethdev_promiscuous_mode_enable,
265         .promiscuous_disable = virtual_ethdev_promiscuous_mode_disable
266 };
267
268 void
269 virtual_ethdev_start_fn_set_success(uint8_t port_id, uint8_t success)
270 {
271         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
272         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
273         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
274
275         if (success)
276                 dev_ops->dev_start = virtual_ethdev_start_success;
277         else
278                 dev_ops->dev_start = virtual_ethdev_start_fail;
279
280 }
281
282 void
283 virtual_ethdev_configure_fn_set_success(uint8_t port_id, uint8_t success)
284 {
285         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
286         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
287         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
288
289         if (success)
290                 dev_ops->dev_configure = virtual_ethdev_configure_success;
291         else
292                 dev_ops->dev_configure = virtual_ethdev_configure_fail;
293 }
294
295 void
296 virtual_ethdev_rx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
297 {
298         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
299         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
300         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
301
302         if (success)
303                 dev_ops->rx_queue_setup = virtual_ethdev_rx_queue_setup_success;
304         else
305                 dev_ops->rx_queue_setup = virtual_ethdev_rx_queue_setup_fail;
306 }
307
308 void
309 virtual_ethdev_tx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
310 {
311         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
312         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
313         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
314
315         if (success)
316                 dev_ops->tx_queue_setup = virtual_ethdev_tx_queue_setup_success;
317         else
318                 dev_ops->tx_queue_setup = virtual_ethdev_tx_queue_setup_fail;
319 }
320
321 void
322 virtual_ethdev_link_update_fn_set_success(uint8_t port_id, uint8_t success)
323 {
324         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
325         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
326         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
327
328         if (success)
329                 dev_ops->link_update = virtual_ethdev_link_update_success;
330         else
331                 dev_ops->link_update = virtual_ethdev_link_update_fail;
332 }
333
334
335 static uint16_t
336 virtual_ethdev_rx_burst_success(void *queue __rte_unused,
337                                                          struct rte_mbuf **bufs,
338                                                          uint16_t nb_pkts)
339 {
340         struct rte_eth_dev *vrtl_eth_dev;
341         struct virtual_ethdev_queue *pq_map;
342         struct virtual_ethdev_private *dev_private;
343
344         int rx_count, i;
345
346         pq_map = (struct virtual_ethdev_queue *)queue;
347         vrtl_eth_dev = &rte_eth_devices[pq_map->port_id];
348         dev_private = vrtl_eth_dev->data->dev_private;
349
350         rx_count = rte_ring_dequeue_burst(dev_private->rx_queue, (void **) bufs,
351                         nb_pkts);
352
353         /* increments ipackets count */
354         dev_private->eth_stats.ipackets += rx_count;
355
356         /* increments ibytes count */
357         for (i = 0; i < rx_count; i++)
358                 dev_private->eth_stats.ibytes += rte_pktmbuf_pkt_len(bufs[i]);
359
360         return rx_count;
361 }
362
363 static uint16_t
364 virtual_ethdev_rx_burst_fail(void *queue __rte_unused,
365                                                          struct rte_mbuf **bufs __rte_unused,
366                                                          uint16_t nb_pkts __rte_unused)
367 {
368         return 0;
369 }
370
371 static uint16_t
372 virtual_ethdev_tx_burst_success(void *queue, struct rte_mbuf **bufs,
373                 uint16_t nb_pkts)
374 {
375         struct virtual_ethdev_queue *tx_q = (struct virtual_ethdev_queue *)queue;
376
377         struct rte_eth_dev *vrtl_eth_dev;
378         struct virtual_ethdev_private *dev_private;
379
380         int i;
381
382         vrtl_eth_dev = &rte_eth_devices[tx_q->port_id];
383         dev_private = vrtl_eth_dev->data->dev_private;
384
385         if (!vrtl_eth_dev->data->dev_link.link_status)
386                 nb_pkts = 0;
387         else
388                 nb_pkts = rte_ring_enqueue_burst(dev_private->tx_queue, (void **)bufs,
389                                 nb_pkts);
390
391         /* increment opacket count */
392         dev_private->eth_stats.opackets += nb_pkts;
393
394         /* increment obytes count */
395         for (i = 0; i < nb_pkts; i++)
396                 dev_private->eth_stats.obytes += rte_pktmbuf_pkt_len(bufs[i]);
397
398         return nb_pkts;
399 }
400
401 static uint16_t
402 virtual_ethdev_tx_burst_fail(void *queue, struct rte_mbuf **bufs,
403                 uint16_t nb_pkts)
404 {
405         struct rte_eth_dev *vrtl_eth_dev = NULL;
406         struct virtual_ethdev_queue *tx_q = NULL;
407         struct virtual_ethdev_private *dev_private = NULL;
408
409         int i;
410
411         tx_q = (struct virtual_ethdev_queue *)queue;
412         vrtl_eth_dev = &rte_eth_devices[tx_q->port_id];
413         dev_private = vrtl_eth_dev->data->dev_private;
414
415         if (dev_private->tx_burst_fail_count < nb_pkts) {
416                 int successfully_txd = nb_pkts - dev_private->tx_burst_fail_count;
417
418                 /* increment opacket count */
419                 dev_private->eth_stats.opackets += successfully_txd;
420
421                 /* free packets in burst */
422                 for (i = 0; i < successfully_txd; i++) {
423                         /* free packets in burst */
424                         if (bufs[i] != NULL)
425                                 rte_pktmbuf_free(bufs[i]);
426
427                         bufs[i] = NULL;
428                 }
429
430                 return successfully_txd;
431         }
432
433         return 0;
434 }
435
436
437 void
438 virtual_ethdev_rx_burst_fn_set_success(uint8_t port_id, uint8_t success)
439 {
440         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
441
442         if (success)
443                 vrtl_eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
444         else
445                 vrtl_eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_fail;
446 }
447
448
449 void
450 virtual_ethdev_tx_burst_fn_set_success(uint8_t port_id, uint8_t success)
451 {
452         struct virtual_ethdev_private *dev_private = NULL;
453         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
454
455         dev_private = vrtl_eth_dev->data->dev_private;
456
457         if (success)
458                 vrtl_eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
459         else
460                 vrtl_eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_fail;
461
462         dev_private->tx_burst_fail_count = 0;
463 }
464
465 void
466 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(uint8_t port_id,
467                 uint8_t packet_fail_count)
468 {
469         struct virtual_ethdev_private *dev_private = NULL;
470         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
471
472
473         dev_private = vrtl_eth_dev->data->dev_private;
474         dev_private->tx_burst_fail_count = packet_fail_count;
475 }
476
477 void
478 virtual_ethdev_set_link_status(uint8_t port_id, uint8_t link_status)
479 {
480         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
481
482         vrtl_eth_dev->data->dev_link.link_status = link_status;
483 }
484
485 void
486 virtual_ethdev_simulate_link_status_interrupt(uint8_t port_id,
487                 uint8_t link_status)
488 {
489         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
490
491         vrtl_eth_dev->data->dev_link.link_status = link_status;
492
493         _rte_eth_dev_callback_process(vrtl_eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
494 }
495
496 int
497 virtual_ethdev_add_mbufs_to_rx_queue(uint8_t port_id,
498                 struct rte_mbuf **pkt_burst, int burst_length)
499 {
500         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
501         struct virtual_ethdev_private *dev_private =
502                         vrtl_eth_dev->data->dev_private;
503
504         return rte_ring_enqueue_burst(dev_private->rx_queue, (void **)pkt_burst,
505                         burst_length);
506 }
507
508 int
509 virtual_ethdev_get_mbufs_from_tx_queue(uint8_t port_id,
510                 struct rte_mbuf **pkt_burst, int burst_length)
511 {
512         struct virtual_ethdev_private *dev_private;
513         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
514
515         dev_private = vrtl_eth_dev->data->dev_private;
516         return rte_ring_dequeue_burst(dev_private->tx_queue, (void **)pkt_burst,
517                 burst_length);
518 }
519
520 static uint8_t
521 get_number_of_sockets(void)
522 {
523         int sockets = 0;
524         int i;
525         const struct rte_memseg *ms = rte_eal_get_physmem_layout();
526
527         for (i = 0; i < RTE_MAX_MEMSEG && ms[i].addr != NULL; i++) {
528                 if (sockets < ms[i].socket_id)
529                         sockets = ms[i].socket_id;
530         }
531         /* Number of sockets = maximum socket_id + 1 */
532         return ++sockets;
533 }
534
535 int
536 virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
537                 uint8_t socket_id, uint8_t isr_support)
538 {
539         struct rte_pci_device *pci_dev = NULL;
540         struct rte_eth_dev *eth_dev = NULL;
541         struct eth_driver *eth_drv = NULL;
542         struct rte_pci_driver *pci_drv = NULL;
543         struct rte_pci_id *id_table = NULL;
544         struct virtual_ethdev_private *dev_private = NULL;
545         char name_buf[RTE_RING_NAMESIZE];
546
547
548         /* now do all data allocation - for eth_dev structure, dummy pci driver
549          * and internal (dev_private) data
550          */
551
552         if (socket_id >= get_number_of_sockets())
553                 goto err;
554
555         pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, socket_id);
556         if (pci_dev == NULL)
557                 goto err;
558
559         eth_drv = rte_zmalloc_socket(name, sizeof(*eth_drv), 0, socket_id);
560         if (eth_drv == NULL)
561                 goto err;
562
563         pci_drv = rte_zmalloc_socket(name, sizeof(*pci_drv), 0, socket_id);
564         if (pci_drv == NULL)
565                 goto err;
566
567         id_table = rte_zmalloc_socket(name, sizeof(*id_table), 0, socket_id);
568         if (id_table == NULL)
569                 goto err;
570         id_table->device_id = 0xBEEF;
571
572         dev_private = rte_zmalloc_socket(name, sizeof(*dev_private), 0, socket_id);
573         if (dev_private == NULL)
574                 goto err;
575
576         snprintf(name_buf, sizeof(name_buf), "%s_rxQ", name);
577         dev_private->rx_queue = rte_ring_create(name_buf, MAX_PKT_BURST, socket_id,
578                         0);
579         if (dev_private->rx_queue == NULL)
580                 goto err;
581
582         snprintf(name_buf, sizeof(name_buf), "%s_txQ", name);
583         dev_private->tx_queue = rte_ring_create(name_buf, MAX_PKT_BURST, socket_id,
584                         0);
585         if (dev_private->tx_queue == NULL)
586                 goto err;
587
588         /* reserve an ethdev entry */
589         eth_dev = rte_eth_dev_allocate(name);
590         if (eth_dev == NULL)
591                 goto err;
592
593         pci_dev->device.numa_node = socket_id;
594         pci_drv->driver.name = virtual_ethdev_driver_name;
595         pci_drv->id_table = id_table;
596
597         if (isr_support)
598                 pci_drv->drv_flags |= RTE_PCI_DRV_INTR_LSC;
599         else
600                 pci_drv->drv_flags &= ~RTE_PCI_DRV_INTR_LSC;
601
602
603         eth_drv->pci_drv = (struct rte_pci_driver)(*pci_drv);
604         eth_dev->driver = eth_drv;
605
606         eth_dev->data->nb_rx_queues = (uint16_t)1;
607         eth_dev->data->nb_tx_queues = (uint16_t)1;
608
609         TAILQ_INIT(&(eth_dev->link_intr_cbs));
610
611         eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
612         eth_dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
613         eth_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
614
615         eth_dev->data->mac_addrs = rte_zmalloc(name, ETHER_ADDR_LEN, 0);
616         if (eth_dev->data->mac_addrs == NULL)
617                 goto err;
618
619         memcpy(eth_dev->data->mac_addrs, mac_addr,
620                         sizeof(*eth_dev->data->mac_addrs));
621
622         eth_dev->data->dev_started = 0;
623         eth_dev->data->promiscuous = 0;
624         eth_dev->data->scattered_rx = 0;
625         eth_dev->data->all_multicast = 0;
626
627         eth_dev->data->dev_private = dev_private;
628
629         /* Copy default device operation functions */
630         dev_private->dev_ops = virtual_ethdev_default_dev_ops;
631         eth_dev->dev_ops = &dev_private->dev_ops;
632
633         eth_dev->pci_dev = pci_dev;
634         eth_dev->pci_dev->device.driver = &eth_drv->pci_drv.driver;
635
636         eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
637         eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
638
639         return eth_dev->data->port_id;
640
641 err:
642         rte_free(pci_dev);
643         rte_free(pci_drv);
644         rte_free(eth_drv);
645         rte_free(id_table);
646         rte_free(dev_private);
647
648         return -1;
649 }