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