1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2020 NXP
5 #ifndef __DPAA2_QDMA_H__
6 #define __DPAA2_QDMA_H__
11 #define DPAA2_QDMA_MAX_FLE 3
12 #define DPAA2_QDMA_MAX_SDD 2
14 #define DPAA2_QDMA_MAX_SG_NB 64
16 #define DPAA2_DPDMAI_MAX_QUEUES 8
18 /** FLE single job pool size: job pointer(uint64_t) +
19 * 3 Frame list + 2 source/destination descriptor.
21 #define QDMA_FLE_SINGLE_POOL_SIZE (sizeof(uint64_t) + \
22 sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE + \
23 sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD)
25 /** FLE sg jobs pool size: job number(uint64_t) +
26 * 3 Frame list + 2 source/destination descriptor +
27 * 64 (src + dst) sg entries + 64 jobs pointers.
29 #define QDMA_FLE_SG_POOL_SIZE (sizeof(uint64_t) + \
30 sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE + \
31 sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD + \
32 sizeof(struct qdma_sg_entry) * (DPAA2_QDMA_MAX_SG_NB * 2) + \
33 sizeof(struct rte_qdma_job *) * DPAA2_QDMA_MAX_SG_NB)
35 #define QDMA_FLE_JOB_NB_OFFSET 0
37 #define QDMA_FLE_SINGLE_JOB_OFFSET 0
39 #define QDMA_FLE_FLE_OFFSET \
40 (QDMA_FLE_JOB_NB_OFFSET + sizeof(uint64_t))
42 #define QDMA_FLE_SDD_OFFSET \
43 (QDMA_FLE_FLE_OFFSET + \
44 sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE)
46 #define QDMA_FLE_SG_ENTRY_OFFSET \
47 (QDMA_FLE_SDD_OFFSET + \
48 sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD)
50 #define QDMA_FLE_SG_JOBS_OFFSET \
51 (QDMA_FLE_SG_ENTRY_OFFSET + \
52 sizeof(struct qdma_sg_entry) * DPAA2_QDMA_MAX_SG_NB * 2)
54 /** FLE pool cache size */
55 #define QDMA_FLE_CACHE_SIZE(_num) (_num/(RTE_MAX_LCORE * 2))
57 /** Notification by FQD_CTX[fqid] */
58 #define QDMA_SER_CTX (1 << 8)
59 #define DPAA2_RBP_MEM_RW 0x0
61 * Source descriptor command read transaction type for RBP=0:
62 * coherent copy of cacheable memory
64 #define DPAA2_COHERENT_NO_ALLOCATE_CACHE 0xb
65 #define DPAA2_LX2_COHERENT_NO_ALLOCATE_CACHE 0x7
67 * Destination descriptor command write transaction type for RBP=0:
68 * coherent copy of cacheable memory
70 #define DPAA2_COHERENT_ALLOCATE_CACHE 0x6
71 #define DPAA2_LX2_COHERENT_ALLOCATE_CACHE 0xb
73 /** Maximum possible H/W Queues on each core */
74 #define MAX_HW_QUEUE_PER_CORE 64
76 #define QDMA_RBP_UPPER_ADDRESS_MASK (0xfff0000000000)
78 * Represents a QDMA device.
79 * A single QDMA device exists which is combination of multiple DPDMAI rawdev's.
82 /** total number of hw queues. */
83 uint16_t num_hw_queues;
85 * Maximum number of hw queues to be alocated per core.
86 * This is limited by MAX_HW_QUEUE_PER_CORE
88 uint16_t max_hw_queues_per_core;
90 /** VQ's of this device */
91 struct qdma_virt_queue *vqs;
92 /** Maximum number of VQ's */
94 /** Device state - started or stopped */
96 /** FLE queue pool size */
97 int fle_queue_pool_cnt;
98 /** A lock to QDMA device whenever required */
102 /** Represents a QDMA H/W queue */
103 struct qdma_hw_queue {
104 /** Pointer to Next instance */
105 TAILQ_ENTRY(qdma_hw_queue) next;
106 /** DPDMAI device to communicate with HW */
107 struct dpaa2_dpdmai_dev *dpdmai_dev;
108 /** queue ID to communicate with HW */
110 /** Associated lcore id */
112 /** Number of users of this hw queue */
116 struct qdma_virt_queue;
118 typedef uint16_t (qdma_get_job_t)(struct qdma_virt_queue *qdma_vq,
119 const struct qbman_fd *fd,
120 struct rte_qdma_job **job,
122 typedef int (qdma_set_fd_t)(struct qdma_virt_queue *qdma_vq,
124 struct rte_qdma_job **job,
127 typedef int (qdma_dequeue_multijob_t)(
128 struct qdma_virt_queue *qdma_vq,
130 struct rte_qdma_job **job,
133 typedef int (qdma_enqueue_multijob_t)(
134 struct qdma_virt_queue *qdma_vq,
135 struct rte_qdma_job **job,
138 /** Represents a QDMA virtual queue */
139 struct qdma_virt_queue {
140 /** Status ring of the virtual queue */
141 struct rte_ring *status_ring;
142 /** Associated hw queue */
143 struct qdma_hw_queue *hw_queue;
144 /** FLE pool for the queue */
145 struct rte_mempool *fle_pool;
147 struct rte_qdma_rbp rbp;
148 /** Associated lcore id */
150 /** States if this vq is in use or not */
152 /** States if this vq has exclusively associated hw queue */
153 uint8_t exclusive_hw_queue;
154 /* Total number of enqueues on this VQ */
155 uint64_t num_enqueues;
156 /* Total number of dequeues from this VQ */
157 uint64_t num_dequeues;
162 qdma_set_fd_t *set_fd;
163 qdma_get_job_t *get_job;
165 qdma_dequeue_multijob_t *dequeue_job;
166 qdma_enqueue_multijob_t *enqueue_job;
169 /** Represents a QDMA per core hw queues allocation in virtual mode */
170 struct qdma_per_core_info {
171 /** list for allocated hw queues */
172 struct qdma_hw_queue *hw_queues[MAX_HW_QUEUE_PER_CORE];
173 /* Number of hw queues allocated for this core */
174 uint16_t num_hw_queues;
177 /** Source/Destination Descriptor */
180 /** Stride configuration */
182 /** Route-by-port command */
226 #define QDMA_SG_FMT_SDB 0x0 /* single data buffer */
227 #define QDMA_SG_FMT_FDS 0x1 /* frame data section */
228 #define QDMA_SG_FMT_SGTE 0x2 /* SGT extension */
229 #define QDMA_SG_SL_SHORT 0x1 /* short length */
230 #define QDMA_SG_SL_LONG 0x0 /* long length */
231 #define QDMA_SG_F 0x1 /* last sg entry */
232 #define QDMA_SG_BMT_ENABLE 0x1
233 #define QDMA_SG_BMT_DISABLE 0x0
235 struct qdma_sg_entry {
236 uint32_t addr_lo; /* address 0:31 */
237 uint32_t addr_hi:17; /* address 32:48 */
240 uint32_t data_len_sl0; /* SL=0, the long format */
242 uint32_t len:17; /* SL=1, the short format */
246 uint32_t size:10; /* buff size */
248 } data_len; /* AVAIL_LENGTH */
250 uint32_t ctrl_fields;
263 /** Represents a DPDMAI raw device */
264 struct dpaa2_dpdmai_dev {
265 /** Pointer to Next device instance */
266 TAILQ_ENTRY(dpaa2_qdma_device) next;
267 /** handle to DPDMAI object */
268 struct fsl_mc_io dpdmai;
269 /** HW ID for DPDMAI object */
271 /** Tocken of this device */
273 /** Number of queue in this DPDMAI device */
276 struct dpaa2_queue rx_queue[DPAA2_DPDMAI_MAX_QUEUES];
278 struct dpaa2_queue tx_queue[DPAA2_DPDMAI_MAX_QUEUES];
279 struct qdma_device *qdma_dev;
282 static inline struct qdma_device *
283 QDMA_DEV_OF_VQ(struct qdma_virt_queue *vq)
285 return vq->hw_queue->dpdmai_dev->qdma_dev;
288 #endif /* __DPAA2_QDMA_H__ */