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 /** Double linked list of virtual device drivers. */
47 TAILQ_HEAD(vdev_device_list, rte_vdev_device);
49 static struct vdev_device_list vdev_device_list =
50 TAILQ_HEAD_INITIALIZER(vdev_device_list);
51 struct vdev_driver_list vdev_driver_list =
52 TAILQ_HEAD_INITIALIZER(vdev_driver_list);
54 static void rte_vdev_bus_register(void);
56 /* register a driver */
58 rte_eal_vdrv_register(struct rte_vdev_driver *driver)
60 rte_vdev_bus_register();
62 TAILQ_INSERT_TAIL(&vdev_driver_list, driver, next);
63 rte_eal_driver_register(&driver->driver);
66 /* unregister a driver */
68 rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
70 rte_eal_driver_unregister(&driver->driver);
71 TAILQ_REMOVE(&vdev_driver_list, driver, next);
75 vdev_probe_all_drivers(const char *name, const char *args)
77 struct rte_vdev_driver *driver;
79 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
81 * search a driver prefix in virtual device name.
82 * For example, if the driver is pcap PMD, driver->name
83 * will be "net_pcap", but "name" will be "net_pcapN".
84 * So use strncmp to compare.
86 if (!strncmp(driver->driver.name, name,
87 strlen(driver->driver.name)))
88 return driver->probe(name, args);
91 /* Give new names precedence over aliases. */
92 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
93 if (driver->driver.alias &&
94 !strncmp(driver->driver.alias, name,
95 strlen(driver->driver.alias)))
96 return driver->probe(name, args);
103 rte_eal_vdev_init(const char *name, const char *args)
110 ret = vdev_probe_all_drivers(name, args);
112 RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
118 vdev_remove_driver(const char *name)
120 struct rte_vdev_driver *driver;
122 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
124 * search a driver prefix in virtual device name.
125 * For example, if the driver is pcap PMD, driver->name
126 * will be "net_pcap", but "name" will be "net_pcapN".
127 * So use strncmp to compare.
129 if (!strncmp(driver->driver.name, name,
130 strlen(driver->driver.name)))
131 return driver->remove(name);
134 /* Give new names precedence over aliases. */
135 TAILQ_FOREACH(driver, &vdev_driver_list, next) {
136 if (driver->driver.alias &&
137 !strncmp(driver->driver.alias, name,
138 strlen(driver->driver.alias)))
139 return driver->remove(name);
146 rte_eal_vdev_uninit(const char *name)
153 ret = vdev_remove_driver(name);
155 RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
163 /* for virtual devices we don't need to scan anything */
170 struct rte_devargs *devargs;
173 * Note that the dev_driver_list is populated here
174 * from calls made to rte_eal_driver_register from constructor functions
175 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
178 /* call the init function for each virtual device */
179 TAILQ_FOREACH(devargs, &devargs_list, next) {
181 if (devargs->type != RTE_DEVTYPE_VIRTUAL)
184 if (rte_eal_vdev_init(devargs->virt.drv_name,
186 RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
187 devargs->virt.drv_name);
195 static struct rte_bus rte_vdev_bus = {
200 RTE_INIT(rte_vdev_bus_register);
202 static void rte_vdev_bus_register(void)
204 static int registered;
210 rte_vdev_bus.name = RTE_STR(virtual);
211 rte_bus_register(&rte_vdev_bus);