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);
221 dcbf(s->addr_cena + offset);
224 static inline uint32_t qbman_cena_read_reg(struct qbman_swp_sys *s,
227 return __raw_readl(s->addr_cena + offset);
230 static inline void *qbman_cena_read(struct qbman_swp_sys *s, uint32_t offset)
232 uint32_t *shadow = (uint32_t *)(s->cena + offset);
234 #ifdef QBMAN_CENA_TRACE
235 pr_info("qbman_cena_read(%p:%d:0x%03x) %p\n",
236 s->addr_cena, s->idx, offset, shadow);
239 for (loop = 0; loop < 16; loop++)
240 shadow[loop] = __raw_readl(s->addr_cena + offset
242 #ifdef QBMAN_CENA_TRACE
248 static inline void *qbman_cena_read_wo_shadow(struct qbman_swp_sys *s,
251 #ifdef QBMAN_CENA_TRACE
252 pr_info("qbman_cena_read(%p:%d:0x%03x) %p\n",
253 s->addr_cena, s->idx, offset);
255 return s->addr_cena + offset;
258 static inline void qbman_cena_invalidate(struct qbman_swp_sys *s,
261 dccivac(s->addr_cena + offset);
264 static inline void qbman_cena_invalidate_prefetch(struct qbman_swp_sys *s,
267 dccivac(s->addr_cena + offset);
268 prefetch_for_load(s->addr_cena + offset);
271 static inline void qbman_cena_prefetch(struct qbman_swp_sys *s,
274 prefetch_for_load(s->addr_cena + offset);
281 /* The SWP_CFG portal register is special, in that it is used by the
282 * platform-specific code rather than the platform-independent code in
283 * qbman_portal.c. So use of it is declared locally here.
285 #define QBMAN_CINH_SWP_CFG 0xd00
287 /* For MC portal use, we always configure with
288 * DQRR_MF is (SWP_CFG,20,3) - DQRR max fill (<- 0x4)
289 * EST is (SWP_CFG,16,3) - EQCR_CI stashing threshold (<- 0x2)
290 * RPM is (SWP_CFG,12,2) - RCR production notification mode (<- 0x3)
291 * DCM is (SWP_CFG,10,2) - DQRR consumption notification mode (<- 0x2)
292 * EPM is (SWP_CFG,8,2) - EQCR production notification mode (<- 0x2)
293 * SD is (SWP_CFG,5,1) - memory stashing drop enable (<- TRUE)
294 * SP is (SWP_CFG,4,1) - memory stashing priority (<- TRUE)
295 * SE is (SWP_CFG,3,1) - memory stashing enable (<- TRUE)
296 * DP is (SWP_CFG,2,1) - dequeue stashing priority (<- TRUE)
297 * DE is (SWP_CFG,1,1) - dequeue stashing enable (<- TRUE)
298 * EP is (SWP_CFG,0,1) - EQCR_CI stashing priority (<- TRUE)
300 static inline uint32_t qbman_set_swp_cfg(uint8_t max_fill, uint8_t wn,
301 uint8_t est, uint8_t rpm, uint8_t dcm,
302 uint8_t epm, int sd, int sp, int se,
303 int dp, int de, int ep)
307 reg = e32_uint8_t(20, (uint32_t)(3 + (max_fill >> 3)), max_fill) |
308 e32_uint8_t(16, 3, est) |
309 e32_uint8_t(12, 2, rpm) | e32_uint8_t(10, 2, dcm) |
310 e32_uint8_t(8, 2, epm) | e32_int(5, 1, sd) |
311 e32_int(4, 1, sp) | e32_int(3, 1, se) | e32_int(2, 1, dp) |
312 e32_int(1, 1, de) | e32_int(0, 1, ep) | e32_uint8_t(14, 1, wn);
316 static inline int qbman_swp_sys_init(struct qbman_swp_sys *s,
317 const struct qbman_swp_desc *d,
322 s->addr_cena = d->cena_bar;
323 s->addr_cinh = d->cinh_bar;
324 s->idx = (uint32_t)d->idx;
325 s->cena = (void *)get_zeroed_page(GFP_KERNEL);
327 pr_err("Could not allocate page for cena shadow\n");
330 s->eqcr_mode = d->eqcr_mode;
331 QBMAN_BUG_ON(d->idx < 0);
332 #ifdef QBMAN_CHECKING
333 /* We should never be asked to initialise for a portal that isn't in
334 * the power-on state. (Ie. don't forget to reset portals when they are
337 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
340 if (s->eqcr_mode == qman_eqcr_vb_array)
341 reg = qbman_set_swp_cfg(dqrr_size, 0, 0, 3, 2, 3, 1, 1, 1, 1,
344 reg = qbman_set_swp_cfg(dqrr_size, 0, 2, 3, 2, 2, 1, 1, 1, 1,
346 qbman_cinh_write(s, QBMAN_CINH_SWP_CFG, reg);
347 reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
349 pr_err("The portal %d is not enabled!\n", s->idx);
356 static inline void qbman_swp_sys_finish(struct qbman_swp_sys *s)
358 free_page((unsigned long)s->cena);