drivers/dpaa: optimize thread local storage
[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 struct rte_dpaa_device;
39 struct rte_dpaa_driver;
40
41 /* DPAA Device and Driver lists for DPAA bus */
42 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
43 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
44
45 enum rte_dpaa_type {
46         FSL_DPAA_ETH = 1,
47         FSL_DPAA_CRYPTO,
48 };
49
50 struct rte_dpaa_bus {
51         struct rte_bus bus;
52         struct rte_dpaa_device_list device_list;
53         struct rte_dpaa_driver_list driver_list;
54         int device_count;
55         int detected;
56 };
57
58 struct dpaa_device_id {
59         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
60         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
61         uint16_t dev_id; /**< Device Identifier from DPDK */
62 };
63
64 struct rte_dpaa_device {
65         TAILQ_ENTRY(rte_dpaa_device) next;
66         struct rte_device device;
67         union {
68                 struct rte_eth_dev *eth_dev;
69                 struct rte_cryptodev *crypto_dev;
70         };
71         struct rte_dpaa_driver *driver;
72         struct dpaa_device_id id;
73         struct rte_intr_handle intr_handle;
74         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
75         char name[RTE_ETH_NAME_MAX_LEN];
76 };
77
78 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
79                                 struct rte_dpaa_device *dpaa_dev);
80 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
81
82 struct rte_dpaa_driver {
83         TAILQ_ENTRY(rte_dpaa_driver) next;
84         struct rte_driver driver;
85         struct rte_dpaa_bus *dpaa_bus;
86         enum rte_dpaa_type drv_type;
87         rte_dpaa_probe_t probe;
88         rte_dpaa_remove_t remove;
89 };
90
91 /* Create storage for dqrr entries per lcore */
92 #define DPAA_PORTAL_DEQUEUE_DEPTH       16
93 struct dpaa_portal_dqrr {
94         void *mbuf[DPAA_PORTAL_DEQUEUE_DEPTH];
95         uint64_t dqrr_held;
96         uint8_t dqrr_size;
97 };
98
99 struct dpaa_portal {
100         uint32_t bman_idx; /**< BMAN Portal ID*/
101         uint32_t qman_idx; /**< QMAN Portal ID*/
102         struct dpaa_portal_dqrr dpaa_held_bufs;
103         struct rte_crypto_op **dpaa_sec_ops;
104         int dpaa_sec_op_nb;
105         uint64_t tid;/**< Parent Thread id for this portal */
106 };
107
108 RTE_DECLARE_PER_LCORE(struct dpaa_portal *, dpaa_io);
109
110 #define DPAA_PER_LCORE_PORTAL \
111         RTE_PER_LCORE(dpaa_io)
112 #define DPAA_PER_LCORE_DQRR_SIZE \
113         RTE_PER_LCORE(dpaa_io)->dpaa_held_bufs.dqrr_size
114 #define DPAA_PER_LCORE_DQRR_HELD \
115         RTE_PER_LCORE(dpaa_io)->dpaa_held_bufs.dqrr_held
116 #define DPAA_PER_LCORE_DQRR_MBUF(i) \
117         RTE_PER_LCORE(dpaa_io)->dpaa_held_bufs.mbuf[i]
118 #define DPAA_PER_LCORE_RTE_CRYPTO_OP \
119         RTE_PER_LCORE(dpaa_io)->dpaa_sec_ops
120 #define DPAA_PER_LCORE_DPAA_SEC_OP_NB \
121         RTE_PER_LCORE(dpaa_io)->dpaa_sec_op_nb
122
123 /* Various structures representing contiguous memory maps */
124 struct dpaa_memseg {
125         TAILQ_ENTRY(dpaa_memseg) next;
126         char *vaddr;
127         rte_iova_t iova;
128         size_t len;
129 };
130
131 TAILQ_HEAD(dpaa_memseg_list, dpaa_memseg);
132 extern struct dpaa_memseg_list rte_dpaa_memsegs;
133
134 /* Either iterate over the list of internal memseg references or fallback to
135  * EAL memseg based iova2virt.
136  */
137 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
138 {
139         struct dpaa_memseg *ms;
140         void *va;
141
142         va = dpaax_iova_table_get_va(paddr);
143         if (likely(va != NULL))
144                 return va;
145
146         /* Check if the address is already part of the memseg list internally
147          * maintained by the dpaa driver.
148          */
149         TAILQ_FOREACH(ms, &rte_dpaa_memsegs, next) {
150                 if (paddr >= ms->iova && paddr <
151                         ms->iova + ms->len)
152                         return RTE_PTR_ADD(ms->vaddr, (uintptr_t)(paddr - ms->iova));
153         }
154
155         /* If not, Fallback to full memseg list searching */
156         va = rte_mem_iova2virt(paddr);
157
158         dpaax_iova_table_update(paddr, va, RTE_CACHE_LINE_SIZE);
159
160         return va;
161 }
162
163 static inline rte_iova_t
164 rte_dpaa_mem_vtop(void *vaddr)
165 {
166         const struct rte_memseg *ms;
167
168         ms = rte_mem_virt2memseg(vaddr, NULL);
169         if (ms)
170                 return ms->iova + RTE_PTR_DIFF(vaddr, ms->addr);
171
172         return (size_t)NULL;
173 }
174
175 /**
176  * Register a DPAA driver.
177  *
178  * @param driver
179  *   A pointer to a rte_dpaa_driver structure describing the driver
180  *   to be registered.
181  */
182 __rte_internal
183 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
184
185 /**
186  * Unregister a DPAA driver.
187  *
188  * @param driver
189  *      A pointer to a rte_dpaa_driver structure describing the driver
190  *      to be unregistered.
191  */
192 __rte_internal
193 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
194
195 /**
196  * Initialize a DPAA portal
197  *
198  * @param arg
199  *      Per thread ID
200  *
201  * @return
202  *      0 in case of success, error otherwise
203  */
204 __rte_internal
205 int rte_dpaa_portal_init(void *arg);
206
207 __rte_internal
208 int rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq);
209
210 __rte_internal
211 int rte_dpaa_portal_fq_close(struct qman_fq *fq);
212
213 /**
214  * Cleanup a DPAA Portal
215  */
216 void dpaa_portal_finish(void *arg);
217
218 /** Helper for DPAA device registration from driver (eth, crypto) instance */
219 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
220 RTE_INIT(dpaainitfn_ ##nm) \
221 {\
222         (dpaa_drv).driver.name = RTE_STR(nm);\
223         rte_dpaa_driver_register(&dpaa_drv); \
224 } \
225 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
226
227 __rte_internal
228 struct fm_eth_port_cfg *dpaa_get_eth_port_cfg(int dev_id);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif /* __RTE_DPAA_BUS_H__ */