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