ce491d5d4308153fb58907ca9627fc8c69f64e39
[dpdk.git] / drivers / raw / dpaa2_qdma / rte_pmd_dpaa2_qdma.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2019 NXP
3  */
4
5 #ifndef __RTE_PMD_DPAA2_QDMA_H__
6 #define __RTE_PMD_DPAA2_QDMA_H__
7
8 /**
9  * @file
10  *
11  * NXP dpaa2 QDMA specific structures.
12  *
13  */
14
15 /** Maximum qdma burst size */
16 #define RTE_QDMA_BURST_NB_MAX 256
17
18 /** Determines the mode of operation */
19 enum {
20         /**
21          * Allocate a H/W queue per VQ i.e. Exclusive hardware queue for a VQ.
22          * This mode will have best performance.
23          */
24         RTE_QDMA_MODE_HW,
25         /**
26          * A VQ shall not have an exclusive associated H/W queue.
27          * Rather a H/W Queue will be shared by multiple Virtual Queues.
28          * This mode will have intermediate data structures to support
29          * multi VQ to PQ mappings thus having some performance implications.
30          * Note: Even in this mode there is an option to allocate a H/W
31          * queue for a VQ. Please see 'RTE_QDMA_VQ_EXCLUSIVE_PQ' flag.
32          */
33         RTE_QDMA_MODE_VIRTUAL
34 };
35
36 /**
37  * If user has configued a Virtual Queue mode, but for some particular VQ
38  * user needs an exclusive H/W queue associated (for better performance
39  * on that particular VQ), then user can pass this flag while creating the
40  * Virtual Queue. A H/W queue will be allocated corresponding to
41  * VQ which uses this flag.
42  */
43 #define RTE_QDMA_VQ_EXCLUSIVE_PQ        (1ULL)
44
45 /** States if the source addresses is physical. */
46 #define RTE_QDMA_JOB_SRC_PHY            (1ULL)
47
48 /** States if the destination addresses is physical. */
49 #define RTE_QDMA_JOB_DEST_PHY           (1ULL << 1)
50
51 /** Provides QDMA device attributes */
52 struct rte_qdma_attr {
53         /** total number of hw QDMA queues present */
54         uint16_t num_hw_queues;
55 };
56
57 /** QDMA device configuration structure */
58 struct rte_qdma_config {
59         /** Number of maximum hw queues to allocate per core. */
60         uint16_t max_hw_queues_per_core;
61         /** Maximum number of VQ's to be used. */
62         uint16_t max_vqs;
63         /** mode of operation - physical(h/w) or virtual */
64         uint8_t mode;
65         /**
66          * User provides this as input to the driver as a size of the FLE pool.
67          * FLE's (and corresponding source/destination descriptors) are
68          * allocated by the driver at enqueue time to store src/dest and
69          * other data and are freed at the dequeue time. This determines the
70          * maximum number of inflight jobs on the QDMA device. This should
71          * be power of 2.
72          */
73         int fle_pool_count;
74 };
75
76 struct rte_qdma_rbp {
77         uint32_t use_ultrashort:1;
78         uint32_t enable:1;
79         /**
80          * dportid:
81          * 0000 PCI-Express 1
82          * 0001 PCI-Express 2
83          * 0010 PCI-Express 3
84          * 0011 PCI-Express 4
85          * 0100 PCI-Express 5
86          * 0101 PCI-Express 6
87          */
88         uint32_t dportid:4;
89         uint32_t dpfid:2;
90         uint32_t dvfid:6;
91         /*using route by port for destination */
92         uint32_t drbp:1;
93         /**
94          * sportid:
95          * 0000 PCI-Express 1
96          * 0001 PCI-Express 2
97          * 0010 PCI-Express 3
98          * 0011 PCI-Express 4
99          * 0100 PCI-Express 5
100          * 0101 PCI-Express 6
101          */
102         uint32_t sportid:4;
103         uint32_t spfid:2;
104         uint32_t svfid:6;
105         /* using route by port for source */
106         uint32_t srbp:1;
107         uint32_t rsv:4;
108 };
109
110 /** Provides QDMA device statistics */
111 struct rte_qdma_vq_stats {
112         /** States if this vq has exclusively associated hw queue */
113         uint8_t exclusive_hw_queue;
114         /** Associated lcore id */
115         uint32_t lcore_id;
116         /* Total number of enqueues on this VQ */
117         uint64_t num_enqueues;
118         /* Total number of dequeues from this VQ */
119         uint64_t num_dequeues;
120         /* total number of pending jobs in this VQ */
121         uint64_t num_pending_jobs;
122 };
123
124 /** Determines a QDMA job */
125 struct rte_qdma_job {
126         /** Source Address from where DMA is (to be) performed */
127         uint64_t src;
128         /** Destination Address where DMA is (to be) done */
129         uint64_t dest;
130         /** Length of the DMA operation in bytes. */
131         uint32_t len;
132         /** See RTE_QDMA_JOB_ flags */
133         uint32_t flags;
134         /**
135          * User can specify a context which will be maintained
136          * on the dequeue operation.
137          */
138         uint64_t cnxt;
139         /**
140          * Status of the transaction.
141          * This is filled in the dequeue operation by the driver.
142          * upper 8bits acc_err for route by port.
143          * lower 8bits fd error
144          */
145         uint16_t status;
146 };
147
148 /**
149  * Initialize the QDMA device.
150  *
151  * @returns
152  *   - 0: Success.
153  *   - <0: Error code.
154  */
155 int
156 rte_qdma_init(void);
157
158 /**
159  * Get the QDMA attributes.
160  *
161  * @param qdma_attr
162  *   QDMA attributes providing total number of hw queues etc.
163  */
164 void
165 rte_qdma_attr_get(struct rte_qdma_attr *qdma_attr);
166
167 /**
168  * Reset the QDMA device. This API will completely reset the QDMA
169  * device, bringing it to original state as if only rte_qdma_init() API
170  * has been called.
171  *
172  * @returns
173  *   - 0: Success.
174  *   - <0: Error code.
175  */
176 int
177 rte_qdma_reset(void);
178
179 /**
180  * Configure the QDMA device.
181  *
182  * @returns
183  *   - 0: Success.
184  *   - <0: Error code.
185  */
186 int
187 rte_qdma_configure(struct rte_qdma_config *qdma_config);
188
189 /**
190  * Start the QDMA device.
191  *
192  * @returns
193  *   - 0: Success.
194  *   - <0: Error code.
195  */
196 int
197 rte_qdma_start(void);
198
199 /**
200  * Create a Virtual Queue on a particular lcore id.
201  * This API can be called from any thread/core. User can create/destroy
202  * VQ's at runtime.
203  *
204  * @param lcore_id
205  *   LCORE ID on which this particular queue would be associated with.
206  * @param flags
207  *  RTE_QDMA_VQ_ flags. See macro definitions.
208  *
209  * @returns
210  *   - >= 0: Virtual queue ID.
211  *   - <0: Error code.
212  */
213 int
214 rte_qdma_vq_create(uint32_t lcore_id, uint32_t flags);
215
216 /*create vq for route-by-port*/
217 int
218 rte_qdma_vq_create_rbp(uint32_t lcore_id, uint32_t flags,
219                         struct rte_qdma_rbp *rbp);
220
221 /**
222  * Enqueue multiple jobs to a Virtual Queue.
223  * If the enqueue is successful, the H/W will perform DMA operations
224  * on the basis of the QDMA jobs provided.
225  *
226  * @param vq_id
227  *   Virtual Queue ID.
228  * @param job
229  *   List of QDMA Jobs containing relevant information related to DMA.
230  * @param nb_jobs
231  *   Number of QDMA jobs provided by the user.
232  *
233  * @returns
234  *   - >=0: Number of jobs successfully submitted
235  *   - <0: Error code.
236  */
237 int
238 rte_qdma_vq_enqueue_multi(uint16_t vq_id,
239                           struct rte_qdma_job **job,
240                           uint16_t nb_jobs);
241
242 /**
243  * Enqueue a single job to a Virtual Queue.
244  * If the enqueue is successful, the H/W will perform DMA operations
245  * on the basis of the QDMA job provided.
246  *
247  * @param vq_id
248  *   Virtual Queue ID.
249  * @param job
250  *   A QDMA Job containing relevant information related to DMA.
251  *
252  * @returns
253  *   - >=0: Number of jobs successfully submitted
254  *   - <0: Error code.
255  */
256 int
257 rte_qdma_vq_enqueue(uint16_t vq_id,
258                     struct rte_qdma_job *job);
259
260 /**
261  * Dequeue multiple completed jobs from a Virtual Queue.
262  * Provides the list of completed jobs capped by nb_jobs.
263  *
264  * @param vq_id
265  *   Virtual Queue ID.
266  * @param job
267  *   List of QDMA Jobs returned from the API.
268  * @param nb_jobs
269  *   Number of QDMA jobs requested for dequeue by the user.
270  *
271  * @returns
272  *   - >=0: Number of jobs successfully received
273  *   - <0: Error code.
274  */
275 int
276 rte_qdma_vq_dequeue_multi(uint16_t vq_id,
277                           struct rte_qdma_job **job,
278                           uint16_t nb_jobs);
279
280 /**
281  * Dequeue a single completed jobs from a Virtual Queue.
282  *
283  * @param vq_id
284  *   Virtual Queue ID.
285  *
286  * @returns
287  *   - A completed job or NULL if no job is there.
288  */
289 struct rte_qdma_job * __rte_experimental
290 rte_qdma_vq_dequeue(uint16_t vq_id);
291
292 /**
293  * Get a Virtual Queue statistics.
294  *
295  * @param vq_id
296  *   Virtual Queue ID.
297  * @param vq_stats
298  *   VQ statistics structure which will be filled in by the driver.
299  */
300 void
301 rte_qdma_vq_stats(uint16_t vq_id,
302                   struct rte_qdma_vq_stats *vq_stats);
303
304 /**
305  * Destroy the Virtual Queue specified by vq_id.
306  * This API can be called from any thread/core. User can create/destroy
307  * VQ's at runtime.
308  *
309  * @param vq_id
310  *   Virtual Queue ID which needs to be deinialized.
311  *
312  * @returns
313  *   - 0: Success.
314  *   - <0: Error code.
315  */
316 int
317 rte_qdma_vq_destroy(uint16_t vq_id);
318
319 /**
320  * Destroy the RBP specific Virtual Queue specified by vq_id.
321  * This API can be called from any thread/core. User can create/destroy
322  * VQ's at runtime.
323  *
324  * @param vq_id
325  *   RBP based Virtual Queue ID which needs to be deinialized.
326  *
327  * @returns
328  *   - 0: Success.
329  *   - <0: Error code.
330  */
331
332 int
333 rte_qdma_vq_destroy_rbp(uint16_t vq_id);
334 /**
335  * Stop QDMA device.
336  */
337 void
338 rte_qdma_stop(void);
339
340 /**
341  * Destroy the QDMA device.
342  */
343 void
344 rte_qdma_destroy(void);
345
346 #endif /* __RTE_PMD_DPAA2_QDMA_H__*/