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