qman.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * ALTERNATIVELY, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL") as published by the Free Software
  16. * Foundation, either version 2 of that License or (at your option) any
  17. * later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __FSL_QMAN_H
  31. #define __FSL_QMAN_H
  32. #include <linux/bitops.h>
  33. /* Hardware constants */
  34. #define QM_CHANNEL_SWPORTAL0 0
  35. #define QMAN_CHANNEL_POOL1 0x21
  36. #define QMAN_CHANNEL_POOL1_REV3 0x401
  37. extern u16 qm_channel_pool1;
  38. /* Portal processing (interrupt) sources */
  39. #define QM_PIRQ_CSCI 0x00100000 /* Congestion State Change */
  40. #define QM_PIRQ_EQCI 0x00080000 /* Enqueue Command Committed */
  41. #define QM_PIRQ_EQRI 0x00040000 /* EQCR Ring (below threshold) */
  42. #define QM_PIRQ_DQRI 0x00020000 /* DQRR Ring (non-empty) */
  43. #define QM_PIRQ_MRI 0x00010000 /* MR Ring (non-empty) */
  44. /*
  45. * This mask contains all the interrupt sources that need handling except DQRI,
  46. * ie. that if present should trigger slow-path processing.
  47. */
  48. #define QM_PIRQ_SLOW (QM_PIRQ_CSCI | QM_PIRQ_EQCI | QM_PIRQ_EQRI | \
  49. QM_PIRQ_MRI)
  50. /* For qman_static_dequeue_*** APIs */
  51. #define QM_SDQCR_CHANNELS_POOL_MASK 0x00007fff
  52. /* for n in [1,15] */
  53. #define QM_SDQCR_CHANNELS_POOL(n) (0x00008000 >> (n))
  54. /* for conversion from n of qm_channel */
  55. static inline u32 QM_SDQCR_CHANNELS_POOL_CONV(u16 channel)
  56. {
  57. return QM_SDQCR_CHANNELS_POOL(channel + 1 - qm_channel_pool1);
  58. }
  59. /* --- QMan data structures (and associated constants) --- */
  60. /* "Frame Descriptor (FD)" */
  61. struct qm_fd {
  62. union {
  63. struct {
  64. u8 cfg8b_w1;
  65. u8 bpid; /* Buffer Pool ID */
  66. u8 cfg8b_w3;
  67. u8 addr_hi; /* high 8-bits of 40-bit address */
  68. __be32 addr_lo; /* low 32-bits of 40-bit address */
  69. } __packed;
  70. __be64 data;
  71. };
  72. __be32 cfg; /* format, offset, length / congestion */
  73. union {
  74. __be32 cmd;
  75. __be32 status;
  76. };
  77. } __aligned(8);
  78. #define QM_FD_FORMAT_SG BIT(31)
  79. #define QM_FD_FORMAT_LONG BIT(30)
  80. #define QM_FD_FORMAT_COMPOUND BIT(29)
  81. #define QM_FD_FORMAT_MASK GENMASK(31, 29)
  82. #define QM_FD_OFF_SHIFT 20
  83. #define QM_FD_OFF_MASK GENMASK(28, 20)
  84. #define QM_FD_LEN_MASK GENMASK(19, 0)
  85. #define QM_FD_LEN_BIG_MASK GENMASK(28, 0)
  86. enum qm_fd_format {
  87. /*
  88. * 'contig' implies a contiguous buffer, whereas 'sg' implies a
  89. * scatter-gather table. 'big' implies a 29-bit length with no offset
  90. * field, otherwise length is 20-bit and offset is 9-bit. 'compound'
  91. * implies a s/g-like table, where each entry itself represents a frame
  92. * (contiguous or scatter-gather) and the 29-bit "length" is
  93. * interpreted purely for congestion calculations, ie. a "congestion
  94. * weight".
  95. */
  96. qm_fd_contig = 0,
  97. qm_fd_contig_big = QM_FD_FORMAT_LONG,
  98. qm_fd_sg = QM_FD_FORMAT_SG,
  99. qm_fd_sg_big = QM_FD_FORMAT_SG | QM_FD_FORMAT_LONG,
  100. qm_fd_compound = QM_FD_FORMAT_COMPOUND
  101. };
  102. static inline dma_addr_t qm_fd_addr(const struct qm_fd *fd)
  103. {
  104. return be64_to_cpu(fd->data) & 0xffffffffffLLU;
  105. }
  106. static inline u64 qm_fd_addr_get64(const struct qm_fd *fd)
  107. {
  108. return be64_to_cpu(fd->data) & 0xffffffffffLLU;
  109. }
  110. static inline void qm_fd_addr_set64(struct qm_fd *fd, u64 addr)
  111. {
  112. fd->addr_hi = upper_32_bits(addr);
  113. fd->addr_lo = cpu_to_be32(lower_32_bits(addr));
  114. }
  115. /*
  116. * The 'format' field indicates the interpretation of the remaining
  117. * 29 bits of the 32-bit word.
  118. * If 'format' is _contig or _sg, 20b length and 9b offset.
  119. * If 'format' is _contig_big or _sg_big, 29b length.
  120. * If 'format' is _compound, 29b "congestion weight".
  121. */
  122. static inline enum qm_fd_format qm_fd_get_format(const struct qm_fd *fd)
  123. {
  124. return be32_to_cpu(fd->cfg) & QM_FD_FORMAT_MASK;
  125. }
  126. static inline int qm_fd_get_offset(const struct qm_fd *fd)
  127. {
  128. return (be32_to_cpu(fd->cfg) & QM_FD_OFF_MASK) >> QM_FD_OFF_SHIFT;
  129. }
  130. static inline int qm_fd_get_length(const struct qm_fd *fd)
  131. {
  132. return be32_to_cpu(fd->cfg) & QM_FD_LEN_MASK;
  133. }
  134. static inline int qm_fd_get_len_big(const struct qm_fd *fd)
  135. {
  136. return be32_to_cpu(fd->cfg) & QM_FD_LEN_BIG_MASK;
  137. }
  138. static inline void qm_fd_set_param(struct qm_fd *fd, enum qm_fd_format fmt,
  139. int off, int len)
  140. {
  141. fd->cfg = cpu_to_be32(fmt | (len & QM_FD_LEN_BIG_MASK) |
  142. ((off << QM_FD_OFF_SHIFT) & QM_FD_OFF_MASK));
  143. }
  144. #define qm_fd_set_contig(fd, off, len) \
  145. qm_fd_set_param(fd, qm_fd_contig, off, len)
  146. #define qm_fd_set_sg(fd, off, len) qm_fd_set_param(fd, qm_fd_sg, off, len)
  147. #define qm_fd_set_contig_big(fd, len) \
  148. qm_fd_set_param(fd, qm_fd_contig_big, 0, len)
  149. #define qm_fd_set_sg_big(fd, len) qm_fd_set_param(fd, qm_fd_sg_big, 0, len)
  150. static inline void qm_fd_clear_fd(struct qm_fd *fd)
  151. {
  152. fd->data = 0;
  153. fd->cfg = 0;
  154. fd->cmd = 0;
  155. }
  156. /* Scatter/Gather table entry */
  157. struct qm_sg_entry {
  158. union {
  159. struct {
  160. u8 __reserved1[3];
  161. u8 addr_hi; /* high 8-bits of 40-bit address */
  162. __be32 addr_lo; /* low 32-bits of 40-bit address */
  163. };
  164. __be64 data;
  165. };
  166. __be32 cfg; /* E bit, F bit, length */
  167. u8 __reserved2;
  168. u8 bpid;
  169. __be16 offset; /* 13-bit, _res[13-15]*/
  170. } __packed;
  171. #define QM_SG_LEN_MASK GENMASK(29, 0)
  172. #define QM_SG_OFF_MASK GENMASK(12, 0)
  173. #define QM_SG_FIN BIT(30)
  174. #define QM_SG_EXT BIT(31)
  175. static inline dma_addr_t qm_sg_addr(const struct qm_sg_entry *sg)
  176. {
  177. return be64_to_cpu(sg->data) & 0xffffffffffLLU;
  178. }
  179. static inline u64 qm_sg_entry_get64(const struct qm_sg_entry *sg)
  180. {
  181. return be64_to_cpu(sg->data) & 0xffffffffffLLU;
  182. }
  183. static inline void qm_sg_entry_set64(struct qm_sg_entry *sg, u64 addr)
  184. {
  185. sg->addr_hi = upper_32_bits(addr);
  186. sg->addr_lo = cpu_to_be32(lower_32_bits(addr));
  187. }
  188. static inline bool qm_sg_entry_is_final(const struct qm_sg_entry *sg)
  189. {
  190. return be32_to_cpu(sg->cfg) & QM_SG_FIN;
  191. }
  192. static inline bool qm_sg_entry_is_ext(const struct qm_sg_entry *sg)
  193. {
  194. return be32_to_cpu(sg->cfg) & QM_SG_EXT;
  195. }
  196. static inline int qm_sg_entry_get_len(const struct qm_sg_entry *sg)
  197. {
  198. return be32_to_cpu(sg->cfg) & QM_SG_LEN_MASK;
  199. }
  200. static inline void qm_sg_entry_set_len(struct qm_sg_entry *sg, int len)
  201. {
  202. sg->cfg = cpu_to_be32(len & QM_SG_LEN_MASK);
  203. }
  204. static inline void qm_sg_entry_set_f(struct qm_sg_entry *sg, int len)
  205. {
  206. sg->cfg = cpu_to_be32(QM_SG_FIN | (len & QM_SG_LEN_MASK));
  207. }
  208. static inline int qm_sg_entry_get_off(const struct qm_sg_entry *sg)
  209. {
  210. return be32_to_cpu(sg->offset) & QM_SG_OFF_MASK;
  211. }
  212. /* "Frame Dequeue Response" */
  213. struct qm_dqrr_entry {
  214. u8 verb;
  215. u8 stat;
  216. __be16 seqnum; /* 15-bit */
  217. u8 tok;
  218. u8 __reserved2[3];
  219. __be32 fqid; /* 24-bit */
  220. __be32 context_b;
  221. struct qm_fd fd;
  222. u8 __reserved4[32];
  223. } __packed;
  224. #define QM_DQRR_VERB_VBIT 0x80
  225. #define QM_DQRR_VERB_MASK 0x7f /* where the verb contains; */
  226. #define QM_DQRR_VERB_FRAME_DEQUEUE 0x60 /* "this format" */
  227. #define QM_DQRR_STAT_FQ_EMPTY 0x80 /* FQ empty */
  228. #define QM_DQRR_STAT_FQ_HELDACTIVE 0x40 /* FQ held active */
  229. #define QM_DQRR_STAT_FQ_FORCEELIGIBLE 0x20 /* FQ was force-eligible'd */
  230. #define QM_DQRR_STAT_FD_VALID 0x10 /* has a non-NULL FD */
  231. #define QM_DQRR_STAT_UNSCHEDULED 0x02 /* Unscheduled dequeue */
  232. #define QM_DQRR_STAT_DQCR_EXPIRED 0x01 /* VDQCR or PDQCR expired*/
  233. /* 'fqid' is a 24-bit field in every h/w descriptor */
  234. #define QM_FQID_MASK GENMASK(23, 0)
  235. #define qm_fqid_set(p, v) ((p)->fqid = cpu_to_be32((v) & QM_FQID_MASK))
  236. #define qm_fqid_get(p) (be32_to_cpu((p)->fqid) & QM_FQID_MASK)
  237. /* "ERN Message Response" */
  238. /* "FQ State Change Notification" */
  239. union qm_mr_entry {
  240. struct {
  241. u8 verb;
  242. u8 __reserved[63];
  243. };
  244. struct {
  245. u8 verb;
  246. u8 dca;
  247. __be16 seqnum;
  248. u8 rc; /* Rej Code: 8-bit */
  249. u8 __reserved[3];
  250. __be32 fqid; /* 24-bit */
  251. __be32 tag;
  252. struct qm_fd fd;
  253. u8 __reserved1[32];
  254. } __packed ern;
  255. struct {
  256. u8 verb;
  257. u8 fqs; /* Frame Queue Status */
  258. u8 __reserved1[6];
  259. __be32 fqid; /* 24-bit */
  260. __be32 context_b;
  261. u8 __reserved2[48];
  262. } __packed fq; /* FQRN/FQRNI/FQRL/FQPN */
  263. };
  264. #define QM_MR_VERB_VBIT 0x80
  265. /*
  266. * ERNs originating from direct-connect portals ("dcern") use 0x20 as a verb
  267. * which would be invalid as a s/w enqueue verb. A s/w ERN can be distinguished
  268. * from the other MR types by noting if the 0x20 bit is unset.
  269. */
  270. #define QM_MR_VERB_TYPE_MASK 0x27
  271. #define QM_MR_VERB_DC_ERN 0x20
  272. #define QM_MR_VERB_FQRN 0x21
  273. #define QM_MR_VERB_FQRNI 0x22
  274. #define QM_MR_VERB_FQRL 0x23
  275. #define QM_MR_VERB_FQPN 0x24
  276. #define QM_MR_RC_MASK 0xf0 /* contains one of; */
  277. #define QM_MR_RC_CGR_TAILDROP 0x00
  278. #define QM_MR_RC_WRED 0x10
  279. #define QM_MR_RC_ERROR 0x20
  280. #define QM_MR_RC_ORPWINDOW_EARLY 0x30
  281. #define QM_MR_RC_ORPWINDOW_LATE 0x40
  282. #define QM_MR_RC_FQ_TAILDROP 0x50
  283. #define QM_MR_RC_ORPWINDOW_RETIRED 0x60
  284. #define QM_MR_RC_ORP_ZERO 0x70
  285. #define QM_MR_FQS_ORLPRESENT 0x02 /* ORL fragments to come */
  286. #define QM_MR_FQS_NOTEMPTY 0x01 /* FQ has enqueued frames */
  287. /*
  288. * An identical structure of FQD fields is present in the "Init FQ" command and
  289. * the "Query FQ" result, it's suctioned out into the "struct qm_fqd" type.
  290. * Within that, the 'stashing' and 'taildrop' pieces are also factored out, the
  291. * latter has two inlines to assist with converting to/from the mant+exp
  292. * representation.
  293. */
  294. struct qm_fqd_stashing {
  295. /* See QM_STASHING_EXCL_<...> */
  296. u8 exclusive;
  297. /* Numbers of cachelines */
  298. u8 cl; /* _res[6-7], as[4-5], ds[2-3], cs[0-1] */
  299. };
  300. struct qm_fqd_oac {
  301. /* "Overhead Accounting Control", see QM_OAC_<...> */
  302. u8 oac; /* oac[6-7], _res[0-5] */
  303. /* Two's-complement value (-128 to +127) */
  304. s8 oal; /* "Overhead Accounting Length" */
  305. };
  306. struct qm_fqd {
  307. /* _res[6-7], orprws[3-5], oa[2], olws[0-1] */
  308. u8 orpc;
  309. u8 cgid;
  310. __be16 fq_ctrl; /* See QM_FQCTRL_<...> */
  311. __be16 dest_wq; /* channel[3-15], wq[0-2] */
  312. __be16 ics_cred; /* 15-bit */
  313. /*
  314. * For "Initialize Frame Queue" commands, the write-enable mask
  315. * determines whether 'td' or 'oac_init' is observed. For query
  316. * commands, this field is always 'td', and 'oac_query' (below) reflects
  317. * the Overhead ACcounting values.
  318. */
  319. union {
  320. __be16 td; /* "Taildrop": _res[13-15], mant[5-12], exp[0-4] */
  321. struct qm_fqd_oac oac_init;
  322. };
  323. __be32 context_b;
  324. union {
  325. /* Treat it as 64-bit opaque */
  326. __be64 opaque;
  327. struct {
  328. __be32 hi;
  329. __be32 lo;
  330. };
  331. /* Treat it as s/w portal stashing config */
  332. /* see "FQD Context_A field used for [...]" */
  333. struct {
  334. struct qm_fqd_stashing stashing;
  335. /*
  336. * 48-bit address of FQ context to
  337. * stash, must be cacheline-aligned
  338. */
  339. __be16 context_hi;
  340. __be32 context_lo;
  341. } __packed;
  342. } context_a;
  343. struct qm_fqd_oac oac_query;
  344. } __packed;
  345. #define QM_FQD_CHAN_OFF 3
  346. #define QM_FQD_WQ_MASK GENMASK(2, 0)
  347. #define QM_FQD_TD_EXP_MASK GENMASK(4, 0)
  348. #define QM_FQD_TD_MANT_OFF 5
  349. #define QM_FQD_TD_MANT_MASK GENMASK(12, 5)
  350. #define QM_FQD_TD_MAX 0xe0000000
  351. #define QM_FQD_TD_MANT_MAX 0xff
  352. #define QM_FQD_OAC_OFF 6
  353. #define QM_FQD_AS_OFF 4
  354. #define QM_FQD_DS_OFF 2
  355. #define QM_FQD_XS_MASK 0x3
  356. /* 64-bit converters for context_hi/lo */
  357. static inline u64 qm_fqd_stashing_get64(const struct qm_fqd *fqd)
  358. {
  359. return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;
  360. }
  361. static inline dma_addr_t qm_fqd_stashing_addr(const struct qm_fqd *fqd)
  362. {
  363. return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;
  364. }
  365. static inline u64 qm_fqd_context_a_get64(const struct qm_fqd *fqd)
  366. {
  367. return qm_fqd_stashing_get64(fqd);
  368. }
  369. static inline void qm_fqd_stashing_set64(struct qm_fqd *fqd, u64 addr)
  370. {
  371. fqd->context_a.context_hi = cpu_to_be16(upper_32_bits(addr));
  372. fqd->context_a.context_lo = cpu_to_be32(lower_32_bits(addr));
  373. }
  374. static inline void qm_fqd_context_a_set64(struct qm_fqd *fqd, u64 addr)
  375. {
  376. fqd->context_a.hi = cpu_to_be32(upper_32_bits(addr));
  377. fqd->context_a.lo = cpu_to_be32(lower_32_bits(addr));
  378. }
  379. /* convert a threshold value into mant+exp representation */
  380. static inline int qm_fqd_set_taildrop(struct qm_fqd *fqd, u32 val,
  381. int roundup)
  382. {
  383. u32 e = 0;
  384. int td, oddbit = 0;
  385. if (val > QM_FQD_TD_MAX)
  386. return -ERANGE;
  387. while (val > QM_FQD_TD_MANT_MAX) {
  388. oddbit = val & 1;
  389. val >>= 1;
  390. e++;
  391. if (roundup && oddbit)
  392. val++;
  393. }
  394. td = (val << QM_FQD_TD_MANT_OFF) & QM_FQD_TD_MANT_MASK;
  395. td |= (e & QM_FQD_TD_EXP_MASK);
  396. fqd->td = cpu_to_be16(td);
  397. return 0;
  398. }
  399. /* and the other direction */
  400. static inline int qm_fqd_get_taildrop(const struct qm_fqd *fqd)
  401. {
  402. int td = be16_to_cpu(fqd->td);
  403. return ((td & QM_FQD_TD_MANT_MASK) >> QM_FQD_TD_MANT_OFF)
  404. << (td & QM_FQD_TD_EXP_MASK);
  405. }
  406. static inline void qm_fqd_set_stashing(struct qm_fqd *fqd, u8 as, u8 ds, u8 cs)
  407. {
  408. struct qm_fqd_stashing *st = &fqd->context_a.stashing;
  409. st->cl = ((as & QM_FQD_XS_MASK) << QM_FQD_AS_OFF) |
  410. ((ds & QM_FQD_XS_MASK) << QM_FQD_DS_OFF) |
  411. (cs & QM_FQD_XS_MASK);
  412. }
  413. static inline u8 qm_fqd_get_stashing(const struct qm_fqd *fqd)
  414. {
  415. return fqd->context_a.stashing.cl;
  416. }
  417. static inline void qm_fqd_set_oac(struct qm_fqd *fqd, u8 val)
  418. {
  419. fqd->oac_init.oac = val << QM_FQD_OAC_OFF;
  420. }
  421. static inline void qm_fqd_set_oal(struct qm_fqd *fqd, s8 val)
  422. {
  423. fqd->oac_init.oal = val;
  424. }
  425. static inline void qm_fqd_set_destwq(struct qm_fqd *fqd, int ch, int wq)
  426. {
  427. fqd->dest_wq = cpu_to_be16((ch << QM_FQD_CHAN_OFF) |
  428. (wq & QM_FQD_WQ_MASK));
  429. }
  430. static inline int qm_fqd_get_chan(const struct qm_fqd *fqd)
  431. {
  432. return be16_to_cpu(fqd->dest_wq) >> QM_FQD_CHAN_OFF;
  433. }
  434. static inline int qm_fqd_get_wq(const struct qm_fqd *fqd)
  435. {
  436. return be16_to_cpu(fqd->dest_wq) & QM_FQD_WQ_MASK;
  437. }
  438. /* See "Frame Queue Descriptor (FQD)" */
  439. /* Frame Queue Descriptor (FQD) field 'fq_ctrl' uses these constants */
  440. #define QM_FQCTRL_MASK 0x07ff /* 'fq_ctrl' flags; */
  441. #define QM_FQCTRL_CGE 0x0400 /* Congestion Group Enable */
  442. #define QM_FQCTRL_TDE 0x0200 /* Tail-Drop Enable */
  443. #define QM_FQCTRL_CTXASTASHING 0x0080 /* Context-A stashing */
  444. #define QM_FQCTRL_CPCSTASH 0x0040 /* CPC Stash Enable */
  445. #define QM_FQCTRL_FORCESFDR 0x0008 /* High-priority SFDRs */
  446. #define QM_FQCTRL_AVOIDBLOCK 0x0004 /* Don't block active */
  447. #define QM_FQCTRL_HOLDACTIVE 0x0002 /* Hold active in portal */
  448. #define QM_FQCTRL_PREFERINCACHE 0x0001 /* Aggressively cache FQD */
  449. #define QM_FQCTRL_LOCKINCACHE QM_FQCTRL_PREFERINCACHE /* older naming */
  450. /* See "FQD Context_A field used for [...] */
  451. /* Frame Queue Descriptor (FQD) field 'CONTEXT_A' uses these constants */
  452. #define QM_STASHING_EXCL_ANNOTATION 0x04
  453. #define QM_STASHING_EXCL_DATA 0x02
  454. #define QM_STASHING_EXCL_CTX 0x01
  455. /* See "Intra Class Scheduling" */
  456. /* FQD field 'OAC' (Overhead ACcounting) uses these constants */
  457. #define QM_OAC_ICS 0x2 /* Accounting for Intra-Class Scheduling */
  458. #define QM_OAC_CG 0x1 /* Accounting for Congestion Groups */
  459. /*
  460. * This struct represents the 32-bit "WR_PARM_[GYR]" parameters in CGR fields
  461. * and associated commands/responses. The WRED parameters are calculated from
  462. * these fields as follows;
  463. * MaxTH = MA * (2 ^ Mn)
  464. * Slope = SA / (2 ^ Sn)
  465. * MaxP = 4 * (Pn + 1)
  466. */
  467. struct qm_cgr_wr_parm {
  468. /* MA[24-31], Mn[19-23], SA[12-18], Sn[6-11], Pn[0-5] */
  469. __be32 word;
  470. };
  471. /*
  472. * This struct represents the 13-bit "CS_THRES" CGR field. In the corresponding
  473. * management commands, this is padded to a 16-bit structure field, so that's
  474. * how we represent it here. The congestion state threshold is calculated from
  475. * these fields as follows;
  476. * CS threshold = TA * (2 ^ Tn)
  477. */
  478. struct qm_cgr_cs_thres {
  479. /* _res[13-15], TA[5-12], Tn[0-4] */
  480. __be16 word;
  481. };
  482. /*
  483. * This identical structure of CGR fields is present in the "Init/Modify CGR"
  484. * commands and the "Query CGR" result. It's suctioned out here into its own
  485. * struct.
  486. */
  487. struct __qm_mc_cgr {
  488. struct qm_cgr_wr_parm wr_parm_g;
  489. struct qm_cgr_wr_parm wr_parm_y;
  490. struct qm_cgr_wr_parm wr_parm_r;
  491. u8 wr_en_g; /* boolean, use QM_CGR_EN */
  492. u8 wr_en_y; /* boolean, use QM_CGR_EN */
  493. u8 wr_en_r; /* boolean, use QM_CGR_EN */
  494. u8 cscn_en; /* boolean, use QM_CGR_EN */
  495. union {
  496. struct {
  497. __be16 cscn_targ_upd_ctrl; /* use QM_CGR_TARG_UDP_* */
  498. __be16 cscn_targ_dcp_low;
  499. };
  500. __be32 cscn_targ; /* use QM_CGR_TARG_* */
  501. };
  502. u8 cstd_en; /* boolean, use QM_CGR_EN */
  503. u8 cs; /* boolean, only used in query response */
  504. struct qm_cgr_cs_thres cs_thres; /* use qm_cgr_cs_thres_set64() */
  505. u8 mode; /* QMAN_CGR_MODE_FRAME not supported in rev1.0 */
  506. } __packed;
  507. #define QM_CGR_EN 0x01 /* For wr_en_*, cscn_en, cstd_en */
  508. #define QM_CGR_TARG_UDP_CTRL_WRITE_BIT 0x8000 /* value written to portal bit*/
  509. #define QM_CGR_TARG_UDP_CTRL_DCP 0x4000 /* 0: SWP, 1: DCP */
  510. #define QM_CGR_TARG_PORTAL(n) (0x80000000 >> (n)) /* s/w portal, 0-9 */
  511. #define QM_CGR_TARG_FMAN0 0x00200000 /* direct-connect portal: fman0 */
  512. #define QM_CGR_TARG_FMAN1 0x00100000 /* : fman1 */
  513. /* Convert CGR thresholds to/from "cs_thres" format */
  514. static inline u64 qm_cgr_cs_thres_get64(const struct qm_cgr_cs_thres *th)
  515. {
  516. int thres = be16_to_cpu(th->word);
  517. return ((thres >> 5) & 0xff) << (thres & 0x1f);
  518. }
  519. static inline int qm_cgr_cs_thres_set64(struct qm_cgr_cs_thres *th, u64 val,
  520. int roundup)
  521. {
  522. u32 e = 0;
  523. int oddbit = 0;
  524. while (val > 0xff) {
  525. oddbit = val & 1;
  526. val >>= 1;
  527. e++;
  528. if (roundup && oddbit)
  529. val++;
  530. }
  531. th->word = cpu_to_be16(((val & 0xff) << 5) | (e & 0x1f));
  532. return 0;
  533. }
  534. /* "Initialize FQ" */
  535. struct qm_mcc_initfq {
  536. u8 __reserved1[2];
  537. __be16 we_mask; /* Write Enable Mask */
  538. __be32 fqid; /* 24-bit */
  539. __be16 count; /* Initialises 'count+1' FQDs */
  540. struct qm_fqd fqd; /* the FQD fields go here */
  541. u8 __reserved2[30];
  542. } __packed;
  543. /* "Initialize/Modify CGR" */
  544. struct qm_mcc_initcgr {
  545. u8 __reserve1[2];
  546. __be16 we_mask; /* Write Enable Mask */
  547. struct __qm_mc_cgr cgr; /* CGR fields */
  548. u8 __reserved2[2];
  549. u8 cgid;
  550. u8 __reserved3[32];
  551. } __packed;
  552. /* INITFQ-specific flags */
  553. #define QM_INITFQ_WE_MASK 0x01ff /* 'Write Enable' flags; */
  554. #define QM_INITFQ_WE_OAC 0x0100
  555. #define QM_INITFQ_WE_ORPC 0x0080
  556. #define QM_INITFQ_WE_CGID 0x0040
  557. #define QM_INITFQ_WE_FQCTRL 0x0020
  558. #define QM_INITFQ_WE_DESTWQ 0x0010
  559. #define QM_INITFQ_WE_ICSCRED 0x0008
  560. #define QM_INITFQ_WE_TDTHRESH 0x0004
  561. #define QM_INITFQ_WE_CONTEXTB 0x0002
  562. #define QM_INITFQ_WE_CONTEXTA 0x0001
  563. /* INITCGR/MODIFYCGR-specific flags */
  564. #define QM_CGR_WE_MASK 0x07ff /* 'Write Enable Mask'; */
  565. #define QM_CGR_WE_WR_PARM_G 0x0400
  566. #define QM_CGR_WE_WR_PARM_Y 0x0200
  567. #define QM_CGR_WE_WR_PARM_R 0x0100
  568. #define QM_CGR_WE_WR_EN_G 0x0080
  569. #define QM_CGR_WE_WR_EN_Y 0x0040
  570. #define QM_CGR_WE_WR_EN_R 0x0020
  571. #define QM_CGR_WE_CSCN_EN 0x0010
  572. #define QM_CGR_WE_CSCN_TARG 0x0008
  573. #define QM_CGR_WE_CSTD_EN 0x0004
  574. #define QM_CGR_WE_CS_THRES 0x0002
  575. #define QM_CGR_WE_MODE 0x0001
  576. #define QMAN_CGR_FLAG_USE_INIT 0x00000001
  577. /* Portal and Frame Queues */
  578. /* Represents a managed portal */
  579. struct qman_portal;
  580. /*
  581. * This object type represents QMan frame queue descriptors (FQD), it is
  582. * cacheline-aligned, and initialised by qman_create_fq(). The structure is
  583. * defined further down.
  584. */
  585. struct qman_fq;
  586. /*
  587. * This object type represents a QMan congestion group, it is defined further
  588. * down.
  589. */
  590. struct qman_cgr;
  591. /*
  592. * This enum, and the callback type that returns it, are used when handling
  593. * dequeued frames via DQRR. Note that for "null" callbacks registered with the
  594. * portal object (for handling dequeues that do not demux because context_b is
  595. * NULL), the return value *MUST* be qman_cb_dqrr_consume.
  596. */
  597. enum qman_cb_dqrr_result {
  598. /* DQRR entry can be consumed */
  599. qman_cb_dqrr_consume,
  600. /* Like _consume, but requests parking - FQ must be held-active */
  601. qman_cb_dqrr_park,
  602. /* Does not consume, for DCA mode only. */
  603. qman_cb_dqrr_defer,
  604. /*
  605. * Stop processing without consuming this ring entry. Exits the current
  606. * qman_p_poll_dqrr() or interrupt-handling, as appropriate. If within
  607. * an interrupt handler, the callback would typically call
  608. * qman_irqsource_remove(QM_PIRQ_DQRI) before returning this value,
  609. * otherwise the interrupt will reassert immediately.
  610. */
  611. qman_cb_dqrr_stop,
  612. /* Like qman_cb_dqrr_stop, but consumes the current entry. */
  613. qman_cb_dqrr_consume_stop
  614. };
  615. typedef enum qman_cb_dqrr_result (*qman_cb_dqrr)(struct qman_portal *qm,
  616. struct qman_fq *fq,
  617. const struct qm_dqrr_entry *dqrr);
  618. /*
  619. * This callback type is used when handling ERNs, FQRNs and FQRLs via MR. They
  620. * are always consumed after the callback returns.
  621. */
  622. typedef void (*qman_cb_mr)(struct qman_portal *qm, struct qman_fq *fq,
  623. const union qm_mr_entry *msg);
  624. /*
  625. * s/w-visible states. Ie. tentatively scheduled + truly scheduled + active +
  626. * held-active + held-suspended are just "sched". Things like "retired" will not
  627. * be assumed until it is complete (ie. QMAN_FQ_STATE_CHANGING is set until
  628. * then, to indicate it's completing and to gate attempts to retry the retire
  629. * command). Note, park commands do not set QMAN_FQ_STATE_CHANGING because it's
  630. * technically impossible in the case of enqueue DCAs (which refer to DQRR ring
  631. * index rather than the FQ that ring entry corresponds to), so repeated park
  632. * commands are allowed (if you're silly enough to try) but won't change FQ
  633. * state, and the resulting park notifications move FQs from "sched" to
  634. * "parked".
  635. */
  636. enum qman_fq_state {
  637. qman_fq_state_oos,
  638. qman_fq_state_parked,
  639. qman_fq_state_sched,
  640. qman_fq_state_retired
  641. };
  642. #define QMAN_FQ_STATE_CHANGING 0x80000000 /* 'state' is changing */
  643. #define QMAN_FQ_STATE_NE 0x40000000 /* retired FQ isn't empty */
  644. #define QMAN_FQ_STATE_ORL 0x20000000 /* retired FQ has ORL */
  645. #define QMAN_FQ_STATE_BLOCKOOS 0xe0000000 /* if any are set, no OOS */
  646. #define QMAN_FQ_STATE_CGR_EN 0x10000000 /* CGR enabled */
  647. #define QMAN_FQ_STATE_VDQCR 0x08000000 /* being volatile dequeued */
  648. /*
  649. * Frame queue objects (struct qman_fq) are stored within memory passed to
  650. * qman_create_fq(), as this allows stashing of caller-provided demux callback
  651. * pointers at no extra cost to stashing of (driver-internal) FQ state. If the
  652. * caller wishes to add per-FQ state and have it benefit from dequeue-stashing,
  653. * they should;
  654. *
  655. * (a) extend the qman_fq structure with their state; eg.
  656. *
  657. * // myfq is allocated and driver_fq callbacks filled in;
  658. * struct my_fq {
  659. * struct qman_fq base;
  660. * int an_extra_field;
  661. * [ ... add other fields to be associated with each FQ ...]
  662. * } *myfq = some_my_fq_allocator();
  663. * struct qman_fq *fq = qman_create_fq(fqid, flags, &myfq->base);
  664. *
  665. * // in a dequeue callback, access extra fields from 'fq' via a cast;
  666. * struct my_fq *myfq = (struct my_fq *)fq;
  667. * do_something_with(myfq->an_extra_field);
  668. * [...]
  669. *
  670. * (b) when and if configuring the FQ for context stashing, specify how ever
  671. * many cachelines are required to stash 'struct my_fq', to accelerate not
  672. * only the QMan driver but the callback as well.
  673. */
  674. struct qman_fq_cb {
  675. qman_cb_dqrr dqrr; /* for dequeued frames */
  676. qman_cb_mr ern; /* for s/w ERNs */
  677. qman_cb_mr fqs; /* frame-queue state changes*/
  678. };
  679. struct qman_fq {
  680. /* Caller of qman_create_fq() provides these demux callbacks */
  681. struct qman_fq_cb cb;
  682. /*
  683. * These are internal to the driver, don't touch. In particular, they
  684. * may change, be removed, or extended (so you shouldn't rely on
  685. * sizeof(qman_fq) being a constant).
  686. */
  687. u32 fqid, idx;
  688. unsigned long flags;
  689. enum qman_fq_state state;
  690. int cgr_groupid;
  691. };
  692. /*
  693. * This callback type is used when handling congestion group entry/exit.
  694. * 'congested' is non-zero on congestion-entry, and zero on congestion-exit.
  695. */
  696. typedef void (*qman_cb_cgr)(struct qman_portal *qm,
  697. struct qman_cgr *cgr, int congested);
  698. struct qman_cgr {
  699. /* Set these prior to qman_create_cgr() */
  700. u32 cgrid; /* 0..255, but u32 to allow specials like -1, 256, etc.*/
  701. qman_cb_cgr cb;
  702. /* These are private to the driver */
  703. u16 chan; /* portal channel this object is created on */
  704. struct list_head node;
  705. };
  706. /* Flags to qman_create_fq() */
  707. #define QMAN_FQ_FLAG_NO_ENQUEUE 0x00000001 /* can't enqueue */
  708. #define QMAN_FQ_FLAG_NO_MODIFY 0x00000002 /* can only enqueue */
  709. #define QMAN_FQ_FLAG_TO_DCPORTAL 0x00000004 /* consumed by CAAM/PME/Fman */
  710. #define QMAN_FQ_FLAG_DYNAMIC_FQID 0x00000020 /* (de)allocate fqid */
  711. /* Flags to qman_init_fq() */
  712. #define QMAN_INITFQ_FLAG_SCHED 0x00000001 /* schedule rather than park */
  713. #define QMAN_INITFQ_FLAG_LOCAL 0x00000004 /* set dest portal */
  714. /* Portal Management */
  715. /**
  716. * qman_p_irqsource_add - add processing sources to be interrupt-driven
  717. * @bits: bitmask of QM_PIRQ_**I processing sources
  718. *
  719. * Adds processing sources that should be interrupt-driven (rather than
  720. * processed via qman_poll_***() functions).
  721. */
  722. void qman_p_irqsource_add(struct qman_portal *p, u32 bits);
  723. /**
  724. * qman_p_irqsource_remove - remove processing sources from being int-driven
  725. * @bits: bitmask of QM_PIRQ_**I processing sources
  726. *
  727. * Removes processing sources from being interrupt-driven, so that they will
  728. * instead be processed via qman_poll_***() functions.
  729. */
  730. void qman_p_irqsource_remove(struct qman_portal *p, u32 bits);
  731. /**
  732. * qman_affine_cpus - return a mask of cpus that have affine portals
  733. */
  734. const cpumask_t *qman_affine_cpus(void);
  735. /**
  736. * qman_affine_channel - return the channel ID of an portal
  737. * @cpu: the cpu whose affine portal is the subject of the query
  738. *
  739. * If @cpu is -1, the affine portal for the current CPU will be used. It is a
  740. * bug to call this function for any value of @cpu (other than -1) that is not a
  741. * member of the mask returned from qman_affine_cpus().
  742. */
  743. u16 qman_affine_channel(int cpu);
  744. /**
  745. * qman_get_affine_portal - return the portal pointer affine to cpu
  746. * @cpu: the cpu whose affine portal is the subject of the query
  747. */
  748. struct qman_portal *qman_get_affine_portal(int cpu);
  749. /**
  750. * qman_p_poll_dqrr - process DQRR (fast-path) entries
  751. * @limit: the maximum number of DQRR entries to process
  752. *
  753. * Use of this function requires that DQRR processing not be interrupt-driven.
  754. * The return value represents the number of DQRR entries processed.
  755. */
  756. int qman_p_poll_dqrr(struct qman_portal *p, unsigned int limit);
  757. /**
  758. * qman_p_static_dequeue_add - Add pool channels to the portal SDQCR
  759. * @pools: bit-mask of pool channels, using QM_SDQCR_CHANNELS_POOL(n)
  760. *
  761. * Adds a set of pool channels to the portal's static dequeue command register
  762. * (SDQCR). The requested pools are limited to those the portal has dequeue
  763. * access to.
  764. */
  765. void qman_p_static_dequeue_add(struct qman_portal *p, u32 pools);
  766. /* FQ management */
  767. /**
  768. * qman_create_fq - Allocates a FQ
  769. * @fqid: the index of the FQD to encapsulate, must be "Out of Service"
  770. * @flags: bit-mask of QMAN_FQ_FLAG_*** options
  771. * @fq: memory for storing the 'fq', with callbacks filled in
  772. *
  773. * Creates a frame queue object for the given @fqid, unless the
  774. * QMAN_FQ_FLAG_DYNAMIC_FQID flag is set in @flags, in which case a FQID is
  775. * dynamically allocated (or the function fails if none are available). Once
  776. * created, the caller should not touch the memory at 'fq' except as extended to
  777. * adjacent memory for user-defined fields (see the definition of "struct
  778. * qman_fq" for more info). NO_MODIFY is only intended for enqueuing to
  779. * pre-existing frame-queues that aren't to be otherwise interfered with, it
  780. * prevents all other modifications to the frame queue. The TO_DCPORTAL flag
  781. * causes the driver to honour any context_b modifications requested in the
  782. * qm_init_fq() API, as this indicates the frame queue will be consumed by a
  783. * direct-connect portal (PME, CAAM, or Fman). When frame queues are consumed by
  784. * software portals, the context_b field is controlled by the driver and can't
  785. * be modified by the caller.
  786. */
  787. int qman_create_fq(u32 fqid, u32 flags, struct qman_fq *fq);
  788. /**
  789. * qman_destroy_fq - Deallocates a FQ
  790. * @fq: the frame queue object to release
  791. *
  792. * The memory for this frame queue object ('fq' provided in qman_create_fq()) is
  793. * not deallocated but the caller regains ownership, to do with as desired. The
  794. * FQ must be in the 'out-of-service' or in the 'parked' state.
  795. */
  796. void qman_destroy_fq(struct qman_fq *fq);
  797. /**
  798. * qman_fq_fqid - Queries the frame queue ID of a FQ object
  799. * @fq: the frame queue object to query
  800. */
  801. u32 qman_fq_fqid(struct qman_fq *fq);
  802. /**
  803. * qman_init_fq - Initialises FQ fields, leaves the FQ "parked" or "scheduled"
  804. * @fq: the frame queue object to modify, must be 'parked' or new.
  805. * @flags: bit-mask of QMAN_INITFQ_FLAG_*** options
  806. * @opts: the FQ-modification settings, as defined in the low-level API
  807. *
  808. * The @opts parameter comes from the low-level portal API. Select
  809. * QMAN_INITFQ_FLAG_SCHED in @flags to cause the frame queue to be scheduled
  810. * rather than parked. NB, @opts can be NULL.
  811. *
  812. * Note that some fields and options within @opts may be ignored or overwritten
  813. * by the driver;
  814. * 1. the 'count' and 'fqid' fields are always ignored (this operation only
  815. * affects one frame queue: @fq).
  816. * 2. the QM_INITFQ_WE_CONTEXTB option of the 'we_mask' field and the associated
  817. * 'fqd' structure's 'context_b' field are sometimes overwritten;
  818. * - if @fq was not created with QMAN_FQ_FLAG_TO_DCPORTAL, then context_b is
  819. * initialised to a value used by the driver for demux.
  820. * - if context_b is initialised for demux, so is context_a in case stashing
  821. * is requested (see item 4).
  822. * (So caller control of context_b is only possible for TO_DCPORTAL frame queue
  823. * objects.)
  824. * 3. if @flags contains QMAN_INITFQ_FLAG_LOCAL, the 'fqd' structure's
  825. * 'dest::channel' field will be overwritten to match the portal used to issue
  826. * the command. If the WE_DESTWQ write-enable bit had already been set by the
  827. * caller, the channel workqueue will be left as-is, otherwise the write-enable
  828. * bit is set and the workqueue is set to a default of 4. If the "LOCAL" flag
  829. * isn't set, the destination channel/workqueue fields and the write-enable bit
  830. * are left as-is.
  831. * 4. if the driver overwrites context_a/b for demux, then if
  832. * QM_INITFQ_WE_CONTEXTA is set, the driver will only overwrite
  833. * context_a.address fields and will leave the stashing fields provided by the
  834. * user alone, otherwise it will zero out the context_a.stashing fields.
  835. */
  836. int qman_init_fq(struct qman_fq *fq, u32 flags, struct qm_mcc_initfq *opts);
  837. /**
  838. * qman_schedule_fq - Schedules a FQ
  839. * @fq: the frame queue object to schedule, must be 'parked'
  840. *
  841. * Schedules the frame queue, which must be Parked, which takes it to
  842. * Tentatively-Scheduled or Truly-Scheduled depending on its fill-level.
  843. */
  844. int qman_schedule_fq(struct qman_fq *fq);
  845. /**
  846. * qman_retire_fq - Retires a FQ
  847. * @fq: the frame queue object to retire
  848. * @flags: FQ flags (QMAN_FQ_STATE*) if retirement completes immediately
  849. *
  850. * Retires the frame queue. This returns zero if it succeeds immediately, +1 if
  851. * the retirement was started asynchronously, otherwise it returns negative for
  852. * failure. When this function returns zero, @flags is set to indicate whether
  853. * the retired FQ is empty and/or whether it has any ORL fragments (to show up
  854. * as ERNs). Otherwise the corresponding flags will be known when a subsequent
  855. * FQRN message shows up on the portal's message ring.
  856. *
  857. * NB, if the retirement is asynchronous (the FQ was in the Truly Scheduled or
  858. * Active state), the completion will be via the message ring as a FQRN - but
  859. * the corresponding callback may occur before this function returns!! Ie. the
  860. * caller should be prepared to accept the callback as the function is called,
  861. * not only once it has returned.
  862. */
  863. int qman_retire_fq(struct qman_fq *fq, u32 *flags);
  864. /**
  865. * qman_oos_fq - Puts a FQ "out of service"
  866. * @fq: the frame queue object to be put out-of-service, must be 'retired'
  867. *
  868. * The frame queue must be retired and empty, and if any order restoration list
  869. * was released as ERNs at the time of retirement, they must all be consumed.
  870. */
  871. int qman_oos_fq(struct qman_fq *fq);
  872. /**
  873. * qman_enqueue - Enqueue a frame to a frame queue
  874. * @fq: the frame queue object to enqueue to
  875. * @fd: a descriptor of the frame to be enqueued
  876. *
  877. * Fills an entry in the EQCR of portal @qm to enqueue the frame described by
  878. * @fd. The descriptor details are copied from @fd to the EQCR entry, the 'pid'
  879. * field is ignored. The return value is non-zero on error, such as ring full.
  880. */
  881. int qman_enqueue(struct qman_fq *fq, const struct qm_fd *fd);
  882. /**
  883. * qman_alloc_fqid_range - Allocate a contiguous range of FQIDs
  884. * @result: is set by the API to the base FQID of the allocated range
  885. * @count: the number of FQIDs required
  886. *
  887. * Returns 0 on success, or a negative error code.
  888. */
  889. int qman_alloc_fqid_range(u32 *result, u32 count);
  890. #define qman_alloc_fqid(result) qman_alloc_fqid_range(result, 1)
  891. /**
  892. * qman_release_fqid - Release the specified frame queue ID
  893. * @fqid: the FQID to be released back to the resource pool
  894. *
  895. * This function can also be used to seed the allocator with
  896. * FQID ranges that it can subsequently allocate from.
  897. * Returns 0 on success, or a negative error code.
  898. */
  899. int qman_release_fqid(u32 fqid);
  900. /* Pool-channel management */
  901. /**
  902. * qman_alloc_pool_range - Allocate a contiguous range of pool-channel IDs
  903. * @result: is set by the API to the base pool-channel ID of the allocated range
  904. * @count: the number of pool-channel IDs required
  905. *
  906. * Returns 0 on success, or a negative error code.
  907. */
  908. int qman_alloc_pool_range(u32 *result, u32 count);
  909. #define qman_alloc_pool(result) qman_alloc_pool_range(result, 1)
  910. /**
  911. * qman_release_pool - Release the specified pool-channel ID
  912. * @id: the pool-chan ID to be released back to the resource pool
  913. *
  914. * This function can also be used to seed the allocator with
  915. * pool-channel ID ranges that it can subsequently allocate from.
  916. * Returns 0 on success, or a negative error code.
  917. */
  918. int qman_release_pool(u32 id);
  919. /* CGR management */
  920. /**
  921. * qman_create_cgr - Register a congestion group object
  922. * @cgr: the 'cgr' object, with fields filled in
  923. * @flags: QMAN_CGR_FLAG_* values
  924. * @opts: optional state of CGR settings
  925. *
  926. * Registers this object to receiving congestion entry/exit callbacks on the
  927. * portal affine to the cpu portal on which this API is executed. If opts is
  928. * NULL then only the callback (cgr->cb) function is registered. If @flags
  929. * contains QMAN_CGR_FLAG_USE_INIT, then an init hw command (which will reset
  930. * any unspecified parameters) will be used rather than a modify hw hardware
  931. * (which only modifies the specified parameters).
  932. */
  933. int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
  934. struct qm_mcc_initcgr *opts);
  935. /**
  936. * qman_delete_cgr - Deregisters a congestion group object
  937. * @cgr: the 'cgr' object to deregister
  938. *
  939. * "Unplugs" this CGR object from the portal affine to the cpu on which this API
  940. * is executed. This must be excuted on the same affine portal on which it was
  941. * created.
  942. */
  943. int qman_delete_cgr(struct qman_cgr *cgr);
  944. /**
  945. * qman_delete_cgr_safe - Deregisters a congestion group object from any CPU
  946. * @cgr: the 'cgr' object to deregister
  947. *
  948. * This will select the proper CPU and run there qman_delete_cgr().
  949. */
  950. void qman_delete_cgr_safe(struct qman_cgr *cgr);
  951. /**
  952. * qman_query_cgr_congested - Queries CGR's congestion status
  953. * @cgr: the 'cgr' object to query
  954. * @result: returns 'cgr's congestion status, 1 (true) if congested
  955. */
  956. int qman_query_cgr_congested(struct qman_cgr *cgr, bool *result);
  957. /**
  958. * qman_alloc_cgrid_range - Allocate a contiguous range of CGR IDs
  959. * @result: is set by the API to the base CGR ID of the allocated range
  960. * @count: the number of CGR IDs required
  961. *
  962. * Returns 0 on success, or a negative error code.
  963. */
  964. int qman_alloc_cgrid_range(u32 *result, u32 count);
  965. #define qman_alloc_cgrid(result) qman_alloc_cgrid_range(result, 1)
  966. /**
  967. * qman_release_cgrid - Release the specified CGR ID
  968. * @id: the CGR ID to be released back to the resource pool
  969. *
  970. * This function can also be used to seed the allocator with
  971. * CGR ID ranges that it can subsequently allocate from.
  972. * Returns 0 on success, or a negative error code.
  973. */
  974. int qman_release_cgrid(u32 id);
  975. #endif /* __FSL_QMAN_H */