xref: /freebsd/sys/dev/dpaa/qman.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1*0aeed3e9SJustin Hibbits /*-
2*0aeed3e9SJustin Hibbits  * Copyright (c) 2011-2012 Semihalf.
3*0aeed3e9SJustin Hibbits  * All rights reserved.
4*0aeed3e9SJustin Hibbits  *
5*0aeed3e9SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
6*0aeed3e9SJustin Hibbits  * modification, are permitted provided that the following conditions
7*0aeed3e9SJustin Hibbits  * are met:
8*0aeed3e9SJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
9*0aeed3e9SJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
10*0aeed3e9SJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
11*0aeed3e9SJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
12*0aeed3e9SJustin Hibbits  *    documentation and/or other materials provided with the distribution.
13*0aeed3e9SJustin Hibbits  *
14*0aeed3e9SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*0aeed3e9SJustin Hibbits  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*0aeed3e9SJustin Hibbits  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*0aeed3e9SJustin Hibbits  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*0aeed3e9SJustin Hibbits  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*0aeed3e9SJustin Hibbits  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*0aeed3e9SJustin Hibbits  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*0aeed3e9SJustin Hibbits  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*0aeed3e9SJustin Hibbits  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*0aeed3e9SJustin Hibbits  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*0aeed3e9SJustin Hibbits  * SUCH DAMAGE.
25*0aeed3e9SJustin Hibbits  */
26*0aeed3e9SJustin Hibbits 
27*0aeed3e9SJustin Hibbits #ifndef _QMAN_H
28*0aeed3e9SJustin Hibbits #define _QMAN_H
29*0aeed3e9SJustin Hibbits 
30*0aeed3e9SJustin Hibbits #include <machine/vmparam.h>
31*0aeed3e9SJustin Hibbits 
32*0aeed3e9SJustin Hibbits #include <contrib/ncsw/inc/Peripherals/qm_ext.h>
33*0aeed3e9SJustin Hibbits 
34*0aeed3e9SJustin Hibbits 
35*0aeed3e9SJustin Hibbits /**
36*0aeed3e9SJustin Hibbits  * @group QMan private defines/declarations
37*0aeed3e9SJustin Hibbits  * @{
38*0aeed3e9SJustin Hibbits  */
39*0aeed3e9SJustin Hibbits /**
40*0aeed3e9SJustin Hibbits  * Maximum number of frame queues in all QMans.
41*0aeed3e9SJustin Hibbits  */
42*0aeed3e9SJustin Hibbits #define		QMAN_MAX_FQIDS			16
43*0aeed3e9SJustin Hibbits 
44*0aeed3e9SJustin Hibbits /**
45*0aeed3e9SJustin Hibbits  * Pool channel common to all software portals.
46*0aeed3e9SJustin Hibbits  * @note Value of 0 reflects the e_QM_FQ_CHANNEL_POOL1 from e_QmFQChannel
47*0aeed3e9SJustin Hibbits  *       type used in qman_fqr_create().
48*0aeed3e9SJustin Hibbits  */
49*0aeed3e9SJustin Hibbits #define		QMAN_COMMON_POOL_CHANNEL	0
50*0aeed3e9SJustin Hibbits 
51*0aeed3e9SJustin Hibbits #define		QMAN_FQID_BASE			1
52*0aeed3e9SJustin Hibbits 
53*0aeed3e9SJustin Hibbits #define		QMAN_CCSR_SIZE			0x1000
54*0aeed3e9SJustin Hibbits 
55*0aeed3e9SJustin Hibbits /*
56*0aeed3e9SJustin Hibbits  * Portal defines
57*0aeed3e9SJustin Hibbits  */
58*0aeed3e9SJustin Hibbits #define QMAN_CE_PA(base)	(base)
59*0aeed3e9SJustin Hibbits #define QMAN_CI_PA(base)	((base) + 0x100000)
60*0aeed3e9SJustin Hibbits 
61*0aeed3e9SJustin Hibbits #define QMAN_PORTAL_CE_PA(base, n)	\
62*0aeed3e9SJustin Hibbits     (QMAN_CE_PA(base) + ((n) * QMAN_PORTAL_CE_SIZE))
63*0aeed3e9SJustin Hibbits #define QMAN_PORTAL_CI_PA(base, n)	\
64*0aeed3e9SJustin Hibbits     (QMAN_CI_PA(base) + ((n) * QMAN_PORTAL_CI_SIZE))
65*0aeed3e9SJustin Hibbits 
66*0aeed3e9SJustin Hibbits struct qman_softc {
67*0aeed3e9SJustin Hibbits 	device_t	sc_dev;			/* device handle */
68*0aeed3e9SJustin Hibbits 	int		sc_rrid;		/* register rid */
69*0aeed3e9SJustin Hibbits 	struct resource	*sc_rres;		/* register resource */
70*0aeed3e9SJustin Hibbits 	int		sc_irid;		/* interrupt rid */
71*0aeed3e9SJustin Hibbits 	struct resource	*sc_ires;		/* interrupt resource */
72*0aeed3e9SJustin Hibbits 
73*0aeed3e9SJustin Hibbits 	bool		sc_regs_mapped[MAXCPU];
74*0aeed3e9SJustin Hibbits 
75*0aeed3e9SJustin Hibbits 	t_Handle	sc_qh;			/* QMAN handle */
76*0aeed3e9SJustin Hibbits 	t_Handle	sc_qph[MAXCPU];		/* QMAN portal handles */
77*0aeed3e9SJustin Hibbits 	vm_paddr_t	sc_qp_pa;		/* QMAN portal PA */
78*0aeed3e9SJustin Hibbits 
79*0aeed3e9SJustin Hibbits 	int		sc_fqr_cpu[QMAN_MAX_FQIDS];
80*0aeed3e9SJustin Hibbits };
81*0aeed3e9SJustin Hibbits /** @> */
82*0aeed3e9SJustin Hibbits 
83*0aeed3e9SJustin Hibbits 
84*0aeed3e9SJustin Hibbits /**
85*0aeed3e9SJustin Hibbits  * @group QMan bus interface
86*0aeed3e9SJustin Hibbits  * @{
87*0aeed3e9SJustin Hibbits  */
88*0aeed3e9SJustin Hibbits int qman_attach(device_t dev);
89*0aeed3e9SJustin Hibbits int qman_detach(device_t dev);
90*0aeed3e9SJustin Hibbits int qman_suspend(device_t dev);
91*0aeed3e9SJustin Hibbits int qman_resume(device_t dev);
92*0aeed3e9SJustin Hibbits int qman_shutdown(device_t dev);
93*0aeed3e9SJustin Hibbits /** @> */
94*0aeed3e9SJustin Hibbits 
95*0aeed3e9SJustin Hibbits 
96*0aeed3e9SJustin Hibbits /**
97*0aeed3e9SJustin Hibbits  * @group QMan API
98*0aeed3e9SJustin Hibbits  * @{
99*0aeed3e9SJustin Hibbits  */
100*0aeed3e9SJustin Hibbits 
101*0aeed3e9SJustin Hibbits /**
102*0aeed3e9SJustin Hibbits  * Create Frame Queue Range.
103*0aeed3e9SJustin Hibbits  *
104*0aeed3e9SJustin Hibbits  * @param fqids_num			Number of frame queues in the range.
105*0aeed3e9SJustin Hibbits  *
106*0aeed3e9SJustin Hibbits  * @param channel			Dedicated channel serviced by this
107*0aeed3e9SJustin Hibbits  * 					Frame Queue Range.
108*0aeed3e9SJustin Hibbits  *
109*0aeed3e9SJustin Hibbits  * @param wq				Work Queue Number within the channel.
110*0aeed3e9SJustin Hibbits  *
111*0aeed3e9SJustin Hibbits  * @param force_fqid			If TRUE, fore allocation of specific
112*0aeed3e9SJustin Hibbits  * 					FQID. Notice that there can not be two
113*0aeed3e9SJustin Hibbits  * 					frame queues with the same ID in the
114*0aeed3e9SJustin Hibbits  * 					system.
115*0aeed3e9SJustin Hibbits  *
116*0aeed3e9SJustin Hibbits  * @param fqid_or_align			FQID if @force_fqid == TRUE, alignment
117*0aeed3e9SJustin Hibbits  * 					of FQIDs entries otherwise.
118*0aeed3e9SJustin Hibbits  *
119*0aeed3e9SJustin Hibbits  * @param init_parked			If TRUE, FQ state is initialized to
120*0aeed3e9SJustin Hibbits  * 					"parked" state on creation. Otherwise,
121*0aeed3e9SJustin Hibbits  * 					to "scheduled" state.
122*0aeed3e9SJustin Hibbits  *
123*0aeed3e9SJustin Hibbits  * @param hold_active			If TRUE, the FQ may be held in the
124*0aeed3e9SJustin Hibbits  * 					portal in "held active" state in
125*0aeed3e9SJustin Hibbits  * 					anticipation of more frames being
126*0aeed3e9SJustin Hibbits  * 					dequeued from it after the head frame
127*0aeed3e9SJustin Hibbits  * 					is removed from the FQ and the dequeue
128*0aeed3e9SJustin Hibbits  * 					response is returned. If FALSE the
129*0aeed3e9SJustin Hibbits  * 					"held_active" state of the FQ is not
130*0aeed3e9SJustin Hibbits  * 					allowed. This affects only on queues
131*0aeed3e9SJustin Hibbits  * 					destined to software portals. Refer to
132*0aeed3e9SJustin Hibbits  * 					the 6.3.4.6 of DPAA Reference Manual.
133*0aeed3e9SJustin Hibbits  *
134*0aeed3e9SJustin Hibbits  * @param prefer_in_cache		If TRUE, prefer this FQR to be in QMan
135*0aeed3e9SJustin Hibbits  * 					internal cache memory for all states.
136*0aeed3e9SJustin Hibbits  *
137*0aeed3e9SJustin Hibbits  * @param congst_avoid_ena		If TRUE, enable congestion avoidance
138*0aeed3e9SJustin Hibbits  * 					mechanism.
139*0aeed3e9SJustin Hibbits  *
140*0aeed3e9SJustin Hibbits  * @param congst_group			A handle to the congestion group. Only
141*0aeed3e9SJustin Hibbits  * 					relevant when @congst_avoid_ena == TRUE.
142*0aeed3e9SJustin Hibbits  *
143*0aeed3e9SJustin Hibbits  * @param overhead_accounting_len	For each frame add this number for CG
144*0aeed3e9SJustin Hibbits  * 					calculation (may be negative), if 0 -
145*0aeed3e9SJustin Hibbits  * 					disable feature.
146*0aeed3e9SJustin Hibbits  *
147*0aeed3e9SJustin Hibbits  * @param tail_drop_threshold		If not 0 - enable tail drop on this
148*0aeed3e9SJustin Hibbits  * 					FQR.
149*0aeed3e9SJustin Hibbits  *
150*0aeed3e9SJustin Hibbits  * @return				A handle to newly created FQR object.
151*0aeed3e9SJustin Hibbits  */
152*0aeed3e9SJustin Hibbits t_Handle qman_fqr_create(uint32_t fqids_num, e_QmFQChannel channel, uint8_t wq,
153*0aeed3e9SJustin Hibbits     bool force_fqid, uint32_t fqid_or_align, bool init_parked,
154*0aeed3e9SJustin Hibbits     bool hold_active, bool prefer_in_cache, bool congst_avoid_ena,
155*0aeed3e9SJustin Hibbits     t_Handle congst_group, int8_t overhead_accounting_len,
156*0aeed3e9SJustin Hibbits     uint32_t tail_drop_threshold);
157*0aeed3e9SJustin Hibbits 
158*0aeed3e9SJustin Hibbits /**
159*0aeed3e9SJustin Hibbits  * Free Frame Queue Range.
160*0aeed3e9SJustin Hibbits  *
161*0aeed3e9SJustin Hibbits  * @param fqr	A handle to FQR to be freed.
162*0aeed3e9SJustin Hibbits  * @return	E_OK on success; error code otherwise.
163*0aeed3e9SJustin Hibbits  */
164*0aeed3e9SJustin Hibbits t_Error qman_fqr_free(t_Handle fqr);
165*0aeed3e9SJustin Hibbits 
166*0aeed3e9SJustin Hibbits /**
167*0aeed3e9SJustin Hibbits  * Register the callback function.
168*0aeed3e9SJustin Hibbits  * The callback function will be called when a frame comes from this FQR.
169*0aeed3e9SJustin Hibbits  *
170*0aeed3e9SJustin Hibbits  * @param fqr		A handle to FQR.
171*0aeed3e9SJustin Hibbits  * @param callback	A pointer to the callback function.
172*0aeed3e9SJustin Hibbits  * @param app		A pointer to the user's data.
173*0aeed3e9SJustin Hibbits  * @return		E_OK on success; error code otherwise.
174*0aeed3e9SJustin Hibbits  */
175*0aeed3e9SJustin Hibbits t_Error	qman_fqr_register_cb(t_Handle fqr, t_QmReceivedFrameCallback *callback,
176*0aeed3e9SJustin Hibbits     t_Handle app);
177*0aeed3e9SJustin Hibbits 
178*0aeed3e9SJustin Hibbits /**
179*0aeed3e9SJustin Hibbits  * Enqueue a frame on a given FQR.
180*0aeed3e9SJustin Hibbits  *
181*0aeed3e9SJustin Hibbits  * @param fqr		A handle to FQR.
182*0aeed3e9SJustin Hibbits  * @param fqid_off	FQID offset wihin the FQR.
183*0aeed3e9SJustin Hibbits  * @param frame		A frame to be enqueued to the transmission.
184*0aeed3e9SJustin Hibbits  * @return		E_OK on success; error code otherwise.
185*0aeed3e9SJustin Hibbits  */
186*0aeed3e9SJustin Hibbits t_Error qman_fqr_enqueue(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame);
187*0aeed3e9SJustin Hibbits 
188*0aeed3e9SJustin Hibbits /**
189*0aeed3e9SJustin Hibbits  * Get one of the FQR counter's value.
190*0aeed3e9SJustin Hibbits  *
191*0aeed3e9SJustin Hibbits  * @param fqr		A handle to FQR.
192*0aeed3e9SJustin Hibbits  * @param fqid_off	FQID offset within the FQR.
193*0aeed3e9SJustin Hibbits  * @param counter	The requested counter.
194*0aeed3e9SJustin Hibbits  * @return		Counter's current value.
195*0aeed3e9SJustin Hibbits  */
196*0aeed3e9SJustin Hibbits uint32_t qman_fqr_get_counter(t_Handle fqr, uint32_t fqid_off,
197*0aeed3e9SJustin Hibbits     e_QmFqrCounters counter);
198*0aeed3e9SJustin Hibbits 
199*0aeed3e9SJustin Hibbits /**
200*0aeed3e9SJustin Hibbits  * Pull frame from FQR.
201*0aeed3e9SJustin Hibbits  *
202*0aeed3e9SJustin Hibbits  * @param fqr		A handle to FQR.
203*0aeed3e9SJustin Hibbits  * @param fqid_off	FQID offset within the FQR.
204*0aeed3e9SJustin Hibbits  * @param frame		The received frame.
205*0aeed3e9SJustin Hibbits  * @return		E_OK on success; error code otherwise.
206*0aeed3e9SJustin Hibbits  */
207*0aeed3e9SJustin Hibbits t_Error qman_fqr_pull_frame(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame);
208*0aeed3e9SJustin Hibbits 
209*0aeed3e9SJustin Hibbits /**
210*0aeed3e9SJustin Hibbits  * Get base FQID of the FQR.
211*0aeed3e9SJustin Hibbits  * @param fqr	A handle to FQR.
212*0aeed3e9SJustin Hibbits  * @return	Base FQID of the FQR.
213*0aeed3e9SJustin Hibbits  */
214*0aeed3e9SJustin Hibbits uint32_t qman_fqr_get_base_fqid(t_Handle fqr);
215*0aeed3e9SJustin Hibbits 
216*0aeed3e9SJustin Hibbits /**
217*0aeed3e9SJustin Hibbits  * Poll frames from QMan.
218*0aeed3e9SJustin Hibbits  * This polls frames from the current software portal.
219*0aeed3e9SJustin Hibbits  *
220*0aeed3e9SJustin Hibbits  * @param source	Type of frames to be polled.
221*0aeed3e9SJustin Hibbits  * @return		E_OK on success; error otherwise.
222*0aeed3e9SJustin Hibbits  */
223*0aeed3e9SJustin Hibbits t_Error qman_poll(e_QmPortalPollSource source);
224*0aeed3e9SJustin Hibbits 
225*0aeed3e9SJustin Hibbits /**
226*0aeed3e9SJustin Hibbits  * General received frame callback.
227*0aeed3e9SJustin Hibbits  * This is called, when user did not register his own callback for a given
228*0aeed3e9SJustin Hibbits  * frame queue range (fqr).
229*0aeed3e9SJustin Hibbits  */
230*0aeed3e9SJustin Hibbits e_RxStoreResponse qman_received_frame_callback(t_Handle app, t_Handle qm_fqr,
231*0aeed3e9SJustin Hibbits     t_Handle qm_portal, uint32_t fqid_offset, t_DpaaFD *frame);
232*0aeed3e9SJustin Hibbits 
233*0aeed3e9SJustin Hibbits /**
234*0aeed3e9SJustin Hibbits  * General rejected frame callback.
235*0aeed3e9SJustin Hibbits  * This is called, when user did not register his own callback for a given
236*0aeed3e9SJustin Hibbits  * frame queue range (fqr).
237*0aeed3e9SJustin Hibbits  */
238*0aeed3e9SJustin Hibbits e_RxStoreResponse qman_rejected_frame_callback(t_Handle app, t_Handle qm_fqr,
239*0aeed3e9SJustin Hibbits     t_Handle qm_portal, uint32_t fqid_offset, t_DpaaFD *frame,
240*0aeed3e9SJustin Hibbits     t_QmRejectedFrameInfo *qm_rejected_frame_info);
241*0aeed3e9SJustin Hibbits 
242*0aeed3e9SJustin Hibbits /** @} */
243*0aeed3e9SJustin Hibbits 
244*0aeed3e9SJustin Hibbits #endif /* QMAN_H */
245