ff7743fb54a71507494756fb18ec8fff02e8a4a0
[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_DPDMAI_MAX_QUEUES 8
15
16 /** FLE pool size: 3 Frame list + 2 source/destination descriptor */
17 #define QDMA_FLE_POOL_SIZE (sizeof(struct rte_qdma_job *) + \
18                 sizeof(struct qbman_fle) * DPAA2_QDMA_MAX_FLE + \
19                 sizeof(struct qdma_sdd) * DPAA2_QDMA_MAX_SDD)
20
21 #define QDMA_FLE_JOB_OFFSET 0
22 #define QDMA_FLE_FLE_OFFSET \
23                 (QDMA_FLE_JOB_OFFSET + sizeof(struct rte_qdma_job *))
24
25 /** FLE pool cache size */
26 #define QDMA_FLE_CACHE_SIZE(_num) (_num/(RTE_MAX_LCORE * 2))
27
28 /** Notification by FQD_CTX[fqid] */
29 #define QDMA_SER_CTX (1 << 8)
30 #define DPAA2_RBP_MEM_RW            0x0
31 /**
32  * Source descriptor command read transaction type for RBP=0:
33  * coherent copy of cacheable memory
34  */
35 #define DPAA2_COHERENT_NO_ALLOCATE_CACHE        0xb
36 #define DPAA2_LX2_COHERENT_NO_ALLOCATE_CACHE    0x7
37 /**
38  * Destination descriptor command write transaction type for RBP=0:
39  * coherent copy of cacheable memory
40  */
41 #define DPAA2_COHERENT_ALLOCATE_CACHE           0x6
42 #define DPAA2_LX2_COHERENT_ALLOCATE_CACHE       0xb
43
44 /** Maximum possible H/W Queues on each core */
45 #define MAX_HW_QUEUE_PER_CORE           64
46
47 #define QDMA_RBP_UPPER_ADDRESS_MASK (0xfff0000000000)
48 /**
49  * Represents a QDMA device.
50  * A single QDMA device exists which is combination of multiple DPDMAI rawdev's.
51  */
52 struct qdma_device {
53         /** total number of hw queues. */
54         uint16_t num_hw_queues;
55         /**
56          * Maximum number of hw queues to be alocated per core.
57          * This is limited by MAX_HW_QUEUE_PER_CORE
58          */
59         uint16_t max_hw_queues_per_core;
60
61         /** VQ's of this device */
62         struct qdma_virt_queue *vqs;
63         /** Maximum number of VQ's */
64         uint16_t max_vqs;
65         /** Device state - started or stopped */
66         uint8_t state;
67         /** FLE pool for the device */
68         struct rte_mempool *fle_pool;
69         /** FLE pool size */
70         int fle_pool_count;
71         /** A lock to QDMA device whenever required */
72         rte_spinlock_t lock;
73 };
74
75 /** Represents a QDMA H/W queue */
76 struct qdma_hw_queue {
77         /** Pointer to Next instance */
78         TAILQ_ENTRY(qdma_hw_queue) next;
79         /** DPDMAI device to communicate with HW */
80         struct dpaa2_dpdmai_dev *dpdmai_dev;
81         /** queue ID to communicate with HW */
82         uint16_t queue_id;
83         /** Associated lcore id */
84         uint32_t lcore_id;
85         /** Number of users of this hw queue */
86         uint32_t num_users;
87 };
88
89 struct qdma_virt_queue;
90
91 typedef uint16_t (qdma_get_job_t)(struct qdma_virt_queue *qdma_vq,
92                                         const struct qbman_fd *fd,
93                                         struct rte_qdma_job **job);
94 typedef int (qdma_set_fd_t)(struct qdma_virt_queue *qdma_vq,
95                                         struct qbman_fd *fd,
96                                         struct rte_qdma_job *job);
97
98 typedef int (qdma_dequeue_multijob_t)(
99                                 struct qdma_virt_queue *qdma_vq,
100                                 uint16_t *vq_id,
101                                 struct rte_qdma_job **job,
102                                 uint16_t nb_jobs);
103
104 typedef int (qdma_enqueue_multijob_t)(
105                         struct qdma_virt_queue *qdma_vq,
106                         struct rte_qdma_job **job,
107                         uint16_t nb_jobs);
108
109 /** Represents a QDMA virtual queue */
110 struct qdma_virt_queue {
111         /** Status ring of the virtual queue */
112         struct rte_ring *status_ring;
113         /** Associated hw queue */
114         struct qdma_hw_queue *hw_queue;
115         /** Route by port */
116         struct rte_qdma_rbp rbp;
117         /** Associated lcore id */
118         uint32_t lcore_id;
119         /** States if this vq is in use or not */
120         uint8_t in_use;
121         /** States if this vq has exclusively associated hw queue */
122         uint8_t exclusive_hw_queue;
123         /* Total number of enqueues on this VQ */
124         uint64_t num_enqueues;
125         /* Total number of dequeues from this VQ */
126         uint64_t num_dequeues;
127
128         uint16_t vq_id;
129
130         qdma_set_fd_t *set_fd;
131         qdma_get_job_t *get_job;
132
133         qdma_dequeue_multijob_t *dequeue_job;
134         qdma_enqueue_multijob_t *enqueue_job;
135 };
136
137 /** Represents a QDMA per core hw queues allocation in virtual mode */
138 struct qdma_per_core_info {
139         /** list for allocated hw queues */
140         struct qdma_hw_queue *hw_queues[MAX_HW_QUEUE_PER_CORE];
141         /* Number of hw queues allocated for this core */
142         uint16_t num_hw_queues;
143 };
144
145 /** Source/Destination Descriptor */
146 struct qdma_sdd {
147         uint32_t rsv;
148         /** Stride configuration */
149         uint32_t stride;
150         /** Route-by-port command */
151         union {
152                 uint32_t rbpcmd;
153                 struct rbpcmd_st {
154                         uint32_t vfid:6;
155                         uint32_t rsv4:2;
156                         uint32_t pfid:1;
157                         uint32_t rsv3:7;
158                         uint32_t attr:3;
159                         uint32_t rsv2:1;
160                         uint32_t at:2;
161                         uint32_t vfa:1;
162                         uint32_t ca:1;
163                         uint32_t tc:3;
164                         uint32_t rsv1:5;
165                 } rbpcmd_simple;
166         };
167         union {
168                 uint32_t cmd;
169                 struct rcmd_simple {
170                         uint32_t portid:4;
171                         uint32_t rsv1:14;
172                         uint32_t rbp:1;
173                         uint32_t ssen:1;
174                         uint32_t rthrotl:4;
175                         uint32_t sqos:3;
176                         uint32_t ns:1;
177                         uint32_t rdtype:4;
178                 } read_cmd;
179                 struct wcmd_simple {
180                         uint32_t portid:4;
181                         uint32_t rsv3:10;
182                         uint32_t rsv2:2;
183                         uint32_t lwc:2;
184                         uint32_t rbp:1;
185                         uint32_t dsen:1;
186                         uint32_t rsv1:4;
187                         uint32_t dqos:3;
188                         uint32_t ns:1;
189                         uint32_t wrttype:4;
190                 } write_cmd;
191         };
192 } __rte_packed;
193
194 /** Represents a DPDMAI raw device */
195 struct dpaa2_dpdmai_dev {
196         /** Pointer to Next device instance */
197         TAILQ_ENTRY(dpaa2_qdma_device) next;
198         /** handle to DPDMAI object */
199         struct fsl_mc_io dpdmai;
200         /** HW ID for DPDMAI object */
201         uint32_t dpdmai_id;
202         /** Tocken of this device */
203         uint16_t token;
204         /** Number of queue in this DPDMAI device */
205         uint8_t num_queues;
206         /** RX queues */
207         struct dpaa2_queue rx_queue[DPAA2_DPDMAI_MAX_QUEUES];
208         /** TX queues */
209         struct dpaa2_queue tx_queue[DPAA2_DPDMAI_MAX_QUEUES];
210         struct qdma_device *qdma_dev;
211 };
212
213 static inline struct qdma_device *
214 QDMA_DEV_OF_VQ(struct qdma_virt_queue *vq)
215 {
216         return vq->hw_queue->dpdmai_dev->qdma_dev;
217 }
218
219 #endif /* __DPAA2_QDMA_H__ */