virtio: add option to bind interface to uio driver 16/37416/9
authorBenoît Ganne <bganne@cisco.com>
Thu, 13 Oct 2022 12:01:03 +0000 (14:01 +0200)
committerDave Wallace <dwallacelf@gmail.com>
Wed, 11 Jan 2023 15:26:41 +0000 (15:26 +0000)
Type: improvement

Change-Id: I30e66370c927afeb62ba3a2b3334bdc2a31d4561
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/vnet/devices/virtio/cli.c
src/vnet/devices/virtio/pci.c
src/vnet/devices/virtio/pci.h

index a783369..2457e9b 100644 (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* */
index f678c39..cb177b3 100644 (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;
index db20537..0cada61 100644 (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;