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.
29 /* Perform extra checking */
30 #define QBMAN_CHECKING
32 /* To maximise the amount of logic that is common between the Linux driver and
33 * other targets (such as the embedded MC firmware), we pivot here between the
34 * inclusion of two platform-specific headers.
36 * The first, qbman_sys_decl.h, includes any and all required system headers as
37 * well as providing any definitions for the purposes of compatibility. The
38 * second, qbman_sys.h, is where platform-specific routines go.
40 * The point of the split is that the platform-independent code (including this
41 * header) may depend on platform-specific declarations, yet other
42 * platform-specific routines may depend on platform-independent definitions.
45 #include "qbman_sys_decl.h"
47 /* When things go wrong, it is a convenient trick to insert a few FOO()
48 * statements in the code to trace progress. TODO: remove this once we are
49 * hacking the code less actively.
51 #define FOO() fsl_os_print("FOO: %s:%d\n", __FILE__, __LINE__)
53 /* Any time there is a register interface which we poll on, this provides a
54 * "break after x iterations" scheme for it. It's handy for debugging, eg.
55 * where you don't want millions of lines of log output from a polling loop
56 * that won't, because such things tend to drown out the earlier log output
57 * that might explain what caused the problem. (NB: put ";" after each macro!)
58 * TODO: we should probably remove this once we're done sanitising the
61 #define DBG_POLL_START(loopvar) (loopvar = 10)
62 #define DBG_POLL_CHECK(loopvar) \
65 QBMAN_BUG_ON(NULL == "DBG_POLL_CHECK"); \
68 /* For CCSR or portal-CINH registers that contain fields at arbitrary offsets
69 * and widths, these macro-generated encode/decode/isolate/remove inlines can
72 * Eg. to "d"ecode a 14-bit field out of a register (into a "uint16_t" type),
73 * where the field is located 3 bits "up" from the least-significant bit of the
74 * register (ie. the field location within the 32-bit register corresponds to a
75 * mask of 0x0001fff8), you would do;
76 * uint16_t field = d32_uint16_t(3, 14, reg_value);
78 * Or to "e"ncode a 1-bit boolean value (input type is "int", zero is FALSE,
79 * non-zero is TRUE, so must convert all non-zero inputs to 1, hence the "!!"
80 * operator) into a register at bit location 0x00080000 (19 bits "in" from the
82 * reg_value |= e32_int(19, 1, !!field);
84 * If you wish to read-modify-write a register, such that you leave the 14-bit
85 * field as-is but have all other fields set to zero, then "i"solate the 14-bit
87 * reg_value = i32_uint16_t(3, 14, reg_value);
89 * Alternatively, you could "r"emove the 1-bit boolean field (setting it to
90 * zero) but leaving all other fields as-is;
91 * reg_val = r32_int(19, 1, reg_value);
95 #define MAKE_MASK32(width) ((uint32_t)(( 1ULL << width) - 1))
97 #define MAKE_MASK32(width) (width == 32 ? 0xffffffff : \
98 (uint32_t)((1 << width) - 1))
100 #define DECLARE_CODEC32(t) \
101 static inline uint32_t e32_##t(uint32_t lsoffset, uint32_t width, t val) \
103 QBMAN_BUG_ON(width > (sizeof(t) * 8)); \
104 return ((uint32_t)val & MAKE_MASK32(width)) << lsoffset; \
106 static inline t d32_##t(uint32_t lsoffset, uint32_t width, uint32_t val) \
108 QBMAN_BUG_ON(width > (sizeof(t) * 8)); \
109 return (t)((val >> lsoffset) & MAKE_MASK32(width)); \
111 static inline uint32_t i32_##t(uint32_t lsoffset, uint32_t width, \
114 QBMAN_BUG_ON(width > (sizeof(t) * 8)); \
115 return e32_##t(lsoffset, width, d32_##t(lsoffset, width, val)); \
117 static inline uint32_t r32_##t(uint32_t lsoffset, uint32_t width, \
120 QBMAN_BUG_ON(width > (sizeof(t) * 8)); \
121 return ~(MAKE_MASK32(width) << lsoffset) & val; \
123 DECLARE_CODEC32(uint32_t)
124 DECLARE_CODEC32(uint16_t)
125 DECLARE_CODEC32(uint8_t)
128 /*********************/
129 /* Debugging assists */
130 /*********************/
132 static inline void __hexdump(unsigned long start, unsigned long end,
133 unsigned long p, size_t sz, const unsigned char *c)
135 while (start < end) {
136 unsigned int pos = 0;
140 pos += sprintf(buf + pos, "%08lx: ", start);
142 if ((start < p) || (start >= (p + sz)))
143 pos += sprintf(buf + pos, "..");
145 pos += sprintf(buf + pos, "%02x", *(c++));
146 if (!(++start & 15)) {
156 } while (start & 15);
164 static inline void hexdump(const void *ptr, size_t sz)
166 unsigned long p = (unsigned long)ptr;
167 unsigned long start = p & ~(unsigned long)15;
168 unsigned long end = (p + sz + 15) & ~(unsigned long)15;
169 const unsigned char *c = ptr;
171 __hexdump(start, end, p, sz, c);
174 #include "qbman_sys.h"