net/ena: fix build with GCC 12
[dpdk.git] / drivers / dma / dpaa2 / dpaa2_qdma.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2022 NXP
3  */
4
5 #ifndef _DPAA2_QDMA_H_
6 #define _DPAA2_QDMA_H_
7
8 #define DPAA2_QDMA_MAX_DESC             1024
9 #define DPAA2_QDMA_MIN_DESC             1
10 #define DPAA2_QDMA_MAX_VHANS            64
11
12 #define DPAA2_QDMA_VQ_FD_SHORT_FORMAT           (1ULL << 0)
13 #define DPAA2_QDMA_VQ_FD_SG_FORMAT              (1ULL << 1)
14 #define DPAA2_QDMA_VQ_NO_RESPONSE               (1ULL << 2)
15
16 #define DPAA2_QDMA_MAX_FLE 3
17 #define DPAA2_QDMA_MAX_SDD 2
18
19 #define DPAA2_QDMA_MAX_SG_NB 64
20
21 #define DPAA2_DPDMAI_MAX_QUEUES 1
22
23 /** FLE single job pool size: job pointer(uint64_t) +
24  * 3 Frame list + 2 source/destination descriptor.
25  */
26 #define QDMA_FLE_SINGLE_POOL_SIZE (sizeof(uint64_t) + \
27                         sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE + \
28                         sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD)
29
30 /** FLE sg jobs pool size: job number(uint64_t) +
31  * 3 Frame list + 2 source/destination descriptor  +
32  * 64 (src + dst) sg entries + 64 jobs pointers.
33  */
34 #define QDMA_FLE_SG_POOL_SIZE (sizeof(uint64_t) + \
35                 sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE + \
36                 sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD + \
37                 sizeof(struct qdma_sg_entry) * (DPAA2_QDMA_MAX_SG_NB * 2) + \
38                 sizeof(struct rte_qdma_job *) * DPAA2_QDMA_MAX_SG_NB)
39
40 #define QDMA_FLE_JOB_NB_OFFSET 0
41
42 #define QDMA_FLE_SINGLE_JOB_OFFSET 0
43
44 #define QDMA_FLE_FLE_OFFSET \
45                 (QDMA_FLE_JOB_NB_OFFSET + sizeof(uint64_t))
46
47 #define QDMA_FLE_SDD_OFFSET \
48                 (QDMA_FLE_FLE_OFFSET + \
49                 sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE)
50
51 #define QDMA_FLE_SG_ENTRY_OFFSET \
52                 (QDMA_FLE_SDD_OFFSET + \
53                 sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD)
54
55 #define QDMA_FLE_SG_JOBS_OFFSET \
56                 (QDMA_FLE_SG_ENTRY_OFFSET + \
57                 sizeof(struct qdma_sg_entry) * DPAA2_QDMA_MAX_SG_NB * 2)
58
59 /** FLE pool cache size */
60 #define QDMA_FLE_CACHE_SIZE(_num) (_num/(RTE_MAX_LCORE * 2))
61
62 /** Notification by FQD_CTX[fqid] */
63 #define QDMA_SER_CTX (1 << 8)
64 #define DPAA2_RBP_MEM_RW            0x0
65 /**
66  * Source descriptor command read transaction type for RBP=0:
67  * coherent copy of cacheable memory
68  */
69 #define DPAA2_COHERENT_NO_ALLOCATE_CACHE        0xb
70 #define DPAA2_LX2_COHERENT_NO_ALLOCATE_CACHE    0x7
71 /**
72  * Destination descriptor command write transaction type for RBP=0:
73  * coherent copy of cacheable memory
74  */
75 #define DPAA2_COHERENT_ALLOCATE_CACHE           0x6
76 #define DPAA2_LX2_COHERENT_ALLOCATE_CACHE       0xb
77
78 /** Maximum possible H/W Queues on each core */
79 #define MAX_HW_QUEUE_PER_CORE           64
80
81 #define QDMA_RBP_UPPER_ADDRESS_MASK (0xfff0000000000)
82
83 /** Source/Destination Descriptor */
84 struct qdma_sdd {
85         uint32_t rsv;
86         /** Stride configuration */
87         uint32_t stride;
88         /** Route-by-port command */
89         union {
90                 uint32_t rbpcmd;
91                 struct rbpcmd_st {
92                         uint32_t vfid:6;
93                         uint32_t rsv4:2;
94                         uint32_t pfid:1;
95                         uint32_t rsv3:7;
96                         uint32_t attr:3;
97                         uint32_t rsv2:1;
98                         uint32_t at:2;
99                         uint32_t vfa:1;
100                         uint32_t ca:1;
101                         uint32_t tc:3;
102                         uint32_t rsv1:5;
103                 } rbpcmd_simple;
104         };
105         union {
106                 uint32_t cmd;
107                 struct rcmd_simple {
108                         uint32_t portid:4;
109                         uint32_t rsv1:14;
110                         uint32_t rbp:1;
111                         uint32_t ssen:1;
112                         uint32_t rthrotl:4;
113                         uint32_t sqos:3;
114                         uint32_t ns:1;
115                         uint32_t rdtype:4;
116                 } read_cmd;
117                 struct wcmd_simple {
118                         uint32_t portid:4;
119                         uint32_t rsv3:10;
120                         uint32_t rsv2:2;
121                         uint32_t lwc:2;
122                         uint32_t rbp:1;
123                         uint32_t dsen:1;
124                         uint32_t rsv1:4;
125                         uint32_t dqos:3;
126                         uint32_t ns:1;
127                         uint32_t wrttype:4;
128                 } write_cmd;
129         };
130 } __rte_packed;
131
132 #define QDMA_SG_FMT_SDB 0x0 /* single data buffer */
133 #define QDMA_SG_FMT_FDS 0x1 /* frame data section */
134 #define QDMA_SG_FMT_SGTE        0x2 /* SGT extension */
135 #define QDMA_SG_SL_SHORT        0x1 /* short length */
136 #define QDMA_SG_SL_LONG 0x0 /* long length */
137 #define QDMA_SG_F       0x1 /* last sg entry */
138 #define QDMA_SG_BMT_ENABLE 0x1
139 #define QDMA_SG_BMT_DISABLE 0x0
140
141 struct qdma_sg_entry {
142         uint32_t addr_lo;               /* address 0:31 */
143         uint32_t addr_hi:17;    /* address 32:48 */
144         uint32_t rsv:15;
145         union {
146                 uint32_t data_len_sl0;  /* SL=0, the long format */
147                 struct {
148                         uint32_t len:17;        /* SL=1, the short format */
149                         uint32_t reserve:3;
150                         uint32_t sf:1;
151                         uint32_t sr:1;
152                         uint32_t size:10;       /* buff size */
153                 } data_len_sl1;
154         } data_len;                                     /* AVAIL_LENGTH */
155         union {
156                 uint32_t ctrl_fields;
157                 struct {
158                         uint32_t bpid:14;
159                         uint32_t ivp:1;
160                         uint32_t bmt:1;
161                         uint32_t offset:12;
162                         uint32_t fmt:2;
163                         uint32_t sl:1;
164                         uint32_t f:1;
165                 } ctrl;
166         };
167 } __rte_packed;
168
169 /** Represents a DPDMAI device */
170 struct dpaa2_dpdmai_dev {
171         /** Pointer to Next device instance */
172         TAILQ_ENTRY(dpaa2_qdma_device) next;
173         /** handle to DPDMAI object */
174         struct fsl_mc_io dpdmai;
175         /** HW ID for DPDMAI object */
176         uint32_t dpdmai_id;
177         /** Tocken of this device */
178         uint16_t token;
179         /** Number of queue in this DPDMAI device */
180         uint8_t num_queues;
181         /** RX queues */
182         struct dpaa2_queue rx_queue[DPAA2_DPDMAI_MAX_QUEUES];
183         /** TX queues */
184         struct dpaa2_queue tx_queue[DPAA2_DPDMAI_MAX_QUEUES];
185         struct qdma_device *qdma_dev;
186 };
187
188 struct qdma_virt_queue;
189
190 typedef uint16_t (qdma_get_job_t)(struct qdma_virt_queue *qdma_vq,
191                                         const struct qbman_fd *fd,
192                                         struct rte_dpaa2_qdma_job **job,
193                                         uint16_t *nb_jobs);
194 typedef int (qdma_set_fd_t)(struct qdma_virt_queue *qdma_vq,
195                                         struct qbman_fd *fd,
196                                         struct rte_dpaa2_qdma_job **job,
197                                         uint16_t nb_jobs);
198
199 typedef int (qdma_dequeue_multijob_t)(
200                                 struct qdma_virt_queue *qdma_vq,
201                                 uint16_t *vq_id,
202                                 struct rte_dpaa2_qdma_job **job,
203                                 uint16_t nb_jobs);
204
205 typedef int (qdma_enqueue_multijob_t)(
206                         struct qdma_virt_queue *qdma_vq,
207                         struct rte_dpaa2_qdma_job **job,
208                         uint16_t nb_jobs);
209
210 /** Represents a QDMA virtual queue */
211 struct qdma_virt_queue {
212         /** Status ring of the virtual queue */
213         struct rte_ring *status_ring;
214         /** Associated hw queue */
215         struct dpaa2_dpdmai_dev *dpdmai_dev;
216         /** FLE pool for the queue */
217         struct rte_mempool *fle_pool;
218         /** Route by port */
219         struct rte_dpaa2_qdma_rbp rbp;
220         /** States if this vq is in use or not */
221         uint8_t in_use;
222         /** States if this vq has exclusively associated hw queue */
223         uint8_t exclusive_hw_queue;
224         /** Number of descriptor for the virtual DMA channel */
225         uint16_t nb_desc;
226         /* Total number of enqueues on this VQ */
227         uint64_t num_enqueues;
228         /* Total number of dequeues from this VQ */
229         uint64_t num_dequeues;
230
231         uint16_t vq_id;
232         uint32_t flags;
233
234         struct rte_dpaa2_qdma_job *job_list[DPAA2_QDMA_MAX_DESC];
235         struct rte_mempool *job_pool;
236         int num_valid_jobs;
237
238         struct rte_dma_stats stats;
239
240         qdma_set_fd_t *set_fd;
241         qdma_get_job_t *get_job;
242
243         qdma_dequeue_multijob_t *dequeue_job;
244         qdma_enqueue_multijob_t *enqueue_job;
245 };
246
247 /** Represents a QDMA device. */
248 struct qdma_device {
249         /** VQ's of this device */
250         struct qdma_virt_queue *vqs;
251         /** Total number of VQ's */
252         uint16_t num_vqs;
253         /** Device state - started or stopped */
254         uint8_t state;
255 };
256
257 #endif /* _DPAA2_QDMA_H_ */