FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pci.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __included_virtio_pci_h__
17 #define __included_virtio_pci_h__
18 
19 /* VirtIO ABI version, this must match exactly. */
20 #define VIRTIO_PCI_ABI_VERSION 0
21 
22 /* VirtIO device IDs. */
23 #define VIRTIO_ID_NETWORK 0x01
24 
25 /*
26  * Vector value used to disable MSI for queue.
27  * define in include/linux/virtio_pci.h
28  */
29 #define VIRTIO_MSI_NO_VECTOR 0xFFFF
30 
31 /* The bit of the ISR which indicates a device has an interrupt. */
32 #define VIRTIO_PCI_ISR_INTR 0x1
33 /* The bit of the ISR which indicates a device configuration change. */
34 #define VIRTIO_PCI_ISR_CONFIG 0x2
35 
36 /* Status byte for guest to report progress. */
37 #define foreach_virtio_config_status_flags \
38  _ (VIRTIO_CONFIG_STATUS_RESET, 0x00) \
39  _ (VIRTIO_CONFIG_STATUS_ACK, 0x01) \
40  _ (VIRTIO_CONFIG_STATUS_DRIVER, 0x02) \
41  _ (VIRTIO_CONFIG_STATUS_DRIVER_OK, 0x04) \
42  _ (VIRTIO_CONFIG_STATUS_FEATURES_OK, 0x08) \
43  _ (VIRTIO_CONFIG_STATUS_DEVICE_NEEDS_RESET, 0x40) \
44  _ (VIRTIO_CONFIG_STATUS_FAILED, 0x80)
45 
46 typedef enum
47 {
48 #define _(a, b) a = b,
50 #undef _
52 
53 
54 #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
55 #define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */
56 
57 #define VIRTIO_NET_OK 0
58 #define VIRTIO_NET_ERR 1
59 
60 /* If multiqueue is provided by host, then we support it. */
61 #define VIRTIO_NET_CTRL_MQ 4
62 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0
63 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1
64 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000
65 
66 /*
67  * Control network offloads
68  * Reconfigures the network offloads that Guest can handle.
69  * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit.
70  * Command data format matches the feature bit mask exactly.
71  * See VIRTIO_NET_F_GUEST_* for the list of offloads
72  * that can be enabled/disabled.
73  */
74 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5
75 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0
76 
77 /* Common configuration */
78 #define VIRTIO_PCI_CAP_COMMON_CFG 1
79 /* Notifications */
80 #define VIRTIO_PCI_CAP_NOTIFY_CFG 2
81 /* ISR Status */
82 #define VIRTIO_PCI_CAP_ISR_CFG 3
83 /* Device specific configuration */
84 #define VIRTIO_PCI_CAP_DEVICE_CFG 4
85 /* PCI configuration access */
86 #define VIRTIO_PCI_CAP_PCI_CFG 5
87 
88 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
89 
90 #define VIRTIO_PCI_VRING_ALIGN 4096
91 
92 typedef enum
93 {
98 
99 /* This is the PCI capability header: */
100 typedef struct
101 {
102  u8 cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */
103  u8 cap_next; /* Generic PCI field: next ptr. */
104  u8 cap_len; /* Generic PCI field: capability length */
105  u8 cfg_type; /* Identifies the structure. */
106  u8 bar; /* Where to find it. */
107  u8 padding[3]; /* Pad to full dword. */
108  u32 offset; /* Offset within bar. */
109  u32 length; /* Length of the structure, in bytes. */
111 
112 typedef struct
113 {
115  u32 notify_off_multiplier; /* Multiplier for queue_notify_off. */
117 
118 /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
119 typedef struct
120 {
121  /* About the whole device. */
122  u32 device_feature_select; /* read-write */
123  u32 device_feature; /* read-only */
124  u32 driver_feature_select; /* read-write */
125  u32 driver_feature; /* read-write */
126  u16 msix_config; /* read-write */
127  u16 num_queues; /* read-only */
128  u8 device_status; /* read-write */
129  u8 config_generation; /* read-only */
130 
131  /* About a specific virtqueue. */
132  u16 queue_select; /* read-write */
133  u16 queue_size; /* read-write, power of 2. */
134  u16 queue_msix_vector; /* read-write */
135  u16 queue_enable; /* read-write */
136  u16 queue_notify_off; /* read-only */
137  u64 queue_desc; /* read-write */
138  u64 queue_driver; /* read-write */
139  u64 queue_device; /* read-write */
141 
142 typedef struct
143 {
144  u8 mac[6];
149 
150 /*
151  * Control virtqueue data structures
152  *
153  * The control virtqueue expects a header in the first sg entry
154  * and an ack/status response in the last entry. Data for the
155  * command goes in between.
156  */
157 /* *INDENT-OFF* */
158 typedef CLIB_PACKED (struct
159 {
160  u8 class;
161  u8 cmd;
162 }) virtio_net_ctrl_hdr_t;
163 /* *INDENT-ON* */
164 
166 
167 typedef struct
168 {
169  virtio_net_ctrl_hdr_t ctrl;
171  u8 data[1024];
173 
174 typedef struct _virtio_pci_func
175 {
176  void (*read_config) (vlib_main_t * vm, virtio_if_t * vif, void *dst,
177  int len, u32 addr);
178  void (*write_config) (vlib_main_t * vm, virtio_if_t * vif, void *src,
179  int len, u32 addr);
180 
181  u64 (*get_device_features) (vlib_main_t * vm, virtio_if_t * vif);
182  u64 (*get_driver_features) (vlib_main_t * vm, virtio_if_t * vif);
183  void (*set_driver_features) (vlib_main_t * vm, virtio_if_t * vif,
184  u64 features);
185 
186  u8 (*get_status) (vlib_main_t * vm, virtio_if_t * vif);
187  void (*set_status) (vlib_main_t * vm, virtio_if_t * vif, u8 status);
188  u8 (*device_reset) (vlib_main_t * vm, virtio_if_t * vif);
189 
190  u8 (*get_isr) (vlib_main_t * vm, virtio_if_t * vif);
191 
192  u16 (*get_queue_size) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id);
193  void (*set_queue_size) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id,
194  u16 queue_size);
195  u8 (*setup_queue) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id,
196  void *p);
197  void (*del_queue) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id);
198  u16 (*get_queue_notify_off) (vlib_main_t * vm, virtio_if_t * vif,
199  u16 queue_id);
200  void (*notify_queue) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id,
201  u16 queue_notify_offset);
202 
203  u16 (*set_config_irq) (vlib_main_t * vm, virtio_if_t * vif, u16 vec);
204  u16 (*set_queue_irq) (vlib_main_t * vm, virtio_if_t * vif, u16 vec,
205  u16 queue_id);
206 
207  void (*get_mac) (vlib_main_t * vm, virtio_if_t * vif);
208  void (*set_mac) (vlib_main_t * vm, virtio_if_t * vif);
209  u16 (*get_device_status) (vlib_main_t * vm, virtio_if_t * vif);
210  u16 (*get_max_queue_pairs) (vlib_main_t * vm, virtio_if_t * vif);
211  u16 (*get_mtu) (vlib_main_t * vm, virtio_if_t * vif);
212  void (*device_debug_config_space) (vlib_main_t * vm, virtio_if_t * vif);
214 
215 #define foreach_virtio_flags \
216  _ (GSO, 0) \
217  _ (CSUM_OFFLOAD, 1) \
218  _ (GRO_COALESCE, 2) \
219  _ (PACKED, 3) \
220  _ (IN_ORDER, 4) \
221  _ (BUFFERING, 5)
222 
223 typedef enum
224 {
225 #define _(a, b) VIRTIO_FLAG_##a = (1 << b),
227 #undef _
228 } virtio_flag_t;
229 
230 typedef struct
231 {
233  /* return */
245 
248 
249 extern void device_status (vlib_main_t * vm, virtio_if_t * vif);
254  int gso_enabled,
255  int checksum_offload_enabled,
256  int offloads_disabled);
257 #endif /* __included_virtio_pci_h__ */
258 /*
259  * fd.io coding-style-patch-verification: ON
260  *
261  * Local Variables:
262  * eval: (c-set-style "gnu")
263  * End:
264  */
virtio_ctrl_msg_t::status
virtio_net_ctrl_ack_t status
Definition: pci.h:170
mac
vl_api_mac_address_t mac
Definition: l2.api:559
virtio_pci_common_cfg_t::config_generation
u8 config_generation
Definition: pci.h:129
virtio_config_status_flags_t
virtio_config_status_flags_t
Definition: pci.h:46
virtio_pci_create_if
void virtio_pci_create_if(vlib_main_t *vm, virtio_pci_create_if_args_t *args)
Definition: pci.c:1348
VIRTIO_MSIX_ENABLED
@ VIRTIO_MSIX_ENABLED
Definition: pci.h:96
virtio_pci_common_cfg_t::queue_enable
u16 queue_enable
Definition: pci.h:135
virtio_pci_cap_t::offset
u32 offset
Definition: pci.h:108
virtio_pci_common_cfg_t::queue_select
u16 queue_select
Definition: pci.h:132
virtio_pci_notify_cap_t::cap
virtio_pci_cap_t cap
Definition: pci.h:114
virtio_net_config_t::max_virtqueue_pairs
u16 max_virtqueue_pairs
Definition: pci.h:146
padding
u32 padding
Definition: vhost_user.h:124
u8
#define u8
Padding.
Definition: clib.h:121
virtio_pci_create_if_args_t::gso_enabled
u8 gso_enabled
Definition: pci.h:239
virtio_pci_cap_t::cap_len
u8 cap_len
Definition: pci.h:104
virtio_pci_create_if_args_t::mac_addr_set
u8 mac_addr_set
Definition: pci.h:236
virtio_ctrl_msg_t::ctrl
virtio_net_ctrl_hdr_t ctrl
Definition: pci.h:169
u16
unsigned short u16
Definition: types.h:57
virtio_pci_cap_t
Definition: pci.h:100
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
virtio_pci_common_cfg_t::num_queues
u16 num_queues
Definition: pci.h:127
virtio_pci_common_cfg_t::queue_msix_vector
u16 queue_msix_vector
Definition: pci.h:134
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
virtio_net_config_t
Definition: pci.h:142
virtio_pci_create_if_args_t::features
u64 features
Definition: pci.h:238
virtio_pci_common_cfg_t::device_feature_select
u32 device_feature_select
Definition: pci.h:122
foreach_virtio_config_status_flags
#define foreach_virtio_config_status_flags
Definition: pci.h:37
i32
signed int i32
Definition: types.h:77
VIRTIO_MSIX_NONE
@ VIRTIO_MSIX_NONE
Definition: pci.h:94
foreach_virtio_flags
#define foreach_virtio_flags
Definition: pci.h:215
virtio_pci_common_cfg_t::queue_notify_off
u16 queue_notify_off
Definition: pci.h:136
len
u8 len
Definition: ip_types.api:103
virtio_pci_notify_cap_t
Definition: pci.h:112
virtio_pci_delete_if
int virtio_pci_delete_if(vlib_main_t *vm, virtio_if_t *ad)
Definition: pci.c:1548
CLIB_PACKED
typedef CLIB_PACKED(struct { u8 class;u8 cmd;}) virtio_net_ctrl_hdr_t
virtio_pci_common_cfg_t::queue_driver
u64 queue_driver
Definition: pci.h:138
virtio_pci_cap_t::cap_vndr
u8 cap_vndr
Definition: pci.h:102
virtio_pci_common_cfg_t::driver_feature
u32 driver_feature
Definition: pci.h:125
virtio_pci_create_if_args_t::addr
u32 addr
Definition: pci.h:232
virtio_pci_create_if_args_t::virtio_flags
u32 virtio_flags
Definition: pci.h:242
virtio_pci_create_if_args_t::checksum_offload_enabled
u8 checksum_offload_enabled
Definition: pci.h:240
virtio_pci_create_if_args_t::error
clib_error_t * error
Definition: pci.h:243
virtio_pci_create_if_args_t::rv
i32 rv
Definition: pci.h:234
virtio_flag_t
virtio_flag_t
Definition: pci.h:223
src
vl_api_address_t src
Definition: gre.api:54
virtio_pci_create_if_args_t::sw_if_index
u32 sw_if_index
Definition: pci.h:235
virtio_pci_cap_t::bar
u8 bar
Definition: pci.h:106
virtio_pci_common_cfg_t::device_status
u8 device_status
Definition: pci.h:128
virtio_net_config_t::mtu
u16 mtu
Definition: pci.h:147
mac_addr
vl_api_mac_address_t mac_addr
Definition: l2.api:210
data
u8 data[128]
Definition: ipsec_types.api:92
virtio_pci_legacy_func
const virtio_pci_func_t virtio_pci_legacy_func
Definition: virtio_pci_legacy.c:360
virtio_pci_common_cfg_t::queue_desc
u64 queue_desc
Definition: pci.h:137
u64
unsigned long u64
Definition: types.h:89
virtio_pci_common_cfg_t
Definition: pci.h:119
u32
unsigned int u32
Definition: types.h:88
virtio_pci_cap_t::length
u32 length
Definition: pci.h:109
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
virtio_pci_common_cfg_t::device_feature
u32 device_feature
Definition: pci.h:123
virtio_pci_common_cfg_t::queue_size
u16 queue_size
Definition: pci.h:133
virtio_ctrl_msg_t
Definition: pci.h:167
virtio_if_t
Definition: virtio.h:128
virtio_pci_cap_t::cap_next
u8 cap_next
Definition: pci.h:103
VIRTIO_MSIX_DISABLED
@ VIRTIO_MSIX_DISABLED
Definition: pci.h:95
virtio_pci_create_if_args_t
Definition: pci.h:230
vlib_main_t
Definition: main.h:102
virtio_pci_notify_cap_t::notify_off_multiplier
u32 notify_off_multiplier
Definition: pci.h:115
u8
unsigned char u8
Definition: types.h:56
virtio_pci_common_cfg_t::msix_config
u16 msix_config
Definition: pci.h:126
clib_error_t
Definition: clib_error.h:21
virtio_pci_modern_func
const virtio_pci_func_t virtio_pci_modern_func
Definition: virtio_pci_modern.c:420
virtio_pci_common_cfg_t::queue_device
u64 queue_device
Definition: pci.h:139
virtio_pci_enable_disable_offloads
int virtio_pci_enable_disable_offloads(vlib_main_t *vm, virtio_if_t *vif, int gso_enabled, int checksum_offload_enabled, int offloads_disabled)
Definition: pci.c:1630
virtio_pci_create_if_args_t::buffering_size
u32 buffering_size
Definition: pci.h:241
virtio_pci_common_cfg_t::driver_feature_select
u32 driver_feature_select
Definition: pci.h:124
virtio_net_config_t::status
u16 status
Definition: pci.h:145
virtio_pci_func_t
struct _virtio_pci_func virtio_pci_func_t
virtio_pci_cap_t::cfg_type
u8 cfg_type
Definition: pci.h:105
virtio_msix_status_t
virtio_msix_status_t
Definition: pci.h:92
device_status
void device_status(vlib_main_t *vm, virtio_if_t *vif)
Definition: pci.c:172
virtio_net_ctrl_ack_t
u8 virtio_net_ctrl_ack_t
Definition: pci.h:165