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