Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright 2021 NXP
4 : : *
5 : : */
6 : :
7 : : #include <unistd.h>
8 : : #include <stdio.h>
9 : : #include <sys/types.h>
10 : : #include <errno.h>
11 : :
12 : : #include <rte_malloc.h>
13 : : #include <dev_driver.h>
14 : :
15 : : #include "private.h"
16 : : #include <fslmc_logs.h>
17 : : #include <mc/fsl_dprc.h>
18 : : #include "portal/dpaa2_hw_pvt.h"
19 : :
20 : : TAILQ_HEAD(dprc_dev_list, dpaa2_dprc_dev);
21 : : static struct dprc_dev_list dprc_dev_list
22 : : = TAILQ_HEAD_INITIALIZER(dprc_dev_list); /*!< DPRC device list */
23 : :
24 : : static int
25 : 0 : rte_dpaa2_create_dprc_device(int vdev_fd __rte_unused,
26 : : struct vfio_device_info *obj_info __rte_unused,
27 : : int dprc_id)
28 : : {
29 : : struct dpaa2_dprc_dev *dprc_node;
30 : : struct dprc_endpoint endpoint1, endpoint2;
31 : : struct rte_dpaa2_device *dev, *dev_tmp;
32 : : int ret;
33 : :
34 : : /* Allocate DPAA2 dprc handle */
35 : 0 : dprc_node = rte_malloc(NULL, sizeof(struct dpaa2_dprc_dev), 0);
36 [ # # ]: 0 : if (!dprc_node) {
37 : 0 : DPAA2_BUS_ERR("Memory allocation failed for DPRC Device");
38 : 0 : return -ENOMEM;
39 : : }
40 : :
41 : : /* Open the dprc object */
42 : 0 : dprc_node->dprc.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
43 : 0 : dprc_node->dprc_id = dprc_id;
44 : 0 : ret = dprc_open(&dprc_node->dprc,
45 : : CMD_PRI_LOW, dprc_id, &dprc_node->token);
46 [ # # ]: 0 : if (ret) {
47 : 0 : DPAA2_BUS_ERR("Resource alloc failure with err code: %d", ret);
48 : 0 : rte_free(dprc_node);
49 : 0 : return ret;
50 : : }
51 : :
52 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_tmp) {
53 [ # # ]: 0 : if (dev->dev_type == DPAA2_ETH) {
54 : : int link_state;
55 : :
56 : : memset(&endpoint1, 0, sizeof(struct dprc_endpoint));
57 : : memset(&endpoint2, 0, sizeof(struct dprc_endpoint));
58 : : strcpy(endpoint1.type, "dpni");
59 : 0 : endpoint1.id = dev->object_id;
60 : 0 : ret = dprc_get_connection(&dprc_node->dprc,
61 : : CMD_PRI_LOW,
62 : 0 : dprc_node->token,
63 : : &endpoint1, &endpoint2,
64 : : &link_state);
65 [ # # ]: 0 : if (ret) {
66 : 0 : DPAA2_BUS_ERR("dpni.%d connection failed!",
67 : : dev->object_id);
68 : 0 : dprc_close(&dprc_node->dprc, CMD_PRI_LOW,
69 : 0 : dprc_node->token);
70 : 0 : rte_free(dprc_node);
71 : 0 : return ret;
72 : : }
73 : :
74 [ # # ]: 0 : if (!strcmp(endpoint2.type, "dpmac"))
75 : 0 : dev->ep_dev_type = DPAA2_MAC;
76 [ # # ]: 0 : else if (!strcmp(endpoint2.type, "dpni"))
77 : 0 : dev->ep_dev_type = DPAA2_ETH;
78 [ # # ]: 0 : else if (!strcmp(endpoint2.type, "dpdmux"))
79 : 0 : dev->ep_dev_type = DPAA2_MUX;
80 : : else
81 : 0 : dev->ep_dev_type = DPAA2_UNKNOWN;
82 : :
83 : 0 : dev->ep_object_id = endpoint2.id;
84 : : } else {
85 : 0 : dev->ep_dev_type = DPAA2_UNKNOWN;
86 : : }
87 : 0 : sprintf(dev->ep_name, "%s.%d", endpoint2.type, endpoint2.id);
88 : : }
89 : :
90 : 0 : TAILQ_INSERT_TAIL(&dprc_dev_list, dprc_node, next);
91 : :
92 : 0 : return 0;
93 : : }
94 : :
95 : : static struct rte_dpaa2_object rte_dpaa2_dprc_obj = {
96 : : .dev_type = DPAA2_DPRC,
97 : : .create = rte_dpaa2_create_dprc_device,
98 : : };
99 : :
100 : 238 : RTE_PMD_REGISTER_DPAA2_OBJECT(dprc, rte_dpaa2_dprc_obj);
|