xref: /openbmc/linux/include/soc/fsl/qman.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
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 #ifndef __FSL_QMAN_H
32c535e923SClaudiu Manoil #define __FSL_QMAN_H
33c535e923SClaudiu Manoil 
34c535e923SClaudiu Manoil #include <linux/bitops.h>
35a2d00f3dSMadalin Bucur #include <linux/device.h>
36c535e923SClaudiu Manoil 
37c535e923SClaudiu Manoil /* Hardware constants */
38c535e923SClaudiu Manoil #define QM_CHANNEL_SWPORTAL0 0
39c535e923SClaudiu Manoil #define QMAN_CHANNEL_POOL1 0x21
40329d0908SHoria Geantă #define QMAN_CHANNEL_CAAM 0x80
41c535e923SClaudiu Manoil #define QMAN_CHANNEL_POOL1_REV3 0x401
42329d0908SHoria Geantă #define QMAN_CHANNEL_CAAM_REV3 0x840
43c535e923SClaudiu Manoil extern u16 qm_channel_pool1;
44329d0908SHoria Geantă extern u16 qm_channel_caam;
45c535e923SClaudiu Manoil 
46c535e923SClaudiu Manoil /* Portal processing (interrupt) sources */
47c535e923SClaudiu Manoil #define QM_PIRQ_CSCI	0x00100000	/* Congestion State Change */
48c535e923SClaudiu Manoil #define QM_PIRQ_EQCI	0x00080000	/* Enqueue Command Committed */
49c535e923SClaudiu Manoil #define QM_PIRQ_EQRI	0x00040000	/* EQCR Ring (below threshold) */
50c535e923SClaudiu Manoil #define QM_PIRQ_DQRI	0x00020000	/* DQRR Ring (non-empty) */
51c535e923SClaudiu Manoil #define QM_PIRQ_MRI	0x00010000	/* MR Ring (non-empty) */
52c535e923SClaudiu Manoil /*
53c535e923SClaudiu Manoil  * This mask contains all the interrupt sources that need handling except DQRI,
54c535e923SClaudiu Manoil  * ie. that if present should trigger slow-path processing.
55c535e923SClaudiu Manoil  */
56c535e923SClaudiu Manoil #define QM_PIRQ_SLOW	(QM_PIRQ_CSCI | QM_PIRQ_EQCI | QM_PIRQ_EQRI | \
57c535e923SClaudiu Manoil 			 QM_PIRQ_MRI)
58c535e923SClaudiu Manoil 
59c535e923SClaudiu Manoil /* For qman_static_dequeue_*** APIs */
60c535e923SClaudiu Manoil #define QM_SDQCR_CHANNELS_POOL_MASK	0x00007fff
61c535e923SClaudiu Manoil /* for n in [1,15] */
62c535e923SClaudiu Manoil #define QM_SDQCR_CHANNELS_POOL(n)	(0x00008000 >> (n))
63c535e923SClaudiu Manoil /* for conversion from n of qm_channel */
QM_SDQCR_CHANNELS_POOL_CONV(u16 channel)64c535e923SClaudiu Manoil static inline u32 QM_SDQCR_CHANNELS_POOL_CONV(u16 channel)
65c535e923SClaudiu Manoil {
66c535e923SClaudiu Manoil 	return QM_SDQCR_CHANNELS_POOL(channel + 1 - qm_channel_pool1);
67c535e923SClaudiu Manoil }
68c535e923SClaudiu Manoil 
69c535e923SClaudiu Manoil /* --- QMan data structures (and associated constants) --- */
70c535e923SClaudiu Manoil 
71c535e923SClaudiu Manoil /* "Frame Descriptor (FD)" */
72c535e923SClaudiu Manoil struct qm_fd {
73c535e923SClaudiu Manoil 	union {
74c535e923SClaudiu Manoil 		struct {
75c535e923SClaudiu Manoil 			u8 cfg8b_w1;
76c535e923SClaudiu Manoil 			u8 bpid;	/* Buffer Pool ID */
77c535e923SClaudiu Manoil 			u8 cfg8b_w3;
78c535e923SClaudiu Manoil 			u8 addr_hi;	/* high 8-bits of 40-bit address */
79c535e923SClaudiu Manoil 			__be32 addr_lo;	/* low 32-bits of 40-bit address */
80c535e923SClaudiu Manoil 		} __packed;
81c535e923SClaudiu Manoil 		__be64 data;
82c535e923SClaudiu Manoil 	};
83c535e923SClaudiu Manoil 	__be32 cfg;	/* format, offset, length / congestion */
84c535e923SClaudiu Manoil 	union {
85c535e923SClaudiu Manoil 		__be32 cmd;
86c535e923SClaudiu Manoil 		__be32 status;
87c535e923SClaudiu Manoil 	};
88c535e923SClaudiu Manoil } __aligned(8);
89c535e923SClaudiu Manoil 
90c535e923SClaudiu Manoil #define QM_FD_FORMAT_SG		BIT(31)
91c535e923SClaudiu Manoil #define QM_FD_FORMAT_LONG	BIT(30)
92c535e923SClaudiu Manoil #define QM_FD_FORMAT_COMPOUND	BIT(29)
93c535e923SClaudiu Manoil #define QM_FD_FORMAT_MASK	GENMASK(31, 29)
94c535e923SClaudiu Manoil #define QM_FD_OFF_SHIFT		20
95c535e923SClaudiu Manoil #define QM_FD_OFF_MASK		GENMASK(28, 20)
96c535e923SClaudiu Manoil #define QM_FD_LEN_MASK		GENMASK(19, 0)
97c535e923SClaudiu Manoil #define QM_FD_LEN_BIG_MASK	GENMASK(28, 0)
98c535e923SClaudiu Manoil 
99c535e923SClaudiu Manoil enum qm_fd_format {
100c535e923SClaudiu Manoil 	/*
101c535e923SClaudiu Manoil 	 * 'contig' implies a contiguous buffer, whereas 'sg' implies a
102c535e923SClaudiu Manoil 	 * scatter-gather table. 'big' implies a 29-bit length with no offset
103c535e923SClaudiu Manoil 	 * field, otherwise length is 20-bit and offset is 9-bit. 'compound'
104c535e923SClaudiu Manoil 	 * implies a s/g-like table, where each entry itself represents a frame
105c535e923SClaudiu Manoil 	 * (contiguous or scatter-gather) and the 29-bit "length" is
106c535e923SClaudiu Manoil 	 * interpreted purely for congestion calculations, ie. a "congestion
107c535e923SClaudiu Manoil 	 * weight".
108c535e923SClaudiu Manoil 	 */
109c535e923SClaudiu Manoil 	qm_fd_contig = 0,
110c535e923SClaudiu Manoil 	qm_fd_contig_big = QM_FD_FORMAT_LONG,
111c535e923SClaudiu Manoil 	qm_fd_sg = QM_FD_FORMAT_SG,
112c535e923SClaudiu Manoil 	qm_fd_sg_big = QM_FD_FORMAT_SG | QM_FD_FORMAT_LONG,
113c535e923SClaudiu Manoil 	qm_fd_compound = QM_FD_FORMAT_COMPOUND
114c535e923SClaudiu Manoil };
115c535e923SClaudiu Manoil 
qm_fd_addr(const struct qm_fd * fd)116c535e923SClaudiu Manoil static inline dma_addr_t qm_fd_addr(const struct qm_fd *fd)
117c535e923SClaudiu Manoil {
118c535e923SClaudiu Manoil 	return be64_to_cpu(fd->data) & 0xffffffffffLLU;
119c535e923SClaudiu Manoil }
120c535e923SClaudiu Manoil 
qm_fd_addr_get64(const struct qm_fd * fd)121c535e923SClaudiu Manoil static inline u64 qm_fd_addr_get64(const struct qm_fd *fd)
122c535e923SClaudiu Manoil {
123c535e923SClaudiu Manoil 	return be64_to_cpu(fd->data) & 0xffffffffffLLU;
124c535e923SClaudiu Manoil }
125c535e923SClaudiu Manoil 
qm_fd_addr_set64(struct qm_fd * fd,u64 addr)126c535e923SClaudiu Manoil static inline void qm_fd_addr_set64(struct qm_fd *fd, u64 addr)
127c535e923SClaudiu Manoil {
128c535e923SClaudiu Manoil 	fd->addr_hi = upper_32_bits(addr);
129c535e923SClaudiu Manoil 	fd->addr_lo = cpu_to_be32(lower_32_bits(addr));
130c535e923SClaudiu Manoil }
131c535e923SClaudiu Manoil 
132c535e923SClaudiu Manoil /*
133c535e923SClaudiu Manoil  * The 'format' field indicates the interpretation of the remaining
134c535e923SClaudiu Manoil  * 29 bits of the 32-bit word.
135c535e923SClaudiu Manoil  * If 'format' is _contig or _sg, 20b length and 9b offset.
136c535e923SClaudiu Manoil  * If 'format' is _contig_big or _sg_big, 29b length.
137c535e923SClaudiu Manoil  * If 'format' is _compound, 29b "congestion weight".
138c535e923SClaudiu Manoil  */
qm_fd_get_format(const struct qm_fd * fd)139c535e923SClaudiu Manoil static inline enum qm_fd_format qm_fd_get_format(const struct qm_fd *fd)
140c535e923SClaudiu Manoil {
141c535e923SClaudiu Manoil 	return be32_to_cpu(fd->cfg) & QM_FD_FORMAT_MASK;
142c535e923SClaudiu Manoil }
143c535e923SClaudiu Manoil 
qm_fd_get_offset(const struct qm_fd * fd)144c535e923SClaudiu Manoil static inline int qm_fd_get_offset(const struct qm_fd *fd)
145c535e923SClaudiu Manoil {
146c535e923SClaudiu Manoil 	return (be32_to_cpu(fd->cfg) & QM_FD_OFF_MASK) >> QM_FD_OFF_SHIFT;
147c535e923SClaudiu Manoil }
148c535e923SClaudiu Manoil 
qm_fd_get_length(const struct qm_fd * fd)149c535e923SClaudiu Manoil static inline int qm_fd_get_length(const struct qm_fd *fd)
150c535e923SClaudiu Manoil {
151c535e923SClaudiu Manoil 	return be32_to_cpu(fd->cfg) & QM_FD_LEN_MASK;
152c535e923SClaudiu Manoil }
153c535e923SClaudiu Manoil 
qm_fd_get_len_big(const struct qm_fd * fd)154c535e923SClaudiu Manoil static inline int qm_fd_get_len_big(const struct qm_fd *fd)
155c535e923SClaudiu Manoil {
156c535e923SClaudiu Manoil 	return be32_to_cpu(fd->cfg) & QM_FD_LEN_BIG_MASK;
157c535e923SClaudiu Manoil }
158c535e923SClaudiu Manoil 
qm_fd_set_param(struct qm_fd * fd,enum qm_fd_format fmt,int off,int len)159c535e923SClaudiu Manoil static inline void qm_fd_set_param(struct qm_fd *fd, enum qm_fd_format fmt,
160c535e923SClaudiu Manoil 				   int off, int len)
161c535e923SClaudiu Manoil {
162c535e923SClaudiu Manoil 	fd->cfg = cpu_to_be32(fmt | (len & QM_FD_LEN_BIG_MASK) |
163c535e923SClaudiu Manoil 			      ((off << QM_FD_OFF_SHIFT) & QM_FD_OFF_MASK));
164c535e923SClaudiu Manoil }
165c535e923SClaudiu Manoil 
166c535e923SClaudiu Manoil #define qm_fd_set_contig(fd, off, len) \
167c535e923SClaudiu Manoil 	qm_fd_set_param(fd, qm_fd_contig, off, len)
168c535e923SClaudiu Manoil #define qm_fd_set_sg(fd, off, len) qm_fd_set_param(fd, qm_fd_sg, off, len)
169c535e923SClaudiu Manoil #define qm_fd_set_contig_big(fd, len) \
170c535e923SClaudiu Manoil 	qm_fd_set_param(fd, qm_fd_contig_big, 0, len)
171c535e923SClaudiu Manoil #define qm_fd_set_sg_big(fd, len) qm_fd_set_param(fd, qm_fd_sg_big, 0, len)
172e5c748a5SHoria Geantă #define qm_fd_set_compound(fd, len) qm_fd_set_param(fd, qm_fd_compound, 0, len)
173c535e923SClaudiu Manoil 
qm_fd_clear_fd(struct qm_fd * fd)174c535e923SClaudiu Manoil static inline void qm_fd_clear_fd(struct qm_fd *fd)
175c535e923SClaudiu Manoil {
176c535e923SClaudiu Manoil 	fd->data = 0;
177c535e923SClaudiu Manoil 	fd->cfg = 0;
178c535e923SClaudiu Manoil 	fd->cmd = 0;
179c535e923SClaudiu Manoil }
180c535e923SClaudiu Manoil 
181c535e923SClaudiu Manoil /* Scatter/Gather table entry */
182c535e923SClaudiu Manoil struct qm_sg_entry {
183c535e923SClaudiu Manoil 	union {
184c535e923SClaudiu Manoil 		struct {
185c535e923SClaudiu Manoil 			u8 __reserved1[3];
186c535e923SClaudiu Manoil 			u8 addr_hi;	/* high 8-bits of 40-bit address */
187c535e923SClaudiu Manoil 			__be32 addr_lo;	/* low 32-bits of 40-bit address */
188c535e923SClaudiu Manoil 		};
189c535e923SClaudiu Manoil 		__be64 data;
190c535e923SClaudiu Manoil 	};
191c535e923SClaudiu Manoil 	__be32 cfg;	/* E bit, F bit, length */
192c535e923SClaudiu Manoil 	u8 __reserved2;
193c535e923SClaudiu Manoil 	u8 bpid;
194c535e923SClaudiu Manoil 	__be16 offset; /* 13-bit, _res[13-15]*/
195c535e923SClaudiu Manoil } __packed;
196c535e923SClaudiu Manoil 
197c535e923SClaudiu Manoil #define QM_SG_LEN_MASK	GENMASK(29, 0)
198c535e923SClaudiu Manoil #define QM_SG_OFF_MASK	GENMASK(12, 0)
199c535e923SClaudiu Manoil #define QM_SG_FIN	BIT(30)
200c535e923SClaudiu Manoil #define QM_SG_EXT	BIT(31)
201c535e923SClaudiu Manoil 
qm_sg_addr(const struct qm_sg_entry * sg)202c535e923SClaudiu Manoil static inline dma_addr_t qm_sg_addr(const struct qm_sg_entry *sg)
203c535e923SClaudiu Manoil {
204c535e923SClaudiu Manoil 	return be64_to_cpu(sg->data) & 0xffffffffffLLU;
205c535e923SClaudiu Manoil }
206c535e923SClaudiu Manoil 
qm_sg_entry_get64(const struct qm_sg_entry * sg)207c535e923SClaudiu Manoil static inline u64 qm_sg_entry_get64(const struct qm_sg_entry *sg)
208c535e923SClaudiu Manoil {
209c535e923SClaudiu Manoil 	return be64_to_cpu(sg->data) & 0xffffffffffLLU;
210c535e923SClaudiu Manoil }
211c535e923SClaudiu Manoil 
qm_sg_entry_set64(struct qm_sg_entry * sg,u64 addr)212c535e923SClaudiu Manoil static inline void qm_sg_entry_set64(struct qm_sg_entry *sg, u64 addr)
213c535e923SClaudiu Manoil {
214c535e923SClaudiu Manoil 	sg->addr_hi = upper_32_bits(addr);
215c535e923SClaudiu Manoil 	sg->addr_lo = cpu_to_be32(lower_32_bits(addr));
216c535e923SClaudiu Manoil }
217c535e923SClaudiu Manoil 
qm_sg_entry_is_final(const struct qm_sg_entry * sg)218c535e923SClaudiu Manoil static inline bool qm_sg_entry_is_final(const struct qm_sg_entry *sg)
219c535e923SClaudiu Manoil {
220c535e923SClaudiu Manoil 	return be32_to_cpu(sg->cfg) & QM_SG_FIN;
221c535e923SClaudiu Manoil }
222c535e923SClaudiu Manoil 
qm_sg_entry_is_ext(const struct qm_sg_entry * sg)223c535e923SClaudiu Manoil static inline bool qm_sg_entry_is_ext(const struct qm_sg_entry *sg)
224c535e923SClaudiu Manoil {
225c535e923SClaudiu Manoil 	return be32_to_cpu(sg->cfg) & QM_SG_EXT;
226c535e923SClaudiu Manoil }
227c535e923SClaudiu Manoil 
qm_sg_entry_get_len(const struct qm_sg_entry * sg)228c535e923SClaudiu Manoil static inline int qm_sg_entry_get_len(const struct qm_sg_entry *sg)
229c535e923SClaudiu Manoil {
230c535e923SClaudiu Manoil 	return be32_to_cpu(sg->cfg) & QM_SG_LEN_MASK;
231c535e923SClaudiu Manoil }
232c535e923SClaudiu Manoil 
qm_sg_entry_set_len(struct qm_sg_entry * sg,int len)233c535e923SClaudiu Manoil static inline void qm_sg_entry_set_len(struct qm_sg_entry *sg, int len)
234c535e923SClaudiu Manoil {
235c535e923SClaudiu Manoil 	sg->cfg = cpu_to_be32(len & QM_SG_LEN_MASK);
236c535e923SClaudiu Manoil }
237c535e923SClaudiu Manoil 
qm_sg_entry_set_f(struct qm_sg_entry * sg,int len)238c535e923SClaudiu Manoil static inline void qm_sg_entry_set_f(struct qm_sg_entry *sg, int len)
239c535e923SClaudiu Manoil {
240c535e923SClaudiu Manoil 	sg->cfg = cpu_to_be32(QM_SG_FIN | (len & QM_SG_LEN_MASK));
241c535e923SClaudiu Manoil }
242c535e923SClaudiu Manoil 
qm_sg_entry_get_off(const struct qm_sg_entry * sg)243c535e923SClaudiu Manoil static inline int qm_sg_entry_get_off(const struct qm_sg_entry *sg)
244c535e923SClaudiu Manoil {
245c535e923SClaudiu Manoil 	return be32_to_cpu(sg->offset) & QM_SG_OFF_MASK;
246c535e923SClaudiu Manoil }
247c535e923SClaudiu Manoil 
248c535e923SClaudiu Manoil /* "Frame Dequeue Response" */
249c535e923SClaudiu Manoil struct qm_dqrr_entry {
250c535e923SClaudiu Manoil 	u8 verb;
251c535e923SClaudiu Manoil 	u8 stat;
25218058822SClaudiu Manoil 	__be16 seqnum;	/* 15-bit */
253c535e923SClaudiu Manoil 	u8 tok;
254c535e923SClaudiu Manoil 	u8 __reserved2[3];
25518058822SClaudiu Manoil 	__be32 fqid;	/* 24-bit */
25618058822SClaudiu Manoil 	__be32 context_b;
257c535e923SClaudiu Manoil 	struct qm_fd fd;
258c535e923SClaudiu Manoil 	u8 __reserved4[32];
2591fe44191SLi Yang } __packed __aligned(64);
260c535e923SClaudiu Manoil #define QM_DQRR_VERB_VBIT		0x80
261c535e923SClaudiu Manoil #define QM_DQRR_VERB_MASK		0x7f	/* where the verb contains; */
262c535e923SClaudiu Manoil #define QM_DQRR_VERB_FRAME_DEQUEUE	0x60	/* "this format" */
263c535e923SClaudiu Manoil #define QM_DQRR_STAT_FQ_EMPTY		0x80	/* FQ empty */
264c535e923SClaudiu Manoil #define QM_DQRR_STAT_FQ_HELDACTIVE	0x40	/* FQ held active */
265c535e923SClaudiu Manoil #define QM_DQRR_STAT_FQ_FORCEELIGIBLE	0x20	/* FQ was force-eligible'd */
266c535e923SClaudiu Manoil #define QM_DQRR_STAT_FD_VALID		0x10	/* has a non-NULL FD */
267c535e923SClaudiu Manoil #define QM_DQRR_STAT_UNSCHEDULED	0x02	/* Unscheduled dequeue */
268c535e923SClaudiu Manoil #define QM_DQRR_STAT_DQCR_EXPIRED	0x01	/* VDQCR or PDQCR expired*/
269c535e923SClaudiu Manoil 
270d6753c7eSClaudiu Manoil /* 'fqid' is a 24-bit field in every h/w descriptor */
271d6753c7eSClaudiu Manoil #define QM_FQID_MASK	GENMASK(23, 0)
27218058822SClaudiu Manoil #define qm_fqid_set(p, v) ((p)->fqid = cpu_to_be32((v) & QM_FQID_MASK))
27318058822SClaudiu Manoil #define qm_fqid_get(p)    (be32_to_cpu((p)->fqid) & QM_FQID_MASK)
274d6753c7eSClaudiu Manoil 
275c535e923SClaudiu Manoil /* "ERN Message Response" */
276c535e923SClaudiu Manoil /* "FQ State Change Notification" */
277c535e923SClaudiu Manoil union qm_mr_entry {
278c535e923SClaudiu Manoil 	struct {
279c535e923SClaudiu Manoil 		u8 verb;
280c535e923SClaudiu Manoil 		u8 __reserved[63];
281c535e923SClaudiu Manoil 	};
282c535e923SClaudiu Manoil 	struct {
283c535e923SClaudiu Manoil 		u8 verb;
284c535e923SClaudiu Manoil 		u8 dca;
28518058822SClaudiu Manoil 		__be16 seqnum;
286c535e923SClaudiu Manoil 		u8 rc;		/* Rej Code: 8-bit */
287b5399452SClaudiu Manoil 		u8 __reserved[3];
28818058822SClaudiu Manoil 		__be32 fqid;	/* 24-bit */
28918058822SClaudiu Manoil 		__be32 tag;
290c535e923SClaudiu Manoil 		struct qm_fd fd;
291c535e923SClaudiu Manoil 		u8 __reserved1[32];
2921fe44191SLi Yang 	} __packed __aligned(64) ern;
293c535e923SClaudiu Manoil 	struct {
294c535e923SClaudiu Manoil 		u8 verb;
295c535e923SClaudiu Manoil 		u8 fqs;		/* Frame Queue Status */
296c535e923SClaudiu Manoil 		u8 __reserved1[6];
29718058822SClaudiu Manoil 		__be32 fqid;	/* 24-bit */
29818058822SClaudiu Manoil 		__be32 context_b;
299c535e923SClaudiu Manoil 		u8 __reserved2[48];
300c535e923SClaudiu Manoil 	} __packed fq;		/* FQRN/FQRNI/FQRL/FQPN */
301c535e923SClaudiu Manoil };
302c535e923SClaudiu Manoil #define QM_MR_VERB_VBIT			0x80
303c535e923SClaudiu Manoil /*
304c535e923SClaudiu Manoil  * ERNs originating from direct-connect portals ("dcern") use 0x20 as a verb
305c535e923SClaudiu Manoil  * which would be invalid as a s/w enqueue verb. A s/w ERN can be distinguished
306c535e923SClaudiu Manoil  * from the other MR types by noting if the 0x20 bit is unset.
307c535e923SClaudiu Manoil  */
308c535e923SClaudiu Manoil #define QM_MR_VERB_TYPE_MASK		0x27
309c535e923SClaudiu Manoil #define QM_MR_VERB_DC_ERN		0x20
310c535e923SClaudiu Manoil #define QM_MR_VERB_FQRN			0x21
311c535e923SClaudiu Manoil #define QM_MR_VERB_FQRNI		0x22
312c535e923SClaudiu Manoil #define QM_MR_VERB_FQRL			0x23
313c535e923SClaudiu Manoil #define QM_MR_VERB_FQPN			0x24
314c535e923SClaudiu Manoil #define QM_MR_RC_MASK			0xf0	/* contains one of; */
315c535e923SClaudiu Manoil #define QM_MR_RC_CGR_TAILDROP		0x00
316c535e923SClaudiu Manoil #define QM_MR_RC_WRED			0x10
317c535e923SClaudiu Manoil #define QM_MR_RC_ERROR			0x20
318c535e923SClaudiu Manoil #define QM_MR_RC_ORPWINDOW_EARLY	0x30
319c535e923SClaudiu Manoil #define QM_MR_RC_ORPWINDOW_LATE		0x40
320c535e923SClaudiu Manoil #define QM_MR_RC_FQ_TAILDROP		0x50
321c535e923SClaudiu Manoil #define QM_MR_RC_ORPWINDOW_RETIRED	0x60
322c535e923SClaudiu Manoil #define QM_MR_RC_ORP_ZERO		0x70
323c535e923SClaudiu Manoil #define QM_MR_FQS_ORLPRESENT		0x02	/* ORL fragments to come */
324c535e923SClaudiu Manoil #define QM_MR_FQS_NOTEMPTY		0x01	/* FQ has enqueued frames */
325c535e923SClaudiu Manoil 
326c535e923SClaudiu Manoil /*
327c535e923SClaudiu Manoil  * An identical structure of FQD fields is present in the "Init FQ" command and
328c535e923SClaudiu Manoil  * the "Query FQ" result, it's suctioned out into the "struct qm_fqd" type.
329c535e923SClaudiu Manoil  * Within that, the 'stashing' and 'taildrop' pieces are also factored out, the
330c535e923SClaudiu Manoil  * latter has two inlines to assist with converting to/from the mant+exp
331c535e923SClaudiu Manoil  * representation.
332c535e923SClaudiu Manoil  */
333c535e923SClaudiu Manoil struct qm_fqd_stashing {
334c535e923SClaudiu Manoil 	/* See QM_STASHING_EXCL_<...> */
335c535e923SClaudiu Manoil 	u8 exclusive;
336c535e923SClaudiu Manoil 	/* Numbers of cachelines */
337c535e923SClaudiu Manoil 	u8 cl; /* _res[6-7], as[4-5], ds[2-3], cs[0-1] */
338c535e923SClaudiu Manoil };
339c535e923SClaudiu Manoil 
340c535e923SClaudiu Manoil struct qm_fqd_oac {
341c535e923SClaudiu Manoil 	/* "Overhead Accounting Control", see QM_OAC_<...> */
342c535e923SClaudiu Manoil 	u8 oac; /* oac[6-7], _res[0-5] */
343c535e923SClaudiu Manoil 	/* Two's-complement value (-128 to +127) */
344c535e923SClaudiu Manoil 	s8 oal; /* "Overhead Accounting Length" */
345c535e923SClaudiu Manoil };
346c535e923SClaudiu Manoil 
347c535e923SClaudiu Manoil struct qm_fqd {
348c535e923SClaudiu Manoil 	/* _res[6-7], orprws[3-5], oa[2], olws[0-1] */
349c535e923SClaudiu Manoil 	u8 orpc;
350c535e923SClaudiu Manoil 	u8 cgid;
351c535e923SClaudiu Manoil 	__be16 fq_ctrl;	/* See QM_FQCTRL_<...> */
352c535e923SClaudiu Manoil 	__be16 dest_wq;	/* channel[3-15], wq[0-2] */
353c535e923SClaudiu Manoil 	__be16 ics_cred; /* 15-bit */
354c535e923SClaudiu Manoil 	/*
355c535e923SClaudiu Manoil 	 * For "Initialize Frame Queue" commands, the write-enable mask
356c535e923SClaudiu Manoil 	 * determines whether 'td' or 'oac_init' is observed. For query
357c535e923SClaudiu Manoil 	 * commands, this field is always 'td', and 'oac_query' (below) reflects
358c535e923SClaudiu Manoil 	 * the Overhead ACcounting values.
359c535e923SClaudiu Manoil 	 */
360c535e923SClaudiu Manoil 	union {
361c535e923SClaudiu Manoil 		__be16 td; /* "Taildrop": _res[13-15], mant[5-12], exp[0-4] */
362c535e923SClaudiu Manoil 		struct qm_fqd_oac oac_init;
363c535e923SClaudiu Manoil 	};
364c535e923SClaudiu Manoil 	__be32 context_b;
365c535e923SClaudiu Manoil 	union {
366c535e923SClaudiu Manoil 		/* Treat it as 64-bit opaque */
367c535e923SClaudiu Manoil 		__be64 opaque;
368c535e923SClaudiu Manoil 		struct {
369c535e923SClaudiu Manoil 			__be32 hi;
370c535e923SClaudiu Manoil 			__be32 lo;
371c535e923SClaudiu Manoil 		};
372c535e923SClaudiu Manoil 		/* Treat it as s/w portal stashing config */
373c535e923SClaudiu Manoil 		/* see "FQD Context_A field used for [...]" */
374c535e923SClaudiu Manoil 		struct {
375c535e923SClaudiu Manoil 			struct qm_fqd_stashing stashing;
376c535e923SClaudiu Manoil 			/*
377c535e923SClaudiu Manoil 			 * 48-bit address of FQ context to
378c535e923SClaudiu Manoil 			 * stash, must be cacheline-aligned
379c535e923SClaudiu Manoil 			 */
380c535e923SClaudiu Manoil 			__be16 context_hi;
381c535e923SClaudiu Manoil 			__be32 context_lo;
382c535e923SClaudiu Manoil 		} __packed;
383c535e923SClaudiu Manoil 	} context_a;
384c535e923SClaudiu Manoil 	struct qm_fqd_oac oac_query;
385c535e923SClaudiu Manoil } __packed;
386c535e923SClaudiu Manoil 
387c535e923SClaudiu Manoil #define QM_FQD_CHAN_OFF		3
388c535e923SClaudiu Manoil #define QM_FQD_WQ_MASK		GENMASK(2, 0)
389c535e923SClaudiu Manoil #define QM_FQD_TD_EXP_MASK	GENMASK(4, 0)
390c535e923SClaudiu Manoil #define QM_FQD_TD_MANT_OFF	5
391c535e923SClaudiu Manoil #define QM_FQD_TD_MANT_MASK	GENMASK(12, 5)
392c535e923SClaudiu Manoil #define QM_FQD_TD_MAX		0xe0000000
393c535e923SClaudiu Manoil #define QM_FQD_TD_MANT_MAX	0xff
394c535e923SClaudiu Manoil #define QM_FQD_OAC_OFF		6
395c535e923SClaudiu Manoil #define QM_FQD_AS_OFF		4
396c535e923SClaudiu Manoil #define QM_FQD_DS_OFF		2
397c535e923SClaudiu Manoil #define QM_FQD_XS_MASK		0x3
398c535e923SClaudiu Manoil 
399c535e923SClaudiu Manoil /* 64-bit converters for context_hi/lo */
qm_fqd_stashing_get64(const struct qm_fqd * fqd)400c535e923SClaudiu Manoil static inline u64 qm_fqd_stashing_get64(const struct qm_fqd *fqd)
401c535e923SClaudiu Manoil {
402c535e923SClaudiu Manoil 	return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;
403c535e923SClaudiu Manoil }
404c535e923SClaudiu Manoil 
qm_fqd_stashing_addr(const struct qm_fqd * fqd)405c535e923SClaudiu Manoil static inline dma_addr_t qm_fqd_stashing_addr(const struct qm_fqd *fqd)
406c535e923SClaudiu Manoil {
407c535e923SClaudiu Manoil 	return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;
408c535e923SClaudiu Manoil }
409c535e923SClaudiu Manoil 
qm_fqd_context_a_get64(const struct qm_fqd * fqd)410c535e923SClaudiu Manoil static inline u64 qm_fqd_context_a_get64(const struct qm_fqd *fqd)
411c535e923SClaudiu Manoil {
412c535e923SClaudiu Manoil 	return qm_fqd_stashing_get64(fqd);
413c535e923SClaudiu Manoil }
414c535e923SClaudiu Manoil 
qm_fqd_stashing_set64(struct qm_fqd * fqd,u64 addr)415c535e923SClaudiu Manoil static inline void qm_fqd_stashing_set64(struct qm_fqd *fqd, u64 addr)
416c535e923SClaudiu Manoil {
41718058822SClaudiu Manoil 	fqd->context_a.context_hi = cpu_to_be16(upper_32_bits(addr));
41818058822SClaudiu Manoil 	fqd->context_a.context_lo = cpu_to_be32(lower_32_bits(addr));
419c535e923SClaudiu Manoil }
420c535e923SClaudiu Manoil 
qm_fqd_context_a_set64(struct qm_fqd * fqd,u64 addr)421c535e923SClaudiu Manoil static inline void qm_fqd_context_a_set64(struct qm_fqd *fqd, u64 addr)
422c535e923SClaudiu Manoil {
4239f3670e8SClaudiu Manoil 	fqd->context_a.hi = cpu_to_be32(upper_32_bits(addr));
424c535e923SClaudiu Manoil 	fqd->context_a.lo = cpu_to_be32(lower_32_bits(addr));
425c535e923SClaudiu Manoil }
426c535e923SClaudiu Manoil 
427c535e923SClaudiu Manoil /* convert a threshold value into mant+exp representation */
qm_fqd_set_taildrop(struct qm_fqd * fqd,u32 val,int roundup)428c535e923SClaudiu Manoil static inline int qm_fqd_set_taildrop(struct qm_fqd *fqd, u32 val,
429c535e923SClaudiu Manoil 				      int roundup)
430c535e923SClaudiu Manoil {
431c535e923SClaudiu Manoil 	u32 e = 0;
432c535e923SClaudiu Manoil 	int td, oddbit = 0;
433c535e923SClaudiu Manoil 
434c535e923SClaudiu Manoil 	if (val > QM_FQD_TD_MAX)
435c535e923SClaudiu Manoil 		return -ERANGE;
436c535e923SClaudiu Manoil 
437c535e923SClaudiu Manoil 	while (val > QM_FQD_TD_MANT_MAX) {
438c535e923SClaudiu Manoil 		oddbit = val & 1;
439c535e923SClaudiu Manoil 		val >>= 1;
440c535e923SClaudiu Manoil 		e++;
441c535e923SClaudiu Manoil 		if (roundup && oddbit)
442c535e923SClaudiu Manoil 			val++;
443c535e923SClaudiu Manoil 	}
444c535e923SClaudiu Manoil 
445c535e923SClaudiu Manoil 	td = (val << QM_FQD_TD_MANT_OFF) & QM_FQD_TD_MANT_MASK;
446c535e923SClaudiu Manoil 	td |= (e & QM_FQD_TD_EXP_MASK);
447c535e923SClaudiu Manoil 	fqd->td = cpu_to_be16(td);
448c535e923SClaudiu Manoil 	return 0;
449c535e923SClaudiu Manoil }
450c535e923SClaudiu Manoil /* and the other direction */
qm_fqd_get_taildrop(const struct qm_fqd * fqd)451c535e923SClaudiu Manoil static inline int qm_fqd_get_taildrop(const struct qm_fqd *fqd)
452c535e923SClaudiu Manoil {
453c535e923SClaudiu Manoil 	int td = be16_to_cpu(fqd->td);
454c535e923SClaudiu Manoil 
455c535e923SClaudiu Manoil 	return ((td & QM_FQD_TD_MANT_MASK) >> QM_FQD_TD_MANT_OFF)
456c535e923SClaudiu Manoil 		<< (td & QM_FQD_TD_EXP_MASK);
457c535e923SClaudiu Manoil }
458c535e923SClaudiu Manoil 
qm_fqd_set_stashing(struct qm_fqd * fqd,u8 as,u8 ds,u8 cs)459c535e923SClaudiu Manoil static inline void qm_fqd_set_stashing(struct qm_fqd *fqd, u8 as, u8 ds, u8 cs)
460c535e923SClaudiu Manoil {
461c535e923SClaudiu Manoil 	struct qm_fqd_stashing *st = &fqd->context_a.stashing;
462c535e923SClaudiu Manoil 
463c535e923SClaudiu Manoil 	st->cl = ((as & QM_FQD_XS_MASK) << QM_FQD_AS_OFF) |
464c535e923SClaudiu Manoil 		 ((ds & QM_FQD_XS_MASK) << QM_FQD_DS_OFF) |
465c535e923SClaudiu Manoil 		 (cs & QM_FQD_XS_MASK);
466c535e923SClaudiu Manoil }
467c535e923SClaudiu Manoil 
qm_fqd_get_stashing(const struct qm_fqd * fqd)468c535e923SClaudiu Manoil static inline u8 qm_fqd_get_stashing(const struct qm_fqd *fqd)
469c535e923SClaudiu Manoil {
470c535e923SClaudiu Manoil 	return fqd->context_a.stashing.cl;
471c535e923SClaudiu Manoil }
472c535e923SClaudiu Manoil 
qm_fqd_set_oac(struct qm_fqd * fqd,u8 val)473c535e923SClaudiu Manoil static inline void qm_fqd_set_oac(struct qm_fqd *fqd, u8 val)
474c535e923SClaudiu Manoil {
475c535e923SClaudiu Manoil 	fqd->oac_init.oac = val << QM_FQD_OAC_OFF;
476c535e923SClaudiu Manoil }
477c535e923SClaudiu Manoil 
qm_fqd_set_oal(struct qm_fqd * fqd,s8 val)478c535e923SClaudiu Manoil static inline void qm_fqd_set_oal(struct qm_fqd *fqd, s8 val)
479c535e923SClaudiu Manoil {
480c535e923SClaudiu Manoil 	fqd->oac_init.oal = val;
481c535e923SClaudiu Manoil }
482c535e923SClaudiu Manoil 
qm_fqd_set_destwq(struct qm_fqd * fqd,int ch,int wq)483c535e923SClaudiu Manoil static inline void qm_fqd_set_destwq(struct qm_fqd *fqd, int ch, int wq)
484c535e923SClaudiu Manoil {
485c535e923SClaudiu Manoil 	fqd->dest_wq = cpu_to_be16((ch << QM_FQD_CHAN_OFF) |
486c535e923SClaudiu Manoil 				   (wq & QM_FQD_WQ_MASK));
487c535e923SClaudiu Manoil }
488c535e923SClaudiu Manoil 
qm_fqd_get_chan(const struct qm_fqd * fqd)489c535e923SClaudiu Manoil static inline int qm_fqd_get_chan(const struct qm_fqd *fqd)
490c535e923SClaudiu Manoil {
491c535e923SClaudiu Manoil 	return be16_to_cpu(fqd->dest_wq) >> QM_FQD_CHAN_OFF;
492c535e923SClaudiu Manoil }
493c535e923SClaudiu Manoil 
qm_fqd_get_wq(const struct qm_fqd * fqd)494c535e923SClaudiu Manoil static inline int qm_fqd_get_wq(const struct qm_fqd *fqd)
495c535e923SClaudiu Manoil {
496c535e923SClaudiu Manoil 	return be16_to_cpu(fqd->dest_wq) & QM_FQD_WQ_MASK;
497c535e923SClaudiu Manoil }
498c535e923SClaudiu Manoil 
499c535e923SClaudiu Manoil /* See "Frame Queue Descriptor (FQD)" */
500c535e923SClaudiu Manoil /* Frame Queue Descriptor (FQD) field 'fq_ctrl' uses these constants */
501c535e923SClaudiu Manoil #define QM_FQCTRL_MASK		0x07ff	/* 'fq_ctrl' flags; */
502c535e923SClaudiu Manoil #define QM_FQCTRL_CGE		0x0400	/* Congestion Group Enable */
503c535e923SClaudiu Manoil #define QM_FQCTRL_TDE		0x0200	/* Tail-Drop Enable */
504c535e923SClaudiu Manoil #define QM_FQCTRL_CTXASTASHING	0x0080	/* Context-A stashing */
505c535e923SClaudiu Manoil #define QM_FQCTRL_CPCSTASH	0x0040	/* CPC Stash Enable */
506c535e923SClaudiu Manoil #define QM_FQCTRL_FORCESFDR	0x0008	/* High-priority SFDRs */
507c535e923SClaudiu Manoil #define QM_FQCTRL_AVOIDBLOCK	0x0004	/* Don't block active */
508c535e923SClaudiu Manoil #define QM_FQCTRL_HOLDACTIVE	0x0002	/* Hold active in portal */
509c535e923SClaudiu Manoil #define QM_FQCTRL_PREFERINCACHE	0x0001	/* Aggressively cache FQD */
510c535e923SClaudiu Manoil #define QM_FQCTRL_LOCKINCACHE	QM_FQCTRL_PREFERINCACHE /* older naming */
511c535e923SClaudiu Manoil 
512c535e923SClaudiu Manoil /* See "FQD Context_A field used for [...] */
513c535e923SClaudiu Manoil /* Frame Queue Descriptor (FQD) field 'CONTEXT_A' uses these constants */
514c535e923SClaudiu Manoil #define QM_STASHING_EXCL_ANNOTATION	0x04
515c535e923SClaudiu Manoil #define QM_STASHING_EXCL_DATA		0x02
516c535e923SClaudiu Manoil #define QM_STASHING_EXCL_CTX		0x01
517c535e923SClaudiu Manoil 
518c535e923SClaudiu Manoil /* See "Intra Class Scheduling" */
519c535e923SClaudiu Manoil /* FQD field 'OAC' (Overhead ACcounting) uses these constants */
520c535e923SClaudiu Manoil #define QM_OAC_ICS		0x2 /* Accounting for Intra-Class Scheduling */
521c535e923SClaudiu Manoil #define QM_OAC_CG		0x1 /* Accounting for Congestion Groups */
522c535e923SClaudiu Manoil 
523c535e923SClaudiu Manoil /*
524c535e923SClaudiu Manoil  * This struct represents the 32-bit "WR_PARM_[GYR]" parameters in CGR fields
525c535e923SClaudiu Manoil  * and associated commands/responses. The WRED parameters are calculated from
526c535e923SClaudiu Manoil  * these fields as follows;
527c535e923SClaudiu Manoil  *   MaxTH = MA * (2 ^ Mn)
528c535e923SClaudiu Manoil  *   Slope = SA / (2 ^ Sn)
529c535e923SClaudiu Manoil  *    MaxP = 4 * (Pn + 1)
530c535e923SClaudiu Manoil  */
531c535e923SClaudiu Manoil struct qm_cgr_wr_parm {
532c535e923SClaudiu Manoil 	/* MA[24-31], Mn[19-23], SA[12-18], Sn[6-11], Pn[0-5] */
53318058822SClaudiu Manoil 	__be32 word;
534c535e923SClaudiu Manoil };
535c535e923SClaudiu Manoil /*
536c535e923SClaudiu Manoil  * This struct represents the 13-bit "CS_THRES" CGR field. In the corresponding
537c535e923SClaudiu Manoil  * management commands, this is padded to a 16-bit structure field, so that's
538c535e923SClaudiu Manoil  * how we represent it here. The congestion state threshold is calculated from
539c535e923SClaudiu Manoil  * these fields as follows;
540c535e923SClaudiu Manoil  *   CS threshold = TA * (2 ^ Tn)
541c535e923SClaudiu Manoil  */
542c535e923SClaudiu Manoil struct qm_cgr_cs_thres {
543c535e923SClaudiu Manoil 	/* _res[13-15], TA[5-12], Tn[0-4] */
54418058822SClaudiu Manoil 	__be16 word;
545c535e923SClaudiu Manoil };
546c535e923SClaudiu Manoil /*
547c535e923SClaudiu Manoil  * This identical structure of CGR fields is present in the "Init/Modify CGR"
548c535e923SClaudiu Manoil  * commands and the "Query CGR" result. It's suctioned out here into its own
549c535e923SClaudiu Manoil  * struct.
550c535e923SClaudiu Manoil  */
551c535e923SClaudiu Manoil struct __qm_mc_cgr {
552c535e923SClaudiu Manoil 	struct qm_cgr_wr_parm wr_parm_g;
553c535e923SClaudiu Manoil 	struct qm_cgr_wr_parm wr_parm_y;
554c535e923SClaudiu Manoil 	struct qm_cgr_wr_parm wr_parm_r;
555c535e923SClaudiu Manoil 	u8 wr_en_g;	/* boolean, use QM_CGR_EN */
556c535e923SClaudiu Manoil 	u8 wr_en_y;	/* boolean, use QM_CGR_EN */
557c535e923SClaudiu Manoil 	u8 wr_en_r;	/* boolean, use QM_CGR_EN */
558c535e923SClaudiu Manoil 	u8 cscn_en;	/* boolean, use QM_CGR_EN */
559c535e923SClaudiu Manoil 	union {
560c535e923SClaudiu Manoil 		struct {
56118058822SClaudiu Manoil 			__be16 cscn_targ_upd_ctrl; /* use QM_CGR_TARG_UDP_* */
56218058822SClaudiu Manoil 			__be16 cscn_targ_dcp_low;
563c535e923SClaudiu Manoil 		};
56418058822SClaudiu Manoil 		__be32 cscn_targ;	/* use QM_CGR_TARG_* */
565c535e923SClaudiu Manoil 	};
566c535e923SClaudiu Manoil 	u8 cstd_en;	/* boolean, use QM_CGR_EN */
567c535e923SClaudiu Manoil 	u8 cs;		/* boolean, only used in query response */
568c535e923SClaudiu Manoil 	struct qm_cgr_cs_thres cs_thres; /* use qm_cgr_cs_thres_set64() */
569c535e923SClaudiu Manoil 	u8 mode;	/* QMAN_CGR_MODE_FRAME not supported in rev1.0 */
570c535e923SClaudiu Manoil } __packed;
571c535e923SClaudiu Manoil #define QM_CGR_EN		0x01 /* For wr_en_*, cscn_en, cstd_en */
572c535e923SClaudiu Manoil #define QM_CGR_TARG_UDP_CTRL_WRITE_BIT	0x8000 /* value written to portal bit*/
573c535e923SClaudiu Manoil #define QM_CGR_TARG_UDP_CTRL_DCP	0x4000 /* 0: SWP, 1: DCP */
574c535e923SClaudiu Manoil #define QM_CGR_TARG_PORTAL(n)	(0x80000000 >> (n)) /* s/w portal, 0-9 */
575c535e923SClaudiu Manoil #define QM_CGR_TARG_FMAN0	0x00200000 /* direct-connect portal: fman0 */
576c535e923SClaudiu Manoil #define QM_CGR_TARG_FMAN1	0x00100000 /*			   : fman1 */
577c535e923SClaudiu Manoil /* Convert CGR thresholds to/from "cs_thres" format */
qm_cgr_cs_thres_get64(const struct qm_cgr_cs_thres * th)578c535e923SClaudiu Manoil static inline u64 qm_cgr_cs_thres_get64(const struct qm_cgr_cs_thres *th)
579c535e923SClaudiu Manoil {
58018058822SClaudiu Manoil 	int thres = be16_to_cpu(th->word);
58118058822SClaudiu Manoil 
58218058822SClaudiu Manoil 	return ((thres >> 5) & 0xff) << (thres & 0x1f);
583c535e923SClaudiu Manoil }
584c535e923SClaudiu Manoil 
qm_cgr_cs_thres_set64(struct qm_cgr_cs_thres * th,u64 val,int roundup)585c535e923SClaudiu Manoil static inline int qm_cgr_cs_thres_set64(struct qm_cgr_cs_thres *th, u64 val,
586c535e923SClaudiu Manoil 					int roundup)
587c535e923SClaudiu Manoil {
588c535e923SClaudiu Manoil 	u32 e = 0;
589c535e923SClaudiu Manoil 	int oddbit = 0;
590c535e923SClaudiu Manoil 
591c535e923SClaudiu Manoil 	while (val > 0xff) {
592c535e923SClaudiu Manoil 		oddbit = val & 1;
593c535e923SClaudiu Manoil 		val >>= 1;
594c535e923SClaudiu Manoil 		e++;
595c535e923SClaudiu Manoil 		if (roundup && oddbit)
596c535e923SClaudiu Manoil 			val++;
597c535e923SClaudiu Manoil 	}
59818058822SClaudiu Manoil 	th->word = cpu_to_be16(((val & 0xff) << 5) | (e & 0x1f));
599c535e923SClaudiu Manoil 	return 0;
600c535e923SClaudiu Manoil }
601c535e923SClaudiu Manoil 
602c535e923SClaudiu Manoil /* "Initialize FQ" */
603c535e923SClaudiu Manoil struct qm_mcc_initfq {
604c535e923SClaudiu Manoil 	u8 __reserved1[2];
60518058822SClaudiu Manoil 	__be16 we_mask;	/* Write Enable Mask */
60618058822SClaudiu Manoil 	__be32 fqid;	/* 24-bit */
60718058822SClaudiu Manoil 	__be16 count;	/* Initialises 'count+1' FQDs */
608c535e923SClaudiu Manoil 	struct qm_fqd fqd; /* the FQD fields go here */
609c535e923SClaudiu Manoil 	u8 __reserved2[30];
610c535e923SClaudiu Manoil } __packed;
611c535e923SClaudiu Manoil /* "Initialize/Modify CGR" */
612c535e923SClaudiu Manoil struct qm_mcc_initcgr {
613c535e923SClaudiu Manoil 	u8 __reserve1[2];
61418058822SClaudiu Manoil 	__be16 we_mask;	/* Write Enable Mask */
615c535e923SClaudiu Manoil 	struct __qm_mc_cgr cgr;	/* CGR fields */
616c535e923SClaudiu Manoil 	u8 __reserved2[2];
617c535e923SClaudiu Manoil 	u8 cgid;
618c535e923SClaudiu Manoil 	u8 __reserved3[32];
619c535e923SClaudiu Manoil } __packed;
620c535e923SClaudiu Manoil 
621c535e923SClaudiu Manoil /* INITFQ-specific flags */
622c535e923SClaudiu Manoil #define QM_INITFQ_WE_MASK		0x01ff	/* 'Write Enable' flags; */
623c535e923SClaudiu Manoil #define QM_INITFQ_WE_OAC		0x0100
624c535e923SClaudiu Manoil #define QM_INITFQ_WE_ORPC		0x0080
625c535e923SClaudiu Manoil #define QM_INITFQ_WE_CGID		0x0040
626c535e923SClaudiu Manoil #define QM_INITFQ_WE_FQCTRL		0x0020
627c535e923SClaudiu Manoil #define QM_INITFQ_WE_DESTWQ		0x0010
628c535e923SClaudiu Manoil #define QM_INITFQ_WE_ICSCRED		0x0008
629c535e923SClaudiu Manoil #define QM_INITFQ_WE_TDTHRESH		0x0004
630c535e923SClaudiu Manoil #define QM_INITFQ_WE_CONTEXTB		0x0002
631c535e923SClaudiu Manoil #define QM_INITFQ_WE_CONTEXTA		0x0001
632c535e923SClaudiu Manoil /* INITCGR/MODIFYCGR-specific flags */
633c535e923SClaudiu Manoil #define QM_CGR_WE_MASK			0x07ff	/* 'Write Enable Mask'; */
634c535e923SClaudiu Manoil #define QM_CGR_WE_WR_PARM_G		0x0400
635c535e923SClaudiu Manoil #define QM_CGR_WE_WR_PARM_Y		0x0200
636c535e923SClaudiu Manoil #define QM_CGR_WE_WR_PARM_R		0x0100
637c535e923SClaudiu Manoil #define QM_CGR_WE_WR_EN_G		0x0080
638c535e923SClaudiu Manoil #define QM_CGR_WE_WR_EN_Y		0x0040
639c535e923SClaudiu Manoil #define QM_CGR_WE_WR_EN_R		0x0020
640c535e923SClaudiu Manoil #define QM_CGR_WE_CSCN_EN		0x0010
641c535e923SClaudiu Manoil #define QM_CGR_WE_CSCN_TARG		0x0008
642c535e923SClaudiu Manoil #define QM_CGR_WE_CSTD_EN		0x0004
643c535e923SClaudiu Manoil #define QM_CGR_WE_CS_THRES		0x0002
644c535e923SClaudiu Manoil #define QM_CGR_WE_MODE			0x0001
645c535e923SClaudiu Manoil 
646c535e923SClaudiu Manoil #define QMAN_CGR_FLAG_USE_INIT	     0x00000001
647e5c748a5SHoria Geantă #define QMAN_CGR_MODE_FRAME          0x00000001
648c535e923SClaudiu Manoil 
649c535e923SClaudiu Manoil 	/* Portal and Frame Queues */
650c535e923SClaudiu Manoil /* Represents a managed portal */
651c535e923SClaudiu Manoil struct qman_portal;
652c535e923SClaudiu Manoil 
653c535e923SClaudiu Manoil /*
654c535e923SClaudiu Manoil  * This object type represents QMan frame queue descriptors (FQD), it is
655c535e923SClaudiu Manoil  * cacheline-aligned, and initialised by qman_create_fq(). The structure is
656c535e923SClaudiu Manoil  * defined further down.
657c535e923SClaudiu Manoil  */
658c535e923SClaudiu Manoil struct qman_fq;
659c535e923SClaudiu Manoil 
660c535e923SClaudiu Manoil /*
661c535e923SClaudiu Manoil  * This object type represents a QMan congestion group, it is defined further
662c535e923SClaudiu Manoil  * down.
663c535e923SClaudiu Manoil  */
664c535e923SClaudiu Manoil struct qman_cgr;
665c535e923SClaudiu Manoil 
666c535e923SClaudiu Manoil /*
667c535e923SClaudiu Manoil  * This enum, and the callback type that returns it, are used when handling
668c535e923SClaudiu Manoil  * dequeued frames via DQRR. Note that for "null" callbacks registered with the
669efe848cdSClaudiu Manoil  * portal object (for handling dequeues that do not demux because context_b is
670c535e923SClaudiu Manoil  * NULL), the return value *MUST* be qman_cb_dqrr_consume.
671c535e923SClaudiu Manoil  */
672c535e923SClaudiu Manoil enum qman_cb_dqrr_result {
673c535e923SClaudiu Manoil 	/* DQRR entry can be consumed */
674c535e923SClaudiu Manoil 	qman_cb_dqrr_consume,
675c535e923SClaudiu Manoil 	/* Like _consume, but requests parking - FQ must be held-active */
676c535e923SClaudiu Manoil 	qman_cb_dqrr_park,
677c535e923SClaudiu Manoil 	/* Does not consume, for DCA mode only. */
678c535e923SClaudiu Manoil 	qman_cb_dqrr_defer,
679c535e923SClaudiu Manoil 	/*
680c535e923SClaudiu Manoil 	 * Stop processing without consuming this ring entry. Exits the current
681c535e923SClaudiu Manoil 	 * qman_p_poll_dqrr() or interrupt-handling, as appropriate. If within
682c535e923SClaudiu Manoil 	 * an interrupt handler, the callback would typically call
683c535e923SClaudiu Manoil 	 * qman_irqsource_remove(QM_PIRQ_DQRI) before returning this value,
684c535e923SClaudiu Manoil 	 * otherwise the interrupt will reassert immediately.
685c535e923SClaudiu Manoil 	 */
686c535e923SClaudiu Manoil 	qman_cb_dqrr_stop,
687c535e923SClaudiu Manoil 	/* Like qman_cb_dqrr_stop, but consumes the current entry. */
688c535e923SClaudiu Manoil 	qman_cb_dqrr_consume_stop
689c535e923SClaudiu Manoil };
690c535e923SClaudiu Manoil typedef enum qman_cb_dqrr_result (*qman_cb_dqrr)(struct qman_portal *qm,
691c535e923SClaudiu Manoil 					struct qman_fq *fq,
692f84754dbSSebastian Andrzej Siewior 					const struct qm_dqrr_entry *dqrr,
693f84754dbSSebastian Andrzej Siewior 					bool sched_napi);
694c535e923SClaudiu Manoil 
695c535e923SClaudiu Manoil /*
696c535e923SClaudiu Manoil  * This callback type is used when handling ERNs, FQRNs and FQRLs via MR. They
697c535e923SClaudiu Manoil  * are always consumed after the callback returns.
698c535e923SClaudiu Manoil  */
699c535e923SClaudiu Manoil typedef void (*qman_cb_mr)(struct qman_portal *qm, struct qman_fq *fq,
700c535e923SClaudiu Manoil 			   const union qm_mr_entry *msg);
701c535e923SClaudiu Manoil 
702c535e923SClaudiu Manoil /*
703c535e923SClaudiu Manoil  * s/w-visible states. Ie. tentatively scheduled + truly scheduled + active +
704c535e923SClaudiu Manoil  * held-active + held-suspended are just "sched". Things like "retired" will not
705c535e923SClaudiu Manoil  * be assumed until it is complete (ie. QMAN_FQ_STATE_CHANGING is set until
706c535e923SClaudiu Manoil  * then, to indicate it's completing and to gate attempts to retry the retire
707c535e923SClaudiu Manoil  * command). Note, park commands do not set QMAN_FQ_STATE_CHANGING because it's
708c535e923SClaudiu Manoil  * technically impossible in the case of enqueue DCAs (which refer to DQRR ring
709c535e923SClaudiu Manoil  * index rather than the FQ that ring entry corresponds to), so repeated park
710c535e923SClaudiu Manoil  * commands are allowed (if you're silly enough to try) but won't change FQ
711c535e923SClaudiu Manoil  * state, and the resulting park notifications move FQs from "sched" to
712c535e923SClaudiu Manoil  * "parked".
713c535e923SClaudiu Manoil  */
714c535e923SClaudiu Manoil enum qman_fq_state {
715c535e923SClaudiu Manoil 	qman_fq_state_oos,
716c535e923SClaudiu Manoil 	qman_fq_state_parked,
717c535e923SClaudiu Manoil 	qman_fq_state_sched,
718c535e923SClaudiu Manoil 	qman_fq_state_retired
719c535e923SClaudiu Manoil };
720c535e923SClaudiu Manoil 
721c535e923SClaudiu Manoil #define QMAN_FQ_STATE_CHANGING	     0x80000000 /* 'state' is changing */
722c535e923SClaudiu Manoil #define QMAN_FQ_STATE_NE	     0x40000000 /* retired FQ isn't empty */
723c535e923SClaudiu Manoil #define QMAN_FQ_STATE_ORL	     0x20000000 /* retired FQ has ORL */
724c535e923SClaudiu Manoil #define QMAN_FQ_STATE_BLOCKOOS	     0xe0000000 /* if any are set, no OOS */
725c535e923SClaudiu Manoil #define QMAN_FQ_STATE_CGR_EN	     0x10000000 /* CGR enabled */
726c535e923SClaudiu Manoil #define QMAN_FQ_STATE_VDQCR	     0x08000000 /* being volatile dequeued */
727c535e923SClaudiu Manoil 
728c535e923SClaudiu Manoil /*
729c535e923SClaudiu Manoil  * Frame queue objects (struct qman_fq) are stored within memory passed to
730c535e923SClaudiu Manoil  * qman_create_fq(), as this allows stashing of caller-provided demux callback
731c535e923SClaudiu Manoil  * pointers at no extra cost to stashing of (driver-internal) FQ state. If the
732c535e923SClaudiu Manoil  * caller wishes to add per-FQ state and have it benefit from dequeue-stashing,
733c535e923SClaudiu Manoil  * they should;
734c535e923SClaudiu Manoil  *
735c535e923SClaudiu Manoil  * (a) extend the qman_fq structure with their state; eg.
736c535e923SClaudiu Manoil  *
737c535e923SClaudiu Manoil  *     // myfq is allocated and driver_fq callbacks filled in;
738c535e923SClaudiu Manoil  *     struct my_fq {
739c535e923SClaudiu Manoil  *	   struct qman_fq base;
740c535e923SClaudiu Manoil  *	   int an_extra_field;
741c535e923SClaudiu Manoil  *	   [ ... add other fields to be associated with each FQ ...]
742c535e923SClaudiu Manoil  *     } *myfq = some_my_fq_allocator();
743c535e923SClaudiu Manoil  *     struct qman_fq *fq = qman_create_fq(fqid, flags, &myfq->base);
744c535e923SClaudiu Manoil  *
745c535e923SClaudiu Manoil  *     // in a dequeue callback, access extra fields from 'fq' via a cast;
746c535e923SClaudiu Manoil  *     struct my_fq *myfq = (struct my_fq *)fq;
747c535e923SClaudiu Manoil  *     do_something_with(myfq->an_extra_field);
748c535e923SClaudiu Manoil  *     [...]
749c535e923SClaudiu Manoil  *
750c535e923SClaudiu Manoil  * (b) when and if configuring the FQ for context stashing, specify how ever
751c535e923SClaudiu Manoil  *     many cachelines are required to stash 'struct my_fq', to accelerate not
752c535e923SClaudiu Manoil  *     only the QMan driver but the callback as well.
753c535e923SClaudiu Manoil  */
754c535e923SClaudiu Manoil 
755c535e923SClaudiu Manoil struct qman_fq_cb {
756c535e923SClaudiu Manoil 	qman_cb_dqrr dqrr;	/* for dequeued frames */
757c535e923SClaudiu Manoil 	qman_cb_mr ern;		/* for s/w ERNs */
758c535e923SClaudiu Manoil 	qman_cb_mr fqs;		/* frame-queue state changes*/
759c535e923SClaudiu Manoil };
760c535e923SClaudiu Manoil 
761c535e923SClaudiu Manoil struct qman_fq {
762c535e923SClaudiu Manoil 	/* Caller of qman_create_fq() provides these demux callbacks */
763c535e923SClaudiu Manoil 	struct qman_fq_cb cb;
764c535e923SClaudiu Manoil 	/*
765c535e923SClaudiu Manoil 	 * These are internal to the driver, don't touch. In particular, they
766c535e923SClaudiu Manoil 	 * may change, be removed, or extended (so you shouldn't rely on
767c535e923SClaudiu Manoil 	 * sizeof(qman_fq) being a constant).
768c535e923SClaudiu Manoil 	 */
769c535e923SClaudiu Manoil 	u32 fqid, idx;
770c535e923SClaudiu Manoil 	unsigned long flags;
771c535e923SClaudiu Manoil 	enum qman_fq_state state;
772c535e923SClaudiu Manoil 	int cgr_groupid;
773c535e923SClaudiu Manoil };
774c535e923SClaudiu Manoil 
775c535e923SClaudiu Manoil /*
776c535e923SClaudiu Manoil  * This callback type is used when handling congestion group entry/exit.
777c535e923SClaudiu Manoil  * 'congested' is non-zero on congestion-entry, and zero on congestion-exit.
778c535e923SClaudiu Manoil  */
779c535e923SClaudiu Manoil typedef void (*qman_cb_cgr)(struct qman_portal *qm,
780c535e923SClaudiu Manoil 			    struct qman_cgr *cgr, int congested);
781c535e923SClaudiu Manoil 
782c535e923SClaudiu Manoil struct qman_cgr {
783c535e923SClaudiu Manoil 	/* Set these prior to qman_create_cgr() */
784c535e923SClaudiu Manoil 	u32 cgrid; /* 0..255, but u32 to allow specials like -1, 256, etc.*/
785c535e923SClaudiu Manoil 	qman_cb_cgr cb;
786c535e923SClaudiu Manoil 	/* These are private to the driver */
787c535e923SClaudiu Manoil 	u16 chan; /* portal channel this object is created on */
788c535e923SClaudiu Manoil 	struct list_head node;
789c535e923SClaudiu Manoil };
790c535e923SClaudiu Manoil 
791c535e923SClaudiu Manoil /* Flags to qman_create_fq() */
792c535e923SClaudiu Manoil #define QMAN_FQ_FLAG_NO_ENQUEUE	     0x00000001 /* can't enqueue */
793c535e923SClaudiu Manoil #define QMAN_FQ_FLAG_NO_MODIFY	     0x00000002 /* can only enqueue */
794c535e923SClaudiu Manoil #define QMAN_FQ_FLAG_TO_DCPORTAL     0x00000004 /* consumed by CAAM/PME/Fman */
795c535e923SClaudiu Manoil #define QMAN_FQ_FLAG_DYNAMIC_FQID    0x00000020 /* (de)allocate fqid */
796c535e923SClaudiu Manoil 
797c535e923SClaudiu Manoil /* Flags to qman_init_fq() */
798c535e923SClaudiu Manoil #define QMAN_INITFQ_FLAG_SCHED	     0x00000001 /* schedule rather than park */
799c535e923SClaudiu Manoil #define QMAN_INITFQ_FLAG_LOCAL	     0x00000004 /* set dest portal */
800c535e923SClaudiu Manoil 
8011662e931SHoria Geantă /*
8021662e931SHoria Geantă  * For qman_volatile_dequeue(); Choose one PRECEDENCE. EXACT is optional. Use
8031662e931SHoria Geantă  * NUMFRAMES(n) (6-bit) or NUMFRAMES_TILLEMPTY to fill in the frame-count. Use
8041662e931SHoria Geantă  * FQID(n) to fill in the frame queue ID.
8051662e931SHoria Geantă  */
8061662e931SHoria Geantă #define QM_VDQCR_PRECEDENCE_VDQCR	0x0
8071662e931SHoria Geantă #define QM_VDQCR_PRECEDENCE_SDQCR	0x80000000
8081662e931SHoria Geantă #define QM_VDQCR_EXACT			0x40000000
8091662e931SHoria Geantă #define QM_VDQCR_NUMFRAMES_MASK		0x3f000000
8101662e931SHoria Geantă #define QM_VDQCR_NUMFRAMES_SET(n)	(((n) & 0x3f) << 24)
8111662e931SHoria Geantă #define QM_VDQCR_NUMFRAMES_GET(n)	(((n) >> 24) & 0x3f)
8121662e931SHoria Geantă #define QM_VDQCR_NUMFRAMES_TILLEMPTY	QM_VDQCR_NUMFRAMES_SET(0)
8131662e931SHoria Geantă 
8141662e931SHoria Geantă #define QMAN_VOLATILE_FLAG_WAIT	     0x00000001 /* wait if VDQCR is in use */
8151662e931SHoria Geantă #define QMAN_VOLATILE_FLAG_WAIT_INT  0x00000002 /* if wait, interruptible? */
8161662e931SHoria Geantă #define QMAN_VOLATILE_FLAG_FINISH    0x00000004 /* wait till VDQCR completes */
8171662e931SHoria Geantă 
8188496272dSHoria Geantă /* "Query FQ Non-Programmable Fields" */
8198496272dSHoria Geantă struct qm_mcr_queryfq_np {
8208496272dSHoria Geantă 	u8 verb;
8218496272dSHoria Geantă 	u8 result;
8228496272dSHoria Geantă 	u8 __reserved1;
8238496272dSHoria Geantă 	u8 state;		/* QM_MCR_NP_STATE_*** */
8248496272dSHoria Geantă 	u32 fqd_link;		/* 24-bit, _res2[24-31] */
8258496272dSHoria Geantă 	u16 odp_seq;		/* 14-bit, _res3[14-15] */
8268496272dSHoria Geantă 	u16 orp_nesn;		/* 14-bit, _res4[14-15] */
8278496272dSHoria Geantă 	u16 orp_ea_hseq;	/* 15-bit, _res5[15] */
8288496272dSHoria Geantă 	u16 orp_ea_tseq;	/* 15-bit, _res6[15] */
8298496272dSHoria Geantă 	u32 orp_ea_hptr;	/* 24-bit, _res7[24-31] */
8308496272dSHoria Geantă 	u32 orp_ea_tptr;	/* 24-bit, _res8[24-31] */
8318496272dSHoria Geantă 	u32 pfdr_hptr;		/* 24-bit, _res9[24-31] */
8328496272dSHoria Geantă 	u32 pfdr_tptr;		/* 24-bit, _res10[24-31] */
8338496272dSHoria Geantă 	u8 __reserved2[5];
8348496272dSHoria Geantă 	u8 is;			/* 1-bit, _res12[1-7] */
8358496272dSHoria Geantă 	u16 ics_surp;
8368496272dSHoria Geantă 	u32 byte_cnt;
8378496272dSHoria Geantă 	u32 frm_cnt;		/* 24-bit, _res13[24-31] */
8388496272dSHoria Geantă 	u32 __reserved3;
8398496272dSHoria Geantă 	u16 ra1_sfdr;		/* QM_MCR_NP_RA1_*** */
8408496272dSHoria Geantă 	u16 ra2_sfdr;		/* QM_MCR_NP_RA2_*** */
8418496272dSHoria Geantă 	u16 __reserved4;
8428496272dSHoria Geantă 	u16 od1_sfdr;		/* QM_MCR_NP_OD1_*** */
8438496272dSHoria Geantă 	u16 od2_sfdr;		/* QM_MCR_NP_OD2_*** */
8448496272dSHoria Geantă 	u16 od3_sfdr;		/* QM_MCR_NP_OD3_*** */
8458496272dSHoria Geantă } __packed;
8468496272dSHoria Geantă 
8478496272dSHoria Geantă #define QM_MCR_NP_STATE_FE		0x10
8488496272dSHoria Geantă #define QM_MCR_NP_STATE_R		0x08
8498496272dSHoria Geantă #define QM_MCR_NP_STATE_MASK		0x07	/* Reads FQD::STATE; */
8508496272dSHoria Geantă #define QM_MCR_NP_STATE_OOS		0x00
8518496272dSHoria Geantă #define QM_MCR_NP_STATE_RETIRED		0x01
8528496272dSHoria Geantă #define QM_MCR_NP_STATE_TEN_SCHED	0x02
8538496272dSHoria Geantă #define QM_MCR_NP_STATE_TRU_SCHED	0x03
8548496272dSHoria Geantă #define QM_MCR_NP_STATE_PARKED		0x04
8558496272dSHoria Geantă #define QM_MCR_NP_STATE_ACTIVE		0x05
8568496272dSHoria Geantă #define QM_MCR_NP_PTR_MASK		0x07ff	/* for RA[12] & OD[123] */
8578496272dSHoria Geantă #define QM_MCR_NP_RA1_NRA(v)		(((v) >> 14) & 0x3)	/* FQD::NRA */
8588496272dSHoria Geantă #define QM_MCR_NP_RA2_IT(v)		(((v) >> 14) & 0x1)	/* FQD::IT */
8598496272dSHoria Geantă #define QM_MCR_NP_OD1_NOD(v)		(((v) >> 14) & 0x3)	/* FQD::NOD */
8608496272dSHoria Geantă #define QM_MCR_NP_OD3_NPC(v)		(((v) >> 14) & 0x3)	/* FQD::NPC */
8618496272dSHoria Geantă 
8628496272dSHoria Geantă enum qm_mcr_queryfq_np_masks {
8638496272dSHoria Geantă 	qm_mcr_fqd_link_mask = BIT(24) - 1,
8648496272dSHoria Geantă 	qm_mcr_odp_seq_mask = BIT(14) - 1,
8658496272dSHoria Geantă 	qm_mcr_orp_nesn_mask = BIT(14) - 1,
8668496272dSHoria Geantă 	qm_mcr_orp_ea_hseq_mask = BIT(15) - 1,
8678496272dSHoria Geantă 	qm_mcr_orp_ea_tseq_mask = BIT(15) - 1,
8688496272dSHoria Geantă 	qm_mcr_orp_ea_hptr_mask = BIT(24) - 1,
8698496272dSHoria Geantă 	qm_mcr_orp_ea_tptr_mask = BIT(24) - 1,
8708496272dSHoria Geantă 	qm_mcr_pfdr_hptr_mask = BIT(24) - 1,
8718496272dSHoria Geantă 	qm_mcr_pfdr_tptr_mask = BIT(24) - 1,
8728496272dSHoria Geantă 	qm_mcr_is_mask = BIT(1) - 1,
8738496272dSHoria Geantă 	qm_mcr_frm_cnt_mask = BIT(24) - 1,
8748496272dSHoria Geantă };
8758496272dSHoria Geantă 
8768496272dSHoria Geantă #define qm_mcr_np_get(np, field) \
8778496272dSHoria Geantă 	((np)->field & (qm_mcr_##field##_mask))
8788496272dSHoria Geantă 
879c535e923SClaudiu Manoil 	/* Portal Management */
880c535e923SClaudiu Manoil /**
881c535e923SClaudiu Manoil  * qman_p_irqsource_add - add processing sources to be interrupt-driven
882c535e923SClaudiu Manoil  * @bits: bitmask of QM_PIRQ_**I processing sources
883c535e923SClaudiu Manoil  *
884c535e923SClaudiu Manoil  * Adds processing sources that should be interrupt-driven (rather than
885c535e923SClaudiu Manoil  * processed via qman_poll_***() functions).
886c535e923SClaudiu Manoil  */
887c535e923SClaudiu Manoil void qman_p_irqsource_add(struct qman_portal *p, u32 bits);
888c535e923SClaudiu Manoil 
889c535e923SClaudiu Manoil /**
890c535e923SClaudiu Manoil  * qman_p_irqsource_remove - remove processing sources from being int-driven
891c535e923SClaudiu Manoil  * @bits: bitmask of QM_PIRQ_**I processing sources
892c535e923SClaudiu Manoil  *
893c535e923SClaudiu Manoil  * Removes processing sources from being interrupt-driven, so that they will
894c535e923SClaudiu Manoil  * instead be processed via qman_poll_***() functions.
895c535e923SClaudiu Manoil  */
896c535e923SClaudiu Manoil void qman_p_irqsource_remove(struct qman_portal *p, u32 bits);
897c535e923SClaudiu Manoil 
898c535e923SClaudiu Manoil /**
899c535e923SClaudiu Manoil  * qman_affine_cpus - return a mask of cpus that have affine portals
900c535e923SClaudiu Manoil  */
901c535e923SClaudiu Manoil const cpumask_t *qman_affine_cpus(void);
902c535e923SClaudiu Manoil 
903c535e923SClaudiu Manoil /**
904c535e923SClaudiu Manoil  * qman_affine_channel - return the channel ID of an portal
905c535e923SClaudiu Manoil  * @cpu: the cpu whose affine portal is the subject of the query
906c535e923SClaudiu Manoil  *
907c535e923SClaudiu Manoil  * If @cpu is -1, the affine portal for the current CPU will be used. It is a
908c535e923SClaudiu Manoil  * bug to call this function for any value of @cpu (other than -1) that is not a
909c535e923SClaudiu Manoil  * member of the mask returned from qman_affine_cpus().
910c535e923SClaudiu Manoil  */
911c535e923SClaudiu Manoil u16 qman_affine_channel(int cpu);
912c535e923SClaudiu Manoil 
913c535e923SClaudiu Manoil /**
914c535e923SClaudiu Manoil  * qman_get_affine_portal - return the portal pointer affine to cpu
915c535e923SClaudiu Manoil  * @cpu: the cpu whose affine portal is the subject of the query
916c535e923SClaudiu Manoil  */
917c535e923SClaudiu Manoil struct qman_portal *qman_get_affine_portal(int cpu);
918c535e923SClaudiu Manoil 
919c535e923SClaudiu Manoil /**
920a2d00f3dSMadalin Bucur  * qman_start_using_portal - register a device link for the portal user
921a2d00f3dSMadalin Bucur  * @p: the portal that will be in use
922a2d00f3dSMadalin Bucur  * @dev: the device that will use the portal
923a2d00f3dSMadalin Bucur  *
924a2d00f3dSMadalin Bucur  * Makes sure that the devices that use the portal are unbound when the
925a2d00f3dSMadalin Bucur  * portal is unbound
926a2d00f3dSMadalin Bucur  */
927a2d00f3dSMadalin Bucur int qman_start_using_portal(struct qman_portal *p, struct device *dev);
928a2d00f3dSMadalin Bucur 
929a2d00f3dSMadalin Bucur /**
930c535e923SClaudiu Manoil  * qman_p_poll_dqrr - process DQRR (fast-path) entries
931c535e923SClaudiu Manoil  * @limit: the maximum number of DQRR entries to process
932c535e923SClaudiu Manoil  *
933c535e923SClaudiu Manoil  * Use of this function requires that DQRR processing not be interrupt-driven.
934c535e923SClaudiu Manoil  * The return value represents the number of DQRR entries processed.
935c535e923SClaudiu Manoil  */
936c535e923SClaudiu Manoil int qman_p_poll_dqrr(struct qman_portal *p, unsigned int limit);
937c535e923SClaudiu Manoil 
938c535e923SClaudiu Manoil /**
939c535e923SClaudiu Manoil  * qman_p_static_dequeue_add - Add pool channels to the portal SDQCR
940c535e923SClaudiu Manoil  * @pools: bit-mask of pool channels, using QM_SDQCR_CHANNELS_POOL(n)
941c535e923SClaudiu Manoil  *
942c535e923SClaudiu Manoil  * Adds a set of pool channels to the portal's static dequeue command register
943c535e923SClaudiu Manoil  * (SDQCR). The requested pools are limited to those the portal has dequeue
944c535e923SClaudiu Manoil  * access to.
945c535e923SClaudiu Manoil  */
946c535e923SClaudiu Manoil void qman_p_static_dequeue_add(struct qman_portal *p, u32 pools);
947c535e923SClaudiu Manoil 
948c535e923SClaudiu Manoil 	/* FQ management */
949c535e923SClaudiu Manoil /**
950c535e923SClaudiu Manoil  * qman_create_fq - Allocates a FQ
951c535e923SClaudiu Manoil  * @fqid: the index of the FQD to encapsulate, must be "Out of Service"
952c535e923SClaudiu Manoil  * @flags: bit-mask of QMAN_FQ_FLAG_*** options
953c535e923SClaudiu Manoil  * @fq: memory for storing the 'fq', with callbacks filled in
954c535e923SClaudiu Manoil  *
955c535e923SClaudiu Manoil  * Creates a frame queue object for the given @fqid, unless the
956c535e923SClaudiu Manoil  * QMAN_FQ_FLAG_DYNAMIC_FQID flag is set in @flags, in which case a FQID is
957c535e923SClaudiu Manoil  * dynamically allocated (or the function fails if none are available). Once
958c535e923SClaudiu Manoil  * created, the caller should not touch the memory at 'fq' except as extended to
959c535e923SClaudiu Manoil  * adjacent memory for user-defined fields (see the definition of "struct
960c535e923SClaudiu Manoil  * qman_fq" for more info). NO_MODIFY is only intended for enqueuing to
961c535e923SClaudiu Manoil  * pre-existing frame-queues that aren't to be otherwise interfered with, it
962c535e923SClaudiu Manoil  * prevents all other modifications to the frame queue. The TO_DCPORTAL flag
963efe848cdSClaudiu Manoil  * causes the driver to honour any context_b modifications requested in the
964c535e923SClaudiu Manoil  * qm_init_fq() API, as this indicates the frame queue will be consumed by a
965c535e923SClaudiu Manoil  * direct-connect portal (PME, CAAM, or Fman). When frame queues are consumed by
966efe848cdSClaudiu Manoil  * software portals, the context_b field is controlled by the driver and can't
967efe848cdSClaudiu Manoil  * be modified by the caller.
968c535e923SClaudiu Manoil  */
969c535e923SClaudiu Manoil int qman_create_fq(u32 fqid, u32 flags, struct qman_fq *fq);
970c535e923SClaudiu Manoil 
971c535e923SClaudiu Manoil /**
972c535e923SClaudiu Manoil  * qman_destroy_fq - Deallocates a FQ
973c535e923SClaudiu Manoil  * @fq: the frame queue object to release
974c535e923SClaudiu Manoil  *
975c535e923SClaudiu Manoil  * The memory for this frame queue object ('fq' provided in qman_create_fq()) is
976c535e923SClaudiu Manoil  * not deallocated but the caller regains ownership, to do with as desired. The
977c535e923SClaudiu Manoil  * FQ must be in the 'out-of-service' or in the 'parked' state.
978c535e923SClaudiu Manoil  */
979c535e923SClaudiu Manoil void qman_destroy_fq(struct qman_fq *fq);
980c535e923SClaudiu Manoil 
981c535e923SClaudiu Manoil /**
982c535e923SClaudiu Manoil  * qman_fq_fqid - Queries the frame queue ID of a FQ object
983c535e923SClaudiu Manoil  * @fq: the frame queue object to query
984c535e923SClaudiu Manoil  */
985c535e923SClaudiu Manoil u32 qman_fq_fqid(struct qman_fq *fq);
986c535e923SClaudiu Manoil 
987c535e923SClaudiu Manoil /**
988c535e923SClaudiu Manoil  * qman_init_fq - Initialises FQ fields, leaves the FQ "parked" or "scheduled"
989c535e923SClaudiu Manoil  * @fq: the frame queue object to modify, must be 'parked' or new.
990c535e923SClaudiu Manoil  * @flags: bit-mask of QMAN_INITFQ_FLAG_*** options
991c535e923SClaudiu Manoil  * @opts: the FQ-modification settings, as defined in the low-level API
992c535e923SClaudiu Manoil  *
993c535e923SClaudiu Manoil  * The @opts parameter comes from the low-level portal API. Select
994c535e923SClaudiu Manoil  * QMAN_INITFQ_FLAG_SCHED in @flags to cause the frame queue to be scheduled
995c535e923SClaudiu Manoil  * rather than parked. NB, @opts can be NULL.
996c535e923SClaudiu Manoil  *
997c535e923SClaudiu Manoil  * Note that some fields and options within @opts may be ignored or overwritten
998c535e923SClaudiu Manoil  * by the driver;
999c535e923SClaudiu Manoil  * 1. the 'count' and 'fqid' fields are always ignored (this operation only
1000c535e923SClaudiu Manoil  * affects one frame queue: @fq).
1001c535e923SClaudiu Manoil  * 2. the QM_INITFQ_WE_CONTEXTB option of the 'we_mask' field and the associated
1002c535e923SClaudiu Manoil  * 'fqd' structure's 'context_b' field are sometimes overwritten;
1003c535e923SClaudiu Manoil  *   - if @fq was not created with QMAN_FQ_FLAG_TO_DCPORTAL, then context_b is
1004c535e923SClaudiu Manoil  *     initialised to a value used by the driver for demux.
1005c535e923SClaudiu Manoil  *   - if context_b is initialised for demux, so is context_a in case stashing
1006c535e923SClaudiu Manoil  *     is requested (see item 4).
1007c535e923SClaudiu Manoil  * (So caller control of context_b is only possible for TO_DCPORTAL frame queue
1008c535e923SClaudiu Manoil  * objects.)
1009c535e923SClaudiu Manoil  * 3. if @flags contains QMAN_INITFQ_FLAG_LOCAL, the 'fqd' structure's
1010c535e923SClaudiu Manoil  * 'dest::channel' field will be overwritten to match the portal used to issue
1011c535e923SClaudiu Manoil  * the command. If the WE_DESTWQ write-enable bit had already been set by the
1012c535e923SClaudiu Manoil  * caller, the channel workqueue will be left as-is, otherwise the write-enable
1013c535e923SClaudiu Manoil  * bit is set and the workqueue is set to a default of 4. If the "LOCAL" flag
1014c535e923SClaudiu Manoil  * isn't set, the destination channel/workqueue fields and the write-enable bit
1015c535e923SClaudiu Manoil  * are left as-is.
1016c535e923SClaudiu Manoil  * 4. if the driver overwrites context_a/b for demux, then if
1017c535e923SClaudiu Manoil  * QM_INITFQ_WE_CONTEXTA is set, the driver will only overwrite
1018c535e923SClaudiu Manoil  * context_a.address fields and will leave the stashing fields provided by the
1019c535e923SClaudiu Manoil  * user alone, otherwise it will zero out the context_a.stashing fields.
1020c535e923SClaudiu Manoil  */
1021c535e923SClaudiu Manoil int qman_init_fq(struct qman_fq *fq, u32 flags, struct qm_mcc_initfq *opts);
1022c535e923SClaudiu Manoil 
1023c535e923SClaudiu Manoil /**
1024c535e923SClaudiu Manoil  * qman_schedule_fq - Schedules a FQ
1025c535e923SClaudiu Manoil  * @fq: the frame queue object to schedule, must be 'parked'
1026c535e923SClaudiu Manoil  *
1027c535e923SClaudiu Manoil  * Schedules the frame queue, which must be Parked, which takes it to
1028c535e923SClaudiu Manoil  * Tentatively-Scheduled or Truly-Scheduled depending on its fill-level.
1029c535e923SClaudiu Manoil  */
1030c535e923SClaudiu Manoil int qman_schedule_fq(struct qman_fq *fq);
1031c535e923SClaudiu Manoil 
1032c535e923SClaudiu Manoil /**
1033c535e923SClaudiu Manoil  * qman_retire_fq - Retires a FQ
1034c535e923SClaudiu Manoil  * @fq: the frame queue object to retire
1035c535e923SClaudiu Manoil  * @flags: FQ flags (QMAN_FQ_STATE*) if retirement completes immediately
1036c535e923SClaudiu Manoil  *
1037c535e923SClaudiu Manoil  * Retires the frame queue. This returns zero if it succeeds immediately, +1 if
1038c535e923SClaudiu Manoil  * the retirement was started asynchronously, otherwise it returns negative for
1039c535e923SClaudiu Manoil  * failure. When this function returns zero, @flags is set to indicate whether
1040c535e923SClaudiu Manoil  * the retired FQ is empty and/or whether it has any ORL fragments (to show up
1041c535e923SClaudiu Manoil  * as ERNs). Otherwise the corresponding flags will be known when a subsequent
1042c535e923SClaudiu Manoil  * FQRN message shows up on the portal's message ring.
1043c535e923SClaudiu Manoil  *
1044c535e923SClaudiu Manoil  * NB, if the retirement is asynchronous (the FQ was in the Truly Scheduled or
1045c535e923SClaudiu Manoil  * Active state), the completion will be via the message ring as a FQRN - but
1046c535e923SClaudiu Manoil  * the corresponding callback may occur before this function returns!! Ie. the
1047c535e923SClaudiu Manoil  * caller should be prepared to accept the callback as the function is called,
1048c535e923SClaudiu Manoil  * not only once it has returned.
1049c535e923SClaudiu Manoil  */
1050c535e923SClaudiu Manoil int qman_retire_fq(struct qman_fq *fq, u32 *flags);
1051c535e923SClaudiu Manoil 
1052c535e923SClaudiu Manoil /**
1053c535e923SClaudiu Manoil  * qman_oos_fq - Puts a FQ "out of service"
1054c535e923SClaudiu Manoil  * @fq: the frame queue object to be put out-of-service, must be 'retired'
1055c535e923SClaudiu Manoil  *
1056c535e923SClaudiu Manoil  * The frame queue must be retired and empty, and if any order restoration list
1057c535e923SClaudiu Manoil  * was released as ERNs at the time of retirement, they must all be consumed.
1058c535e923SClaudiu Manoil  */
1059c535e923SClaudiu Manoil int qman_oos_fq(struct qman_fq *fq);
1060c535e923SClaudiu Manoil 
10611662e931SHoria Geantă /*
10621662e931SHoria Geantă  * qman_volatile_dequeue - Issue a volatile dequeue command
10631662e931SHoria Geantă  * @fq: the frame queue object to dequeue from
10641662e931SHoria Geantă  * @flags: a bit-mask of QMAN_VOLATILE_FLAG_*** options
10651662e931SHoria Geantă  * @vdqcr: bit mask of QM_VDQCR_*** options, as per qm_dqrr_vdqcr_set()
10661662e931SHoria Geantă  *
10671662e931SHoria Geantă  * Attempts to lock access to the portal's VDQCR volatile dequeue functionality.
10681662e931SHoria Geantă  * The function will block and sleep if QMAN_VOLATILE_FLAG_WAIT is specified and
10691662e931SHoria Geantă  * the VDQCR is already in use, otherwise returns non-zero for failure. If
10701662e931SHoria Geantă  * QMAN_VOLATILE_FLAG_FINISH is specified, the function will only return once
10711662e931SHoria Geantă  * the VDQCR command has finished executing (ie. once the callback for the last
10721662e931SHoria Geantă  * DQRR entry resulting from the VDQCR command has been called). If not using
10731662e931SHoria Geantă  * the FINISH flag, completion can be determined either by detecting the
10741662e931SHoria Geantă  * presence of the QM_DQRR_STAT_UNSCHEDULED and QM_DQRR_STAT_DQCR_EXPIRED bits
10751662e931SHoria Geantă  * in the "stat" parameter passed to the FQ's dequeue callback, or by waiting
10761662e931SHoria Geantă  * for the QMAN_FQ_STATE_VDQCR bit to disappear.
10771662e931SHoria Geantă  */
10781662e931SHoria Geantă int qman_volatile_dequeue(struct qman_fq *fq, u32 flags, u32 vdqcr);
10791662e931SHoria Geantă 
1080c535e923SClaudiu Manoil /**
1081c535e923SClaudiu Manoil  * qman_enqueue - Enqueue a frame to a frame queue
1082c535e923SClaudiu Manoil  * @fq: the frame queue object to enqueue to
1083c535e923SClaudiu Manoil  * @fd: a descriptor of the frame to be enqueued
1084c535e923SClaudiu Manoil  *
1085c535e923SClaudiu Manoil  * Fills an entry in the EQCR of portal @qm to enqueue the frame described by
1086c535e923SClaudiu Manoil  * @fd. The descriptor details are copied from @fd to the EQCR entry, the 'pid'
1087c535e923SClaudiu Manoil  * field is ignored. The return value is non-zero on error, such as ring full.
1088c535e923SClaudiu Manoil  */
1089c535e923SClaudiu Manoil int qman_enqueue(struct qman_fq *fq, const struct qm_fd *fd);
1090c535e923SClaudiu Manoil 
1091c535e923SClaudiu Manoil /**
1092c535e923SClaudiu Manoil  * qman_alloc_fqid_range - Allocate a contiguous range of FQIDs
1093c535e923SClaudiu Manoil  * @result: is set by the API to the base FQID of the allocated range
1094c535e923SClaudiu Manoil  * @count: the number of FQIDs required
1095c535e923SClaudiu Manoil  *
1096c535e923SClaudiu Manoil  * Returns 0 on success, or a negative error code.
1097c535e923SClaudiu Manoil  */
1098c535e923SClaudiu Manoil int qman_alloc_fqid_range(u32 *result, u32 count);
1099c535e923SClaudiu Manoil #define qman_alloc_fqid(result) qman_alloc_fqid_range(result, 1)
1100c535e923SClaudiu Manoil 
1101c535e923SClaudiu Manoil /**
1102c535e923SClaudiu Manoil  * qman_release_fqid - Release the specified frame queue ID
1103c535e923SClaudiu Manoil  * @fqid: the FQID to be released back to the resource pool
1104c535e923SClaudiu Manoil  *
1105c535e923SClaudiu Manoil  * This function can also be used to seed the allocator with
1106c535e923SClaudiu Manoil  * FQID ranges that it can subsequently allocate from.
1107c535e923SClaudiu Manoil  * Returns 0 on success, or a negative error code.
1108c535e923SClaudiu Manoil  */
1109c535e923SClaudiu Manoil int qman_release_fqid(u32 fqid);
1110c535e923SClaudiu Manoil 
11118496272dSHoria Geantă /**
11128496272dSHoria Geantă  * qman_query_fq_np - Queries non-programmable FQD fields
11138496272dSHoria Geantă  * @fq: the frame queue object to be queried
11148496272dSHoria Geantă  * @np: storage for the queried FQD fields
11158496272dSHoria Geantă  */
11168496272dSHoria Geantă int qman_query_fq_np(struct qman_fq *fq, struct qm_mcr_queryfq_np *np);
11178496272dSHoria Geantă 
1118c535e923SClaudiu Manoil 	/* Pool-channel management */
1119c535e923SClaudiu Manoil /**
1120c535e923SClaudiu Manoil  * qman_alloc_pool_range - Allocate a contiguous range of pool-channel IDs
1121c535e923SClaudiu Manoil  * @result: is set by the API to the base pool-channel ID of the allocated range
1122c535e923SClaudiu Manoil  * @count: the number of pool-channel IDs required
1123c535e923SClaudiu Manoil  *
1124c535e923SClaudiu Manoil  * Returns 0 on success, or a negative error code.
1125c535e923SClaudiu Manoil  */
1126c535e923SClaudiu Manoil int qman_alloc_pool_range(u32 *result, u32 count);
1127c535e923SClaudiu Manoil #define qman_alloc_pool(result) qman_alloc_pool_range(result, 1)
1128c535e923SClaudiu Manoil 
1129c535e923SClaudiu Manoil /**
1130c535e923SClaudiu Manoil  * qman_release_pool - Release the specified pool-channel ID
1131c535e923SClaudiu Manoil  * @id: the pool-chan ID to be released back to the resource pool
1132c535e923SClaudiu Manoil  *
1133c535e923SClaudiu Manoil  * This function can also be used to seed the allocator with
1134c535e923SClaudiu Manoil  * pool-channel ID ranges that it can subsequently allocate from.
1135c535e923SClaudiu Manoil  * Returns 0 on success, or a negative error code.
1136c535e923SClaudiu Manoil  */
1137c535e923SClaudiu Manoil int qman_release_pool(u32 id);
1138c535e923SClaudiu Manoil 
1139c535e923SClaudiu Manoil 	/* CGR management */
1140c535e923SClaudiu Manoil /**
1141c535e923SClaudiu Manoil  * qman_create_cgr - Register a congestion group object
1142c535e923SClaudiu Manoil  * @cgr: the 'cgr' object, with fields filled in
1143c535e923SClaudiu Manoil  * @flags: QMAN_CGR_FLAG_* values
1144c535e923SClaudiu Manoil  * @opts: optional state of CGR settings
1145c535e923SClaudiu Manoil  *
1146c535e923SClaudiu Manoil  * Registers this object to receiving congestion entry/exit callbacks on the
1147c535e923SClaudiu Manoil  * portal affine to the cpu portal on which this API is executed. If opts is
1148c535e923SClaudiu Manoil  * NULL then only the callback (cgr->cb) function is registered. If @flags
1149c535e923SClaudiu Manoil  * contains QMAN_CGR_FLAG_USE_INIT, then an init hw command (which will reset
1150c535e923SClaudiu Manoil  * any unspecified parameters) will be used rather than a modify hw hardware
1151c535e923SClaudiu Manoil  * (which only modifies the specified parameters).
1152c535e923SClaudiu Manoil  */
1153c535e923SClaudiu Manoil int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
1154c535e923SClaudiu Manoil 		    struct qm_mcc_initcgr *opts);
1155c535e923SClaudiu Manoil 
1156c535e923SClaudiu Manoil /**
1157c535e923SClaudiu Manoil  * qman_delete_cgr - Deregisters a congestion group object
1158c535e923SClaudiu Manoil  * @cgr: the 'cgr' object to deregister
1159c535e923SClaudiu Manoil  *
1160c535e923SClaudiu Manoil  * "Unplugs" this CGR object from the portal affine to the cpu on which this API
1161c535e923SClaudiu Manoil  * is executed. This must be excuted on the same affine portal on which it was
1162c535e923SClaudiu Manoil  * created.
1163c535e923SClaudiu Manoil  */
1164c535e923SClaudiu Manoil int qman_delete_cgr(struct qman_cgr *cgr);
1165c535e923SClaudiu Manoil 
1166c535e923SClaudiu Manoil /**
1167c535e923SClaudiu Manoil  * qman_delete_cgr_safe - Deregisters a congestion group object from any CPU
1168c535e923SClaudiu Manoil  * @cgr: the 'cgr' object to deregister
1169c535e923SClaudiu Manoil  *
1170c535e923SClaudiu Manoil  * This will select the proper CPU and run there qman_delete_cgr().
1171c535e923SClaudiu Manoil  */
1172c535e923SClaudiu Manoil void qman_delete_cgr_safe(struct qman_cgr *cgr);
1173c535e923SClaudiu Manoil 
1174c535e923SClaudiu Manoil /**
1175*914f8b22SSean Anderson  * qman_update_cgr_safe - Modifies a congestion group object from any CPU
1176*914f8b22SSean Anderson  * @cgr: the 'cgr' object to modify
1177*914f8b22SSean Anderson  * @opts: state of the CGR settings
1178*914f8b22SSean Anderson  *
1179*914f8b22SSean Anderson  * This will select the proper CPU and modify the CGR settings.
1180*914f8b22SSean Anderson  */
1181*914f8b22SSean Anderson int qman_update_cgr_safe(struct qman_cgr *cgr, struct qm_mcc_initcgr *opts);
1182*914f8b22SSean Anderson 
1183*914f8b22SSean Anderson /**
1184c535e923SClaudiu Manoil  * qman_query_cgr_congested - Queries CGR's congestion status
1185c535e923SClaudiu Manoil  * @cgr: the 'cgr' object to query
1186c535e923SClaudiu Manoil  * @result: returns 'cgr's congestion status, 1 (true) if congested
1187c535e923SClaudiu Manoil  */
1188c535e923SClaudiu Manoil int qman_query_cgr_congested(struct qman_cgr *cgr, bool *result);
1189c535e923SClaudiu Manoil 
1190c535e923SClaudiu Manoil /**
1191c535e923SClaudiu Manoil  * qman_alloc_cgrid_range - Allocate a contiguous range of CGR IDs
1192c535e923SClaudiu Manoil  * @result: is set by the API to the base CGR ID of the allocated range
1193c535e923SClaudiu Manoil  * @count: the number of CGR IDs required
1194c535e923SClaudiu Manoil  *
1195c535e923SClaudiu Manoil  * Returns 0 on success, or a negative error code.
1196c535e923SClaudiu Manoil  */
1197c535e923SClaudiu Manoil int qman_alloc_cgrid_range(u32 *result, u32 count);
1198c535e923SClaudiu Manoil #define qman_alloc_cgrid(result) qman_alloc_cgrid_range(result, 1)
1199c535e923SClaudiu Manoil 
1200c535e923SClaudiu Manoil /**
1201c535e923SClaudiu Manoil  * qman_release_cgrid - Release the specified CGR ID
1202c535e923SClaudiu Manoil  * @id: the CGR ID to be released back to the resource pool
1203c535e923SClaudiu Manoil  *
1204c535e923SClaudiu Manoil  * This function can also be used to seed the allocator with
1205c535e923SClaudiu Manoil  * CGR ID ranges that it can subsequently allocate from.
1206c535e923SClaudiu Manoil  * Returns 0 on success, or a negative error code.
1207c535e923SClaudiu Manoil  */
1208c535e923SClaudiu Manoil int qman_release_cgrid(u32 id);
1209c535e923SClaudiu Manoil 
1210853dc104SLaurentiu Tudor /**
1211853dc104SLaurentiu Tudor  * qman_is_probed - Check if qman is probed
1212853dc104SLaurentiu Tudor  *
1213853dc104SLaurentiu Tudor  * Returns 1 if the qman driver successfully probed, -1 if the qman driver
1214853dc104SLaurentiu Tudor  * failed to probe or 0 if the qman driver did not probed yet.
1215853dc104SLaurentiu Tudor  */
1216853dc104SLaurentiu Tudor int qman_is_probed(void);
1217853dc104SLaurentiu Tudor 
12186d06009cSMadalin Bucur /**
12195d1d046eSLaurentiu Tudor  * qman_portals_probed - Check if all cpu bound qman portals are probed
12205d1d046eSLaurentiu Tudor  *
12215d1d046eSLaurentiu Tudor  * Returns 1 if all the required cpu bound qman portals successfully probed,
12225d1d046eSLaurentiu Tudor  * -1 if probe errors appeared or 0 if the qman portals did not yet finished
12235d1d046eSLaurentiu Tudor  * probing.
12245d1d046eSLaurentiu Tudor  */
12255d1d046eSLaurentiu Tudor int qman_portals_probed(void);
12265d1d046eSLaurentiu Tudor 
12275d1d046eSLaurentiu Tudor /**
12286d06009cSMadalin Bucur  * qman_dqrr_get_ithresh - Get coalesce interrupt threshold
12296d06009cSMadalin Bucur  * @portal: portal to get the value for
12306d06009cSMadalin Bucur  * @ithresh: threshold pointer
12316d06009cSMadalin Bucur  */
12326d06009cSMadalin Bucur void qman_dqrr_get_ithresh(struct qman_portal *portal, u8 *ithresh);
12336d06009cSMadalin Bucur 
12346d06009cSMadalin Bucur /**
12356d06009cSMadalin Bucur  * qman_dqrr_set_ithresh - Set coalesce interrupt threshold
12366d06009cSMadalin Bucur  * @portal: portal to set the new value on
12376d06009cSMadalin Bucur  * @ithresh: new threshold value
12385c664aceSMadalin Bucur  *
12395c664aceSMadalin Bucur  * Returns 0 on success, or a negative error code.
12406d06009cSMadalin Bucur  */
12415c664aceSMadalin Bucur int qman_dqrr_set_ithresh(struct qman_portal *portal, u8 ithresh);
12426d06009cSMadalin Bucur 
12436d06009cSMadalin Bucur /**
12446d06009cSMadalin Bucur  * qman_dqrr_get_iperiod - Get coalesce interrupt period
12456d06009cSMadalin Bucur  * @portal: portal to get the value for
12466d06009cSMadalin Bucur  * @iperiod: period pointer
12476d06009cSMadalin Bucur  */
12486d06009cSMadalin Bucur void qman_portal_get_iperiod(struct qman_portal *portal, u32 *iperiod);
12496d06009cSMadalin Bucur 
12506d06009cSMadalin Bucur /**
12516d06009cSMadalin Bucur  * qman_dqrr_set_iperiod - Set coalesce interrupt period
12526d06009cSMadalin Bucur  * @portal: portal to set the new value on
12536d06009cSMadalin Bucur  * @ithresh: new period value
12545c664aceSMadalin Bucur  *
12555c664aceSMadalin Bucur  * Returns 0 on success, or a negative error code.
12566d06009cSMadalin Bucur  */
12575c664aceSMadalin Bucur int qman_portal_set_iperiod(struct qman_portal *portal, u32 iperiod);
12586d06009cSMadalin Bucur 
1259c535e923SClaudiu Manoil #endif	/* __FSL_QMAN_H */
1260