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