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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/mutex.h>
40 #include <sys/sched.h>
43 #include <machine/bus.h>
44 #include <machine/resource.h>
45 #include <machine/tlb.h>
50 extern struct dpaa_portals_softc *qp_sc;
51 static struct qman_softc *qman_sc;
53 extern t_Handle qman_portal_setup(struct qman_softc *qsc);
56 qman_exception(t_Handle app, e_QmExceptions exception)
58 struct qman_softc *sc;
64 case e_QM_EX_CORENET_INITIATOR_DATA:
65 message = "Initiator Data Error";
67 case e_QM_EX_CORENET_TARGET_DATA:
68 message = "CoreNet Target Data Error";
70 case e_QM_EX_CORENET_INVALID_TARGET_TRANSACTION:
71 message = "Invalid Target Transaction";
73 case e_QM_EX_PFDR_THRESHOLD:
74 message = "PFDR Low Watermark Interrupt";
76 case e_QM_EX_PFDR_ENQUEUE_BLOCKED:
77 message = "PFDR Enqueues Blocked Interrupt";
79 case e_QM_EX_SINGLE_ECC:
80 message = "Single Bit ECC Error Interrupt";
82 case e_QM_EX_MULTI_ECC:
83 message = "Multi Bit ECC Error Interrupt";
85 case e_QM_EX_INVALID_COMMAND:
86 message = "Invalid Command Verb Interrupt";
88 case e_QM_EX_DEQUEUE_DCP:
89 message = "Invalid Dequeue Direct Connect Portal Interrupt";
91 case e_QM_EX_DEQUEUE_FQ:
92 message = "Invalid Dequeue FQ Interrupt";
94 case e_QM_EX_DEQUEUE_SOURCE:
95 message = "Invalid Dequeue Source Interrupt";
97 case e_QM_EX_DEQUEUE_QUEUE:
98 message = "Invalid Dequeue Queue Interrupt";
100 case e_QM_EX_ENQUEUE_OVERFLOW:
101 message = "Invalid Enqueue Overflow Interrupt";
103 case e_QM_EX_ENQUEUE_STATE:
104 message = "Invalid Enqueue State Interrupt";
106 case e_QM_EX_ENQUEUE_CHANNEL:
107 message = "Invalid Enqueue Channel Interrupt";
109 case e_QM_EX_ENQUEUE_QUEUE:
110 message = "Invalid Enqueue Queue Interrupt";
112 case e_QM_EX_CG_STATE_CHANGE:
113 message = "CG change state notification";
116 message = "Unknown error";
119 device_printf(sc->sc_dev, "QMan Exception: %s.\n", message);
123 * General received frame callback.
124 * This is called, when user did not register his own callback for a given
125 * frame queue range (fqr).
128 qman_received_frame_callback(t_Handle app, t_Handle qm_fqr, t_Handle qm_portal,
129 uint32_t fqid_offset, t_DpaaFD *frame)
131 struct qman_softc *sc;
135 device_printf(sc->sc_dev, "dummy callback for received frame.\n");
136 return (e_RX_STORE_RESPONSE_CONTINUE);
140 * General rejected frame callback.
141 * This is called, when user did not register his own callback for a given
142 * frame queue range (fqr).
145 qman_rejected_frame_callback(t_Handle app, t_Handle qm_fqr, t_Handle qm_portal,
146 uint32_t fqid_offset, t_DpaaFD *frame,
147 t_QmRejectedFrameInfo *qm_rejected_frame_info)
149 struct qman_softc *sc;
153 device_printf(sc->sc_dev, "dummy callback for rejected frame.\n");
154 return (e_RX_STORE_RESPONSE_CONTINUE);
158 qman_attach(device_t dev)
160 struct qman_softc *sc;
163 t_QmRevisionInfo rev;
165 sc = device_get_softc(dev);
169 if (XX_MallocSmartInit() != E_OK) {
170 device_printf(dev, "could not initialize smart allocator.\n");
176 /* Allocate resources */
178 sc->sc_rres = bus_alloc_resource(dev, SYS_RES_MEMORY,
179 &sc->sc_rrid, 0, ~0, QMAN_CCSR_SIZE, RF_ACTIVE);
180 if (sc->sc_rres == NULL) {
181 device_printf(dev, "could not allocate memory.\n");
186 sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
187 &sc->sc_irid, RF_ACTIVE | RF_SHAREABLE);
188 if (sc->sc_ires == NULL) {
189 device_printf(dev, "could not allocate error interrupt.\n");
196 dpaa_portal_map_registers(qp_sc);
198 /* Initialize QMan */
199 qp.guestId = NCSW_MASTER_ID;
200 qp.baseAddress = rman_get_bushandle(sc->sc_rres);
201 qp.swPortalsBaseAddress = rman_get_bushandle(qp_sc->sc_rres[0]);
203 qp.totalNumOfFqids = QMAN_MAX_FQIDS;
204 qp.fqdMemPartitionId = NCSW_MASTER_ID;
205 qp.pfdrMemPartitionId = NCSW_MASTER_ID;
206 qp.f_Exception = qman_exception;
208 qp.errIrq = (uintptr_t)sc->sc_ires;
209 qp.partFqidBase = QMAN_FQID_BASE;
210 qp.partNumOfFqids = QMAN_MAX_FQIDS;
214 sc->sc_qh = QM_Config(&qp);
215 if (sc->sc_qh == NULL) {
216 device_printf(dev, "could not be configured\n");
220 error = QM_Init(sc->sc_qh);
222 device_printf(dev, "could not be initialized\n");
226 error = QM_GetRevision(sc->sc_qh, &rev);
228 device_printf(dev, "could not get QMan revision\n");
232 device_printf(dev, "Hardware version: %d.%d.\n",
233 rev.majorRev, rev.minorRev);
237 qman_portal_setup(sc);
248 qman_detach(device_t dev)
250 struct qman_softc *sc;
252 sc = device_get_softc(dev);
257 if (sc->sc_ires != NULL)
258 XX_DeallocIntr((uintptr_t)sc->sc_ires);
260 if (sc->sc_ires != NULL)
261 bus_release_resource(dev, SYS_RES_IRQ,
262 sc->sc_irid, sc->sc_ires);
264 if (sc->sc_rres != NULL)
265 bus_release_resource(dev, SYS_RES_MEMORY,
266 sc->sc_rrid, sc->sc_rres);
272 qman_suspend(device_t dev)
279 qman_resume(device_t dev)
286 qman_shutdown(device_t dev)
294 * @group QMan API functions implementation.
299 qman_fqr_create(uint32_t fqids_num, e_QmFQChannel channel, uint8_t wq,
300 bool force_fqid, uint32_t fqid_or_align, bool init_parked,
301 bool hold_active, bool prefer_in_cache, bool congst_avoid_ena,
302 t_Handle congst_group, int8_t overhead_accounting_len,
303 uint32_t tail_drop_threshold)
305 struct qman_softc *sc;
308 t_Handle fqrh, portal;
313 cpu = PCPU_GET(cpuid);
315 /* Ensure we have got QMan port initialized */
316 portal = qman_portal_setup(sc);
317 if (portal == NULL) {
318 device_printf(sc->sc_dev, "could not setup QMan portal\n");
322 fqr.h_Qm = sc->sc_qh;
323 fqr.h_QmPortal = portal;
324 fqr.initParked = init_parked;
325 fqr.holdActive = hold_active;
326 fqr.preferInCache = prefer_in_cache;
328 /* We do not support stashing */
329 fqr.useContextAForStash = FALSE;
333 fqr.channel = channel;
335 fqr.shadowMode = FALSE;
336 fqr.numOfFqids = fqids_num;
339 fqr.useForce = force_fqid;
341 fqr.qs.frcQ.fqid = fqid_or_align;
343 fqr.qs.nonFrcQs.align = fqid_or_align;
346 /* Congestion Avoidance */
347 fqr.congestionAvoidanceEnable = congst_avoid_ena;
348 if (congst_avoid_ena) {
349 fqr.congestionAvoidanceParams.h_QmCg = congst_group;
350 fqr.congestionAvoidanceParams.overheadAccountingLength =
351 overhead_accounting_len;
352 fqr.congestionAvoidanceParams.fqTailDropThreshold =
355 fqr.congestionAvoidanceParams.h_QmCg = 0;
356 fqr.congestionAvoidanceParams.overheadAccountingLength = 0;
357 fqr.congestionAvoidanceParams.fqTailDropThreshold = 0;
360 fqrh = QM_FQR_Create(&fqr);
362 device_printf(sc->sc_dev, "could not create Frame Queue Range"
367 sc->sc_fqr_cpu[QM_FQR_GetFqid(fqrh)] = PCPU_GET(cpuid);
380 qman_fqr_free(t_Handle fqr)
382 struct qman_softc *sc;
386 thread_lock(curthread);
387 sched_bind(curthread, sc->sc_fqr_cpu[QM_FQR_GetFqid(fqr)]);
388 thread_unlock(curthread);
390 error = QM_FQR_Free(fqr);
392 thread_lock(curthread);
393 sched_unbind(curthread);
394 thread_unlock(curthread);
400 qman_fqr_register_cb(t_Handle fqr, t_QmReceivedFrameCallback *callback,
403 struct qman_softc *sc;
410 /* Ensure we have got QMan port initialized */
411 portal = qman_portal_setup(sc);
412 if (portal == NULL) {
413 device_printf(sc->sc_dev, "could not setup QMan portal\n");
415 return (E_NOT_SUPPORTED);
418 error = QM_FQR_RegisterCB(fqr, callback, app);
426 qman_fqr_enqueue(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame)
428 struct qman_softc *sc;
435 /* Ensure we have got QMan port initialized */
436 portal = qman_portal_setup(sc);
437 if (portal == NULL) {
438 device_printf(sc->sc_dev, "could not setup QMan portal\n");
440 return (E_NOT_SUPPORTED);
443 error = QM_FQR_Enqueue(fqr, portal, fqid_off, frame);
451 qman_fqr_get_counter(t_Handle fqr, uint32_t fqid_off,
452 e_QmFqrCounters counter)
454 struct qman_softc *sc;
461 /* Ensure we have got QMan port initialized */
462 portal = qman_portal_setup(sc);
463 if (portal == NULL) {
464 device_printf(sc->sc_dev, "could not setup QMan portal\n");
469 val = QM_FQR_GetCounter(fqr, portal, fqid_off, counter);
477 qman_fqr_pull_frame(t_Handle fqr, uint32_t fqid_off, t_DpaaFD *frame)
479 struct qman_softc *sc;
486 /* Ensure we have got QMan port initialized */
487 portal = qman_portal_setup(sc);
488 if (portal == NULL) {
489 device_printf(sc->sc_dev, "could not setup QMan portal\n");
491 return (E_NOT_SUPPORTED);
494 error = QM_FQR_PullFrame(fqr, portal, fqid_off, frame);
502 qman_fqr_get_base_fqid(t_Handle fqr)
504 struct qman_softc *sc;
511 /* Ensure we have got QMan port initialized */
512 portal = qman_portal_setup(sc);
513 if (portal == NULL) {
514 device_printf(sc->sc_dev, "could not setup QMan portal\n");
519 val = QM_FQR_GetFqid(fqr);
527 qman_poll(e_QmPortalPollSource source)
529 struct qman_softc *sc;
536 /* Ensure we have got QMan port initialized */
537 portal = qman_portal_setup(sc);
538 if (portal == NULL) {
539 device_printf(sc->sc_dev, "could not setup QMan portal\n");
541 return (E_NOT_SUPPORTED);
544 error = QM_Poll(sc->sc_qh, source);
552 * TODO: add polling and/or congestion support.