qbman-portal.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
  2. /*
  3. * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  4. * Copyright 2016-2019 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. /* Management response */
  99. struct {
  100. u32 valid_bit; /* 0x00 or 0x80 */
  101. } mr;
  102. /* Push dequeues */
  103. u32 sdq;
  104. /* Volatile dequeues */
  105. struct {
  106. atomic_t available; /* indicates if a command can be sent */
  107. u32 valid_bit; /* 0x00 or 0x80 */
  108. struct dpaa2_dq *storage; /* NULL if DQRR */
  109. } vdq;
  110. /* DQRR */
  111. struct {
  112. u32 next_idx;
  113. u32 valid_bit;
  114. u8 dqrr_size;
  115. int reset_bug; /* indicates dqrr reset workaround is needed */
  116. } dqrr;
  117. };
  118. struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
  119. void qbman_swp_finish(struct qbman_swp *p);
  120. u32 qbman_swp_interrupt_read_status(struct qbman_swp *p);
  121. void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask);
  122. u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
  123. void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask);
  124. int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
  125. void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
  126. void qbman_swp_push_get(struct qbman_swp *p, u8 channel_idx, int *enabled);
  127. void qbman_swp_push_set(struct qbman_swp *p, u8 channel_idx, int enable);
  128. void qbman_pull_desc_clear(struct qbman_pull_desc *d);
  129. void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
  130. struct dpaa2_dq *storage,
  131. dma_addr_t storage_phys,
  132. int stash);
  133. void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes);
  134. void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid);
  135. void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
  136. enum qbman_pull_type_e dct);
  137. void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
  138. enum qbman_pull_type_e dct);
  139. int qbman_swp_pull(struct qbman_swp *p, struct qbman_pull_desc *d);
  140. const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s);
  141. void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq);
  142. int qbman_result_has_new_result(struct qbman_swp *p, const struct dpaa2_dq *dq);
  143. void qbman_eq_desc_clear(struct qbman_eq_desc *d);
  144. void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
  145. void qbman_eq_desc_set_token(struct qbman_eq_desc *d, u8 token);
  146. void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid);
  147. void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
  148. u32 qd_bin, u32 qd_prio);
  149. int qbman_swp_enqueue(struct qbman_swp *p, const struct qbman_eq_desc *d,
  150. const struct dpaa2_fd *fd);
  151. void qbman_release_desc_clear(struct qbman_release_desc *d);
  152. void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid);
  153. void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
  154. int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
  155. const u64 *buffers, unsigned int num_buffers);
  156. int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
  157. unsigned int num_buffers);
  158. int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
  159. u8 alt_fq_verb);
  160. int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
  161. u8 we_mask, u8 cdan_en,
  162. u64 ctx);
  163. void *qbman_swp_mc_start(struct qbman_swp *p);
  164. void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb);
  165. void *qbman_swp_mc_result(struct qbman_swp *p);
  166. /**
  167. * qbman_result_is_DQ() - check if the dequeue result is a dequeue response
  168. * @dq: the dequeue result to be checked
  169. *
  170. * DQRR entries may contain non-dequeue results, ie. notifications
  171. */
  172. static inline int qbman_result_is_DQ(const struct dpaa2_dq *dq)
  173. {
  174. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_DQ);
  175. }
  176. /**
  177. * qbman_result_is_SCN() - Check the dequeue result is notification or not
  178. * @dq: the dequeue result to be checked
  179. *
  180. */
  181. static inline int qbman_result_is_SCN(const struct dpaa2_dq *dq)
  182. {
  183. return !qbman_result_is_DQ(dq);
  184. }
  185. /* FQ Data Availability */
  186. static inline int qbman_result_is_FQDAN(const struct dpaa2_dq *dq)
  187. {
  188. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQDAN);
  189. }
  190. /* Channel Data Availability */
  191. static inline int qbman_result_is_CDAN(const struct dpaa2_dq *dq)
  192. {
  193. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CDAN);
  194. }
  195. /* Congestion State Change */
  196. static inline int qbman_result_is_CSCN(const struct dpaa2_dq *dq)
  197. {
  198. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CSCN_WQ);
  199. }
  200. /* Buffer Pool State Change */
  201. static inline int qbman_result_is_BPSCN(const struct dpaa2_dq *dq)
  202. {
  203. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_BPSCN);
  204. }
  205. /* Congestion Group Count Update */
  206. static inline int qbman_result_is_CGCU(const struct dpaa2_dq *dq)
  207. {
  208. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CGCU);
  209. }
  210. /* Retirement */
  211. static inline int qbman_result_is_FQRN(const struct dpaa2_dq *dq)
  212. {
  213. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRN);
  214. }
  215. /* Retirement Immediate */
  216. static inline int qbman_result_is_FQRNI(const struct dpaa2_dq *dq)
  217. {
  218. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRNI);
  219. }
  220. /* Park */
  221. static inline int qbman_result_is_FQPN(const struct dpaa2_dq *dq)
  222. {
  223. return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQPN);
  224. }
  225. /**
  226. * qbman_result_SCN_state() - Get the state field in State-change notification
  227. */
  228. static inline u8 qbman_result_SCN_state(const struct dpaa2_dq *scn)
  229. {
  230. return scn->scn.state;
  231. }
  232. #define SCN_RID_MASK 0x00FFFFFF
  233. /**
  234. * qbman_result_SCN_rid() - Get the resource id in State-change notification
  235. */
  236. static inline u32 qbman_result_SCN_rid(const struct dpaa2_dq *scn)
  237. {
  238. return le32_to_cpu(scn->scn.rid_tok) & SCN_RID_MASK;
  239. }
  240. /**
  241. * qbman_result_SCN_ctx() - Get the context data in State-change notification
  242. */
  243. static inline u64 qbman_result_SCN_ctx(const struct dpaa2_dq *scn)
  244. {
  245. return le64_to_cpu(scn->scn.ctx);
  246. }
  247. /**
  248. * qbman_swp_fq_schedule() - Move the fq to the scheduled state
  249. * @s: the software portal object
  250. * @fqid: the index of frame queue to be scheduled
  251. *
  252. * There are a couple of different ways that a FQ can end up parked state,
  253. * This schedules it.
  254. *
  255. * Return 0 for success, or negative error code for failure.
  256. */
  257. static inline int qbman_swp_fq_schedule(struct qbman_swp *s, u32 fqid)
  258. {
  259. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_SCHEDULE);
  260. }
  261. /**
  262. * qbman_swp_fq_force() - Force the FQ to fully scheduled state
  263. * @s: the software portal object
  264. * @fqid: the index of frame queue to be forced
  265. *
  266. * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
  267. * and thus be available for selection by any channel-dequeuing behaviour (push
  268. * or pull). If the FQ is subsequently "dequeued" from the channel and is still
  269. * empty at the time this happens, the resulting dq_entry will have no FD.
  270. * (qbman_result_DQ_fd() will return NULL.)
  271. *
  272. * Return 0 for success, or negative error code for failure.
  273. */
  274. static inline int qbman_swp_fq_force(struct qbman_swp *s, u32 fqid)
  275. {
  276. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_FORCE);
  277. }
  278. /**
  279. * qbman_swp_fq_xon() - sets FQ flow-control to XON
  280. * @s: the software portal object
  281. * @fqid: the index of frame queue
  282. *
  283. * This setting doesn't affect enqueues to the FQ, just dequeues.
  284. *
  285. * Return 0 for success, or negative error code for failure.
  286. */
  287. static inline int qbman_swp_fq_xon(struct qbman_swp *s, u32 fqid)
  288. {
  289. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XON);
  290. }
  291. /**
  292. * qbman_swp_fq_xoff() - sets FQ flow-control to XOFF
  293. * @s: the software portal object
  294. * @fqid: the index of frame queue
  295. *
  296. * This setting doesn't affect enqueues to the FQ, just dequeues.
  297. * XOFF FQs will remain in the tenatively-scheduled state, even when
  298. * non-empty, meaning they won't be selected for scheduled dequeuing.
  299. * If a FQ is changed to XOFF after it had already become truly-scheduled
  300. * to a channel, and a pull dequeue of that channel occurs that selects
  301. * that FQ for dequeuing, then the resulting dq_entry will have no FD.
  302. * (qbman_result_DQ_fd() will return NULL.)
  303. *
  304. * Return 0 for success, or negative error code for failure.
  305. */
  306. static inline int qbman_swp_fq_xoff(struct qbman_swp *s, u32 fqid)
  307. {
  308. return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XOFF);
  309. }
  310. /* If the user has been allocated a channel object that is going to generate
  311. * CDANs to another channel, then the qbman_swp_CDAN* functions will be
  312. * necessary.
  313. *
  314. * CDAN-enabled channels only generate a single CDAN notification, after which
  315. * they need to be reenabled before they'll generate another. The idea is
  316. * that pull dequeuing will occur in reaction to the CDAN, followed by a
  317. * reenable step. Each function generates a distinct command to hardware, so a
  318. * combination function is provided if the user wishes to modify the "context"
  319. * (which shows up in each CDAN message) each time they reenable, as a single
  320. * command to hardware.
  321. */
  322. /**
  323. * qbman_swp_CDAN_set_context() - Set CDAN context
  324. * @s: the software portal object
  325. * @channelid: the channel index
  326. * @ctx: the context to be set in CDAN
  327. *
  328. * Return 0 for success, or negative error code for failure.
  329. */
  330. static inline int qbman_swp_CDAN_set_context(struct qbman_swp *s, u16 channelid,
  331. u64 ctx)
  332. {
  333. return qbman_swp_CDAN_set(s, channelid,
  334. CODE_CDAN_WE_CTX,
  335. 0, ctx);
  336. }
  337. /**
  338. * qbman_swp_CDAN_enable() - Enable CDAN for the channel
  339. * @s: the software portal object
  340. * @channelid: the index of the channel to generate CDAN
  341. *
  342. * Return 0 for success, or negative error code for failure.
  343. */
  344. static inline int qbman_swp_CDAN_enable(struct qbman_swp *s, u16 channelid)
  345. {
  346. return qbman_swp_CDAN_set(s, channelid,
  347. CODE_CDAN_WE_EN,
  348. 1, 0);
  349. }
  350. /**
  351. * qbman_swp_CDAN_disable() - disable CDAN for the channel
  352. * @s: the software portal object
  353. * @channelid: the index of the channel to generate CDAN
  354. *
  355. * Return 0 for success, or negative error code for failure.
  356. */
  357. static inline int qbman_swp_CDAN_disable(struct qbman_swp *s, u16 channelid)
  358. {
  359. return qbman_swp_CDAN_set(s, channelid,
  360. CODE_CDAN_WE_EN,
  361. 0, 0);
  362. }
  363. /**
  364. * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
  365. * @s: the software portal object
  366. * @channelid: the index of the channel to generate CDAN
  367. * @ctx:i the context set in CDAN
  368. *
  369. * Return 0 for success, or negative error code for failure.
  370. */
  371. static inline int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s,
  372. u16 channelid,
  373. u64 ctx)
  374. {
  375. return qbman_swp_CDAN_set(s, channelid,
  376. CODE_CDAN_WE_EN | CODE_CDAN_WE_CTX,
  377. 1, ctx);
  378. }
  379. /* Wraps up submit + poll-for-result */
  380. static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
  381. u8 cmd_verb)
  382. {
  383. int loopvar = 2000;
  384. qbman_swp_mc_submit(swp, cmd, cmd_verb);
  385. do {
  386. cmd = qbman_swp_mc_result(swp);
  387. } while (!cmd && loopvar--);
  388. WARN_ON(!loopvar);
  389. return cmd;
  390. }
  391. /* Query APIs */
  392. struct qbman_fq_query_np_rslt {
  393. u8 verb;
  394. u8 rslt;
  395. u8 st1;
  396. u8 st2;
  397. u8 reserved[2];
  398. __le16 od1_sfdr;
  399. __le16 od2_sfdr;
  400. __le16 od3_sfdr;
  401. __le16 ra1_sfdr;
  402. __le16 ra2_sfdr;
  403. __le32 pfdr_hptr;
  404. __le32 pfdr_tptr;
  405. __le32 frm_cnt;
  406. __le32 byte_cnt;
  407. __le16 ics_surp;
  408. u8 is;
  409. u8 reserved2[29];
  410. };
  411. int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
  412. struct qbman_fq_query_np_rslt *r);
  413. u32 qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r);
  414. u32 qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r);
  415. struct qbman_bp_query_rslt {
  416. u8 verb;
  417. u8 rslt;
  418. u8 reserved[4];
  419. u8 bdi;
  420. u8 state;
  421. __le32 fill;
  422. __le32 hdotr;
  423. __le16 swdet;
  424. __le16 swdxt;
  425. __le16 hwdet;
  426. __le16 hwdxt;
  427. __le16 swset;
  428. __le16 swsxt;
  429. __le16 vbpid;
  430. __le16 icid;
  431. __le64 bpscn_addr;
  432. __le64 bpscn_ctx;
  433. __le16 hw_targ;
  434. u8 dbe;
  435. u8 reserved2;
  436. u8 sdcnt;
  437. u8 hdcnt;
  438. u8 sscnt;
  439. u8 reserved3[9];
  440. };
  441. int qbman_bp_query(struct qbman_swp *s, u16 bpid,
  442. struct qbman_bp_query_rslt *r);
  443. u32 qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt *a);
  444. #endif /* __FSL_QBMAN_PORTAL_H */