31a5ea3fca921a45ff693133e96cf35b887b2e15
[dpdk.git] / drivers / bus / dpaa / rte_dpaa_bus.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017-2020 NXP
4  *
5  */
6 #ifndef __RTE_DPAA_BUS_H__
7 #define __RTE_DPAA_BUS_H__
8
9 #include <rte_bus.h>
10 #include <rte_mbuf_dyn.h>
11 #include <rte_mempool.h>
12 #include <dpaax_iova_table.h>
13
14 #include <dpaa_of.h>
15 #include <fsl_usd.h>
16 #include <fsl_qman.h>
17 #include <fsl_bman.h>
18 #include <netcfg.h>
19
20 /* This sequence number field is used to store event entry index for
21  * driver specific usage. For parallel mode queues, invalid
22  * index will be set and for atomic mode queues, valid value
23  * ranging from 1 to 16.
24  */
25 #define DPAA_INVALID_MBUF_SEQN  0
26
27 typedef uint32_t dpaa_seqn_t;
28 extern int dpaa_seqn_dynfield_offset;
29
30 /**
31  * Read dpaa sequence number from mbuf.
32  *
33  * @param mbuf Structure to read from.
34  * @return pointer to dpaa sequence number.
35  */
36 __rte_internal
37 static inline dpaa_seqn_t *
38 dpaa_seqn(struct rte_mbuf *mbuf)
39 {
40         return RTE_MBUF_DYNFIELD(mbuf, dpaa_seqn_dynfield_offset,
41                 dpaa_seqn_t *);
42 }
43
44 #define DPAA_MEMPOOL_OPS_NAME   "dpaa"
45
46 #define DEV_TO_DPAA_DEVICE(ptr) \
47                 container_of(ptr, struct rte_dpaa_device, device)
48
49 /* DPAA SoC identifier; If this is not available, it can be concluded
50  * that board is non-DPAA. Single slot is currently supported.
51  */
52 #define DPAA_SOC_ID_FILE        "/sys/devices/soc0/soc_id"
53
54 #define SVR_LS1043A_FAMILY      0x87920000
55 #define SVR_LS1046A_FAMILY      0x87070000
56 #define SVR_MASK                0xffff0000
57
58 /** Device driver supports link state interrupt */
59 #define RTE_DPAA_DRV_INTR_LSC  0x0008
60
61 /** Number of supported QDMA devices */
62 #define RTE_DPAA_QDMA_DEVICES  1
63
64 #define RTE_DEV_TO_DPAA_CONST(ptr) \
65         container_of(ptr, const struct rte_dpaa_device, device)
66
67 extern unsigned int dpaa_svr_family;
68
69 struct rte_dpaa_device;
70 struct rte_dpaa_driver;
71
72 /* DPAA Device and Driver lists for DPAA bus */
73 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
74 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
75
76 enum rte_dpaa_type {
77         FSL_DPAA_ETH = 1,
78         FSL_DPAA_CRYPTO,
79         FSL_DPAA_QDMA
80 };
81
82 struct rte_dpaa_bus {
83         struct rte_bus bus;
84         struct rte_dpaa_device_list device_list;
85         struct rte_dpaa_driver_list driver_list;
86         int device_count;
87         int detected;
88 };
89
90 struct dpaa_device_id {
91         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
92         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
93         uint16_t dev_id; /**< Device Identifier from DPDK */
94 };
95
96 struct rte_dpaa_device {
97         TAILQ_ENTRY(rte_dpaa_device) next;
98         struct rte_device device;
99         union {
100                 struct rte_eth_dev *eth_dev;
101                 struct rte_cryptodev *crypto_dev;
102                 struct rte_dma_dev *dmadev;
103         };
104         struct rte_dpaa_driver *driver;
105         struct dpaa_device_id id;
106         struct rte_intr_handle *intr_handle;
107         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
108         char name[RTE_ETH_NAME_MAX_LEN];
109 };
110
111 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
112                                 struct rte_dpaa_device *dpaa_dev);
113 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
114
115 struct rte_dpaa_driver {
116         TAILQ_ENTRY(rte_dpaa_driver) next;
117         struct rte_driver driver;
118         struct rte_dpaa_bus *dpaa_bus;
119         enum rte_dpaa_type drv_type;
120         rte_dpaa_probe_t probe;
121         rte_dpaa_remove_t remove;
122         uint32_t drv_flags;                 /**< Flags for controlling device.*/
123 };
124
125 /* Create storage for dqrr entries per lcore */
126 #define DPAA_PORTAL_DEQUEUE_DEPTH       16
127 struct dpaa_portal_dqrr {
128         void *mbuf[DPAA_PORTAL_DEQUEUE_DEPTH];
129         uint64_t dqrr_held;
130         uint8_t dqrr_size;
131 };
132
133 struct dpaa_portal {
134         uint32_t bman_idx; /**< BMAN Portal ID*/
135         uint32_t qman_idx; /**< QMAN Portal ID*/
136         struct dpaa_portal_dqrr dpaa_held_bufs;
137         struct rte_crypto_op **dpaa_sec_ops;
138         int dpaa_sec_op_nb;
139         uint64_t tid;/**< Parent Thread id for this portal */
140 };
141
142 RTE_DECLARE_PER_LCORE(struct dpaa_portal *, dpaa_io);
143
144 #define DPAA_PER_LCORE_PORTAL \
145         RTE_PER_LCORE(dpaa_io)
146 #define DPAA_PER_LCORE_DQRR_SIZE \
147         RTE_PER_LCORE(dpaa_io)->dpaa_held_bufs.dqrr_size
148 #define DPAA_PER_LCORE_DQRR_HELD \
149         RTE_PER_LCORE(dpaa_io)->dpaa_held_bufs.dqrr_held
150 #define DPAA_PER_LCORE_DQRR_MBUF(i) \
151         RTE_PER_LCORE(dpaa_io)->dpaa_held_bufs.mbuf[i]
152 #define DPAA_PER_LCORE_RTE_CRYPTO_OP \
153         RTE_PER_LCORE(dpaa_io)->dpaa_sec_ops
154 #define DPAA_PER_LCORE_DPAA_SEC_OP_NB \
155         RTE_PER_LCORE(dpaa_io)->dpaa_sec_op_nb
156
157 /* Various structures representing contiguous memory maps */
158 struct dpaa_memseg {
159         TAILQ_ENTRY(dpaa_memseg) next;
160         char *vaddr;
161         rte_iova_t iova;
162         size_t len;
163 };
164
165 TAILQ_HEAD(dpaa_memseg_list, dpaa_memseg);
166 extern struct dpaa_memseg_list rte_dpaa_memsegs;
167
168 /* Either iterate over the list of internal memseg references or fallback to
169  * EAL memseg based iova2virt.
170  */
171 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
172 {
173         struct dpaa_memseg *ms;
174         void *va;
175
176         va = dpaax_iova_table_get_va(paddr);
177         if (likely(va != NULL))
178                 return va;
179
180         /* Check if the address is already part of the memseg list internally
181          * maintained by the dpaa driver.
182          */
183         TAILQ_FOREACH(ms, &rte_dpaa_memsegs, next) {
184                 if (paddr >= ms->iova && paddr <
185                         ms->iova + ms->len)
186                         return RTE_PTR_ADD(ms->vaddr, (uintptr_t)(paddr - ms->iova));
187         }
188
189         /* If not, Fallback to full memseg list searching */
190         va = rte_mem_iova2virt(paddr);
191
192         dpaax_iova_table_update(paddr, va, RTE_CACHE_LINE_SIZE);
193
194         return va;
195 }
196
197 static inline rte_iova_t
198 rte_dpaa_mem_vtop(void *vaddr)
199 {
200         const struct rte_memseg *ms;
201
202         ms = rte_mem_virt2memseg(vaddr, NULL);
203         if (ms)
204                 return ms->iova + RTE_PTR_DIFF(vaddr, ms->addr);
205
206         return (size_t)NULL;
207 }
208
209 /**
210  * Register a DPAA driver.
211  *
212  * @param driver
213  *   A pointer to a rte_dpaa_driver structure describing the driver
214  *   to be registered.
215  */
216 __rte_internal
217 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
218
219 /**
220  * Unregister a DPAA driver.
221  *
222  * @param driver
223  *      A pointer to a rte_dpaa_driver structure describing the driver
224  *      to be unregistered.
225  */
226 __rte_internal
227 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
228
229 /**
230  * Initialize a DPAA portal
231  *
232  * @param arg
233  *      Per thread ID
234  *
235  * @return
236  *      0 in case of success, error otherwise
237  */
238 __rte_internal
239 int rte_dpaa_portal_init(void *arg);
240
241 __rte_internal
242 int rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq);
243
244 __rte_internal
245 int rte_dpaa_portal_fq_close(struct qman_fq *fq);
246
247 /**
248  * Cleanup a DPAA Portal
249  */
250 void dpaa_portal_finish(void *arg);
251
252 /** Helper for DPAA device registration from driver (eth, crypto) instance */
253 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
254 RTE_INIT(dpaainitfn_ ##nm) \
255 {\
256         (dpaa_drv).driver.name = RTE_STR(nm);\
257         rte_dpaa_driver_register(&dpaa_drv); \
258 } \
259 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
260
261 __rte_internal
262 struct fm_eth_port_cfg *dpaa_get_eth_port_cfg(int dev_id);
263
264 #ifdef __cplusplus
265 }
266 #endif
267
268 #endif /* __RTE_DPAA_BUS_H__ */