Skip to content

Commit ad4dd47

Browse files
committed
Define struct virtio_net_dev and functions in virtio-net.h
Define struct `virtio_net_dev` to represent the virtio-net device. Provide `virtio_net_init` for initializing the TAP device, `virtio_net_init_pci` for registering the virtio-net device to PCI, and `virtio_net_exit` for cleanup during VM exit.
1 parent 4a42541 commit ad4dd47

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/virtio-net.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
#pragma once
22

3+
#include <linux/virtio_net.h>
4+
#include "pci.h"
5+
#include "virtio-pci.h"
6+
#include "virtq.h"
7+
38
#define VIRTIO_NET_VIRTQ_NUM 2
49
#define VIRTIO_NET_PCI_CLASS 0x020000
10+
11+
struct virtio_net_dev {
12+
struct virtio_pci_dev virtio_pci_dev;
13+
struct virtio_net_config config;
14+
struct virtq vq[VIRTIO_NET_VIRTQ_NUM];
15+
int tapfd;
16+
int irqfd;
17+
int rx_ioeventfd;
18+
int tx_ioeventfd;
19+
int irq_num;
20+
pthread_t rx_thread;
21+
pthread_t tx_thread;
22+
bool enable;
23+
};
24+
25+
bool virtio_net_init(struct virtio_net_dev *virtio_net_dev);
26+
void virtio_net_exit(struct virtio_net_dev *virtio_net_dev);
27+
void virtio_net_init_pci(struct virtio_net_dev *virtio_net_dev,
28+
struct pci *pci,
29+
struct bus *io_bus,
30+
struct bus *mmio_bus);
31+
32+

0 commit comments

Comments
 (0)