xref: /freebsd/sys/dev/dpaa/qman.h (revision ccf5e68e5bb2cdabb4686d81c2d63c2f6304d0a4)
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  * $FreeBSD$
27  */
28 
29 #ifndef _QMAN_H
30 #define _QMAN_H
31 
32 #include <machine/vmparam.h>
33 
34 #include <contrib/ncsw/inc/Peripherals/qm_ext.h>
35 
36 
37 /**
38  * @group QMan private defines/declarations
39  * @{
40  */
41 /**
42  * Maximum number of frame queues in all QMans.
43  */
44 #define		QMAN_MAX_FQIDS			16
45 
46 /**
47  * Pool channel common to all software portals.
48  * @note Value of 0 reflects the e_QM_FQ_CHANNEL_POOL1 from e_QmFQChannel
49  *       type used in qman_fqr_create().
50  */
51 #define		QMAN_COMMON_POOL_CHANNEL	0
52 
53 #define		QMAN_FQID_BASE			1
54 
55 #define		QMAN_CCSR_SIZE			0x1000
56 
57 /*
58  * Portal defines
59  */
60 #define QMAN_CE_PA(base)	(base)
61 #define QMAN_CI_PA(base)	((base) + 0x100000)
62 
63 #define QMAN_PORTAL_CE_PA(base, n)	\
64     (QMAN_CE_PA(base) + ((n) * QMAN_PORTAL_CE_SIZE))
65 #define QMAN_PORTAL_CI_PA(base, n)	\
66     (QMAN_CI_PA(base) + ((n) * QMAN_PORTAL_CI_SIZE))
67 
68 struct qman_softc {
69 	device_t	sc_dev;			/* device handle */
70 	int		sc_rrid;		/* register rid */
71 	struct resource	*sc_rres;		/* register resource */
72 	int		sc_irid;		/* interrupt rid */
73 	struct resource	*sc_ires;		/* interrupt resource */
74 
75 	bool		sc_regs_mapped[MAXCPU];
76 
77 	t_Handle	sc_qh;			/* QMAN handle */
78 	t_Handle	sc_qph[MAXCPU];		/* QMAN portal handles */
79 	vm_paddr_t	sc_qp_pa;		/* QMAN portal PA */
80 
81 	int		sc_fqr_cpu[QMAN_MAX_FQIDS];
82 };
83 /** @> */
84 
85 
86 /**
87  * @group QMan bus interface
88  * @{
89  */
90 int qman_attach(device_t dev);
91 int qman_detach(device_t dev);
92 int qman_suspend(device_t dev);
93 int qman_resume(device_t dev);
94 int qman_shutdown(device_t dev);
95 /** @> */
96 
97 
98 /**
99  * @group QMan API
100  * @{
101  */
102 
103 /**
104  * Create Frame Queue Range.
105  *
106  * @param fqids_num			Number of frame queues in the range.
107  *
108  * @param channel			Dedicated channel serviced by this
109  * 					Frame Queue Range.
110  *
111  * @param wq				Work Queue Number within the channel.
112  *
113  * @param force_fqid			If TRUE, fore allocation of specific
114  * 					FQID. Notice that there can not be two
115  * 					frame queues with the same ID in the
116  * 					system.
117  *
118  * @param fqid_or_align			FQID if @force_fqid == TRUE, alignment
119  * 					of FQIDs entries otherwise.
120  *
121  * @param init_parked			If TRUE, FQ state is initialized to
122  * 					"parked" state on creation. Otherwise,
123  * 					to "scheduled" state.
124  *
125  * @param hold_active			If TRUE, the FQ may be held in the
126  * 					portal in "held active" state in
127  * 					anticipation of more frames being
128  * 					dequeued from it after the head frame
129  * 					is removed from the FQ and the dequeue
130  * 					response is returned. If FALSE the
131  * 					"held_active" state of the FQ is not
132  * 					allowed. This affects only on queues
133  * 					destined to software portals. Refer to
134  * 					the 6.3.4.6 of DPAA Reference Manual.
135  *
136  * @param prefer_in_cache		If TRUE, prefer this FQR to be in QMan
137  * 					internal cache memory for all states.
138  *
139  * @param congst_avoid_ena		If TRUE, enable congestion avoidance
140  * 					mechanism.
141  *
142  * @param congst_group			A handle to the congestion group. Only
143  * 					relevant when @congst_avoid_ena == TRUE.
144  *
145  * @param overhead_accounting_len	For each frame add this number for CG
146  * 					calculation (may be negative), if 0 -
147  * 					disable feature.
148  *
149  * @param tail_drop_threshold		If not 0 - enable tail drop on this
150  * 					FQR.
151  *
152  * @return				A handle to newly created FQR object.
153  */
154 t_Handle qman_fqr_create(uint32_t fqids_num, e_QmFQChannel channel, uint8_t wq,
155     bool force_fqid, uint32_t fqid_or_align, bool init_parked,
156     bool hold_active, bool prefer_in_cache, bool congst_avoid_ena,
157     t_Handle congst_group, int8_t overhead_accounting_len,
158     uint32_t tail_drop_threshold);
159 
160 /**
161  * Free Frame Queue Range.
162  *
163  * @param fqr	A handle to FQR to be freed.
164  * @return	E_OK on success; error code otherwise.
165  */
166 t_Error qman_fqr_free(t_Handle fqr);
167 
168 /**
169  * Register the callback function.
170  * The callback function will be called when a frame comes from this FQR.
171  *
172  * @param fqr		A handle to FQR.
173  * @param callback	A pointer to the callback function.
174  * @param app		A pointer to the user's data.
175  * @return		E_OK on success; error code otherwise.
176  */
177 t_Error	qman_fqr_register_cb(t_Handle fqr, t_QmReceivedFrameCallback *callback,
178     t_Handle app);
179 
180 /**
181  * Enqueue a frame on a given FQR.
182  *
183  * @param fqr		A handle to FQR.
184  * @param fqid_off	FQID offset wihin the FQR.
185  * @param frame		A frame to be enqueued to the transmission.
186  * @return		E_OK on success; error code otherwise.
187  */
188 t_Error qman_fqr_enqueue(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame);
189 
190 /**
191  * Get one of the FQR counter's value.
192  *
193  * @param fqr		A handle to FQR.
194  * @param fqid_off	FQID offset within the FQR.
195  * @param counter	The requested counter.
196  * @return		Counter's current value.
197  */
198 uint32_t qman_fqr_get_counter(t_Handle fqr, uint32_t fqid_off,
199     e_QmFqrCounters counter);
200 
201 /**
202  * Pull frame from FQR.
203  *
204  * @param fqr		A handle to FQR.
205  * @param fqid_off	FQID offset within the FQR.
206  * @param frame		The received frame.
207  * @return		E_OK on success; error code otherwise.
208  */
209 t_Error qman_fqr_pull_frame(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame);
210 
211 /**
212  * Get base FQID of the FQR.
213  * @param fqr	A handle to FQR.
214  * @return	Base FQID of the FQR.
215  */
216 uint32_t qman_fqr_get_base_fqid(t_Handle fqr);
217 
218 /**
219  * Poll frames from QMan.
220  * This polls frames from the current software portal.
221  *
222  * @param source	Type of frames to be polled.
223  * @return		E_OK on success; error otherwise.
224  */
225 t_Error qman_poll(e_QmPortalPollSource source);
226 
227 /**
228  * General received frame callback.
229  * This is called, when user did not register his own callback for a given
230  * frame queue range (fqr).
231  */
232 e_RxStoreResponse qman_received_frame_callback(t_Handle app, t_Handle qm_fqr,
233     t_Handle qm_portal, uint32_t fqid_offset, t_DpaaFD *frame);
234 
235 /**
236  * General rejected frame callback.
237  * This is called, when user did not register his own callback for a given
238  * frame queue range (fqr).
239  */
240 e_RxStoreResponse qman_rejected_frame_callback(t_Handle app, t_Handle qm_fqr,
241     t_Handle qm_portal, uint32_t fqid_offset, t_DpaaFD *frame,
242     t_QmRejectedFrameInfo *qm_rejected_frame_info);
243 
244 /** @} */
245 
246 #endif /* QMAN_H */
247