/* Copyright 2008 - 2016 Freescale Semiconductor, Inc.1*2* Redistribution and use in source and binary forms, with or without3* modification, are permitted provided that the following conditions are met:4* * Redistributions of source code must retain the above copyright5* notice, this list of conditions and the following disclaimer.6* * Redistributions in binary form must reproduce the above copyright7* notice, this list of conditions and the following disclaimer in the8* documentation and/or other materials provided with the distribution.9* * Neither the name of Freescale Semiconductor nor the10* names of its contributors may be used to endorse or promote products11* derived from this software without specific prior written permission.12*13* ALTERNATIVELY, this software may be distributed under the terms of the14* GNU General Public License ("GPL") as published by the Free Software15* Foundation, either version 2 of that License or (at your option) any16* later version.17*18* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE21* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/2930#ifndef __FSL_QMAN_H31#define __FSL_QMAN_H3233#include <linux/bitops.h>34#include <linux/device.h>3536/* Hardware constants */37#define QM_CHANNEL_SWPORTAL0 038#define QMAN_CHANNEL_POOL1 0x2139#define QMAN_CHANNEL_CAAM 0x8040#define QMAN_CHANNEL_POOL1_REV3 0x40141#define QMAN_CHANNEL_CAAM_REV3 0x84042extern u16 qm_channel_pool1;43extern u16 qm_channel_caam;4445/* Portal processing (interrupt) sources */46#define QM_PIRQ_CSCI 0x00100000 /* Congestion State Change */47#define QM_PIRQ_EQCI 0x00080000 /* Enqueue Command Committed */48#define QM_PIRQ_EQRI 0x00040000 /* EQCR Ring (below threshold) */49#define QM_PIRQ_DQRI 0x00020000 /* DQRR Ring (non-empty) */50#define QM_PIRQ_MRI 0x00010000 /* MR Ring (non-empty) */51/*52* This mask contains all the interrupt sources that need handling except DQRI,53* ie. that if present should trigger slow-path processing.54*/55#define QM_PIRQ_SLOW (QM_PIRQ_CSCI | QM_PIRQ_EQCI | QM_PIRQ_EQRI | \56QM_PIRQ_MRI)5758/* For qman_static_dequeue_*** APIs */59#define QM_SDQCR_CHANNELS_POOL_MASK 0x00007fff60/* for n in [1,15] */61#define QM_SDQCR_CHANNELS_POOL(n) (0x00008000 >> (n))62/* for conversion from n of qm_channel */63static inline u32 QM_SDQCR_CHANNELS_POOL_CONV(u16 channel)64{65return QM_SDQCR_CHANNELS_POOL(channel + 1 - qm_channel_pool1);66}6768/* --- QMan data structures (and associated constants) --- */6970/* "Frame Descriptor (FD)" */71struct qm_fd {72union {73struct {74u8 cfg8b_w1;75u8 bpid; /* Buffer Pool ID */76u8 cfg8b_w3;77u8 addr_hi; /* high 8-bits of 40-bit address */78__be32 addr_lo; /* low 32-bits of 40-bit address */79} __packed;80__be64 data;81};82__be32 cfg; /* format, offset, length / congestion */83union {84__be32 cmd;85__be32 status;86};87} __aligned(8);8889#define QM_FD_FORMAT_SG BIT(31)90#define QM_FD_FORMAT_LONG BIT(30)91#define QM_FD_FORMAT_COMPOUND BIT(29)92#define QM_FD_FORMAT_MASK GENMASK(31, 29)93#define QM_FD_OFF_SHIFT 2094#define QM_FD_OFF_MASK GENMASK(28, 20)95#define QM_FD_LEN_MASK GENMASK(19, 0)96#define QM_FD_LEN_BIG_MASK GENMASK(28, 0)9798enum qm_fd_format {99/*100* 'contig' implies a contiguous buffer, whereas 'sg' implies a101* scatter-gather table. 'big' implies a 29-bit length with no offset102* field, otherwise length is 20-bit and offset is 9-bit. 'compound'103* implies a s/g-like table, where each entry itself represents a frame104* (contiguous or scatter-gather) and the 29-bit "length" is105* interpreted purely for congestion calculations, ie. a "congestion106* weight".107*/108qm_fd_contig = 0,109qm_fd_contig_big = QM_FD_FORMAT_LONG,110qm_fd_sg = QM_FD_FORMAT_SG,111qm_fd_sg_big = QM_FD_FORMAT_SG | QM_FD_FORMAT_LONG,112qm_fd_compound = QM_FD_FORMAT_COMPOUND113};114115static inline dma_addr_t qm_fd_addr(const struct qm_fd *fd)116{117return be64_to_cpu(fd->data) & 0xffffffffffLLU;118}119120static inline u64 qm_fd_addr_get64(const struct qm_fd *fd)121{122return be64_to_cpu(fd->data) & 0xffffffffffLLU;123}124125static inline void qm_fd_addr_set64(struct qm_fd *fd, u64 addr)126{127fd->addr_hi = upper_32_bits(addr);128fd->addr_lo = cpu_to_be32(lower_32_bits(addr));129}130131/*132* The 'format' field indicates the interpretation of the remaining133* 29 bits of the 32-bit word.134* If 'format' is _contig or _sg, 20b length and 9b offset.135* If 'format' is _contig_big or _sg_big, 29b length.136* If 'format' is _compound, 29b "congestion weight".137*/138static inline enum qm_fd_format qm_fd_get_format(const struct qm_fd *fd)139{140return be32_to_cpu(fd->cfg) & QM_FD_FORMAT_MASK;141}142143static inline int qm_fd_get_offset(const struct qm_fd *fd)144{145return (be32_to_cpu(fd->cfg) & QM_FD_OFF_MASK) >> QM_FD_OFF_SHIFT;146}147148static inline int qm_fd_get_length(const struct qm_fd *fd)149{150return be32_to_cpu(fd->cfg) & QM_FD_LEN_MASK;151}152153static inline int qm_fd_get_len_big(const struct qm_fd *fd)154{155return be32_to_cpu(fd->cfg) & QM_FD_LEN_BIG_MASK;156}157158static inline void qm_fd_set_param(struct qm_fd *fd, enum qm_fd_format fmt,159int off, int len)160{161fd->cfg = cpu_to_be32(fmt | (len & QM_FD_LEN_BIG_MASK) |162((off << QM_FD_OFF_SHIFT) & QM_FD_OFF_MASK));163}164165#define qm_fd_set_contig(fd, off, len) \166qm_fd_set_param(fd, qm_fd_contig, off, len)167#define qm_fd_set_sg(fd, off, len) qm_fd_set_param(fd, qm_fd_sg, off, len)168#define qm_fd_set_contig_big(fd, len) \169qm_fd_set_param(fd, qm_fd_contig_big, 0, len)170#define qm_fd_set_sg_big(fd, len) qm_fd_set_param(fd, qm_fd_sg_big, 0, len)171#define qm_fd_set_compound(fd, len) qm_fd_set_param(fd, qm_fd_compound, 0, len)172173static inline void qm_fd_clear_fd(struct qm_fd *fd)174{175fd->data = 0;176fd->cfg = 0;177fd->cmd = 0;178}179180/* Scatter/Gather table entry */181struct qm_sg_entry {182union {183struct {184u8 __reserved1[3];185u8 addr_hi; /* high 8-bits of 40-bit address */186__be32 addr_lo; /* low 32-bits of 40-bit address */187};188__be64 data;189};190__be32 cfg; /* E bit, F bit, length */191u8 __reserved2;192u8 bpid;193__be16 offset; /* 13-bit, _res[13-15]*/194} __packed;195196#define QM_SG_LEN_MASK GENMASK(29, 0)197#define QM_SG_OFF_MASK GENMASK(12, 0)198#define QM_SG_FIN BIT(30)199#define QM_SG_EXT BIT(31)200201static inline dma_addr_t qm_sg_addr(const struct qm_sg_entry *sg)202{203return be64_to_cpu(sg->data) & 0xffffffffffLLU;204}205206static inline u64 qm_sg_entry_get64(const struct qm_sg_entry *sg)207{208return be64_to_cpu(sg->data) & 0xffffffffffLLU;209}210211static inline void qm_sg_entry_set64(struct qm_sg_entry *sg, u64 addr)212{213sg->addr_hi = upper_32_bits(addr);214sg->addr_lo = cpu_to_be32(lower_32_bits(addr));215}216217static inline bool qm_sg_entry_is_final(const struct qm_sg_entry *sg)218{219return be32_to_cpu(sg->cfg) & QM_SG_FIN;220}221222static inline bool qm_sg_entry_is_ext(const struct qm_sg_entry *sg)223{224return be32_to_cpu(sg->cfg) & QM_SG_EXT;225}226227static inline int qm_sg_entry_get_len(const struct qm_sg_entry *sg)228{229return be32_to_cpu(sg->cfg) & QM_SG_LEN_MASK;230}231232static inline void qm_sg_entry_set_len(struct qm_sg_entry *sg, int len)233{234sg->cfg = cpu_to_be32(len & QM_SG_LEN_MASK);235}236237static inline void qm_sg_entry_set_f(struct qm_sg_entry *sg, int len)238{239sg->cfg = cpu_to_be32(QM_SG_FIN | (len & QM_SG_LEN_MASK));240}241242static inline int qm_sg_entry_get_off(const struct qm_sg_entry *sg)243{244return be16_to_cpu(sg->offset) & QM_SG_OFF_MASK;245}246247/* "Frame Dequeue Response" */248struct qm_dqrr_entry {249u8 verb;250u8 stat;251__be16 seqnum; /* 15-bit */252u8 tok;253u8 __reserved2[3];254__be32 fqid; /* 24-bit */255__be32 context_b;256struct qm_fd fd;257u8 __reserved4[32];258} __packed __aligned(64);259#define QM_DQRR_VERB_VBIT 0x80260#define QM_DQRR_VERB_MASK 0x7f /* where the verb contains; */261#define QM_DQRR_VERB_FRAME_DEQUEUE 0x60 /* "this format" */262#define QM_DQRR_STAT_FQ_EMPTY 0x80 /* FQ empty */263#define QM_DQRR_STAT_FQ_HELDACTIVE 0x40 /* FQ held active */264#define QM_DQRR_STAT_FQ_FORCEELIGIBLE 0x20 /* FQ was force-eligible'd */265#define QM_DQRR_STAT_FD_VALID 0x10 /* has a non-NULL FD */266#define QM_DQRR_STAT_UNSCHEDULED 0x02 /* Unscheduled dequeue */267#define QM_DQRR_STAT_DQCR_EXPIRED 0x01 /* VDQCR or PDQCR expired*/268269/* 'fqid' is a 24-bit field in every h/w descriptor */270#define QM_FQID_MASK GENMASK(23, 0)271#define qm_fqid_set(p, v) ((p)->fqid = cpu_to_be32((v) & QM_FQID_MASK))272#define qm_fqid_get(p) (be32_to_cpu((p)->fqid) & QM_FQID_MASK)273274/* "ERN Message Response" */275/* "FQ State Change Notification" */276union qm_mr_entry {277struct {278u8 verb;279u8 __reserved[63];280};281struct {282u8 verb;283u8 dca;284__be16 seqnum;285u8 rc; /* Rej Code: 8-bit */286u8 __reserved[3];287__be32 fqid; /* 24-bit */288__be32 tag;289struct qm_fd fd;290u8 __reserved1[32];291} __packed __aligned(64) ern;292struct {293u8 verb;294u8 fqs; /* Frame Queue Status */295u8 __reserved1[6];296__be32 fqid; /* 24-bit */297__be32 context_b;298u8 __reserved2[48];299} __packed fq; /* FQRN/FQRNI/FQRL/FQPN */300};301#define QM_MR_VERB_VBIT 0x80302/*303* ERNs originating from direct-connect portals ("dcern") use 0x20 as a verb304* which would be invalid as a s/w enqueue verb. A s/w ERN can be distinguished305* from the other MR types by noting if the 0x20 bit is unset.306*/307#define QM_MR_VERB_TYPE_MASK 0x27308#define QM_MR_VERB_DC_ERN 0x20309#define QM_MR_VERB_FQRN 0x21310#define QM_MR_VERB_FQRNI 0x22311#define QM_MR_VERB_FQRL 0x23312#define QM_MR_VERB_FQPN 0x24313#define QM_MR_RC_MASK 0xf0 /* contains one of; */314#define QM_MR_RC_CGR_TAILDROP 0x00315#define QM_MR_RC_WRED 0x10316#define QM_MR_RC_ERROR 0x20317#define QM_MR_RC_ORPWINDOW_EARLY 0x30318#define QM_MR_RC_ORPWINDOW_LATE 0x40319#define QM_MR_RC_FQ_TAILDROP 0x50320#define QM_MR_RC_ORPWINDOW_RETIRED 0x60321#define QM_MR_RC_ORP_ZERO 0x70322#define QM_MR_FQS_ORLPRESENT 0x02 /* ORL fragments to come */323#define QM_MR_FQS_NOTEMPTY 0x01 /* FQ has enqueued frames */324325/*326* An identical structure of FQD fields is present in the "Init FQ" command and327* the "Query FQ" result, it's suctioned out into the "struct qm_fqd" type.328* Within that, the 'stashing' and 'taildrop' pieces are also factored out, the329* latter has two inlines to assist with converting to/from the mant+exp330* representation.331*/332struct qm_fqd_stashing {333/* See QM_STASHING_EXCL_<...> */334u8 exclusive;335/* Numbers of cachelines */336u8 cl; /* _res[6-7], as[4-5], ds[2-3], cs[0-1] */337};338339struct qm_fqd_oac {340/* "Overhead Accounting Control", see QM_OAC_<...> */341u8 oac; /* oac[6-7], _res[0-5] */342/* Two's-complement value (-128 to +127) */343s8 oal; /* "Overhead Accounting Length" */344};345346struct qm_fqd {347/* _res[6-7], orprws[3-5], oa[2], olws[0-1] */348u8 orpc;349u8 cgid;350__be16 fq_ctrl; /* See QM_FQCTRL_<...> */351__be16 dest_wq; /* channel[3-15], wq[0-2] */352__be16 ics_cred; /* 15-bit */353/*354* For "Initialize Frame Queue" commands, the write-enable mask355* determines whether 'td' or 'oac_init' is observed. For query356* commands, this field is always 'td', and 'oac_query' (below) reflects357* the Overhead ACcounting values.358*/359union {360__be16 td; /* "Taildrop": _res[13-15], mant[5-12], exp[0-4] */361struct qm_fqd_oac oac_init;362};363__be32 context_b;364union {365/* Treat it as 64-bit opaque */366__be64 opaque;367struct {368__be32 hi;369__be32 lo;370};371/* Treat it as s/w portal stashing config */372/* see "FQD Context_A field used for [...]" */373struct {374struct qm_fqd_stashing stashing;375/*376* 48-bit address of FQ context to377* stash, must be cacheline-aligned378*/379__be16 context_hi;380__be32 context_lo;381} __packed;382} context_a;383struct qm_fqd_oac oac_query;384} __packed;385386#define QM_FQD_CHAN_OFF 3387#define QM_FQD_WQ_MASK GENMASK(2, 0)388#define QM_FQD_TD_EXP_MASK GENMASK(4, 0)389#define QM_FQD_TD_MANT_OFF 5390#define QM_FQD_TD_MANT_MASK GENMASK(12, 5)391#define QM_FQD_TD_MAX 0xe0000000392#define QM_FQD_TD_MANT_MAX 0xff393#define QM_FQD_OAC_OFF 6394#define QM_FQD_AS_OFF 4395#define QM_FQD_DS_OFF 2396#define QM_FQD_XS_MASK 0x3397398/* 64-bit converters for context_hi/lo */399static inline u64 qm_fqd_stashing_get64(const struct qm_fqd *fqd)400{401return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;402}403404static inline dma_addr_t qm_fqd_stashing_addr(const struct qm_fqd *fqd)405{406return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;407}408409static inline u64 qm_fqd_context_a_get64(const struct qm_fqd *fqd)410{411return qm_fqd_stashing_get64(fqd);412}413414static inline void qm_fqd_stashing_set64(struct qm_fqd *fqd, u64 addr)415{416fqd->context_a.context_hi = cpu_to_be16(upper_32_bits(addr));417fqd->context_a.context_lo = cpu_to_be32(lower_32_bits(addr));418}419420static inline void qm_fqd_context_a_set64(struct qm_fqd *fqd, u64 addr)421{422fqd->context_a.hi = cpu_to_be32(upper_32_bits(addr));423fqd->context_a.lo = cpu_to_be32(lower_32_bits(addr));424}425426/* convert a threshold value into mant+exp representation */427static inline int qm_fqd_set_taildrop(struct qm_fqd *fqd, u32 val,428int roundup)429{430u32 e = 0;431int td, oddbit = 0;432433if (val > QM_FQD_TD_MAX)434return -ERANGE;435436while (val > QM_FQD_TD_MANT_MAX) {437oddbit = val & 1;438val >>= 1;439e++;440if (roundup && oddbit)441val++;442}443444td = (val << QM_FQD_TD_MANT_OFF) & QM_FQD_TD_MANT_MASK;445td |= (e & QM_FQD_TD_EXP_MASK);446fqd->td = cpu_to_be16(td);447return 0;448}449/* and the other direction */450static inline int qm_fqd_get_taildrop(const struct qm_fqd *fqd)451{452int td = be16_to_cpu(fqd->td);453454return ((td & QM_FQD_TD_MANT_MASK) >> QM_FQD_TD_MANT_OFF)455<< (td & QM_FQD_TD_EXP_MASK);456}457458static inline void qm_fqd_set_stashing(struct qm_fqd *fqd, u8 as, u8 ds, u8 cs)459{460struct qm_fqd_stashing *st = &fqd->context_a.stashing;461462st->cl = ((as & QM_FQD_XS_MASK) << QM_FQD_AS_OFF) |463((ds & QM_FQD_XS_MASK) << QM_FQD_DS_OFF) |464(cs & QM_FQD_XS_MASK);465}466467static inline u8 qm_fqd_get_stashing(const struct qm_fqd *fqd)468{469return fqd->context_a.stashing.cl;470}471472static inline void qm_fqd_set_oac(struct qm_fqd *fqd, u8 val)473{474fqd->oac_init.oac = val << QM_FQD_OAC_OFF;475}476477static inline void qm_fqd_set_oal(struct qm_fqd *fqd, s8 val)478{479fqd->oac_init.oal = val;480}481482static inline void qm_fqd_set_destwq(struct qm_fqd *fqd, int ch, int wq)483{484fqd->dest_wq = cpu_to_be16((ch << QM_FQD_CHAN_OFF) |485(wq & QM_FQD_WQ_MASK));486}487488static inline int qm_fqd_get_chan(const struct qm_fqd *fqd)489{490return be16_to_cpu(fqd->dest_wq) >> QM_FQD_CHAN_OFF;491}492493static inline int qm_fqd_get_wq(const struct qm_fqd *fqd)494{495return be16_to_cpu(fqd->dest_wq) & QM_FQD_WQ_MASK;496}497498/* See "Frame Queue Descriptor (FQD)" */499/* Frame Queue Descriptor (FQD) field 'fq_ctrl' uses these constants */500#define QM_FQCTRL_MASK 0x07ff /* 'fq_ctrl' flags; */501#define QM_FQCTRL_CGE 0x0400 /* Congestion Group Enable */502#define QM_FQCTRL_TDE 0x0200 /* Tail-Drop Enable */503#define QM_FQCTRL_CTXASTASHING 0x0080 /* Context-A stashing */504#define QM_FQCTRL_CPCSTASH 0x0040 /* CPC Stash Enable */505#define QM_FQCTRL_FORCESFDR 0x0008 /* High-priority SFDRs */506#define QM_FQCTRL_AVOIDBLOCK 0x0004 /* Don't block active */507#define QM_FQCTRL_HOLDACTIVE 0x0002 /* Hold active in portal */508#define QM_FQCTRL_PREFERINCACHE 0x0001 /* Aggressively cache FQD */509#define QM_FQCTRL_LOCKINCACHE QM_FQCTRL_PREFERINCACHE /* older naming */510511/* See "FQD Context_A field used for [...] */512/* Frame Queue Descriptor (FQD) field 'CONTEXT_A' uses these constants */513#define QM_STASHING_EXCL_ANNOTATION 0x04514#define QM_STASHING_EXCL_DATA 0x02515#define QM_STASHING_EXCL_CTX 0x01516517/* See "Intra Class Scheduling" */518/* FQD field 'OAC' (Overhead ACcounting) uses these constants */519#define QM_OAC_ICS 0x2 /* Accounting for Intra-Class Scheduling */520#define QM_OAC_CG 0x1 /* Accounting for Congestion Groups */521522/*523* This struct represents the 32-bit "WR_PARM_[GYR]" parameters in CGR fields524* and associated commands/responses. The WRED parameters are calculated from525* these fields as follows;526* MaxTH = MA * (2 ^ Mn)527* Slope = SA / (2 ^ Sn)528* MaxP = 4 * (Pn + 1)529*/530struct qm_cgr_wr_parm {531/* MA[24-31], Mn[19-23], SA[12-18], Sn[6-11], Pn[0-5] */532__be32 word;533};534/*535* This struct represents the 13-bit "CS_THRES" CGR field. In the corresponding536* management commands, this is padded to a 16-bit structure field, so that's537* how we represent it here. The congestion state threshold is calculated from538* these fields as follows;539* CS threshold = TA * (2 ^ Tn)540*/541struct qm_cgr_cs_thres {542/* _res[13-15], TA[5-12], Tn[0-4] */543__be16 word;544};545/*546* This identical structure of CGR fields is present in the "Init/Modify CGR"547* commands and the "Query CGR" result. It's suctioned out here into its own548* struct.549*/550struct __qm_mc_cgr {551struct qm_cgr_wr_parm wr_parm_g;552struct qm_cgr_wr_parm wr_parm_y;553struct qm_cgr_wr_parm wr_parm_r;554u8 wr_en_g; /* boolean, use QM_CGR_EN */555u8 wr_en_y; /* boolean, use QM_CGR_EN */556u8 wr_en_r; /* boolean, use QM_CGR_EN */557u8 cscn_en; /* boolean, use QM_CGR_EN */558union {559struct {560__be16 cscn_targ_upd_ctrl; /* use QM_CGR_TARG_UDP_* */561__be16 cscn_targ_dcp_low;562};563__be32 cscn_targ; /* use QM_CGR_TARG_* */564};565u8 cstd_en; /* boolean, use QM_CGR_EN */566u8 cs; /* boolean, only used in query response */567struct qm_cgr_cs_thres cs_thres; /* use qm_cgr_cs_thres_set64() */568u8 mode; /* QMAN_CGR_MODE_FRAME not supported in rev1.0 */569} __packed;570#define QM_CGR_EN 0x01 /* For wr_en_*, cscn_en, cstd_en */571#define QM_CGR_TARG_UDP_CTRL_WRITE_BIT 0x8000 /* value written to portal bit*/572#define QM_CGR_TARG_UDP_CTRL_DCP 0x4000 /* 0: SWP, 1: DCP */573#define QM_CGR_TARG_PORTAL(n) (0x80000000 >> (n)) /* s/w portal, 0-9 */574#define QM_CGR_TARG_FMAN0 0x00200000 /* direct-connect portal: fman0 */575#define QM_CGR_TARG_FMAN1 0x00100000 /* : fman1 */576/* Convert CGR thresholds to/from "cs_thres" format */577static inline u64 qm_cgr_cs_thres_get64(const struct qm_cgr_cs_thres *th)578{579int thres = be16_to_cpu(th->word);580581return ((thres >> 5) & 0xff) << (thres & 0x1f);582}583584static inline int qm_cgr_cs_thres_set64(struct qm_cgr_cs_thres *th, u64 val,585int roundup)586{587u32 e = 0;588int oddbit = 0;589590while (val > 0xff) {591oddbit = val & 1;592val >>= 1;593e++;594if (roundup && oddbit)595val++;596}597th->word = cpu_to_be16(((val & 0xff) << 5) | (e & 0x1f));598return 0;599}600601/* "Initialize FQ" */602struct qm_mcc_initfq {603u8 __reserved1[2];604__be16 we_mask; /* Write Enable Mask */605__be32 fqid; /* 24-bit */606__be16 count; /* Initialises 'count+1' FQDs */607struct qm_fqd fqd; /* the FQD fields go here */608u8 __reserved2[30];609} __packed;610/* "Initialize/Modify CGR" */611struct qm_mcc_initcgr {612u8 __reserve1[2];613__be16 we_mask; /* Write Enable Mask */614struct __qm_mc_cgr cgr; /* CGR fields */615u8 __reserved2[2];616u8 cgid;617u8 __reserved3[32];618} __packed;619620/* INITFQ-specific flags */621#define QM_INITFQ_WE_MASK 0x01ff /* 'Write Enable' flags; */622#define QM_INITFQ_WE_OAC 0x0100623#define QM_INITFQ_WE_ORPC 0x0080624#define QM_INITFQ_WE_CGID 0x0040625#define QM_INITFQ_WE_FQCTRL 0x0020626#define QM_INITFQ_WE_DESTWQ 0x0010627#define QM_INITFQ_WE_ICSCRED 0x0008628#define QM_INITFQ_WE_TDTHRESH 0x0004629#define QM_INITFQ_WE_CONTEXTB 0x0002630#define QM_INITFQ_WE_CONTEXTA 0x0001631/* INITCGR/MODIFYCGR-specific flags */632#define QM_CGR_WE_MASK 0x07ff /* 'Write Enable Mask'; */633#define QM_CGR_WE_WR_PARM_G 0x0400634#define QM_CGR_WE_WR_PARM_Y 0x0200635#define QM_CGR_WE_WR_PARM_R 0x0100636#define QM_CGR_WE_WR_EN_G 0x0080637#define QM_CGR_WE_WR_EN_Y 0x0040638#define QM_CGR_WE_WR_EN_R 0x0020639#define QM_CGR_WE_CSCN_EN 0x0010640#define QM_CGR_WE_CSCN_TARG 0x0008641#define QM_CGR_WE_CSTD_EN 0x0004642#define QM_CGR_WE_CS_THRES 0x0002643#define QM_CGR_WE_MODE 0x0001644645#define QMAN_CGR_FLAG_USE_INIT 0x00000001646#define QMAN_CGR_MODE_FRAME 0x00000001647648/* Portal and Frame Queues */649/* Represents a managed portal */650struct qman_portal;651652/*653* This object type represents QMan frame queue descriptors (FQD), it is654* cacheline-aligned, and initialised by qman_create_fq(). The structure is655* defined further down.656*/657struct qman_fq;658659/*660* This object type represents a QMan congestion group, it is defined further661* down.662*/663struct qman_cgr;664665/*666* This enum, and the callback type that returns it, are used when handling667* dequeued frames via DQRR. Note that for "null" callbacks registered with the668* portal object (for handling dequeues that do not demux because context_b is669* NULL), the return value *MUST* be qman_cb_dqrr_consume.670*/671enum qman_cb_dqrr_result {672/* DQRR entry can be consumed */673qman_cb_dqrr_consume,674/* Like _consume, but requests parking - FQ must be held-active */675qman_cb_dqrr_park,676/* Does not consume, for DCA mode only. */677qman_cb_dqrr_defer,678/*679* Stop processing without consuming this ring entry. Exits the current680* qman_p_poll_dqrr() or interrupt-handling, as appropriate. If within681* an interrupt handler, the callback would typically call682* qman_irqsource_remove(QM_PIRQ_DQRI) before returning this value,683* otherwise the interrupt will reassert immediately.684*/685qman_cb_dqrr_stop,686/* Like qman_cb_dqrr_stop, but consumes the current entry. */687qman_cb_dqrr_consume_stop688};689typedef enum qman_cb_dqrr_result (*qman_cb_dqrr)(struct qman_portal *qm,690struct qman_fq *fq,691const struct qm_dqrr_entry *dqrr,692bool sched_napi);693694/*695* This callback type is used when handling ERNs, FQRNs and FQRLs via MR. They696* are always consumed after the callback returns.697*/698typedef void (*qman_cb_mr)(struct qman_portal *qm, struct qman_fq *fq,699const union qm_mr_entry *msg);700701/*702* s/w-visible states. Ie. tentatively scheduled + truly scheduled + active +703* held-active + held-suspended are just "sched". Things like "retired" will not704* be assumed until it is complete (ie. QMAN_FQ_STATE_CHANGING is set until705* then, to indicate it's completing and to gate attempts to retry the retire706* command). Note, park commands do not set QMAN_FQ_STATE_CHANGING because it's707* technically impossible in the case of enqueue DCAs (which refer to DQRR ring708* index rather than the FQ that ring entry corresponds to), so repeated park709* commands are allowed (if you're silly enough to try) but won't change FQ710* state, and the resulting park notifications move FQs from "sched" to711* "parked".712*/713enum qman_fq_state {714qman_fq_state_oos,715qman_fq_state_parked,716qman_fq_state_sched,717qman_fq_state_retired718};719720#define QMAN_FQ_STATE_CHANGING 0x80000000 /* 'state' is changing */721#define QMAN_FQ_STATE_NE 0x40000000 /* retired FQ isn't empty */722#define QMAN_FQ_STATE_ORL 0x20000000 /* retired FQ has ORL */723#define QMAN_FQ_STATE_BLOCKOOS 0xe0000000 /* if any are set, no OOS */724#define QMAN_FQ_STATE_CGR_EN 0x10000000 /* CGR enabled */725#define QMAN_FQ_STATE_VDQCR 0x08000000 /* being volatile dequeued */726727/*728* Frame queue objects (struct qman_fq) are stored within memory passed to729* qman_create_fq(), as this allows stashing of caller-provided demux callback730* pointers at no extra cost to stashing of (driver-internal) FQ state. If the731* caller wishes to add per-FQ state and have it benefit from dequeue-stashing,732* they should;733*734* (a) extend the qman_fq structure with their state; eg.735*736* // myfq is allocated and driver_fq callbacks filled in;737* struct my_fq {738* struct qman_fq base;739* int an_extra_field;740* [ ... add other fields to be associated with each FQ ...]741* } *myfq = some_my_fq_allocator();742* struct qman_fq *fq = qman_create_fq(fqid, flags, &myfq->base);743*744* // in a dequeue callback, access extra fields from 'fq' via a cast;745* struct my_fq *myfq = (struct my_fq *)fq;746* do_something_with(myfq->an_extra_field);747* [...]748*749* (b) when and if configuring the FQ for context stashing, specify how ever750* many cachelines are required to stash 'struct my_fq', to accelerate not751* only the QMan driver but the callback as well.752*/753754struct qman_fq_cb {755qman_cb_dqrr dqrr; /* for dequeued frames */756qman_cb_mr ern; /* for s/w ERNs */757qman_cb_mr fqs; /* frame-queue state changes*/758};759760struct qman_fq {761/* Caller of qman_create_fq() provides these demux callbacks */762struct qman_fq_cb cb;763/*764* These are internal to the driver, don't touch. In particular, they765* may change, be removed, or extended (so you shouldn't rely on766* sizeof(qman_fq) being a constant).767*/768u32 fqid, idx;769unsigned long flags;770enum qman_fq_state state;771int cgr_groupid;772};773774/*775* This callback type is used when handling congestion group entry/exit.776* 'congested' is non-zero on congestion-entry, and zero on congestion-exit.777*/778typedef void (*qman_cb_cgr)(struct qman_portal *qm,779struct qman_cgr *cgr, int congested);780781struct qman_cgr {782/* Set these prior to qman_create_cgr() */783u32 cgrid; /* 0..255, but u32 to allow specials like -1, 256, etc.*/784qman_cb_cgr cb;785/* These are private to the driver */786u16 chan; /* portal channel this object is created on */787struct list_head node;788};789790/* Flags to qman_create_fq() */791#define QMAN_FQ_FLAG_NO_ENQUEUE 0x00000001 /* can't enqueue */792#define QMAN_FQ_FLAG_NO_MODIFY 0x00000002 /* can only enqueue */793#define QMAN_FQ_FLAG_TO_DCPORTAL 0x00000004 /* consumed by CAAM/PME/Fman */794#define QMAN_FQ_FLAG_DYNAMIC_FQID 0x00000020 /* (de)allocate fqid */795796/* Flags to qman_init_fq() */797#define QMAN_INITFQ_FLAG_SCHED 0x00000001 /* schedule rather than park */798#define QMAN_INITFQ_FLAG_LOCAL 0x00000004 /* set dest portal */799800/*801* For qman_volatile_dequeue(); Choose one PRECEDENCE. EXACT is optional. Use802* NUMFRAMES(n) (6-bit) or NUMFRAMES_TILLEMPTY to fill in the frame-count. Use803* FQID(n) to fill in the frame queue ID.804*/805#define QM_VDQCR_PRECEDENCE_VDQCR 0x0806#define QM_VDQCR_PRECEDENCE_SDQCR 0x80000000807#define QM_VDQCR_EXACT 0x40000000808#define QM_VDQCR_NUMFRAMES_MASK 0x3f000000809#define QM_VDQCR_NUMFRAMES_SET(n) (((n) & 0x3f) << 24)810#define QM_VDQCR_NUMFRAMES_GET(n) (((n) >> 24) & 0x3f)811#define QM_VDQCR_NUMFRAMES_TILLEMPTY QM_VDQCR_NUMFRAMES_SET(0)812813#define QMAN_VOLATILE_FLAG_WAIT 0x00000001 /* wait if VDQCR is in use */814#define QMAN_VOLATILE_FLAG_WAIT_INT 0x00000002 /* if wait, interruptible? */815#define QMAN_VOLATILE_FLAG_FINISH 0x00000004 /* wait till VDQCR completes */816817/* "Query FQ Non-Programmable Fields" */818struct qm_mcr_queryfq_np {819u8 verb;820u8 result;821u8 __reserved1;822u8 state; /* QM_MCR_NP_STATE_*** */823u32 fqd_link; /* 24-bit, _res2[24-31] */824u16 odp_seq; /* 14-bit, _res3[14-15] */825u16 orp_nesn; /* 14-bit, _res4[14-15] */826u16 orp_ea_hseq; /* 15-bit, _res5[15] */827u16 orp_ea_tseq; /* 15-bit, _res6[15] */828u32 orp_ea_hptr; /* 24-bit, _res7[24-31] */829u32 orp_ea_tptr; /* 24-bit, _res8[24-31] */830u32 pfdr_hptr; /* 24-bit, _res9[24-31] */831u32 pfdr_tptr; /* 24-bit, _res10[24-31] */832u8 __reserved2[5];833u8 is; /* 1-bit, _res12[1-7] */834u16 ics_surp;835u32 byte_cnt;836u32 frm_cnt; /* 24-bit, _res13[24-31] */837u32 __reserved3;838u16 ra1_sfdr; /* QM_MCR_NP_RA1_*** */839u16 ra2_sfdr; /* QM_MCR_NP_RA2_*** */840u16 __reserved4;841u16 od1_sfdr; /* QM_MCR_NP_OD1_*** */842u16 od2_sfdr; /* QM_MCR_NP_OD2_*** */843u16 od3_sfdr; /* QM_MCR_NP_OD3_*** */844} __packed;845846#define QM_MCR_NP_STATE_FE 0x10847#define QM_MCR_NP_STATE_R 0x08848#define QM_MCR_NP_STATE_MASK 0x07 /* Reads FQD::STATE; */849#define QM_MCR_NP_STATE_OOS 0x00850#define QM_MCR_NP_STATE_RETIRED 0x01851#define QM_MCR_NP_STATE_TEN_SCHED 0x02852#define QM_MCR_NP_STATE_TRU_SCHED 0x03853#define QM_MCR_NP_STATE_PARKED 0x04854#define QM_MCR_NP_STATE_ACTIVE 0x05855#define QM_MCR_NP_PTR_MASK 0x07ff /* for RA[12] & OD[123] */856#define QM_MCR_NP_RA1_NRA(v) (((v) >> 14) & 0x3) /* FQD::NRA */857#define QM_MCR_NP_RA2_IT(v) (((v) >> 14) & 0x1) /* FQD::IT */858#define QM_MCR_NP_OD1_NOD(v) (((v) >> 14) & 0x3) /* FQD::NOD */859#define QM_MCR_NP_OD3_NPC(v) (((v) >> 14) & 0x3) /* FQD::NPC */860861enum qm_mcr_queryfq_np_masks {862qm_mcr_fqd_link_mask = BIT(24) - 1,863qm_mcr_odp_seq_mask = BIT(14) - 1,864qm_mcr_orp_nesn_mask = BIT(14) - 1,865qm_mcr_orp_ea_hseq_mask = BIT(15) - 1,866qm_mcr_orp_ea_tseq_mask = BIT(15) - 1,867qm_mcr_orp_ea_hptr_mask = BIT(24) - 1,868qm_mcr_orp_ea_tptr_mask = BIT(24) - 1,869qm_mcr_pfdr_hptr_mask = BIT(24) - 1,870qm_mcr_pfdr_tptr_mask = BIT(24) - 1,871qm_mcr_is_mask = BIT(1) - 1,872qm_mcr_frm_cnt_mask = BIT(24) - 1,873};874875#define qm_mcr_np_get(np, field) \876((np)->field & (qm_mcr_##field##_mask))877878/* Portal Management */879/**880* qman_p_irqsource_add - add processing sources to be interrupt-driven881* @bits: bitmask of QM_PIRQ_**I processing sources882*883* Adds processing sources that should be interrupt-driven (rather than884* processed via qman_poll_***() functions).885*/886void qman_p_irqsource_add(struct qman_portal *p, u32 bits);887888/**889* qman_p_irqsource_remove - remove processing sources from being int-driven890* @bits: bitmask of QM_PIRQ_**I processing sources891*892* Removes processing sources from being interrupt-driven, so that they will893* instead be processed via qman_poll_***() functions.894*/895void qman_p_irqsource_remove(struct qman_portal *p, u32 bits);896897/**898* qman_affine_cpus - return a mask of cpus that have affine portals899*/900const cpumask_t *qman_affine_cpus(void);901902/**903* qman_affine_channel - return the channel ID of an portal904* @cpu: the cpu whose affine portal is the subject of the query905*906* If @cpu is -1, the affine portal for the current CPU will be used. It is a907* bug to call this function for any value of @cpu (other than -1) that is not a908* member of the mask returned from qman_affine_cpus().909*/910u16 qman_affine_channel(int cpu);911912/**913* qman_get_affine_portal - return the portal pointer affine to cpu914* @cpu: the cpu whose affine portal is the subject of the query915*/916struct qman_portal *qman_get_affine_portal(int cpu);917918/**919* qman_start_using_portal - register a device link for the portal user920* @p: the portal that will be in use921* @dev: the device that will use the portal922*923* Makes sure that the devices that use the portal are unbound when the924* portal is unbound925*/926int qman_start_using_portal(struct qman_portal *p, struct device *dev);927928/**929* qman_p_poll_dqrr - process DQRR (fast-path) entries930* @limit: the maximum number of DQRR entries to process931*932* Use of this function requires that DQRR processing not be interrupt-driven.933* The return value represents the number of DQRR entries processed.934*/935int qman_p_poll_dqrr(struct qman_portal *p, unsigned int limit);936937/**938* qman_p_static_dequeue_add - Add pool channels to the portal SDQCR939* @pools: bit-mask of pool channels, using QM_SDQCR_CHANNELS_POOL(n)940*941* Adds a set of pool channels to the portal's static dequeue command register942* (SDQCR). The requested pools are limited to those the portal has dequeue943* access to.944*/945void qman_p_static_dequeue_add(struct qman_portal *p, u32 pools);946947/* FQ management */948/**949* qman_create_fq - Allocates a FQ950* @fqid: the index of the FQD to encapsulate, must be "Out of Service"951* @flags: bit-mask of QMAN_FQ_FLAG_*** options952* @fq: memory for storing the 'fq', with callbacks filled in953*954* Creates a frame queue object for the given @fqid, unless the955* QMAN_FQ_FLAG_DYNAMIC_FQID flag is set in @flags, in which case a FQID is956* dynamically allocated (or the function fails if none are available). Once957* created, the caller should not touch the memory at 'fq' except as extended to958* adjacent memory for user-defined fields (see the definition of "struct959* qman_fq" for more info). NO_MODIFY is only intended for enqueuing to960* pre-existing frame-queues that aren't to be otherwise interfered with, it961* prevents all other modifications to the frame queue. The TO_DCPORTAL flag962* causes the driver to honour any context_b modifications requested in the963* qm_init_fq() API, as this indicates the frame queue will be consumed by a964* direct-connect portal (PME, CAAM, or Fman). When frame queues are consumed by965* software portals, the context_b field is controlled by the driver and can't966* be modified by the caller.967*/968int qman_create_fq(u32 fqid, u32 flags, struct qman_fq *fq);969970/**971* qman_destroy_fq - Deallocates a FQ972* @fq: the frame queue object to release973*974* The memory for this frame queue object ('fq' provided in qman_create_fq()) is975* not deallocated but the caller regains ownership, to do with as desired. The976* FQ must be in the 'out-of-service' or in the 'parked' state.977*/978void qman_destroy_fq(struct qman_fq *fq);979980/**981* qman_fq_fqid - Queries the frame queue ID of a FQ object982* @fq: the frame queue object to query983*/984u32 qman_fq_fqid(struct qman_fq *fq);985986/**987* qman_init_fq - Initialises FQ fields, leaves the FQ "parked" or "scheduled"988* @fq: the frame queue object to modify, must be 'parked' or new.989* @flags: bit-mask of QMAN_INITFQ_FLAG_*** options990* @opts: the FQ-modification settings, as defined in the low-level API991*992* The @opts parameter comes from the low-level portal API. Select993* QMAN_INITFQ_FLAG_SCHED in @flags to cause the frame queue to be scheduled994* rather than parked. NB, @opts can be NULL.995*996* Note that some fields and options within @opts may be ignored or overwritten997* by the driver;998* 1. the 'count' and 'fqid' fields are always ignored (this operation only999* affects one frame queue: @fq).1000* 2. the QM_INITFQ_WE_CONTEXTB option of the 'we_mask' field and the associated1001* 'fqd' structure's 'context_b' field are sometimes overwritten;1002* - if @fq was not created with QMAN_FQ_FLAG_TO_DCPORTAL, then context_b is1003* initialised to a value used by the driver for demux.1004* - if context_b is initialised for demux, so is context_a in case stashing1005* is requested (see item 4).1006* (So caller control of context_b is only possible for TO_DCPORTAL frame queue1007* objects.)1008* 3. if @flags contains QMAN_INITFQ_FLAG_LOCAL, the 'fqd' structure's1009* 'dest::channel' field will be overwritten to match the portal used to issue1010* the command. If the WE_DESTWQ write-enable bit had already been set by the1011* caller, the channel workqueue will be left as-is, otherwise the write-enable1012* bit is set and the workqueue is set to a default of 4. If the "LOCAL" flag1013* isn't set, the destination channel/workqueue fields and the write-enable bit1014* are left as-is.1015* 4. if the driver overwrites context_a/b for demux, then if1016* QM_INITFQ_WE_CONTEXTA is set, the driver will only overwrite1017* context_a.address fields and will leave the stashing fields provided by the1018* user alone, otherwise it will zero out the context_a.stashing fields.1019*/1020int qman_init_fq(struct qman_fq *fq, u32 flags, struct qm_mcc_initfq *opts);10211022/**1023* qman_schedule_fq - Schedules a FQ1024* @fq: the frame queue object to schedule, must be 'parked'1025*1026* Schedules the frame queue, which must be Parked, which takes it to1027* Tentatively-Scheduled or Truly-Scheduled depending on its fill-level.1028*/1029int qman_schedule_fq(struct qman_fq *fq);10301031/**1032* qman_retire_fq - Retires a FQ1033* @fq: the frame queue object to retire1034* @flags: FQ flags (QMAN_FQ_STATE*) if retirement completes immediately1035*1036* Retires the frame queue. This returns zero if it succeeds immediately, +1 if1037* the retirement was started asynchronously, otherwise it returns negative for1038* failure. When this function returns zero, @flags is set to indicate whether1039* the retired FQ is empty and/or whether it has any ORL fragments (to show up1040* as ERNs). Otherwise the corresponding flags will be known when a subsequent1041* FQRN message shows up on the portal's message ring.1042*1043* NB, if the retirement is asynchronous (the FQ was in the Truly Scheduled or1044* Active state), the completion will be via the message ring as a FQRN - but1045* the corresponding callback may occur before this function returns!! Ie. the1046* caller should be prepared to accept the callback as the function is called,1047* not only once it has returned.1048*/1049int qman_retire_fq(struct qman_fq *fq, u32 *flags);10501051/**1052* qman_oos_fq - Puts a FQ "out of service"1053* @fq: the frame queue object to be put out-of-service, must be 'retired'1054*1055* The frame queue must be retired and empty, and if any order restoration list1056* was released as ERNs at the time of retirement, they must all be consumed.1057*/1058int qman_oos_fq(struct qman_fq *fq);10591060/*1061* qman_volatile_dequeue - Issue a volatile dequeue command1062* @fq: the frame queue object to dequeue from1063* @flags: a bit-mask of QMAN_VOLATILE_FLAG_*** options1064* @vdqcr: bit mask of QM_VDQCR_*** options, as per qm_dqrr_vdqcr_set()1065*1066* Attempts to lock access to the portal's VDQCR volatile dequeue functionality.1067* The function will block and sleep if QMAN_VOLATILE_FLAG_WAIT is specified and1068* the VDQCR is already in use, otherwise returns non-zero for failure. If1069* QMAN_VOLATILE_FLAG_FINISH is specified, the function will only return once1070* the VDQCR command has finished executing (ie. once the callback for the last1071* DQRR entry resulting from the VDQCR command has been called). If not using1072* the FINISH flag, completion can be determined either by detecting the1073* presence of the QM_DQRR_STAT_UNSCHEDULED and QM_DQRR_STAT_DQCR_EXPIRED bits1074* in the "stat" parameter passed to the FQ's dequeue callback, or by waiting1075* for the QMAN_FQ_STATE_VDQCR bit to disappear.1076*/1077int qman_volatile_dequeue(struct qman_fq *fq, u32 flags, u32 vdqcr);10781079/**1080* qman_enqueue - Enqueue a frame to a frame queue1081* @fq: the frame queue object to enqueue to1082* @fd: a descriptor of the frame to be enqueued1083*1084* Fills an entry in the EQCR of portal @qm to enqueue the frame described by1085* @fd. The descriptor details are copied from @fd to the EQCR entry, the 'pid'1086* field is ignored. The return value is non-zero on error, such as ring full.1087*/1088int qman_enqueue(struct qman_fq *fq, const struct qm_fd *fd);10891090/**1091* qman_alloc_fqid_range - Allocate a contiguous range of FQIDs1092* @result: is set by the API to the base FQID of the allocated range1093* @count: the number of FQIDs required1094*1095* Returns 0 on success, or a negative error code.1096*/1097int qman_alloc_fqid_range(u32 *result, u32 count);1098#define qman_alloc_fqid(result) qman_alloc_fqid_range(result, 1)10991100/**1101* qman_release_fqid - Release the specified frame queue ID1102* @fqid: the FQID to be released back to the resource pool1103*1104* This function can also be used to seed the allocator with1105* FQID ranges that it can subsequently allocate from.1106* Returns 0 on success, or a negative error code.1107*/1108int qman_release_fqid(u32 fqid);11091110/**1111* qman_query_fq_np - Queries non-programmable FQD fields1112* @fq: the frame queue object to be queried1113* @np: storage for the queried FQD fields1114*/1115int qman_query_fq_np(struct qman_fq *fq, struct qm_mcr_queryfq_np *np);11161117/* Pool-channel management */1118/**1119* qman_alloc_pool_range - Allocate a contiguous range of pool-channel IDs1120* @result: is set by the API to the base pool-channel ID of the allocated range1121* @count: the number of pool-channel IDs required1122*1123* Returns 0 on success, or a negative error code.1124*/1125int qman_alloc_pool_range(u32 *result, u32 count);1126#define qman_alloc_pool(result) qman_alloc_pool_range(result, 1)11271128/**1129* qman_release_pool - Release the specified pool-channel ID1130* @id: the pool-chan ID to be released back to the resource pool1131*1132* This function can also be used to seed the allocator with1133* pool-channel ID ranges that it can subsequently allocate from.1134* Returns 0 on success, or a negative error code.1135*/1136int qman_release_pool(u32 id);11371138/* CGR management */1139/**1140* qman_create_cgr - Register a congestion group object1141* @cgr: the 'cgr' object, with fields filled in1142* @flags: QMAN_CGR_FLAG_* values1143* @opts: optional state of CGR settings1144*1145* Registers this object to receiving congestion entry/exit callbacks on the1146* portal affine to the cpu portal on which this API is executed. If opts is1147* NULL then only the callback (cgr->cb) function is registered. If @flags1148* contains QMAN_CGR_FLAG_USE_INIT, then an init hw command (which will reset1149* any unspecified parameters) will be used rather than a modify hw hardware1150* (which only modifies the specified parameters).1151*/1152int qman_create_cgr(struct qman_cgr *cgr, u32 flags,1153struct qm_mcc_initcgr *opts);11541155/**1156* qman_delete_cgr - Deregisters a congestion group object1157* @cgr: the 'cgr' object to deregister1158*1159* "Unplugs" this CGR object from the portal affine to the cpu on which this API1160* is executed. This must be excuted on the same affine portal on which it was1161* created.1162*/1163int qman_delete_cgr(struct qman_cgr *cgr);11641165/**1166* qman_delete_cgr_safe - Deregisters a congestion group object from any CPU1167* @cgr: the 'cgr' object to deregister1168*1169* This will select the proper CPU and run there qman_delete_cgr().1170*/1171void qman_delete_cgr_safe(struct qman_cgr *cgr);11721173/**1174* qman_update_cgr_safe - Modifies a congestion group object from any CPU1175* @cgr: the 'cgr' object to modify1176* @opts: state of the CGR settings1177*1178* This will select the proper CPU and modify the CGR settings.1179*/1180int qman_update_cgr_safe(struct qman_cgr *cgr, struct qm_mcc_initcgr *opts);11811182/**1183* qman_query_cgr_congested - Queries CGR's congestion status1184* @cgr: the 'cgr' object to query1185* @result: returns 'cgr's congestion status, 1 (true) if congested1186*/1187int qman_query_cgr_congested(struct qman_cgr *cgr, bool *result);11881189/**1190* qman_alloc_cgrid_range - Allocate a contiguous range of CGR IDs1191* @result: is set by the API to the base CGR ID of the allocated range1192* @count: the number of CGR IDs required1193*1194* Returns 0 on success, or a negative error code.1195*/1196int qman_alloc_cgrid_range(u32 *result, u32 count);1197#define qman_alloc_cgrid(result) qman_alloc_cgrid_range(result, 1)11981199/**1200* qman_release_cgrid - Release the specified CGR ID1201* @id: the CGR ID to be released back to the resource pool1202*1203* This function can also be used to seed the allocator with1204* CGR ID ranges that it can subsequently allocate from.1205* Returns 0 on success, or a negative error code.1206*/1207int qman_release_cgrid(u32 id);12081209/**1210* qman_is_probed - Check if qman is probed1211*1212* Returns 1 if the qman driver successfully probed, -1 if the qman driver1213* failed to probe or 0 if the qman driver did not probed yet.1214*/1215int qman_is_probed(void);12161217/**1218* qman_portals_probed - Check if all cpu bound qman portals are probed1219*1220* Returns 1 if all the required cpu bound qman portals successfully probed,1221* -1 if probe errors appeared or 0 if the qman portals did not yet finished1222* probing.1223*/1224int qman_portals_probed(void);12251226/**1227* qman_dqrr_get_ithresh - Get coalesce interrupt threshold1228* @portal: portal to get the value for1229* @ithresh: threshold pointer1230*/1231void qman_dqrr_get_ithresh(struct qman_portal *portal, u8 *ithresh);12321233/**1234* qman_dqrr_set_ithresh - Set coalesce interrupt threshold1235* @portal: portal to set the new value on1236* @ithresh: new threshold value1237*1238* Returns 0 on success, or a negative error code.1239*/1240int qman_dqrr_set_ithresh(struct qman_portal *portal, u8 ithresh);12411242/**1243* qman_dqrr_get_iperiod - Get coalesce interrupt period1244* @portal: portal to get the value for1245* @iperiod: period pointer1246*/1247void qman_portal_get_iperiod(struct qman_portal *portal, u32 *iperiod);12481249/**1250* qman_dqrr_set_iperiod - Set coalesce interrupt period1251* @portal: portal to set the new value on1252* @ithresh: new period value1253*1254* Returns 0 on success, or a negative error code.1255*/1256int qman_portal_set_iperiod(struct qman_portal *portal, u32 iperiod);12571258#endif /* __FSL_QMAN_H */125912601261