qbman-portal.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
  2. /*
  3. * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  4. * Copyright 2016 NXP
  5. *
  6. */
  7. #ifndef __FSL_QBMAN_PORTAL_H
  8. #define __FSL_QBMAN_PORTAL_H
  9. #include <soc/fsl/dpaa2-fd.h>
  10. struct dpaa2_dq;
  11. struct qbman_swp;
  12. /* qbman software portal descriptor structure */
  13. struct qbman_swp_desc {
  14. void *cena_bar; /* Cache-enabled portal base address */
  15. void __iomem *cinh_bar; /* Cache-inhibited portal base address */
  16. u32 qman_version;
  17. };
  18. #define QBMAN_SWP_INTERRUPT_EQRI 0x01
  19. #define QBMAN_SWP_INTERRUPT_EQDI 0x02
  20. #define QBMAN_SWP_INTERRUPT_DQRI 0x04
  21. #define QBMAN_SWP_INTERRUPT_RCRI 0x08
  22. #define QBMAN_SWP_INTERRUPT_RCDI 0x10
  23. #define QBMAN_SWP_INTERRUPT_VDCI 0x20
  24. /* the structure for pull dequeue descriptor */
  25. struct qbman_pull_desc {
  26. u8 verb;
  27. u8 numf;
  28. u8 tok;
  29. u8 reserved;
  30. __le32 dq_src;
  31. __le64 rsp_addr;
  32. u64 rsp_addr_virt;
  33. u8 padding[40];
  34. };
  35. enum qbman_pull_type_e {
  36. /* dequeue with priority precedence, respect intra-class scheduling */
  37. qbman_pull_type_prio = 1,
  38. /* dequeue with active FQ precedence, respect ICS */
  39. qbman_pull_type_active,
  40. /* dequeue with active FQ precedence, no ICS */
  41. qbman_pull_type_active_noics
  42. };
  43. /* Definitions for parsing dequeue entries */
  44. #define QBMAN_RESULT_MASK 0x7f
  45. #define QBMAN_RESULT_DQ 0x60
  46. #define QBMAN_RESULT_FQRN 0x21
  47. #define QBMAN_RESULT_FQRNI 0x22
  48. #define QBMAN_RESULT_FQPN 0x24
  49. #define QBMAN_RESULT_FQDAN 0x25
  50. #define QBMAN_RESULT_CDAN 0x26
  51. #define QBMAN_RESULT_CSCN_MEM 0x27
  52. #define QBMAN_RESULT_CGCU 0x28
  53. #define QBMAN_RESULT_BPSCN 0x29
  54. #define QBMAN_RESULT_CSCN_WQ 0x2a
  55. /* QBMan FQ management command codes */
  56. #define QBMAN_FQ_SCHEDULE 0x48
  57. #define QBMAN_FQ_FORCE 0x49
  58. #define QBMAN_FQ_XON 0x4d
  59. #define QBMAN_FQ_XOFF 0x4e
  60. /* structure of enqueue descriptor */
  61. struct qbman_eq_desc {
  62. u8 verb;
  63. u8 dca;
  64. __le16 seqnum;
  65. __le16 orpid;
  66. __le16 reserved1;
  67. __le32 tgtid;
  68. __le32 tag;
  69. __le16 qdbin;
  70. u8 qpri;
  71. u8 reserved[3];
  72. u8 wae;
  73. u8 rspid;
  74. __le64 rsp_addr;
  75. u8 fd[32];
  76. };
  77. /* buffer release descriptor */
  78. struct qbman_release_desc {
  79. u8 verb;
  80. u8 reserved;
  81. __le16 bpid;
  82. __le32 reserved2;
  83. __le64 buf[7];
  84. };
  85. /* Management command result codes */
  86. #define QBMAN_MC_RSLT_OK 0xf0
  87. #define CODE_CDAN_WE_EN 0x1
  88. #define CODE_CDAN_WE_CTX 0x4
  89. /* portal data structure */
  90. struct qbman_swp {
  91. const struct qbman_swp_desc *desc;
  92. void *addr_cena;
  93. void __iomem *addr_cinh;
  94. /* Management commands */
  95. struct {
  96. u32 valid_bit; /* 0x00 or 0x80 */
  97. } mc;
  98. /* Push dequeues */
  99. u32 sdq;
  100. /* Volatile dequeues */
  101. struct {
  102. atomic_t available; /* indicates if a command can be sent */
  103. u32 valid_bit; /* 0x00 or 0x80 */
  104. struct dpaa2_dq *storage; /* NULL if DQRR */
  105. } vdq;
  106. /* DQRR */
  107. struct {
  108. u32 next_idx;
  109. u32 valid_bit;
  110. u8 dqrr_size;
  111. int reset_bug; /* indicates dqrr reset workaround is needed */
  112. } dqrr;
  113. };
  114. struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
  115. void qbman_swp_finish(struct qbman_swp *p);
  116. u32 qbman_swp_interrupt_read_status(struct qbman_swp *p);
  117. void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask);
  118. u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
  119. void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask);
  120. int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
  121. void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
  122. void qbman_swp_push_get(struct qbman_swp *p, u8 channel_idx, int *enabled);
  123. void qbman_swp_push_set(struct qbman_swp *p, u8 channel_idx, int enable);
  124. void qbman_pull_desc_clear(struct qbman_pull_desc *d);
  125. void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
  126. struct dpaa2_dq *storage,
  127. dma_addr_t storage_phys,
  128. int stash);
  129. void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes);
  130. void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid);
  131. void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
  132. enum qbman_pull_type_e dct);
  133. void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
  134. enum qbman_pull_type_e dct);
  135. int qbman_swp_pull(struct qbman_swp *p, struct qbman_pull_desc *d);
  136. const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s);
  137. void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq);
  138. int qbman_result_has_new_result(struct qbman_swp *p, const struct dpaa2_dq *dq);
  139. void qbman_eq_desc_clear(struct qbman_eq_desc *d);
  140. void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
  141. void qbman_eq_desc_set_token(struct qbman_eq_desc *d, u8 token);
  142. void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid);
  143. void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
  144. u32 qd_bin, u32 qd_prio);
  145. int qbman_swp_enqueue(struct qbman_swp *p, const struct qbman_eq_desc *d,
  146. const struct dpaa2_fd *fd);
  147. void qbman_release_desc_clear(struct qbman_release_desc *d);
  148. void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid);
  149. void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
  150. int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
  151. const u64 *buffers, unsigned int num_buffers);
  152. int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
  153. unsigned int num_buffers);
  154. int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
  155. u8 alt_fq_verb);
  156. int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
  157. u8 we_mask, u8 cdan_en,
  158. u64 ctx);
  159. void *qbman_swp_mc_start(struct qbman_swp *p);
  160. void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb);
  161. void *qbman_swp_mc_result(struct qbman_swp *p);
  162. /**
  163. * qbman_result_is_DQ() - check if the dequeue result is a dequeue response
  164. * @dq: the dequeue result to be checked
  165. *
  166. * DQRR entries may contain non-dequeue results, ie. notifications
  167. */
  168. static inline int qbman_result_is_DQ(const struct dpaa2_dq *dq)
  169. {
  170. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_DQ);
  171. }
  172. /**
  173. * qbman_result_is_SCN() - Check the dequeue result is notification or not
  174. * @dq: the dequeue result to be checked
  175. *
  176. */
  177. static inline int qbman_result_is_SCN(const struct dpaa2_dq *dq)
  178. {
  179. return !qbman_result_is_DQ(dq);
  180. }
  181. /* FQ Data Availability */
  182. static inline int qbman_result_is_FQDAN(const struct dpaa2_dq *dq)
  183. {
  184. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQDAN);
  185. }
  186. /* Channel Data Availability */
  187. static inline int qbman_result_is_CDAN(const struct dpaa2_dq *dq)
  188. {
  189. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CDAN);
  190. }
  191. /* Congestion State Change */
  192. static inline int qbman_result_is_CSCN(const struct dpaa2_dq *dq)
  193. {
  194. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CSCN_WQ);
  195. }
  196. /* Buffer Pool State Change */
  197. static inline int qbman_result_is_BPSCN(const struct dpaa2_dq *dq)
  198. {
  199. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_BPSCN);
  200. }
  201. /* Congestion Group Count Update */
  202. static inline int qbman_result_is_CGCU(const struct dpaa2_dq *dq)
  203. {
  204. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CGCU);
  205. }
  206. /* Retirement */
  207. static inline int qbman_result_is_FQRN(const struct dpaa2_dq *dq)
  208. {
  209. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRN);
  210. }
  211. /* Retirement Immediate */
  212. static inline int qbman_result_is_FQRNI(const struct dpaa2_dq *dq)
  213. {
  214. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRNI);
  215. }
  216. /* Park */
  217. static inline int qbman_result_is_FQPN(const struct dpaa2_dq *dq)
  218. {
  219. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQPN);
  220. }
  221. /**
  222. * qbman_result_SCN_state() - Get the state field in State-change notification
  223. */
  224. static inline u8 qbman_result_SCN_state(const struct dpaa2_dq *scn)
  225. {
  226. return scn->scn.state;
  227. }
  228. #define SCN_RID_MASK 0x00FFFFFF
  229. /**
  230. * qbman_result_SCN_rid() - Get the resource id in State-change notification
  231. */
  232. static inline u32 qbman_result_SCN_rid(const struct dpaa2_dq *scn)
  233. {
  234. return le32_to_cpu(scn->scn.rid_tok) & SCN_RID_MASK;
  235. }
  236. /**
  237. * qbman_result_SCN_ctx() - Get the context data in State-change notification
  238. */
  239. static inline u64 qbman_result_SCN_ctx(const struct dpaa2_dq *scn)
  240. {
  241. return le64_to_cpu(scn->scn.ctx);
  242. }
  243. /**
  244. * qbman_swp_fq_schedule() - Move the fq to the scheduled state
  245. * @s: the software portal object
  246. * @fqid: the index of frame queue to be scheduled
  247. *
  248. * There are a couple of different ways that a FQ can end up parked state,
  249. * This schedules it.
  250. *
  251. * Return 0 for success, or negative error code for failure.
  252. */
  253. static inline int qbman_swp_fq_schedule(struct qbman_swp *s, u32 fqid)
  254. {
  255. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_SCHEDULE);
  256. }
  257. /**
  258. * qbman_swp_fq_force() - Force the FQ to fully scheduled state
  259. * @s: the software portal object
  260. * @fqid: the index of frame queue to be forced
  261. *
  262. * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
  263. * and thus be available for selection by any channel-dequeuing behaviour (push
  264. * or pull). If the FQ is subsequently "dequeued" from the channel and is still
  265. * empty at the time this happens, the resulting dq_entry will have no FD.
  266. * (qbman_result_DQ_fd() will return NULL.)
  267. *
  268. * Return 0 for success, or negative error code for failure.
  269. */
  270. static inline int qbman_swp_fq_force(struct qbman_swp *s, u32 fqid)
  271. {
  272. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_FORCE);
  273. }
  274. /**
  275. * qbman_swp_fq_xon() - sets FQ flow-control to XON
  276. * @s: the software portal object
  277. * @fqid: the index of frame queue
  278. *
  279. * This setting doesn't affect enqueues to the FQ, just dequeues.
  280. *
  281. * Return 0 for success, or negative error code for failure.
  282. */
  283. static inline int qbman_swp_fq_xon(struct qbman_swp *s, u32 fqid)
  284. {
  285. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XON);
  286. }
  287. /**
  288. * qbman_swp_fq_xoff() - sets FQ flow-control to XOFF
  289. * @s: the software portal object
  290. * @fqid: the index of frame queue
  291. *
  292. * This setting doesn't affect enqueues to the FQ, just dequeues.
  293. * XOFF FQs will remain in the tenatively-scheduled state, even when
  294. * non-empty, meaning they won't be selected for scheduled dequeuing.
  295. * If a FQ is changed to XOFF after it had already become truly-scheduled
  296. * to a channel, and a pull dequeue of that channel occurs that selects
  297. * that FQ for dequeuing, then the resulting dq_entry will have no FD.
  298. * (qbman_result_DQ_fd() will return NULL.)
  299. *
  300. * Return 0 for success, or negative error code for failure.
  301. */
  302. static inline int qbman_swp_fq_xoff(struct qbman_swp *s, u32 fqid)
  303. {
  304. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XOFF);
  305. }
  306. /* If the user has been allocated a channel object that is going to generate
  307. * CDANs to another channel, then the qbman_swp_CDAN* functions will be
  308. * necessary.
  309. *
  310. * CDAN-enabled channels only generate a single CDAN notification, after which
  311. * they need to be reenabled before they'll generate another. The idea is
  312. * that pull dequeuing will occur in reaction to the CDAN, followed by a
  313. * reenable step. Each function generates a distinct command to hardware, so a
  314. * combination function is provided if the user wishes to modify the "context"
  315. * (which shows up in each CDAN message) each time they reenable, as a single
  316. * command to hardware.
  317. */
  318. /**
  319. * qbman_swp_CDAN_set_context() - Set CDAN context
  320. * @s: the software portal object
  321. * @channelid: the channel index
  322. * @ctx: the context to be set in CDAN
  323. *
  324. * Return 0 for success, or negative error code for failure.
  325. */
  326. static inline int qbman_swp_CDAN_set_context(struct qbman_swp *s, u16 channelid,
  327. u64 ctx)
  328. {
  329. return qbman_swp_CDAN_set(s, channelid,
  330. CODE_CDAN_WE_CTX,
  331. 0, ctx);
  332. }
  333. /**
  334. * qbman_swp_CDAN_enable() - Enable CDAN for the channel
  335. * @s: the software portal object
  336. * @channelid: the index of the channel to generate CDAN
  337. *
  338. * Return 0 for success, or negative error code for failure.
  339. */
  340. static inline int qbman_swp_CDAN_enable(struct qbman_swp *s, u16 channelid)
  341. {
  342. return qbman_swp_CDAN_set(s, channelid,
  343. CODE_CDAN_WE_EN,
  344. 1, 0);
  345. }
  346. /**
  347. * qbman_swp_CDAN_disable() - disable CDAN for the channel
  348. * @s: the software portal object
  349. * @channelid: the index of the channel to generate CDAN
  350. *
  351. * Return 0 for success, or negative error code for failure.
  352. */
  353. static inline int qbman_swp_CDAN_disable(struct qbman_swp *s, u16 channelid)
  354. {
  355. return qbman_swp_CDAN_set(s, channelid,
  356. CODE_CDAN_WE_EN,
  357. 0, 0);
  358. }
  359. /**
  360. * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
  361. * @s: the software portal object
  362. * @channelid: the index of the channel to generate CDAN
  363. * @ctx:i the context set in CDAN
  364. *
  365. * Return 0 for success, or negative error code for failure.
  366. */
  367. static inline int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s,
  368. u16 channelid,
  369. u64 ctx)
  370. {
  371. return qbman_swp_CDAN_set(s, channelid,
  372. CODE_CDAN_WE_EN | CODE_CDAN_WE_CTX,
  373. 1, ctx);
  374. }
  375. /* Wraps up submit + poll-for-result */
  376. static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
  377. u8 cmd_verb)
  378. {
  379. int loopvar = 1000;
  380. qbman_swp_mc_submit(swp, cmd, cmd_verb);
  381. do {
  382. cmd = qbman_swp_mc_result(swp);
  383. } while (!cmd && loopvar--);
  384. WARN_ON(!loopvar);
  385. return cmd;
  386. }
  387. #endif /* __FSL_QBMAN_PORTAL_H */