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