virtio: add option to bind interface to uio driver

Type: improvement

Change-Id: I30e66370c927afeb62ba3a2b3334bdc2a31d4561
Signed-off-by: Benoît Ganne <bganne@cisco.com>
This commit is contained in:
Benoît Ganne
2022-10-13 14:01:03 +02:00
committed by Dave Wallace
parent 6a07348f4a
commit c04d8c41d1
3 changed files with 32 additions and 2 deletions

View File

@ -55,6 +55,10 @@ virtio_pci_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
}
else if (unformat (line_input, "packed"))
args.virtio_flags |= VIRTIO_FLAG_PACKED;
else if (unformat (line_input, "bind force"))
args.bind = VIRTIO_BIND_FORCE;
else if (unformat (line_input, "bind"))
args.bind = VIRTIO_BIND_DEFAULT;
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
@ -70,8 +74,8 @@ virtio_pci_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
VLIB_CLI_COMMAND (virtio_pci_create_command, static) = {
.path = "create interface virtio",
.short_help = "create interface virtio <pci-address> "
"[feature-mask <hex-mask>] [gso-enabled] [csum-enabled] "
"[buffering [size <buffering-szie>]] [packed]",
"[feature-mask <hex-mask>] [gso-enabled] [csum-enabled] "
"[buffering [size <buffering-szie>]] [packed] [bind [force]]",
.function = virtio_pci_create_command_fn,
};
/* *INDENT-ON* */

View File

@ -1343,6 +1343,24 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
}
/* *INDENT-ON* */
if (args->bind)
{
vlib_pci_addr_t pci = { .as_u32 = args->addr };
error = vlib_pci_bind_to_uio (vm, &pci, (char *) "auto",
VIRTIO_BIND_FORCE == args->bind);
if (error)
{
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
args->error =
clib_error_return (error, "%U: %s", format_vlib_pci_addr, &pci,
"error encountered on binding pci device");
vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
format_vlib_pci_addr, &pci,
"error encountered on binding pci devicee");
return;
}
}
pool_get (vim->interfaces, vif);
vif->dev_instance = vif - vim->interfaces;
vif->per_interface_next_index = ~0;

View File

@ -227,6 +227,13 @@ typedef enum
#undef _
} virtio_flag_t;
typedef enum
{
VIRTIO_BIND_NONE = 0,
VIRTIO_BIND_DEFAULT = 1,
VIRTIO_BIND_FORCE = 2,
} __clib_packed virtio_bind_t;
typedef struct
{
u32 addr;
@ -238,6 +245,7 @@ typedef struct
u64 features;
u8 gso_enabled;
u8 checksum_offload_enabled;
virtio_bind_t bind;
u32 buffering_size;
u32 virtio_flags;
clib_error_t *error;