xref: /freebsd/sys/dev/dpaa/qman.h (revision fd8d34ce272ba40f3e0218198ba542a29c390a4a)
1 /*-
2  * Copyright (c) 2011-2012 Semihalf.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef _QMAN_H
28 #define _QMAN_H
29 
30 #include <sys/vmem.h>
31 #include <machine/vmparam.h>
32 
33 struct qman_fq;
34 struct qman_fq;
35 struct dpaa_fd;
36 struct qman_portal;
37 
38 /**
39  * @group QMan private defines/declarations
40  * @{
41  */
42 /**
43  * Maximum number of frame queues in all QMans.
44  */
45 #define		QMAN_MAX_FQIDS			16
46 
47 /**
48  * Pool channel common to all software portals.
49  * @note Value of 0 reflects the e_QM_FQ_CHANNEL_POOL1 from e_QmFQChannel
50  *       type used in qman_fq_create().
51  */
52 #define		QMAN_COMMON_POOL_CHANNEL	0
53 
54 #define		QMAN_FQID_BASE			1
55 
56 /* Counters */
57 #define	QMAN_COUNTER_FRAME	0
58 #define	QMAN_COUNTER_BYTES	1
59 
60 /*
61  * Portal defines
62  */
63 #define QMAN_CE_PA(base)	(base)
64 #define QMAN_CI_PA(base)	((base) + 0x100000)
65 
66 #define QMAN_PORTAL_CE_PA(base, n)	\
67     (QMAN_CE_PA(base) + ((n) * QMAN_PORTAL_CE_SIZE))
68 #define QMAN_PORTAL_CI_PA(base, n)	\
69     (QMAN_CI_PA(base) + ((n) * QMAN_PORTAL_CI_SIZE))
70 
71 struct qman_softc {
72 	device_t	sc_dev;			/* device handle */
73 	int		sc_rrid;		/* register rid */
74 	struct resource	*sc_rres;		/* register resource */
75 	int		sc_irid;		/* interrupt rid */
76 	struct resource	*sc_ires;		/* interrupt resource */
77 	vmem_t		*sc_fqalloc;
78 	vmem_t		*sc_qpalloc;
79 	vmem_t		*sc_cgalloc;
80 	void		*sc_intr_cookie;
81 	int		sc_qman_base_channel;
82 	int		sc_qman_major;
83 
84 	vm_paddr_t	sc_qp_pa;		/* QMAN portal PA */
85 
86 	int		sc_fq_cpu[QMAN_MAX_FQIDS];
87 };
88 
89 struct qman_fd {
90 	uint64_t dd:2;
91 	uint64_t liodn_off:6;
92 	uint64_t bpid:8;
93 	uint64_t eliodn_off:4;
94 	uint64_t _rsvd0:4;
95 	uint64_t addr:40;
96 	union {
97 		struct {
98 			uint32_t format:3;
99 			uint32_t offset:9;
100 			uint32_t length:20;
101 		};
102 		struct {
103 			uint32_t format2:3;
104 			uint32_t wlength:29;
105 		};
106 	};
107 	uint32_t cmd_stat;
108 };
109 
110 _Static_assert(sizeof(struct qman_fd) == 16, "qman_fd size mismatch");
111 
112 struct qman_dqrr_entry {
113 	uint8_t verb;
114 	uint8_t stat;
115 	uint16_t seqnum;
116 	uint8_t tok;
117 	uint8_t _rsvd0[3];
118 	uint32_t fqid;
119 	uint32_t ctxb;
120 	struct qman_fd fd;
121 	uint8_t _rsvd1[32];
122 };
123 
124 /* Bits for qman_dqrr_entry fields */
125 #define	QMAN_DQRR_STAT_FQ_EMPTY		0x80
126 #define	QMAN_DQRR_STAT_FQ_HELD_ACTIVE	0x40
127 #define	QMAN_DQRR_STAT_FQ_FORCED	0x20
128 #define	QMAN_DQRR_STAT_HAS_FRAME	0x10
129 #define	QMAN_DQRR_STAT_VDQCR		0x02
130 #define	QMAN_DQRR_STAT_EXPIRED		0x01
131 
132 struct qman_mr_entry {
133 	union {
134 		struct {
135 			uint8_t verb;
136 			uint8_t data[63];
137 		};
138 		struct {
139 			uint8_t verb;
140 			uint8_t dca;
141 			uint16_t seqnum;
142 			uint32_t rc:8;
143 			uint32_t orp:24;
144 			uint32_t fqid;
145 			uint32_t tag;
146 			struct qman_fd fd;
147 			uint8_t _rsvd[32];
148 		} ern;
149 		struct {
150 			uint8_t verb;
151 			uint8_t fqs;
152 			uint8_t _rsvd0[6];
153 			uint32_t fqid;
154 			uint32_t ctxb;
155 			uint8_t _rsvd1[48];
156 		} fqscn;
157 	};
158 };
159 
160 _Static_assert(sizeof(struct qman_mr_entry) == 64, "bad sizeof qman_mr");
161 /** @> */
162 
163 typedef int (*qman_cb_dqrr)(device_t, struct qman_fq *,
164     struct qman_fd *, void *);
165 typedef void (*qman_cb_mr)(device_t, struct qman_fq *,
166     struct qman_mr_entry *);
167 
168 struct qman_cb {
169 	qman_cb_dqrr dqrr;
170 	qman_cb_mr ern;
171 	qman_cb_mr fqscn;
172 	void *ctx;
173 };
174 /**
175  * @group QMan bus interface
176  * @{
177  */
178 int qman_attach(device_t dev);
179 int qman_detach(device_t dev);
180 int qman_suspend(device_t dev);
181 int qman_resume(device_t dev);
182 int qman_shutdown(device_t dev);
183 /** @> */
184 int qman_create_affine_portal(device_t, vm_offset_t, vm_offset_t, int);
185 void qman_set_sdest(uint16_t, int);
186 
187 
188 /**
189  * @group QMan API
190  * @{
191  */
192 
193 /**
194  * Create Frame Queue Range.
195  *
196  * @param fqids_num			Number of frame queues in the range.
197  *
198  * @param channel			Dedicated channel serviced by this
199  * 					Frame Queue Range.
200  *
201  * @param wq				Work Queue Number within the channel.
202  *
203  * @param force_fqid			If TRUE, fore allocation of specific
204  * 					FQID. Notice that there can not be two
205  * 					frame queues with the same ID in the
206  * 					system.
207  *
208  * @param fqid_or_align			FQID if @force_fqid == TRUE, alignment
209  * 					of FQIDs entries otherwise.
210  *
211  * @param init_parked			If TRUE, FQ state is initialized to
212  * 					"parked" state on creation. Otherwise,
213  * 					to "scheduled" state.
214  *
215  * @param hold_active			If TRUE, the FQ may be held in the
216  * 					portal in "held active" state in
217  * 					anticipation of more frames being
218  * 					dequeued from it after the head frame
219  * 					is removed from the FQ and the dequeue
220  * 					response is returned. If FALSE the
221  * 					"held_active" state of the FQ is not
222  * 					allowed. This affects only on queues
223  * 					destined to software portals. Refer to
224  * 					the 6.3.4.6 of DPAA Reference Manual.
225  *
226  * @param prefer_in_cache		If TRUE, prefer this FQR to be in QMan
227  * 					internal cache memory for all states.
228  *
229  * @param congst_avoid_ena		If TRUE, enable congestion avoidance
230  * 					mechanism.
231  *
232  * @param congst_group			A handle to the congestion group. Only
233  * 					relevant when @congst_avoid_ena == TRUE.
234  *
235  * @param overhead_accounting_len	For each frame add this number for CG
236  * 					calculation (may be negative), if 0 -
237  * 					disable feature.
238  *
239  * @param tail_drop_threshold		If not 0 - enable tail drop on this
240  * 					FQR.
241  *
242  * @return				A handle to newly created FQR object.
243  */
244 struct qman_fq *qman_fq_create(uint32_t fqids_num, int channel,
245     uint8_t wq, bool force_fqid, uint32_t fqid_or_align, bool init_parked,
246     bool hold_active, bool prefer_in_cache, bool congst_avoid_ena,
247     void *congst_group, int8_t overhead_accounting_len,
248     uint32_t tail_drop_threshold);
249 
250 /**
251  * Free Frame Queue Range.
252  *
253  * @param fq	A handle to FQR to be freed.
254  * @return	E_OK on success; error code otherwise.
255  */
256 int qman_fq_free(struct qman_fq *fq);
257 
258 /**
259  * Register the callback function.
260  * The callback function will be called when a frame comes from this FQR.
261  *
262  * @param fq		A handle to FQR.
263  * @param callback	A pointer to the callback function.
264  * @param app		A pointer to the user's data.
265  * @return		E_OK on success; error code otherwise.
266  */
267 int	qman_fq_register_cb(struct qman_fq *fq, qman_cb_dqrr callback,
268     void *ctx);
269 
270 /**
271  * Enqueue a frame on a given FQ.
272  *
273  * @param fq		A handle to FQ.
274  * @param frame		A frame to be enqueued to the transmission.
275  * @return		E_OK on success; error code otherwise.
276  */
277 int qman_fq_enqueue(struct qman_fq *fq, struct dpaa_fd *frame);
278 
279 /**
280  * Get one of the FQ counter's value.
281  *
282  * @param fq		A handle to FQ.
283  * @param counter	The requested counter.
284  * @return		Counter's current value.
285  */
286 uint32_t qman_fq_get_counter(struct qman_fq *fq, int counter);
287 
288 /**
289  * Pull frame from FQ.
290  *
291  * @param fq		A handle to FQ.
292  * @param frame		The received frame.
293  * @return		E_OK on success; error code otherwise.
294  */
295 int qman_fq_pull_frame(struct qman_fq *fq, struct dpaa_fd *frame);
296 
297 /**
298  * Get FQID of the FQ.
299  * @param fq	A handle to FQ.
300  * @return	FQID of the FQ.
301  */
302 uint32_t qman_fq_get_fqid(struct qman_fq *fq);
303 
304 /*
305  * Allocate a QMan channel to be used with an FQ.
306  * @return	Channel ID
307  */
308 int qman_alloc_channel(void);
309 
310 /*
311  * Free a channel
312  * @param chan	Channel ID returned from qman_alloc_channel().
313  */
314 void qman_free_channel(int);
315 
316 /**
317  * Poll frames from QMan.
318  * This polls frames from the current software portal.
319  *
320  * @param source	Type of frames to be polled.
321  * @return		E_OK on success; error otherwise.
322  */
323 int qman_poll(int source);
324 
325 /**
326  * General received frame callback.
327  * This is called, when user did not register his own callback for a given
328  * frame queue range (fq).
329  */
330 int qman_received_frame_callback(void *ctx, struct qman_fq *fq,
331     void *qm_portal, uint32_t fqid_offset, struct dpaa_fd *frame);
332 
333 /**
334  * General rejected frame callback.
335  * This is called, when user did not register his own callback for a given
336  * frame queue range (fq).
337  */
338 int qman_rejected_frame_callback(void *ctx, struct qman_fq *fq,
339     void *qm_portal, uint32_t fqid_offset, struct dpaa_fd *frame,
340     void *qm_rejected_frame_info);
341 
342 /** @} */
343 
344 #endif /* QMAN_H */
345