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