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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <sys/ioctl.h>
19 #include <vppinfra/types.h>
20 #include <vlib/vlib.h>
21 #include <vlib/pci/pci.h>
22 #include <vnet/ethernet/ethernet.h>
23 #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>
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
33 #define PCI_CAPABILITY_LIST 0x34
34 #define PCI_CAP_ID_VNDR 0x09
35 #define PCI_CAP_ID_MSIX 0x11
37 #define PCI_MSIX_ENABLE 0x8000
39 #define PCI_CONFIG_SIZE(vif) ((vif->msix_enabled == VIRTIO_MSIX_ENABLED) ? \
42 static pci_device_id_t virtio_pci_device_ids[] = {
44 .vendor_id = PCI_VENDOR_ID_VIRTIO,
45 .device_id = PCI_DEVICE_ID_VIRTIO_NIC},
47 .vendor_id = PCI_VENDOR_ID_VIRTIO,
48 .device_id = PCI_DEVICE_ID_VIRTIO_NIC_MODERN},
53 virtio_pci_legacy_read_config (vlib_main_t * vm, virtio_if_t * vif, void *dst,
57 vlib_pci_dev_handle_t h = vif->pci_dev_handle;
64 vlib_pci_read_io_u32 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst);
69 vlib_pci_read_io_u16 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst);
74 vlib_pci_read_io_u8 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst);
76 dst = (u8 *) dst + size;
83 virtio_pci_legacy_write_config (vlib_main_t * vm, virtio_if_t * vif,
84 void *src, int len, u32 addr)
87 vlib_pci_dev_handle_t h = vif->pci_dev_handle;
94 vlib_pci_write_io_u32 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src);
99 vlib_pci_write_io_u16 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src);
104 vlib_pci_write_io_u8 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src);
106 src = (u8 *) src + size;
113 virtio_pci_legacy_get_host_features (vlib_main_t * vm, virtio_if_t * vif)
116 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_HOST_FEATURES,
122 virtio_pci_legacy_get_guest_features (vlib_main_t * vm, virtio_if_t * vif)
125 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
127 vif->features = feature;
132 virtio_pci_legacy_set_guest_features (vlib_main_t * vm, virtio_if_t * vif,
135 if ((features >> 32) != 0)
137 clib_warning ("only 32 bit features are allowed for legacy virtio!");
139 u32 feature = 0, guest_features = (u32) features;
140 vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
142 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
148 virtio_pci_legacy_get_status (vlib_main_t * vm, virtio_if_t * vif)
151 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &status);
156 virtio_pci_legacy_set_status (vlib_main_t * vm, virtio_if_t * vif, u8 status)
158 if (status != VIRTIO_CONFIG_STATUS_RESET)
159 status |= virtio_pci_legacy_get_status (vm, vif);
160 vlib_pci_write_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &status);
164 virtio_pci_legacy_reset (vlib_main_t * vm, virtio_if_t * vif)
166 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_RESET);
167 return virtio_pci_legacy_get_status (vm, vif);
171 virtio_pci_legacy_get_isr (vlib_main_t * vm, virtio_if_t * vif)
174 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_ISR, &isr);
179 virtio_pci_legacy_get_queue_num (vlib_main_t * vm, virtio_if_t * vif,
183 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
185 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NUM,
191 virtio_pci_legacy_setup_queue (vlib_main_t * vm, virtio_if_t * vif,
192 u16 queue_id, void *p)
194 u64 addr = vlib_physmem_get_pa (vm, p) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT;
196 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
198 vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
200 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
202 if ((u32) addr == addr2)
208 virtio_pci_legacy_del_queue (vlib_main_t * vm, virtio_if_t * vif,
212 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
214 vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN, &src);
218 virtio_pci_legacy_notify_queue (vlib_main_t * vm, virtio_if_t * vif,
221 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NOTIFY,
225 /* Enable one vector (0) for Link State Intrerrupt */
227 virtio_pci_legacy_set_config_irq (vlib_main_t * vm, virtio_if_t * vif,
230 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR,
232 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR,
238 virtio_pci_legacy_set_queue_irq (vlib_main_t * vm, virtio_if_t * vif, u16 vec,
241 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
243 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR,
245 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR,
251 virtio_pci_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw,
257 static clib_error_t *
258 virtio_pci_get_max_virtqueue_pairs (vlib_main_t * vm, virtio_if_t * vif)
260 virtio_net_config_t config;
261 clib_error_t *error = 0;
262 u16 max_queue_pairs = 1;
264 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
266 virtio_pci_legacy_read_config (vm, vif, &config.max_virtqueue_pairs,
267 sizeof (config.max_virtqueue_pairs),
268 STRUCT_OFFSET_OF (virtio_net_config_t,
269 max_virtqueue_pairs));
270 max_queue_pairs = config.max_virtqueue_pairs;
273 virtio_log_debug (vif, "max queue pair is %x", max_queue_pairs);
274 if (max_queue_pairs < 1 || max_queue_pairs > 0x8000)
275 return clib_error_return (error, "max queue pair is %x,"
276 " should be in range [1, 0x8000]",
279 vif->max_queue_pairs = max_queue_pairs;
284 virtio_pci_set_mac (vlib_main_t * vm, virtio_if_t * vif)
286 virtio_pci_legacy_write_config (vm, vif, vif->mac_addr,
287 sizeof (vif->mac_addr), 0);
291 virtio_pci_get_mac (vlib_main_t * vm, virtio_if_t * vif)
293 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MAC))
295 virtio_pci_legacy_read_config (vm, vif, vif->mac_addr,
296 sizeof (vif->mac_addr), 0);
303 virtio_pci_is_link_up (vlib_main_t * vm, virtio_if_t * vif)
306 * Minimal driver: assumes link is up
309 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_STATUS))
310 virtio_pci_legacy_read_config (vm, vif, &status, sizeof (status), /* mac */
311 STRUCT_OFFSET_OF (virtio_net_config_t,
317 virtio_pci_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
319 vnet_main_t *vnm = vnet_get_main ();
320 virtio_main_t *vim = &virtio_main;
321 uword pd = vlib_pci_get_private_data (vm, h);
322 virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
325 vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index, qid);
329 virtio_pci_irq_1_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
331 vnet_main_t *vnm = vnet_get_main ();
332 virtio_main_t *vim = &virtio_main;
333 uword pd = vlib_pci_get_private_data (vm, h);
334 virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
336 if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
338 vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
339 vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
340 VNET_HW_INTERFACE_FLAG_LINK_UP);
344 vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
345 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
350 virtio_pci_irq_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h)
352 virtio_main_t *vim = &virtio_main;
353 uword pd = vlib_pci_get_private_data (vm, h);
354 virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
358 isr = virtio_pci_legacy_get_isr (vm, vif);
361 * If the lower bit is set: look through the used rings of
362 * all virtqueues for the device, to see if any progress has
363 * been made by the device which requires servicing.
365 if (isr & VIRTIO_PCI_ISR_INTR)
366 virtio_pci_irq_0_handler (vm, h, line);
368 if (isr & VIRTIO_PCI_ISR_CONFIG)
369 virtio_pci_irq_1_handler (vm, h, line);
373 device_status (vlib_main_t * vm, virtio_if_t * vif)
380 struct status_struct *status_entry;
381 static struct status_struct status_array[] = {
382 #define _(s,b) { .str = #s, .bit = b, },
383 foreach_virtio_config_status_flags
388 vlib_cli_output (vm, " status 0x%x", vif->status);
390 status_entry = (struct status_struct *) &status_array;
391 while (status_entry->str)
393 if (vif->status & status_entry->bit)
394 vlib_cli_output (vm, " %s (%x)", status_entry->str,
401 debug_device_config_space (vlib_main_t * vm, virtio_if_t * vif)
406 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_HOST_FEATURES,
408 vlib_cli_output (vm, "remote features 0x%lx", data_u32);
409 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES,
411 vlib_cli_output (vm, "guest features 0x%lx", data_u32);
412 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
414 vlib_cli_output (vm, "queue address 0x%lx", data_u32);
415 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NUM,
417 vlib_cli_output (vm, "queue size 0x%x", data_u16);
418 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
420 vlib_cli_output (vm, "queue select 0x%x", data_u16);
421 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NOTIFY,
423 vlib_cli_output (vm, "queue notify 0x%x", data_u16);
424 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &data_u8);
425 vlib_cli_output (vm, "status 0x%x", data_u8);
426 vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_ISR, &data_u8);
427 vlib_cli_output (vm, "isr 0x%x", data_u8);
429 if (vif->msix_enabled == VIRTIO_MSIX_ENABLED)
431 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR,
433 vlib_cli_output (vm, "config vector 0x%x", data_u16);
435 vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
437 vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR,
439 vlib_cli_output (vm, "queue vector for queue (0) 0x%x", data_u16);
443 virtio_pci_legacy_read_config (vm, vif, mac, sizeof (mac), 0);
444 vlib_cli_output (vm, "mac %U", format_ethernet_address, mac);
445 virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), /* offset to status */
447 vlib_cli_output (vm, "link up/down status 0x%x", data_u16);
448 virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16),
449 /* offset to max_virtqueue */ 8);
450 vlib_cli_output (vm, "num of virtqueue 0x%x", data_u16);
451 virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), /* offset to mtu */
453 vlib_cli_output (vm, "mtu 0x%x", data_u16);
455 u32 i = PCI_CONFIG_SIZE (vif) + 12, a = 4;
458 for (; i < 64; i += 4)
461 vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, i, &data);
462 vlib_cli_output (vm, "0x%lx", data);
466 struct virtio_ctrl_msg
468 struct virtio_net_ctrl_hdr ctrl;
469 virtio_net_ctrl_ack status;
474 virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif,
475 struct virtio_ctrl_msg *data, u32 len)
477 virtio_vring_t *vring = vif->cxq_vring;
478 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
479 struct virtio_ctrl_msg result;
482 u16 used, next, avail;
483 u16 sz = vring->size;
486 used = vring->desc_in_use;
487 next = vring->desc_next;
488 avail = vring->avail->idx;
489 struct vring_desc *d = &vring->desc[next];
491 if (vlib_buffer_alloc (vm, &buffer_index, 1))
492 b = vlib_get_buffer (vm, buffer_index);
494 return VIRTIO_NET_ERR;
496 * current_data may not be initialized with 0 and may contain
500 clib_memcpy (vlib_buffer_get_current (b), data,
501 sizeof (struct virtio_ctrl_msg));
502 d->flags = VRING_DESC_F_NEXT;
503 d->addr = vlib_buffer_get_current_pa (vm, b);
504 d->len = sizeof (struct virtio_net_ctrl_hdr);
505 vring->avail->ring[avail & mask] = next;
507 next = (next + 1) & mask;
511 d = &vring->desc[next];
512 d->flags = VRING_DESC_F_NEXT;
513 d->addr = vlib_buffer_get_current_pa (vm, b) +
514 STRUCT_OFFSET_OF (struct virtio_ctrl_msg, data);
516 next = (next + 1) & mask;
520 d = &vring->desc[next];
521 d->flags = VRING_DESC_F_WRITE;
522 d->addr = vlib_buffer_get_current_pa (vm, b) +
523 STRUCT_OFFSET_OF (struct virtio_ctrl_msg, status);
524 d->len = sizeof (data->status);
525 next = (next + 1) & mask;
528 CLIB_MEMORY_STORE_BARRIER ();
529 vring->avail->idx = avail;
530 vring->desc_next = next;
531 vring->desc_in_use = used;
533 if ((vring->used->flags & VIRTIO_RING_FLAG_MASK_INT) == 0)
535 virtio_kick (vm, vring, vif);
538 u16 last = vring->last_used_idx, n_left = 0;
539 n_left = vring->used->idx - last;
543 struct vring_used_elem *e = &vring->used->ring[last & mask];
546 d = &vring->desc[slot];
547 while (d->flags & VRING_DESC_F_NEXT)
551 d = &vring->desc[slot];
557 vring->desc_in_use = used;
558 vring->last_used_idx = last;
560 CLIB_MEMORY_BARRIER ();
561 clib_memcpy (&result, vlib_buffer_get_current (b),
562 sizeof (struct virtio_ctrl_msg));
563 virtio_log_debug (vif, "ctrl-queue: status %u", result.status);
564 status = result.status;
565 vlib_buffer_free (vm, &buffer_index, 1);
570 virtio_pci_disable_offload (vlib_main_t * vm, virtio_if_t * vif)
572 struct virtio_ctrl_msg offload_hdr;
573 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
575 offload_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
576 offload_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
577 offload_hdr.status = VIRTIO_NET_ERR;
579 clib_memcpy (offload_hdr.data, &offloads, sizeof (offloads));
582 virtio_pci_send_ctrl_msg (vm, vif, &offload_hdr, sizeof (offloads));
583 virtio_log_debug (vif, "disable offloads");
584 vif->remote_features = virtio_pci_legacy_get_host_features (vm, vif);
585 virtio_pci_legacy_get_guest_features (vm, vif);
590 virtio_pci_enable_checksum_offload (vlib_main_t * vm, virtio_if_t * vif)
592 struct virtio_ctrl_msg csum_offload_hdr;
593 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
595 csum_offload_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
596 csum_offload_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
597 csum_offload_hdr.status = VIRTIO_NET_ERR;
599 offloads |= VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM);
600 clib_memcpy (csum_offload_hdr.data, &offloads, sizeof (offloads));
603 virtio_pci_send_ctrl_msg (vm, vif, &csum_offload_hdr, sizeof (offloads));
604 virtio_log_debug (vif, "enable checksum offload");
605 vif->remote_features = virtio_pci_legacy_get_host_features (vm, vif);
606 virtio_pci_legacy_get_guest_features (vm, vif);
611 virtio_pci_enable_gso (vlib_main_t * vm, virtio_if_t * vif)
613 struct virtio_ctrl_msg gso_hdr;
614 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
616 gso_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
617 gso_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
618 gso_hdr.status = VIRTIO_NET_ERR;
619 u64 offloads = VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM)
620 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4)
621 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6);
622 clib_memcpy (gso_hdr.data, &offloads, sizeof (offloads));
624 status = virtio_pci_send_ctrl_msg (vm, vif, &gso_hdr, sizeof (offloads));
625 virtio_log_debug (vif, "enable gso");
626 vif->remote_features = virtio_pci_legacy_get_host_features (vm, vif);
627 virtio_pci_legacy_get_guest_features (vm, vif);
632 virtio_pci_offloads (vlib_main_t * vm, virtio_if_t * vif, int gso_enabled,
633 int csum_offload_enabled)
635 vnet_main_t *vnm = vnet_get_main ();
636 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
638 if ((vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) &&
639 (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)))
642 && (vif->features & (VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO4) |
643 VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO6))))
645 if (virtio_pci_enable_gso (vm, vif))
647 virtio_log_warning (vif, "gso is not enabled");
651 vif->gso_enabled = 1;
652 vif->csum_offload_enabled = 0;
653 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO |
654 VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
657 else if (csum_offload_enabled
658 && (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CSUM)))
660 if (virtio_pci_enable_checksum_offload (vm, vif))
662 virtio_log_warning (vif, "checksum offload is not enabled");
666 vif->csum_offload_enabled = 1;
667 vif->gso_enabled = 0;
668 hw->flags &= ~VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO;
670 VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
675 if (virtio_pci_disable_offload (vm, vif))
677 virtio_log_warning (vif, "offloads are not disabled");
681 vif->csum_offload_enabled = 0;
682 vif->gso_enabled = 0;
683 hw->flags &= ~(VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO |
684 VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD);
693 virtio_pci_enable_multiqueue (vlib_main_t * vm, virtio_if_t * vif,
696 struct virtio_ctrl_msg mq_hdr;
697 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
699 mq_hdr.ctrl.class = VIRTIO_NET_CTRL_MQ;
700 mq_hdr.ctrl.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET;
701 mq_hdr.status = VIRTIO_NET_ERR;
702 clib_memcpy (mq_hdr.data, &num_queues, sizeof (num_queues));
704 status = virtio_pci_send_ctrl_msg (vm, vif, &mq_hdr, sizeof (num_queues));
705 virtio_log_debug (vif, "multi-queue enable %u queues", num_queues);
710 virtio_pci_queue_size_valid (u16 qsz)
712 if (qsz < 64 || qsz > 4096)
720 virtio_pci_control_vring_init (vlib_main_t * vm, virtio_if_t * vif,
723 clib_error_t *error = 0;
725 virtio_vring_t *vring;
730 queue_size = virtio_pci_legacy_get_queue_num (vm, vif, queue_num);
731 if (!virtio_pci_queue_size_valid (queue_size))
732 clib_warning ("queue size is not valid");
734 if (!is_pow2 (queue_size))
735 return clib_error_return (0, "ring size must be power of 2");
737 if (queue_size > 32768)
738 return clib_error_return (0, "ring size must be 32768 or lower");
743 vec_validate_aligned (vif->cxq_vring, 0, CLIB_CACHE_LINE_BYTES);
744 vring = vec_elt_at_index (vif->cxq_vring, 0);
745 i = vring_size (queue_size, VIRTIO_PCI_VRING_ALIGN);
746 i = round_pow2 (i, VIRTIO_PCI_VRING_ALIGN);
748 vlib_physmem_alloc_aligned_on_numa (vm, i, VIRTIO_PCI_VRING_ALIGN,
751 return vlib_physmem_last_error (vm);
752 clib_memset (ptr, 0, i);
753 vring_init (&vr, queue_size, ptr, VIRTIO_PCI_VRING_ALIGN);
754 vring->desc = vr.desc;
755 vring->avail = vr.avail;
756 vring->used = vr.used;
757 vring->queue_id = queue_num;
758 vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT;
760 ASSERT (vring->buffers == 0);
762 vring->size = queue_size;
763 virtio_log_debug (vif, "control-queue: number %u, size %u", queue_num,
765 virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr);
772 virtio_pci_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 queue_num)
774 clib_error_t *error = 0;
776 virtio_vring_t *vring;
781 queue_size = virtio_pci_legacy_get_queue_num (vm, vif, queue_num);
782 if (!virtio_pci_queue_size_valid (queue_size))
783 clib_warning ("queue size is not valid");
785 if (!is_pow2 (queue_size))
786 return clib_error_return (0, "ring size must be power of 2");
788 if (queue_size > 32768)
789 return clib_error_return (0, "ring size must be 32768 or lower");
796 vec_validate_aligned (vif->txq_vrings, TX_QUEUE_ACCESS (queue_num),
797 CLIB_CACHE_LINE_BYTES);
798 vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (queue_num));
799 clib_spinlock_init (&vring->lockp);
803 vec_validate_aligned (vif->rxq_vrings, RX_QUEUE_ACCESS (queue_num),
804 CLIB_CACHE_LINE_BYTES);
805 vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (queue_num));
807 i = vring_size (queue_size, VIRTIO_PCI_VRING_ALIGN);
808 i = round_pow2 (i, VIRTIO_PCI_VRING_ALIGN);
810 vlib_physmem_alloc_aligned_on_numa (vm, i, VIRTIO_PCI_VRING_ALIGN,
813 return vlib_physmem_last_error (vm);
814 clib_memset (ptr, 0, i);
815 vring_init (&vr, queue_size, ptr, VIRTIO_PCI_VRING_ALIGN);
816 vring->desc = vr.desc;
817 vring->avail = vr.avail;
818 vring->used = vr.used;
819 vring->queue_id = queue_num;
820 vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT;
822 ASSERT (vring->buffers == 0);
823 vec_validate_aligned (vring->buffers, queue_size, CLIB_CACHE_LINE_BYTES);
826 virtio_log_debug (vif, "tx-queue: number %u, size %u", queue_num,
828 clib_memset_u32 (vring->buffers, ~0, queue_size);
832 virtio_log_debug (vif, "rx-queue: number %u, size %u", queue_num,
835 vring->size = queue_size;
836 if (virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr))
837 return clib_error_return (0, "error in queue address setup");
844 virtio_negotiate_features (vlib_main_t * vm, virtio_if_t * vif,
848 * if features are not requested
849 * default: all supported features
851 u64 supported_features = VIRTIO_FEATURE (VIRTIO_NET_F_CSUM)
852 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM)
853 | VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)
854 | VIRTIO_FEATURE (VIRTIO_NET_F_MTU)
855 | VIRTIO_FEATURE (VIRTIO_NET_F_MAC)
856 | VIRTIO_FEATURE (VIRTIO_NET_F_GSO)
857 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4)
858 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6)
859 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO)
860 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO4)
861 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO6)
862 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_UFO)
863 | VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF)
864 | VIRTIO_FEATURE (VIRTIO_NET_F_STATUS)
865 | VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)
866 | VIRTIO_FEATURE (VIRTIO_NET_F_MQ)
867 | VIRTIO_FEATURE (VIRTIO_F_NOTIFY_ON_EMPTY)
868 | VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)
869 | VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC);
871 if (req_features == 0)
873 req_features = supported_features;
876 vif->features = req_features & vif->remote_features & supported_features;
878 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MTU))
880 virtio_net_config_t config;
881 virtio_pci_legacy_read_config (vm, vif, &config.mtu,
883 STRUCT_OFFSET_OF (virtio_net_config_t,
886 vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MTU);
890 virtio_pci_legacy_set_guest_features (vm, vif, vif->features);
894 virtio_pci_read_device_feature (vlib_main_t * vm, virtio_if_t * vif)
896 vif->remote_features = virtio_pci_legacy_get_host_features (vm, vif);
900 virtio_pci_reset_device (vlib_main_t * vm, virtio_if_t * vif)
907 status = virtio_pci_legacy_reset (vm, vif);
910 * Set the Acknowledge status bit
912 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_ACK);
915 * Set the Driver status bit
917 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_DRIVER);
920 * Read the status and verify it
922 status = virtio_pci_legacy_get_status (vm, vif);
924 ((status & VIRTIO_CONFIG_STATUS_ACK)
925 && (status & VIRTIO_CONFIG_STATUS_DRIVER)))
927 vif->status = status;
933 virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
935 clib_error_t *error = 0;
936 struct virtio_pci_cap cap;
937 u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0, pci_cfg = 0;
938 vlib_pci_dev_handle_t h = vif->pci_dev_handle;
940 if ((error = vlib_pci_read_config_u8 (vm, h, PCI_CAPABILITY_LIST, &pos)))
942 virtio_log_error (vif, "error in reading capabilty list position");
943 clib_error_return (error, "error in reading capabilty list position");
948 vlib_pci_read_write_config (vm, h, VLIB_READ, pos, &cap,
951 virtio_log_error (vif, "%s [%2x]",
952 "error in reading the capability at", pos);
953 clib_error_return (error,
954 "error in reading the capability at [%2x]", pos);
957 if (cap.cap_vndr == PCI_CAP_ID_MSIX)
959 u16 flags, table_size, table_size_mask = 0x07FF;
962 vlib_pci_read_write_config (vm, h, VLIB_READ, pos + 2, &flags,
964 clib_error_return (error,
965 "error in reading the capability at [%2x]",
968 table_size = flags & table_size_mask;
969 virtio_log_debug (vif, "flags:0x%x %s 0x%x", flags,
970 "msix interrupt vector table-size", table_size);
972 if (flags & PCI_MSIX_ENABLE)
974 virtio_log_debug (vif, "msix interrupt enabled");
975 vif->msix_enabled = VIRTIO_MSIX_ENABLED;
979 virtio_log_debug (vif, "msix interrupt disabled");
980 vif->msix_enabled = VIRTIO_MSIX_DISABLED;
984 if (cap.cap_vndr != PCI_CAP_ID_VNDR)
986 virtio_log_debug (vif, "[%2x] %s %2x ", pos,
987 "skipping non VNDR cap id:", cap.cap_vndr);
991 virtio_log_debug (vif,
992 "[%4x] cfg type: %u, bar: %u, offset: %04x, len: %u",
993 pos, cap.cfg_type, cap.bar, cap.offset, cap.length);
994 switch (cap.cfg_type)
996 case VIRTIO_PCI_CAP_COMMON_CFG:
999 case VIRTIO_PCI_CAP_NOTIFY_CFG:
1002 case VIRTIO_PCI_CAP_DEVICE_CFG:
1005 case VIRTIO_PCI_CAP_ISR_CFG:
1008 case VIRTIO_PCI_CAP_PCI_CFG:
1017 if (common_cfg == 0 || notify_base == 0 || dev_cfg == 0 || isr == 0)
1019 virtio_log_debug (vif, "legacy virtio pci device found");
1024 clib_error_return (error, "modern virtio pci device found");
1026 virtio_log_debug (vif, "transitional virtio pci device found");
1030 static clib_error_t *
1031 virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
1032 virtio_pci_create_if_args_t * args)
1034 clib_error_t *error = 0;
1035 vlib_thread_main_t *vtm = vlib_get_thread_main ();
1038 if ((error = virtio_pci_read_caps (vm, vif)))
1040 args->rv = VNET_API_ERROR_UNSUPPORTED;
1041 virtio_log_error (vif, "Device is not supported");
1042 clib_error_return (error, "Device is not supported");
1045 if (virtio_pci_reset_device (vm, vif) < 0)
1047 args->rv = VNET_API_ERROR_INIT_FAILED;
1048 virtio_log_error (vif, "Failed to reset the device");
1049 clib_error_return (error, "Failed to reset the device");
1052 * read device features and negotiate (user) requested features
1054 virtio_pci_read_device_feature (vm, vif);
1055 virtio_negotiate_features (vm, vif, args->features);
1058 * After FEATURE_OK, driver should not accept new feature bits
1060 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_FEATURES_OK);
1061 status = virtio_pci_legacy_get_status (vm, vif);
1062 if (!(status & VIRTIO_CONFIG_STATUS_FEATURES_OK))
1064 args->rv = VNET_API_ERROR_UNSUPPORTED;
1065 virtio_log_error (vif,
1066 "error encountered: Device doesn't support requested features");
1067 clib_error_return (error, "Device doesn't support requested features");
1069 vif->status = status;
1072 * get or set the mac address
1074 if (virtio_pci_get_mac (vm, vif))
1076 f64 now = vlib_time_now (vm);
1078 rnd = (u32) (now * 1e6);
1079 rnd = random_u32 (&rnd);
1081 memcpy (vif->mac_addr + 2, &rnd, sizeof (rnd));
1082 vif->mac_addr[0] = 2;
1083 vif->mac_addr[1] = 0xfe;
1084 virtio_pci_set_mac (vm, vif);
1087 virtio_set_net_hdr_size (vif);
1090 * Initialize the virtqueues
1092 if ((error = virtio_pci_get_max_virtqueue_pairs (vm, vif)))
1094 args->rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1098 for (int i = 0; i < vif->max_queue_pairs; i++)
1100 if ((error = virtio_pci_vring_init (vm, vif, RX_QUEUE (i))))
1102 args->rv = VNET_API_ERROR_INIT_FAILED;
1103 virtio_log_error (vif, "%s (%u) %s", "error in rxq-queue",
1104 RX_QUEUE (i), "initialization");
1105 clib_error_return (error, "%s (%u) %s", "error in rxq-queue",
1106 RX_QUEUE (i), "initialization");
1113 if (i >= vtm->n_vlib_mains)
1116 * There is 1:1 mapping between tx queue and vpp worker thread.
1117 * tx queue 0 is bind with thread index 0, tx queue 1 on thread
1118 * index 1 and so on.
1119 * Multiple worker threads can poll same tx queue when number of
1120 * workers are more than tx queues. In this case, 1:N mapping
1121 * between tx queue and vpp worker thread.
1123 virtio_log_debug (vif, "%s %u, %s", "tx-queue: number",
1125 "no VPP worker thread is available");
1129 if ((error = virtio_pci_vring_init (vm, vif, TX_QUEUE (i))))
1131 args->rv = VNET_API_ERROR_INIT_FAILED;
1132 virtio_log_error (vif, "%s (%u) %s", "error in txq-queue",
1133 TX_QUEUE (i), "initialization");
1134 clib_error_return (error, "%s (%u) %s", "error in txq-queue",
1135 TX_QUEUE (i), "initialization");
1143 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
1146 virtio_pci_control_vring_init (vm, vif, vif->max_queue_pairs * 2)))
1148 virtio_log_warning (vif, "%s (%u) %s", "error in control-queue",
1149 vif->max_queue_pairs * 2, "initialization");
1150 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
1151 vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MQ);
1156 virtio_log_debug (vif, "control queue is not available");
1157 vif->cxq_vring = NULL;
1161 * set the msix interrupts
1163 if (vif->msix_enabled == VIRTIO_MSIX_ENABLED)
1165 if (virtio_pci_legacy_set_config_irq (vm, vif, 1) ==
1166 VIRTIO_MSI_NO_VECTOR)
1167 virtio_log_warning (vif, "config vector 1 is not set");
1168 if (virtio_pci_legacy_set_queue_irq (vm, vif, 0, 0) ==
1169 VIRTIO_MSI_NO_VECTOR)
1170 virtio_log_warning (vif, "queue vector 0 is not set");
1174 * set the driver status OK
1176 virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_DRIVER_OK);
1177 vif->status = virtio_pci_legacy_get_status (vm, vif);
1183 virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
1185 vnet_main_t *vnm = vnet_get_main ();
1186 virtio_main_t *vim = &virtio_main;
1188 vlib_pci_dev_handle_t h;
1189 clib_error_t *error = 0;
1192 pool_foreach (vif, vim->interfaces, ({
1193 if (vif->pci_addr.as_u32 == args->addr)
1195 args->rv = VNET_API_ERROR_ADDRESS_IN_USE;
1197 clib_error_return (error, "PCI address in use");
1198 vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
1199 format_vlib_pci_addr, &args->addr,
1200 " PCI address in use");
1206 pool_get (vim->interfaces, vif);
1207 vif->dev_instance = vif - vim->interfaces;
1208 vif->per_interface_next_index = ~0;
1209 vif->pci_addr.as_u32 = args->addr;
1212 vlib_pci_device_open (vm, (vlib_pci_addr_t *) & vif->pci_addr,
1213 virtio_pci_device_ids, &h)))
1215 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1217 clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
1219 vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
1220 format_vlib_pci_addr, &vif->pci_addr,
1221 "error encountered on pci device open");
1222 pool_put (vim->interfaces, vif);
1225 vif->pci_dev_handle = h;
1226 vlib_pci_set_private_data (vm, h, vif->dev_instance);
1227 vif->numa_node = vlib_pci_get_numa_node (vm, h);
1228 vif->type = VIRTIO_IF_TYPE_PCI;
1230 if ((error = vlib_pci_bus_master_enable (vm, h)))
1232 virtio_log_error (vif, "error encountered on pci bus master enable");
1236 if ((error = vlib_pci_io_region (vm, h, 0)))
1238 virtio_log_error (vif, "error encountered on pci io region");
1242 if (vlib_pci_get_num_msix_interrupts (vm, h) > 1)
1244 if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
1245 &virtio_pci_irq_0_handler)))
1247 args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
1248 virtio_log_error (vif,
1249 "error encountered on pci register msix handler 0");
1252 if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
1253 &virtio_pci_irq_1_handler)))
1255 args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
1256 virtio_log_error (vif,
1257 "error encountered on pci register msix handler 1");
1261 if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
1263 virtio_log_error (vif, "error encountered on pci enable msix irq");
1266 vif->support_int_mode = 1;
1267 virtio_log_debug (vif, "device supports msix interrupts");
1269 else if (vlib_pci_get_num_msix_interrupts (vm, h) == 1)
1272 * if msix table-size is 1, fall back to intX.
1275 vlib_pci_register_intx_handler (vm, h, &virtio_pci_irq_handler)))
1277 virtio_log_error (vif,
1278 "error encountered on pci register interrupt handler");
1281 vif->support_int_mode = 1;
1282 virtio_log_debug (vif, "pci register interrupt handler");
1287 * WARN: intX is showing some weird behaviour.
1288 * Please don't use interrupt mode with UIO driver.
1290 vif->support_int_mode = 0;
1291 virtio_log_debug (vif, "driver is configured in poll mode only");
1294 if ((error = vlib_pci_intr_enable (vm, h)))
1296 virtio_log_error (vif, "error encountered on pci interrupt enable");
1300 if ((error = virtio_pci_device_init (vm, vif, args)))
1302 virtio_log_error (vif, "error encountered on device init");
1306 /* create interface */
1307 error = ethernet_register_interface (vnm, virtio_device_class.index,
1308 vif->dev_instance, vif->mac_addr,
1310 virtio_pci_flag_change);
1314 args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
1315 virtio_log_error (vif,
1316 "error encountered on ethernet register interface");
1320 vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
1321 vif->sw_if_index = sw->sw_if_index;
1322 args->sw_if_index = sw->sw_if_index;
1324 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
1325 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
1326 vnet_hw_interface_set_input_node (vnm, vif->hw_if_index,
1327 virtio_input_node.index);
1329 vec_foreach_index (i, vif->rxq_vrings)
1331 vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, i, ~0);
1332 virtio_vring_set_numa_node (vm, vif, RX_QUEUE (i));
1333 /* Set default rx mode to POLLING */
1334 vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, i,
1335 VNET_HW_INTERFACE_RX_MODE_POLLING);
1337 if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
1339 vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
1340 vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
1341 VNET_HW_INTERFACE_FLAG_LINK_UP);
1344 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
1346 virtio_pci_offloads (vm, vif, args->gso_enabled,
1347 args->checksum_offload_enabled);
1349 if ((vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) &&
1350 (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ)))
1352 if (virtio_pci_enable_multiqueue (vm, vif, vif->max_queue_pairs))
1353 virtio_log_warning (vif, "multiqueue is not set");
1358 virtio_pci_delete_if (vm, vif);
1360 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1361 args->error = error;
1365 virtio_pci_delete_if (vlib_main_t * vm, virtio_if_t * vif)
1367 vnet_main_t *vnm = vnet_get_main ();
1368 virtio_main_t *vim = &virtio_main;
1371 if (vif->type != VIRTIO_IF_TYPE_PCI)
1372 return VNET_API_ERROR_INVALID_INTERFACE;
1374 vlib_pci_intr_disable (vm, vif->pci_dev_handle);
1376 for (i = 0; i < vif->max_queue_pairs; i++)
1378 virtio_pci_legacy_del_queue (vm, vif, RX_QUEUE (i));
1379 virtio_pci_legacy_del_queue (vm, vif, TX_QUEUE (i));
1382 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
1383 virtio_pci_legacy_del_queue (vm, vif, vif->max_queue_pairs * 2);
1385 virtio_pci_legacy_reset (vm, vif);
1387 if (vif->hw_if_index)
1389 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
1390 vec_foreach_index (i, vif->rxq_vrings)
1392 vnet_hw_interface_unassign_rx_thread (vnm, vif->hw_if_index, i);
1394 ethernet_delete_interface (vnm, vif->hw_if_index);
1397 vlib_pci_device_close (vm, vif->pci_dev_handle);
1399 vec_foreach_index (i, vif->rxq_vrings)
1401 virtio_vring_t *vring = vec_elt_at_index (vif->rxq_vrings, i);
1402 if (vring->kick_fd != -1)
1403 close (vring->kick_fd);
1406 virtio_free_rx_buffers (vm, vring);
1408 vec_free (vring->buffers);
1409 vlib_physmem_free (vm, vring->desc);
1412 vec_foreach_index (i, vif->txq_vrings)
1414 virtio_vring_t *vring = vec_elt_at_index (vif->txq_vrings, i);
1415 if (vring->kick_fd != -1)
1416 close (vring->kick_fd);
1419 virtio_free_used_desc (vm, vring);
1421 vec_free (vring->buffers);
1422 clib_spinlock_free (&vring->lockp);
1423 vlib_physmem_free (vm, vring->desc);
1426 if (vif->cxq_vring != NULL)
1428 u16 last = vif->cxq_vring->last_used_idx;
1429 u16 n_left = vif->cxq_vring->used->idx - last;
1436 vif->cxq_vring->last_used_idx = last;
1437 vlib_physmem_free (vm, vif->cxq_vring->desc);
1440 vec_free (vif->rxq_vrings);
1441 vec_free (vif->txq_vrings);
1442 vec_free (vif->cxq_vring);
1444 clib_error_free (vif->error);
1445 memset (vif, 0, sizeof (*vif));
1446 pool_put (vim->interfaces, vif);
1452 virtio_pci_enable_disable_offloads (vlib_main_t * vm, virtio_if_t * vif,
1454 int checksum_offload_enabled,
1455 int offloads_disabled)
1457 if (vif->type != VIRTIO_IF_TYPE_PCI)
1458 return VNET_API_ERROR_INVALID_INTERFACE;
1461 virtio_pci_offloads (vm, vif, 1, 0);
1462 else if (checksum_offload_enabled)
1463 virtio_pci_offloads (vm, vif, 0, 1);
1464 else if (offloads_disabled)
1465 virtio_pci_offloads (vm, vif, 0, 0);
1471 * fd.io coding-style-patch-verification: ON
1474 * eval: (c-set-style "gnu")