iPXE
|
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <ipxe/list.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/pci.h>
#include <ipxe/dma.h>
#include <ipxe/if_ether.h>
#include <ipxe/ethernet.h>
#include <ipxe/virtio-pci.h>
#include <ipxe/virtio-ring.h>
#include "virtio-net.h"
Go to the source code of this file.
Data Structures | |
struct | virtnet_nic |
Macros | |
#define | NUM_RX_BUF 8 |
Max number of pending rx packets. More... | |
Enumerations | |
enum | { RX_INDEX = 0, TX_INDEX, QUEUE_NB } |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static void | virtnet_enqueue_iob (struct net_device *netdev, int vq_idx, struct io_buffer *iobuf) |
Add an iobuf to a virtqueue. More... | |
static void | virtnet_refill_rx_virtqueue (struct net_device *netdev) |
Try to keep rx virtqueue filled with iobufs. More... | |
static void | virtnet_free_virtqueues (struct net_device *netdev) |
Helper to free all virtqueue memory. More... | |
static int | virtnet_open_legacy (struct net_device *netdev) |
Open network device, legacy virtio 0.9.5. More... | |
static int | virtnet_open_modern (struct net_device *netdev) |
Open network device, modern virtio 1.0. More... | |
static int | virtnet_open (struct net_device *netdev) |
Open network device. More... | |
static void | virtnet_close (struct net_device *netdev) |
Close network device. More... | |
static int | virtnet_transmit (struct net_device *netdev, struct io_buffer *iobuf) |
Transmit packet. More... | |
static void | virtnet_process_tx_packets (struct net_device *netdev) |
Complete packet transmission. More... | |
static void | virtnet_process_rx_packets (struct net_device *netdev) |
Complete packet reception. More... | |
static void | virtnet_poll (struct net_device *netdev) |
Poll for completed and received packets. More... | |
static void | virtnet_irq (struct net_device *netdev, int enable) |
Enable or disable interrupts. More... | |
static int | virtnet_probe_legacy (struct pci_device *pci) |
Probe PCI device, legacy virtio 0.9.5. More... | |
static int | virtnet_probe_modern (struct pci_device *pci, int *found_dev) |
Probe PCI device, modern virtio 1.0. More... | |
static int | virtnet_probe (struct pci_device *pci) |
Probe PCI device. More... | |
static void | virtnet_remove (struct pci_device *pci) |
Remove device. More... | |
Variables | |
static struct net_device_operations | virtnet_operations |
virtio-net device operations More... | |
static struct pci_device_id | virtnet_nics [] |
struct pci_driver virtnet_driver | __pci_driver |
#define NUM_RX_BUF 8 |
Max number of pending rx packets.
Definition at line 82 of file virtio-net.c.
anonymous enum |
Enumerator | |
---|---|
RX_INDEX | |
TX_INDEX | |
QUEUE_NB |
Definition at line 75 of file virtio-net.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Add an iobuf to a virtqueue.
netdev | Network device |
vq_idx | Virtqueue index (RX_INDEX or TX_INDEX) |
iobuf | I/O buffer |
The virtqueue is kicked after the iobuf has been added.
Definition at line 116 of file virtio-net.c.
References vring_list::addr, DBGC2, dma(), vring_virtqueue::empty_header, header, in, virtnet_nic::ioaddr, iob_dma(), iob_len(), vring_virtqueue::map, netdev, NULL, out, net_device::priv, TX_INDEX, virtnet_nic::vdev, virtnet_nic::virtio_version, virtnet_nic::virtqueue, vring_add_buf(), and vring_kick().
Referenced by virtnet_refill_rx_virtqueue(), and virtnet_transmit().
|
static |
Try to keep rx virtqueue filled with iobufs.
netdev | Network device |
Definition at line 158 of file virtio-net.c.
References alloc_rx_iob(), virtnet_nic::dma, iob_put, len, io_buffer::list, list_add, net_device::max_pkt_len, netdev, NUM_RX_BUF, net_device::priv, RX_INDEX, virtnet_nic::rx_iobufs, virtnet_nic::rx_num_iobufs, and virtnet_enqueue_iob().
Referenced by virtnet_open_legacy(), virtnet_open_modern(), and virtnet_process_rx_packets().
|
static |
Helper to free all virtqueue memory.
netdev | Network device |
Definition at line 185 of file virtio-net.c.
References free, netdev, vring_virtqueue::notification, NULL, net_device::priv, QUEUE_NB, virtio_pci_unmap_capability(), virtnet_nic::virtqueue, and vp_free_vq().
Referenced by virtnet_close(), virtnet_open_legacy(), and virtnet_open_modern().
|
static |
Open network device, legacy virtio 0.9.5.
netdev | Network device |
rc | Return status code |
Definition at line 203 of file virtio-net.c.
References DBGC, virtnet_nic::dma, ENOENT, ENOMEM, features, INIT_LIST_HEAD, virtnet_nic::ioaddr, ioaddr, netdev, netdev_irq(), net_device::priv, QUEUE_NB, virtnet_nic::rx_iobufs, virtnet_nic::rx_num_iobufs, VIRTIO_CONFIG_S_DRIVER, VIRTIO_CONFIG_S_DRIVER_OK, VIRTIO_NET_F_MAC, VIRTIO_NET_F_MTU, virtnet_free_virtqueues(), virtnet_refill_rx_virtqueue(), virtnet_nic::virtqueue, vp_find_vq(), vp_get_features(), vp_reset(), vp_set_features(), vp_set_status(), and zalloc().
Referenced by virtnet_open().
|
static |
Open network device, modern virtio 1.0.
netdev | Network device |
rc | Return status code |
Definition at line 250 of file virtio-net.c.
References DBGC, virtnet_nic::dma, EINVAL, ENOENT, ENOMEM, features, INIT_LIST_HEAD, netdev, netdev_irq(), net_device::priv, QUEUE_NB, virtnet_nic::rx_iobufs, virtnet_nic::rx_num_iobufs, status, virtnet_nic::vdev, VIRTIO_CONFIG_S_DRIVER_OK, VIRTIO_CONFIG_S_FAILED, VIRTIO_CONFIG_S_FEATURES_OK, VIRTIO_F_ANY_LAYOUT, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, VIRTIO_NET_F_MAC, VIRTIO_NET_F_MTU, virtnet_free_virtqueues(), virtnet_refill_rx_virtqueue(), virtnet_nic::virtqueue, vpm_add_status(), vpm_find_vqs(), vpm_get_features(), vpm_get_status(), vpm_set_features(), and zalloc().
Referenced by virtnet_open().
|
static |
Open network device.
netdev | Network device |
rc | Return status code |
Definition at line 312 of file virtio-net.c.
References netdev, net_device::priv, virtnet_nic::virtio_version, virtnet_open_legacy(), and virtnet_open_modern().
|
static |
Close network device.
netdev | Network device |
Definition at line 326 of file virtio-net.c.
References free_rx_iob(), INIT_LIST_HEAD, virtnet_nic::ioaddr, io_buffer::list, list_for_each_entry_safe, netdev, net_device::priv, virtnet_nic::rx_iobufs, virtnet_nic::rx_num_iobufs, virtnet_nic::vdev, virtnet_nic::virtio_version, virtnet_free_virtqueues(), vp_reset(), and vpm_reset().
|
static |
Transmit packet.
netdev | Network device |
iobuf | I/O buffer |
rc | Return status code |
Definition at line 354 of file virtio-net.c.
References netdev, TX_INDEX, and virtnet_enqueue_iob().
|
static |
Complete packet transmission.
netdev | Network device |
Definition at line 364 of file virtio-net.c.
References DBGC2, netdev, netdev_tx_complete(), NULL, net_device::priv, TX_INDEX, virtnet_nic::virtqueue, vring_get_buf(), and vring_more_used().
Referenced by virtnet_poll().
|
static |
Complete packet reception.
netdev | Network device |
Definition at line 382 of file virtio-net.c.
References DBGC2, iob_len(), iob_put, iob_unput, len, io_buffer::list, list_del, netdev, netdev_rx(), net_device::priv, RX_INDEX, virtnet_nic::rx_num_iobufs, virtnet_refill_rx_virtqueue(), virtnet_nic::virtqueue, vring_get_buf(), and vring_more_used().
Referenced by virtnet_poll().
|
static |
Poll for completed and received packets.
netdev | Network device |
Definition at line 412 of file virtio-net.c.
References virtnet_nic::ioaddr, netdev, net_device::priv, virtnet_nic::vdev, virtnet_nic::virtio_version, virtnet_process_rx_packets(), virtnet_process_tx_packets(), vp_get_isr(), and vpm_get_isr().
|
static |
Enable or disable interrupts.
netdev | Network device |
enable | Interrupts should be enabled |
Definition at line 435 of file virtio-net.c.
References netdev, net_device::priv, QUEUE_NB, virtnet_nic::virtqueue, vring_disable_cb(), and vring_enable_cb().
|
static |
Probe PCI device, legacy virtio 0.9.5.
pci | PCI device |
rc | Return status code |
Definition at line 462 of file virtio-net.c.
References adjust_pci_device(), alloc_etherdev(), DBGC, pci_device::dev, net_device::dev, virtnet_nic::dma, pci_device::dma, net_device::dma, dma_set_mask_64bit(), ENOMEM, ETH_ALEN, ETH_HLEN, eth_ntoa(), features, net_device::hw_addr, virtnet_nic::ioaddr, ioaddr, pci_device::ioaddr, pci_device::irq, mac, net_device::max_pkt_len, mtu, net_device::mtu, device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), offsetof, pci_set_drvdata(), net_device::priv, rc, register_netdev(), unregister_netdev(), VIRTIO_NET_F_MAC, VIRTIO_NET_F_MTU, virtnet_operations, vp_get(), vp_get_features(), and vp_reset().
Referenced by virtnet_probe().
|
static |
Probe PCI device, modern virtio 1.0.
pci | PCI device |
found_dev | Set to non-zero if modern device was found (probe may still fail) |
rc | Return status code |
Definition at line 533 of file virtio-net.c.
References adjust_pci_device(), alloc_etherdev(), virtio_pci_modern_device::cfg_cap_pos, virtio_pci_modern_device::common, common, DBG, DBGC, pci_device::dev, net_device::dev, device, virtio_pci_modern_device::device, virtnet_nic::dma, pci_device::dma, net_device::dma, dma_set_mask_64bit(), EADDRNOTAVAIL, EINVAL, ENODEV, ENOMEM, ETH_ALEN, ETH_HLEN, eth_ntoa(), features, net_device::hw_addr, pci_device::irq, is_valid_ether_addr(), isr, virtio_pci_modern_device::isr, mac, net_device::max_pkt_len, mtu, device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), virtio_pci_modern_device::notify_cap_pos, offsetof, virtio_pci_modern_device::pci, pci_set_drvdata(), net_device::priv, rc, register_netdev(), unregister_netdev(), virtnet_nic::vdev, VIRTIO_CONFIG_S_ACKNOWLEDGE, VIRTIO_CONFIG_S_DRIVER, VIRTIO_NET_F_MAC, VIRTIO_NET_F_MTU, VIRTIO_PCI_CAP_COMMON_CFG, VIRTIO_PCI_CAP_DEVICE_CFG, VIRTIO_PCI_CAP_ISR_CFG, VIRTIO_PCI_CAP_NOTIFY_CFG, VIRTIO_PCI_CAP_PCI_CFG, virtio_pci_find_capability(), virtio_pci_map_capability(), virtio_pci_unmap_capability(), virtnet_nic::virtio_version, virtnet_operations, vpm_add_status(), vpm_get(), vpm_get_features(), and vpm_reset().
Referenced by virtnet_probe().
|
static |
Probe PCI device.
pci | PCI device |
rc | Return status code |
Definition at line 666 of file virtio-net.c.
References pci_device::device, rc, virtnet_probe_legacy(), and virtnet_probe_modern().
|
static |
Remove device.
pci | PCI device |
Definition at line 681 of file virtio-net.c.
References virtio_pci_modern_device::common, virtio_pci_modern_device::device, virtio_pci_modern_device::isr, netdev, netdev_nullify(), netdev_put(), pci_get_drvdata(), net_device::priv, unregister_netdev(), virtnet_nic::vdev, and virtio_pci_unmap_capability().
|
static |
virtio-net device operations
Definition at line 448 of file virtio-net.c.
Referenced by virtnet_probe_legacy(), and virtnet_probe_modern().
|
static |
struct pci_driver virtnet_driver __pci_driver |
Definition at line 699 of file virtio-net.c.