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