cryptodev: uninline parameter parsing
[dpdk.git] / lib / librte_eal / common / eal_common_dev.c
index 8c42738..a8a4146 100644 (file)
@@ -1,14 +1,14 @@
 /*-
  *   BSD LICENSE
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   Copyright(c) 2014 6WIND S.A.
  *   All rights reserved.
- * 
+ *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
  *   are met:
- * 
+ *
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
@@ -18,7 +18,7 @@
  *     * Neither the name of Intel Corporation nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
- * 
+ *
  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -32,6 +32,7 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
 #include <sys/queue.h>
@@ -40,6 +41,7 @@
 #include <rte_devargs.h>
 #include <rte_debug.h>
 #include <rte_devargs.h>
+#include <rte_log.h>
 
 #include "eal_private.h"
 
@@ -61,6 +63,32 @@ rte_eal_driver_unregister(struct rte_driver *driver)
        TAILQ_REMOVE(&dev_driver_list, driver, next);
 }
 
+int
+rte_eal_vdev_init(const char *name, const char *args)
+{
+       struct rte_driver *driver;
+
+       if (name == NULL)
+               return -EINVAL;
+
+       TAILQ_FOREACH(driver, &dev_driver_list, next) {
+               if (driver->type != PMD_VDEV)
+                       continue;
+
+               /*
+                * search a driver prefix in virtual device name.
+                * For example, if the driver is pcap PMD, driver->name
+                * will be "eth_pcap", but "name" will be "eth_pcapN".
+                * So use strncmp to compare.
+                */
+               if (!strncmp(driver->name, name, strlen(driver->name)))
+                       return driver->init(name, args);
+       }
+
+       RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+       return -EINVAL;
+}
+
 int
 rte_eal_dev_init(void)
 {
@@ -79,22 +107,11 @@ rte_eal_dev_init(void)
                if (devargs->type != RTE_DEVTYPE_VIRTUAL)
                        continue;
 
-               TAILQ_FOREACH(driver, &dev_driver_list, next) {
-                       if (driver->type != PMD_VDEV)
-                               continue;
-
-                       /* search a driver prefix in virtual device name */
-                       if (!strncmp(driver->name, devargs->virtual.drv_name,
-                                       strlen(driver->name))) {
-                               driver->init(devargs->virtual.drv_name,
-                                       devargs->args);
-                               break;
-                       }
-               }
-
-               if (driver == NULL) {
-                       rte_panic("no driver found for %s\n",
-                                 devargs->virtual.drv_name);
+               if (rte_eal_vdev_init(devargs->virt.drv_name,
+                                       devargs->args)) {
+                       RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
+                                       devargs->virt.drv_name);
+                       return -1;
                }
        }
 
@@ -107,3 +124,29 @@ rte_eal_dev_init(void)
        }
        return 0;
 }
+
+int
+rte_eal_vdev_uninit(const char *name)
+{
+       struct rte_driver *driver;
+
+       if (name == NULL)
+               return -EINVAL;
+
+       TAILQ_FOREACH(driver, &dev_driver_list, next) {
+               if (driver->type != PMD_VDEV)
+                       continue;
+
+               /*
+                * search a driver prefix in virtual device name.
+                * For example, if the driver is pcap PMD, driver->name
+                * will be "eth_pcap", but "name" will be "eth_pcapN".
+                * So use strncmp to compare.
+                */
+               if (!strncmp(driver->name, name, strlen(driver->name)))
+                       return driver->uninit(name);
+       }
+
+       RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+       return -EINVAL;
+}