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