bus/fslmc: support device blacklisting
authorHemant Agrawal <hemant.agrawal@nxp.com>
Wed, 25 Apr 2018 12:56:59 +0000 (18:26 +0530)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 13 May 2018 22:35:47 +0000 (00:35 +0200)
Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
doc/guides/cryptodevs/dpaa2_sec.rst
doc/guides/nics/dpaa2.rst
drivers/bus/fslmc/fslmc_bus.c
drivers/bus/fslmc/rte_fslmc.h

index fcea483..3ea24c8 100644 (file)
@@ -134,6 +134,17 @@ Supported DPAA2 SoCs
 * LS2088A/LS2048A
 * LS1088A/LS1048A
 
+Whitelisting & Blacklisting
+---------------------------
+
+For blacklisting a DPAA2 SEC device, following commands can be used.
+
+ .. code-block:: console
+
+    <dpdk app> <EAL args> -b "fslmc:dpseci.x" -- ...
+
+Where x is the device object id as configured in resource container.
+
 Limitations
 -----------
 
index 85d2650..66c03e1 100644 (file)
@@ -561,6 +561,17 @@ which are lower than logging ``level``.
 Using ``pmd.dpaa2`` as log matching criteria, all PMD logs can be enabled
 which are lower than logging ``level``.
 
+Whitelisting & Blacklisting
+---------------------------
+
+For blacklisting a DPAA2 device, following commands can be used.
+
+ .. code-block:: console
+
+    <dpdk app> <EAL args> -b "fslmc:dpni.x" -- ...
+
+Where x is the device object id as configured in resource container.
+
 Limitations
 -----------
 
index fde5f19..677fcc2 100644 (file)
@@ -23,6 +23,7 @@
 int dpaa2_logtype_bus;
 
 #define VFIO_IOMMU_GROUP_PATH "/sys/kernel/iommu_groups"
+#define FSLMC_BUS_NAME fslmc
 
 struct rte_fslmc_bus rte_fslmc_bus;
 uint8_t dpaa2_virt_mode;
@@ -93,6 +94,22 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)
                TAILQ_INSERT_TAIL(&rte_fslmc_bus.device_list, newdev, next);
 }
 
+static struct rte_devargs *
+fslmc_devargs_lookup(struct rte_dpaa2_device *dev)
+{
+       struct rte_devargs *devargs;
+       char dev_name[32];
+
+       RTE_EAL_DEVARGS_FOREACH("fslmc", devargs) {
+               devargs->bus->parse(devargs->name, &dev_name);
+               if (strcmp(dev_name, dev->device.name) == 0) {
+                       DPAA2_BUS_INFO("**Devargs matched %s", dev_name);
+                       return devargs;
+               }
+       }
+       return NULL;
+}
+
 static void
 dump_device_list(void)
 {
@@ -184,6 +201,7 @@ scan_one_fslmc_device(char *dev_name)
                DPAA2_BUS_ERR("Unable to clone device name. Out of memory");
                goto cleanup;
        }
+       dev->device.devargs = fslmc_devargs_lookup(dev);
 
        /* Add device in the fslmc device list */
        insert_in_device_list(dev);
@@ -201,6 +219,54 @@ cleanup:
        return -1;
 }
 
+static int
+rte_fslmc_parse(const char *name, void *addr)
+{
+       uint16_t dev_id;
+       char *t_ptr;
+       char *sep = strchr(name, ':');
+
+       if (strncmp(name, RTE_STR(FSLMC_BUS_NAME),
+               strlen(RTE_STR(FSLMC_BUS_NAME)))) {
+               return -EINVAL;
+       }
+
+       if (!sep) {
+               DPAA2_BUS_ERR("Incorrect device name observed");
+               return -EINVAL;
+       }
+
+       t_ptr = (char *)(sep + 1);
+
+       if (strncmp("dpni", t_ptr, 4) &&
+           strncmp("dpseci", t_ptr, 6) &&
+           strncmp("dpcon", t_ptr, 5) &&
+           strncmp("dpbp", t_ptr, 4) &&
+           strncmp("dpio", t_ptr, 4) &&
+           strncmp("dpci", t_ptr, 4) &&
+           strncmp("dpmcp", t_ptr, 5) &&
+           strncmp("dpdmai", t_ptr, 6)) {
+               DPAA2_BUS_ERR("Unknown or unsupported device");
+               return -EINVAL;
+       }
+
+       t_ptr = strchr(name, '.');
+       if (!t_ptr) {
+               DPAA2_BUS_ERR("Incorrect device string observed (%s)", t_ptr);
+               return -EINVAL;
+       }
+
+       t_ptr = (char *)(t_ptr + 1);
+       if (sscanf(t_ptr, "%hu", &dev_id) <= 0) {
+               DPAA2_BUS_ERR("Incorrect device string observed (%s)", t_ptr);
+               return -EINVAL;
+       }
+
+       if (addr)
+               strcpy(addr, (char *)(sep + 1));
+       return 0;
+}
+
 static int
 rte_fslmc_scan(void)
 {
@@ -276,6 +342,8 @@ static int
 rte_fslmc_probe(void)
 {
        int ret = 0;
+       int probe_all;
+
        struct rte_dpaa2_device *dev;
        struct rte_dpaa2_driver *drv;
 
@@ -305,6 +373,8 @@ rte_fslmc_probe(void)
                return 0;
        }
 
+       probe_all = rte_fslmc_bus.bus.conf.scan_mode != RTE_BUS_SCAN_WHITELIST;
+
        TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
                TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
                        ret = rte_fslmc_match(drv, dev);
@@ -314,9 +384,21 @@ rte_fslmc_probe(void)
                        if (!drv->probe)
                                continue;
 
-                       ret = drv->probe(drv, dev);
-                       if (ret)
-                               DPAA2_BUS_ERR("Unable to probe");
+                       if (dev->device.devargs &&
+                         dev->device.devargs->policy == RTE_DEV_BLACKLISTED) {
+                               DPAA2_BUS_LOG(DEBUG, "%s Blacklisted, skipping",
+                                             dev->device.name);
+                               continue;
+                       }
+
+                       if (probe_all ||
+                          (dev->device.devargs &&
+                          dev->device.devargs->policy ==
+                          RTE_DEV_WHITELISTED)) {
+                               ret = drv->probe(drv, dev);
+                               if (ret)
+                                       DPAA2_BUS_ERR("Unable to probe");
+                       }
                        break;
                }
        }
@@ -331,17 +413,19 @@ static struct rte_device *
 rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
                      const void *data)
 {
+       const struct rte_dpaa2_device *dstart;
        struct rte_dpaa2_device *dev;
 
-       TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
-               if (start != NULL) {
-                       if (&dev->device == start)
-                               start = NULL;  /* starting point found */
-                       continue;
-               }
-
+       if (start != NULL) {
+               dstart = RTE_DEV_TO_FSLMC_CONST(start);
+               dev = TAILQ_NEXT(dstart, next);
+       } else {
+               dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
+       }
+       while (dev != NULL) {
                if (cmp(&dev->device, data) == 0)
                        return &dev->device;
+               dev = TAILQ_NEXT(dev, next);
        }
 
        return NULL;
@@ -424,6 +508,7 @@ struct rte_fslmc_bus rte_fslmc_bus = {
        .bus = {
                .scan = rte_fslmc_scan,
                .probe = rte_fslmc_probe,
+               .parse = rte_fslmc_parse,
                .find_device = rte_fslmc_find_device,
                .get_iommu_class = rte_dpaa2_get_iommu_class,
        },
@@ -432,7 +517,7 @@ struct rte_fslmc_bus rte_fslmc_bus = {
        .device_count = {0},
 };
 
-RTE_REGISTER_BUS(fslmc, rte_fslmc_bus.bus);
+RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);
 
 RTE_INIT(fslmc_init_log);
 static void
index 7b34368..33552b4 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 #include <rte_tailq.h>
+#include <rte_devargs.h>
 
 #include <fslmc_vfio.h>
 
@@ -49,6 +50,9 @@ struct rte_dpaa2_driver;
 TAILQ_HEAD(rte_fslmc_device_list, rte_dpaa2_device);
 TAILQ_HEAD(rte_fslmc_driver_list, rte_dpaa2_driver);
 
+#define RTE_DEV_TO_FSLMC_CONST(ptr) \
+       container_of(ptr, const struct rte_dpaa2_device, device)
+
 extern struct rte_fslmc_bus rte_fslmc_bus;
 
 enum rte_dpaa2_dev_type {