qman.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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. u16 seqnum; /* 15-bit */
  217. u8 tok;
  218. u8 __reserved2[3];
  219. u32 fqid; /* 24-bit */
  220. u32 contextB;
  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. /* "ERN Message Response" */
  234. /* "FQ State Change Notification" */
  235. union qm_mr_entry {
  236. struct {
  237. u8 verb;
  238. u8 __reserved[63];
  239. };
  240. struct {
  241. u8 verb;
  242. u8 dca;
  243. u16 seqnum;
  244. u8 rc; /* Rej Code: 8-bit */
  245. u8 orp_hi; /* ORP: 24-bit */
  246. u16 orp_lo;
  247. u32 fqid; /* 24-bit */
  248. u32 tag;
  249. struct qm_fd fd;
  250. u8 __reserved1[32];
  251. } __packed ern;
  252. struct {
  253. u8 verb;
  254. u8 fqs; /* Frame Queue Status */
  255. u8 __reserved1[6];
  256. u32 fqid; /* 24-bit */
  257. u32 contextB;
  258. u8 __reserved2[48];
  259. } __packed fq; /* FQRN/FQRNI/FQRL/FQPN */
  260. };
  261. #define QM_MR_VERB_VBIT 0x80
  262. /*
  263. * ERNs originating from direct-connect portals ("dcern") use 0x20 as a verb
  264. * which would be invalid as a s/w enqueue verb. A s/w ERN can be distinguished
  265. * from the other MR types by noting if the 0x20 bit is unset.
  266. */
  267. #define QM_MR_VERB_TYPE_MASK 0x27
  268. #define QM_MR_VERB_DC_ERN 0x20
  269. #define QM_MR_VERB_FQRN 0x21
  270. #define QM_MR_VERB_FQRNI 0x22
  271. #define QM_MR_VERB_FQRL 0x23
  272. #define QM_MR_VERB_FQPN 0x24
  273. #define QM_MR_RC_MASK 0xf0 /* contains one of; */
  274. #define QM_MR_RC_CGR_TAILDROP 0x00
  275. #define QM_MR_RC_WRED 0x10
  276. #define QM_MR_RC_ERROR 0x20
  277. #define QM_MR_RC_ORPWINDOW_EARLY 0x30
  278. #define QM_MR_RC_ORPWINDOW_LATE 0x40
  279. #define QM_MR_RC_FQ_TAILDROP 0x50
  280. #define QM_MR_RC_ORPWINDOW_RETIRED 0x60
  281. #define QM_MR_RC_ORP_ZERO 0x70
  282. #define QM_MR_FQS_ORLPRESENT 0x02 /* ORL fragments to come */
  283. #define QM_MR_FQS_NOTEMPTY 0x01 /* FQ has enqueued frames */
  284. /*
  285. * An identical structure of FQD fields is present in the "Init FQ" command and
  286. * the "Query FQ" result, it's suctioned out into the "struct qm_fqd" type.
  287. * Within that, the 'stashing' and 'taildrop' pieces are also factored out, the
  288. * latter has two inlines to assist with converting to/from the mant+exp
  289. * representation.
  290. */
  291. struct qm_fqd_stashing {
  292. /* See QM_STASHING_EXCL_<...> */
  293. u8 exclusive;
  294. /* Numbers of cachelines */
  295. u8 cl; /* _res[6-7], as[4-5], ds[2-3], cs[0-1] */
  296. };
  297. struct qm_fqd_oac {
  298. /* "Overhead Accounting Control", see QM_OAC_<...> */
  299. u8 oac; /* oac[6-7], _res[0-5] */
  300. /* Two's-complement value (-128 to +127) */
  301. s8 oal; /* "Overhead Accounting Length" */
  302. };
  303. struct qm_fqd {
  304. /* _res[6-7], orprws[3-5], oa[2], olws[0-1] */
  305. u8 orpc;
  306. u8 cgid;
  307. __be16 fq_ctrl; /* See QM_FQCTRL_<...> */
  308. __be16 dest_wq; /* channel[3-15], wq[0-2] */
  309. __be16 ics_cred; /* 15-bit */
  310. /*
  311. * For "Initialize Frame Queue" commands, the write-enable mask
  312. * determines whether 'td' or 'oac_init' is observed. For query
  313. * commands, this field is always 'td', and 'oac_query' (below) reflects
  314. * the Overhead ACcounting values.
  315. */
  316. union {
  317. __be16 td; /* "Taildrop": _res[13-15], mant[5-12], exp[0-4] */
  318. struct qm_fqd_oac oac_init;
  319. };
  320. __be32 context_b;
  321. union {
  322. /* Treat it as 64-bit opaque */
  323. __be64 opaque;
  324. struct {
  325. __be32 hi;
  326. __be32 lo;
  327. };
  328. /* Treat it as s/w portal stashing config */
  329. /* see "FQD Context_A field used for [...]" */
  330. struct {
  331. struct qm_fqd_stashing stashing;
  332. /*
  333. * 48-bit address of FQ context to
  334. * stash, must be cacheline-aligned
  335. */
  336. __be16 context_hi;
  337. __be32 context_lo;
  338. } __packed;
  339. } context_a;
  340. struct qm_fqd_oac oac_query;
  341. } __packed;
  342. #define QM_FQD_CHAN_OFF 3
  343. #define QM_FQD_WQ_MASK GENMASK(2, 0)
  344. #define QM_FQD_TD_EXP_MASK GENMASK(4, 0)
  345. #define QM_FQD_TD_MANT_OFF 5
  346. #define QM_FQD_TD_MANT_MASK GENMASK(12, 5)
  347. #define QM_FQD_TD_MAX 0xe0000000
  348. #define QM_FQD_TD_MANT_MAX 0xff
  349. #define QM_FQD_OAC_OFF 6
  350. #define QM_FQD_AS_OFF 4
  351. #define QM_FQD_DS_OFF 2
  352. #define QM_FQD_XS_MASK 0x3
  353. /* 64-bit converters for context_hi/lo */
  354. static inline u64 qm_fqd_stashing_get64(const struct qm_fqd *fqd)
  355. {
  356. return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;
  357. }
  358. static inline dma_addr_t qm_fqd_stashing_addr(const struct qm_fqd *fqd)
  359. {
  360. return be64_to_cpu(fqd->context_a.opaque) & 0xffffffffffffULL;
  361. }
  362. static inline u64 qm_fqd_context_a_get64(const struct qm_fqd *fqd)
  363. {
  364. return qm_fqd_stashing_get64(fqd);
  365. }
  366. static inline void qm_fqd_stashing_set64(struct qm_fqd *fqd, u64 addr)
  367. {
  368. fqd->context_a.context_hi = upper_32_bits(addr);
  369. fqd->context_a.context_lo = lower_32_bits(addr);
  370. }
  371. static inline void qm_fqd_context_a_set64(struct qm_fqd *fqd, u64 addr)
  372. {
  373. fqd->context_a.hi = cpu_to_be16(upper_32_bits(addr));
  374. fqd->context_a.lo = cpu_to_be32(lower_32_bits(addr));
  375. }
  376. /* convert a threshold value into mant+exp representation */
  377. static inline int qm_fqd_set_taildrop(struct qm_fqd *fqd, u32 val,
  378. int roundup)
  379. {
  380. u32 e = 0;
  381. int td, oddbit = 0;
  382. if (val > QM_FQD_TD_MAX)
  383. return -ERANGE;
  384. while (val > QM_FQD_TD_MANT_MAX) {
  385. oddbit = val & 1;
  386. val >>= 1;
  387. e++;
  388. if (roundup && oddbit)
  389. val++;
  390. }
  391. td = (val << QM_FQD_TD_MANT_OFF) & QM_FQD_TD_MANT_MASK;
  392. td |= (e & QM_FQD_TD_EXP_MASK);
  393. fqd->td = cpu_to_be16(td);
  394. return 0;
  395. }
  396. /* and the other direction */
  397. static inline int qm_fqd_get_taildrop(const struct qm_fqd *fqd)
  398. {
  399. int td = be16_to_cpu(fqd->td);
  400. return ((td & QM_FQD_TD_MANT_MASK) >> QM_FQD_TD_MANT_OFF)
  401. << (td & QM_FQD_TD_EXP_MASK);
  402. }
  403. static inline void qm_fqd_set_stashing(struct qm_fqd *fqd, u8 as, u8 ds, u8 cs)
  404. {
  405. struct qm_fqd_stashing *st = &fqd->context_a.stashing;
  406. st->cl = ((as & QM_FQD_XS_MASK) << QM_FQD_AS_OFF) |
  407. ((ds & QM_FQD_XS_MASK) << QM_FQD_DS_OFF) |
  408. (cs & QM_FQD_XS_MASK);
  409. }
  410. static inline u8 qm_fqd_get_stashing(const struct qm_fqd *fqd)
  411. {
  412. return fqd->context_a.stashing.cl;
  413. }
  414. static inline void qm_fqd_set_oac(struct qm_fqd *fqd, u8 val)
  415. {
  416. fqd->oac_init.oac = val << QM_FQD_OAC_OFF;
  417. }
  418. static inline void qm_fqd_set_oal(struct qm_fqd *fqd, s8 val)
  419. {
  420. fqd->oac_init.oal = val;
  421. }
  422. static inline void qm_fqd_set_destwq(struct qm_fqd *fqd, int ch, int wq)
  423. {
  424. fqd->dest_wq = cpu_to_be16((ch << QM_FQD_CHAN_OFF) |
  425. (wq & QM_FQD_WQ_MASK));
  426. }
  427. static inline int qm_fqd_get_chan(const struct qm_fqd *fqd)
  428. {
  429. return be16_to_cpu(fqd->dest_wq) >> QM_FQD_CHAN_OFF;
  430. }
  431. static inline int qm_fqd_get_wq(const struct qm_fqd *fqd)
  432. {
  433. return be16_to_cpu(fqd->dest_wq) & QM_FQD_WQ_MASK;
  434. }
  435. /* See "Frame Queue Descriptor (FQD)" */
  436. /* Frame Queue Descriptor (FQD) field 'fq_ctrl' uses these constants */
  437. #define QM_FQCTRL_MASK 0x07ff /* 'fq_ctrl' flags; */
  438. #define QM_FQCTRL_CGE 0x0400 /* Congestion Group Enable */
  439. #define QM_FQCTRL_TDE 0x0200 /* Tail-Drop Enable */
  440. #define QM_FQCTRL_CTXASTASHING 0x0080 /* Context-A stashing */
  441. #define QM_FQCTRL_CPCSTASH 0x0040 /* CPC Stash Enable */
  442. #define QM_FQCTRL_FORCESFDR 0x0008 /* High-priority SFDRs */
  443. #define QM_FQCTRL_AVOIDBLOCK 0x0004 /* Don't block active */
  444. #define QM_FQCTRL_HOLDACTIVE 0x0002 /* Hold active in portal */
  445. #define QM_FQCTRL_PREFERINCACHE 0x0001 /* Aggressively cache FQD */
  446. #define QM_FQCTRL_LOCKINCACHE QM_FQCTRL_PREFERINCACHE /* older naming */
  447. /* See "FQD Context_A field used for [...] */
  448. /* Frame Queue Descriptor (FQD) field 'CONTEXT_A' uses these constants */
  449. #define QM_STASHING_EXCL_ANNOTATION 0x04
  450. #define QM_STASHING_EXCL_DATA 0x02
  451. #define QM_STASHING_EXCL_CTX 0x01
  452. /* See "Intra Class Scheduling" */
  453. /* FQD field 'OAC' (Overhead ACcounting) uses these constants */
  454. #define QM_OAC_ICS 0x2 /* Accounting for Intra-Class Scheduling */
  455. #define QM_OAC_CG 0x1 /* Accounting for Congestion Groups */
  456. /*
  457. * This struct represents the 32-bit "WR_PARM_[GYR]" parameters in CGR fields
  458. * and associated commands/responses. The WRED parameters are calculated from
  459. * these fields as follows;
  460. * MaxTH = MA * (2 ^ Mn)
  461. * Slope = SA / (2 ^ Sn)
  462. * MaxP = 4 * (Pn + 1)
  463. */
  464. struct qm_cgr_wr_parm {
  465. /* MA[24-31], Mn[19-23], SA[12-18], Sn[6-11], Pn[0-5] */
  466. u32 word;
  467. };
  468. /*
  469. * This struct represents the 13-bit "CS_THRES" CGR field. In the corresponding
  470. * management commands, this is padded to a 16-bit structure field, so that's
  471. * how we represent it here. The congestion state threshold is calculated from
  472. * these fields as follows;
  473. * CS threshold = TA * (2 ^ Tn)
  474. */
  475. struct qm_cgr_cs_thres {
  476. /* _res[13-15], TA[5-12], Tn[0-4] */
  477. u16 word;
  478. };
  479. /*
  480. * This identical structure of CGR fields is present in the "Init/Modify CGR"
  481. * commands and the "Query CGR" result. It's suctioned out here into its own
  482. * struct.
  483. */
  484. struct __qm_mc_cgr {
  485. struct qm_cgr_wr_parm wr_parm_g;
  486. struct qm_cgr_wr_parm wr_parm_y;
  487. struct qm_cgr_wr_parm wr_parm_r;
  488. u8 wr_en_g; /* boolean, use QM_CGR_EN */
  489. u8 wr_en_y; /* boolean, use QM_CGR_EN */
  490. u8 wr_en_r; /* boolean, use QM_CGR_EN */
  491. u8 cscn_en; /* boolean, use QM_CGR_EN */
  492. union {
  493. struct {
  494. u16 cscn_targ_upd_ctrl; /* use QM_CSCN_TARG_UDP_ */
  495. u16 cscn_targ_dcp_low; /* CSCN_TARG_DCP low-16bits */
  496. };
  497. u32 cscn_targ; /* use QM_CGR_TARG_* */
  498. };
  499. u8 cstd_en; /* boolean, use QM_CGR_EN */
  500. u8 cs; /* boolean, only used in query response */
  501. struct qm_cgr_cs_thres cs_thres; /* use qm_cgr_cs_thres_set64() */
  502. u8 mode; /* QMAN_CGR_MODE_FRAME not supported in rev1.0 */
  503. } __packed;
  504. #define QM_CGR_EN 0x01 /* For wr_en_*, cscn_en, cstd_en */
  505. #define QM_CGR_TARG_UDP_CTRL_WRITE_BIT 0x8000 /* value written to portal bit*/
  506. #define QM_CGR_TARG_UDP_CTRL_DCP 0x4000 /* 0: SWP, 1: DCP */
  507. #define QM_CGR_TARG_PORTAL(n) (0x80000000 >> (n)) /* s/w portal, 0-9 */
  508. #define QM_CGR_TARG_FMAN0 0x00200000 /* direct-connect portal: fman0 */
  509. #define QM_CGR_TARG_FMAN1 0x00100000 /* : fman1 */
  510. /* Convert CGR thresholds to/from "cs_thres" format */
  511. static inline u64 qm_cgr_cs_thres_get64(const struct qm_cgr_cs_thres *th)
  512. {
  513. return ((th->word >> 5) & 0xff) << (th->word & 0x1f);
  514. }
  515. static inline int qm_cgr_cs_thres_set64(struct qm_cgr_cs_thres *th, u64 val,
  516. int roundup)
  517. {
  518. u32 e = 0;
  519. int oddbit = 0;
  520. while (val > 0xff) {
  521. oddbit = val & 1;
  522. val >>= 1;
  523. e++;
  524. if (roundup && oddbit)
  525. val++;
  526. }
  527. th->word = ((val & 0xff) << 5) | (e & 0x1f);
  528. return 0;
  529. }
  530. /* "Initialize FQ" */
  531. struct qm_mcc_initfq {
  532. u8 __reserved1[2];
  533. u16 we_mask; /* Write Enable Mask */
  534. u32 fqid; /* 24-bit */
  535. u16 count; /* Initialises 'count+1' FQDs */
  536. struct qm_fqd fqd; /* the FQD fields go here */
  537. u8 __reserved2[30];
  538. } __packed;
  539. /* "Initialize/Modify CGR" */
  540. struct qm_mcc_initcgr {
  541. u8 __reserve1[2];
  542. u16 we_mask; /* Write Enable Mask */
  543. struct __qm_mc_cgr cgr; /* CGR fields */
  544. u8 __reserved2[2];
  545. u8 cgid;
  546. u8 __reserved3[32];
  547. } __packed;
  548. /* INITFQ-specific flags */
  549. #define QM_INITFQ_WE_MASK 0x01ff /* 'Write Enable' flags; */
  550. #define QM_INITFQ_WE_OAC 0x0100
  551. #define QM_INITFQ_WE_ORPC 0x0080
  552. #define QM_INITFQ_WE_CGID 0x0040
  553. #define QM_INITFQ_WE_FQCTRL 0x0020
  554. #define QM_INITFQ_WE_DESTWQ 0x0010
  555. #define QM_INITFQ_WE_ICSCRED 0x0008
  556. #define QM_INITFQ_WE_TDTHRESH 0x0004
  557. #define QM_INITFQ_WE_CONTEXTB 0x0002
  558. #define QM_INITFQ_WE_CONTEXTA 0x0001
  559. /* INITCGR/MODIFYCGR-specific flags */
  560. #define QM_CGR_WE_MASK 0x07ff /* 'Write Enable Mask'; */
  561. #define QM_CGR_WE_WR_PARM_G 0x0400
  562. #define QM_CGR_WE_WR_PARM_Y 0x0200
  563. #define QM_CGR_WE_WR_PARM_R 0x0100
  564. #define QM_CGR_WE_WR_EN_G 0x0080
  565. #define QM_CGR_WE_WR_EN_Y 0x0040
  566. #define QM_CGR_WE_WR_EN_R 0x0020
  567. #define QM_CGR_WE_CSCN_EN 0x0010
  568. #define QM_CGR_WE_CSCN_TARG 0x0008
  569. #define QM_CGR_WE_CSTD_EN 0x0004
  570. #define QM_CGR_WE_CS_THRES 0x0002
  571. #define QM_CGR_WE_MODE 0x0001
  572. #define QMAN_CGR_FLAG_USE_INIT 0x00000001
  573. /* Portal and Frame Queues */
  574. /* Represents a managed portal */
  575. struct qman_portal;
  576. /*
  577. * This object type represents QMan frame queue descriptors (FQD), it is
  578. * cacheline-aligned, and initialised by qman_create_fq(). The structure is
  579. * defined further down.
  580. */
  581. struct qman_fq;
  582. /*
  583. * This object type represents a QMan congestion group, it is defined further
  584. * down.
  585. */
  586. struct qman_cgr;
  587. /*
  588. * This enum, and the callback type that returns it, are used when handling
  589. * dequeued frames via DQRR. Note that for "null" callbacks registered with the
  590. * portal object (for handling dequeues that do not demux because contextB is
  591. * NULL), the return value *MUST* be qman_cb_dqrr_consume.
  592. */
  593. enum qman_cb_dqrr_result {
  594. /* DQRR entry can be consumed */
  595. qman_cb_dqrr_consume,
  596. /* Like _consume, but requests parking - FQ must be held-active */
  597. qman_cb_dqrr_park,
  598. /* Does not consume, for DCA mode only. */
  599. qman_cb_dqrr_defer,
  600. /*
  601. * Stop processing without consuming this ring entry. Exits the current
  602. * qman_p_poll_dqrr() or interrupt-handling, as appropriate. If within
  603. * an interrupt handler, the callback would typically call
  604. * qman_irqsource_remove(QM_PIRQ_DQRI) before returning this value,
  605. * otherwise the interrupt will reassert immediately.
  606. */
  607. qman_cb_dqrr_stop,
  608. /* Like qman_cb_dqrr_stop, but consumes the current entry. */
  609. qman_cb_dqrr_consume_stop
  610. };
  611. typedef enum qman_cb_dqrr_result (*qman_cb_dqrr)(struct qman_portal *qm,
  612. struct qman_fq *fq,
  613. const struct qm_dqrr_entry *dqrr);
  614. /*
  615. * This callback type is used when handling ERNs, FQRNs and FQRLs via MR. They
  616. * are always consumed after the callback returns.
  617. */
  618. typedef void (*qman_cb_mr)(struct qman_portal *qm, struct qman_fq *fq,
  619. const union qm_mr_entry *msg);
  620. /*
  621. * s/w-visible states. Ie. tentatively scheduled + truly scheduled + active +
  622. * held-active + held-suspended are just "sched". Things like "retired" will not
  623. * be assumed until it is complete (ie. QMAN_FQ_STATE_CHANGING is set until
  624. * then, to indicate it's completing and to gate attempts to retry the retire
  625. * command). Note, park commands do not set QMAN_FQ_STATE_CHANGING because it's
  626. * technically impossible in the case of enqueue DCAs (which refer to DQRR ring
  627. * index rather than the FQ that ring entry corresponds to), so repeated park
  628. * commands are allowed (if you're silly enough to try) but won't change FQ
  629. * state, and the resulting park notifications move FQs from "sched" to
  630. * "parked".
  631. */
  632. enum qman_fq_state {
  633. qman_fq_state_oos,
  634. qman_fq_state_parked,
  635. qman_fq_state_sched,
  636. qman_fq_state_retired
  637. };
  638. #define QMAN_FQ_STATE_CHANGING 0x80000000 /* 'state' is changing */
  639. #define QMAN_FQ_STATE_NE 0x40000000 /* retired FQ isn't empty */
  640. #define QMAN_FQ_STATE_ORL 0x20000000 /* retired FQ has ORL */
  641. #define QMAN_FQ_STATE_BLOCKOOS 0xe0000000 /* if any are set, no OOS */
  642. #define QMAN_FQ_STATE_CGR_EN 0x10000000 /* CGR enabled */
  643. #define QMAN_FQ_STATE_VDQCR 0x08000000 /* being volatile dequeued */
  644. /*
  645. * Frame queue objects (struct qman_fq) are stored within memory passed to
  646. * qman_create_fq(), as this allows stashing of caller-provided demux callback
  647. * pointers at no extra cost to stashing of (driver-internal) FQ state. If the
  648. * caller wishes to add per-FQ state and have it benefit from dequeue-stashing,
  649. * they should;
  650. *
  651. * (a) extend the qman_fq structure with their state; eg.
  652. *
  653. * // myfq is allocated and driver_fq callbacks filled in;
  654. * struct my_fq {
  655. * struct qman_fq base;
  656. * int an_extra_field;
  657. * [ ... add other fields to be associated with each FQ ...]
  658. * } *myfq = some_my_fq_allocator();
  659. * struct qman_fq *fq = qman_create_fq(fqid, flags, &myfq->base);
  660. *
  661. * // in a dequeue callback, access extra fields from 'fq' via a cast;
  662. * struct my_fq *myfq = (struct my_fq *)fq;
  663. * do_something_with(myfq->an_extra_field);
  664. * [...]
  665. *
  666. * (b) when and if configuring the FQ for context stashing, specify how ever
  667. * many cachelines are required to stash 'struct my_fq', to accelerate not
  668. * only the QMan driver but the callback as well.
  669. */
  670. struct qman_fq_cb {
  671. qman_cb_dqrr dqrr; /* for dequeued frames */
  672. qman_cb_mr ern; /* for s/w ERNs */
  673. qman_cb_mr fqs; /* frame-queue state changes*/
  674. };
  675. struct qman_fq {
  676. /* Caller of qman_create_fq() provides these demux callbacks */
  677. struct qman_fq_cb cb;
  678. /*
  679. * These are internal to the driver, don't touch. In particular, they
  680. * may change, be removed, or extended (so you shouldn't rely on
  681. * sizeof(qman_fq) being a constant).
  682. */
  683. u32 fqid, idx;
  684. unsigned long flags;
  685. enum qman_fq_state state;
  686. int cgr_groupid;
  687. };
  688. /*
  689. * This callback type is used when handling congestion group entry/exit.
  690. * 'congested' is non-zero on congestion-entry, and zero on congestion-exit.
  691. */
  692. typedef void (*qman_cb_cgr)(struct qman_portal *qm,
  693. struct qman_cgr *cgr, int congested);
  694. struct qman_cgr {
  695. /* Set these prior to qman_create_cgr() */
  696. u32 cgrid; /* 0..255, but u32 to allow specials like -1, 256, etc.*/
  697. qman_cb_cgr cb;
  698. /* These are private to the driver */
  699. u16 chan; /* portal channel this object is created on */
  700. struct list_head node;
  701. };
  702. /* Flags to qman_create_fq() */
  703. #define QMAN_FQ_FLAG_NO_ENQUEUE 0x00000001 /* can't enqueue */
  704. #define QMAN_FQ_FLAG_NO_MODIFY 0x00000002 /* can only enqueue */
  705. #define QMAN_FQ_FLAG_TO_DCPORTAL 0x00000004 /* consumed by CAAM/PME/Fman */
  706. #define QMAN_FQ_FLAG_DYNAMIC_FQID 0x00000020 /* (de)allocate fqid */
  707. /* Flags to qman_init_fq() */
  708. #define QMAN_INITFQ_FLAG_SCHED 0x00000001 /* schedule rather than park */
  709. #define QMAN_INITFQ_FLAG_LOCAL 0x00000004 /* set dest portal */
  710. /* Portal Management */
  711. /**
  712. * qman_p_irqsource_add - add processing sources to be interrupt-driven
  713. * @bits: bitmask of QM_PIRQ_**I processing sources
  714. *
  715. * Adds processing sources that should be interrupt-driven (rather than
  716. * processed via qman_poll_***() functions).
  717. */
  718. void qman_p_irqsource_add(struct qman_portal *p, u32 bits);
  719. /**
  720. * qman_p_irqsource_remove - remove processing sources from being int-driven
  721. * @bits: bitmask of QM_PIRQ_**I processing sources
  722. *
  723. * Removes processing sources from being interrupt-driven, so that they will
  724. * instead be processed via qman_poll_***() functions.
  725. */
  726. void qman_p_irqsource_remove(struct qman_portal *p, u32 bits);
  727. /**
  728. * qman_affine_cpus - return a mask of cpus that have affine portals
  729. */
  730. const cpumask_t *qman_affine_cpus(void);
  731. /**
  732. * qman_affine_channel - return the channel ID of an portal
  733. * @cpu: the cpu whose affine portal is the subject of the query
  734. *
  735. * If @cpu is -1, the affine portal for the current CPU will be used. It is a
  736. * bug to call this function for any value of @cpu (other than -1) that is not a
  737. * member of the mask returned from qman_affine_cpus().
  738. */
  739. u16 qman_affine_channel(int cpu);
  740. /**
  741. * qman_get_affine_portal - return the portal pointer affine to cpu
  742. * @cpu: the cpu whose affine portal is the subject of the query
  743. */
  744. struct qman_portal *qman_get_affine_portal(int cpu);
  745. /**
  746. * qman_p_poll_dqrr - process DQRR (fast-path) entries
  747. * @limit: the maximum number of DQRR entries to process
  748. *
  749. * Use of this function requires that DQRR processing not be interrupt-driven.
  750. * The return value represents the number of DQRR entries processed.
  751. */
  752. int qman_p_poll_dqrr(struct qman_portal *p, unsigned int limit);
  753. /**
  754. * qman_p_static_dequeue_add - Add pool channels to the portal SDQCR
  755. * @pools: bit-mask of pool channels, using QM_SDQCR_CHANNELS_POOL(n)
  756. *
  757. * Adds a set of pool channels to the portal's static dequeue command register
  758. * (SDQCR). The requested pools are limited to those the portal has dequeue
  759. * access to.
  760. */
  761. void qman_p_static_dequeue_add(struct qman_portal *p, u32 pools);
  762. /* FQ management */
  763. /**
  764. * qman_create_fq - Allocates a FQ
  765. * @fqid: the index of the FQD to encapsulate, must be "Out of Service"
  766. * @flags: bit-mask of QMAN_FQ_FLAG_*** options
  767. * @fq: memory for storing the 'fq', with callbacks filled in
  768. *
  769. * Creates a frame queue object for the given @fqid, unless the
  770. * QMAN_FQ_FLAG_DYNAMIC_FQID flag is set in @flags, in which case a FQID is
  771. * dynamically allocated (or the function fails if none are available). Once
  772. * created, the caller should not touch the memory at 'fq' except as extended to
  773. * adjacent memory for user-defined fields (see the definition of "struct
  774. * qman_fq" for more info). NO_MODIFY is only intended for enqueuing to
  775. * pre-existing frame-queues that aren't to be otherwise interfered with, it
  776. * prevents all other modifications to the frame queue. The TO_DCPORTAL flag
  777. * causes the driver to honour any contextB modifications requested in the
  778. * qm_init_fq() API, as this indicates the frame queue will be consumed by a
  779. * direct-connect portal (PME, CAAM, or Fman). When frame queues are consumed by
  780. * software portals, the contextB field is controlled by the driver and can't be
  781. * modified by the caller.
  782. */
  783. int qman_create_fq(u32 fqid, u32 flags, struct qman_fq *fq);
  784. /**
  785. * qman_destroy_fq - Deallocates a FQ
  786. * @fq: the frame queue object to release
  787. *
  788. * The memory for this frame queue object ('fq' provided in qman_create_fq()) is
  789. * not deallocated but the caller regains ownership, to do with as desired. The
  790. * FQ must be in the 'out-of-service' or in the 'parked' state.
  791. */
  792. void qman_destroy_fq(struct qman_fq *fq);
  793. /**
  794. * qman_fq_fqid - Queries the frame queue ID of a FQ object
  795. * @fq: the frame queue object to query
  796. */
  797. u32 qman_fq_fqid(struct qman_fq *fq);
  798. /**
  799. * qman_init_fq - Initialises FQ fields, leaves the FQ "parked" or "scheduled"
  800. * @fq: the frame queue object to modify, must be 'parked' or new.
  801. * @flags: bit-mask of QMAN_INITFQ_FLAG_*** options
  802. * @opts: the FQ-modification settings, as defined in the low-level API
  803. *
  804. * The @opts parameter comes from the low-level portal API. Select
  805. * QMAN_INITFQ_FLAG_SCHED in @flags to cause the frame queue to be scheduled
  806. * rather than parked. NB, @opts can be NULL.
  807. *
  808. * Note that some fields and options within @opts may be ignored or overwritten
  809. * by the driver;
  810. * 1. the 'count' and 'fqid' fields are always ignored (this operation only
  811. * affects one frame queue: @fq).
  812. * 2. the QM_INITFQ_WE_CONTEXTB option of the 'we_mask' field and the associated
  813. * 'fqd' structure's 'context_b' field are sometimes overwritten;
  814. * - if @fq was not created with QMAN_FQ_FLAG_TO_DCPORTAL, then context_b is
  815. * initialised to a value used by the driver for demux.
  816. * - if context_b is initialised for demux, so is context_a in case stashing
  817. * is requested (see item 4).
  818. * (So caller control of context_b is only possible for TO_DCPORTAL frame queue
  819. * objects.)
  820. * 3. if @flags contains QMAN_INITFQ_FLAG_LOCAL, the 'fqd' structure's
  821. * 'dest::channel' field will be overwritten to match the portal used to issue
  822. * the command. If the WE_DESTWQ write-enable bit had already been set by the
  823. * caller, the channel workqueue will be left as-is, otherwise the write-enable
  824. * bit is set and the workqueue is set to a default of 4. If the "LOCAL" flag
  825. * isn't set, the destination channel/workqueue fields and the write-enable bit
  826. * are left as-is.
  827. * 4. if the driver overwrites context_a/b for demux, then if
  828. * QM_INITFQ_WE_CONTEXTA is set, the driver will only overwrite
  829. * context_a.address fields and will leave the stashing fields provided by the
  830. * user alone, otherwise it will zero out the context_a.stashing fields.
  831. */
  832. int qman_init_fq(struct qman_fq *fq, u32 flags, struct qm_mcc_initfq *opts);
  833. /**
  834. * qman_schedule_fq - Schedules a FQ
  835. * @fq: the frame queue object to schedule, must be 'parked'
  836. *
  837. * Schedules the frame queue, which must be Parked, which takes it to
  838. * Tentatively-Scheduled or Truly-Scheduled depending on its fill-level.
  839. */
  840. int qman_schedule_fq(struct qman_fq *fq);
  841. /**
  842. * qman_retire_fq - Retires a FQ
  843. * @fq: the frame queue object to retire
  844. * @flags: FQ flags (QMAN_FQ_STATE*) if retirement completes immediately
  845. *
  846. * Retires the frame queue. This returns zero if it succeeds immediately, +1 if
  847. * the retirement was started asynchronously, otherwise it returns negative for
  848. * failure. When this function returns zero, @flags is set to indicate whether
  849. * the retired FQ is empty and/or whether it has any ORL fragments (to show up
  850. * as ERNs). Otherwise the corresponding flags will be known when a subsequent
  851. * FQRN message shows up on the portal's message ring.
  852. *
  853. * NB, if the retirement is asynchronous (the FQ was in the Truly Scheduled or
  854. * Active state), the completion will be via the message ring as a FQRN - but
  855. * the corresponding callback may occur before this function returns!! Ie. the
  856. * caller should be prepared to accept the callback as the function is called,
  857. * not only once it has returned.
  858. */
  859. int qman_retire_fq(struct qman_fq *fq, u32 *flags);
  860. /**
  861. * qman_oos_fq - Puts a FQ "out of service"
  862. * @fq: the frame queue object to be put out-of-service, must be 'retired'
  863. *
  864. * The frame queue must be retired and empty, and if any order restoration list
  865. * was released as ERNs at the time of retirement, they must all be consumed.
  866. */
  867. int qman_oos_fq(struct qman_fq *fq);
  868. /**
  869. * qman_enqueue - Enqueue a frame to a frame queue
  870. * @fq: the frame queue object to enqueue to
  871. * @fd: a descriptor of the frame to be enqueued
  872. *
  873. * Fills an entry in the EQCR of portal @qm to enqueue the frame described by
  874. * @fd. The descriptor details are copied from @fd to the EQCR entry, the 'pid'
  875. * field is ignored. The return value is non-zero on error, such as ring full.
  876. */
  877. int qman_enqueue(struct qman_fq *fq, const struct qm_fd *fd);
  878. /**
  879. * qman_alloc_fqid_range - Allocate a contiguous range of FQIDs
  880. * @result: is set by the API to the base FQID of the allocated range
  881. * @count: the number of FQIDs required
  882. *
  883. * Returns 0 on success, or a negative error code.
  884. */
  885. int qman_alloc_fqid_range(u32 *result, u32 count);
  886. #define qman_alloc_fqid(result) qman_alloc_fqid_range(result, 1)
  887. /**
  888. * qman_release_fqid - Release the specified frame queue ID
  889. * @fqid: the FQID to be released back to the resource pool
  890. *
  891. * This function can also be used to seed the allocator with
  892. * FQID ranges that it can subsequently allocate from.
  893. * Returns 0 on success, or a negative error code.
  894. */
  895. int qman_release_fqid(u32 fqid);
  896. /* Pool-channel management */
  897. /**
  898. * qman_alloc_pool_range - Allocate a contiguous range of pool-channel IDs
  899. * @result: is set by the API to the base pool-channel ID of the allocated range
  900. * @count: the number of pool-channel IDs required
  901. *
  902. * Returns 0 on success, or a negative error code.
  903. */
  904. int qman_alloc_pool_range(u32 *result, u32 count);
  905. #define qman_alloc_pool(result) qman_alloc_pool_range(result, 1)
  906. /**
  907. * qman_release_pool - Release the specified pool-channel ID
  908. * @id: the pool-chan ID to be released back to the resource pool
  909. *
  910. * This function can also be used to seed the allocator with
  911. * pool-channel ID ranges that it can subsequently allocate from.
  912. * Returns 0 on success, or a negative error code.
  913. */
  914. int qman_release_pool(u32 id);
  915. /* CGR management */
  916. /**
  917. * qman_create_cgr - Register a congestion group object
  918. * @cgr: the 'cgr' object, with fields filled in
  919. * @flags: QMAN_CGR_FLAG_* values
  920. * @opts: optional state of CGR settings
  921. *
  922. * Registers this object to receiving congestion entry/exit callbacks on the
  923. * portal affine to the cpu portal on which this API is executed. If opts is
  924. * NULL then only the callback (cgr->cb) function is registered. If @flags
  925. * contains QMAN_CGR_FLAG_USE_INIT, then an init hw command (which will reset
  926. * any unspecified parameters) will be used rather than a modify hw hardware
  927. * (which only modifies the specified parameters).
  928. */
  929. int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
  930. struct qm_mcc_initcgr *opts);
  931. /**
  932. * qman_delete_cgr - Deregisters a congestion group object
  933. * @cgr: the 'cgr' object to deregister
  934. *
  935. * "Unplugs" this CGR object from the portal affine to the cpu on which this API
  936. * is executed. This must be excuted on the same affine portal on which it was
  937. * created.
  938. */
  939. int qman_delete_cgr(struct qman_cgr *cgr);
  940. /**
  941. * qman_delete_cgr_safe - Deregisters a congestion group object from any CPU
  942. * @cgr: the 'cgr' object to deregister
  943. *
  944. * This will select the proper CPU and run there qman_delete_cgr().
  945. */
  946. void qman_delete_cgr_safe(struct qman_cgr *cgr);
  947. /**
  948. * qman_query_cgr_congested - Queries CGR's congestion status
  949. * @cgr: the 'cgr' object to query
  950. * @result: returns 'cgr's congestion status, 1 (true) if congested
  951. */
  952. int qman_query_cgr_congested(struct qman_cgr *cgr, bool *result);
  953. /**
  954. * qman_alloc_cgrid_range - Allocate a contiguous range of CGR IDs
  955. * @result: is set by the API to the base CGR ID of the allocated range
  956. * @count: the number of CGR IDs required
  957. *
  958. * Returns 0 on success, or a negative error code.
  959. */
  960. int qman_alloc_cgrid_range(u32 *result, u32 count);
  961. #define qman_alloc_cgrid(result) qman_alloc_cgrid_range(result, 1)
  962. /**
  963. * qman_release_cgrid - Release the specified CGR ID
  964. * @id: the CGR ID to be released back to the resource pool
  965. *
  966. * This function can also be used to seed the allocator with
  967. * CGR ID ranges that it can subsequently allocate from.
  968. * Returns 0 on success, or a negative error code.
  969. */
  970. int qman_release_cgrid(u32 id);
  971. #endif /* __FSL_QMAN_H */