4 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 /* qbman_sys_decl.h and qbman_sys.h are the two platform-specific files in the
29 * driver. They are only included via qbman_private.h, which is itself a
30 * platform-independent file and is included by all the other driver source.
32 * qbman_sys_decl.h is included prior to all other declarations and logic, and
33 * it exists to provide compatibility with any linux interfaces our
34 * single-source driver code is dependent on (eg. kmalloc). Ie. this file
35 * provides linux compatibility.
37 * This qbman_sys.h header, on the other hand, is included *after* any common
38 * and platform-neutral declarations and logic in qbman_private.h, and exists to
39 * implement any platform-specific logic of the qbman driver itself. Ie. it is
40 * *not* to provide linux compatibility.
43 /* Trace the 3 different classes of read/write access to QBMan. #undef as
46 #undef QBMAN_CCSR_TRACE
47 #undef QBMAN_CINH_TRACE
48 #undef QBMAN_CENA_TRACE
50 /* Currently, the CENA support code expects each 32-bit word to be written in
51 * host order, and these are converted to hardware (little-endian) order on
52 * command submission. However, 64-bit quantities are must be written (and read)
53 * as two 32-bit words with the least-significant word first, irrespective of
56 static inline void u64_to_le32_copy(void *d, const uint64_t *s,
60 const uint32_t *ss = (const uint32_t *)s;
63 /* TBD: the toolchain was choking on the use of 64-bit types up
64 * until recently so this works entirely with 32-bit variables.
65 * When 64-bit types become usable again, investigate better
68 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
79 static inline void u64_from_le32_copy(uint64_t *d, const void *s,
82 const uint32_t *ss = s;
83 uint32_t *dd = (uint32_t *)d;
86 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
97 /* Convert a host-native 32bit value into little endian */
98 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
99 static inline uint32_t make_le32(uint32_t val)
101 return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
102 ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
105 static inline uint32_t make_le24(uint32_t val)
107 return (((val & 0xff) << 16) | (val & 0xff00) |
108 ((val & 0xff0000) >> 16));
111 static inline void make_le32_n(uint32_t *val, unsigned int num)
114 *val = make_le32(*val);
120 #define make_le32(val) (val)
121 #define make_le24(val) (val)
122 #define make_le32_n(val, len) do {} while (0)
128 struct qbman_swp_sys {
129 /* On GPP, the sys support for qbman_swp is here. The CENA region isi
130 * not an mmap() of the real portal registers, but an allocated
131 * place-holder, because the actual writes/reads to/from the portal are
132 * marshalled from these allocated areas using QBMan's "MC access
133 * registers". CINH accesses are atomic so there's no need for a
137 uint8_t __iomem *addr_cena;
138 uint8_t __iomem *addr_cinh;
140 enum qbman_eqcr_mode eqcr_mode;
143 /* P_OFFSET is (ACCESS_CMD,0,12) - offset within the portal
144 * C is (ACCESS_CMD,12,1) - is inhibited? (0==CENA, 1==CINH)
145 * SWP_IDX is (ACCESS_CMD,16,10) - Software portal index
146 * P is (ACCESS_CMD,28,1) - (0==special portal, 1==any portal)
147 * T is (ACCESS_CMD,29,1) - Command type (0==READ, 1==WRITE)
148 * E is (ACCESS_CMD,31,1) - Command execute (1 to issue, poll for 0==complete)
151 static inline void qbman_cinh_write(struct qbman_swp_sys *s, uint32_t offset,
154 __raw_writel(val, s->addr_cinh + offset);
155 #ifdef QBMAN_CINH_TRACE
156 pr_info("qbman_cinh_write(%p:%d:0x%03x) 0x%08x\n",
157 s->addr_cinh, s->idx, offset, val);
161 static inline uint32_t qbman_cinh_read(struct qbman_swp_sys *s, uint32_t offset)
163 uint32_t reg = __raw_readl(s->addr_cinh + offset);
164 #ifdef QBMAN_CINH_TRACE
165 pr_info("qbman_cinh_read(%p:%d:0x%03x) 0x%08x\n",
166 s->addr_cinh, s->idx, offset, reg);
171 static inline void *qbman_cena_write_start(struct qbman_swp_sys *s,
174 void *shadow = s->cena + offset;
176 #ifdef QBMAN_CENA_TRACE
177 pr_info("qbman_cena_write_start(%p:%d:0x%03x) %p\n",
178 s->addr_cena, s->idx, offset, shadow);
180 QBMAN_BUG_ON(offset & 63);
185 static inline void *qbman_cena_write_start_wo_shadow(struct qbman_swp_sys *s,
188 #ifdef QBMAN_CENA_TRACE
189 pr_info("qbman_cena_write_start(%p:%d:0x%03x)\n",
190 s->addr_cena, s->idx, offset);
192 QBMAN_BUG_ON(offset & 63);
193 return (s->addr_cena + offset);
196 static inline void qbman_cena_write_complete(struct qbman_swp_sys *s,
197 uint32_t offset, void *cmd)
199 const uint32_t *shadow = cmd;
201 #ifdef QBMAN_CENA_TRACE
202 pr_info("qbman_cena_write_complete(%p:%d:0x%03x) %p\n",
203 s->addr_cena, s->idx, offset, shadow);
206 for (loop = 15; loop >= 1; loop--)
207 __raw_writel(shadow[loop], s->addr_cena +
210 __raw_writel(shadow[0], s->addr_cena + offset);
211 dcbf(s->addr_cena + offset);
214 static inline void qbman_cena_write_complete_wo_shadow(struct qbman_swp_sys *s,
217 #ifdef QBMAN_CENA_TRACE
218 pr_info("qbman_cena_write_complete(%p:%d:0x%03x)\n",
219 s->addr_cena, s->idx, offset);
222 dcbf(s->addr_cena + offset);
225 static inline uint32_t qbman_cena_read_reg(struct qbman_swp_sys *s,
228 return __raw_readl(s->addr_cena + offset);
231 static inline void *qbman_cena_read(struct qbman_swp_sys *s, uint32_t offset)
233 uint32_t *shadow = (uint32_t *)(s->cena + offset);
235 #ifdef QBMAN_CENA_TRACE
236 pr_info("qbman_cena_read(%p:%d:0x%03x) %p\n",
237 s->addr_cena, s->idx, offset, shadow);
240 for (loop = 0; loop < 16; loop++)
241 shadow[loop] = __raw_readl(s->addr_cena + offset
243 #ifdef QBMAN_CENA_TRACE
249 static inline void *qbman_cena_read_wo_shadow(struct qbman_swp_sys *s,
252 #ifdef QBMAN_CENA_TRACE
253 pr_info("qbman_cena_read(%p:%d:0x%03x) %p\n",
254 s->addr_cena, s->idx, offset, shadow);
257 #ifdef QBMAN_CENA_TRACE
260 return s->addr_cena + offset;
263 static inline void qbman_cena_invalidate(struct qbman_swp_sys *s,
266 dccivac(s->addr_cena + offset);
269 static inline void qbman_cena_invalidate_prefetch(struct qbman_swp_sys *s,
272 dccivac(s->addr_cena + offset);
273 prefetch_for_load(s->addr_cena + offset);
276 static inline void qbman_cena_prefetch(struct qbman_swp_sys *s,
279 prefetch_for_load(s->addr_cena + offset);
286 /* The SWP_CFG portal register is special, in that it is used by the
287 * platform-specific code rather than the platform-independent code in
288 * qbman_portal.c. So use of it is declared locally here.
290 #define QBMAN_CINH_SWP_CFG 0xd00
292 /* For MC portal use, we always configure with
293 * DQRR_MF is (SWP_CFG,20,3) - DQRR max fill (<- 0x4)
294 * EST is (SWP_CFG,16,3) - EQCR_CI stashing threshold (<- 0x2)
295 * RPM is (SWP_CFG,12,2) - RCR production notification mode (<- 0x3)
296 * DCM is (SWP_CFG,10,2) - DQRR consumption notification mode (<- 0x2)
297 * EPM is (SWP_CFG,8,2) - EQCR production notification mode (<- 0x2)
298 * SD is (SWP_CFG,5,1) - memory stashing drop enable (<- TRUE)
299 * SP is (SWP_CFG,4,1) - memory stashing priority (<- TRUE)
300 * SE is (SWP_CFG,3,1) - memory stashing enable (<- TRUE)
301 * DP is (SWP_CFG,2,1) - dequeue stashing priority (<- TRUE)
302 * DE is (SWP_CFG,1,1) - dequeue stashing enable (<- TRUE)
303 * EP is (SWP_CFG,0,1) - EQCR_CI stashing priority (<- TRUE)
305 static inline uint32_t qbman_set_swp_cfg(uint8_t max_fill, uint8_t wn,
306 uint8_t est, uint8_t rpm, uint8_t dcm,
307 uint8_t epm, int sd, int sp, int se,
308 int dp, int de, int ep)
312 reg = e32_uint8_t(20, (uint32_t)(3 + (max_fill >> 3)), max_fill) |
313 e32_uint8_t(16, 3, est) |
314 e32_uint8_t(12, 2, rpm) | e32_uint8_t(10, 2, dcm) |
315 e32_uint8_t(8, 2, epm) | e32_int(5, 1, sd) |
316 e32_int(4, 1, sp) | e32_int(3, 1, se) | e32_int(2, 1, dp) |
317 e32_int(1, 1, de) | e32_int(0, 1, ep) | e32_uint8_t(14, 1, wn);
321 static inline int qbman_swp_sys_init(struct qbman_swp_sys *s,
322 const struct qbman_swp_desc *d,
327 s->addr_cena = d->cena_bar;
328 s->addr_cinh = d->cinh_bar;
329 s->idx = (uint32_t)d->idx;
330 s->cena = (void *)get_zeroed_page(GFP_KERNEL);
332 pr_err("Could not allocate page for cena shadow\n");
335 s->eqcr_mode = d->eqcr_mode;
336 QBMAN_BUG_ON(d->idx < 0);
337 #ifdef QBMAN_CHECKING
338 /* We should never be asked to initialise for a portal that isn't in
339 * the power-on state. (Ie. don't forget to reset portals when they are
342 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
345 if (s->eqcr_mode == qman_eqcr_vb_array)
346 reg = qbman_set_swp_cfg(dqrr_size, 0, 0, 3, 2, 3, 1, 1, 1, 1,
349 reg = qbman_set_swp_cfg(dqrr_size, 0, 2, 3, 2, 2, 1, 1, 1, 1,
351 qbman_cinh_write(s, QBMAN_CINH_SWP_CFG, reg);
352 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
354 pr_err("The portal %d is not enabled!\n", s->idx);
361 static inline void qbman_swp_sys_finish(struct qbman_swp_sys *s)
363 free_page((unsigned long)s->cena);
367 qbman_cena_write_start_wo_shadow_fast(struct qbman_swp_sys *s,
370 #ifdef QBMAN_CENA_TRACE
371 pr_info("qbman_cena_write_start(%p:%d:0x%03x)\n",
372 s->addr_cena, s->idx, offset);
374 QBMAN_BUG_ON(offset & 63);
375 return (s->addr_cena + offset);