4 * Copyright(c) 2016 RehiveTech. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of RehiveTech nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/queue.h>
43 #include <rte_common.h>
44 #include <rte_devargs.h>
46 struct vdev_driver_list vdev_driver_list =
47 TAILQ_HEAD_INITIALIZER(vdev_driver_list);
49 static void rte_vdev_bus_register(void);
51 /* register a driver */
53 rte_eal_vdrv_register(struct rte_vdev_driver *driver)
55 rte_vdev_bus_register();
57 TAILQ_INSERT_TAIL(&vdev_driver_list, driver, next);
58 rte_eal_driver_register(&driver->driver);
61 /* unregister a driver */
63 rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
65 rte_eal_driver_unregister(&driver->driver);
66 TAILQ_REMOVE(&vdev_driver_list, driver, next);
70 vdev_probe_all_drivers(const char *name, const char *args)
72 struct rte_vdev_driver *driver;
74 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
76 * search a driver prefix in virtual device name.
77 * For example, if the driver is pcap PMD, driver->name
78 * will be "net_pcap", but "name" will be "net_pcapN".
79 * So use strncmp to compare.
81 if (!strncmp(driver->driver.name, name,
82 strlen(driver->driver.name)))
83 return driver->probe(name, args);
86 /* Give new names precedence over aliases. */
87 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
88 if (driver->driver.alias &&
89 !strncmp(driver->driver.alias, name,
90 strlen(driver->driver.alias)))
91 return driver->probe(name, args);
98 rte_eal_vdev_init(const char *name, const char *args)
105 ret = vdev_probe_all_drivers(name, args);
107 RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
113 vdev_remove_driver(const char *name)
115 struct rte_vdev_driver *driver;
117 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
119 * search a driver prefix in virtual device name.
120 * For example, if the driver is pcap PMD, driver->name
121 * will be "net_pcap", but "name" will be "net_pcapN".
122 * So use strncmp to compare.
124 if (!strncmp(driver->driver.name, name,
125 strlen(driver->driver.name)))
126 return driver->remove(name);
129 /* Give new names precedence over aliases. */
130 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
131 if (driver->driver.alias &&
132 !strncmp(driver->driver.alias, name,
133 strlen(driver->driver.alias)))
134 return driver->remove(name);
141 rte_eal_vdev_uninit(const char *name)
148 ret = vdev_remove_driver(name);
150 RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
158 /* for virtual devices we don't need to scan anything */
165 struct rte_devargs *devargs;
168 * Note that the dev_driver_list is populated here
169 * from calls made to rte_eal_driver_register from constructor functions
170 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
173 /* call the init function for each virtual device */
174 TAILQ_FOREACH(devargs, &devargs_list, next) {
176 if (devargs->type != RTE_DEVTYPE_VIRTUAL)
179 if (rte_eal_vdev_init(devargs->virt.drv_name,
181 RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
182 devargs->virt.drv_name);
190 static struct rte_bus rte_vdev_bus = {
195 RTE_INIT(rte_vdev_bus_register);
197 static void rte_vdev_bus_register(void)
199 static int registered;
205 rte_vdev_bus.name = RTE_STR(virtual);
206 rte_bus_register(&rte_vdev_bus);