1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 /* qbman_sys_decl.h and qbman_sys.h are the two platform-specific files in the
7 * driver. They are only included via qbman_private.h, which is itself a
8 * platform-independent file and is included by all the other driver source.
10 * qbman_sys_decl.h is included prior to all other declarations and logic, and
11 * it exists to provide compatibility with any linux interfaces our
12 * single-source driver code is dependent on (eg. kmalloc). Ie. this file
13 * provides linux compatibility.
15 * This qbman_sys.h header, on the other hand, is included *after* any common
16 * and platform-neutral declarations and logic in qbman_private.h, and exists to
17 * implement any platform-specific logic of the qbman driver itself. Ie. it is
18 * *not* to provide linux compatibility.
21 #include "qbman_sys_decl.h"
23 /* Debugging assists */
24 static inline void __hexdump(unsigned long start, unsigned long end,
25 unsigned long p, size_t sz, const unsigned char *c)
32 pos += sprintf(buf + pos, "%08lx: ", start);
34 if ((start < p) || (start >= (p + sz)))
35 pos += sprintf(buf + pos, "..");
37 pos += sprintf(buf + pos, "%02x", *(c++));
38 if (!(++start & 15)) {
56 static inline void hexdump(const void *ptr, size_t sz)
58 unsigned long p = (unsigned long)ptr;
59 unsigned long start = p & ~15;
60 unsigned long end = (p + sz + 15) & ~15;
61 const unsigned char *c = ptr;
63 __hexdump(start, end, p, sz, c);
66 /* Currently, the CENA support code expects each 32-bit word to be written in
67 * host order, and these are converted to hardware (little-endian) order on
68 * command submission. However, 64-bit quantities are must be written (and read)
69 * as two 32-bit words with the least-significant word first, irrespective of
72 static inline void u64_to_le32_copy(void *d, const uint64_t *s,
76 const uint32_t *ss = (const uint32_t *)s;
79 /* TBD: the toolchain was choking on the use of 64-bit types up
80 * until recently so this works entirely with 32-bit variables.
81 * When 64-bit types become usable again, investigate better
84 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
95 static inline void u64_from_le32_copy(uint64_t *d, const void *s,
98 const uint32_t *ss = s;
99 uint32_t *dd = (uint32_t *)d;
102 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
116 struct qbman_swp_sys {
117 /* On GPP, the sys support for qbman_swp is here. The CENA region isi
118 * not an mmap() of the real portal registers, but an allocated
119 * place-holder, because the actual writes/reads to/from the portal are
120 * marshalled from these allocated areas using QBMan's "MC access
121 * registers". CINH accesses are atomic so there's no need for a
125 uint8_t __iomem *addr_cena;
126 uint8_t __iomem *addr_cinh;
128 enum qbman_eqcr_mode eqcr_mode;
131 /* P_OFFSET is (ACCESS_CMD,0,12) - offset within the portal
132 * C is (ACCESS_CMD,12,1) - is inhibited? (0==CENA, 1==CINH)
133 * SWP_IDX is (ACCESS_CMD,16,10) - Software portal index
134 * P is (ACCESS_CMD,28,1) - (0==special portal, 1==any portal)
135 * T is (ACCESS_CMD,29,1) - Command type (0==READ, 1==WRITE)
136 * E is (ACCESS_CMD,31,1) - Command execute (1 to issue, poll for 0==complete)
139 static inline void qbman_cinh_write(struct qbman_swp_sys *s, uint32_t offset,
142 __raw_writel(val, s->addr_cinh + offset);
143 #ifdef QBMAN_CINH_TRACE
144 pr_info("qbman_cinh_write(%p:%d:0x%03x) 0x%08x\n",
145 s->addr_cinh, s->idx, offset, val);
149 static inline uint32_t qbman_cinh_read(struct qbman_swp_sys *s, uint32_t offset)
151 uint32_t reg = __raw_readl(s->addr_cinh + offset);
152 #ifdef QBMAN_CINH_TRACE
153 pr_info("qbman_cinh_read(%p:%d:0x%03x) 0x%08x\n",
154 s->addr_cinh, s->idx, offset, reg);
159 static inline void *qbman_cena_write_start(struct qbman_swp_sys *s,
162 void *shadow = s->cena + offset;
164 #ifdef QBMAN_CENA_TRACE
165 pr_info("qbman_cena_write_start(%p:%d:0x%03x) %p\n",
166 s->addr_cena, s->idx, offset, shadow);
168 QBMAN_BUG_ON(offset & 63);
173 static inline void *qbman_cena_write_start_wo_shadow(struct qbman_swp_sys *s,
176 #ifdef QBMAN_CENA_TRACE
177 pr_info("qbman_cena_write_start(%p:%d:0x%03x)\n",
178 s->addr_cena, s->idx, offset);
180 QBMAN_BUG_ON(offset & 63);
181 return (s->addr_cena + offset);
184 static inline void qbman_cena_write_complete(struct qbman_swp_sys *s,
185 uint32_t offset, void *cmd)
187 const uint32_t *shadow = cmd;
189 #ifdef QBMAN_CENA_TRACE
190 pr_info("qbman_cena_write_complete(%p:%d:0x%03x) %p\n",
191 s->addr_cena, s->idx, offset, shadow);
194 for (loop = 15; loop >= 1; loop--)
195 __raw_writel(shadow[loop], s->addr_cena +
198 __raw_writel(shadow[0], s->addr_cena + offset);
199 dcbf(s->addr_cena + offset);
202 static inline void qbman_cena_write_complete_wo_shadow(struct qbman_swp_sys *s,
205 #ifdef QBMAN_CENA_TRACE
206 pr_info("qbman_cena_write_complete(%p:%d:0x%03x)\n",
207 s->addr_cena, s->idx, offset);
209 dcbf(s->addr_cena + offset);
212 static inline uint32_t qbman_cena_read_reg(struct qbman_swp_sys *s,
215 return __raw_readl(s->addr_cena + offset);
218 static inline void *qbman_cena_read(struct qbman_swp_sys *s, uint32_t offset)
220 uint32_t *shadow = (uint32_t *)(s->cena + offset);
222 #ifdef QBMAN_CENA_TRACE
223 pr_info("qbman_cena_read(%p:%d:0x%03x) %p\n",
224 s->addr_cena, s->idx, offset, shadow);
227 for (loop = 0; loop < 16; loop++)
228 shadow[loop] = __raw_readl(s->addr_cena + offset
230 #ifdef QBMAN_CENA_TRACE
236 static inline void *qbman_cena_read_wo_shadow(struct qbman_swp_sys *s,
239 #ifdef QBMAN_CENA_TRACE
240 pr_info("qbman_cena_read(%p:%d:0x%03x)\n",
241 s->addr_cena, s->idx, offset);
243 return s->addr_cena + offset;
246 static inline void qbman_cena_invalidate(struct qbman_swp_sys *s,
249 dccivac(s->addr_cena + offset);
252 static inline void qbman_cena_invalidate_prefetch(struct qbman_swp_sys *s,
255 dccivac(s->addr_cena + offset);
256 prefetch_for_load(s->addr_cena + offset);
259 static inline void qbman_cena_prefetch(struct qbman_swp_sys *s,
262 prefetch_for_load(s->addr_cena + offset);
269 /* The SWP_CFG portal register is special, in that it is used by the
270 * platform-specific code rather than the platform-independent code in
271 * qbman_portal.c. So use of it is declared locally here.
273 #define QBMAN_CINH_SWP_CFG 0xd00
274 #define QBMAN_CINH_SWP_CFG 0xd00
275 #define SWP_CFG_DQRR_MF_SHIFT 20
276 #define SWP_CFG_EST_SHIFT 16
277 #define SWP_CFG_WN_SHIFT 14
278 #define SWP_CFG_RPM_SHIFT 12
279 #define SWP_CFG_DCM_SHIFT 10
280 #define SWP_CFG_EPM_SHIFT 8
281 #define SWP_CFG_SD_SHIFT 5
282 #define SWP_CFG_SP_SHIFT 4
283 #define SWP_CFG_SE_SHIFT 3
284 #define SWP_CFG_DP_SHIFT 2
285 #define SWP_CFG_DE_SHIFT 1
286 #define SWP_CFG_EP_SHIFT 0
288 static inline uint32_t qbman_set_swp_cfg(uint8_t max_fill, uint8_t wn,
289 uint8_t est, uint8_t rpm, uint8_t dcm,
290 uint8_t epm, int sd, int sp, int se,
291 int dp, int de, int ep)
295 reg = (max_fill << SWP_CFG_DQRR_MF_SHIFT |
296 est << SWP_CFG_EST_SHIFT |
297 wn << SWP_CFG_WN_SHIFT |
298 rpm << SWP_CFG_RPM_SHIFT |
299 dcm << SWP_CFG_DCM_SHIFT |
300 epm << SWP_CFG_EPM_SHIFT |
301 sd << SWP_CFG_SD_SHIFT |
302 sp << SWP_CFG_SP_SHIFT |
303 se << SWP_CFG_SE_SHIFT |
304 dp << SWP_CFG_DP_SHIFT |
305 de << SWP_CFG_DE_SHIFT |
306 ep << SWP_CFG_EP_SHIFT);
311 static inline int qbman_swp_sys_init(struct qbman_swp_sys *s,
312 const struct qbman_swp_desc *d,
317 s->addr_cena = d->cena_bar;
318 s->addr_cinh = d->cinh_bar;
319 s->idx = (uint32_t)d->idx;
320 s->cena = malloc(4096);
322 pr_err("Could not allocate page for cena shadow\n");
325 s->eqcr_mode = d->eqcr_mode;
326 QBMAN_BUG_ON(d->idx < 0);
327 #ifdef QBMAN_CHECKING
328 /* We should never be asked to initialise for a portal that isn't in
329 * the power-on state. (Ie. don't forget to reset portals when they are
332 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
335 if (s->eqcr_mode == qman_eqcr_vb_array)
336 reg = qbman_set_swp_cfg(dqrr_size, 0, 0, 3, 2, 3, 1, 1, 1, 1,
339 reg = qbman_set_swp_cfg(dqrr_size, 0, 1, 3, 2, 2, 1, 1, 1, 1,
341 qbman_cinh_write(s, QBMAN_CINH_SWP_CFG, reg);
342 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
344 pr_err("The portal %d is not enabled!\n", s->idx);
351 static inline void qbman_swp_sys_finish(struct qbman_swp_sys *s)