blob: 1f569acb00852f9be9f4f1be1302d40f1552859d [file] [log] [blame]
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001/*
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#include <fcntl.h>
17#include <sys/ioctl.h>
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020018
19#include <vppinfra/types.h>
20#include <vlib/vlib.h>
21#include <vlib/pci/pci.h>
22#include <vnet/ethernet/ethernet.h>
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020023#include <vnet/ip/ip4_packet.h>
24#include <vnet/ip/ip6_packet.h>
25#include <vnet/devices/virtio/virtio.h>
26#include <vnet/devices/virtio/pci.h>
27
28#define PCI_VENDOR_ID_VIRTIO 0x1af4
29#define PCI_DEVICE_ID_VIRTIO_NIC 0x1000
30/* Doesn't support modern device */
31#define PCI_DEVICE_ID_VIRTIO_NIC_MODERN 0x1041
32
33#define PCI_CAPABILITY_LIST 0x34
34#define PCI_CAP_ID_VNDR 0x09
35#define PCI_CAP_ID_MSIX 0x11
36
37#define PCI_MSIX_ENABLE 0x8000
38
Mohsin Kazmib74fe322019-01-31 13:50:56 +000039#define PCI_CONFIG_SIZE(vif) ((vif->msix_enabled == VIRTIO_MSIX_ENABLED) ? \
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020040 24 : 20)
41
42static pci_device_id_t virtio_pci_device_ids[] = {
43 {
44 .vendor_id = PCI_VENDOR_ID_VIRTIO,
45 .device_id = PCI_DEVICE_ID_VIRTIO_NIC},
46 {
47 .vendor_id = PCI_VENDOR_ID_VIRTIO,
48 .device_id = PCI_DEVICE_ID_VIRTIO_NIC_MODERN},
49 {0},
50};
51
52static void
53virtio_pci_legacy_read_config (vlib_main_t * vm, virtio_if_t * vif, void *dst,
54 int len, u32 addr)
55{
56 u32 size = 0;
57 vlib_pci_dev_handle_t h = vif->pci_dev_handle;
58
59 while (len > 0)
60 {
61 if (len >= 4)
62 {
63 size = 4;
Mohsin Kazmib74fe322019-01-31 13:50:56 +000064 vlib_pci_read_io_u32 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020065 }
66 else if (len >= 2)
67 {
68 size = 2;
Mohsin Kazmib74fe322019-01-31 13:50:56 +000069 vlib_pci_read_io_u16 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020070 }
71 else
72 {
73 size = 1;
Mohsin Kazmib74fe322019-01-31 13:50:56 +000074 vlib_pci_read_io_u8 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020075 }
76 dst = (u8 *) dst + size;
77 addr += size;
78 len -= size;
79 }
80}
81
82static void
83virtio_pci_legacy_write_config (vlib_main_t * vm, virtio_if_t * vif,
84 void *src, int len, u32 addr)
85{
86 u32 size = 0;
87 vlib_pci_dev_handle_t h = vif->pci_dev_handle;
88
89 while (len > 0)
90 {
91 if (len >= 4)
92 {
93 size = 4;
Mohsin Kazmib74fe322019-01-31 13:50:56 +000094 vlib_pci_write_io_u32 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020095 }
96 else if (len >= 2)
97 {
98 size = 2;
Mohsin Kazmib74fe322019-01-31 13:50:56 +000099 vlib_pci_write_io_u16 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200100 }
101 else
102 {
103 size = 1;
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000104 vlib_pci_write_io_u8 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200105 }
106 src = (u8 *) src + size;
107 addr += size;
108 len -= size;
109 }
110}
111
112static u64
113virtio_pci_legacy_get_features (vlib_main_t * vm, virtio_if_t * vif)
114{
115 u32 features;
116 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_HOST_FEATURES,
117 &features);
118 return features;
119}
120
121static u32
122virtio_pci_legacy_set_features (vlib_main_t * vm, virtio_if_t * vif,
123 u64 features)
124{
125 if ((features >> 32) != 0)
126 {
127 clib_warning ("only 32 bit features are allowed for legacy virtio!");
128 }
129 u32 feature = 0, guest_features = (u32) features;
130 vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
131 &guest_features);
132 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
133 &feature);
134 return feature;
135}
136
137static u8
138virtio_pci_legacy_get_status (vlib_main_t * vm, virtio_if_t * vif)
139{
140 u8 status = 0;
141 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &status);
142 return status;
143}
144
145static void
146virtio_pci_legacy_set_status (vlib_main_t * vm, virtio_if_t * vif, u8 status)
147{
148 if (status != VIRTIO_CONFIG_STATUS_RESET)
149 status |= virtio_pci_legacy_get_status (vm, vif);
150 vlib_pci_write_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &status);
151}
152
153static u8
154virtio_pci_legacy_reset (vlib_main_t * vm, virtio_if_t * vif)
155{
156 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_RESET);
157 return virtio_pci_legacy_get_status (vm, vif);
158}
159
160static u8
161virtio_pci_legacy_get_isr (vlib_main_t * vm, virtio_if_t * vif)
162{
163 u8 isr = 0;
164 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_ISR, &isr);
165 return isr;
166}
167
168static u16
169virtio_pci_legacy_get_queue_num (vlib_main_t * vm, virtio_if_t * vif,
170 u16 queue_id)
171{
172 u16 queue_num = 0;
173 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
174 &queue_id);
175 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NUM,
176 &queue_num);
177 return queue_num;
178}
179
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200180static int
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200181virtio_pci_legacy_setup_queue (vlib_main_t * vm, virtio_if_t * vif,
182 u16 queue_id, void *p)
183{
184 u64 addr = vlib_physmem_get_pa (vm, p) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT;
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200185 u32 addr2 = 0;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200186 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
187 &queue_id);
188 vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
189 (u32 *) & addr);
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200190 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
191 &addr2);
192 if ((u32) addr == addr2)
193 return 0;
194 return 1;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200195}
196
197static void
198virtio_pci_legacy_del_queue (vlib_main_t * vm, virtio_if_t * vif,
199 u16 queue_id)
200{
201 u32 src = 0;
202 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
203 &queue_id);
204 vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN, &src);
205}
206
207inline void
208virtio_pci_legacy_notify_queue (vlib_main_t * vm, virtio_if_t * vif,
209 u16 queue_id)
210{
211 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NOTIFY,
212 &queue_id);
213}
214
215/* Enable one vector (0) for Link State Intrerrupt */
216static u16
217virtio_pci_legacy_set_config_irq (vlib_main_t * vm, virtio_if_t * vif,
218 u16 vec)
219{
220 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR,
221 &vec);
222 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR,
223 &vec);
224 return vec;
225}
226
227static u16
228virtio_pci_legacy_set_queue_irq (vlib_main_t * vm, virtio_if_t * vif, u16 vec,
229 u16 queue_id)
230{
231 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
232 &queue_id);
233 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR,
234 &vec);
235 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR,
236 &vec);
237 return vec;
238}
239
240static u32
241virtio_pci_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw,
242 u32 flags)
243{
244 return 0;
245}
246
247static clib_error_t *
248virtio_pci_get_max_virtqueue_pairs (vlib_main_t * vm, virtio_if_t * vif)
249{
250 virtio_net_config_t config;
251 clib_error_t *error = 0;
252 u16 max_queue_pairs = 1;
253
254 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
255 {
256 virtio_pci_legacy_read_config (vm, vif, &config.max_virtqueue_pairs,
Mohsin Kazmi46f877e2019-04-08 10:36:18 +0200257 sizeof (config.max_virtqueue_pairs),
258 STRUCT_OFFSET_OF (virtio_net_config_t,
259 max_virtqueue_pairs));
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200260 max_queue_pairs = config.max_virtqueue_pairs;
261 }
262
Damjan Marionf41244f2019-11-08 17:41:06 +0100263 virtio_log_debug (vif, "max queue pair is %x", max_queue_pairs);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200264 if (max_queue_pairs < 1 || max_queue_pairs > 0x8000)
Mohsin Kazmi46f877e2019-04-08 10:36:18 +0200265 return clib_error_return (error, "max queue pair is %x", max_queue_pairs);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200266
267 vif->max_queue_pairs = max_queue_pairs;
268 return error;
269}
270
271static void
272virtio_pci_set_mac (vlib_main_t * vm, virtio_if_t * vif)
273{
274 virtio_pci_legacy_write_config (vm, vif, vif->mac_addr,
275 sizeof (vif->mac_addr), 0);
276}
277
278static u32
279virtio_pci_get_mac (vlib_main_t * vm, virtio_if_t * vif)
280{
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000281 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MAC))
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200282 {
283 virtio_pci_legacy_read_config (vm, vif, vif->mac_addr,
284 sizeof (vif->mac_addr), 0);
285 return 0;
286 }
287 return 1;
288}
289
290static u16
291virtio_pci_is_link_up (vlib_main_t * vm, virtio_if_t * vif)
292{
293 /*
294 * Minimal driver: assumes link is up
295 */
296 u16 status = 1;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000297 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_STATUS))
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200298 virtio_pci_legacy_read_config (vm, vif, &status, sizeof (status), /* mac */
Mohsin Kazmi46f877e2019-04-08 10:36:18 +0200299 STRUCT_OFFSET_OF (virtio_net_config_t,
300 status));
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200301 return status;
302}
303
304static void
305virtio_pci_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
306{
307 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000308 virtio_main_t *vim = &virtio_main;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200309 uword pd = vlib_pci_get_private_data (vm, h);
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000310 virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200311 u16 qid = line;
312
313 vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index, qid);
314}
315
316static void
317virtio_pci_irq_1_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
318{
319 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000320 virtio_main_t *vim = &virtio_main;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200321 uword pd = vlib_pci_get_private_data (vm, h);
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000322 virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200323
324 if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
325 {
326 vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
327 vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
328 VNET_HW_INTERFACE_FLAG_LINK_UP);
329 }
330 else
331 {
332 vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
333 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
334 }
335}
336
337static void
338virtio_pci_irq_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h)
339{
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000340 virtio_main_t *vim = &virtio_main;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200341 uword pd = vlib_pci_get_private_data (vm, h);
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000342 virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200343 u8 isr = 0;
344 u16 line = 0;
345
346 isr = virtio_pci_legacy_get_isr (vm, vif);
347
348 /*
349 * If the lower bit is set: look through the used rings of
350 * all virtqueues for the device, to see if any progress has
351 * been made by the device which requires servicing.
352 */
353 if (isr & VIRTIO_PCI_ISR_INTR)
354 virtio_pci_irq_0_handler (vm, h, line);
355
356 if (isr & VIRTIO_PCI_ISR_CONFIG)
357 virtio_pci_irq_1_handler (vm, h, line);
358}
359
360inline void
361device_status (vlib_main_t * vm, virtio_if_t * vif)
362{
363 struct status_struct
364 {
365 u8 bit;
366 char *str;
367 };
368 struct status_struct *status_entry;
369 static struct status_struct status_array[] = {
370#define _(s,b) { .str = #s, .bit = b, },
371 foreach_virtio_config_status_flags
372#undef _
373 {.str = NULL}
374 };
375
376 vlib_cli_output (vm, " status 0x%x", vif->status);
377
378 status_entry = (struct status_struct *) &status_array;
379 while (status_entry->str)
380 {
381 if (vif->status & status_entry->bit)
382 vlib_cli_output (vm, " %s (%x)", status_entry->str,
383 status_entry->bit);
384 status_entry++;
385 }
386}
387
388inline void
389debug_device_config_space (vlib_main_t * vm, virtio_if_t * vif)
390{
391 u32 data_u32;
392 u16 data_u16;
393 u8 data_u8;
394 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_HOST_FEATURES,
395 &data_u32);
396 vlib_cli_output (vm, "remote features 0x%lx", data_u32);
397 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
398 &data_u32);
399 vlib_cli_output (vm, "guest features 0x%lx", data_u32);
400 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
401 &data_u32);
402 vlib_cli_output (vm, "queue address 0x%lx", data_u32);
403 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NUM,
404 &data_u16);
405 vlib_cli_output (vm, "queue size 0x%x", data_u16);
406 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
407 &data_u16);
408 vlib_cli_output (vm, "queue select 0x%x", data_u16);
409 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NOTIFY,
410 &data_u16);
411 vlib_cli_output (vm, "queue notify 0x%x", data_u16);
412 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &data_u8);
413 vlib_cli_output (vm, "status 0x%x", data_u8);
414 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_ISR, &data_u8);
415 vlib_cli_output (vm, "isr 0x%x", data_u8);
416
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000417 if (vif->msix_enabled == VIRTIO_MSIX_ENABLED)
418 {
419 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR,
420 &data_u16);
421 vlib_cli_output (vm, "config vector 0x%x", data_u16);
422 u16 queue_id = 0;
423 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
424 &queue_id);
425 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR,
426 &data_u16);
427 vlib_cli_output (vm, "queue vector for queue (0) 0x%x", data_u16);
428 }
429
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200430 u8 mac[6];
431 virtio_pci_legacy_read_config (vm, vif, mac, sizeof (mac), 0);
432 vlib_cli_output (vm, "mac %U", format_ethernet_address, mac);
433 virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), /* offset to status */
434 6);
435 vlib_cli_output (vm, "link up/down status 0x%x", data_u16);
436 virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16),
437 /* offset to max_virtqueue */ 8);
438 vlib_cli_output (vm, "num of virtqueue 0x%x", data_u16);
439 virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), /* offset to mtu */
440 10);
441 vlib_cli_output (vm, "mtu 0x%x", data_u16);
442
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000443 u32 i = PCI_CONFIG_SIZE (vif) + 12, a = 4;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200444 i += a;
445 i &= ~a;
446 for (; i < 64; i += 4)
447 {
448 u32 data = 0;
449 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, i, &data);
450 vlib_cli_output (vm, "0x%lx", data);
451 }
452}
453
Mohsin Kazmi05493782019-05-01 14:26:17 +0200454struct virtio_ctrl_msg
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000455{
456 struct virtio_net_ctrl_hdr ctrl;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000457 virtio_net_ctrl_ack status;
Mohsin Kazmi05493782019-05-01 14:26:17 +0200458 u8 data[1024];
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000459};
460
461static int
Mohsin Kazmi05493782019-05-01 14:26:17 +0200462virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif,
463 struct virtio_ctrl_msg *data, u32 len)
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000464{
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000465 virtio_vring_t *vring = vif->cxq_vring;
Mohsin Kazmi05493782019-05-01 14:26:17 +0200466 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
467 struct virtio_ctrl_msg result;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000468 u32 buffer_index;
469 vlib_buffer_t *b;
470 u16 used, next, avail;
471 u16 sz = vring->size;
472 u16 mask = sz - 1;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000473
474 used = vring->desc_in_use;
475 next = vring->desc_next;
476 avail = vring->avail->idx;
477 struct vring_desc *d = &vring->desc[next];
478
479 if (vlib_buffer_alloc (vm, &buffer_index, 1))
480 b = vlib_get_buffer (vm, buffer_index);
481 else
482 return VIRTIO_NET_ERR;
483 /*
484 * current_data may not be initialized with 0 and may contain
485 * previous offset.
486 */
487 b->current_data = 0;
Mohsin Kazmi05493782019-05-01 14:26:17 +0200488 clib_memcpy (vlib_buffer_get_current (b), data,
489 sizeof (struct virtio_ctrl_msg));
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000490 d->flags = VRING_DESC_F_NEXT;
491 d->addr = vlib_buffer_get_current_pa (vm, b);
492 d->len = sizeof (struct virtio_net_ctrl_hdr);
493 vring->avail->ring[avail & mask] = next;
494 avail++;
495 next = (next + 1) & mask;
496 d->next = next;
497 used++;
498
499 d = &vring->desc[next];
500 d->flags = VRING_DESC_F_NEXT;
501 d->addr = vlib_buffer_get_current_pa (vm, b) +
Mohsin Kazmi05493782019-05-01 14:26:17 +0200502 STRUCT_OFFSET_OF (struct virtio_ctrl_msg, data);
503 d->len = len;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000504 next = (next + 1) & mask;
505 d->next = next;
506 used++;
507
508 d = &vring->desc[next];
509 d->flags = VRING_DESC_F_WRITE;
510 d->addr = vlib_buffer_get_current_pa (vm, b) +
Mohsin Kazmi05493782019-05-01 14:26:17 +0200511 STRUCT_OFFSET_OF (struct virtio_ctrl_msg, status);
512 d->len = sizeof (data->status);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000513 next = (next + 1) & mask;
514 used++;
515
516 CLIB_MEMORY_STORE_BARRIER ();
517 vring->avail->idx = avail;
518 vring->desc_next = next;
519 vring->desc_in_use = used;
520
521 if ((vring->used->flags & VIRTIO_RING_FLAG_MASK_INT) == 0)
522 {
523 virtio_kick (vm, vring, vif);
524 }
525
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000526 u16 last = vring->last_used_idx, n_left = 0;
527 n_left = vring->used->idx - last;
528
529 while (n_left)
530 {
531 struct vring_used_elem *e = &vring->used->ring[last & mask];
532 u16 slot = e->id;
533
534 d = &vring->desc[slot];
535 while (d->flags & VRING_DESC_F_NEXT)
536 {
537 used--;
538 slot = d->next;
539 d = &vring->desc[slot];
540 }
541 used--;
542 last++;
543 n_left--;
544 }
545 vring->desc_in_use = used;
546 vring->last_used_idx = last;
547
548 CLIB_MEMORY_BARRIER ();
549 clib_memcpy (&result, vlib_buffer_get_current (b),
Mohsin Kazmi05493782019-05-01 14:26:17 +0200550 sizeof (struct virtio_ctrl_msg));
Damjan Marionf41244f2019-11-08 17:41:06 +0100551 virtio_log_debug (vif, "ctrl-queue: status %u", result.status);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000552 status = result.status;
553 vlib_buffer_free (vm, &buffer_index, 1);
554 return status;
555}
556
Mohsin Kazmi05493782019-05-01 14:26:17 +0200557static int
Mohsin Kazmibbd6b742019-05-02 13:54:59 +0200558virtio_pci_enable_gso (vlib_main_t * vm, virtio_if_t * vif)
559{
Mohsin Kazmibbd6b742019-05-02 13:54:59 +0200560 struct virtio_ctrl_msg gso_hdr;
561 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
562
563 gso_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
564 gso_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
565 gso_hdr.status = VIRTIO_NET_ERR;
566 u64 offloads = VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM)
567 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4)
568 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6)
569 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO);
570 clib_memcpy (gso_hdr.data, &offloads, sizeof (offloads));
571
572 status = virtio_pci_send_ctrl_msg (vm, vif, &gso_hdr, sizeof (offloads));
Damjan Marionf41244f2019-11-08 17:41:06 +0100573 virtio_log_debug (vif, "enable gso");
Mohsin Kazmibbd6b742019-05-02 13:54:59 +0200574 return status;
575}
576
577static int
Mohsin Kazmi05493782019-05-01 14:26:17 +0200578virtio_pci_enable_multiqueue (vlib_main_t * vm, virtio_if_t * vif,
579 u16 num_queues)
580{
Mohsin Kazmi05493782019-05-01 14:26:17 +0200581 struct virtio_ctrl_msg mq_hdr;
582 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
583
584 mq_hdr.ctrl.class = VIRTIO_NET_CTRL_MQ;
585 mq_hdr.ctrl.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET;
586 mq_hdr.status = VIRTIO_NET_ERR;
587 clib_memcpy (mq_hdr.data, &num_queues, sizeof (num_queues));
588
589 status = virtio_pci_send_ctrl_msg (vm, vif, &mq_hdr, sizeof (num_queues));
Damjan Marionf41244f2019-11-08 17:41:06 +0100590 virtio_log_debug (vif, "multi-queue enable %u queues", num_queues);
Mohsin Kazmi05493782019-05-01 14:26:17 +0200591 return status;
592}
593
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200594static u8
595virtio_pci_queue_size_valid (u16 qsz)
596{
597 if (qsz < 64 || qsz > 4096)
598 return 0;
599 if ((qsz % 64) != 0)
600 return 0;
601 return 1;
602}
603
604clib_error_t *
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000605virtio_pci_control_vring_init (vlib_main_t * vm, virtio_if_t * vif,
606 u16 queue_num)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200607{
608 clib_error_t *error = 0;
609 u16 queue_size = 0;
610 virtio_vring_t *vring;
611 struct vring vr;
612 u32 i = 0;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000613 void *ptr = NULL;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200614
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000615 queue_size = virtio_pci_legacy_get_queue_num (vm, vif, queue_num);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200616 if (!virtio_pci_queue_size_valid (queue_size))
617 clib_warning ("queue size is not valid");
618
619 if (!is_pow2 (queue_size))
620 return clib_error_return (0, "ring size must be power of 2");
621
622 if (queue_size > 32768)
623 return clib_error_return (0, "ring size must be 32768 or lower");
624
625 if (queue_size == 0)
626 queue_size = 256;
627
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000628 vec_validate_aligned (vif->cxq_vring, 0, CLIB_CACHE_LINE_BYTES);
629 vring = vec_elt_at_index (vif->cxq_vring, 0);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200630 i = vring_size (queue_size, VIRTIO_PCI_VRING_ALIGN);
631 i = round_pow2 (i, VIRTIO_PCI_VRING_ALIGN);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000632 ptr =
633 vlib_physmem_alloc_aligned_on_numa (vm, i, VIRTIO_PCI_VRING_ALIGN,
634 vif->numa_node);
635 if (!ptr)
636 return vlib_physmem_last_error (vm);
637 clib_memset (ptr, 0, i);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200638 vring_init (&vr, queue_size, ptr, VIRTIO_PCI_VRING_ALIGN);
639 vring->desc = vr.desc;
640 vring->avail = vr.avail;
641 vring->used = vr.used;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000642 vring->queue_id = queue_num;
643 vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT;
644
645 ASSERT (vring->buffers == 0);
646
647 vring->size = queue_size;
Damjan Marionf41244f2019-11-08 17:41:06 +0100648 virtio_log_debug (vif, "control-queue: number %u, size %u", queue_num,
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000649 queue_size);
650 virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr);
651 vring->kick_fd = -1;
652
653 return error;
654}
655
656clib_error_t *
657virtio_pci_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 queue_num)
658{
659 clib_error_t *error = 0;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000660 vlib_thread_main_t *vtm = vlib_get_thread_main ();
661 u16 queue_size = 0;
662 virtio_vring_t *vring;
663 struct vring vr;
664 u32 i = 0;
665 void *ptr = NULL;
666
667 queue_size = virtio_pci_legacy_get_queue_num (vm, vif, queue_num);
668 if (!virtio_pci_queue_size_valid (queue_size))
669 clib_warning ("queue size is not valid");
670
671 if (!is_pow2 (queue_size))
672 return clib_error_return (0, "ring size must be power of 2");
673
674 if (queue_size > 32768)
675 return clib_error_return (0, "ring size must be 32768 or lower");
676
677 if (queue_size == 0)
678 queue_size = 256;
679
680 if (queue_num % 2)
681 {
682 if (TX_QUEUE_ACCESS (queue_num) > vtm->n_vlib_mains)
683 return error;
684 vec_validate_aligned (vif->txq_vrings, TX_QUEUE_ACCESS (queue_num),
685 CLIB_CACHE_LINE_BYTES);
686 vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (queue_num));
687 clib_spinlock_init (&vring->lockp);
688 }
689 else
690 {
691 vec_validate_aligned (vif->rxq_vrings, RX_QUEUE_ACCESS (queue_num),
692 CLIB_CACHE_LINE_BYTES);
693 vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (queue_num));
694 }
695 i = vring_size (queue_size, VIRTIO_PCI_VRING_ALIGN);
696 i = round_pow2 (i, VIRTIO_PCI_VRING_ALIGN);
697 ptr =
698 vlib_physmem_alloc_aligned_on_numa (vm, i, VIRTIO_PCI_VRING_ALIGN,
699 vif->numa_node);
700 if (!ptr)
701 return vlib_physmem_last_error (vm);
702 clib_memset (ptr, 0, i);
703 vring_init (&vr, queue_size, ptr, VIRTIO_PCI_VRING_ALIGN);
704 vring->desc = vr.desc;
705 vring->avail = vr.avail;
706 vring->used = vr.used;
707 vring->queue_id = queue_num;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200708 vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT;
709
710 ASSERT (vring->buffers == 0);
711 vec_validate_aligned (vring->buffers, queue_size, CLIB_CACHE_LINE_BYTES);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000712 if (queue_num % 2)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200713 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100714 virtio_log_debug (vif, "tx-queue: number %u, size %u", queue_num,
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000715 queue_size);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200716 }
717 else
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000718 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100719 virtio_log_debug (vif, "rx-queue: number %u, size %u", queue_num,
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000720 queue_size);
721 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200722 vring->size = queue_size;
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200723 if (virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr))
724 return clib_error_return (0, "error in queue address setup");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200725
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200726 vring->kick_fd = -1;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200727 return error;
728}
729
730static void
731virtio_negotiate_features (vlib_main_t * vm, virtio_if_t * vif,
732 u64 req_features)
733{
734 /*
735 * if features are not requested
736 * default: all supported features
737 */
Mohsin Kazmibbd6b742019-05-02 13:54:59 +0200738 u64 supported_features = VIRTIO_FEATURE (VIRTIO_NET_F_CSUM)
739 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM)
740 | VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)
741 | VIRTIO_FEATURE (VIRTIO_NET_F_MTU)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200742 | VIRTIO_FEATURE (VIRTIO_NET_F_MAC)
Mohsin Kazmibbd6b742019-05-02 13:54:59 +0200743 | VIRTIO_FEATURE (VIRTIO_NET_F_GSO)
744 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4)
745 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6)
746 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO)
747 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO4)
748 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO6)
749 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_UFO)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200750 | VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF)
751 | VIRTIO_FEATURE (VIRTIO_NET_F_STATUS)
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000752 | VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)
753 | VIRTIO_FEATURE (VIRTIO_NET_F_MQ)
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000754 | VIRTIO_FEATURE (VIRTIO_F_NOTIFY_ON_EMPTY)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200755 | VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)
756 | VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC);
757
758 if (req_features == 0)
759 {
760 req_features = supported_features;
761 }
762
763 vif->features = req_features & vif->remote_features & supported_features;
764
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000765 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MTU))
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200766 {
767 virtio_net_config_t config;
768 virtio_pci_legacy_read_config (vm, vif, &config.mtu,
Mohsin Kazmi46f877e2019-04-08 10:36:18 +0200769 sizeof (config.mtu),
770 STRUCT_OFFSET_OF (virtio_net_config_t,
771 mtu));
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200772 if (config.mtu < 64)
773 vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MTU);
774 }
775
776 vif->features = virtio_pci_legacy_set_features (vm, vif, vif->features);
777}
778
779void
780virtio_pci_read_device_feature (vlib_main_t * vm, virtio_if_t * vif)
781{
782 vif->remote_features = virtio_pci_legacy_get_features (vm, vif);
783}
784
785int
786virtio_pci_reset_device (vlib_main_t * vm, virtio_if_t * vif)
787{
788 u8 status = 0;
789
790 /*
791 * Reset the device
792 */
793 status = virtio_pci_legacy_reset (vm, vif);
794
795 /*
796 * Set the Acknowledge status bit
797 */
798 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_ACK);
799
800 /*
801 * Set the Driver status bit
802 */
803 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_DRIVER);
804
805 /*
806 * Read the status and verify it
807 */
808 status = virtio_pci_legacy_get_status (vm, vif);
809 if (!
810 ((status & VIRTIO_CONFIG_STATUS_ACK)
811 && (status & VIRTIO_CONFIG_STATUS_DRIVER)))
812 return -1;
813 vif->status = status;
814
815 return 0;
816}
817
818clib_error_t *
819virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
820{
821 clib_error_t *error = 0;
822 struct virtio_pci_cap cap;
Mohsin Kazmi22c0ece2019-01-28 19:30:21 +0000823 u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0, pci_cfg = 0;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200824 vlib_pci_dev_handle_t h = vif->pci_dev_handle;
825
826 if ((error = vlib_pci_read_config_u8 (vm, h, PCI_CAPABILITY_LIST, &pos)))
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000827 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100828 virtio_log_error (vif, "error in reading capabilty list position");
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000829 clib_error_return (error, "error in reading capabilty list position");
830 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200831 while (pos)
832 {
833 if ((error =
834 vlib_pci_read_write_config (vm, h, VLIB_READ, pos, &cap,
835 sizeof (cap))))
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000836 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100837 virtio_log_error (vif, "%s [%2x]",
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000838 "error in reading the capability at", pos);
839 clib_error_return (error,
840 "error in reading the capability at [%2x]", pos);
841 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200842
843 if (cap.cap_vndr == PCI_CAP_ID_MSIX)
844 {
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000845 u16 flags, table_size, table_size_mask = 0x07FF;
846
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200847 if ((error =
848 vlib_pci_read_write_config (vm, h, VLIB_READ, pos + 2, &flags,
849 sizeof (flags))))
850 clib_error_return (error,
851 "error in reading the capability at [%2x]",
852 pos + 2);
853
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000854 table_size = flags & table_size_mask;
Damjan Marionf41244f2019-11-08 17:41:06 +0100855 virtio_log_debug (vif, "flags:0x%x %s 0x%x", flags,
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000856 "msix interrupt vector table-size", table_size);
857
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200858 if (flags & PCI_MSIX_ENABLE)
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000859 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100860 virtio_log_debug (vif, "msix interrupt enabled");
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000861 vif->msix_enabled = VIRTIO_MSIX_ENABLED;
862 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200863 else
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000864 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100865 virtio_log_debug (vif, "msix interrupt disabled");
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000866 vif->msix_enabled = VIRTIO_MSIX_DISABLED;
867 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200868 }
869
870 if (cap.cap_vndr != PCI_CAP_ID_VNDR)
871 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100872 virtio_log_debug (vif, "[%2x] %s %2x ", pos,
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000873 "skipping non VNDR cap id:", cap.cap_vndr);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200874 goto next;
875 }
876
Damjan Marionf41244f2019-11-08 17:41:06 +0100877 virtio_log_debug (vif,
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000878 "[%4x] cfg type: %u, bar: %u, offset: %04x, len: %u",
879 pos, cap.cfg_type, cap.bar, cap.offset, cap.length);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200880 switch (cap.cfg_type)
881 {
882 case VIRTIO_PCI_CAP_COMMON_CFG:
883 common_cfg = 1;
884 break;
885 case VIRTIO_PCI_CAP_NOTIFY_CFG:
886 notify_base = 1;
887 break;
888 case VIRTIO_PCI_CAP_DEVICE_CFG:
889 dev_cfg = 1;
890 break;
891 case VIRTIO_PCI_CAP_ISR_CFG:
892 isr = 1;
893 break;
Mohsin Kazmi22c0ece2019-01-28 19:30:21 +0000894 case VIRTIO_PCI_CAP_PCI_CFG:
895 if (cap.bar == 0)
896 pci_cfg = 1;
897 break;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200898 }
899 next:
900 pos = cap.cap_next;
901 }
902
903 if (common_cfg == 0 || notify_base == 0 || dev_cfg == 0 || isr == 0)
904 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100905 virtio_log_debug (vif, "legacy virtio pci device found");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200906 return error;
907 }
908
Mohsin Kazmi0e2bc632019-01-30 13:36:57 +0000909 if (!pci_cfg)
910 clib_error_return (error, "modern virtio pci device found");
911
Damjan Marionf41244f2019-11-08 17:41:06 +0100912 virtio_log_debug (vif, "transitional virtio pci device found");
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +0000913 return error;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200914}
915
916static clib_error_t *
917virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
918 virtio_pci_create_if_args_t * args)
919{
920 clib_error_t *error = 0;
921 u8 status = 0;
922
Mohsin Kazmi22c0ece2019-01-28 19:30:21 +0000923 if ((error = virtio_pci_read_caps (vm, vif)))
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000924 clib_error_return (error, "Device is not supported");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200925
926 if (virtio_pci_reset_device (vm, vif) < 0)
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000927 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100928 virtio_log_error (vif, "Failed to reset the device");
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000929 clib_error_return (error, "Failed to reset the device");
930 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200931 /*
932 * read device features and negotiate (user) requested features
933 */
934 virtio_pci_read_device_feature (vm, vif);
935 virtio_negotiate_features (vm, vif, args->features);
936
937 /*
938 * After FEATURE_OK, driver should not accept new feature bits
939 */
940 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_FEATURES_OK);
941 status = virtio_pci_legacy_get_status (vm, vif);
942 if (!(status & VIRTIO_CONFIG_STATUS_FEATURES_OK))
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000943 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100944 virtio_log_error (vif,
Mohsin Kazmib74fe322019-01-31 13:50:56 +0000945 "error encountered: Device doesn't support requested features");
946 clib_error_return (error, "Device doesn't support requested features");
947 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200948 vif->status = status;
949
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000950 /*
951 * get or set the mac address
952 */
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200953 if (virtio_pci_get_mac (vm, vif))
954 {
955 f64 now = vlib_time_now (vm);
956 u32 rnd;
957 rnd = (u32) (now * 1e6);
958 rnd = random_u32 (&rnd);
959
960 memcpy (vif->mac_addr + 2, &rnd, sizeof (rnd));
961 vif->mac_addr[0] = 2;
962 vif->mac_addr[1] = 0xfe;
963 virtio_pci_set_mac (vm, vif);
964 }
965
966 virtio_set_net_hdr_size (vif);
967
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000968 /*
969 * Initialize the virtqueues
970 */
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200971 if ((error = virtio_pci_get_max_virtqueue_pairs (vm, vif)))
Mohsin Kazmi46f877e2019-04-08 10:36:18 +0200972 goto err;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200973
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000974 for (int i = 0; i < vif->max_queue_pairs; i++)
975 {
976 if ((error = virtio_pci_vring_init (vm, vif, RX_QUEUE (i))))
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200977 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100978 virtio_log_warning (vif, "%s (%u) %s", "error in rxq-queue",
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200979 RX_QUEUE (i), "initialization");
980 }
981 else
982 {
983 vif->num_rxqs++;
984 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200985
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000986 if ((error = virtio_pci_vring_init (vm, vif, TX_QUEUE (i))))
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200987 {
Damjan Marionf41244f2019-11-08 17:41:06 +0100988 virtio_log_warning (vif, "%s (%u) %s", "error in txq-queue",
Mohsin Kazmi43b512c2019-04-30 17:25:26 +0200989 TX_QUEUE (i), "initialization");
990 }
991 else
992 {
993 vif->num_txqs++;
994 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000995 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200996
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000997 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
998 {
999 if ((error =
1000 virtio_pci_control_vring_init (vm, vif, vif->max_queue_pairs * 2)))
1001 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001002 virtio_log_warning (vif, "%s (%u) %s", "error in control-queue",
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001003 vif->max_queue_pairs * 2, "initialization");
1004 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
1005 vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MQ);
1006 }
1007 }
1008 else
1009 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001010 virtio_log_debug (vif, "control queue is not available");
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001011 vif->cxq_vring = NULL;
1012 }
1013
1014 /*
1015 * set the msix interrupts
1016 */
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001017 if (vif->msix_enabled == VIRTIO_MSIX_ENABLED)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001018 {
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001019 if (virtio_pci_legacy_set_config_irq (vm, vif, 1) ==
1020 VIRTIO_MSI_NO_VECTOR)
Damjan Marionf41244f2019-11-08 17:41:06 +01001021 virtio_log_warning (vif, "config vector 1 is not set");
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001022 if (virtio_pci_legacy_set_queue_irq (vm, vif, 0, 0) ==
1023 VIRTIO_MSI_NO_VECTOR)
Damjan Marionf41244f2019-11-08 17:41:06 +01001024 virtio_log_warning (vif, "queue vector 0 is not set");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001025 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001026
1027 /*
1028 * set the driver status OK
1029 */
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001030 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_DRIVER_OK);
1031 vif->status = virtio_pci_legacy_get_status (vm, vif);
Mohsin Kazmi46f877e2019-04-08 10:36:18 +02001032err:
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001033 return error;
1034}
1035
1036void
1037virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
1038{
1039 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001040 virtio_main_t *vim = &virtio_main;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001041 virtio_if_t *vif;
1042 vlib_pci_dev_handle_t h;
1043 clib_error_t *error = 0;
1044
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001045 /* *INDENT-OFF* */
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001046 pool_foreach (vif, vim->interfaces, ({
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001047 if (vif->pci_addr.as_u32 == args->addr)
1048 {
1049 args->rv = VNET_API_ERROR_INVALID_VALUE;
1050 args->error =
1051 clib_error_return (error, "PCI address in use");
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001052 vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
1053 format_vlib_pci_addr, &args->addr,
1054 " PCI address in use");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001055 return;
1056 }
1057 }));
1058 /* *INDENT-ON* */
1059
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001060 pool_get (vim->interfaces, vif);
1061 vif->dev_instance = vif - vim->interfaces;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001062 vif->per_interface_next_index = ~0;
1063 vif->pci_addr.as_u32 = args->addr;
1064
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001065 if ((error =
1066 vlib_pci_device_open (vm, (vlib_pci_addr_t *) & vif->pci_addr,
1067 virtio_pci_device_ids, &h)))
1068 {
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001069 pool_put (vim->interfaces, vif);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001070 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1071 args->error =
1072 clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
1073 &vif->pci_addr);
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001074 vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
1075 format_vlib_pci_addr, &vif->pci_addr,
1076 "error encountered on pci device open");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001077 return;
1078 }
1079 vif->pci_dev_handle = h;
1080 vlib_pci_set_private_data (vm, h, vif->dev_instance);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001081 vif->numa_node = vlib_pci_get_numa_node (vm, h);
Damjan Marionf41244f2019-11-08 17:41:06 +01001082 vif->type = VIRTIO_IF_TYPE_PCI;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001083
1084 if ((error = vlib_pci_bus_master_enable (vm, h)))
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001085 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001086 virtio_log_error (vif, "error encountered on pci bus master enable");
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001087 goto error;
1088 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001089
1090 if ((error = vlib_pci_io_region (vm, h, 0)))
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001091 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001092 virtio_log_error (vif, "error encountered on pci io region");
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001093 goto error;
1094 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001095
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001096 if (vlib_pci_get_num_msix_interrupts (vm, h) > 1)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001097 {
1098 if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
1099 &virtio_pci_irq_0_handler)))
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001100 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001101 virtio_log_error (vif,
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001102 "error encountered on pci register msix handler 0");
1103 goto error;
1104 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001105 if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
1106 &virtio_pci_irq_1_handler)))
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001107 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001108 virtio_log_error (vif,
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001109 "error encountered on pci register msix handler 1");
1110 goto error;
1111 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001112
1113 if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001114 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001115 virtio_log_error (vif, "error encountered on pci enable msix irq");
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001116 goto error;
1117 }
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001118 vif->support_int_mode = 1;
Damjan Marionf41244f2019-11-08 17:41:06 +01001119 virtio_log_debug (vif, "device supports msix interrupts");
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001120 }
1121 else if (vlib_pci_get_num_msix_interrupts (vm, h) == 1)
1122 {
1123 /*
1124 * if msix table-size is 1, fall back to intX.
1125 */
1126 if ((error =
1127 vlib_pci_register_intx_handler (vm, h, &virtio_pci_irq_handler)))
1128 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001129 virtio_log_error (vif,
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001130 "error encountered on pci register interrupt handler");
1131 goto error;
1132 }
1133 vif->support_int_mode = 1;
Damjan Marionf41244f2019-11-08 17:41:06 +01001134 virtio_log_debug (vif, "pci register interrupt handler");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001135 }
1136 else
1137 {
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001138 /*
1139 * WARN: intX is showing some weird behaviour.
1140 * Please don't use interrupt mode with UIO driver.
1141 */
1142 vif->support_int_mode = 0;
Damjan Marionf41244f2019-11-08 17:41:06 +01001143 virtio_log_debug (vif, "driver is configured in poll mode only");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001144 }
1145
1146 if ((error = vlib_pci_intr_enable (vm, h)))
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001147 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001148 virtio_log_error (vif, "error encountered on pci interrupt enable");
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001149 goto error;
1150 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001151
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001152 if ((error = virtio_pci_device_init (vm, vif, args)))
1153 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001154 virtio_log_error (vif, "error encountered on device init");
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001155 goto error;
1156 }
1157
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001158 /* create interface */
1159 error = ethernet_register_interface (vnm, virtio_device_class.index,
1160 vif->dev_instance, vif->mac_addr,
1161 &vif->hw_if_index,
1162 virtio_pci_flag_change);
1163
1164 if (error)
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001165 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001166 virtio_log_error (vif,
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001167 "error encountered on ethernet register interface");
1168 goto error;
1169 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001170
1171 vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
1172 vif->sw_if_index = sw->sw_if_index;
1173 args->sw_if_index = sw->sw_if_index;
1174
1175 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
1176 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
1177 vnet_hw_interface_set_input_node (vnm, vif->hw_if_index,
1178 virtio_input_node.index);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001179 u32 i = 0;
1180 vec_foreach_index (i, vif->rxq_vrings)
1181 {
1182 vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, i, ~0);
1183 virtio_vring_set_numa_node (vm, vif, RX_QUEUE (i));
1184 /* Set default rx mode to POLLING */
1185 vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, i,
1186 VNET_HW_INTERFACE_RX_MODE_POLLING);
1187 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001188 if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
1189 {
1190 vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
1191 vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
1192 VNET_HW_INTERFACE_FLAG_LINK_UP);
1193 }
1194 else
1195 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001196
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02001197 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001198 {
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02001199 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) &&
1200 args->gso_enabled)
1201 {
1202 if (virtio_pci_enable_gso (vm, vif))
1203 {
Damjan Marionf41244f2019-11-08 17:41:06 +01001204 virtio_log_warning (vif, "gso is not enabled");
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02001205 }
1206 else
1207 {
1208 vif->gso_enabled = 1;
1209 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO;
1210 vnm->interface_main.gso_interface_count++;
1211 }
1212 }
1213 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
1214 {
1215 if (virtio_pci_enable_multiqueue (vm, vif, vif->max_queue_pairs))
Damjan Marionf41244f2019-11-08 17:41:06 +01001216 virtio_log_warning (vif, "multiqueue is not set");
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02001217 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001218 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001219 return;
1220
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02001221
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001222error:
1223 virtio_pci_delete_if (vm, vif);
1224 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1225 args->error = error;
1226}
1227
1228int
1229virtio_pci_delete_if (vlib_main_t * vm, virtio_if_t * vif)
1230{
1231 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001232 virtio_main_t *vim = &virtio_main;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001233 u32 i = 0;
1234
1235 if (vif->type != VIRTIO_IF_TYPE_PCI)
1236 return VNET_API_ERROR_INVALID_INTERFACE;
1237
1238 vlib_pci_intr_disable (vm, vif->pci_dev_handle);
1239
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001240 for (i = 0; i < vif->max_queue_pairs; i++)
1241 {
1242 virtio_pci_legacy_del_queue (vm, vif, RX_QUEUE (i));
1243 virtio_pci_legacy_del_queue (vm, vif, TX_QUEUE (i));
1244 }
1245
1246 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
1247 virtio_pci_legacy_del_queue (vm, vif, vif->max_queue_pairs * 2);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001248
1249 virtio_pci_legacy_reset (vm, vif);
1250
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02001251 if (vif->gso_enabled)
1252 vnm->interface_main.gso_interface_count--;
1253
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001254 if (vif->hw_if_index)
1255 {
1256 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001257 vec_foreach_index (i, vif->rxq_vrings)
1258 {
1259 vnet_hw_interface_unassign_rx_thread (vnm, vif->hw_if_index, i);
1260 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001261 ethernet_delete_interface (vnm, vif->hw_if_index);
1262 }
1263
1264 vlib_pci_device_close (vm, vif->pci_dev_handle);
1265
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001266 vec_foreach_index (i, vif->rxq_vrings)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001267 {
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001268 virtio_vring_t *vring = vec_elt_at_index (vif->rxq_vrings, i);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001269 if (vring->kick_fd != -1)
1270 close (vring->kick_fd);
1271 if (vring->used)
1272 {
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001273 virtio_free_rx_buffers (vm, vring);
1274 }
1275 vec_free (vring->buffers);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001276 vlib_physmem_free (vm, vring->desc);
1277 }
1278
1279 vec_foreach_index (i, vif->txq_vrings)
1280 {
1281 virtio_vring_t *vring = vec_elt_at_index (vif->txq_vrings, i);
1282 if (vring->kick_fd != -1)
1283 close (vring->kick_fd);
1284 if (vring->used)
1285 {
1286 virtio_free_used_desc (vm, vring);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001287 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001288 vec_free (vring->buffers);
Steven Luonge5584962019-06-25 13:47:06 -07001289 clib_spinlock_free (&vring->lockp);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001290 vlib_physmem_free (vm, vring->desc);
1291 }
1292
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +00001293 if (vif->cxq_vring != NULL)
1294 {
1295 u16 last = vif->cxq_vring->last_used_idx;
1296 u16 n_left = vif->cxq_vring->used->idx - last;
1297 while (n_left)
1298 {
1299 last++;
1300 n_left--;
1301 }
1302
1303 vif->cxq_vring->last_used_idx = last;
1304 vlib_physmem_free (vm, vif->cxq_vring->desc);
1305 }
1306
1307 vec_free (vif->rxq_vrings);
1308 vec_free (vif->txq_vrings);
1309 vec_free (vif->cxq_vring);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001310
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001311 clib_error_free (vif->error);
1312 memset (vif, 0, sizeof (*vif));
Mohsin Kazmi33cc5cf2019-01-21 15:19:39 +00001313 pool_put (vim->interfaces, vif);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001314
1315 return 0;
1316}
1317
1318/*
1319 * fd.io coding-style-patch-verification: ON
1320 *
1321 * Local Variables:
1322 * eval: (c-set-style "gnu")
1323 * End:
1324 */