}
}
-struct virtio_ctrl_msg
-{
- struct virtio_net_ctrl_hdr ctrl;
- virtio_net_ctrl_ack status;
- u8 data[1024];
-};
-
static int
virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif,
- struct virtio_ctrl_msg *data, u32 len)
+ virtio_ctrl_msg_t * data, u32 len)
{
virtio_vring_t *vring = vif->cxq_vring;
- virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
- struct virtio_ctrl_msg result;
+ virtio_net_ctrl_ack_t status = VIRTIO_NET_ERR;
+ virtio_ctrl_msg_t result;
u32 buffer_index;
vlib_buffer_t *b;
u16 used, next, avail;
used = vring->desc_in_use;
next = vring->desc_next;
avail = vring->avail->idx;
- struct vring_desc *d = &vring->desc[next];
+ vring_desc_t *d = &vring->desc[next];
if (vlib_buffer_alloc (vm, &buffer_index, 1))
b = vlib_get_buffer (vm, buffer_index);
* previous offset.
*/
b->current_data = 0;
- clib_memcpy (vlib_buffer_get_current (b), data,
- sizeof (struct virtio_ctrl_msg));
+ clib_memcpy (vlib_buffer_get_current (b), data, sizeof (virtio_ctrl_msg_t));
d->flags = VRING_DESC_F_NEXT;
d->addr = vlib_buffer_get_current_pa (vm, b);
- d->len = sizeof (struct virtio_net_ctrl_hdr);
+ d->len = sizeof (virtio_net_ctrl_hdr_t);
vring->avail->ring[avail & mask] = next;
avail++;
next = (next + 1) & mask;
d = &vring->desc[next];
d->flags = VRING_DESC_F_NEXT;
d->addr = vlib_buffer_get_current_pa (vm, b) +
- STRUCT_OFFSET_OF (struct virtio_ctrl_msg, data);
+ STRUCT_OFFSET_OF (virtio_ctrl_msg_t, data);
d->len = len;
next = (next + 1) & mask;
d->next = next;
d = &vring->desc[next];
d->flags = VRING_DESC_F_WRITE;
d->addr = vlib_buffer_get_current_pa (vm, b) +
- STRUCT_OFFSET_OF (struct virtio_ctrl_msg, status);
+ STRUCT_OFFSET_OF (virtio_ctrl_msg_t, status);
d->len = sizeof (data->status);
next = (next + 1) & mask;
used++;
while (n_left)
{
- struct vring_used_elem *e = &vring->used->ring[last & mask];
+ vring_used_elem_t *e = &vring->used->ring[last & mask];
u16 slot = e->id;
d = &vring->desc[slot];
CLIB_MEMORY_BARRIER ();
clib_memcpy (&result, vlib_buffer_get_current (b),
- sizeof (struct virtio_ctrl_msg));
+ sizeof (virtio_ctrl_msg_t));
virtio_log_debug (vif, "ctrl-queue: status %u", result.status);
status = result.status;
vlib_buffer_free (vm, &buffer_index, 1);
static int
virtio_pci_disable_offload (vlib_main_t * vm, virtio_if_t * vif)
{
- struct virtio_ctrl_msg offload_hdr;
- virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+ virtio_ctrl_msg_t offload_hdr;
+ virtio_net_ctrl_ack_t status = VIRTIO_NET_ERR;
offload_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
offload_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
static int
virtio_pci_enable_checksum_offload (vlib_main_t * vm, virtio_if_t * vif)
{
- struct virtio_ctrl_msg csum_offload_hdr;
- virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+ virtio_ctrl_msg_t csum_offload_hdr;
+ virtio_net_ctrl_ack_t status = VIRTIO_NET_ERR;
csum_offload_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
csum_offload_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
static int
virtio_pci_enable_gso (vlib_main_t * vm, virtio_if_t * vif)
{
- struct virtio_ctrl_msg gso_hdr;
- virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+ virtio_ctrl_msg_t gso_hdr;
+ virtio_net_ctrl_ack_t status = VIRTIO_NET_ERR;
gso_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS;
gso_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET;
virtio_pci_enable_multiqueue (vlib_main_t * vm, virtio_if_t * vif,
u16 num_queues)
{
- struct virtio_ctrl_msg mq_hdr;
- virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+ virtio_ctrl_msg_t mq_hdr;
+ virtio_net_ctrl_ack_t status = VIRTIO_NET_ERR;
mq_hdr.ctrl.class = VIRTIO_NET_CTRL_MQ;
mq_hdr.ctrl.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET;
clib_error_t *error = 0;
u16 queue_size = 0;
virtio_vring_t *vring;
- struct vring vr;
+ vring_t vr;
u32 i = 0;
void *ptr = NULL;
clib_error_t *error = 0;
u16 queue_size = 0;
virtio_vring_t *vring;
- struct vring vr;
+ vring_t vr;
u32 i = 0;
void *ptr = NULL;
| VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)
| VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC);
+ if (vif->is_modern)
+ supported_features |= VIRTIO_FEATURE (VIRTIO_F_VERSION_1);
+
if (req_features == 0)
{
req_features = supported_features;
* Read the status and verify it
*/
status = vif->virtio_pci_func->get_status (vm, vif);
- if (!
- ((status & VIRTIO_CONFIG_STATUS_ACK)
- && (status & VIRTIO_CONFIG_STATUS_DRIVER)))
+ if ((status & VIRTIO_CONFIG_STATUS_ACK)
+ && (status & VIRTIO_CONFIG_STATUS_DRIVER))
+ vif->status = status;
+ else
return -1;
- vif->status = status;
return 0;
}
clib_error_t *
-virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
+virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif, void **bar)
{
clib_error_t *error = 0;
- struct virtio_pci_cap cap;
- u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0, pci_cfg = 0;
+ virtio_pci_cap_t cap;
+ u8 pos, common_cfg = 0, notify = 0, dev_cfg = 0, isr = 0, pci_cfg = 0;
vlib_pci_dev_handle_t h = vif->pci_dev_handle;
if ((error = vlib_pci_read_config_u8 (vm, h, PCI_CAPABILITY_LIST, &pos)))
{
virtio_log_error (vif, "error in reading capabilty list position");
- clib_error_return (error, "error in reading capabilty list position");
+ return clib_error_return (error,
+ "error in reading capabilty list position");
}
while (pos)
{
{
virtio_log_error (vif, "%s [%2x]",
"error in reading the capability at", pos);
- clib_error_return (error,
- "error in reading the capability at [%2x]", pos);
+ return clib_error_return (error,
+ "error in reading the capability at [%2x]",
+ pos);
}
if (cap.cap_vndr == PCI_CAP_ID_MSIX)
if ((error =
vlib_pci_read_write_config (vm, h, VLIB_READ, pos + 2, &flags,
sizeof (flags))))
- clib_error_return (error,
- "error in reading the capability at [%2x]",
- pos + 2);
+ return clib_error_return (error,
+ "error in reading the capability at [%2x]",
+ pos + 2);
table_size = flags & table_size_mask;
virtio_log_debug (vif, "flags:0x%x %s 0x%x", flags,
virtio_log_debug (vif,
"[%4x] cfg type: %u, bar: %u, offset: %04x, len: %u",
pos, cap.cfg_type, cap.bar, cap.offset, cap.length);
+
+ if (cap.bar >= 0 && cap.bar <= 5)
+ {
+ vif->bar = bar[cap.bar];
+ vif->bar_id = cap.bar;
+ }
+ else
+ return clib_error_return (error, "invalid bar %u", cap.bar);
+
switch (cap.cfg_type)
{
case VIRTIO_PCI_CAP_COMMON_CFG:
+ vif->common_offset = cap.offset;
common_cfg = 1;
break;
case VIRTIO_PCI_CAP_NOTIFY_CFG:
- notify_base = 1;
+ if ((error =
+ vlib_pci_read_write_config (vm, h, VLIB_READ,
+ pos + sizeof (cap),
+ &vif->notify_off_multiplier,
+ sizeof
+ (vif->notify_off_multiplier))))
+ {
+ virtio_log_error (vif, "notify off multiplier is not given");
+ }
+ else
+ {
+ virtio_log_debug (vif, "notify off multiplier is %u",
+ vif->notify_off_multiplier);
+ vif->notify_offset = cap.offset;
+ notify = 1;
+ }
break;
case VIRTIO_PCI_CAP_DEVICE_CFG:
+ vif->device_offset = cap.offset;
dev_cfg = 1;
break;
case VIRTIO_PCI_CAP_ISR_CFG:
+ vif->isr_offset = cap.offset;
isr = 1;
break;
case VIRTIO_PCI_CAP_PCI_CFG:
pos = cap.cap_next;
}
- vif->virtio_pci_func = &virtio_pci_legacy_func;
-
- if (common_cfg == 0 || notify_base == 0 || dev_cfg == 0 || isr == 0)
+ if (common_cfg == 0 || notify == 0 || dev_cfg == 0 || isr == 0)
{
+ vif->virtio_pci_func = &virtio_pci_legacy_func;
virtio_log_debug (vif, "legacy virtio pci device found");
return error;
}
+ vif->is_modern = 1;
+ vif->virtio_pci_func = &virtio_pci_modern_func;
+
if (!pci_cfg)
- clib_error_return (error, "modern virtio pci device found");
+ virtio_log_debug (vif, "modern virtio pci device found");
virtio_log_debug (vif, "transitional virtio pci device found");
return error;
static clib_error_t *
virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
- virtio_pci_create_if_args_t * args)
+ virtio_pci_create_if_args_t * args, void **bar)
{
clib_error_t *error = 0;
vlib_thread_main_t *vtm = vlib_get_thread_main ();
u8 status = 0;
- if ((error = virtio_pci_read_caps (vm, vif)))
+ if ((error = virtio_pci_read_caps (vm, vif, bar)))
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
virtio_log_error (vif, "Device is not supported");
- clib_error_return (error, "Device is not supported");
+ return clib_error_return (error, "Device is not supported");
}
if (virtio_pci_reset_device (vm, vif) < 0)
{
args->rv = VNET_API_ERROR_INIT_FAILED;
virtio_log_error (vif, "Failed to reset the device");
- clib_error_return (error, "Failed to reset the device");
+ return clib_error_return (error, "Failed to reset the device");
}
/*
* read device features and negotiate (user) requested features
args->rv = VNET_API_ERROR_UNSUPPORTED;
virtio_log_error (vif,
"error encountered: Device doesn't support requested features");
- clib_error_return (error, "Device doesn't support requested features");
+ return clib_error_return (error,
+ "Device doesn't support requested features");
}
vif->status = status;
goto error;
}
+ void *bar[6];
+ for (u32 i = 0; i <= 5; i++)
+ {
+
+ if ((error = vlib_pci_map_region (vm, h, i, &bar[i])))
+ {
+ virtio_log_debug (vif, "no pci map region for bar %u", i);
+ }
+ else
+ {
+ virtio_log_debug (vif, "pci map region for bar %u at %p", i,
+ bar[i]);
+ }
+ }
+
if ((error = vlib_pci_io_region (vm, h, 0)))
{
virtio_log_error (vif, "error encountered on pci io region");
goto error;
}
- if ((error = virtio_pci_device_init (vm, vif, args)))
+ if ((error = virtio_pci_device_init (vm, vif, args, bar)))
{
virtio_log_error (vif, "error encountered on device init");
goto error;
if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
vif->virtio_pci_func->del_queue (vm, vif, vif->max_queue_pairs * 2);
- vif->virtio_pci_func->device_reset (vm, vif);
+ if (vif->virtio_pci_func)
+ vif->virtio_pci_func->device_reset (vm, vif);
if (vif->hw_if_index)
{