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