qman.h 41 KB

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