xref: /linux/drivers/soc/fsl/qbman/qman_priv.h (revision 2c62f8b6fbd0431ccfb31b730a299d864a6bb8c9)
1c535e923SClaudiu Manoil /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
2c535e923SClaudiu Manoil  *
3c535e923SClaudiu Manoil  * Redistribution and use in source and binary forms, with or without
4c535e923SClaudiu Manoil  * modification, are permitted provided that the following conditions are met:
5c535e923SClaudiu Manoil  *     * Redistributions of source code must retain the above copyright
6c535e923SClaudiu Manoil  *	 notice, this list of conditions and the following disclaimer.
7c535e923SClaudiu Manoil  *     * Redistributions in binary form must reproduce the above copyright
8c535e923SClaudiu Manoil  *	 notice, this list of conditions and the following disclaimer in the
9c535e923SClaudiu Manoil  *	 documentation and/or other materials provided with the distribution.
10c535e923SClaudiu Manoil  *     * Neither the name of Freescale Semiconductor nor the
11c535e923SClaudiu Manoil  *	 names of its contributors may be used to endorse or promote products
12c535e923SClaudiu Manoil  *	 derived from this software without specific prior written permission.
13c535e923SClaudiu Manoil  *
14c535e923SClaudiu Manoil  * ALTERNATIVELY, this software may be distributed under the terms of the
15c535e923SClaudiu Manoil  * GNU General Public License ("GPL") as published by the Free Software
16c535e923SClaudiu Manoil  * Foundation, either version 2 of that License or (at your option) any
17c535e923SClaudiu Manoil  * later version.
18c535e923SClaudiu Manoil  *
19c535e923SClaudiu Manoil  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
20c535e923SClaudiu Manoil  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21c535e923SClaudiu Manoil  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22c535e923SClaudiu Manoil  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
23c535e923SClaudiu Manoil  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c535e923SClaudiu Manoil  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c535e923SClaudiu Manoil  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26c535e923SClaudiu Manoil  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27c535e923SClaudiu Manoil  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28c535e923SClaudiu Manoil  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c535e923SClaudiu Manoil  */
30c535e923SClaudiu Manoil 
31c535e923SClaudiu Manoil #include "dpaa_sys.h"
32c535e923SClaudiu Manoil 
33c535e923SClaudiu Manoil #include <soc/fsl/qman.h>
34290d638eSPaul Gortmaker #include <linux/dma-mapping.h>
35c535e923SClaudiu Manoil #include <linux/iommu.h>
36c535e923SClaudiu Manoil 
37c535e923SClaudiu Manoil #if defined(CONFIG_FSL_PAMU)
38c535e923SClaudiu Manoil #include <asm/fsl_pamu_stash.h>
39c535e923SClaudiu Manoil #endif
40c535e923SClaudiu Manoil 
41c535e923SClaudiu Manoil struct qm_mcr_querywq {
42c535e923SClaudiu Manoil 	u8 verb;
43c535e923SClaudiu Manoil 	u8 result;
44c535e923SClaudiu Manoil 	u16 channel_wq; /* ignores wq (3 lsbits): _res[0-2] */
45c535e923SClaudiu Manoil 	u8 __reserved[28];
46c535e923SClaudiu Manoil 	u32 wq_len[8];
47c535e923SClaudiu Manoil } __packed;
48c535e923SClaudiu Manoil 
49c535e923SClaudiu Manoil static inline u16 qm_mcr_querywq_get_chan(const struct qm_mcr_querywq *wq)
50c535e923SClaudiu Manoil {
51c535e923SClaudiu Manoil 	return wq->channel_wq >> 3;
52c535e923SClaudiu Manoil }
53c535e923SClaudiu Manoil 
54c535e923SClaudiu Manoil struct __qm_mcr_querycongestion {
55c535e923SClaudiu Manoil 	u32 state[8];
56c535e923SClaudiu Manoil };
57c535e923SClaudiu Manoil 
58c535e923SClaudiu Manoil /* "Query Congestion Group State" */
59c535e923SClaudiu Manoil struct qm_mcr_querycongestion {
60c535e923SClaudiu Manoil 	u8 verb;
61c535e923SClaudiu Manoil 	u8 result;
62c535e923SClaudiu Manoil 	u8 __reserved[30];
63c535e923SClaudiu Manoil 	/* Access this struct using qman_cgrs_get() */
64c535e923SClaudiu Manoil 	struct __qm_mcr_querycongestion state;
65c535e923SClaudiu Manoil } __packed;
66c535e923SClaudiu Manoil 
67c535e923SClaudiu Manoil /* "Query CGR" */
68c535e923SClaudiu Manoil struct qm_mcr_querycgr {
69c535e923SClaudiu Manoil 	u8 verb;
70c535e923SClaudiu Manoil 	u8 result;
71c535e923SClaudiu Manoil 	u16 __reserved1;
72c535e923SClaudiu Manoil 	struct __qm_mc_cgr cgr; /* CGR fields */
73c535e923SClaudiu Manoil 	u8 __reserved2[6];
74c535e923SClaudiu Manoil 	u8 i_bcnt_hi;	/* high 8-bits of 40-bit "Instant" */
7518058822SClaudiu Manoil 	__be32 i_bcnt_lo;	/* low 32-bits of 40-bit */
76c535e923SClaudiu Manoil 	u8 __reserved3[3];
77c535e923SClaudiu Manoil 	u8 a_bcnt_hi;	/* high 8-bits of 40-bit "Average" */
7818058822SClaudiu Manoil 	__be32 a_bcnt_lo;	/* low 32-bits of 40-bit */
7918058822SClaudiu Manoil 	__be32 cscn_targ_swp[4];
80c535e923SClaudiu Manoil } __packed;
81c535e923SClaudiu Manoil 
82c535e923SClaudiu Manoil static inline u64 qm_mcr_querycgr_i_get64(const struct qm_mcr_querycgr *q)
83c535e923SClaudiu Manoil {
8418058822SClaudiu Manoil 	return ((u64)q->i_bcnt_hi << 32) | be32_to_cpu(q->i_bcnt_lo);
85c535e923SClaudiu Manoil }
86c535e923SClaudiu Manoil static inline u64 qm_mcr_querycgr_a_get64(const struct qm_mcr_querycgr *q)
87c535e923SClaudiu Manoil {
8818058822SClaudiu Manoil 	return ((u64)q->a_bcnt_hi << 32) | be32_to_cpu(q->a_bcnt_lo);
89c535e923SClaudiu Manoil }
90c535e923SClaudiu Manoil 
91c535e923SClaudiu Manoil /* Congestion Groups */
92c535e923SClaudiu Manoil 
93c535e923SClaudiu Manoil /*
94c535e923SClaudiu Manoil  * This wrapper represents a bit-array for the state of the 256 QMan congestion
95c535e923SClaudiu Manoil  * groups. Is also used as a *mask* for congestion groups, eg. so we ignore
96c535e923SClaudiu Manoil  * those that don't concern us. We harness the structure and accessor details
97c535e923SClaudiu Manoil  * already used in the management command to query congestion groups.
98c535e923SClaudiu Manoil  */
99c535e923SClaudiu Manoil #define CGR_BITS_PER_WORD 5
100c535e923SClaudiu Manoil #define CGR_WORD(x)	((x) >> CGR_BITS_PER_WORD)
101c535e923SClaudiu Manoil #define CGR_BIT(x)	(BIT(31) >> ((x) & 0x1f))
102c535e923SClaudiu Manoil #define CGR_NUM	(sizeof(struct __qm_mcr_querycongestion) << 3)
103c535e923SClaudiu Manoil 
104c535e923SClaudiu Manoil struct qman_cgrs {
105c535e923SClaudiu Manoil 	struct __qm_mcr_querycongestion q;
106c535e923SClaudiu Manoil };
107c535e923SClaudiu Manoil 
108c535e923SClaudiu Manoil static inline void qman_cgrs_init(struct qman_cgrs *c)
109c535e923SClaudiu Manoil {
110c535e923SClaudiu Manoil 	memset(c, 0, sizeof(*c));
111c535e923SClaudiu Manoil }
112c535e923SClaudiu Manoil 
113c535e923SClaudiu Manoil static inline void qman_cgrs_fill(struct qman_cgrs *c)
114c535e923SClaudiu Manoil {
115c535e923SClaudiu Manoil 	memset(c, 0xff, sizeof(*c));
116c535e923SClaudiu Manoil }
117c535e923SClaudiu Manoil 
118c535e923SClaudiu Manoil static inline int qman_cgrs_get(struct qman_cgrs *c, u8 cgr)
119c535e923SClaudiu Manoil {
120c535e923SClaudiu Manoil 	return c->q.state[CGR_WORD(cgr)] & CGR_BIT(cgr);
121c535e923SClaudiu Manoil }
122c535e923SClaudiu Manoil 
123c535e923SClaudiu Manoil static inline void qman_cgrs_cp(struct qman_cgrs *dest,
124c535e923SClaudiu Manoil 				const struct qman_cgrs *src)
125c535e923SClaudiu Manoil {
126c535e923SClaudiu Manoil 	*dest = *src;
127c535e923SClaudiu Manoil }
128c535e923SClaudiu Manoil 
129c535e923SClaudiu Manoil static inline void qman_cgrs_and(struct qman_cgrs *dest,
130c535e923SClaudiu Manoil 			const struct qman_cgrs *a, const struct qman_cgrs *b)
131c535e923SClaudiu Manoil {
132c535e923SClaudiu Manoil 	int ret;
133c535e923SClaudiu Manoil 	u32 *_d = dest->q.state;
134c535e923SClaudiu Manoil 	const u32 *_a = a->q.state;
135c535e923SClaudiu Manoil 	const u32 *_b = b->q.state;
136c535e923SClaudiu Manoil 
137c535e923SClaudiu Manoil 	for (ret = 0; ret < 8; ret++)
138c535e923SClaudiu Manoil 		*_d++ = *_a++ & *_b++;
139c535e923SClaudiu Manoil }
140c535e923SClaudiu Manoil 
141c535e923SClaudiu Manoil static inline void qman_cgrs_xor(struct qman_cgrs *dest,
142c535e923SClaudiu Manoil 			const struct qman_cgrs *a, const struct qman_cgrs *b)
143c535e923SClaudiu Manoil {
144c535e923SClaudiu Manoil 	int ret;
145c535e923SClaudiu Manoil 	u32 *_d = dest->q.state;
146c535e923SClaudiu Manoil 	const u32 *_a = a->q.state;
147c535e923SClaudiu Manoil 	const u32 *_b = b->q.state;
148c535e923SClaudiu Manoil 
149c535e923SClaudiu Manoil 	for (ret = 0; ret < 8; ret++)
150c535e923SClaudiu Manoil 		*_d++ = *_a++ ^ *_b++;
151c535e923SClaudiu Manoil }
152c535e923SClaudiu Manoil 
153c535e923SClaudiu Manoil void qman_init_cgr_all(void);
154c535e923SClaudiu Manoil 
155c535e923SClaudiu Manoil struct qm_portal_config {
156e6e2df69SRoy Pledge 	/* Portal addresses */
157e6e2df69SRoy Pledge 	void *addr_virt_ce;
158e6e2df69SRoy Pledge 	void __iomem *addr_virt_ci;
159c535e923SClaudiu Manoil 	struct device *dev;
160c535e923SClaudiu Manoil 	struct iommu_domain *iommu_domain;
161c535e923SClaudiu Manoil 	/* Allow these to be joined in lists */
162c535e923SClaudiu Manoil 	struct list_head list;
163c535e923SClaudiu Manoil 	/* User-visible portal configuration settings */
164c535e923SClaudiu Manoil 	/* portal is affined to this cpu */
165c535e923SClaudiu Manoil 	int cpu;
166c535e923SClaudiu Manoil 	/* portal interrupt line */
167c535e923SClaudiu Manoil 	int irq;
168c535e923SClaudiu Manoil 	/*
169c535e923SClaudiu Manoil 	 * the portal's dedicated channel id, used initialising
170c535e923SClaudiu Manoil 	 * frame queues to target this portal when scheduled
171c535e923SClaudiu Manoil 	 */
172c535e923SClaudiu Manoil 	u16 channel;
173c535e923SClaudiu Manoil 	/*
174c535e923SClaudiu Manoil 	 * mask of pool channels this portal has dequeue access to
175c535e923SClaudiu Manoil 	 * (using QM_SDQCR_CHANNELS_POOL(n) for the bitmask)
176c535e923SClaudiu Manoil 	 */
177c535e923SClaudiu Manoil 	u32 pools;
178c535e923SClaudiu Manoil };
179c535e923SClaudiu Manoil 
180c535e923SClaudiu Manoil /* Revision info (for errata and feature handling) */
181c535e923SClaudiu Manoil #define QMAN_REV11 0x0101
182c535e923SClaudiu Manoil #define QMAN_REV12 0x0102
183c535e923SClaudiu Manoil #define QMAN_REV20 0x0200
184c535e923SClaudiu Manoil #define QMAN_REV30 0x0300
185c535e923SClaudiu Manoil #define QMAN_REV31 0x0301
186*2c62f8b6SMadalin Bucur #define QMAN_REV32 0x0302
187c535e923SClaudiu Manoil extern u16 qman_ip_rev; /* 0 if uninitialised, otherwise QMAN_REVx */
188c535e923SClaudiu Manoil 
189c535e923SClaudiu Manoil #define QM_FQID_RANGE_START 1 /* FQID 0 reserved for internal use */
190c535e923SClaudiu Manoil extern struct gen_pool *qm_fqalloc; /* FQID allocator */
191c535e923SClaudiu Manoil extern struct gen_pool *qm_qpalloc; /* pool-channel allocator */
192c535e923SClaudiu Manoil extern struct gen_pool *qm_cgralloc; /* CGR ID allocator */
193c535e923SClaudiu Manoil u32 qm_get_pools_sdqcr(void);
194c535e923SClaudiu Manoil 
195c535e923SClaudiu Manoil int qman_wq_alloc(void);
196c535e923SClaudiu Manoil void qman_liodn_fixup(u16 channel);
197c535e923SClaudiu Manoil void qman_set_sdest(u16 channel, unsigned int cpu_idx);
198c535e923SClaudiu Manoil 
199c535e923SClaudiu Manoil struct qman_portal *qman_create_affine_portal(
200c535e923SClaudiu Manoil 			const struct qm_portal_config *config,
201c535e923SClaudiu Manoil 			const struct qman_cgrs *cgrs);
202c535e923SClaudiu Manoil const struct qm_portal_config *qman_destroy_affine_portal(void);
203c535e923SClaudiu Manoil 
204c535e923SClaudiu Manoil /*
205c535e923SClaudiu Manoil  * qman_query_fq - Queries FQD fields (via h/w query command)
206c535e923SClaudiu Manoil  * @fq: the frame queue object to be queried
207c535e923SClaudiu Manoil  * @fqd: storage for the queried FQD fields
208c535e923SClaudiu Manoil  */
209c535e923SClaudiu Manoil int qman_query_fq(struct qman_fq *fq, struct qm_fqd *fqd);
210c535e923SClaudiu Manoil 
211c535e923SClaudiu Manoil int qman_alloc_fq_table(u32 num_fqids);
212c535e923SClaudiu Manoil 
213c535e923SClaudiu Manoil /*   QMan s/w corenet portal, low-level i/face	 */
214c535e923SClaudiu Manoil 
215c535e923SClaudiu Manoil /*
216c535e923SClaudiu Manoil  * For qm_dqrr_sdqcr_set(); Choose one SOURCE. Choose one COUNT. Choose one
217c535e923SClaudiu Manoil  * dequeue TYPE. Choose TOKEN (8-bit).
218c535e923SClaudiu Manoil  * If SOURCE == CHANNELS,
219c535e923SClaudiu Manoil  *   Choose CHANNELS_DEDICATED and/or CHANNELS_POOL(n).
220c535e923SClaudiu Manoil  *   You can choose DEDICATED_PRECEDENCE if the portal channel should have
221c535e923SClaudiu Manoil  *   priority.
222c535e923SClaudiu Manoil  * If SOURCE == SPECIFICWQ,
223c535e923SClaudiu Manoil  *     Either select the work-queue ID with SPECIFICWQ_WQ(), or select the
224c535e923SClaudiu Manoil  *     channel (SPECIFICWQ_DEDICATED or SPECIFICWQ_POOL()) and specify the
225c535e923SClaudiu Manoil  *     work-queue priority (0-7) with SPECIFICWQ_WQ() - either way, you get the
226c535e923SClaudiu Manoil  *     same value.
227c535e923SClaudiu Manoil  */
228c535e923SClaudiu Manoil #define QM_SDQCR_SOURCE_CHANNELS	0x0
229c535e923SClaudiu Manoil #define QM_SDQCR_SOURCE_SPECIFICWQ	0x40000000
230c535e923SClaudiu Manoil #define QM_SDQCR_COUNT_EXACT1		0x0
231c535e923SClaudiu Manoil #define QM_SDQCR_COUNT_UPTO3		0x20000000
232c535e923SClaudiu Manoil #define QM_SDQCR_DEDICATED_PRECEDENCE	0x10000000
233c535e923SClaudiu Manoil #define QM_SDQCR_TYPE_MASK		0x03000000
234c535e923SClaudiu Manoil #define QM_SDQCR_TYPE_NULL		0x0
235c535e923SClaudiu Manoil #define QM_SDQCR_TYPE_PRIO_QOS		0x01000000
236c535e923SClaudiu Manoil #define QM_SDQCR_TYPE_ACTIVE_QOS	0x02000000
237c535e923SClaudiu Manoil #define QM_SDQCR_TYPE_ACTIVE		0x03000000
238c535e923SClaudiu Manoil #define QM_SDQCR_TOKEN_MASK		0x00ff0000
239c535e923SClaudiu Manoil #define QM_SDQCR_TOKEN_SET(v)		(((v) & 0xff) << 16)
240c535e923SClaudiu Manoil #define QM_SDQCR_TOKEN_GET(v)		(((v) >> 16) & 0xff)
241c535e923SClaudiu Manoil #define QM_SDQCR_CHANNELS_DEDICATED	0x00008000
242c535e923SClaudiu Manoil #define QM_SDQCR_SPECIFICWQ_MASK	0x000000f7
243c535e923SClaudiu Manoil #define QM_SDQCR_SPECIFICWQ_DEDICATED	0x00000000
244c535e923SClaudiu Manoil #define QM_SDQCR_SPECIFICWQ_POOL(n)	((n) << 4)
245c535e923SClaudiu Manoil #define QM_SDQCR_SPECIFICWQ_WQ(n)	(n)
246c535e923SClaudiu Manoil 
247c535e923SClaudiu Manoil /* For qm_dqrr_vdqcr_set(): use FQID(n) to fill in the frame queue ID */
248c535e923SClaudiu Manoil #define QM_VDQCR_FQID_MASK		0x00ffffff
249c535e923SClaudiu Manoil #define QM_VDQCR_FQID(n)		((n) & QM_VDQCR_FQID_MASK)
250c535e923SClaudiu Manoil 
251c535e923SClaudiu Manoil /*
252c535e923SClaudiu Manoil  * Used by all portal interrupt registers except 'inhibit'
253c535e923SClaudiu Manoil  * Channels with frame availability
254c535e923SClaudiu Manoil  */
255c535e923SClaudiu Manoil #define QM_PIRQ_DQAVAIL	0x0000ffff
256c535e923SClaudiu Manoil 
257c535e923SClaudiu Manoil /* The DQAVAIL interrupt fields break down into these bits; */
258c535e923SClaudiu Manoil #define QM_DQAVAIL_PORTAL	0x8000		/* Portal channel */
259c535e923SClaudiu Manoil #define QM_DQAVAIL_POOL(n)	(0x8000 >> (n))	/* Pool channel, n==[1..15] */
260c535e923SClaudiu Manoil #define QM_DQAVAIL_MASK		0xffff
261c535e923SClaudiu Manoil /* This mask contains all the "irqsource" bits visible to API users */
262c535e923SClaudiu Manoil #define QM_PIRQ_VISIBLE	(QM_PIRQ_SLOW | QM_PIRQ_DQRI)
263c535e923SClaudiu Manoil 
264c535e923SClaudiu Manoil extern struct qman_portal *affine_portals[NR_CPUS];
2650fbeac3bSClaudiu Manoil extern struct qman_portal *qman_dma_portal;
266c535e923SClaudiu Manoil const struct qm_portal_config *qman_get_qm_portal_config(
267c535e923SClaudiu Manoil 						struct qman_portal *portal);
268