This parameter allows specifying any non-NetVSC interface to use with tap
sub-devices for development purposes.

Signed-off-by: Adrien Mazarguil <adrien.mazarg...@6wind.com>
---
 doc/guides/nics/vdev_netvsc.rst       |  5 +++++
 drivers/net/vdev_netvsc/vdev_netvsc.c | 27 +++++++++++++++++++--------
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/doc/guides/nics/vdev_netvsc.rst b/doc/guides/nics/vdev_netvsc.rst
index 73a63e552..a0417b5ef 100644
--- a/doc/guides/nics/vdev_netvsc.rst
+++ b/doc/guides/nics/vdev_netvsc.rst
@@ -107,5 +107,10 @@ The following device parameters are supported:
   Same as ``iface`` except a suitable NetVSC interface is located using its
   MAC address.
 
+- ``force`` [int]
+
+  If nonzero, forces the use of specified interfaces even if not detected as
+  NetVSC.
+
 Not specifying either ``iface`` or ``mac`` makes this PMD attach itself to
 all NetVSC interfaces found on the system.
diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c 
b/drivers/net/vdev_netvsc/vdev_netvsc.c
index 738196e75..5e426adc0 100644
--- a/drivers/net/vdev_netvsc/vdev_netvsc.c
+++ b/drivers/net/vdev_netvsc/vdev_netvsc.c
@@ -63,6 +63,7 @@
 #define VDEV_NETVSC_DRIVER net_vdev_netvsc
 #define VDEV_NETVSC_ARG_IFACE "iface"
 #define VDEV_NETVSC_ARG_MAC "mac"
+#define VDEV_NETVSC_ARG_FORCE "force"
 #define VDEV_NETVSC_PROBE_MS 1000
 
 #define NETVSC_CLASS_ID "{f8615163-df3e-46c5-913f-f2d2f965ed0e}"
@@ -405,6 +406,9 @@ vdev_netvsc_alarm(__rte_unused void *arg)
  *   - struct rte_kvargs *kvargs:
  *     Device arguments provided to current driver instance.
  *
+ *   - int force:
+ *     Accept specified interface even if not detected as NetVSC.
+ *
  *   - unsigned int specified:
  *     Number of specific netdevices provided as device arguments.
  *
@@ -422,6 +426,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface,
 {
        const char *name = va_arg(ap, const char *);
        struct rte_kvargs *kvargs = va_arg(ap, struct rte_kvargs *);
+       int force = va_arg(ap, int);
        unsigned int specified = va_arg(ap, unsigned int);
        unsigned int *matched = va_arg(ap, unsigned int *);
        unsigned int i;
@@ -480,10 +485,11 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface,
                if (!specified)
                        return 0;
                PMD_DRV_LOG(WARNING,
-                           "interface \"%s\" (index %u) is not NetVSC,"
-                           " skipping",
-                           iface->if_name, iface->if_index);
-               return 0;
+                           "interface \"%s\" (index %u) is not NetVSC, %s",
+                           iface->if_name, iface->if_index,
+                           force ? "using anyway (forced)" : "skipping");
+               if (!force)
+                       return 0;
        }
        /* Create interface context. */
        ctx = calloc(1, sizeof(*ctx));
@@ -610,6 +616,7 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev)
        static const char *const vdev_netvsc_arg[] = {
                VDEV_NETVSC_ARG_IFACE,
                VDEV_NETVSC_ARG_MAC,
+               VDEV_NETVSC_ARG_FORCE,
                NULL,
        };
        const char *name = rte_vdev_device_name(dev);
@@ -618,6 +625,7 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev)
                                                     vdev_netvsc_arg);
        unsigned int specified = 0;
        unsigned int matched = 0;
+       int force = 0;
        unsigned int i;
        int ret;
 
@@ -631,14 +639,16 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev)
        for (i = 0; i != kvargs->count; ++i) {
                const struct rte_kvargs_pair *pair = &kvargs->pairs[i];
 
-               if (!strcmp(pair->key, VDEV_NETVSC_ARG_IFACE) ||
-                   !strcmp(pair->key, VDEV_NETVSC_ARG_MAC))
+               if (!strcmp(pair->key, VDEV_NETVSC_ARG_FORCE))
+                       force = !!atoi(pair->value);
+               else if (!strcmp(pair->key, VDEV_NETVSC_ARG_IFACE) ||
+                        !strcmp(pair->key, VDEV_NETVSC_ARG_MAC))
                        ++specified;
        }
        rte_eal_alarm_cancel(vdev_netvsc_alarm, NULL);
        /* Gather interfaces. */
        ret = vdev_netvsc_foreach_iface(vdev_netvsc_netvsc_probe, name, kvargs,
-                                       specified, &matched);
+                                       force, specified, &matched);
        if (ret < 0)
                goto error;
        if (matched < specified)
@@ -697,7 +707,8 @@ RTE_PMD_REGISTER_VDEV(VDEV_NETVSC_DRIVER, vdev_netvsc_vdev);
 RTE_PMD_REGISTER_ALIAS(VDEV_NETVSC_DRIVER, eth_vdev_netvsc);
 RTE_PMD_REGISTER_PARAM_STRING(net_vdev_netvsc,
                              VDEV_NETVSC_ARG_IFACE "=<string> "
-                             VDEV_NETVSC_ARG_MAC "=<string>");
+                             VDEV_NETVSC_ARG_MAC "=<string> "
+                             VDEV_NETVSC_ARG_FORCE "=<int>");
 
 /** Initialize driver log type. */
 static void
-- 
2.11.0

Reply via email to