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