4 * Copyright (c) 2016 NXP. 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 NXP 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.
39 #include <rte_eal_memconfig.h>
40 #include <rte_malloc.h>
41 #include <rte_devargs.h>
42 #include <rte_memcpy.h>
43 #include <rte_ethdev.h>
45 #include "rte_fslmc.h"
46 #include "fslmc_vfio.h"
48 #define FSLMC_BUS_LOG(level, fmt, args...) \
49 RTE_LOG(level, EAL, "%s(): " fmt "\n", __func__, ##args)
51 struct rte_fslmc_bus rte_fslmc_bus;
58 ret = fslmc_vfio_setup_group();
60 FSLMC_BUS_LOG(ERR, "fslmc: Unable to setup VFIO");
64 ret = fslmc_vfio_process_group();
66 FSLMC_BUS_LOG(ERR, "fslmc: Unable to setup devices");
70 RTE_LOG(INFO, EAL, "fslmc: Bus scan completed\n");
75 rte_fslmc_match(struct rte_dpaa2_driver *dpaa2_drv,
76 struct rte_dpaa2_device *dpaa2_dev)
78 if (dpaa2_drv->drv_type == dpaa2_dev->dev_type)
88 struct rte_dpaa2_device *dev;
89 struct rte_dpaa2_driver *drv;
91 TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
92 TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
93 ret = rte_fslmc_match(drv, dev);
100 ret = drv->probe(drv, dev);
102 FSLMC_BUS_LOG(ERR, "Unable to probe.\n");
109 static struct rte_device *
110 rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
113 struct rte_dpaa2_device *dev;
114 bool start_found = !start;
116 TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
118 if (&dev->device == start)
123 if (cmp(&dev->device, data) == 0)
130 /*register a fslmc bus based dpaa2 driver */
132 rte_fslmc_driver_register(struct rte_dpaa2_driver *driver)
136 TAILQ_INSERT_TAIL(&rte_fslmc_bus.driver_list, driver, next);
137 /* Update Bus references */
138 driver->fslmc_bus = &rte_fslmc_bus;
141 /*un-register a fslmc bus based dpaa2 driver */
143 rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver)
145 struct rte_fslmc_bus *fslmc_bus;
147 fslmc_bus = driver->fslmc_bus;
149 TAILQ_REMOVE(&fslmc_bus->driver_list, driver, next);
150 /* Update Bus references */
151 driver->fslmc_bus = NULL;
154 struct rte_fslmc_bus rte_fslmc_bus = {
156 .scan = rte_fslmc_scan,
157 .probe = rte_fslmc_probe,
158 .find_device = rte_fslmc_find_device,
160 .device_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.device_list),
161 .driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
164 RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);