2 * Copyright (c) 2011-2012 Semihalf.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
32 #include <machine/vmparam.h>
34 #include <contrib/ncsw/inc/Peripherals/qm_ext.h>
38 * @group QMan private defines/declarations
42 * Maximum number of frame queues in all QMans.
44 #define QMAN_MAX_FQIDS 16
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().
51 #define QMAN_COMMON_POOL_CHANNEL 0
53 #define QMAN_FQID_BASE 1
55 #define QMAN_CCSR_SIZE 0x1000
60 #define QMAN_CE_PA(base) (base)
61 #define QMAN_CI_PA(base) ((base) + 0x100000)
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))
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 */
75 bool sc_regs_mapped[MAXCPU];
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 */
81 int sc_fqr_cpu[QMAN_MAX_FQIDS];
87 * @group QMan bus interface
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);
104 * Create Frame Queue Range.
106 * @param fqids_num Number of frame queues in the range.
108 * @param channel Dedicated channel serviced by this
111 * @param wq Work Queue Number within the channel.
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
118 * @param fqid_or_align FQID if @force_fqid == TRUE, alignment
119 * of FQIDs entries otherwise.
121 * @param init_parked If TRUE, FQ state is initialized to
122 * "parked" state on creation. Otherwise,
123 * to "scheduled" state.
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.
136 * @param prefer_in_cache If TRUE, prefer this FQR to be in QMan
137 * internal cache memory for all states.
139 * @param congst_avoid_ena If TRUE, enable congestion avoidance
142 * @param congst_group A handle to the congestion group. Only
143 * relevant when @congst_avoid_ena == TRUE.
145 * @param overhead_accounting_len For each frame add this number for CG
146 * calculation (may be negative), if 0 -
149 * @param tail_drop_threshold If not 0 - enable tail drop on this
152 * @return A handle to newly created FQR object.
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);
161 * Free Frame Queue Range.
163 * @param fqr A handle to FQR to be freed.
164 * @return E_OK on success; error code otherwise.
166 t_Error qman_fqr_free(t_Handle fqr);
169 * Register the callback function.
170 * The callback function will be called when a frame comes from this FQR.
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.
177 t_Error qman_fqr_register_cb(t_Handle fqr, t_QmReceivedFrameCallback *callback,
181 * Enqueue a frame on a given FQR.
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.
188 t_Error qman_fqr_enqueue(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame);
191 * Get one of the FQR counter's value.
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.
198 uint32_t qman_fqr_get_counter(t_Handle fqr, uint32_t fqid_off,
199 e_QmFqrCounters counter);
202 * Pull frame from FQR.
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.
209 t_Error qman_fqr_pull_frame(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame);
212 * Get base FQID of the FQR.
213 * @param fqr A handle to FQR.
214 * @return Base FQID of the FQR.
216 uint32_t qman_fqr_get_base_fqid(t_Handle fqr);
219 * Poll frames from QMan.
220 * This polls frames from the current software portal.
222 * @param source Type of frames to be polled.
223 * @return E_OK on success; error otherwise.
225 t_Error qman_poll(e_QmPortalPollSource source);
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).
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);
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).
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);