Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright 2017-2026 NXP
4 : : *
5 : : */
6 : : /* System headers */
7 : : #include <stdalign.h>
8 : : #include <stdio.h>
9 : : #include <inttypes.h>
10 : : #include <unistd.h>
11 : : #include <limits.h>
12 : : #include <sched.h>
13 : : #include <signal.h>
14 : : #include <pthread.h>
15 : : #include <sys/types.h>
16 : : #include <sys/eventfd.h>
17 : :
18 : : #include <eal_export.h>
19 : : #include <rte_byteorder.h>
20 : : #include <rte_common.h>
21 : : #include <rte_interrupts.h>
22 : : #include <rte_log.h>
23 : : #include <rte_debug.h>
24 : : #include <rte_atomic.h>
25 : : #include <rte_branch_prediction.h>
26 : : #include <rte_memory.h>
27 : : #include <rte_tailq.h>
28 : : #include <rte_eal.h>
29 : : #include <rte_alarm.h>
30 : : #include <rte_ether.h>
31 : : #include <ethdev_driver.h>
32 : : #include <rte_malloc.h>
33 : : #include <rte_ring.h>
34 : : #include <bus_driver.h>
35 : : #include <rte_mbuf_pool_ops.h>
36 : : #include <rte_mbuf_dyn.h>
37 : :
38 : : #include <dpaa_of.h>
39 : : #include <bus_dpaa_driver.h>
40 : : #include <rte_dpaa_logs.h>
41 : : #include <dpaax_iova_table.h>
42 : :
43 : : #include <fsl_usd.h>
44 : : #include <fsl_qman.h>
45 : : #include <fsl_bman.h>
46 : : #include <netcfg.h>
47 : : #include <fman.h>
48 : :
49 : : #define DPAA_SOC_ID_FILE "/sys/devices/soc0/soc_id"
50 : : #define DPAA_SVR_MASK 0xffff0000
51 : : #define RTE_PRIORITY_102 102
52 : :
53 : : #define DPAA_PUSH_RXQ_NUM_ARG "dpaa_push_rxq_num"
54 : : /* At present we allow up to 4 push mode queues as default - as each of
55 : : * this queue need dedicated portal and we are short of portals.
56 : : */
57 : : #define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"
58 : : #define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa"
59 : :
60 : : #define DPAA_MAX_PUSH_MODE_QUEUE 8
61 : : #define DPAA_DEFAULT_PUSH_MODE_QUEUE 4
62 : :
63 : : struct rte_dpaa_bus_private {
64 : : int device_count;
65 : : int detected;
66 : : uint32_t svr_ver;
67 : : uint16_t max_push_rxq_num;
68 : : RTE_ATOMIC(uint16_t) push_rxq_num;
69 : : };
70 : :
71 : : static struct rte_bus rte_dpaa_bus;
72 : : static struct rte_dpaa_bus_private dpaa_bus;
73 : : static struct netcfg_info *dpaa_netcfg;
74 : :
75 : : /* define a variable to hold the portal_key, once created.*/
76 : : static pthread_key_t dpaa_portal_key;
77 : : /* dpaa lcore specific portals */
78 : : struct dpaa_portal *dpaa_portals[RTE_MAX_LCORE] = {NULL};
79 : : static int dpaa_bus_global_init;
80 : :
81 : : RTE_EXPORT_INTERNAL_SYMBOL(per_lcore_dpaa_io)
82 : : RTE_DEFINE_PER_LCORE(struct dpaa_portal *, dpaa_io);
83 : :
84 : : #define DPAA_SEQN_DYNFIELD_NAME "dpaa_seqn_dynfield"
85 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_seqn_dynfield_offset)
86 : : int dpaa_seqn_dynfield_offset = -1;
87 : :
88 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_get_eth_port_cfg)
89 : :
90 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_soc_ver)
91 : 0 : uint32_t dpaa_soc_ver(void)
92 : : {
93 : 0 : return dpaa_bus.svr_ver;
94 : : }
95 : :
96 : : struct fm_eth_port_cfg *
97 : 0 : dpaa_get_eth_port_cfg(int dev_id)
98 : : {
99 : 0 : return &dpaa_netcfg->port_cfg[dev_id];
100 : : }
101 : :
102 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_push_queue_num_update)
103 : : int
104 : 0 : dpaa_push_queue_num_update(void)
105 : : {
106 : : int ret = false;
107 : : uint16_t current, new_val;
108 : :
109 : 0 : current = rte_atomic_load_explicit(&dpaa_bus.push_rxq_num,
110 : : rte_memory_order_acquire);
111 [ # # ]: 0 : if (current < dpaa_bus.max_push_rxq_num) {
112 : 0 : new_val = current + 1;
113 [ # # ]: 0 : if (rte_atomic_compare_exchange_strong_explicit(&dpaa_bus.push_rxq_num,
114 : : ¤t, new_val,
115 : : rte_memory_order_release,
116 : : rte_memory_order_acquire))
117 : : ret = true;
118 : : }
119 : :
120 : 0 : return ret;
121 : : }
122 : :
123 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_push_queue_max_num)
124 : : uint16_t
125 : 0 : dpaa_push_queue_max_num(void)
126 : : {
127 : 0 : return dpaa_bus.max_push_rxq_num;
128 : : }
129 : :
130 : : static int
131 : : compare_dpaa_devices(struct rte_dpaa_device *dev1,
132 : : struct rte_dpaa_device *dev2)
133 : : {
134 : : int comp = 0;
135 : :
136 : : /* Segregating ETH from SEC devices */
137 : 0 : if (dev1->device_type > dev2->device_type)
138 : : comp = 1;
139 [ # # ]: 0 : else if (dev1->device_type < dev2->device_type)
140 : : comp = -1;
141 : : else
142 : : comp = 0;
143 : :
144 [ # # ]: 0 : if ((comp != 0) || (dev1->device_type != FSL_DPAA_ETH))
145 : : return comp;
146 : :
147 [ # # ]: 0 : if (dev1->id.fman_id > dev2->id.fman_id) {
148 : : comp = 1;
149 [ # # ]: 0 : } else if (dev1->id.fman_id < dev2->id.fman_id) {
150 : : comp = -1;
151 : : } else {
152 : : /* FMAN ids match, check for mac_id */
153 [ # # ]: 0 : if (dev1->id.mac_id > dev2->id.mac_id)
154 : : comp = 1;
155 [ # # ]: 0 : else if (dev1->id.mac_id < dev2->id.mac_id)
156 : : comp = -1;
157 : : else
158 : : comp = 0;
159 : : }
160 : :
161 : : return comp;
162 : : }
163 : :
164 : : static inline void
165 : 0 : dpaa_add_to_device_list(struct rte_dpaa_device *newdev)
166 : : {
167 : : int comp, inserted = 0;
168 : : struct rte_dpaa_device *dev = NULL;
169 : :
170 [ # # # # ]: 0 : RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {
171 : : comp = compare_dpaa_devices(newdev, dev);
172 : : if (comp < 0) {
173 : 0 : rte_bus_insert_device(&rte_dpaa_bus, &dev->device, &newdev->device);
174 : : inserted = 1;
175 : : break;
176 : : }
177 : : }
178 : :
179 : : if (!inserted)
180 : 0 : rte_bus_add_device(&rte_dpaa_bus, &newdev->device);
181 : 0 : }
182 : :
183 : : /*
184 : : * Reads the SEC device from DTS
185 : : * Returns -1 if SEC devices not available, 0 otherwise
186 : : */
187 : : static inline int
188 : : dpaa_sec_available(void)
189 : : {
190 : : const struct device_node *caam_node;
191 : :
192 [ # # ]: 0 : for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
193 : : return 0;
194 : : }
195 : :
196 : : return -1;
197 : : }
198 : :
199 : : static int
200 : 0 : dpaa_create_device_list(void)
201 : : {
202 : : int i;
203 : : int ret;
204 : : struct rte_dpaa_device *dev;
205 : : struct fm_eth_port_cfg *cfg;
206 : : struct fman_if *fman_intf;
207 : :
208 : 0 : dpaa_bus.device_count = 0;
209 : :
210 : : /* Creating Ethernet Devices */
211 [ # # # # ]: 0 : for (i = 0; dpaa_netcfg && (i < dpaa_netcfg->num_ethports); i++) {
212 : 0 : dev = calloc(1, sizeof(struct rte_dpaa_device));
213 [ # # ]: 0 : if (!dev) {
214 : 0 : DPAA_BUS_ERR("Failed to allocate ETH devices");
215 : : ret = -ENOMEM;
216 : 0 : goto cleanup;
217 : : }
218 : :
219 : 0 : dev->device.numa_node = SOCKET_ID_ANY;
220 : :
221 : : cfg = &dpaa_netcfg->port_cfg[i];
222 : 0 : fman_intf = cfg->fman_if;
223 : :
224 : : /* Device identifiers */
225 : 0 : dev->id.fman_id = fman_intf->fman->idx + 1;
226 : 0 : dev->id.mac_id = fman_intf->mac_idx;
227 : 0 : dev->device_type = FSL_DPAA_ETH;
228 : 0 : dev->id.dev_id = i;
229 : :
230 : : /* Create device name */
231 [ # # ]: 0 : memset(dev->name, 0, RTE_ETH_NAME_MAX_LEN);
232 [ # # ]: 0 : if (fman_intf->mac_type == fman_offline_internal) {
233 : 0 : snprintf(dev->name, RTE_ETH_NAME_MAX_LEN, "fm%d-oh%d",
234 : 0 : (fman_intf->fman->idx + 1), fman_intf->mac_idx);
235 [ # # ]: 0 : } else if (fman_intf->mac_type == fman_onic) {
236 : 0 : snprintf(dev->name, RTE_ETH_NAME_MAX_LEN, "fm%d-onic%d",
237 : 0 : (fman_intf->fman->idx + 1), fman_intf->mac_idx);
238 : : } else {
239 : 0 : snprintf(dev->name, RTE_ETH_NAME_MAX_LEN, "fm%d-mac%d",
240 : 0 : (fman_intf->fman->idx + 1), fman_intf->mac_idx);
241 : : }
242 : 0 : dev->device.name = dev->name;
243 : 0 : dev->device.devargs = rte_bus_find_devargs(&rte_dpaa_bus, dev->name);
244 [ # # ]: 0 : if (dev->device.devargs != NULL)
245 : 0 : DPAA_BUS_INFO("**Devargs matched %s", dev->name);
246 : :
247 : 0 : dpaa_add_to_device_list(dev);
248 : : }
249 : :
250 : 0 : dpaa_bus.device_count += i;
251 : :
252 : : /* Unlike case of ETH, RTE_LIBRTE_DPAA_MAX_CRYPTODEV SEC devices are
253 : : * constantly created only if "sec" property is found in the device
254 : : * tree. Logically there is no limit for number of devices (QI
255 : : * interfaces) that can be created.
256 : : */
257 : :
258 : : if (dpaa_sec_available()) {
259 : 0 : DPAA_BUS_INFO("DPAA SEC devices are not available");
260 : 0 : goto qdma_dpaa;
261 : : }
262 : :
263 : : /* Creating SEC Devices */
264 [ # # ]: 0 : for (i = 0; i < RTE_LIBRTE_DPAA_MAX_CRYPTODEV; i++) {
265 : 0 : dev = calloc(1, sizeof(struct rte_dpaa_device));
266 [ # # ]: 0 : if (!dev) {
267 : 0 : DPAA_BUS_ERR("Failed to allocate SEC devices");
268 : : ret = -ENOMEM;
269 : 0 : goto cleanup;
270 : : }
271 : :
272 : 0 : dev->device_type = FSL_DPAA_CRYPTO;
273 : 0 : dev->id.dev_id = dpaa_bus.device_count + i;
274 : :
275 : : /* Even though RTE_CRYPTODEV_NAME_MAX_LEN is valid length of
276 : : * crypto PMD, using RTE_ETH_NAME_MAX_LEN as that is the size
277 : : * allocated for dev->name/
278 : : */
279 : 0 : memset(dev->name, 0, RTE_ETH_NAME_MAX_LEN);
280 : 0 : sprintf(dev->name, "dpaa_sec-%d", i+1);
281 : 0 : DPAA_BUS_INFO("%s cryptodev added", dev->name);
282 : 0 : dev->device.name = dev->name;
283 : 0 : dev->device.devargs = rte_bus_find_devargs(&rte_dpaa_bus, dev->name);
284 [ # # ]: 0 : if (dev->device.devargs != NULL)
285 : 0 : DPAA_BUS_INFO("**Devargs matched %s", dev->name);
286 : :
287 : 0 : dpaa_add_to_device_list(dev);
288 : : }
289 : :
290 : 0 : dpaa_bus.device_count += i;
291 : :
292 : : qdma_dpaa:
293 : : /* Creating QDMA Device */
294 [ # # ]: 0 : for (i = 0; i < RTE_DPAA_QDMA_DEVICES; i++) {
295 : 0 : dev = calloc(1, sizeof(struct rte_dpaa_device));
296 [ # # ]: 0 : if (!dev) {
297 : 0 : DPAA_BUS_ERR("Failed to allocate QDMA device");
298 : : ret = -ENOMEM;
299 : 0 : goto cleanup;
300 : : }
301 : :
302 : 0 : dev->device_type = FSL_DPAA_QDMA;
303 : 0 : dev->id.dev_id = dpaa_bus.device_count + i;
304 : :
305 : 0 : memset(dev->name, 0, RTE_ETH_NAME_MAX_LEN);
306 : : sprintf(dev->name, "dpaa_qdma-%d", i+1);
307 : 0 : DPAA_BUS_INFO("%s qdma device added", dev->name);
308 : 0 : dev->device.name = dev->name;
309 : 0 : dev->device.devargs = rte_bus_find_devargs(&rte_dpaa_bus, dev->name);
310 [ # # ]: 0 : if (dev->device.devargs != NULL)
311 : 0 : DPAA_BUS_INFO("**Devargs matched %s", dev->name);
312 : :
313 : 0 : dpaa_add_to_device_list(dev);
314 : : }
315 : 0 : dpaa_bus.device_count += i;
316 : :
317 : 0 : return 0;
318 : :
319 : 0 : cleanup:
320 [ # # ]: 0 : RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {
321 : 0 : rte_bus_remove_device(&rte_dpaa_bus, &dev->device);
322 : 0 : free(dev);
323 : : }
324 : :
325 : : return ret;
326 : : }
327 : :
328 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_portal_init)
329 : 0 : int rte_dpaa_portal_init(void *arg)
330 : : {
331 : : static const struct rte_mbuf_dynfield dpaa_seqn_dynfield_desc = {
332 : : .name = DPAA_SEQN_DYNFIELD_NAME,
333 : : .size = sizeof(dpaa_seqn_t),
334 : : .align = alignof(dpaa_seqn_t),
335 : : };
336 : : unsigned int cpu, lcore = rte_lcore_id();
337 : : int ret;
338 : :
339 : 0 : BUS_INIT_FUNC_TRACE();
340 : :
341 [ # # ]: 0 : if ((size_t)arg == 1 || lcore == LCORE_ID_ANY)
342 : 0 : lcore = rte_get_main_lcore();
343 : : else
344 [ # # ]: 0 : if (lcore >= RTE_MAX_LCORE)
345 : : return -1;
346 : :
347 : 0 : cpu = rte_lcore_to_cpu_id(lcore);
348 : :
349 : 0 : dpaa_seqn_dynfield_offset =
350 : 0 : rte_mbuf_dynfield_register(&dpaa_seqn_dynfield_desc);
351 [ # # ]: 0 : if (dpaa_seqn_dynfield_offset < 0) {
352 : 0 : DPAA_BUS_ERR("Failed to register mbuf field for dpaa sequence number");
353 : 0 : return -rte_errno;
354 : : }
355 : :
356 : : /* Initialise bman thread portals */
357 : 0 : ret = bman_thread_init();
358 [ # # ]: 0 : if (ret) {
359 : 0 : DPAA_BUS_ERR("Failed(%d) to init bman thread on cpu%d/lcore%d",
360 : : ret, cpu, lcore);
361 : 0 : return ret;
362 : : }
363 : :
364 : 0 : DPAA_BUS_DEBUG("BMAN thread initialized - CPU=%d lcore=%d", cpu, lcore);
365 : :
366 : : /* Initialise qman thread portals */
367 : 0 : ret = qman_thread_init();
368 [ # # ]: 0 : if (ret) {
369 : 0 : DPAA_BUS_ERR("Failed(%d) to init qman thread on cpu%d/lcore%d",
370 : : ret, cpu, lcore);
371 : 0 : bman_thread_finish();
372 : 0 : return ret;
373 : : }
374 : :
375 : 0 : DPAA_BUS_DEBUG("QMAN thread initialized - CPU=%d lcore=%d", cpu, lcore);
376 : :
377 : 0 : DPAA_PER_LCORE_PORTAL = rte_malloc(NULL, sizeof(struct dpaa_portal),
378 : : RTE_CACHE_LINE_SIZE);
379 [ # # ]: 0 : if (!DPAA_PER_LCORE_PORTAL) {
380 : 0 : DPAA_BUS_ERR("Unable to allocate memory");
381 : 0 : bman_thread_finish();
382 : 0 : qman_thread_finish();
383 : 0 : return -ENOMEM;
384 : : }
385 : :
386 : 0 : DPAA_PER_LCORE_PORTAL->qman_idx = qman_get_portal_index();
387 [ # # ]: 0 : DPAA_PER_LCORE_PORTAL->bman_idx = bman_get_portal_index();
388 : 0 : DPAA_PER_LCORE_PORTAL->tid = rte_gettid();
389 : :
390 : 0 : ret = pthread_setspecific(dpaa_portal_key,
391 : : (void *)DPAA_PER_LCORE_PORTAL);
392 [ # # ]: 0 : if (ret) {
393 : 0 : DPAA_BUS_ERR("Failed(%d) to set portal per thread on cpu%u/lcore%u",
394 : : ret, cpu, lcore);
395 : 0 : dpaa_portal_finish(NULL);
396 : :
397 : 0 : return ret;
398 : : }
399 : 0 : dpaa_portals[lcore] = DPAA_PER_LCORE_PORTAL;
400 : :
401 : 0 : DPAA_BUS_DEBUG("QMAN thread initialized");
402 : :
403 : 0 : return 0;
404 : : }
405 : :
406 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_portal_fq_init)
407 : : int
408 : 0 : rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq)
409 : : {
410 : : /* Affine above created portal with channel*/
411 : : u32 sdqcr;
412 : : int ret;
413 : :
414 [ # # ]: 0 : if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
415 : 0 : ret = rte_dpaa_portal_init(arg);
416 [ # # ]: 0 : if (ret < 0) {
417 : 0 : DPAA_BUS_ERR("portal initialization failure");
418 : 0 : return ret;
419 : : }
420 : : }
421 : :
422 : : /* Initialise qman specific portals */
423 : 0 : ret = fsl_qman_fq_portal_init(fq->qp);
424 [ # # ]: 0 : if (ret) {
425 : 0 : DPAA_BUS_ERR("Unable to init fq portal");
426 : 0 : return -1;
427 : : }
428 : :
429 : 0 : sdqcr = QM_SDQCR_CHANNELS_POOL_CONV(fq->ch_id);
430 : 0 : qman_static_dequeue_add(sdqcr, fq->qp);
431 : :
432 : 0 : return 0;
433 : : }
434 : :
435 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_portal_fq_close)
436 : 0 : int rte_dpaa_portal_fq_close(struct qman_fq *fq)
437 : : {
438 : 0 : return fsl_qman_fq_portal_destroy(fq->qp);
439 : : }
440 : :
441 : : void
442 : 299 : dpaa_portal_finish(void *arg)
443 : : {
444 : : struct dpaa_portal *dpaa_io_portal = (struct dpaa_portal *)arg;
445 : :
446 [ + - ]: 299 : if (!dpaa_io_portal) {
447 : 299 : DPAA_BUS_DEBUG("Portal already cleaned");
448 : 299 : return;
449 : : }
450 : :
451 : 0 : bman_thread_finish();
452 : 0 : qman_thread_finish();
453 : :
454 : 0 : pthread_setspecific(dpaa_portal_key, NULL);
455 : :
456 : 0 : rte_free(dpaa_io_portal);
457 : : dpaa_io_portal = NULL;
458 : 0 : DPAA_PER_LCORE_PORTAL = NULL;
459 : 0 : dpaa_portals[rte_lcore_id()] = NULL;
460 : 0 : DPAA_BUS_DEBUG("Portal cleanup done for lcore = %d", rte_lcore_id());
461 : : }
462 : :
463 : : static int
464 : 41 : rte_dpaa_bus_parse(const char *name, void *out)
465 : : {
466 : : unsigned int i, j;
467 : : size_t delta, dev_delta;
468 : : size_t max_name_len;
469 : :
470 : : /* There are two ways of passing device name, with and without
471 : : * separator. "dpaa_bus:fm1-mac3" with separator, and "fm1-mac3"
472 : : * without separator. Both need to be handled.
473 : : * It is also possible that "name=fm1-mac3" is passed along.
474 : : */
475 : 41 : DPAA_BUS_DEBUG("Parse device name (%s)", name);
476 : :
477 : : delta = 0;
478 [ + - ]: 41 : if (strncmp(name, "dpaa_bus:", 9) == 0) {
479 : : delta = 9;
480 [ - + ]: 41 : } else if (strncmp(name, "name=", 5) == 0) {
481 : : delta = 5;
482 : : }
483 : :
484 : : /* dev_delta points to the dev name (mac/oh/onic). Not valid for
485 : : * dpaa_sec.
486 : : */
487 : 41 : dev_delta = delta + sizeof("fm.-") - 1;
488 : :
489 [ - + ]: 41 : if (strncmp("dpaa_sec", &name[delta], 8) == 0) {
490 [ # # ]: 0 : if (sscanf(&name[delta], "dpaa_sec-%u", &i) != 1 ||
491 [ # # # # ]: 0 : i < 1 || i > 4)
492 : : return -EINVAL;
493 : : max_name_len = sizeof("dpaa_sec-.") - 1;
494 [ - + ]: 41 : } else if (strncmp("dpaa_qdma", &name[delta], 9) == 0) {
495 [ # # ]: 0 : if (sscanf(&name[delta], "dpaa_qdma-%u", &i) != 1 ||
496 [ # # # # ]: 0 : i < 1 || i > RTE_DPAA_QDMA_DEVICES)
497 : : return -EINVAL;
498 : : max_name_len = sizeof("dpaa_qdma-.") - 1;
499 [ - + ]: 41 : } else if (strncmp("oh", &name[dev_delta], 2) == 0) {
500 [ # # ]: 0 : if (sscanf(&name[delta], "fm%u-oh%u", &i, &j) != 2 ||
501 [ # # # # ]: 0 : i >= 2 || j >= 16)
502 : : return -EINVAL;
503 : : max_name_len = sizeof("fm.-oh..") - 1;
504 [ - + ]: 41 : } else if (strncmp("onic", &name[dev_delta], 4) == 0) {
505 [ # # ]: 0 : if (sscanf(&name[delta], "fm%u-onic%u", &i, &j) != 2 ||
506 [ # # # # ]: 0 : i >= 2 || j >= 16)
507 : : return -EINVAL;
508 : : max_name_len = sizeof("fm.-onic..") - 1;
509 : : } else {
510 [ - + ]: 41 : if (sscanf(&name[delta], "fm%u-mac%u", &i, &j) != 2 ||
511 [ # # # # ]: 0 : i >= 2 || j >= 16)
512 : : return -EINVAL;
513 : : max_name_len = sizeof("fm.-mac..") - 1;
514 : : }
515 : :
516 [ # # ]: 0 : if (out != NULL) {
517 : : char *out_name = out;
518 : :
519 : : /* Do not check for truncation, either name ends with
520 : : * '\0' or the device name is followed by parameters and there
521 : : * will be a ',' instead. Not copying past this comma is not an
522 : : * error.
523 : : */
524 [ # # ]: 0 : strlcpy(out_name, &name[delta], max_name_len + 1);
525 : :
526 : : /* Second digit of mac%u could instead be ','. */
527 [ # # ]: 0 : if ((strlen(out_name) == max_name_len) &&
528 [ # # ]: 0 : out_name[max_name_len] == ',')
529 : 0 : out_name[max_name_len] = '\0';
530 : : }
531 : :
532 : : return 0;
533 : : }
534 : :
535 : : static int
536 : 0 : dpaa_bus_dev_compare(const char *name1, const char *name2)
537 : : {
538 : : char devname1[32], devname2[32];
539 : :
540 [ # # # # ]: 0 : if (rte_dpaa_bus_parse(name1, devname1) != 0 ||
541 : 0 : rte_dpaa_bus_parse(name2, devname2) != 0)
542 : 0 : return 1;
543 : :
544 : 0 : return strncmp(devname1, devname2, sizeof(devname1));
545 : : }
546 : :
547 : : /* register a dpaa bus based dpaa driver */
548 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_driver_register)
549 : : void
550 : 918 : rte_dpaa_driver_register(struct rte_dpaa_driver *driver)
551 : : {
552 [ - + ]: 918 : RTE_VERIFY(driver);
553 [ - + ]: 918 : RTE_VERIFY(driver->probe != NULL);
554 : :
555 : 918 : BUS_INIT_FUNC_TRACE();
556 : :
557 : 918 : rte_bus_add_driver(&rte_dpaa_bus, &driver->driver);
558 : 918 : }
559 : :
560 : : /* un-register a dpaa bus based dpaa driver */
561 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_driver_unregister)
562 : : void
563 : 0 : rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver)
564 : : {
565 : 0 : BUS_INIT_FUNC_TRACE();
566 : :
567 : 0 : rte_bus_remove_driver(&rte_dpaa_bus, &driver->driver);
568 : 0 : }
569 : :
570 : : static bool
571 : 0 : dpaa_bus_match(const struct rte_driver *drv, const struct rte_device *dev)
572 : : {
573 : : const struct rte_dpaa_driver *dpaa_drv = RTE_BUS_DRIVER(drv, *dpaa_drv);
574 : : const struct rte_dpaa_device *dpaa_dev = RTE_BUS_DEVICE(dev, *dpaa_dev);
575 : :
576 [ # # ]: 0 : if (dpaa_drv->drv_type == dpaa_dev->device_type)
577 : 0 : return true;
578 : :
579 : : return false;
580 : : }
581 : :
582 : : static int
583 : 0 : rte_dpaa_bus_dev_build(void)
584 : : {
585 : : int ret;
586 : :
587 : : /* Load the device-tree driver */
588 : : ret = of_init();
589 [ # # ]: 0 : if (ret) {
590 : 0 : DPAA_BUS_ERR("Failed(%d) to init device tree", ret);
591 : 0 : return ret;
592 : : }
593 : :
594 : : /* Get the interface configurations from device-tree */
595 : 0 : dpaa_netcfg = netcfg_acquire();
596 [ # # ]: 0 : if (!dpaa_netcfg) {
597 : 0 : DPAA_BUS_ERR("netcfg failed: /dev/fsl_usdpaa device not available");
598 : 0 : DPAA_BUS_WARN("Check if you are using USDPAA based device tree");
599 : 0 : return -EINVAL;
600 : : }
601 : :
602 : 0 : DPAA_BUS_NOTICE("DPAA Bus Detected");
603 : :
604 [ # # ]: 0 : if (!dpaa_netcfg->num_ethports) {
605 : 0 : DPAA_BUS_INFO("NO DPDK mapped net interfaces available");
606 : : /* This is not an error */
607 : : }
608 : :
609 : : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
610 : : dump_netcfg(dpaa_netcfg, stdout);
611 : : #endif
612 : :
613 : 0 : DPAA_BUS_DEBUG("Number of ethernet devices = %d",
614 : : dpaa_netcfg->num_ethports);
615 : 0 : ret = dpaa_create_device_list();
616 [ # # ]: 0 : if (ret) {
617 : 0 : DPAA_BUS_ERR("Unable to create device list. (%d)", ret);
618 : 0 : return ret;
619 : : }
620 : : return 0;
621 : : }
622 : :
623 : : static int
624 : 0 : dpaa_setup_intr(struct rte_intr_handle *intr_handle)
625 : : {
626 : : int fd;
627 : :
628 : 0 : fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
629 [ # # ]: 0 : if (fd < 0) {
630 : 0 : DPAA_BUS_ERR("Cannot set up eventfd, error %i (%s)",
631 : : errno, strerror(errno));
632 : 0 : return -errno;
633 : : }
634 : :
635 [ # # # # ]: 0 : if (rte_intr_fd_set(intr_handle, fd) ||
636 : 0 : rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_EXT)) {
637 : 0 : int err = -rte_errno;
638 : :
639 : 0 : close(fd);
640 : 0 : rte_intr_fd_set(intr_handle, -1);
641 : 0 : return err;
642 : : }
643 : :
644 : : return 0;
645 : : }
646 : :
647 : :
648 : : static int
649 : 230 : rte_dpaa_bus_scan(void)
650 : : {
651 : : FILE *svr_file = NULL;
652 : : uint32_t svr_ver;
653 : : static int process_once;
654 : : char *penv;
655 : : int ret;
656 : :
657 : 230 : BUS_INIT_FUNC_TRACE();
658 : :
659 [ + - + - ]: 460 : if ((access(DPAA_DEV_PATH1, F_OK) != 0) &&
660 : 230 : (access(DPAA_DEV_PATH2, F_OK) != 0)) {
661 : 230 : DPAA_BUS_DEBUG("DPAA Bus not present. Skipping.");
662 : 230 : return 0;
663 : : }
664 : :
665 [ # # ]: 0 : if (dpaa_bus.detected)
666 : : return 0;
667 : :
668 : 0 : dpaa_bus.detected = 1;
669 : :
670 : : /* create the key, supplying a function that'll be invoked
671 : : * when a portal affined thread will be deleted.
672 : : */
673 : 0 : ret = pthread_key_create(&dpaa_portal_key, dpaa_portal_finish);
674 [ # # ]: 0 : if (ret) {
675 : 0 : DPAA_BUS_DEBUG("Unable to create pthread key. (%d)", ret);
676 : 0 : return ret;
677 : : }
678 : :
679 : : /* SoC version detection and configuration */
680 : 0 : svr_file = fopen(DPAA_SOC_ID_FILE, "r");
681 [ # # ]: 0 : if (svr_file) {
682 [ # # ]: 0 : if (fscanf(svr_file, "svr:%x", &svr_ver) > 0)
683 : 0 : dpaa_bus.svr_ver = svr_ver & DPAA_SVR_MASK;
684 : : else
685 : 0 : dpaa_bus.svr_ver = 0;
686 : 0 : fclose(svr_file);
687 : : } else {
688 : 0 : dpaa_bus.svr_ver = 0;
689 : : }
690 [ # # ]: 0 : if (dpaa_bus.svr_ver == SVR_LS1046A_FAMILY) {
691 : 0 : DPAA_BUS_INFO("This is LS1046A family SoC.");
692 [ # # ]: 0 : } else if (dpaa_bus.svr_ver == SVR_LS1043A_FAMILY) {
693 : 0 : DPAA_BUS_INFO("This is LS1043A family SoC.");
694 : : } else {
695 : 0 : DPAA_BUS_WARN("This is Unknown(%08x) DPAA1 family SoC.",
696 : : dpaa_bus.svr_ver);
697 : : }
698 : :
699 : : /* Disabling the default push mode for LS1043A due to errata */
700 [ # # ]: 0 : if (dpaa_bus.svr_ver == SVR_LS1043A_FAMILY) {
701 : 0 : dpaa_bus.max_push_rxq_num = 0;
702 : : } else {
703 : 0 : penv = getenv("DPAA_PUSH_QUEUES_NUMBER");
704 [ # # ]: 0 : if (penv)
705 : 0 : dpaa_bus.max_push_rxq_num = atoi(penv);
706 [ # # ]: 0 : if (dpaa_bus.max_push_rxq_num > DPAA_MAX_PUSH_MODE_QUEUE)
707 : 0 : dpaa_bus.max_push_rxq_num = DPAA_MAX_PUSH_MODE_QUEUE;
708 : : }
709 : :
710 : : /* Device list creation is only done once */
711 [ # # ]: 0 : if (!process_once) {
712 : 0 : rte_dpaa_bus_dev_build();
713 : : /* One time load of Qman/Bman drivers */
714 : 0 : ret = qman_global_init();
715 [ # # ]: 0 : if (ret) {
716 : 0 : DPAA_BUS_ERR("QMAN initialization failed: %d",
717 : : ret);
718 : 0 : return ret;
719 : : }
720 : 0 : ret = bman_global_init();
721 [ # # ]: 0 : if (ret) {
722 : 0 : DPAA_BUS_ERR("BMAN initialization failed: %d",
723 : : ret);
724 : 0 : return ret;
725 : : }
726 : : }
727 : 0 : process_once = 1;
728 : :
729 : : /* If no device present on DPAA bus nothing needs to be done */
730 [ # # ]: 0 : if (TAILQ_EMPTY(&rte_dpaa_bus.device_list))
731 : : return 0;
732 : :
733 : : /* Register DPAA mempool ops only if any DPAA device has
734 : : * been detected.
735 : : */
736 : 0 : rte_mbuf_set_platform_mempool_ops(DPAA_MEMPOOL_OPS_NAME);
737 : :
738 : : /* And initialize the PA->VA translation table */
739 : 0 : dpaax_iova_table_populate();
740 : :
741 : 0 : dpaa_bus_global_init = 1;
742 : 0 : return 0;
743 : : }
744 : :
745 : : /*
746 : : * Get iommu class of DPAA2 devices on the bus.
747 : : */
748 : : static enum rte_iova_mode
749 : 230 : rte_dpaa_get_iommu_class(void)
750 : : {
751 [ + - + - ]: 460 : if ((access(DPAA_DEV_PATH1, F_OK) != 0) &&
752 : 230 : (access(DPAA_DEV_PATH2, F_OK) != 0)) {
753 : 230 : return RTE_IOVA_DC;
754 : : }
755 : : return RTE_IOVA_PA;
756 : : }
757 : :
758 : : static int
759 : 0 : dpaa_bus_probe_device(struct rte_driver *drv, struct rte_device *dev)
760 : : {
761 : : struct rte_dpaa_device *dpaa_dev = RTE_BUS_DEVICE(dev, *dpaa_dev);
762 : : struct rte_dpaa_driver *dpaa_drv = RTE_BUS_DRIVER(drv, *dpaa_drv);
763 : : int ret;
764 : :
765 : : /* Allocate interrupt handle instance */
766 : 0 : dpaa_dev->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
767 [ # # ]: 0 : if (dpaa_dev->intr_handle == NULL) {
768 : 0 : DPAA_BUS_ERR("Failed to allocate intr handle");
769 : 0 : return -ENOMEM;
770 : : }
771 : :
772 [ # # ]: 0 : if (dpaa_dev->device_type == FSL_DPAA_ETH) {
773 : 0 : ret = dpaa_setup_intr(dpaa_dev->intr_handle);
774 [ # # ]: 0 : if (ret != 0) {
775 : 0 : DPAA_BUS_ERR("error setting up interrupt: %s", dpaa_dev->name);
776 : 0 : goto release_intr;
777 : : }
778 : : }
779 : :
780 : 0 : ret = dpaa_drv->probe(dpaa_drv, dpaa_dev);
781 : : /* A positive return means the driver declined the device. */
782 [ # # ]: 0 : if (ret < 0) {
783 : 0 : DPAA_BUS_ERR("unable to probe: %s", dpaa_dev->name);
784 : 0 : rte_intr_fd_close(dpaa_dev->intr_handle);
785 : 0 : release_intr:
786 : 0 : rte_intr_instance_free(dpaa_dev->intr_handle);
787 : 0 : dpaa_dev->intr_handle = NULL;
788 : : }
789 : : return ret;
790 : : }
791 : :
792 : : static int
793 : 0 : dpaa_bus_unplug_device(struct rte_device *rte_dev)
794 : : {
795 : 0 : const struct rte_dpaa_driver *drv = RTE_BUS_DRIVER(rte_dev->driver, *drv);
796 : : struct rte_dpaa_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
797 : :
798 [ # # ]: 0 : if (drv->remove != NULL) {
799 : : int ret;
800 : :
801 : 0 : ret = drv->remove(dev);
802 [ # # ]: 0 : if (ret < 0)
803 : : return ret;
804 : : }
805 : :
806 : 0 : rte_intr_fd_close(dev->intr_handle);
807 : 0 : rte_intr_instance_free(dev->intr_handle);
808 : 0 : dev->intr_handle = NULL;
809 : :
810 : 0 : return 0;
811 : : }
812 : :
813 : : static void
814 : 0 : dpaa_bus_free_device(struct rte_device *dev)
815 : : {
816 : 0 : free(RTE_BUS_DEVICE(dev, struct rte_dpaa_device));
817 : 0 : }
818 : :
819 : : static int
820 : 299 : dpaa_bus_cleanup(struct rte_bus *bus)
821 : : {
822 : : int ret;
823 : :
824 : 299 : BUS_INIT_FUNC_TRACE();
825 : :
826 : 299 : ret = rte_bus_generic_cleanup(bus);
827 : :
828 : 299 : dpaa_portal_finish((void *)DPAA_PER_LCORE_PORTAL);
829 : 299 : dpaa_bus_global_init = 0;
830 : 299 : DPAA_BUS_DEBUG("Bus cleanup done");
831 : :
832 : 299 : return ret;
833 : : }
834 : :
835 : : /* Adding destructor for double check in case non-gracefully
836 : : * exit.
837 : : */
838 : 306 : RTE_FINI_PRIO(dpaa_cleanup, 102)
839 : : {
840 : : unsigned int lcore_id;
841 : :
842 [ - + ]: 306 : if (!dpaa_bus_global_init)
843 : : return;
844 : :
845 : : /* cleanup portals in case non-graceful exit */
846 [ # # ]: 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
847 : : /* Check for non zero id */
848 : 0 : dpaa_portal_finish((void *)dpaa_portals[lcore_id]);
849 : : }
850 : 0 : dpaa_portal_finish((void *)DPAA_PER_LCORE_PORTAL);
851 : 0 : dpaa_bus_global_init = 0;
852 : 0 : DPAA_BUS_DEBUG("Worker thread clean up done");
853 : : }
854 : :
855 : : static struct rte_bus rte_dpaa_bus = {
856 : : .scan = rte_dpaa_bus_scan,
857 : : .probe = rte_bus_generic_probe,
858 : : .free_device = dpaa_bus_free_device,
859 : : .cleanup = dpaa_bus_cleanup,
860 : : .parse = rte_dpaa_bus_parse,
861 : : .dev_compare = dpaa_bus_dev_compare,
862 : : .find_device = rte_bus_generic_find_device,
863 : : .get_iommu_class = rte_dpaa_get_iommu_class,
864 : : .match = dpaa_bus_match,
865 : : .probe_device = dpaa_bus_probe_device,
866 : : .unplug_device = dpaa_bus_unplug_device,
867 : : .dev_iterate = rte_bus_generic_dev_iterate,
868 : : };
869 : :
870 : : static struct rte_dpaa_bus_private dpaa_bus = {
871 : : .max_push_rxq_num = DPAA_DEFAULT_PUSH_MODE_QUEUE,
872 : : .device_count = 0,
873 : : };
874 : :
875 : 306 : RTE_REGISTER_BUS(dpaa_bus, rte_dpaa_bus);
876 [ - + ]: 306 : RTE_LOG_REGISTER_DEFAULT(dpaa_logtype_bus, NOTICE);
|