1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
33#include "dpaa_sys.h"
34
35#include <soc/fsl/qman.h>
36#include <linux/dma-mapping.h>
37#include <linux/iommu.h>
38
39#if defined(CONFIG_FSL_PAMU)
40#include <asm/fsl_pamu_stash.h>
41#endif
42
43struct qm_mcr_querywq {
44 u8 verb;
45 u8 result;
46 u16 channel_wq;
47 u8 __reserved[28];
48 u32 wq_len[8];
49} __packed;
50
51static inline u16 qm_mcr_querywq_get_chan(const struct qm_mcr_querywq *wq)
52{
53 return wq->channel_wq >> 3;
54}
55
56struct __qm_mcr_querycongestion {
57 u32 state[8];
58};
59
60
61struct qm_mcr_querycongestion {
62 u8 verb;
63 u8 result;
64 u8 __reserved[30];
65
66 struct __qm_mcr_querycongestion state;
67} __packed;
68
69
70struct qm_mcr_querycgr {
71 u8 verb;
72 u8 result;
73 u16 __reserved1;
74 struct __qm_mc_cgr cgr;
75 u8 __reserved2[6];
76 u8 i_bcnt_hi;
77 __be32 i_bcnt_lo;
78 u8 __reserved3[3];
79 u8 a_bcnt_hi;
80 __be32 a_bcnt_lo;
81 __be32 cscn_targ_swp[4];
82} __packed;
83
84static inline u64 qm_mcr_querycgr_i_get64(const struct qm_mcr_querycgr *q)
85{
86 return ((u64)q->i_bcnt_hi << 32) | be32_to_cpu(q->i_bcnt_lo);
87}
88static inline u64 qm_mcr_querycgr_a_get64(const struct qm_mcr_querycgr *q)
89{
90 return ((u64)q->a_bcnt_hi << 32) | be32_to_cpu(q->a_bcnt_lo);
91}
92
93
94
95
96
97
98
99
100
101#define CGR_BITS_PER_WORD 5
102#define CGR_WORD(x) ((x) >> CGR_BITS_PER_WORD)
103#define CGR_BIT(x) (BIT(31) >> ((x) & 0x1f))
104#define CGR_NUM (sizeof(struct __qm_mcr_querycongestion) << 3)
105
106struct qman_cgrs {
107 struct __qm_mcr_querycongestion q;
108};
109
110static inline void qman_cgrs_init(struct qman_cgrs *c)
111{
112 memset(c, 0, sizeof(*c));
113}
114
115static inline void qman_cgrs_fill(struct qman_cgrs *c)
116{
117 memset(c, 0xff, sizeof(*c));
118}
119
120static inline int qman_cgrs_get(struct qman_cgrs *c, u8 cgr)
121{
122 return c->q.state[CGR_WORD(cgr)] & CGR_BIT(cgr);
123}
124
125static inline void qman_cgrs_cp(struct qman_cgrs *dest,
126 const struct qman_cgrs *src)
127{
128 *dest = *src;
129}
130
131static inline void qman_cgrs_and(struct qman_cgrs *dest,
132 const struct qman_cgrs *a, const struct qman_cgrs *b)
133{
134 int ret;
135 u32 *_d = dest->q.state;
136 const u32 *_a = a->q.state;
137 const u32 *_b = b->q.state;
138
139 for (ret = 0; ret < 8; ret++)
140 *_d++ = *_a++ & *_b++;
141}
142
143static inline void qman_cgrs_xor(struct qman_cgrs *dest,
144 const struct qman_cgrs *a, const struct qman_cgrs *b)
145{
146 int ret;
147 u32 *_d = dest->q.state;
148 const u32 *_a = a->q.state;
149 const u32 *_b = b->q.state;
150
151 for (ret = 0; ret < 8; ret++)
152 *_d++ = *_a++ ^ *_b++;
153}
154
155void qman_init_cgr_all(void);
156
157struct qm_portal_config {
158
159
160
161
162 void __iomem *addr_virt[2];
163 struct device *dev;
164 struct iommu_domain *iommu_domain;
165
166 struct list_head list;
167
168
169 int cpu;
170
171 int irq;
172
173
174
175
176 u16 channel;
177
178
179
180
181 u32 pools;
182};
183
184
185#define QMAN_REV11 0x0101
186#define QMAN_REV12 0x0102
187#define QMAN_REV20 0x0200
188#define QMAN_REV30 0x0300
189#define QMAN_REV31 0x0301
190extern u16 qman_ip_rev;
191
192#define QM_FQID_RANGE_START 1
193extern struct gen_pool *qm_fqalloc;
194extern struct gen_pool *qm_qpalloc;
195extern struct gen_pool *qm_cgralloc;
196u32 qm_get_pools_sdqcr(void);
197
198int qman_wq_alloc(void);
199void qman_liodn_fixup(u16 channel);
200void qman_set_sdest(u16 channel, unsigned int cpu_idx);
201
202struct qman_portal *qman_create_affine_portal(
203 const struct qm_portal_config *config,
204 const struct qman_cgrs *cgrs);
205const struct qm_portal_config *qman_destroy_affine_portal(void);
206
207
208
209
210
211
212int qman_query_fq(struct qman_fq *fq, struct qm_fqd *fqd);
213
214int qman_alloc_fq_table(u32 num_fqids);
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231#define QM_SDQCR_SOURCE_CHANNELS 0x0
232#define QM_SDQCR_SOURCE_SPECIFICWQ 0x40000000
233#define QM_SDQCR_COUNT_EXACT1 0x0
234#define QM_SDQCR_COUNT_UPTO3 0x20000000
235#define QM_SDQCR_DEDICATED_PRECEDENCE 0x10000000
236#define QM_SDQCR_TYPE_MASK 0x03000000
237#define QM_SDQCR_TYPE_NULL 0x0
238#define QM_SDQCR_TYPE_PRIO_QOS 0x01000000
239#define QM_SDQCR_TYPE_ACTIVE_QOS 0x02000000
240#define QM_SDQCR_TYPE_ACTIVE 0x03000000
241#define QM_SDQCR_TOKEN_MASK 0x00ff0000
242#define QM_SDQCR_TOKEN_SET(v) (((v) & 0xff) << 16)
243#define QM_SDQCR_TOKEN_GET(v) (((v) >> 16) & 0xff)
244#define QM_SDQCR_CHANNELS_DEDICATED 0x00008000
245#define QM_SDQCR_SPECIFICWQ_MASK 0x000000f7
246#define QM_SDQCR_SPECIFICWQ_DEDICATED 0x00000000
247#define QM_SDQCR_SPECIFICWQ_POOL(n) ((n) << 4)
248#define QM_SDQCR_SPECIFICWQ_WQ(n) (n)
249
250
251#define QM_VDQCR_FQID_MASK 0x00ffffff
252#define QM_VDQCR_FQID(n) ((n) & QM_VDQCR_FQID_MASK)
253
254
255
256
257
258#define QM_PIRQ_DQAVAIL 0x0000ffff
259
260
261#define QM_DQAVAIL_PORTAL 0x8000
262#define QM_DQAVAIL_POOL(n) (0x8000 >> (n))
263#define QM_DQAVAIL_MASK 0xffff
264
265#define QM_PIRQ_VISIBLE (QM_PIRQ_SLOW | QM_PIRQ_DQRI)
266
267extern struct qman_portal *affine_portals[NR_CPUS];
268extern struct qman_portal *qman_dma_portal;
269const struct qm_portal_config *qman_get_qm_portal_config(
270 struct qman_portal *portal);
271