New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / bus / dpaa / base / qbman / qman_priv.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2008-2016 Freescale Semiconductor Inc.
8  * Copyright 2017 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 #ifndef __QMAN_PRIV_H
42 #define __QMAN_PRIV_H
43
44 #include "dpaa_sys.h"
45 #include <fsl_qman.h>
46
47 /* Congestion Groups */
48 /*
49  * This wrapper represents a bit-array for the state of the 256 QMan congestion
50  * groups. Is also used as a *mask* for congestion groups, eg. so we ignore
51  * those that don't concern us. We harness the structure and accessor details
52  * already used in the management command to query congestion groups.
53  */
54 struct qman_cgrs {
55         struct __qm_mcr_querycongestion q;
56 };
57
58 static inline void qman_cgrs_init(struct qman_cgrs *c)
59 {
60         memset(c, 0, sizeof(*c));
61 }
62
63 static inline void qman_cgrs_fill(struct qman_cgrs *c)
64 {
65         memset(c, 0xff, sizeof(*c));
66 }
67
68 static inline int qman_cgrs_get(struct qman_cgrs *c, int num)
69 {
70         return QM_MCR_QUERYCONGESTION(&c->q, num);
71 }
72
73 static inline void qman_cgrs_set(struct qman_cgrs *c, int num)
74 {
75         c->q.state[__CGR_WORD(num)] |= (0x80000000 >> __CGR_SHIFT(num));
76 }
77
78 static inline void qman_cgrs_unset(struct qman_cgrs *c, int num)
79 {
80         c->q.state[__CGR_WORD(num)] &= ~(0x80000000 >> __CGR_SHIFT(num));
81 }
82
83 static inline int qman_cgrs_next(struct qman_cgrs *c, int num)
84 {
85         while ((++num < (int)__CGR_NUM) && !qman_cgrs_get(c, num))
86                 ;
87         return num;
88 }
89
90 static inline void qman_cgrs_cp(struct qman_cgrs *dest,
91                                 const struct qman_cgrs *src)
92 {
93         memcpy(dest, src, sizeof(*dest));
94 }
95
96 static inline void qman_cgrs_and(struct qman_cgrs *dest,
97                                  const struct qman_cgrs *a,
98                                  const struct qman_cgrs *b)
99 {
100         int ret;
101         u32 *_d = dest->q.state;
102         const u32 *_a = a->q.state;
103         const u32 *_b = b->q.state;
104
105         for (ret = 0; ret < 8; ret++)
106                 *(_d++) = *(_a++) & *(_b++);
107 }
108
109 static inline void qman_cgrs_xor(struct qman_cgrs *dest,
110                                  const struct qman_cgrs *a,
111                                  const struct qman_cgrs *b)
112 {
113         int ret;
114         u32 *_d = dest->q.state;
115         const u32 *_a = a->q.state;
116         const u32 *_b = b->q.state;
117
118         for (ret = 0; ret < 8; ret++)
119                 *(_d++) = *(_a++) ^ *(_b++);
120 }
121
122 /* used by CCSR and portal interrupt code */
123 enum qm_isr_reg {
124         qm_isr_status = 0,
125         qm_isr_enable = 1,
126         qm_isr_disable = 2,
127         qm_isr_inhibit = 3
128 };
129
130 struct qm_portal_config {
131         /*
132          * Corenet portal addresses;
133          * [0]==cache-enabled, [1]==cache-inhibited.
134          */
135         void __iomem *addr_virt[2];
136         struct device_node *node;
137         /* Allow these to be joined in lists */
138         struct list_head list;
139         /* User-visible portal configuration settings */
140         /* If the caller enables DQRR stashing (and thus wishes to operate the
141          * portal from only one cpu), this is the logical CPU that the portal
142          * will stash to. Whether stashing is enabled or not, this setting is
143          * also used for any "core-affine" portals, ie. default portals
144          * associated to the corresponding cpu. -1 implies that there is no
145          * core affinity configured.
146          */
147         int cpu;
148         /* portal interrupt line */
149         int irq;
150         /* the unique index of this portal */
151         u32 index;
152         /* Is this portal shared? (If so, it has coarser locking and demuxes
153          * processing on behalf of other CPUs.).
154          */
155         int is_shared;
156         /* The portal's dedicated channel id, use this value for initialising
157          * frame queues to target this portal when scheduled.
158          */
159         u16 channel;
160         /* A mask of which pool channels this portal has dequeue access to
161          * (using QM_SDQCR_CHANNELS_POOL(n) for the bitmask).
162          */
163         u32 pools;
164
165 };
166
167 /* Revision info (for errata and feature handling) */
168 #define QMAN_REV11 0x0101
169 #define QMAN_REV12 0x0102
170 #define QMAN_REV20 0x0200
171 #define QMAN_REV30 0x0300
172 #define QMAN_REV31 0x0301
173 #define QMAN_REV32 0x0302
174 extern u16 qman_ip_rev; /* 0 if uninitialised, otherwise QMAN_REVx */
175 extern u32 qman_clk;
176
177 int qm_set_wpm(int wpm);
178 int qm_get_wpm(int *wpm);
179
180 struct qman_portal *qman_create_affine_portal(
181                         const struct qm_portal_config *config,
182                         const struct qman_cgrs *cgrs);
183 const struct qm_portal_config *qman_destroy_affine_portal(void);
184
185 struct qm_portal_config *qm_get_unused_portal(void);
186 struct qm_portal_config *qm_get_unused_portal_idx(uint32_t idx);
187
188 void qm_put_unused_portal(struct qm_portal_config *pcfg);
189 void qm_set_liodns(struct qm_portal_config *pcfg);
190
191 /* This CGR feature is supported by h/w and required by unit-tests and the
192  * debugfs hooks, so is implemented in the driver. However it allows an explicit
193  * corruption of h/w fields by s/w that are usually incorruptible (because the
194  * counters are usually maintained entirely within h/w). As such, we declare
195  * this API internally.
196  */
197 int qman_testwrite_cgr(struct qman_cgr *cgr, u64 i_bcnt,
198                        struct qm_mcr_cgrtestwrite *result);
199
200 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
201 /* If the fq object pointer is greater than the size of context_b field,
202  * than a lookup table is required.
203  */
204 int qman_setup_fq_lookup_table(size_t num_entries);
205 #endif
206
207 /*   QMan s/w corenet portal, low-level i/face   */
208
209 /*
210  * For Choose one SOURCE. Choose one COUNT. Choose one
211  * dequeue TYPE. Choose TOKEN (8-bit).
212  * If SOURCE == CHANNELS,
213  *   Choose CHANNELS_DEDICATED and/or CHANNELS_POOL(n).
214  *   You can choose DEDICATED_PRECEDENCE if the portal channel should have
215  *   priority.
216  * If SOURCE == SPECIFICWQ,
217  *     Either select the work-queue ID with SPECIFICWQ_WQ(), or select the
218  *     channel (SPECIFICWQ_DEDICATED or SPECIFICWQ_POOL()) and specify the
219  *     work-queue priority (0-7) with SPECIFICWQ_WQ() - either way, you get the
220  *     same value.
221  */
222 #define QM_SDQCR_SOURCE_CHANNELS        0x0
223 #define QM_SDQCR_SOURCE_SPECIFICWQ      0x40000000
224 #define QM_SDQCR_COUNT_EXACT1           0x0
225 #define QM_SDQCR_COUNT_UPTO3            0x20000000
226 #define QM_SDQCR_DEDICATED_PRECEDENCE   0x10000000
227 #define QM_SDQCR_TYPE_MASK              0x03000000
228 #define QM_SDQCR_TYPE_NULL              0x0
229 #define QM_SDQCR_TYPE_PRIO_QOS          0x01000000
230 #define QM_SDQCR_TYPE_ACTIVE_QOS        0x02000000
231 #define QM_SDQCR_TYPE_ACTIVE            0x03000000
232 #define QM_SDQCR_TOKEN_MASK             0x00ff0000
233 #define QM_SDQCR_TOKEN_SET(v)           (((v) & 0xff) << 16)
234 #define QM_SDQCR_TOKEN_GET(v)           (((v) >> 16) & 0xff)
235 #define QM_SDQCR_CHANNELS_DEDICATED     0x00008000
236 #define QM_SDQCR_SPECIFICWQ_MASK        0x000000f7
237 #define QM_SDQCR_SPECIFICWQ_DEDICATED   0x00000000
238 #define QM_SDQCR_SPECIFICWQ_POOL(n)     ((n) << 4)
239 #define QM_SDQCR_SPECIFICWQ_WQ(n)       (n)
240
241 #define QM_VDQCR_FQID_MASK              0x00ffffff
242 #define QM_VDQCR_FQID(n)                ((n) & QM_VDQCR_FQID_MASK)
243
244 #define QM_EQCR_VERB_VBIT               0x80
245 #define QM_EQCR_VERB_CMD_MASK           0x61    /* but only one value; */
246 #define QM_EQCR_VERB_CMD_ENQUEUE        0x01
247 #define QM_EQCR_VERB_COLOUR_MASK        0x18    /* 4 possible values; */
248 #define QM_EQCR_VERB_COLOUR_GREEN       0x00
249 #define QM_EQCR_VERB_COLOUR_YELLOW      0x08
250 #define QM_EQCR_VERB_COLOUR_RED         0x10
251 #define QM_EQCR_VERB_COLOUR_OVERRIDE    0x18
252 #define QM_EQCR_VERB_INTERRUPT          0x04    /* on command consumption */
253 #define QM_EQCR_VERB_ORP                0x02    /* enable order restoration */
254 #define QM_EQCR_DCA_ENABLE              0x80
255 #define QM_EQCR_DCA_PARK                0x40
256 #define QM_EQCR_DCA_IDXMASK             0x0f    /* "DQRR::idx" goes here */
257 #define QM_EQCR_SEQNUM_NESN             0x8000  /* Advance NESN */
258 #define QM_EQCR_SEQNUM_NLIS             0x4000  /* More fragments to come */
259 #define QM_EQCR_SEQNUM_SEQMASK          0x3fff  /* sequence number goes here */
260 #define QM_EQCR_FQID_NULL               0       /* eg. for an ORP seqnum hole */
261
262 #define QM_MCC_VERB_VBIT                0x80
263 #define QM_MCC_VERB_MASK                0x7f    /* where the verb contains; */
264 #define QM_MCC_VERB_INITFQ_PARKED       0x40
265 #define QM_MCC_VERB_INITFQ_SCHED        0x41
266 #define QM_MCC_VERB_QUERYFQ             0x44
267 #define QM_MCC_VERB_QUERYFQ_NP          0x45    /* "non-programmable" fields */
268 #define QM_MCC_VERB_QUERYWQ             0x46
269 #define QM_MCC_VERB_QUERYWQ_DEDICATED   0x47
270 #define QM_MCC_VERB_ALTER_SCHED         0x48    /* Schedule FQ */
271 #define QM_MCC_VERB_ALTER_FE            0x49    /* Force Eligible FQ */
272 #define QM_MCC_VERB_ALTER_RETIRE        0x4a    /* Retire FQ */
273 #define QM_MCC_VERB_ALTER_OOS           0x4b    /* Take FQ out of service */
274 #define QM_MCC_VERB_ALTER_FQXON         0x4d    /* FQ XON */
275 #define QM_MCC_VERB_ALTER_FQXOFF        0x4e    /* FQ XOFF */
276 #define QM_MCC_VERB_INITCGR             0x50
277 #define QM_MCC_VERB_MODIFYCGR           0x51
278 #define QM_MCC_VERB_CGRTESTWRITE        0x52
279 #define QM_MCC_VERB_QUERYCGR            0x58
280 #define QM_MCC_VERB_QUERYCONGESTION     0x59
281
282 /*
283  * Used by all portal interrupt registers except 'inhibit'
284  * Channels with frame availability
285  */
286 #define QM_PIRQ_DQAVAIL 0x0000ffff
287
288 /* The DQAVAIL interrupt fields break down into these bits; */
289 #define QM_DQAVAIL_PORTAL       0x8000          /* Portal channel */
290 #define QM_DQAVAIL_POOL(n)      (0x8000 >> (n)) /* Pool channel, n==[1..15] */
291 #define QM_DQAVAIL_MASK         0xffff
292 /* This mask contains all the "irqsource" bits visible to API users */
293 #define QM_PIRQ_VISIBLE (QM_PIRQ_SLOW | QM_PIRQ_DQRI)
294
295 /* These are qm_<reg>_<verb>(). So for example, qm_disable_write() means "write
296  * the disable register" rather than "disable the ability to write".
297  */
298 #define qm_isr_status_read(qm)          __qm_isr_read(qm, qm_isr_status)
299 #define qm_isr_status_clear(qm, m)      __qm_isr_write(qm, qm_isr_status, m)
300 #define qm_isr_enable_read(qm)          __qm_isr_read(qm, qm_isr_enable)
301 #define qm_isr_enable_write(qm, v)      __qm_isr_write(qm, qm_isr_enable, v)
302 #define qm_isr_disable_read(qm)         __qm_isr_read(qm, qm_isr_disable)
303 #define qm_isr_disable_write(qm, v)     __qm_isr_write(qm, qm_isr_disable, v)
304 /* TODO: unfortunate name-clash here, reword? */
305 #define qm_isr_inhibit(qm)              __qm_isr_write(qm, qm_isr_inhibit, 1)
306 #define qm_isr_uninhibit(qm)            __qm_isr_write(qm, qm_isr_inhibit, 0)
307
308 #define QMAN_PORTAL_IRQ_PATH "/dev/fsl-usdpaa-irq"
309
310 #endif /* _QMAN_PRIV_H */