6fa0c3d63102c19ec54a4c2b002ea71e99a80e8a
[dpdk.git] / drivers / bus / dpaa / rte_dpaa_bus.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017 NXP
4  *
5  */
6 #ifndef __RTE_DPAA_BUS_H__
7 #define __RTE_DPAA_BUS_H__
8
9 #include <rte_bus.h>
10 #include <rte_mempool.h>
11
12 #include <fsl_usd.h>
13 #include <fsl_qman.h>
14 #include <fsl_bman.h>
15 #include <of.h>
16 #include <netcfg.h>
17
18 #define FSL_DPAA_BUS_NAME       "FSL_DPAA_BUS"
19
20 #define DEV_TO_DPAA_DEVICE(ptr) \
21                 container_of(ptr, struct rte_dpaa_device, device)
22
23 /* DPAA SoC identifier; If this is not available, it can be concluded
24  * that board is non-DPAA. Single slot is currently supported.
25  */
26 #define DPAA_SOC_ID_FILE        "/sys/devices/soc0/soc_id"
27
28 #define SVR_LS1043A_FAMILY      0x87920000
29 #define SVR_LS1046A_FAMILY      0x87070000
30 #define SVR_MASK                0xffff0000
31
32 extern unsigned int dpaa_svr_family;
33
34 struct rte_dpaa_device;
35 struct rte_dpaa_driver;
36
37 /* DPAA Device and Driver lists for DPAA bus */
38 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
39 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
40
41 /* Configuration variables exported from DPAA bus */
42 extern struct netcfg_info *dpaa_netcfg;
43
44 enum rte_dpaa_type {
45         FSL_DPAA_ETH = 1,
46         FSL_DPAA_CRYPTO,
47 };
48
49 struct rte_dpaa_bus {
50         struct rte_bus bus;
51         struct rte_dpaa_device_list device_list;
52         struct rte_dpaa_driver_list driver_list;
53         int device_count;
54 };
55
56 struct dpaa_device_id {
57         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
58         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
59         uint16_t dev_id; /**< Device Identifier from DPDK */
60 };
61
62 struct rte_dpaa_device {
63         TAILQ_ENTRY(rte_dpaa_device) next;
64         struct rte_device device;
65         union {
66                 struct rte_eth_dev *eth_dev;
67                 struct rte_cryptodev *crypto_dev;
68         };
69         struct rte_dpaa_driver *driver;
70         struct dpaa_device_id id;
71         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
72         char name[RTE_ETH_NAME_MAX_LEN];
73 };
74
75 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
76                                 struct rte_dpaa_device *dpaa_dev);
77 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
78
79 struct rte_dpaa_driver {
80         TAILQ_ENTRY(rte_dpaa_driver) next;
81         struct rte_driver driver;
82         struct rte_dpaa_bus *dpaa_bus;
83         enum rte_dpaa_type drv_type;
84         rte_dpaa_probe_t probe;
85         rte_dpaa_remove_t remove;
86 };
87
88 struct dpaa_portal {
89         uint32_t bman_idx; /**< BMAN Portal ID*/
90         uint32_t qman_idx; /**< QMAN Portal ID*/
91         uint64_t tid;/**< Parent Thread id for this portal */
92 };
93
94 /* TODO - this is costly, need to write a fast coversion routine */
95 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
96 {
97         const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
98         int i;
99
100         for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr != NULL; i++) {
101                 if (paddr >= memseg[i].iova && paddr <
102                         memseg[i].iova + memseg[i].len)
103                         return (uint8_t *)(memseg[i].addr) +
104                                (paddr - memseg[i].iova);
105         }
106
107         return NULL;
108 }
109
110 /**
111  * Register a DPAA driver.
112  *
113  * @param driver
114  *   A pointer to a rte_dpaa_driver structure describing the driver
115  *   to be registered.
116  */
117 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
118
119 /**
120  * Unregister a DPAA driver.
121  *
122  * @param driver
123  *      A pointer to a rte_dpaa_driver structure describing the driver
124  *      to be unregistered.
125  */
126 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
127
128 /**
129  * Initialize a DPAA portal
130  *
131  * @param arg
132  *      Per thread ID
133  *
134  * @return
135  *      0 in case of success, error otherwise
136  */
137 int rte_dpaa_portal_init(void *arg);
138
139 int rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq);
140
141 int rte_dpaa_portal_fq_close(struct qman_fq *fq);
142
143 /**
144  * Cleanup a DPAA Portal
145  */
146 void dpaa_portal_finish(void *arg);
147
148 /** Helper for DPAA device registration from driver (eth, crypto) instance */
149 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
150 RTE_INIT(dpaainitfn_ ##nm); \
151 static void dpaainitfn_ ##nm(void) \
152 {\
153         (dpaa_drv).driver.name = RTE_STR(nm);\
154         rte_dpaa_driver_register(&dpaa_drv); \
155 } \
156 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
157
158 /* Create storage for dqrr entries per lcore */
159 #define DPAA_PORTAL_DEQUEUE_DEPTH       16
160 struct dpaa_portal_dqrr {
161         void *mbuf[DPAA_PORTAL_DEQUEUE_DEPTH];
162         uint64_t dqrr_held;
163         uint8_t dqrr_size;
164 };
165
166 RTE_DECLARE_PER_LCORE(struct dpaa_portal_dqrr, held_bufs);
167
168 #define DPAA_PER_LCORE_DQRR_SIZE       RTE_PER_LCORE(held_bufs).dqrr_size
169 #define DPAA_PER_LCORE_DQRR_HELD       RTE_PER_LCORE(held_bufs).dqrr_held
170 #define DPAA_PER_LCORE_DQRR_MBUF(i)    RTE_PER_LCORE(held_bufs).mbuf[i]
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif /* __RTE_DPAA_BUS_H__ */