Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright 2016,2018-2021 NXP
4 : : *
5 : : */
6 : :
7 : : #include <string.h>
8 : : #include <dirent.h>
9 : : #include <stdalign.h>
10 : : #include <stdbool.h>
11 : :
12 : : #include <eal_export.h>
13 : : #include <rte_log.h>
14 : : #include <bus_driver.h>
15 : : #include <rte_malloc.h>
16 : : #include <rte_devargs.h>
17 : : #include <rte_memcpy.h>
18 : : #include <ethdev_driver.h>
19 : : #include <rte_mbuf_dyn.h>
20 : : #include <rte_vfio.h>
21 : :
22 : : #include "private.h"
23 : : #include <fslmc_vfio.h>
24 : : #include "fslmc_logs.h"
25 : :
26 : : #include <dpaax_iova_table.h>
27 : :
28 : : #define VFIO_IOMMU_GROUP_PATH "/sys/kernel/iommu_groups"
29 : : #define FSLMC_BUS_NAME fslmc
30 : :
31 : : struct rte_fslmc_bus rte_fslmc_bus;
32 : :
33 : : #define DPAA2_SEQN_DYNFIELD_NAME "dpaa2_seqn_dynfield"
34 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa2_seqn_dynfield_offset)
35 : : int dpaa2_seqn_dynfield_offset = -1;
36 : :
37 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_get_device_count)
38 : : uint32_t
39 : 0 : rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)
40 : : {
41 [ # # ]: 0 : if (device_type >= DPAA2_DEVTYPE_MAX)
42 : : return 0;
43 : 0 : return rte_fslmc_bus.device_count[device_type];
44 : : }
45 : :
46 : : static void
47 : 0 : cleanup_fslmc_device_list(void)
48 : : {
49 : : struct rte_dpaa2_device *dev;
50 : : struct rte_dpaa2_device *t_dev;
51 : :
52 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, t_dev) {
53 [ # # ]: 0 : TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
54 : 0 : rte_intr_instance_free(dev->intr_handle);
55 : 0 : free(dev);
56 : : dev = NULL;
57 : : }
58 : 0 : }
59 : :
60 : : static int
61 : : compare_dpaa2_devname(struct rte_dpaa2_device *dev1,
62 : : struct rte_dpaa2_device *dev2)
63 : : {
64 : : int comp;
65 : :
66 : 0 : if (dev1->dev_type > dev2->dev_type) {
67 : : comp = 1;
68 [ # # ]: 0 : } else if (dev1->dev_type < dev2->dev_type) {
69 : : comp = -1;
70 : : } else {
71 : : /* Check the ID as types match */
72 [ # # ]: 0 : if (dev1->object_id > dev2->object_id)
73 : : comp = 1;
74 [ # # ]: 0 : else if (dev1->object_id < dev2->object_id)
75 : : comp = -1;
76 : : else
77 : : comp = 0; /* Duplicate device name */
78 : : }
79 : :
80 : : return comp;
81 : : }
82 : :
83 : : static void
84 : 0 : insert_in_device_list(struct rte_dpaa2_device *newdev)
85 : : {
86 : : int comp, inserted = 0;
87 : : struct rte_dpaa2_device *dev = NULL;
88 : : struct rte_dpaa2_device *tdev = NULL;
89 : :
90 [ # # # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, tdev) {
91 : : comp = compare_dpaa2_devname(newdev, dev);
92 : : if (comp < 0) {
93 : 0 : TAILQ_INSERT_BEFORE(dev, newdev, next);
94 : : inserted = 1;
95 : : break;
96 : : }
97 : : }
98 : :
99 : : if (!inserted)
100 : 0 : TAILQ_INSERT_TAIL(&rte_fslmc_bus.device_list, newdev, next);
101 : 0 : }
102 : :
103 : : static struct rte_devargs *
104 : 0 : fslmc_devargs_lookup(struct rte_dpaa2_device *dev)
105 : : {
106 : : struct rte_devargs *devargs;
107 : : char dev_name[32];
108 : :
109 [ # # ]: 0 : RTE_EAL_DEVARGS_FOREACH("fslmc", devargs) {
110 : 0 : devargs->bus->parse(devargs->name, &dev_name);
111 [ # # ]: 0 : if (strcmp(dev_name, dev->device.name) == 0) {
112 : 0 : DPAA2_BUS_INFO("**Devargs matched %s", dev_name);
113 : 0 : return devargs;
114 : : }
115 : : }
116 : : return NULL;
117 : : }
118 : :
119 : : static void
120 : 0 : dump_device_list(void)
121 : : {
122 : : struct rte_dpaa2_device *dev;
123 : :
124 : : /* Only if the log level has been set to Debugging, print list */
125 [ # # ]: 0 : if (rte_log_can_log(dpaa2_logtype_bus, RTE_LOG_DEBUG)) {
126 : 0 : DPAA2_BUS_LOG(DEBUG, "List of devices scanned on bus:");
127 [ # # ]: 0 : TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
128 : 0 : DPAA2_BUS_LOG(DEBUG, "\t\t%s", dev->device.name);
129 : : }
130 : : }
131 : 0 : }
132 : :
133 : : static int
134 : 0 : scan_one_fslmc_device(char *dev_name)
135 : : {
136 : : char *dup_dev_name, *t_ptr;
137 : : struct rte_dpaa2_device *dev = NULL;
138 : : int ret = -1;
139 : :
140 [ # # ]: 0 : if (!dev_name)
141 : : return ret;
142 : :
143 : : /* Creating a temporary copy to perform cut-parse over string */
144 : 0 : dup_dev_name = strdup(dev_name);
145 [ # # ]: 0 : if (!dup_dev_name) {
146 : 0 : DPAA2_BUS_ERR("Unable to allocate device name memory");
147 : 0 : return -ENOMEM;
148 : : }
149 : :
150 : : /* For all other devices, we allocate rte_dpaa2_device.
151 : : * For those devices where there is no driver, probe would release
152 : : * the memory associated with the rte_dpaa2_device after necessary
153 : : * initialization.
154 : : */
155 : 0 : dev = calloc(1, sizeof(struct rte_dpaa2_device));
156 [ # # ]: 0 : if (!dev) {
157 : 0 : DPAA2_BUS_ERR("Unable to allocate device object");
158 : 0 : free(dup_dev_name);
159 : 0 : return -ENOMEM;
160 : : }
161 : :
162 : 0 : dev->device.bus = &rte_fslmc_bus.bus;
163 : 0 : dev->device.numa_node = SOCKET_ID_ANY;
164 : :
165 : : /* Allocate interrupt instance */
166 : 0 : dev->intr_handle =
167 : 0 : rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
168 [ # # ]: 0 : if (dev->intr_handle == NULL) {
169 : 0 : DPAA2_BUS_ERR("Failed to allocate intr handle");
170 : : ret = -ENOMEM;
171 : 0 : goto cleanup;
172 : : }
173 : :
174 : : /* Parse the device name and ID */
175 : 0 : t_ptr = strtok(dup_dev_name, ".");
176 [ # # ]: 0 : if (!t_ptr) {
177 : 0 : DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
178 : : ret = -EINVAL;
179 : 0 : goto cleanup;
180 : : }
181 [ # # ]: 0 : if (!strncmp("dpni", t_ptr, 4))
182 : 0 : dev->dev_type = DPAA2_ETH;
183 [ # # ]: 0 : else if (!strncmp("dpseci", t_ptr, 6))
184 : 0 : dev->dev_type = DPAA2_CRYPTO;
185 [ # # ]: 0 : else if (!strncmp("dpcon", t_ptr, 5))
186 : 0 : dev->dev_type = DPAA2_CON;
187 [ # # ]: 0 : else if (!strncmp("dpbp", t_ptr, 4))
188 : 0 : dev->dev_type = DPAA2_BPOOL;
189 [ # # ]: 0 : else if (!strncmp("dpio", t_ptr, 4))
190 : 0 : dev->dev_type = DPAA2_IO;
191 [ # # ]: 0 : else if (!strncmp("dpci", t_ptr, 4))
192 : 0 : dev->dev_type = DPAA2_CI;
193 [ # # ]: 0 : else if (!strncmp("dpmcp", t_ptr, 5))
194 : 0 : dev->dev_type = DPAA2_MPORTAL;
195 [ # # ]: 0 : else if (!strncmp("dpdmai", t_ptr, 6))
196 : 0 : dev->dev_type = DPAA2_QDMA;
197 [ # # ]: 0 : else if (!strncmp("dpdmux", t_ptr, 6))
198 : 0 : dev->dev_type = DPAA2_MUX;
199 [ # # ]: 0 : else if (!strncmp("dprtc", t_ptr, 5))
200 : 0 : dev->dev_type = DPAA2_DPRTC;
201 [ # # ]: 0 : else if (!strncmp("dprc", t_ptr, 4))
202 : 0 : dev->dev_type = DPAA2_DPRC;
203 : : else
204 : 0 : dev->dev_type = DPAA2_UNKNOWN;
205 : :
206 : 0 : t_ptr = strtok(NULL, ".");
207 [ # # ]: 0 : if (!t_ptr) {
208 : 0 : DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
209 : : ret = 0;
210 : 0 : goto cleanup;
211 : : }
212 : :
213 : 0 : sscanf(t_ptr, "%hu", &dev->object_id);
214 : 0 : dev->device.name = strdup(dev_name);
215 [ # # ]: 0 : if (!dev->device.name) {
216 : 0 : DPAA2_BUS_ERR("Unable to clone device name. Out of memory");
217 : : ret = -ENOMEM;
218 : 0 : goto cleanup;
219 : : }
220 : 0 : dev->device.devargs = fslmc_devargs_lookup(dev);
221 : :
222 : : /* Update the device found into the device_count table */
223 : 0 : rte_fslmc_bus.device_count[dev->dev_type]++;
224 : :
225 : : /* Add device in the fslmc device list */
226 : 0 : insert_in_device_list(dev);
227 : :
228 : : /* Don't need the duplicated device filesystem entry anymore */
229 : 0 : free(dup_dev_name);
230 : :
231 : 0 : return 0;
232 : 0 : cleanup:
233 : 0 : free(dup_dev_name);
234 : : if (dev) {
235 : 0 : rte_intr_instance_free(dev->intr_handle);
236 : 0 : free(dev);
237 : : }
238 : 0 : return ret;
239 : : }
240 : :
241 : : static int
242 : 37 : rte_fslmc_parse(const char *name, void *addr)
243 : : {
244 : : uint16_t dev_id;
245 : : const char *t_ptr;
246 : : const char *sep;
247 : : uint8_t sep_exists = 0;
248 : : int ret = -1;
249 : :
250 : : /* There are multiple ways this can be called, with bus:dev, name=dev
251 : : * or just dev. In all cases, the 'addr' is actually a string.
252 : : */
253 : 37 : sep = strchr(name, ':');
254 [ + + ]: 37 : if (!sep) {
255 : : /* check for '=' */
256 : 18 : sep = strchr(name, '=');
257 [ + + ]: 18 : if (!sep)
258 : : sep_exists = 0;
259 : : else
260 : : sep_exists = 1;
261 : : } else
262 : : sep_exists = 1;
263 : :
264 : : /* Check if starting part if either of 'fslmc:' or 'name=', separator
265 : : * exists.
266 : : */
267 : : if (sep_exists) {
268 : : /* If either of "fslmc" or "name" are starting part */
269 [ + - ]: 21 : if (!strncmp(name, RTE_STR(FSLMC_BUS_NAME),
270 : 21 : strlen(RTE_STR(FSLMC_BUS_NAME))) ||
271 [ - + ]: 21 : (!strncmp(name, "name", strlen("name")))) {
272 : 0 : goto jump_out;
273 : : } else {
274 : 21 : DPAA2_BUS_DEBUG("Invalid device for matching (%s).",
275 : : name);
276 : : ret = -EINVAL;
277 : 21 : goto err_out;
278 : : }
279 : : } else
280 : : sep = name;
281 : :
282 : 16 : jump_out:
283 : : /* Validate device name */
284 [ + - ]: 16 : if (strncmp("dpni", sep, 4) &&
285 [ + - ]: 16 : strncmp("dpseci", sep, 6) &&
286 [ + - ]: 16 : strncmp("dpcon", sep, 5) &&
287 [ + - ]: 16 : strncmp("dpbp", sep, 4) &&
288 [ + - ]: 16 : strncmp("dpio", sep, 4) &&
289 [ + - ]: 16 : strncmp("dpci", sep, 4) &&
290 [ + - ]: 16 : strncmp("dpmcp", sep, 5) &&
291 [ + - ]: 16 : strncmp("dpdmai", sep, 6) &&
292 [ + - ]: 16 : strncmp("dpdmux", sep, 6)) {
293 : 16 : DPAA2_BUS_DEBUG("Unknown or unsupported device (%s)", sep);
294 : : ret = -EINVAL;
295 : 16 : goto err_out;
296 : : }
297 : :
298 : 0 : t_ptr = strchr(sep, '.');
299 [ # # # # ]: 0 : if (!t_ptr || sscanf(t_ptr + 1, "%hu", &dev_id) != 1) {
300 : 0 : DPAA2_BUS_ERR("Missing device id in device name (%s)", sep);
301 : : ret = -EINVAL;
302 : 0 : goto err_out;
303 : : }
304 : :
305 [ # # ]: 0 : if (addr)
306 : : strcpy(addr, sep);
307 : :
308 : : ret = 0;
309 : 37 : err_out:
310 : 37 : return ret;
311 : : }
312 : :
313 : : static int
314 : 209 : rte_fslmc_scan(void)
315 : : {
316 : : int ret;
317 : : char fslmc_dirpath[PATH_MAX];
318 : : DIR *dir;
319 : : struct dirent *entry;
320 : : static int process_once;
321 : : int groupid;
322 : : char *group_name;
323 : :
324 [ - + ]: 209 : if (process_once) {
325 : : struct rte_dpaa2_device *dev;
326 : :
327 : 0 : DPAA2_BUS_DEBUG("Fslmc bus already scanned. Not rescanning");
328 [ # # ]: 0 : TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next)
329 : 0 : dev->device.devargs = fslmc_devargs_lookup(dev);
330 : : return 0;
331 : : }
332 : 209 : process_once = 1;
333 : :
334 : : /* Now we only support single group per process.*/
335 : 209 : group_name = getenv("DPRC");
336 [ + - ]: 209 : if (!group_name) {
337 : 209 : DPAA2_BUS_DEBUG("DPAA2: DPRC not available");
338 : : ret = -EINVAL;
339 : 209 : goto scan_fail;
340 : : }
341 : :
342 : 0 : ret = fslmc_get_container_group(group_name, &groupid);
343 [ # # ]: 0 : if (ret != 0)
344 : 0 : goto scan_fail;
345 : :
346 : : /* Scan devices on the group */
347 : : sprintf(fslmc_dirpath, "%s/%s", SYSFS_FSL_MC_DEVICES, group_name);
348 : 0 : dir = opendir(fslmc_dirpath);
349 [ # # ]: 0 : if (!dir) {
350 : 0 : DPAA2_BUS_ERR("Unable to open VFIO group directory");
351 : 0 : goto scan_fail;
352 : : }
353 : :
354 : : /* Scan the DPRC container object */
355 : 0 : ret = scan_one_fslmc_device(group_name);
356 [ # # ]: 0 : if (ret != 0) {
357 : : /* Error in parsing directory - exit gracefully */
358 : 0 : goto scan_fail_cleanup;
359 : : }
360 : :
361 [ # # ]: 0 : while ((entry = readdir(dir)) != NULL) {
362 [ # # # # ]: 0 : if (entry->d_name[0] == '.' || entry->d_type != DT_DIR)
363 : 0 : continue;
364 : :
365 : 0 : ret = scan_one_fslmc_device(entry->d_name);
366 [ # # ]: 0 : if (ret != 0) {
367 : : /* Error in parsing directory - exit gracefully */
368 : 0 : goto scan_fail_cleanup;
369 : : }
370 : : }
371 : :
372 : 0 : closedir(dir);
373 : :
374 : 0 : DPAA2_BUS_INFO("FSLMC Bus scan completed");
375 : : /* If debugging is enabled, device list is dumped to log output */
376 : 0 : dump_device_list();
377 : :
378 : 0 : return 0;
379 : :
380 : 0 : scan_fail_cleanup:
381 : 0 : closedir(dir);
382 : :
383 : : /* Remove all devices in the list */
384 : 0 : cleanup_fslmc_device_list();
385 : 209 : scan_fail:
386 : 209 : DPAA2_BUS_DEBUG("FSLMC Bus Not Available. Skipping (%d)", ret);
387 : : /* Irrespective of failure, scan only return success */
388 : 209 : return 0;
389 : : }
390 : :
391 : : static int
392 : : rte_fslmc_match(struct rte_dpaa2_driver *dpaa2_drv,
393 : : struct rte_dpaa2_device *dpaa2_dev)
394 : : {
395 [ # # # # : 0 : if (dpaa2_drv->drv_type == dpaa2_dev->dev_type)
# # ]
396 : : return 0;
397 : :
398 : : return 1;
399 : : }
400 : :
401 : : static int
402 : 269 : rte_fslmc_close(void)
403 : : {
404 : : int ret = 0;
405 : :
406 : 269 : ret = fslmc_vfio_close_group();
407 [ + - ]: 269 : if (ret)
408 : 269 : DPAA2_BUS_INFO("Unable to close devices %d", ret);
409 : :
410 : 269 : return 0;
411 : : }
412 : :
413 : : static int
414 : 204 : rte_fslmc_probe(void)
415 : : {
416 : : int ret = 0;
417 : : int probe_all;
418 : :
419 : : struct rte_dpaa2_device *dev;
420 : : struct rte_dpaa2_driver *drv;
421 : :
422 : : static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = {
423 : : .name = DPAA2_SEQN_DYNFIELD_NAME,
424 : : .size = sizeof(dpaa2_seqn_t),
425 : : .align = alignof(dpaa2_seqn_t),
426 : : };
427 : :
428 [ - + ]: 204 : if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
429 : : return 0;
430 : :
431 : 0 : dpaa2_seqn_dynfield_offset =
432 : 0 : rte_mbuf_dynfield_register(&dpaa2_seqn_dynfield_desc);
433 [ # # ]: 0 : if (dpaa2_seqn_dynfield_offset < 0) {
434 : 0 : DPAA2_BUS_ERR("Failed to register mbuf field for dpaa sequence number");
435 : 0 : return 0;
436 : : }
437 : :
438 : 0 : ret = fslmc_vfio_setup_group();
439 [ # # ]: 0 : if (ret) {
440 : 0 : DPAA2_BUS_ERR("Unable to setup VFIO %d", ret);
441 : 0 : return 0;
442 : : }
443 : :
444 : : /* Map existing segments as well as, in case of hotpluggable memory,
445 : : * install callback handler.
446 : : */
447 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
448 : 0 : ret = fslmc_vfio_dmamap();
449 [ # # ]: 0 : if (ret) {
450 : 0 : DPAA2_BUS_ERR("Unable to DMA map existing VAs: (%d)",
451 : : ret);
452 : : /* Not continuing ahead */
453 : 0 : DPAA2_BUS_ERR("FSLMC VFIO Mapping failed");
454 : 0 : return 0;
455 : : }
456 : : }
457 : :
458 : 0 : ret = fslmc_vfio_process_group();
459 [ # # ]: 0 : if (ret) {
460 : 0 : DPAA2_BUS_ERR("Unable to setup devices %d", ret);
461 : 0 : return 0;
462 : : }
463 : :
464 : 0 : probe_all = rte_fslmc_bus.bus.conf.scan_mode != RTE_BUS_SCAN_ALLOWLIST;
465 : :
466 [ # # ]: 0 : TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
467 [ # # ]: 0 : TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
468 : : ret = rte_fslmc_match(drv, dev);
469 : 0 : if (ret)
470 : 0 : continue;
471 : :
472 [ # # ]: 0 : if (!drv->probe)
473 : 0 : continue;
474 : :
475 [ # # ]: 0 : if (rte_dev_is_probed(&dev->device))
476 : 0 : continue;
477 : :
478 [ # # ]: 0 : if (dev->device.devargs &&
479 [ # # ]: 0 : dev->device.devargs->policy == RTE_DEV_BLOCKED) {
480 : 0 : DPAA2_BUS_LOG(DEBUG, "%s Blocked, skipping",
481 : : dev->device.name);
482 : 0 : continue;
483 : : }
484 : :
485 [ # # # # ]: 0 : if (probe_all ||
486 : 0 : (dev->device.devargs &&
487 [ # # ]: 0 : dev->device.devargs->policy == RTE_DEV_ALLOWED)) {
488 : 0 : ret = drv->probe(drv, dev);
489 [ # # ]: 0 : if (ret) {
490 : 0 : DPAA2_BUS_ERR("Unable to probe");
491 : : } else {
492 : 0 : dev->driver = drv;
493 : 0 : dev->device.driver = &drv->driver;
494 : : }
495 : : }
496 : : break;
497 : : }
498 : : }
499 : :
500 : : return 0;
501 : : }
502 : :
503 : : static struct rte_device *
504 : 0 : rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
505 : : const void *data)
506 : : {
507 : : const struct rte_dpaa2_device *dstart;
508 : : struct rte_dpaa2_device *dev;
509 : :
510 : 0 : DPAA2_BUS_DEBUG("Finding a device named %s", (const char *)data);
511 : :
512 : : /* find_device is always called with an opaque object which should be
513 : : * passed along to the 'cmp' function iterating over all device obj
514 : : * on the bus.
515 : : */
516 : :
517 [ # # ]: 0 : if (start != NULL) {
518 : 0 : dstart = RTE_DEV_TO_FSLMC_CONST(start);
519 : 0 : dev = TAILQ_NEXT(dstart, next);
520 : : } else {
521 : 0 : dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
522 : : }
523 [ # # ]: 0 : while (dev != NULL) {
524 [ # # ]: 0 : if (cmp(&dev->device, data) == 0) {
525 : 0 : DPAA2_BUS_DEBUG("Found device (%s)",
526 : : dev->device.name);
527 : 0 : return &dev->device;
528 : : }
529 : 0 : dev = TAILQ_NEXT(dev, next);
530 : : }
531 : :
532 : : return NULL;
533 : : }
534 : :
535 : : /*register a fslmc bus based dpaa2 driver */
536 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_register)
537 : : void
538 : 828 : rte_fslmc_driver_register(struct rte_dpaa2_driver *driver)
539 : : {
540 [ - + ]: 828 : RTE_VERIFY(driver);
541 : :
542 : 828 : TAILQ_INSERT_TAIL(&rte_fslmc_bus.driver_list, driver, next);
543 : 828 : }
544 : :
545 : : /*un-register a fslmc bus based dpaa2 driver */
546 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_unregister)
547 : : void
548 : 0 : rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver)
549 : : {
550 [ # # ]: 0 : TAILQ_REMOVE(&rte_fslmc_bus.driver_list, driver, next);
551 : 0 : }
552 : :
553 : : /*
554 : : * All device has iova as va
555 : : */
556 : : static inline int
557 : : fslmc_all_device_support_iova(void)
558 : : {
559 : : int ret = 0;
560 : : struct rte_dpaa2_device *dev;
561 : : struct rte_dpaa2_driver *drv;
562 : :
563 [ # # ]: 0 : TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
564 [ # # ]: 0 : TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
565 : : ret = rte_fslmc_match(drv, dev);
566 : 0 : if (ret)
567 : 0 : continue;
568 : : /* if the driver is not supporting IOVA */
569 [ # # ]: 0 : if (!(drv->drv_flags & RTE_DPAA2_DRV_IOVA_AS_VA))
570 : : return 0;
571 : : }
572 : : }
573 : : return 1;
574 : : }
575 : :
576 : : /*
577 : : * Get iommu class of DPAA2 devices on the bus.
578 : : */
579 : : static enum rte_iova_mode
580 : 209 : rte_dpaa2_get_iommu_class(void)
581 : : {
582 [ + - ]: 209 : if (rte_eal_iova_mode() == RTE_IOVA_PA)
583 : : return RTE_IOVA_PA;
584 : :
585 [ - + ]: 209 : if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
586 : : return RTE_IOVA_DC;
587 : :
588 : : /* check if all devices on the bus support Virtual addressing or not */
589 [ # # # # ]: 0 : if (fslmc_all_device_support_iova() != 0 && rte_vfio_noiommu_is_enabled() == 0)
590 : 0 : return RTE_IOVA_VA;
591 : :
592 : : return RTE_IOVA_PA;
593 : : }
594 : :
595 : : static int
596 : 0 : fslmc_bus_plug(struct rte_device *rte_dev)
597 : : {
598 : : int ret = 0;
599 : 0 : struct rte_dpaa2_device *dev = container_of(rte_dev,
600 : : struct rte_dpaa2_device, device);
601 : : struct rte_dpaa2_driver *drv;
602 : :
603 [ # # ]: 0 : TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
604 : : ret = rte_fslmc_match(drv, dev);
605 : 0 : if (ret)
606 : 0 : continue;
607 : :
608 [ # # ]: 0 : if (!drv->probe)
609 : 0 : continue;
610 : :
611 [ # # ]: 0 : if (rte_dev_is_probed(&dev->device))
612 : 0 : continue;
613 : :
614 [ # # ]: 0 : if (dev->device.devargs &&
615 [ # # ]: 0 : dev->device.devargs->policy == RTE_DEV_BLOCKED) {
616 : 0 : DPAA2_BUS_DEBUG("%s Blocked, skipping",
617 : : dev->device.name);
618 : 0 : continue;
619 : : }
620 : :
621 : 0 : ret = drv->probe(drv, dev);
622 [ # # ]: 0 : if (ret) {
623 : 0 : DPAA2_BUS_ERR("Unable to probe");
624 : : } else {
625 : 0 : dev->driver = drv;
626 : 0 : dev->device.driver = &drv->driver;
627 : 0 : DPAA2_BUS_INFO("%s Plugged", dev->device.name);
628 : : }
629 : : break;
630 : : }
631 : :
632 : 0 : return ret;
633 : : }
634 : :
635 : : static int
636 : 0 : fslmc_bus_unplug(struct rte_device *rte_dev)
637 : : {
638 : 0 : struct rte_dpaa2_device *dev = container_of(rte_dev,
639 : : struct rte_dpaa2_device, device);
640 : 0 : struct rte_dpaa2_driver *drv = dev->driver;
641 : :
642 [ # # # # ]: 0 : if (drv && drv->remove) {
643 : 0 : drv->remove(dev);
644 : 0 : dev->driver = NULL;
645 : 0 : dev->device.driver = NULL;
646 : 0 : DPAA2_BUS_INFO("%s Un-Plugged", dev->device.name);
647 : 0 : return 0;
648 : : }
649 : :
650 : : return -ENODEV;
651 : : }
652 : :
653 : : static void *
654 : 0 : fslmc_bus_dev_iterate(const void *start, const char *str,
655 : : const struct rte_dev_iterator *it __rte_unused)
656 : : {
657 : : const struct rte_dpaa2_device *dstart;
658 : : struct rte_dpaa2_device *dev;
659 : : char *dup, *dev_name = NULL;
660 : :
661 [ # # ]: 0 : if (str == NULL) {
662 : 0 : DPAA2_BUS_DEBUG("No device string");
663 : 0 : return NULL;
664 : : }
665 : :
666 : : /* Expectation is that device would be name=device_name */
667 [ # # ]: 0 : if (strncmp(str, "name=", 5) != 0) {
668 : 0 : DPAA2_BUS_DEBUG("Invalid device string (%s)", str);
669 : 0 : return NULL;
670 : : }
671 : :
672 : : /* Now that name=device_name format is available, split */
673 : 0 : dup = strdup(str);
674 [ # # ]: 0 : if (dup == NULL) {
675 : 0 : DPAA2_BUS_DEBUG("Dup string (%s) failed!", str);
676 : 0 : return NULL;
677 : : }
678 : 0 : dev_name = dup + strlen("name=");
679 : :
680 [ # # ]: 0 : if (start != NULL) {
681 : 0 : dstart = RTE_DEV_TO_FSLMC_CONST(start);
682 : 0 : dev = TAILQ_NEXT(dstart, next);
683 : : } else {
684 : 0 : dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
685 : : }
686 : :
687 [ # # ]: 0 : while (dev != NULL) {
688 [ # # ]: 0 : if (strcmp(dev->device.name, dev_name) == 0) {
689 : 0 : free(dup);
690 : 0 : return &dev->device;
691 : : }
692 : 0 : dev = TAILQ_NEXT(dev, next);
693 : : }
694 : :
695 : 0 : free(dup);
696 : 0 : return NULL;
697 : : }
698 : :
699 : : struct rte_fslmc_bus rte_fslmc_bus = {
700 : : .bus = {
701 : : .scan = rte_fslmc_scan,
702 : : .probe = rte_fslmc_probe,
703 : : .cleanup = rte_fslmc_close,
704 : : .parse = rte_fslmc_parse,
705 : : .find_device = rte_fslmc_find_device,
706 : : .get_iommu_class = rte_dpaa2_get_iommu_class,
707 : : .plug = fslmc_bus_plug,
708 : : .unplug = fslmc_bus_unplug,
709 : : .dev_iterate = fslmc_bus_dev_iterate,
710 : : },
711 : : .device_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.device_list),
712 : : .driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
713 : : .device_count = {0},
714 : : };
715 : :
716 : 276 : RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);
717 [ - + ]: 276 : RTE_LOG_REGISTER_DEFAULT(dpaa2_logtype_bus, NOTICE);
|