1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2014 Freescale Semiconductor
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 /* Trace the 3 different classes of read/write access to QBMan. #undef as
23 #undef QBMAN_CCSR_TRACE
24 #undef QBMAN_CINH_TRACE
25 #undef QBMAN_CENA_TRACE
27 /* Temporarily define this to get around the fact that cache enabled mapping is
28 * not working right now. Will remove this after uboot could map the cache
29 * enabled portal memory.
31 #define QBMAN_CINH_ONLY
33 static inline void word_copy(void *d, const void *s, unsigned int cnt)
36 const uint32_t *ss = s;
42 /* Currently, the CENA support code expects each 32-bit word to be written in
43 * host order, and these are converted to hardware (little-endian) order on
44 * command submission. However, 64-bit quantities are must be written (and read)
45 * as two 32-bit words with the least-significant word first, irrespective of
47 static inline void u64_to_le32_copy(void *d, const uint64_t *s,
51 const uint32_t *ss = (const uint32_t *)s;
54 /* TBD: the toolchain was choking on the use of 64-bit types up
55 * until recently so this works entirely with 32-bit variables.
56 * When 64-bit types become usable again, investigate better
57 * ways of doing this. */
58 #if defined(__BIG_ENDIAN)
68 static inline void u64_from_le32_copy(uint64_t *d, const void *s,
71 const uint32_t *ss = s;
72 uint32_t *dd = (uint32_t *)d;
75 #if defined(__BIG_ENDIAN)
86 /* Convert a host-native 32bit value into little endian */
87 #if defined(__BIG_ENDIAN)
88 static inline uint32_t make_le32(uint32_t val)
90 return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
91 ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
94 #define make_le32(val) (val)
96 static inline void make_le32_n(uint32_t *val, unsigned int num)
99 *val = make_le32(*val);
107 struct qbman_swp_sys {
108 /* On GPP, the sys support for qbman_swp is here. The CENA region isi
109 * not an mmap() of the real portal registers, but an allocated
110 * place-holder, because the actual writes/reads to/from the portal are
111 * marshalled from these allocated areas using QBMan's "MC access
112 * registers". CINH accesses are atomic so there's no need for a
115 void __iomem *addr_cena;
116 void __iomem *addr_cinh;
119 /* P_OFFSET is (ACCESS_CMD,0,12) - offset within the portal
120 * C is (ACCESS_CMD,12,1) - is inhibited? (0==CENA, 1==CINH)
121 * SWP_IDX is (ACCESS_CMD,16,10) - Software portal index
122 * P is (ACCESS_CMD,28,1) - (0==special portal, 1==any portal)
123 * T is (ACCESS_CMD,29,1) - Command type (0==READ, 1==WRITE)
124 * E is (ACCESS_CMD,31,1) - Command execute (1 to issue, poll for 0==complete)
127 static inline void qbman_cinh_write(struct qbman_swp_sys *s, uint32_t offset,
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);
137 static inline uint32_t qbman_cinh_read(struct qbman_swp_sys *s, uint32_t offset)
139 uint32_t reg = __raw_readl(s->addr_cinh + offset);
141 #ifdef QBMAN_CINH_TRACE
142 pr_info("qbman_cinh_read(%p:0x%03x) 0x%08x\n",
143 s->addr_cinh, offset, reg);
148 static inline void *qbman_cena_write_start(struct qbman_swp_sys *s,
151 void *shadow = s->cena + offset;
153 #ifdef QBMAN_CENA_TRACE
154 pr_info("qbman_cena_write_start(%p:0x%03x) %p\n",
155 s->addr_cena, offset, shadow);
162 static inline void qbman_cena_write_complete(struct qbman_swp_sys *s,
163 uint32_t offset, void *cmd)
165 const uint32_t *shadow = cmd;
168 #ifdef QBMAN_CENA_TRACE
169 pr_info("qbman_cena_write_complete(%p:0x%03x) %p\n",
170 s->addr_cena, offset, shadow);
173 for (loop = 15; loop >= 0; loop--)
174 #ifdef QBMAN_CINH_ONLY
175 __raw_writel(shadow[loop], s->addr_cinh +
178 __raw_writel(shadow[loop], s->addr_cena +
183 static inline void *qbman_cena_read(struct qbman_swp_sys *s, uint32_t offset)
185 uint32_t *shadow = s->cena + offset;
188 #ifdef QBMAN_CENA_TRACE
189 pr_info("qbman_cena_read(%p:0x%03x) %p\n",
190 s->addr_cena, offset, shadow);
193 for (loop = 0; loop < 16; loop++)
194 #ifdef QBMAN_CINH_ONLY
195 shadow[loop] = __raw_readl(s->addr_cinh + offset
198 shadow[loop] = __raw_readl(s->addr_cena + offset
201 #ifdef QBMAN_CENA_TRACE
207 static inline void qbman_cena_invalidate_prefetch(struct qbman_swp_sys *s,
216 /* The SWP_CFG portal register is special, in that it is used by the
217 * platform-specific code rather than the platform-independent code in
218 * qbman_portal.c. So use of it is declared locally here. */
219 #define QBMAN_CINH_SWP_CFG 0xd00
221 /* For MC portal use, we always configure with
222 * DQRR_MF is (SWP_CFG,20,3) - DQRR max fill (<- 0x4)
223 * EST is (SWP_CFG,16,3) - EQCR_CI stashing threshold (<- 0x0)
224 * RPM is (SWP_CFG,12,2) - RCR production notification mode (<- 0x3)
225 * DCM is (SWP_CFG,10,2) - DQRR consumption notification mode (<- 0x2)
226 * EPM is (SWP_CFG,8,2) - EQCR production notification mode (<- 0x3)
227 * SD is (SWP_CFG,5,1) - memory stashing drop enable (<- FALSE)
228 * SP is (SWP_CFG,4,1) - memory stashing priority (<- TRUE)
229 * SE is (SWP_CFG,3,1) - memory stashing enable (<- 0x0)
230 * DP is (SWP_CFG,2,1) - dequeue stashing priority (<- TRUE)
231 * DE is (SWP_CFG,1,1) - dequeue stashing enable (<- 0x0)
232 * EP is (SWP_CFG,0,1) - EQCR_CI stashing priority (<- FALSE)
234 static 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)
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);
250 static inline int qbman_swp_sys_init(struct qbman_swp_sys *s,
251 const struct qbman_swp_desc *d,
256 s->addr_cena = d->cena_bar;
257 s->addr_cinh = d->cinh_bar;
258 s->cena = (void *)valloc(CONFIG_SYS_PAGE_SIZE);
260 printf("Could not allocate page for cena shadow\n");
263 memset((void *)s->cena, 0x00, CONFIG_SYS_PAGE_SIZE);
265 #ifdef QBMAN_CHECKING
266 /* We should never be asked to initialise for a portal that isn't in
267 * the power-on state. (Ie. don't forget to reset portals when they are
270 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
273 #ifdef QBMAN_CINH_ONLY
274 reg = qbman_set_swp_cfg(dqrr_size, 1, 0, 3, 2, 3, 0, 1, 0, 1, 0, 0);
276 reg = qbman_set_swp_cfg(dqrr_size, 0, 0, 3, 2, 3, 0, 1, 0, 1, 0, 0);
278 qbman_cinh_write(s, QBMAN_CINH_SWP_CFG, reg);
279 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
281 printf("The portal is not enabled!\n");
288 static inline void qbman_swp_sys_finish(struct qbman_swp_sys *s)
290 free((void *)s->cena);