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