bus/dpaa: mark internal symbols
[dpdk.git] / drivers / bus / dpaa / rte_dpaa_bus.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017-2019 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 #include <dpaax_iova_table.h>
12
13 #include <dpaa_of.h>
14 #include <fsl_usd.h>
15 #include <fsl_qman.h>
16 #include <fsl_bman.h>
17 #include <netcfg.h>
18
19 #define DPAA_MEMPOOL_OPS_NAME   "dpaa"
20
21 #define DEV_TO_DPAA_DEVICE(ptr) \
22                 container_of(ptr, struct rte_dpaa_device, device)
23
24 /* DPAA SoC identifier; If this is not available, it can be concluded
25  * that board is non-DPAA. Single slot is currently supported.
26  */
27 #define DPAA_SOC_ID_FILE        "/sys/devices/soc0/soc_id"
28
29 #define SVR_LS1043A_FAMILY      0x87920000
30 #define SVR_LS1046A_FAMILY      0x87070000
31 #define SVR_MASK                0xffff0000
32
33 #define RTE_DEV_TO_DPAA_CONST(ptr) \
34         container_of(ptr, const struct rte_dpaa_device, device)
35
36 extern unsigned int dpaa_svr_family;
37
38 extern RTE_DEFINE_PER_LCORE(bool, dpaa_io);
39
40 struct rte_dpaa_device;
41 struct rte_dpaa_driver;
42
43 /* DPAA Device and Driver lists for DPAA bus */
44 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
45 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
46
47 /* Configuration variables exported from DPAA bus */
48 extern struct netcfg_info *dpaa_netcfg;
49
50 enum rte_dpaa_type {
51         FSL_DPAA_ETH = 1,
52         FSL_DPAA_CRYPTO,
53 };
54
55 struct rte_dpaa_bus {
56         struct rte_bus bus;
57         struct rte_dpaa_device_list device_list;
58         struct rte_dpaa_driver_list driver_list;
59         int device_count;
60         int detected;
61 };
62
63 struct dpaa_device_id {
64         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
65         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
66         uint16_t dev_id; /**< Device Identifier from DPDK */
67 };
68
69 struct rte_dpaa_device {
70         TAILQ_ENTRY(rte_dpaa_device) next;
71         struct rte_device device;
72         union {
73                 struct rte_eth_dev *eth_dev;
74                 struct rte_cryptodev *crypto_dev;
75         };
76         struct rte_dpaa_driver *driver;
77         struct dpaa_device_id id;
78         struct rte_intr_handle intr_handle;
79         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
80         char name[RTE_ETH_NAME_MAX_LEN];
81 };
82
83 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
84                                 struct rte_dpaa_device *dpaa_dev);
85 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
86
87 struct rte_dpaa_driver {
88         TAILQ_ENTRY(rte_dpaa_driver) next;
89         struct rte_driver driver;
90         struct rte_dpaa_bus *dpaa_bus;
91         enum rte_dpaa_type drv_type;
92         rte_dpaa_probe_t probe;
93         rte_dpaa_remove_t remove;
94 };
95
96 struct dpaa_portal {
97         uint32_t bman_idx; /**< BMAN Portal ID*/
98         uint32_t qman_idx; /**< QMAN Portal ID*/
99         uint64_t tid;/**< Parent Thread id for this portal */
100 };
101
102 /* Various structures representing contiguous memory maps */
103 struct dpaa_memseg {
104         TAILQ_ENTRY(dpaa_memseg) next;
105         char *vaddr;
106         rte_iova_t iova;
107         size_t len;
108 };
109
110 TAILQ_HEAD(dpaa_memseg_list, dpaa_memseg);
111 extern struct dpaa_memseg_list rte_dpaa_memsegs;
112
113 /* Either iterate over the list of internal memseg references or fallback to
114  * EAL memseg based iova2virt.
115  */
116 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
117 {
118         struct dpaa_memseg *ms;
119         void *va;
120
121         va = dpaax_iova_table_get_va(paddr);
122         if (likely(va != NULL))
123                 return va;
124
125         /* Check if the address is already part of the memseg list internally
126          * maintained by the dpaa driver.
127          */
128         TAILQ_FOREACH(ms, &rte_dpaa_memsegs, next) {
129                 if (paddr >= ms->iova && paddr <
130                         ms->iova + ms->len)
131                         return RTE_PTR_ADD(ms->vaddr, (uintptr_t)(paddr - ms->iova));
132         }
133
134         /* If not, Fallback to full memseg list searching */
135         va = rte_mem_iova2virt(paddr);
136
137         dpaax_iova_table_update(paddr, va, RTE_CACHE_LINE_SIZE);
138
139         return va;
140 }
141
142 static inline rte_iova_t
143 rte_dpaa_mem_vtop(void *vaddr)
144 {
145         const struct rte_memseg *ms;
146
147         ms = rte_mem_virt2memseg(vaddr, NULL);
148         if (ms)
149                 return ms->iova + RTE_PTR_DIFF(vaddr, ms->addr);
150
151         return (size_t)NULL;
152 }
153
154 /**
155  * Register a DPAA driver.
156  *
157  * @param driver
158  *   A pointer to a rte_dpaa_driver structure describing the driver
159  *   to be registered.
160  */
161 __rte_internal
162 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
163
164 /**
165  * Unregister a DPAA driver.
166  *
167  * @param driver
168  *      A pointer to a rte_dpaa_driver structure describing the driver
169  *      to be unregistered.
170  */
171 __rte_internal
172 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
173
174 /**
175  * Initialize a DPAA portal
176  *
177  * @param arg
178  *      Per thread ID
179  *
180  * @return
181  *      0 in case of success, error otherwise
182  */
183 __rte_internal
184 int rte_dpaa_portal_init(void *arg);
185
186 __rte_internal
187 int rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq);
188
189 __rte_internal
190 int rte_dpaa_portal_fq_close(struct qman_fq *fq);
191
192 /**
193  * Cleanup a DPAA Portal
194  */
195 void dpaa_portal_finish(void *arg);
196
197 /** Helper for DPAA device registration from driver (eth, crypto) instance */
198 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
199 RTE_INIT(dpaainitfn_ ##nm) \
200 {\
201         (dpaa_drv).driver.name = RTE_STR(nm);\
202         rte_dpaa_driver_register(&dpaa_drv); \
203 } \
204 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
205
206 /* Create storage for dqrr entries per lcore */
207 #define DPAA_PORTAL_DEQUEUE_DEPTH       16
208 struct dpaa_portal_dqrr {
209         void *mbuf[DPAA_PORTAL_DEQUEUE_DEPTH];
210         uint64_t dqrr_held;
211         uint8_t dqrr_size;
212 };
213
214 RTE_DECLARE_PER_LCORE(struct dpaa_portal_dqrr, held_bufs);
215
216 #define DPAA_PER_LCORE_DQRR_SIZE       RTE_PER_LCORE(held_bufs).dqrr_size
217 #define DPAA_PER_LCORE_DQRR_HELD       RTE_PER_LCORE(held_bufs).dqrr_held
218 #define DPAA_PER_LCORE_DQRR_MBUF(i)    RTE_PER_LCORE(held_bufs).mbuf[i]
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif /* __RTE_DPAA_BUS_H__ */