1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#undef QBMAN_CCSR_TRACE
24#undef QBMAN_CINH_TRACE
25#undef QBMAN_CENA_TRACE
26
27
28
29
30
31#define QBMAN_CINH_ONLY
32
33static inline void word_copy(void *d, const void *s, unsigned int cnt)
34{
35 uint32_t *dd = d;
36 const uint32_t *ss = s;
37
38 while (cnt--)
39 *(dd++) = *(ss++);
40}
41
42
43
44
45
46
47static inline void u64_to_le32_copy(void *d, const uint64_t *s,
48 unsigned int cnt)
49{
50 uint32_t *dd = d;
51 const uint32_t *ss = (const uint32_t *)s;
52
53 while (cnt--) {
54
55
56
57
58#if defined(__BIG_ENDIAN)
59 *(dd++) = ss[1];
60 *(dd++) = ss[0];
61 ss += 2;
62#else
63 *(dd++) = *(ss++);
64 *(dd++) = *(ss++);
65#endif
66 }
67}
68static inline void u64_from_le32_copy(uint64_t *d, const void *s,
69 unsigned int cnt)
70{
71 const uint32_t *ss = s;
72 uint32_t *dd = (uint32_t *)d;
73
74 while (cnt--) {
75#if defined(__BIG_ENDIAN)
76 dd[1] = *(ss++);
77 dd[0] = *(ss++);
78 dd += 2;
79#else
80 *(dd++) = *(ss++);
81 *(dd++) = *(ss++);
82#endif
83 }
84}
85
86
87#if defined(__BIG_ENDIAN)
88static inline uint32_t make_le32(uint32_t val)
89{
90 return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
91 ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
92}
93#else
94#define make_le32(val) (val)
95#endif
96static inline void make_le32_n(uint32_t *val, unsigned int num)
97{
98 while (num--) {
99 *val = make_le32(*val);
100 val++;
101 }
102}
103
104
105
106
107struct qbman_swp_sys {
108
109
110
111
112
113
114 void *cena;
115 void __iomem *addr_cena;
116 void __iomem *addr_cinh;
117};
118
119
120
121
122
123
124
125
126
127static inline void qbman_cinh_write(struct qbman_swp_sys *s, uint32_t offset,
128 uint32_t val)
129{
130 __raw_writel(val, s->addr_cinh + offset);
131#ifdef QBMAN_CINH_TRACE
132 pr_info("qbman_cinh_write(%p:0x%03x) 0x%08x\n",
133 s->addr_cinh, offset, val);
134#endif
135}
136
137static inline uint32_t qbman_cinh_read(struct qbman_swp_sys *s, uint32_t offset)
138{
139 uint32_t reg = __raw_readl(s->addr_cinh + offset);
140
141#ifdef QBMAN_CINH_TRACE
142 pr_info("qbman_cinh_read(%p:0x%03x) 0x%08x\n",
143 s->addr_cinh, offset, reg);
144#endif
145 return reg;
146}
147
148static inline void *qbman_cena_write_start(struct qbman_swp_sys *s,
149 uint32_t offset)
150{
151 void *shadow = s->cena + offset;
152
153#ifdef QBMAN_CENA_TRACE
154 pr_info("qbman_cena_write_start(%p:0x%03x) %p\n",
155 s->addr_cena, offset, shadow);
156#endif
157 BUG_ON(offset & 63);
158 dcbz(shadow);
159 return shadow;
160}
161
162static inline void qbman_cena_write_complete(struct qbman_swp_sys *s,
163 uint32_t offset, void *cmd)
164{
165 const uint32_t *shadow = cmd;
166 int loop;
167
168#ifdef QBMAN_CENA_TRACE
169 pr_info("qbman_cena_write_complete(%p:0x%03x) %p\n",
170 s->addr_cena, offset, shadow);
171 hexdump(cmd, 64);
172#endif
173 for (loop = 15; loop >= 0; loop--)
174#ifdef QBMAN_CINH_ONLY
175 __raw_writel(shadow[loop], s->addr_cinh +
176 offset + loop * 4);
177#else
178 __raw_writel(shadow[loop], s->addr_cena +
179 offset + loop * 4);
180#endif
181}
182
183static inline void *qbman_cena_read(struct qbman_swp_sys *s, uint32_t offset)
184{
185 uint32_t *shadow = s->cena + offset;
186 unsigned int loop;
187
188#ifdef QBMAN_CENA_TRACE
189 pr_info("qbman_cena_read(%p:0x%03x) %p\n",
190 s->addr_cena, offset, shadow);
191#endif
192
193 for (loop = 0; loop < 16; loop++)
194#ifdef QBMAN_CINH_ONLY
195 shadow[loop] = __raw_readl(s->addr_cinh + offset
196 + loop * 4);
197#else
198 shadow[loop] = __raw_readl(s->addr_cena + offset
199 + loop * 4);
200#endif
201#ifdef QBMAN_CENA_TRACE
202 hexdump(shadow, 64);
203#endif
204 return shadow;
205}
206
207static inline void qbman_cena_invalidate_prefetch(struct qbman_swp_sys *s,
208 uint32_t offset)
209{
210}
211
212
213
214
215
216
217
218
219#define QBMAN_CINH_SWP_CFG 0xd00
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234static inline uint32_t qbman_set_swp_cfg(uint8_t max_fill, uint8_t wn,
235 uint8_t est, uint8_t rpm, uint8_t dcm,
236 uint8_t epm, int sd, int sp, int se,
237 int dp, int de, int ep)
238{
239 uint32_t reg;
240
241 reg = e32_uint8_t(20, (uint32_t)(3 + (max_fill >> 3)), max_fill) |
242 e32_uint8_t(16, 3, est) | e32_uint8_t(12, 2, rpm) |
243 e32_uint8_t(10, 2, dcm) | e32_uint8_t(8, 2, epm) |
244 e32_int(5, 1, sd) | e32_int(4, 1, sp) | e32_int(3, 1, se) |
245 e32_int(2, 1, dp) | e32_int(1, 1, de) | e32_int(0, 1, ep) |
246 e32_uint8_t(14, 1, wn);
247 return reg;
248}
249
250static inline int qbman_swp_sys_init(struct qbman_swp_sys *s,
251 const struct qbman_swp_desc *d,
252 uint8_t dqrr_size)
253{
254 uint32_t reg;
255
256 s->addr_cena = d->cena_bar;
257 s->addr_cinh = d->cinh_bar;
258 s->cena = (void *)valloc(CONFIG_SYS_PAGE_SIZE);
259 if (!s->cena) {
260 printf("Could not allocate page for cena shadow\n");
261 return -1;
262 }
263 memset((void *)s->cena, 0x00, CONFIG_SYS_PAGE_SIZE);
264
265#ifdef QBMAN_CHECKING
266
267
268
269
270 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
271 BUG_ON(reg);
272#endif
273#ifdef QBMAN_CINH_ONLY
274 reg = qbman_set_swp_cfg(dqrr_size, 1, 0, 3, 2, 3, 0, 1, 0, 1, 0, 0);
275#else
276 reg = qbman_set_swp_cfg(dqrr_size, 0, 0, 3, 2, 3, 0, 1, 0, 1, 0, 0);
277#endif
278 qbman_cinh_write(s, QBMAN_CINH_SWP_CFG, reg);
279 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
280 if (!reg) {
281 printf("The portal is not enabled!\n");
282 free(s->cena);
283 return -1;
284 }
285 return 0;
286}
287
288static inline void qbman_swp_sys_finish(struct qbman_swp_sys *s)
289{
290 free((void *)s->cena);
291}
292