1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (C) 2014 Freescale Semiconductor
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun /* Perform extra checking */
8*4882a593Smuzhiyun #include <common.h>
9*4882a593Smuzhiyun #include <errno.h>
10*4882a593Smuzhiyun #include <asm/io.h>
11*4882a593Smuzhiyun #include <linux/types.h>
12*4882a593Smuzhiyun #include <asm/atomic.h>
13*4882a593Smuzhiyun #include <malloc.h>
14*4882a593Smuzhiyun #include <asm/arch/soc.h>
15*4882a593Smuzhiyun #include <fsl-mc/fsl_qbman_base.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #define QBMAN_CHECKING
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun /* Any time there is a register interface which we poll on, this provides a
20*4882a593Smuzhiyun * "break after x iterations" scheme for it. It's handy for debugging, eg.
21*4882a593Smuzhiyun * where you don't want millions of lines of log output from a polling loop
22*4882a593Smuzhiyun * that won't, because such things tend to drown out the earlier log output
23*4882a593Smuzhiyun * that might explain what caused the problem. (NB: put ";" after each macro!)
24*4882a593Smuzhiyun * TODO: we should probably remove this once we're done sanitising the
25*4882a593Smuzhiyun * simulator...
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun #define DBG_POLL_START(loopvar) (loopvar = 10)
28*4882a593Smuzhiyun #define DBG_POLL_CHECK(loopvar) \
29*4882a593Smuzhiyun do {if (!(loopvar--)) BUG_ON(NULL == "DBG_POLL_CHECK"); } while (0)
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /* For CCSR or portal-CINH registers that contain fields at arbitrary offsets
32*4882a593Smuzhiyun * and widths, these macro-generated encode/decode/isolate/remove inlines can
33*4882a593Smuzhiyun * be used.
34*4882a593Smuzhiyun *
35*4882a593Smuzhiyun * Eg. to "d"ecode a 14-bit field out of a register (into a "uint16_t" type),
36*4882a593Smuzhiyun * where the field is located 3 bits "up" from the least-significant bit of the
37*4882a593Smuzhiyun * register (ie. the field location within the 32-bit register corresponds to a
38*4882a593Smuzhiyun * mask of 0x0001fff8), you would do;
39*4882a593Smuzhiyun * uint16_t field = d32_uint16_t(3, 14, reg_value);
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * Or to "e"ncode a 1-bit boolean value (input type is "int", zero is FALSE,
42*4882a593Smuzhiyun * non-zero is TRUE, so must convert all non-zero inputs to 1, hence the "!!"
43*4882a593Smuzhiyun * operator) into a register at bit location 0x00080000 (19 bits "in" from the
44*4882a593Smuzhiyun * LS bit), do;
45*4882a593Smuzhiyun * reg_value |= e32_int(19, 1, !!field);
46*4882a593Smuzhiyun *
47*4882a593Smuzhiyun * If you wish to read-modify-write a register, such that you leave the 14-bit
48*4882a593Smuzhiyun * field as-is but have all other fields set to zero, then "i"solate the 14-bit
49*4882a593Smuzhiyun * value using;
50*4882a593Smuzhiyun * reg_value = i32_uint16_t(3, 14, reg_value);
51*4882a593Smuzhiyun *
52*4882a593Smuzhiyun * Alternatively, you could "r"emove the 1-bit boolean field (setting it to
53*4882a593Smuzhiyun * zero) but leaving all other fields as-is;
54*4882a593Smuzhiyun * reg_val = r32_int(19, 1, reg_value);
55*4882a593Smuzhiyun *
56*4882a593Smuzhiyun */
57*4882a593Smuzhiyun #define MAKE_MASK32(width) (width == 32 ? 0xffffffff : \
58*4882a593Smuzhiyun (uint32_t)((1 << width) - 1))
59*4882a593Smuzhiyun #define DECLARE_CODEC32(t) \
60*4882a593Smuzhiyun static inline uint32_t e32_##t(uint32_t lsoffset, uint32_t width, t val) \
61*4882a593Smuzhiyun { \
62*4882a593Smuzhiyun BUG_ON(width > (sizeof(t) * 8)); \
63*4882a593Smuzhiyun return ((uint32_t)val & MAKE_MASK32(width)) << lsoffset; \
64*4882a593Smuzhiyun } \
65*4882a593Smuzhiyun static inline t d32_##t(uint32_t lsoffset, uint32_t width, uint32_t val) \
66*4882a593Smuzhiyun { \
67*4882a593Smuzhiyun BUG_ON(width > (sizeof(t) * 8)); \
68*4882a593Smuzhiyun return (t)((val >> lsoffset) & MAKE_MASK32(width)); \
69*4882a593Smuzhiyun } \
70*4882a593Smuzhiyun static inline uint32_t i32_##t(uint32_t lsoffset, uint32_t width, \
71*4882a593Smuzhiyun uint32_t val) \
72*4882a593Smuzhiyun { \
73*4882a593Smuzhiyun BUG_ON(width > (sizeof(t) * 8)); \
74*4882a593Smuzhiyun return e32_##t(lsoffset, width, d32_##t(lsoffset, width, val)); \
75*4882a593Smuzhiyun } \
76*4882a593Smuzhiyun static inline uint32_t r32_##t(uint32_t lsoffset, uint32_t width, \
77*4882a593Smuzhiyun uint32_t val) \
78*4882a593Smuzhiyun { \
79*4882a593Smuzhiyun BUG_ON(width > (sizeof(t) * 8)); \
80*4882a593Smuzhiyun return ~(MAKE_MASK32(width) << lsoffset) & val; \
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun DECLARE_CODEC32(uint32_t)
DECLARE_CODEC32(uint16_t)83*4882a593Smuzhiyun DECLARE_CODEC32(uint16_t)
84*4882a593Smuzhiyun DECLARE_CODEC32(uint8_t)
85*4882a593Smuzhiyun DECLARE_CODEC32(int)
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun /*********************/
88*4882a593Smuzhiyun /* Debugging assists */
89*4882a593Smuzhiyun /*********************/
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun static inline void __hexdump(unsigned long start, unsigned long end,
92*4882a593Smuzhiyun unsigned long p, size_t sz, const unsigned char *c)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun while (start < end) {
95*4882a593Smuzhiyun unsigned int pos = 0;
96*4882a593Smuzhiyun char buf[64];
97*4882a593Smuzhiyun int nl = 0;
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun pos += sprintf(buf + pos, "%08lx: ", start);
100*4882a593Smuzhiyun do {
101*4882a593Smuzhiyun if ((start < p) || (start >= (p + sz)))
102*4882a593Smuzhiyun pos += sprintf(buf + pos, "..");
103*4882a593Smuzhiyun else
104*4882a593Smuzhiyun pos += sprintf(buf + pos, "%02x", *(c++));
105*4882a593Smuzhiyun if (!(++start & 15)) {
106*4882a593Smuzhiyun buf[pos++] = '\n';
107*4882a593Smuzhiyun nl = 1;
108*4882a593Smuzhiyun } else {
109*4882a593Smuzhiyun nl = 0;
110*4882a593Smuzhiyun if (!(start & 1))
111*4882a593Smuzhiyun buf[pos++] = ' ';
112*4882a593Smuzhiyun if (!(start & 3))
113*4882a593Smuzhiyun buf[pos++] = ' ';
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun } while (start & 15);
116*4882a593Smuzhiyun if (!nl)
117*4882a593Smuzhiyun buf[pos++] = '\n';
118*4882a593Smuzhiyun buf[pos] = '\0';
119*4882a593Smuzhiyun debug("%s", buf);
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun }
hexdump(const void * ptr,size_t sz)122*4882a593Smuzhiyun static inline void hexdump(const void *ptr, size_t sz)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun unsigned long p = (unsigned long)ptr;
125*4882a593Smuzhiyun unsigned long start = p & ~(unsigned long)15;
126*4882a593Smuzhiyun unsigned long end = (p + sz + 15) & ~(unsigned long)15;
127*4882a593Smuzhiyun const unsigned char *c = ptr;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun __hexdump(start, end, p, sz, c);
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun #if defined(__BIG_ENDIAN)
133*4882a593Smuzhiyun #define DQRR_TOK_OFFSET 0
134*4882a593Smuzhiyun #else
135*4882a593Smuzhiyun #define DQRR_TOK_OFFSET 24
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /* Similarly-named functions */
139*4882a593Smuzhiyun #define upper32(a) upper_32_bits(a)
140*4882a593Smuzhiyun #define lower32(a) lower_32_bits(a)
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun /****************/
143*4882a593Smuzhiyun /* arch assists */
144*4882a593Smuzhiyun /****************/
145*4882a593Smuzhiyun
dcbz(void * ptr)146*4882a593Smuzhiyun static inline void dcbz(void *ptr)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun uint32_t *p = ptr;
149*4882a593Smuzhiyun BUG_ON((unsigned long)ptr & 63);
150*4882a593Smuzhiyun p[0] = 0;
151*4882a593Smuzhiyun p[1] = 0;
152*4882a593Smuzhiyun p[2] = 0;
153*4882a593Smuzhiyun p[3] = 0;
154*4882a593Smuzhiyun p[4] = 0;
155*4882a593Smuzhiyun p[5] = 0;
156*4882a593Smuzhiyun p[6] = 0;
157*4882a593Smuzhiyun p[7] = 0;
158*4882a593Smuzhiyun p[8] = 0;
159*4882a593Smuzhiyun p[9] = 0;
160*4882a593Smuzhiyun p[10] = 0;
161*4882a593Smuzhiyun p[11] = 0;
162*4882a593Smuzhiyun p[12] = 0;
163*4882a593Smuzhiyun p[13] = 0;
164*4882a593Smuzhiyun p[14] = 0;
165*4882a593Smuzhiyun p[15] = 0;
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun #define lwsync()
169*4882a593Smuzhiyun
qbman_version(u32 * major,u32 * minor)170*4882a593Smuzhiyun void qbman_version(u32 *major, u32 *minor)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun u32 svr_dev_id;
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /*
175*4882a593Smuzhiyun * LS2080A SoC and its personalities has qbman cotroller version 4.0
176*4882a593Smuzhiyun * New SoCs like LS2088A, LS1088A has qbman conroller version 4.1
177*4882a593Smuzhiyun */
178*4882a593Smuzhiyun svr_dev_id = get_svr();
179*4882a593Smuzhiyun if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A))) {
180*4882a593Smuzhiyun *major = 4;
181*4882a593Smuzhiyun *minor = 0;
182*4882a593Smuzhiyun } else {
183*4882a593Smuzhiyun *major = 4;
184*4882a593Smuzhiyun *minor = 1;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun #include "qbman_sys.h"
189