122 unsigned int in = ( vq_idx ==
TX_INDEX ) ? 0 : 2;
124 sizeof ( *header ) :
sizeof (
header->legacy ) );
138 .length = header_len,
146 DBGC2 ( virtnet,
"VIRTIO-NET %p enqueuing iobuf %p on vq %d\n",
147 virtnet, iobuf, vq_idx );
222 DBGC ( virtnet,
"VIRTIO-NET %p cannot register queue %d\n",
271 DBGC ( virtnet,
"VIRTIO-NET %p device didn't accept features\n",
288 DBGC ( virtnet,
"VIRTIO-NET %p cannot register queues\n",
371 DBGC2 ( virtnet,
"VIRTIO-NET %p tx complete iobuf %p\n",
398 DBGC2 ( virtnet,
"VIRTIO-NET %p rx complete iobuf %p len %zd\n",
399 virtnet, iobuf,
iob_len ( iobuf ) );
480 DBGC ( virtnet,
"VIRTIO-NET %p busaddr=%s ioaddr=%#lx irq=%d\n",
498 DBGC ( virtnet,
"VIRTIO-NET %p mac=%s\n", virtnet,
504 DBGC ( virtnet,
"VIRTIO-NET %p mtu=%d\n", virtnet,
mtu );
511 goto err_register_netdev;
542 DBG (
"Common virtio capability not found!\n" );
550 if ( !
isr || ! notify || ! config ) {
551 DBG (
"Missing virtio capabilities %i/%i/%i/%i\n",
567 DBGC ( virtnet,
"VIRTIO-NET modern %p busaddr=%s irq=%d\n",
616 DBGC ( virtnet,
"VIRTIO-NET %p mac=%s\n", virtnet,
623 DBGC ( virtnet,
"VIRTIO-NET %p mtu=%d\n", virtnet,
632 goto err_mac_address;
637 goto err_register_netdev;
667 int found_modern = 0;
669 if ( ! found_modern && pci->
device < 0x1040 ) {
695 PCI_ROM(0x1af4, 0x1000,
"virtio-net",
"Virtio Network Interface", 0),
696 PCI_ROM(0x1af4, 0x1041,
"virtio-net",
"Virtio Network Interface 1.0", 0),
void vring_kick(struct virtio_pci_modern_device *vdev, unsigned int ioaddr, struct vring_virtqueue *vq, int num_added)
#define VIRTIO_F_VERSION_1
static u8 vpm_get_status(struct virtio_pci_modern_device *vdev)
static void vpm_set_features(struct virtio_pci_modern_device *vdev, u64 features)
#define EINVAL
Invalid argument.
uint8_t irq
Interrupt number.
static void vpm_get(struct virtio_pci_modern_device *vdev, unsigned offset, void *buf, unsigned len)
struct arbelprm_rc_send_wqe rc
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
#define iob_put(iobuf, len)
struct dma_device dma
DMA device.
static int vring_more_used(struct vring_virtqueue *vq)
static void virtnet_remove(struct pci_device *pci)
Remove device.
static void virtnet_free_virtqueues(struct net_device *netdev)
Helper to free all virtqueue memory.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int(* open)(struct net_device *netdev)
Open network device.
#define list_add(new, head)
Add a new entry to the head of a list.
unsigned long ioaddr
I/O address.
static u32 vp_get_features(unsigned int ioaddr)
static void virtnet_process_rx_packets(struct net_device *netdev)
Complete packet reception.
struct pci_device_id * ids
PCI ID table.
size_t mtu
Maximum transmission unit length.
#define VIRTIO_PCI_CAP_PCI_CFG
int vpm_find_vqs(struct virtio_pci_modern_device *vdev, unsigned nvqs, struct vring_virtqueue *vqs, struct dma_device *dma_dev, size_t header_size)
#define ENOENT
No such file or directory.
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
struct dma_device * dma
DMA device.
static void vp_set_features(unsigned int ioaddr, u32 features)
#define VIRTIO_PCI_CAP_DEVICE_CFG
#define offsetof(type, field)
Get offset of a field within a structure.
#define VIRTIO_PCI_CAP_COMMON_CFG
uint8_t mac[ETH_ALEN]
MAC address.
static void vring_disable_cb(struct vring_virtqueue *vq)
uint16_t device
Device ID.
static void vring_enable_cb(struct vring_virtqueue *vq)
int virtio_pci_map_capability(struct pci_device *pci, int cap, size_t minlen, u32 align, u32 start, u32 size, struct virtio_pci_region *region)
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
struct device dev
Generic device.
A doubly-linked list entry (or list head)
static int virtnet_probe_modern(struct pci_device *pci, int *found_dev)
Probe PCI device, modern virtio 1.0.
static void vpm_reset(struct virtio_pci_modern_device *vdev)
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
#define list_del(list)
Delete an entry from a list.
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
#define ENOMEM
Not enough space.
static unsigned long ioaddr
void vp_free_vq(struct vring_virtqueue *vq)
struct virtio_pci_region device
uint16_t device
Device ID.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
static void virtnet_enqueue_iob(struct net_device *netdev, int vq_idx, struct io_buffer *iobuf)
Add an iobuf to a virtqueue.
void * priv
Driver private data.
struct dma_device * dma
DMA device.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
int virtio_pci_find_capability(struct pci_device *pci, uint8_t cfg_type)
static struct net_device * netdev
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
#define VIRTIO_F_IOMMU_PLATFORM
static u8 vp_get_isr(unsigned int ioaddr)
static void virtnet_close(struct net_device *netdev)
Close network device.
unsigned int rx_num_iobufs
Pending rx packet count.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
static int virtnet_open_modern(struct net_device *netdev)
Open network device, modern virtio 1.0.
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
void virtio_pci_unmap_capability(struct virtio_pci_region *region)
static void vp_set_status(unsigned int ioaddr, u8 status)
#define iob_unput(iobuf, len)
static void(* free)(struct refcnt *refcnt))
struct io_buffer * alloc_rx_iob(size_t len, struct dma_device *dma)
Allocate and map I/O buffer for receive DMA.
void * zalloc(size_t size)
Allocate cleared memory.
struct virtio_pci_region notification
int register_netdev(struct net_device *netdev)
Register network device.
uint32_t features
Supported features.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
static void virtnet_poll(struct net_device *netdev)
Poll for completed and received packets.
void * vring_get_buf(struct vring_virtqueue *vq, unsigned int *len)
struct virtio_pci_region common
void netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
struct virtio_pci_region isr
#define ENODEV
No such device.
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
#define VIRTIO_CONFIG_S_ACKNOWLEDGE
#define VIRTIO_PCI_CAP_NOTIFY_CFG
#define VIRTIO_F_ANY_LAYOUT
int virtio_version
0 for legacy, 1 for virtio 1.0
struct pci_driver virtnet_driver __pci_driver
A PCI device ID list entry.
static void virtnet_process_tx_packets(struct net_device *netdev)
Complete packet transmission.
static void virtnet_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
struct ib_cm_common common
static struct pci_device_id virtnet_nics[]
static int virtnet_probe_legacy(struct pci_device *pci)
Probe PCI device, legacy virtio 0.9.5.
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
static struct xen_remove_from_physmap * remove
static int virtnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
struct virtio_net_hdr_modern * empty_header
Network device operations.
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
struct device * dev
Underlying hardware device.
#define EADDRNOTAVAIL
Address not available.
#define VIRTIO_PCI_CAP_ISR_CFG
Network device management.
static int virtnet_open(struct net_device *netdev)
Open network device.
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
#define VIRTIO_CONFIG_S_DRIVER
#define INIT_LIST_HEAD(list)
Initialise a list head.
static struct net_device_operations virtnet_operations
virtio-net device operations
static void vpm_add_status(struct virtio_pci_modern_device *vdev, u8 status)
int vp_find_vq(unsigned int ioaddr, int queue_index, struct vring_virtqueue *vq, struct dma_device *dma_dev, size_t header_size)
struct list_head list
List of which this buffer is a member.
#define NUM_RX_BUF
Max number of pending rx packets.
struct list_head rx_iobufs
RX packets handed to the NIC waiting to be filled in.
void free_rx_iob(struct io_buffer *iobuf)
Unmap and free I/O buffer for receive DMA.
int(* probe)(struct pci_device *pci)
Probe device.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
struct ena_aq_header header
Header.
static void vp_get(unsigned int ioaddr, unsigned offset, void *buf, unsigned len)
static void virtnet_refill_rx_virtqueue(struct net_device *netdev)
Try to keep rx virtqueue filled with iobufs.
struct virtio_pci_modern_device vdev
Virtio 1.0 device data.
#define VIRTIO_CONFIG_S_FAILED
static u8 vpm_get_isr(struct virtio_pci_modern_device *vdev)
size_t max_pkt_len
Maximum packet length.
unsigned long ioaddr
Base pio register address.
#define VIRTIO_CONFIG_S_DRIVER_OK
#define DBG(...)
Print a debugging message.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
static int virtnet_probe(struct pci_device *pci)
Probe PCI device.
void vring_add_buf(struct vring_virtqueue *vq, struct vring_list list[], unsigned int out, unsigned int in, void *opaque, int num_added)
static void vp_reset(unsigned int ioaddr)
static u64 vpm_get_features(struct virtio_pci_modern_device *vdev)
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
#define NULL
NULL pointer (VOID *)
#define VIRTIO_CONFIG_S_FEATURES_OK
#define PCI_ROM(_vendor, _device, _name, _description, _data)
static int virtnet_open_legacy(struct net_device *netdev)
Open network device, legacy virtio 0.9.5.
struct vring_virtqueue * virtqueue
RX/TX virtqueues.