[virtio] Use separate RX and TX empty header buffers
[ipxe.git] / src / drivers / net / virtio-net.c
1 /*
2 * (c) Copyright 2010 Stefan Hajnoczi <stefanha@gmail.com>
3 *
4 * based on the Etherboot virtio-net driver
5 *
6 * (c) Copyright 2008 Bull S.A.S.
7 *
8 * Author: Laurent Vivier <Laurent.Vivier@bull.net>
9 *
10 * some parts from Linux Virtio PCI driver
11 *
12 * Copyright IBM Corp. 2007
13 * Authors: Anthony Liguori <aliguori@us.ibm.com>
14 *
15 * some parts from Linux Virtio Ring
16 *
17 * Copyright Rusty Russell IBM Corporation 2007
18 *
19 * This work is licensed under the terms of the GNU GPL, version 2 or later.
20 * See the COPYING file in the top-level directory.
21 */
22
23 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
24
25 #include <errno.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <ipxe/list.h>
29 #include <ipxe/iobuf.h>
30 #include <ipxe/netdevice.h>
31 #include <ipxe/pci.h>
32 #include <ipxe/if_ether.h>
33 #include <ipxe/ethernet.h>
34 #include <ipxe/virtio-pci.h>
35 #include <ipxe/virtio-ring.h>
36 #include "virtio-net.h"
37
38 /*
39 * Virtio network device driver
40 *
41 * Specification:
42 * http://ozlabs.org/~rusty/virtio-spec/
43 *
44 * The virtio network device is supported by Linux virtualization software
45 * including QEMU/KVM and lguest. This driver supports the virtio over PCI
46 * transport; virtual machines have one virtio-net PCI adapter per NIC.
47 *
48 * Virtio-net is different from hardware NICs because virtio devices
49 * communicate with the hypervisor via virtqueues, not traditional descriptor
50 * rings. Virtqueues are unordered queues, they support add_buf() and
51 * get_buf() operations. To transmit a packet, the driver has to add the
52 * packet buffer onto the virtqueue. To receive a packet, the driver must
53 * first add an empty buffer to the virtqueue and then get the filled packet
54 * buffer on completion.
55 *
56 * Virtqueues are an abstraction that is commonly implemented using the vring
57 * descriptor ring layout. The vring is the actual shared memory structure
58 * that allows the virtual machine to communicate buffers with the hypervisor.
59 * Because the vring layout is optimized for flexibility and performance rather
60 * than space, it is heavy-weight and allocated like traditional descriptor
61 * rings in the open() function of the driver and not in probe().
62 *
63 * There is no true interrupt enable/disable. Virtqueues have callback
64 * enable/disable flags but these are only hints. The hypervisor may still
65 * raise an interrupt. Nevertheless, this driver disables callbacks in the
66 * hopes of avoiding interrupts.
67 */
68
69 /* Driver types are declared here so virtio-net.h can be easily synced with its
70 * Linux source.
71 */
72
73 /* Virtqueue indices */
74 enum {
75 RX_INDEX = 0,
76 TX_INDEX,
77 QUEUE_NB
78 };
79
80 enum {
81 /** Max number of pending rx packets */
82 NUM_RX_BUF = 8,
83
84 /** Max Ethernet frame length, including FCS and VLAN tag */
85 RX_BUF_SIZE = 1522,
86 };
87
88 struct virtnet_nic {
89 /** Base pio register address */
90 unsigned long ioaddr;
91
92 /** 0 for legacy, 1 for virtio 1.0 */
93 int virtio_version;
94
95 /** Virtio 1.0 device data */
96 struct virtio_pci_modern_device vdev;
97
98 /** RX/TX virtqueues */
99 struct vring_virtqueue *virtqueue;
100
101 /** RX packets handed to the NIC waiting to be filled in */
102 struct list_head rx_iobufs;
103
104 /** Pending rx packet count */
105 unsigned int rx_num_iobufs;
106
107 /** Virtio net dummy packet headers */
108 struct virtio_net_hdr_modern empty_header[QUEUE_NB];
109 };
110
111 /** Add an iobuf to a virtqueue
112 *
113 * @v netdev Network device
114 * @v vq_idx Virtqueue index (RX_INDEX or TX_INDEX)
115 * @v iobuf I/O buffer
116 *
117 * The virtqueue is kicked after the iobuf has been added.
118 */
119 static void virtnet_enqueue_iob ( struct net_device *netdev,
120 int vq_idx, struct io_buffer *iobuf ) {
121 struct virtnet_nic *virtnet = netdev->priv;
122 struct vring_virtqueue *vq = &virtnet->virtqueue[vq_idx];
123 struct virtio_net_hdr_modern *header = &virtnet->empty_header[vq_idx];
124 unsigned int out = ( vq_idx == TX_INDEX ) ? 2 : 0;
125 unsigned int in = ( vq_idx == TX_INDEX ) ? 0 : 2;
126 size_t header_len = ( virtnet->virtio_version ?
127 sizeof ( *header ) : sizeof ( header->legacy ) );
128 struct vring_list list[] = {
129 {
130 /* Share a single zeroed virtio net header between all
131 * packets in a ring. This works because this driver
132 * does not use any advanced features so none of the
133 * header fields get used.
134 *
135 * Some host implementations (notably Google Compute
136 * Platform) are known to unconditionally write back
137 * to header->flags for received packets. Work around
138 * this by using separate RX and TX headers.
139 */
140 .addr = ( char* ) header,
141 .length = header_len,
142 },
143 {
144 .addr = ( char* ) iobuf->data,
145 .length = iob_len ( iobuf ),
146 },
147 };
148
149 DBGC2 ( virtnet, "VIRTIO-NET %p enqueuing iobuf %p on vq %d\n",
150 virtnet, iobuf, vq_idx );
151
152 vring_add_buf ( vq, list, out, in, iobuf, 0 );
153 vring_kick ( virtnet->virtio_version ? &virtnet->vdev : NULL,
154 virtnet->ioaddr, vq, 1 );
155 }
156
157 /** Try to keep rx virtqueue filled with iobufs
158 *
159 * @v netdev Network device
160 */
161 static void virtnet_refill_rx_virtqueue ( struct net_device *netdev ) {
162 struct virtnet_nic *virtnet = netdev->priv;
163
164 while ( virtnet->rx_num_iobufs < NUM_RX_BUF ) {
165 struct io_buffer *iobuf;
166
167 /* Try to allocate a buffer, stop for now if out of memory */
168 iobuf = alloc_iob ( RX_BUF_SIZE );
169 if ( ! iobuf )
170 break;
171
172 /* Keep track of iobuf so close() can free it */
173 list_add ( &iobuf->list, &virtnet->rx_iobufs );
174
175 /* Mark packet length until we know the actual size */
176 iob_put ( iobuf, RX_BUF_SIZE );
177
178 virtnet_enqueue_iob ( netdev, RX_INDEX, iobuf );
179 virtnet->rx_num_iobufs++;
180 }
181 }
182
183 /** Helper to free all virtqueue memory
184 *
185 * @v netdev Network device
186 */
187 static void virtnet_free_virtqueues ( struct net_device *netdev ) {
188 struct virtnet_nic *virtnet = netdev->priv;
189 int i;
190
191 for ( i = 0; i < QUEUE_NB; i++ ) {
192 virtio_pci_unmap_capability ( &virtnet->virtqueue[i].notification );
193 vp_free_vq ( &virtnet->virtqueue[i] );
194 }
195
196 free ( virtnet->virtqueue );
197 virtnet->virtqueue = NULL;
198 }
199
200 /** Open network device, legacy virtio 0.9.5
201 *
202 * @v netdev Network device
203 * @ret rc Return status code
204 */
205 static int virtnet_open_legacy ( struct net_device *netdev ) {
206 struct virtnet_nic *virtnet = netdev->priv;
207 unsigned long ioaddr = virtnet->ioaddr;
208 u32 features;
209 int i;
210
211 /* Reset for sanity */
212 vp_reset ( ioaddr );
213
214 /* Allocate virtqueues */
215 virtnet->virtqueue = zalloc ( QUEUE_NB *
216 sizeof ( *virtnet->virtqueue ) );
217 if ( ! virtnet->virtqueue )
218 return -ENOMEM;
219
220 /* Initialize rx/tx virtqueues */
221 for ( i = 0; i < QUEUE_NB; i++ ) {
222 if ( vp_find_vq ( ioaddr, i, &virtnet->virtqueue[i] ) == -1 ) {
223 DBGC ( virtnet, "VIRTIO-NET %p cannot register queue %d\n",
224 virtnet, i );
225 virtnet_free_virtqueues ( netdev );
226 return -ENOENT;
227 }
228 }
229
230 /* Initialize rx packets */
231 INIT_LIST_HEAD ( &virtnet->rx_iobufs );
232 virtnet->rx_num_iobufs = 0;
233 virtnet_refill_rx_virtqueue ( netdev );
234
235 /* Disable interrupts before starting */
236 netdev_irq ( netdev, 0 );
237
238 /* Driver is ready */
239 features = vp_get_features ( ioaddr );
240 vp_set_features ( ioaddr, features & ( 1 << VIRTIO_NET_F_MAC ) );
241 vp_set_status ( ioaddr, VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK );
242 return 0;
243 }
244
245 /** Open network device, modern virtio 1.0
246 *
247 * @v netdev Network device
248 * @ret rc Return status code
249 */
250 static int virtnet_open_modern ( struct net_device *netdev ) {
251 struct virtnet_nic *virtnet = netdev->priv;
252 u64 features;
253 u8 status;
254
255 /* Negotiate features */
256 features = vpm_get_features ( &virtnet->vdev );
257 if ( ! ( features & VIRTIO_F_VERSION_1 ) ) {
258 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED );
259 return -EINVAL;
260 }
261 vpm_set_features ( &virtnet->vdev, features & (
262 ( 1ULL << VIRTIO_NET_F_MAC ) |
263 ( 1ULL << VIRTIO_F_VERSION_1 ) |
264 ( 1ULL << VIRTIO_F_ANY_LAYOUT ) ) );
265 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FEATURES_OK );
266
267 status = vpm_get_status ( &virtnet->vdev );
268 if ( ! ( status & VIRTIO_CONFIG_S_FEATURES_OK ) ) {
269 DBGC ( virtnet, "VIRTIO-NET %p device didn't accept features\n",
270 virtnet );
271 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED );
272 return -EINVAL;
273 }
274
275 /* Allocate virtqueues */
276 virtnet->virtqueue = zalloc ( QUEUE_NB *
277 sizeof ( *virtnet->virtqueue ) );
278 if ( ! virtnet->virtqueue ) {
279 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED );
280 return -ENOMEM;
281 }
282
283 /* Initialize rx/tx virtqueues */
284 if ( vpm_find_vqs ( &virtnet->vdev, QUEUE_NB, virtnet->virtqueue ) ) {
285 DBGC ( virtnet, "VIRTIO-NET %p cannot register queues\n",
286 virtnet );
287 virtnet_free_virtqueues ( netdev );
288 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED );
289 return -ENOENT;
290 }
291
292 /* Disable interrupts before starting */
293 netdev_irq ( netdev, 0 );
294
295 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_DRIVER_OK );
296
297 /* Initialize rx packets */
298 INIT_LIST_HEAD ( &virtnet->rx_iobufs );
299 virtnet->rx_num_iobufs = 0;
300 virtnet_refill_rx_virtqueue ( netdev );
301 return 0;
302 }
303
304 /** Open network device
305 *
306 * @v netdev Network device
307 * @ret rc Return status code
308 */
309 static int virtnet_open ( struct net_device *netdev ) {
310 struct virtnet_nic *virtnet = netdev->priv;
311
312 if ( virtnet->virtio_version ) {
313 return virtnet_open_modern ( netdev );
314 } else {
315 return virtnet_open_legacy ( netdev );
316 }
317 }
318
319 /** Close network device
320 *
321 * @v netdev Network device
322 */
323 static void virtnet_close ( struct net_device *netdev ) {
324 struct virtnet_nic *virtnet = netdev->priv;
325 struct io_buffer *iobuf;
326 struct io_buffer *next_iobuf;
327
328 if ( virtnet->virtio_version ) {
329 vpm_reset ( &virtnet->vdev );
330 } else {
331 vp_reset ( virtnet->ioaddr );
332 }
333
334 /* Virtqueues can be freed now that NIC is reset */
335 virtnet_free_virtqueues ( netdev );
336
337 /* Free rx iobufs */
338 list_for_each_entry_safe ( iobuf, next_iobuf, &virtnet->rx_iobufs, list ) {
339 free_iob ( iobuf );
340 }
341 INIT_LIST_HEAD ( &virtnet->rx_iobufs );
342 virtnet->rx_num_iobufs = 0;
343 }
344
345 /** Transmit packet
346 *
347 * @v netdev Network device
348 * @v iobuf I/O buffer
349 * @ret rc Return status code
350 */
351 static int virtnet_transmit ( struct net_device *netdev,
352 struct io_buffer *iobuf ) {
353 virtnet_enqueue_iob ( netdev, TX_INDEX, iobuf );
354 return 0;
355 }
356
357 /** Complete packet transmission
358 *
359 * @v netdev Network device
360 */
361 static void virtnet_process_tx_packets ( struct net_device *netdev ) {
362 struct virtnet_nic *virtnet = netdev->priv;
363 struct vring_virtqueue *tx_vq = &virtnet->virtqueue[TX_INDEX];
364
365 while ( vring_more_used ( tx_vq ) ) {
366 struct io_buffer *iobuf = vring_get_buf ( tx_vq, NULL );
367
368 DBGC2 ( virtnet, "VIRTIO-NET %p tx complete iobuf %p\n",
369 virtnet, iobuf );
370
371 netdev_tx_complete ( netdev, iobuf );
372 }
373 }
374
375 /** Complete packet reception
376 *
377 * @v netdev Network device
378 */
379 static void virtnet_process_rx_packets ( struct net_device *netdev ) {
380 struct virtnet_nic *virtnet = netdev->priv;
381 struct vring_virtqueue *rx_vq = &virtnet->virtqueue[RX_INDEX];
382
383 while ( vring_more_used ( rx_vq ) ) {
384 unsigned int len;
385 struct io_buffer *iobuf = vring_get_buf ( rx_vq, &len );
386
387 /* Release ownership of iobuf */
388 list_del ( &iobuf->list );
389 virtnet->rx_num_iobufs--;
390
391 /* Update iobuf length */
392 iob_unput ( iobuf, RX_BUF_SIZE );
393 iob_put ( iobuf, len - sizeof ( struct virtio_net_hdr ) );
394
395 DBGC2 ( virtnet, "VIRTIO-NET %p rx complete iobuf %p len %zd\n",
396 virtnet, iobuf, iob_len ( iobuf ) );
397
398 /* Pass completed packet to the network stack */
399 netdev_rx ( netdev, iobuf );
400 }
401
402 virtnet_refill_rx_virtqueue ( netdev );
403 }
404
405 /** Poll for completed and received packets
406 *
407 * @v netdev Network device
408 */
409 static void virtnet_poll ( struct net_device *netdev ) {
410 struct virtnet_nic *virtnet = netdev->priv;
411
412 /* Acknowledge interrupt. This is necessary for UNDI operation and
413 * interrupts that are raised despite VRING_AVAIL_F_NO_INTERRUPT being
414 * set (that flag is just a hint and the hypervisor does not have to
415 * honor it).
416 */
417 if ( virtnet->virtio_version ) {
418 vpm_get_isr ( &virtnet->vdev );
419 } else {
420 vp_get_isr ( virtnet->ioaddr );
421 }
422
423 virtnet_process_tx_packets ( netdev );
424 virtnet_process_rx_packets ( netdev );
425 }
426
427 /** Enable or disable interrupts
428 *
429 * @v netdev Network device
430 * @v enable Interrupts should be enabled
431 */
432 static void virtnet_irq ( struct net_device *netdev, int enable ) {
433 struct virtnet_nic *virtnet = netdev->priv;
434 int i;
435
436 for ( i = 0; i < QUEUE_NB; i++ ) {
437 if ( enable )
438 vring_enable_cb ( &virtnet->virtqueue[i] );
439 else
440 vring_disable_cb ( &virtnet->virtqueue[i] );
441 }
442 }
443
444 /** virtio-net device operations */
445 static struct net_device_operations virtnet_operations = {
446 .open = virtnet_open,
447 .close = virtnet_close,
448 .transmit = virtnet_transmit,
449 .poll = virtnet_poll,
450 .irq = virtnet_irq,
451 };
452
453 /**
454 * Probe PCI device, legacy virtio 0.9.5
455 *
456 * @v pci PCI device
457 * @ret rc Return status code
458 */
459 static int virtnet_probe_legacy ( struct pci_device *pci ) {
460 unsigned long ioaddr = pci->ioaddr;
461 struct net_device *netdev;
462 struct virtnet_nic *virtnet;
463 u32 features;
464 int rc;
465
466 /* Allocate and hook up net device */
467 netdev = alloc_etherdev ( sizeof ( *virtnet ) );
468 if ( ! netdev )
469 return -ENOMEM;
470 netdev_init ( netdev, &virtnet_operations );
471 virtnet = netdev->priv;
472 virtnet->ioaddr = ioaddr;
473 pci_set_drvdata ( pci, netdev );
474 netdev->dev = &pci->dev;
475
476 DBGC ( virtnet, "VIRTIO-NET %p busaddr=%s ioaddr=%#lx irq=%d\n",
477 virtnet, pci->dev.name, ioaddr, pci->irq );
478
479 /* Enable PCI bus master and reset NIC */
480 adjust_pci_device ( pci );
481 vp_reset ( ioaddr );
482
483 /* Load MAC address */
484 features = vp_get_features ( ioaddr );
485 if ( features & ( 1 << VIRTIO_NET_F_MAC ) ) {
486 vp_get ( ioaddr, offsetof ( struct virtio_net_config, mac ),
487 netdev->hw_addr, ETH_ALEN );
488 DBGC ( virtnet, "VIRTIO-NET %p mac=%s\n", virtnet,
489 eth_ntoa ( netdev->hw_addr ) );
490 }
491
492 /* Register network device */
493 if ( ( rc = register_netdev ( netdev ) ) != 0 )
494 goto err_register_netdev;
495
496 /* Mark link as up, control virtqueue is not used */
497 netdev_link_up ( netdev );
498
499 return 0;
500
501 unregister_netdev ( netdev );
502 err_register_netdev:
503 vp_reset ( ioaddr );
504 netdev_nullify ( netdev );
505 netdev_put ( netdev );
506 return rc;
507 }
508
509 /**
510 * Probe PCI device, modern virtio 1.0
511 *
512 * @v pci PCI device
513 * @v found_dev Set to non-zero if modern device was found (probe may still fail)
514 * @ret rc Return status code
515 */
516 static int virtnet_probe_modern ( struct pci_device *pci, int *found_dev ) {
517 struct net_device *netdev;
518 struct virtnet_nic *virtnet;
519 u64 features;
520 int rc, common, isr, notify, config, device;
521
522 common = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_COMMON_CFG );
523 if ( ! common ) {
524 DBG ( "Common virtio capability not found!\n" );
525 return -ENODEV;
526 }
527 *found_dev = 1;
528
529 isr = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_ISR_CFG );
530 notify = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_NOTIFY_CFG );
531 config = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_PCI_CFG );
532 if ( ! isr || ! notify || ! config ) {
533 DBG ( "Missing virtio capabilities %i/%i/%i/%i\n",
534 common, isr, notify, config );
535 return -EINVAL;
536 }
537 device = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_DEVICE_CFG );
538
539 /* Allocate and hook up net device */
540 netdev = alloc_etherdev ( sizeof ( *virtnet ) );
541 if ( ! netdev )
542 return -ENOMEM;
543 netdev_init ( netdev, &virtnet_operations );
544 virtnet = netdev->priv;
545
546 pci_set_drvdata ( pci, netdev );
547 netdev->dev = &pci->dev;
548
549 DBGC ( virtnet, "VIRTIO-NET modern %p busaddr=%s irq=%d\n",
550 virtnet, pci->dev.name, pci->irq );
551
552 virtnet->vdev.pci = pci;
553 rc = virtio_pci_map_capability ( pci, common,
554 sizeof ( struct virtio_pci_common_cfg ), 4,
555 0, sizeof ( struct virtio_pci_common_cfg ),
556 &virtnet->vdev.common );
557 if ( rc )
558 goto err_map_common;
559
560 rc = virtio_pci_map_capability ( pci, isr, sizeof ( u8 ), 1,
561 0, 1,
562 &virtnet->vdev.isr );
563 if ( rc )
564 goto err_map_isr;
565
566 virtnet->vdev.notify_cap_pos = notify;
567 virtnet->vdev.cfg_cap_pos = config;
568
569 /* Map the device capability */
570 if ( device ) {
571 rc = virtio_pci_map_capability ( pci, device,
572 0, 4, 0, sizeof ( struct virtio_net_config ),
573 &virtnet->vdev.device );
574 if ( rc )
575 goto err_map_device;
576 }
577
578 /* Enable the PCI device */
579 adjust_pci_device ( pci );
580
581 /* Reset the device and set initial status bits */
582 vpm_reset ( &virtnet->vdev );
583 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_ACKNOWLEDGE );
584 vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_DRIVER );
585
586 /* Load MAC address */
587 if ( device ) {
588 features = vpm_get_features ( &virtnet->vdev );
589 if ( features & ( 1ULL << VIRTIO_NET_F_MAC ) ) {
590 vpm_get ( &virtnet->vdev,
591 offsetof ( struct virtio_net_config, mac ),
592 netdev->hw_addr, ETH_ALEN );
593 DBGC ( virtnet, "VIRTIO-NET %p mac=%s\n", virtnet,
594 eth_ntoa ( netdev->hw_addr ) );
595 }
596 }
597
598 /* We need a valid MAC address */
599 if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
600 rc = -EADDRNOTAVAIL;
601 goto err_mac_address;
602 }
603
604 /* Register network device */
605 if ( ( rc = register_netdev ( netdev ) ) != 0 )
606 goto err_register_netdev;
607
608 /* Mark link as up, control virtqueue is not used */
609 netdev_link_up ( netdev );
610
611 virtnet->virtio_version = 1;
612 return 0;
613
614 unregister_netdev ( netdev );
615 err_register_netdev:
616 err_mac_address:
617 vpm_reset ( &virtnet->vdev );
618 netdev_nullify ( netdev );
619 netdev_put ( netdev );
620
621 virtio_pci_unmap_capability ( &virtnet->vdev.device );
622 err_map_device:
623 virtio_pci_unmap_capability ( &virtnet->vdev.isr );
624 err_map_isr:
625 virtio_pci_unmap_capability ( &virtnet->vdev.common );
626 err_map_common:
627 return rc;
628 }
629
630 /**
631 * Probe PCI device
632 *
633 * @v pci PCI device
634 * @ret rc Return status code
635 */
636 static int virtnet_probe ( struct pci_device *pci ) {
637 int found_modern = 0;
638 int rc = virtnet_probe_modern ( pci, &found_modern );
639 if ( ! found_modern && pci->device < 0x1040 ) {
640 /* fall back to the legacy probe */
641 rc = virtnet_probe_legacy ( pci );
642 }
643 return rc;
644 }
645
646 /**
647 * Remove device
648 *
649 * @v pci PCI device
650 */
651 static void virtnet_remove ( struct pci_device *pci ) {
652 struct net_device *netdev = pci_get_drvdata ( pci );
653 struct virtnet_nic *virtnet = netdev->priv;
654
655 virtio_pci_unmap_capability ( &virtnet->vdev.device );
656 virtio_pci_unmap_capability ( &virtnet->vdev.isr );
657 virtio_pci_unmap_capability ( &virtnet->vdev.common );
658
659 unregister_netdev ( netdev );
660 netdev_nullify ( netdev );
661 netdev_put ( netdev );
662 }
663
664 static struct pci_device_id virtnet_nics[] = {
665 PCI_ROM(0x1af4, 0x1000, "virtio-net", "Virtio Network Interface", 0),
666 PCI_ROM(0x1af4, 0x1041, "virtio-net", "Virtio Network Interface 1.0", 0),
667 };
668
669 struct pci_driver virtnet_driver __pci_driver = {
670 .ids = virtnet_nics,
671 .id_count = ( sizeof ( virtnet_nics ) / sizeof ( virtnet_nics[0] ) ),
672 .probe = virtnet_probe,
673 .remove = virtnet_remove,
674 };