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