Sfoglia il codice sorgente

[virtio] Add virtio 1.0 constants and data structures

Virtio 1.0 introduces new constants and data structures, common to all
devices as well as specific to virtio-net.  This commit adds a subset
of these to be able to drive the virtio-net 1.0 network device.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Ladi Prosek 8 anni fa
parent
commit
7b499f849e

+ 16
- 0
src/drivers/net/virtio-net.h Vedi File

@@ -14,6 +14,12 @@
14 14
 #define VIRTIO_NET_F_HOST_TSO6  12      /* Host can handle TSOv6 in. */
15 15
 #define VIRTIO_NET_F_HOST_ECN   13      /* Host can handle TSO[6] w/ ECN in. */
16 16
 #define VIRTIO_NET_F_HOST_UFO   14      /* Host can handle UFO in. */
17
+#define VIRTIO_NET_F_MRG_RXBUF  15      /* Driver can merge receive buffers. */
18
+#define VIRTIO_NET_F_STATUS     16      /* Configuration status field is available. */
19
+#define VIRTIO_NET_F_CTRL_VQ    17      /* Control channel is available. */
20
+#define VIRTIO_NET_F_CTRL_RX    18      /* Control channel RX mode support. */
21
+#define VIRTIO_NET_F_CTRL_VLAN  19      /* Control channel VLAN filtering. */
22
+#define VIRTIO_NET_F_GUEST_ANNOUNCE 21  /* Driver can send gratuitous packets. */
17 23
 
18 24
 struct virtio_net_config
19 25
 {
@@ -41,4 +47,14 @@ struct virtio_net_hdr
41 47
    uint16_t csum_start;
42 48
    uint16_t csum_offset;
43 49
 };
50
+
51
+/* Virtio 1.0 version of the first element of the scatter-gather list. */
52
+struct virtio_net_hdr_modern
53
+{
54
+   struct virtio_net_hdr legacy;
55
+
56
+   /* Used only if VIRTIO_NET_F_MRG_RXBUF: */
57
+   uint16_t num_buffers;
58
+};
59
+
44 60
 #endif /* _VIRTIO_NET_H_ */

+ 60
- 0
src/include/ipxe/virtio-pci.h Vedi File

@@ -37,6 +37,66 @@
37 37
 /* Virtio ABI version, this must match exactly */
38 38
 #define VIRTIO_PCI_ABI_VERSION          0
39 39
 
40
+/* PCI capability types: */
41
+#define VIRTIO_PCI_CAP_COMMON_CFG       1  /* Common configuration */
42
+#define VIRTIO_PCI_CAP_NOTIFY_CFG       2  /* Notifications */
43
+#define VIRTIO_PCI_CAP_ISR_CFG          3  /* ISR access */
44
+#define VIRTIO_PCI_CAP_DEVICE_CFG       4  /* Device specific configuration */
45
+#define VIRTIO_PCI_CAP_PCI_CFG          5  /* PCI configuration access */
46
+
47
+#define __u8       uint8_t
48
+#define __le16     uint16_t
49
+#define __le32     uint32_t
50
+#define __le64     uint64_t
51
+
52
+/* This is the PCI capability header: */
53
+struct virtio_pci_cap {
54
+    __u8 cap_vndr;    /* Generic PCI field: PCI_CAP_ID_VNDR */
55
+    __u8 cap_next;    /* Generic PCI field: next ptr. */
56
+    __u8 cap_len;     /* Generic PCI field: capability length */
57
+    __u8 cfg_type;    /* Identifies the structure. */
58
+    __u8 bar;         /* Where to find it. */
59
+    __u8 padding[3];  /* Pad to full dword. */
60
+    __le32 offset;    /* Offset within bar. */
61
+    __le32 length;    /* Length of the structure, in bytes. */
62
+};
63
+
64
+struct virtio_pci_notify_cap {
65
+    struct virtio_pci_cap cap;
66
+    __le32 notify_off_multiplier; /* Multiplier for queue_notify_off. */
67
+};
68
+
69
+struct virtio_pci_cfg_cap {
70
+    struct virtio_pci_cap cap;
71
+    __u8 pci_cfg_data[4]; /* Data for BAR access. */
72
+};
73
+
74
+/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
75
+struct virtio_pci_common_cfg {
76
+    /* About the whole device. */
77
+    __le32 device_feature_select; /* read-write */
78
+    __le32 device_feature;        /* read-only */
79
+    __le32 guest_feature_select;  /* read-write */
80
+    __le32 guest_feature;         /* read-write */
81
+    __le16 msix_config;           /* read-write */
82
+    __le16 num_queues;            /* read-only */
83
+    __u8 device_status;           /* read-write */
84
+    __u8 config_generation;       /* read-only */
85
+
86
+    /* About a specific virtqueue. */
87
+    __le16 queue_select;          /* read-write */
88
+    __le16 queue_size;            /* read-write, power of 2. */
89
+    __le16 queue_msix_vector;     /* read-write */
90
+    __le16 queue_enable;          /* read-write */
91
+    __le16 queue_notify_off;      /* read-only */
92
+    __le32 queue_desc_lo;         /* read-write */
93
+    __le32 queue_desc_hi;         /* read-write */
94
+    __le32 queue_avail_lo;        /* read-write */
95
+    __le32 queue_avail_hi;        /* read-write */
96
+    __le32 queue_used_lo;         /* read-write */
97
+    __le32 queue_used_hi;         /* read-write */
98
+};
99
+
40 100
 static inline u32 vp_get_features(unsigned int ioaddr)
41 101
 {
42 102
    return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);

+ 8
- 0
src/include/ipxe/virtio-ring.h Vedi File

@@ -8,9 +8,17 @@
8 8
 #define VIRTIO_CONFIG_S_DRIVER          2
9 9
 /* Driver has used its parts of the config, and is happy */
10 10
 #define VIRTIO_CONFIG_S_DRIVER_OK       4
11
+/* Driver has finished configuring features */
12
+#define VIRTIO_CONFIG_S_FEATURES_OK     8
11 13
 /* We've given up on this device. */
12 14
 #define VIRTIO_CONFIG_S_FAILED          0x80
13 15
 
16
+/* Virtio feature flags used to negotiate device and driver features. */
17
+/* Can the device handle any descriptor layout? */
18
+#define VIRTIO_F_ANY_LAYOUT             27
19
+/* v1.0 compliant. */
20
+#define VIRTIO_F_VERSION_1              32
21
+
14 22
 #define MAX_QUEUE_NUM      (256)
15 23
 
16 24
 #define VRING_DESC_F_NEXT  1

Loading…
Annulla
Salva