qbman-portal.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  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. #include <asm/cacheflush.h>
  8. #include <linux/io.h>
  9. #include <linux/slab.h>
  10. #include <soc/fsl/dpaa2-global.h>
  11. #include "qbman-portal.h"
  12. #define QMAN_REV_4000 0x04000000
  13. #define QMAN_REV_4100 0x04010000
  14. #define QMAN_REV_4101 0x04010001
  15. #define QMAN_REV_5000 0x05000000
  16. #define QMAN_REV_MASK 0xffff0000
  17. /* All QBMan command and result structures use this "valid bit" encoding */
  18. #define QB_VALID_BIT ((u32)0x80)
  19. /* QBMan portal management command codes */
  20. #define QBMAN_MC_ACQUIRE 0x30
  21. #define QBMAN_WQCHAN_CONFIGURE 0x46
  22. /* CINH register offsets */
  23. #define QBMAN_CINH_SWP_EQCR_PI 0x800
  24. #define QBMAN_CINH_SWP_EQAR 0x8c0
  25. #define QBMAN_CINH_SWP_CR_RT 0x900
  26. #define QBMAN_CINH_SWP_VDQCR_RT 0x940
  27. #define QBMAN_CINH_SWP_EQCR_AM_RT 0x980
  28. #define QBMAN_CINH_SWP_RCR_AM_RT 0x9c0
  29. #define QBMAN_CINH_SWP_DQPI 0xa00
  30. #define QBMAN_CINH_SWP_DCAP 0xac0
  31. #define QBMAN_CINH_SWP_SDQCR 0xb00
  32. #define QBMAN_CINH_SWP_EQCR_AM_RT2 0xb40
  33. #define QBMAN_CINH_SWP_RCR_PI 0xc00
  34. #define QBMAN_CINH_SWP_RAR 0xcc0
  35. #define QBMAN_CINH_SWP_ISR 0xe00
  36. #define QBMAN_CINH_SWP_IER 0xe40
  37. #define QBMAN_CINH_SWP_ISDR 0xe80
  38. #define QBMAN_CINH_SWP_IIR 0xec0
  39. /* CENA register offsets */
  40. #define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((u32)(n) << 6))
  41. #define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((u32)(n) << 6))
  42. #define QBMAN_CENA_SWP_RCR(n) (0x400 + ((u32)(n) << 6))
  43. #define QBMAN_CENA_SWP_CR 0x600
  44. #define QBMAN_CENA_SWP_RR(vb) (0x700 + ((u32)(vb) >> 1))
  45. #define QBMAN_CENA_SWP_VDQCR 0x780
  46. /* CENA register offsets in memory-backed mode */
  47. #define QBMAN_CENA_SWP_DQRR_MEM(n) (0x800 + ((u32)(n) << 6))
  48. #define QBMAN_CENA_SWP_RCR_MEM(n) (0x1400 + ((u32)(n) << 6))
  49. #define QBMAN_CENA_SWP_CR_MEM 0x1600
  50. #define QBMAN_CENA_SWP_RR_MEM 0x1680
  51. #define QBMAN_CENA_SWP_VDQCR_MEM 0x1780
  52. /* Reverse mapping of QBMAN_CENA_SWP_DQRR() */
  53. #define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)(p) & 0x1ff) >> 6)
  54. /* Define token used to determine if response written to memory is valid */
  55. #define QMAN_DQ_TOKEN_VALID 1
  56. /* SDQCR attribute codes */
  57. #define QB_SDQCR_FC_SHIFT 29
  58. #define QB_SDQCR_FC_MASK 0x1
  59. #define QB_SDQCR_DCT_SHIFT 24
  60. #define QB_SDQCR_DCT_MASK 0x3
  61. #define QB_SDQCR_TOK_SHIFT 16
  62. #define QB_SDQCR_TOK_MASK 0xff
  63. #define QB_SDQCR_SRC_SHIFT 0
  64. #define QB_SDQCR_SRC_MASK 0xffff
  65. /* opaque token for static dequeues */
  66. #define QMAN_SDQCR_TOKEN 0xbb
  67. enum qbman_sdqcr_dct {
  68. qbman_sdqcr_dct_null = 0,
  69. qbman_sdqcr_dct_prio_ics,
  70. qbman_sdqcr_dct_active_ics,
  71. qbman_sdqcr_dct_active
  72. };
  73. enum qbman_sdqcr_fc {
  74. qbman_sdqcr_fc_one = 0,
  75. qbman_sdqcr_fc_up_to_3 = 1
  76. };
  77. /* Portal Access */
  78. static inline u32 qbman_read_register(struct qbman_swp *p, u32 offset)
  79. {
  80. return readl_relaxed(p->addr_cinh + offset);
  81. }
  82. static inline void qbman_write_register(struct qbman_swp *p, u32 offset,
  83. u32 value)
  84. {
  85. writel_relaxed(value, p->addr_cinh + offset);
  86. }
  87. static inline void *qbman_get_cmd(struct qbman_swp *p, u32 offset)
  88. {
  89. return p->addr_cena + offset;
  90. }
  91. #define QBMAN_CINH_SWP_CFG 0xd00
  92. #define SWP_CFG_DQRR_MF_SHIFT 20
  93. #define SWP_CFG_EST_SHIFT 16
  94. #define SWP_CFG_CPBS_SHIFT 15
  95. #define SWP_CFG_WN_SHIFT 14
  96. #define SWP_CFG_RPM_SHIFT 12
  97. #define SWP_CFG_DCM_SHIFT 10
  98. #define SWP_CFG_EPM_SHIFT 8
  99. #define SWP_CFG_VPM_SHIFT 7
  100. #define SWP_CFG_CPM_SHIFT 6
  101. #define SWP_CFG_SD_SHIFT 5
  102. #define SWP_CFG_SP_SHIFT 4
  103. #define SWP_CFG_SE_SHIFT 3
  104. #define SWP_CFG_DP_SHIFT 2
  105. #define SWP_CFG_DE_SHIFT 1
  106. #define SWP_CFG_EP_SHIFT 0
  107. static inline u32 qbman_set_swp_cfg(u8 max_fill, u8 wn, u8 est, u8 rpm, u8 dcm,
  108. u8 epm, int sd, int sp, int se,
  109. int dp, int de, int ep)
  110. {
  111. return (max_fill << SWP_CFG_DQRR_MF_SHIFT |
  112. est << SWP_CFG_EST_SHIFT |
  113. wn << SWP_CFG_WN_SHIFT |
  114. rpm << SWP_CFG_RPM_SHIFT |
  115. dcm << SWP_CFG_DCM_SHIFT |
  116. epm << SWP_CFG_EPM_SHIFT |
  117. sd << SWP_CFG_SD_SHIFT |
  118. sp << SWP_CFG_SP_SHIFT |
  119. se << SWP_CFG_SE_SHIFT |
  120. dp << SWP_CFG_DP_SHIFT |
  121. de << SWP_CFG_DE_SHIFT |
  122. ep << SWP_CFG_EP_SHIFT);
  123. }
  124. #define QMAN_RT_MODE 0x00000100
  125. /**
  126. * qbman_swp_init() - Create a functional object representing the given
  127. * QBMan portal descriptor.
  128. * @d: the given qbman swp descriptor
  129. *
  130. * Return qbman_swp portal for success, NULL if the object cannot
  131. * be created.
  132. */
  133. struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
  134. {
  135. struct qbman_swp *p = kmalloc(sizeof(*p), GFP_KERNEL);
  136. u32 reg;
  137. if (!p)
  138. return NULL;
  139. p->desc = d;
  140. p->mc.valid_bit = QB_VALID_BIT;
  141. p->sdq = 0;
  142. p->sdq |= qbman_sdqcr_dct_prio_ics << QB_SDQCR_DCT_SHIFT;
  143. p->sdq |= qbman_sdqcr_fc_up_to_3 << QB_SDQCR_FC_SHIFT;
  144. p->sdq |= QMAN_SDQCR_TOKEN << QB_SDQCR_TOK_SHIFT;
  145. if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
  146. p->mr.valid_bit = QB_VALID_BIT;
  147. atomic_set(&p->vdq.available, 1);
  148. p->vdq.valid_bit = QB_VALID_BIT;
  149. p->dqrr.next_idx = 0;
  150. p->dqrr.valid_bit = QB_VALID_BIT;
  151. if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_4100) {
  152. p->dqrr.dqrr_size = 4;
  153. p->dqrr.reset_bug = 1;
  154. } else {
  155. p->dqrr.dqrr_size = 8;
  156. p->dqrr.reset_bug = 0;
  157. }
  158. p->addr_cena = d->cena_bar;
  159. p->addr_cinh = d->cinh_bar;
  160. if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
  161. memset(p->addr_cena, 0, 64 * 1024);
  162. reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
  163. 1, /* Writes Non-cacheable */
  164. 0, /* EQCR_CI stashing threshold */
  165. 3, /* RPM: Valid bit mode, RCR in array mode */
  166. 2, /* DCM: Discrete consumption ack mode */
  167. 3, /* EPM: Valid bit mode, EQCR in array mode */
  168. 1, /* mem stashing drop enable == TRUE */
  169. 1, /* mem stashing priority == TRUE */
  170. 1, /* mem stashing enable == TRUE */
  171. 1, /* dequeue stashing priority == TRUE */
  172. 0, /* dequeue stashing enable == FALSE */
  173. 0); /* EQCR_CI stashing priority == FALSE */
  174. if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
  175. reg |= 1 << SWP_CFG_CPBS_SHIFT | /* memory-backed mode */
  176. 1 << SWP_CFG_VPM_SHIFT | /* VDQCR read triggered mode */
  177. 1 << SWP_CFG_CPM_SHIFT; /* CR read triggered mode */
  178. qbman_write_register(p, QBMAN_CINH_SWP_CFG, reg);
  179. reg = qbman_read_register(p, QBMAN_CINH_SWP_CFG);
  180. if (!reg) {
  181. pr_err("qbman: the portal is not enabled!\n");
  182. kfree(p);
  183. return NULL;
  184. }
  185. if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000) {
  186. qbman_write_register(p, QBMAN_CINH_SWP_EQCR_PI, QMAN_RT_MODE);
  187. qbman_write_register(p, QBMAN_CINH_SWP_RCR_PI, QMAN_RT_MODE);
  188. }
  189. /*
  190. * SDQCR needs to be initialized to 0 when no channels are
  191. * being dequeued from or else the QMan HW will indicate an
  192. * error. The values that were calculated above will be
  193. * applied when dequeues from a specific channel are enabled.
  194. */
  195. qbman_write_register(p, QBMAN_CINH_SWP_SDQCR, 0);
  196. return p;
  197. }
  198. /**
  199. * qbman_swp_finish() - Create and destroy a functional object representing
  200. * the given QBMan portal descriptor.
  201. * @p: the qbman_swp object to be destroyed
  202. */
  203. void qbman_swp_finish(struct qbman_swp *p)
  204. {
  205. kfree(p);
  206. }
  207. /**
  208. * qbman_swp_interrupt_read_status()
  209. * @p: the given software portal
  210. *
  211. * Return the value in the SWP_ISR register.
  212. */
  213. u32 qbman_swp_interrupt_read_status(struct qbman_swp *p)
  214. {
  215. return qbman_read_register(p, QBMAN_CINH_SWP_ISR);
  216. }
  217. /**
  218. * qbman_swp_interrupt_clear_status()
  219. * @p: the given software portal
  220. * @mask: The mask to clear in SWP_ISR register
  221. */
  222. void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask)
  223. {
  224. qbman_write_register(p, QBMAN_CINH_SWP_ISR, mask);
  225. }
  226. /**
  227. * qbman_swp_interrupt_get_trigger() - read interrupt enable register
  228. * @p: the given software portal
  229. *
  230. * Return the value in the SWP_IER register.
  231. */
  232. u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p)
  233. {
  234. return qbman_read_register(p, QBMAN_CINH_SWP_IER);
  235. }
  236. /**
  237. * qbman_swp_interrupt_set_trigger() - enable interrupts for a swp
  238. * @p: the given software portal
  239. * @mask: The mask of bits to enable in SWP_IER
  240. */
  241. void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask)
  242. {
  243. qbman_write_register(p, QBMAN_CINH_SWP_IER, mask);
  244. }
  245. /**
  246. * qbman_swp_interrupt_get_inhibit() - read interrupt mask register
  247. * @p: the given software portal object
  248. *
  249. * Return the value in the SWP_IIR register.
  250. */
  251. int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p)
  252. {
  253. return qbman_read_register(p, QBMAN_CINH_SWP_IIR);
  254. }
  255. /**
  256. * qbman_swp_interrupt_set_inhibit() - write interrupt mask register
  257. * @p: the given software portal object
  258. * @mask: The mask to set in SWP_IIR register
  259. */
  260. void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit)
  261. {
  262. qbman_write_register(p, QBMAN_CINH_SWP_IIR, inhibit ? 0xffffffff : 0);
  263. }
  264. /*
  265. * Different management commands all use this common base layer of code to issue
  266. * commands and poll for results.
  267. */
  268. /*
  269. * Returns a pointer to where the caller should fill in their management command
  270. * (caller should ignore the verb byte)
  271. */
  272. void *qbman_swp_mc_start(struct qbman_swp *p)
  273. {
  274. if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
  275. return qbman_get_cmd(p, QBMAN_CENA_SWP_CR);
  276. else
  277. return qbman_get_cmd(p, QBMAN_CENA_SWP_CR_MEM);
  278. }
  279. /*
  280. * Commits merges in the caller-supplied command verb (which should not include
  281. * the valid-bit) and submits the command to hardware
  282. */
  283. void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb)
  284. {
  285. u8 *v = cmd;
  286. if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
  287. dma_wmb();
  288. *v = cmd_verb | p->mc.valid_bit;
  289. } else {
  290. *v = cmd_verb | p->mc.valid_bit;
  291. dma_wmb();
  292. qbman_write_register(p, QBMAN_CINH_SWP_CR_RT, QMAN_RT_MODE);
  293. }
  294. }
  295. /*
  296. * Checks for a completed response (returns non-NULL if only if the response
  297. * is complete).
  298. */
  299. void *qbman_swp_mc_result(struct qbman_swp *p)
  300. {
  301. u32 *ret, verb;
  302. if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
  303. ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
  304. /* Remove the valid-bit - command completed if the rest
  305. * is non-zero.
  306. */
  307. verb = ret[0] & ~QB_VALID_BIT;
  308. if (!verb)
  309. return NULL;
  310. p->mc.valid_bit ^= QB_VALID_BIT;
  311. } else {
  312. ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR_MEM);
  313. /* Command completed if the valid bit is toggled */
  314. if (p->mr.valid_bit != (ret[0] & QB_VALID_BIT))
  315. return NULL;
  316. /* Command completed if the rest is non-zero */
  317. verb = ret[0] & ~QB_VALID_BIT;
  318. if (!verb)
  319. return NULL;
  320. p->mr.valid_bit ^= QB_VALID_BIT;
  321. }
  322. return ret;
  323. }
  324. #define QB_ENQUEUE_CMD_OPTIONS_SHIFT 0
  325. enum qb_enqueue_commands {
  326. enqueue_empty = 0,
  327. enqueue_response_always = 1,
  328. enqueue_rejects_to_fq = 2
  329. };
  330. #define QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT 2
  331. #define QB_ENQUEUE_CMD_IRQ_ON_DISPATCH_SHIFT 3
  332. #define QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT 4
  333. /**
  334. * qbman_eq_desc_clear() - Clear the contents of a descriptor to
  335. * default/starting state.
  336. */
  337. void qbman_eq_desc_clear(struct qbman_eq_desc *d)
  338. {
  339. memset(d, 0, sizeof(*d));
  340. }
  341. /**
  342. * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
  343. * @d: the enqueue descriptor.
  344. * @response_success: 1 = enqueue with response always; 0 = enqueue with
  345. * rejections returned on a FQ.
  346. */
  347. void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
  348. {
  349. d->verb &= ~(1 << QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT);
  350. if (respond_success)
  351. d->verb |= enqueue_response_always;
  352. else
  353. d->verb |= enqueue_rejects_to_fq;
  354. }
  355. /*
  356. * Exactly one of the following descriptor "targets" should be set. (Calling any
  357. * one of these will replace the effect of any prior call to one of these.)
  358. * -enqueue to a frame queue
  359. * -enqueue to a queuing destination
  360. */
  361. /**
  362. * qbman_eq_desc_set_fq() - set the FQ for the enqueue command
  363. * @d: the enqueue descriptor
  364. * @fqid: the id of the frame queue to be enqueued
  365. */
  366. void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid)
  367. {
  368. d->verb &= ~(1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT);
  369. d->tgtid = cpu_to_le32(fqid);
  370. }
  371. /**
  372. * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command
  373. * @d: the enqueue descriptor
  374. * @qdid: the id of the queuing destination to be enqueued
  375. * @qd_bin: the queuing destination bin
  376. * @qd_prio: the queuing destination priority
  377. */
  378. void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
  379. u32 qd_bin, u32 qd_prio)
  380. {
  381. d->verb |= 1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT;
  382. d->tgtid = cpu_to_le32(qdid);
  383. d->qdbin = cpu_to_le16(qd_bin);
  384. d->qpri = qd_prio;
  385. }
  386. #define EQAR_IDX(eqar) ((eqar) & 0x7)
  387. #define EQAR_VB(eqar) ((eqar) & 0x80)
  388. #define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
  389. static inline void qbman_write_eqcr_am_rt_register(struct qbman_swp *p,
  390. u8 idx)
  391. {
  392. if (idx < 16)
  393. qbman_write_register(p, QBMAN_CINH_SWP_EQCR_AM_RT + idx * 4,
  394. QMAN_RT_MODE);
  395. else
  396. qbman_write_register(p, QBMAN_CINH_SWP_EQCR_AM_RT2 +
  397. (idx - 16) * 4,
  398. QMAN_RT_MODE);
  399. }
  400. /**
  401. * qbman_swp_enqueue() - Issue an enqueue command
  402. * @s: the software portal used for enqueue
  403. * @d: the enqueue descriptor
  404. * @fd: the frame descriptor to be enqueued
  405. *
  406. * Please note that 'fd' should only be NULL if the "action" of the
  407. * descriptor is "orp_hole" or "orp_nesn".
  408. *
  409. * Return 0 for successful enqueue, -EBUSY if the EQCR is not ready.
  410. */
  411. int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
  412. const struct dpaa2_fd *fd)
  413. {
  414. struct qbman_eq_desc *p;
  415. u32 eqar = qbman_read_register(s, QBMAN_CINH_SWP_EQAR);
  416. if (!EQAR_SUCCESS(eqar))
  417. return -EBUSY;
  418. p = qbman_get_cmd(s, QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)));
  419. memcpy(&p->dca, &d->dca, 31);
  420. memcpy(&p->fd, fd, sizeof(*fd));
  421. if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
  422. /* Set the verb byte, have to substitute in the valid-bit */
  423. dma_wmb();
  424. p->verb = d->verb | EQAR_VB(eqar);
  425. } else {
  426. p->verb = d->verb | EQAR_VB(eqar);
  427. dma_wmb();
  428. qbman_write_eqcr_am_rt_register(s, EQAR_IDX(eqar));
  429. }
  430. return 0;
  431. }
  432. /* Static (push) dequeue */
  433. /**
  434. * qbman_swp_push_get() - Get the push dequeue setup
  435. * @p: the software portal object
  436. * @channel_idx: the channel index to query
  437. * @enabled: returned boolean to show whether the push dequeue is enabled
  438. * for the given channel
  439. */
  440. void qbman_swp_push_get(struct qbman_swp *s, u8 channel_idx, int *enabled)
  441. {
  442. u16 src = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
  443. WARN_ON(channel_idx > 15);
  444. *enabled = src | (1 << channel_idx);
  445. }
  446. /**
  447. * qbman_swp_push_set() - Enable or disable push dequeue
  448. * @p: the software portal object
  449. * @channel_idx: the channel index (0 to 15)
  450. * @enable: enable or disable push dequeue
  451. */
  452. void qbman_swp_push_set(struct qbman_swp *s, u8 channel_idx, int enable)
  453. {
  454. u16 dqsrc;
  455. WARN_ON(channel_idx > 15);
  456. if (enable)
  457. s->sdq |= 1 << channel_idx;
  458. else
  459. s->sdq &= ~(1 << channel_idx);
  460. /* Read make the complete src map. If no channels are enabled
  461. * the SDQCR must be 0 or else QMan will assert errors
  462. */
  463. dqsrc = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
  464. if (dqsrc != 0)
  465. qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, s->sdq);
  466. else
  467. qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, 0);
  468. }
  469. #define QB_VDQCR_VERB_DCT_SHIFT 0
  470. #define QB_VDQCR_VERB_DT_SHIFT 2
  471. #define QB_VDQCR_VERB_RLS_SHIFT 4
  472. #define QB_VDQCR_VERB_WAE_SHIFT 5
  473. enum qb_pull_dt_e {
  474. qb_pull_dt_channel,
  475. qb_pull_dt_workqueue,
  476. qb_pull_dt_framequeue
  477. };
  478. /**
  479. * qbman_pull_desc_clear() - Clear the contents of a descriptor to
  480. * default/starting state
  481. * @d: the pull dequeue descriptor to be cleared
  482. */
  483. void qbman_pull_desc_clear(struct qbman_pull_desc *d)
  484. {
  485. memset(d, 0, sizeof(*d));
  486. }
  487. /**
  488. * qbman_pull_desc_set_storage()- Set the pull dequeue storage
  489. * @d: the pull dequeue descriptor to be set
  490. * @storage: the pointer of the memory to store the dequeue result
  491. * @storage_phys: the physical address of the storage memory
  492. * @stash: to indicate whether write allocate is enabled
  493. *
  494. * If not called, or if called with 'storage' as NULL, the result pull dequeues
  495. * will produce results to DQRR. If 'storage' is non-NULL, then results are
  496. * produced to the given memory location (using the DMA address which
  497. * the caller provides in 'storage_phys'), and 'stash' controls whether or not
  498. * those writes to main-memory express a cache-warming attribute.
  499. */
  500. void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
  501. struct dpaa2_dq *storage,
  502. dma_addr_t storage_phys,
  503. int stash)
  504. {
  505. /* save the virtual address */
  506. d->rsp_addr_virt = (u64)(uintptr_t)storage;
  507. if (!storage) {
  508. d->verb &= ~(1 << QB_VDQCR_VERB_RLS_SHIFT);
  509. return;
  510. }
  511. d->verb |= 1 << QB_VDQCR_VERB_RLS_SHIFT;
  512. if (stash)
  513. d->verb |= 1 << QB_VDQCR_VERB_WAE_SHIFT;
  514. else
  515. d->verb &= ~(1 << QB_VDQCR_VERB_WAE_SHIFT);
  516. d->rsp_addr = cpu_to_le64(storage_phys);
  517. }
  518. /**
  519. * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued
  520. * @d: the pull dequeue descriptor to be set
  521. * @numframes: number of frames to be set, must be between 1 and 16, inclusive
  522. */
  523. void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes)
  524. {
  525. d->numf = numframes - 1;
  526. }
  527. /*
  528. * Exactly one of the following descriptor "actions" should be set. (Calling any
  529. * one of these will replace the effect of any prior call to one of these.)
  530. * - pull dequeue from the given frame queue (FQ)
  531. * - pull dequeue from any FQ in the given work queue (WQ)
  532. * - pull dequeue from any FQ in any WQ in the given channel
  533. */
  534. /**
  535. * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues
  536. * @fqid: the frame queue index of the given FQ
  537. */
  538. void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid)
  539. {
  540. d->verb |= 1 << QB_VDQCR_VERB_DCT_SHIFT;
  541. d->verb |= qb_pull_dt_framequeue << QB_VDQCR_VERB_DT_SHIFT;
  542. d->dq_src = cpu_to_le32(fqid);
  543. }
  544. /**
  545. * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues
  546. * @wqid: composed of channel id and wqid within the channel
  547. * @dct: the dequeue command type
  548. */
  549. void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
  550. enum qbman_pull_type_e dct)
  551. {
  552. d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
  553. d->verb |= qb_pull_dt_workqueue << QB_VDQCR_VERB_DT_SHIFT;
  554. d->dq_src = cpu_to_le32(wqid);
  555. }
  556. /**
  557. * qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
  558. * dequeues
  559. * @chid: the channel id to be dequeued
  560. * @dct: the dequeue command type
  561. */
  562. void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
  563. enum qbman_pull_type_e dct)
  564. {
  565. d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
  566. d->verb |= qb_pull_dt_channel << QB_VDQCR_VERB_DT_SHIFT;
  567. d->dq_src = cpu_to_le32(chid);
  568. }
  569. /**
  570. * qbman_swp_pull() - Issue the pull dequeue command
  571. * @s: the software portal object
  572. * @d: the software portal descriptor which has been configured with
  573. * the set of qbman_pull_desc_set_*() calls
  574. *
  575. * Return 0 for success, and -EBUSY if the software portal is not ready
  576. * to do pull dequeue.
  577. */
  578. int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d)
  579. {
  580. struct qbman_pull_desc *p;
  581. if (!atomic_dec_and_test(&s->vdq.available)) {
  582. atomic_inc(&s->vdq.available);
  583. return -EBUSY;
  584. }
  585. s->vdq.storage = (void *)(uintptr_t)d->rsp_addr_virt;
  586. if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
  587. p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
  588. else
  589. p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR_MEM);
  590. p->numf = d->numf;
  591. p->tok = QMAN_DQ_TOKEN_VALID;
  592. p->dq_src = d->dq_src;
  593. p->rsp_addr = d->rsp_addr;
  594. p->rsp_addr_virt = d->rsp_addr_virt;
  595. if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
  596. dma_wmb();
  597. /* Set the verb byte, have to substitute in the valid-bit */
  598. p->verb = d->verb | s->vdq.valid_bit;
  599. s->vdq.valid_bit ^= QB_VALID_BIT;
  600. } else {
  601. p->verb = d->verb | s->vdq.valid_bit;
  602. s->vdq.valid_bit ^= QB_VALID_BIT;
  603. dma_wmb();
  604. qbman_write_register(s, QBMAN_CINH_SWP_VDQCR_RT, QMAN_RT_MODE);
  605. }
  606. return 0;
  607. }
  608. #define QMAN_DQRR_PI_MASK 0xf
  609. /**
  610. * qbman_swp_dqrr_next() - Get an valid DQRR entry
  611. * @s: the software portal object
  612. *
  613. * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
  614. * only once, so repeated calls can return a sequence of DQRR entries, without
  615. * requiring they be consumed immediately or in any particular order.
  616. */
  617. const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s)
  618. {
  619. u32 verb;
  620. u32 response_verb;
  621. u32 flags;
  622. struct dpaa2_dq *p;
  623. /* Before using valid-bit to detect if something is there, we have to
  624. * handle the case of the DQRR reset bug...
  625. */
  626. if (unlikely(s->dqrr.reset_bug)) {
  627. /*
  628. * We pick up new entries by cache-inhibited producer index,
  629. * which means that a non-coherent mapping would require us to
  630. * invalidate and read *only* once that PI has indicated that
  631. * there's an entry here. The first trip around the DQRR ring
  632. * will be much less efficient than all subsequent trips around
  633. * it...
  634. */
  635. u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
  636. QMAN_DQRR_PI_MASK;
  637. /* there are new entries if pi != next_idx */
  638. if (pi == s->dqrr.next_idx)
  639. return NULL;
  640. /*
  641. * if next_idx is/was the last ring index, and 'pi' is
  642. * different, we can disable the workaround as all the ring
  643. * entries have now been DMA'd to so valid-bit checking is
  644. * repaired. Note: this logic needs to be based on next_idx
  645. * (which increments one at a time), rather than on pi (which
  646. * can burst and wrap-around between our snapshots of it).
  647. */
  648. if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
  649. pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
  650. s->dqrr.next_idx, pi);
  651. s->dqrr.reset_bug = 0;
  652. }
  653. prefetch(qbman_get_cmd(s,
  654. QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
  655. }
  656. if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
  657. p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  658. else
  659. p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR_MEM(s->dqrr.next_idx));
  660. verb = p->dq.verb;
  661. /*
  662. * If the valid-bit isn't of the expected polarity, nothing there. Note,
  663. * in the DQRR reset bug workaround, we shouldn't need to skip these
  664. * check, because we've already determined that a new entry is available
  665. * and we've invalidated the cacheline before reading it, so the
  666. * valid-bit behaviour is repaired and should tell us what we already
  667. * knew from reading PI.
  668. */
  669. if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
  670. prefetch(qbman_get_cmd(s,
  671. QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
  672. return NULL;
  673. }
  674. /*
  675. * There's something there. Move "next_idx" attention to the next ring
  676. * entry (and prefetch it) before returning what we found.
  677. */
  678. s->dqrr.next_idx++;
  679. s->dqrr.next_idx &= s->dqrr.dqrr_size - 1; /* Wrap around */
  680. if (!s->dqrr.next_idx)
  681. s->dqrr.valid_bit ^= QB_VALID_BIT;
  682. /*
  683. * If this is the final response to a volatile dequeue command
  684. * indicate that the vdq is available
  685. */
  686. flags = p->dq.stat;
  687. response_verb = verb & QBMAN_RESULT_MASK;
  688. if ((response_verb == QBMAN_RESULT_DQ) &&
  689. (flags & DPAA2_DQ_STAT_VOLATILE) &&
  690. (flags & DPAA2_DQ_STAT_EXPIRED))
  691. atomic_inc(&s->vdq.available);
  692. prefetch(qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
  693. return p;
  694. }
  695. /**
  696. * qbman_swp_dqrr_consume() - Consume DQRR entries previously returned from
  697. * qbman_swp_dqrr_next().
  698. * @s: the software portal object
  699. * @dq: the DQRR entry to be consumed
  700. */
  701. void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq)
  702. {
  703. qbman_write_register(s, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
  704. }
  705. /**
  706. * qbman_result_has_new_result() - Check and get the dequeue response from the
  707. * dq storage memory set in pull dequeue command
  708. * @s: the software portal object
  709. * @dq: the dequeue result read from the memory
  710. *
  711. * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
  712. * dequeue result.
  713. *
  714. * Only used for user-provided storage of dequeue results, not DQRR. For
  715. * efficiency purposes, the driver will perform any required endianness
  716. * conversion to ensure that the user's dequeue result storage is in host-endian
  717. * format. As such, once the user has called qbman_result_has_new_result() and
  718. * been returned a valid dequeue result, they should not call it again on
  719. * the same memory location (except of course if another dequeue command has
  720. * been executed to produce a new result to that location).
  721. */
  722. int qbman_result_has_new_result(struct qbman_swp *s, const struct dpaa2_dq *dq)
  723. {
  724. if (dq->dq.tok != QMAN_DQ_TOKEN_VALID)
  725. return 0;
  726. /*
  727. * Set token to be 0 so we will detect change back to 1
  728. * next time the looping is traversed. Const is cast away here
  729. * as we want users to treat the dequeue responses as read only.
  730. */
  731. ((struct dpaa2_dq *)dq)->dq.tok = 0;
  732. /*
  733. * Determine whether VDQCR is available based on whether the
  734. * current result is sitting in the first storage location of
  735. * the busy command.
  736. */
  737. if (s->vdq.storage == dq) {
  738. s->vdq.storage = NULL;
  739. atomic_inc(&s->vdq.available);
  740. }
  741. return 1;
  742. }
  743. /**
  744. * qbman_release_desc_clear() - Clear the contents of a descriptor to
  745. * default/starting state.
  746. */
  747. void qbman_release_desc_clear(struct qbman_release_desc *d)
  748. {
  749. memset(d, 0, sizeof(*d));
  750. d->verb = 1 << 5; /* Release Command Valid */
  751. }
  752. /**
  753. * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
  754. */
  755. void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid)
  756. {
  757. d->bpid = cpu_to_le16(bpid);
  758. }
  759. /**
  760. * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
  761. * interrupt source should be asserted after the release command is completed.
  762. */
  763. void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable)
  764. {
  765. if (enable)
  766. d->verb |= 1 << 6;
  767. else
  768. d->verb &= ~(1 << 6);
  769. }
  770. #define RAR_IDX(rar) ((rar) & 0x7)
  771. #define RAR_VB(rar) ((rar) & 0x80)
  772. #define RAR_SUCCESS(rar) ((rar) & 0x100)
  773. /**
  774. * qbman_swp_release() - Issue a buffer release command
  775. * @s: the software portal object
  776. * @d: the release descriptor
  777. * @buffers: a pointer pointing to the buffer address to be released
  778. * @num_buffers: number of buffers to be released, must be less than 8
  779. *
  780. * Return 0 for success, -EBUSY if the release command ring is not ready.
  781. */
  782. int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
  783. const u64 *buffers, unsigned int num_buffers)
  784. {
  785. int i;
  786. struct qbman_release_desc *p;
  787. u32 rar;
  788. if (!num_buffers || (num_buffers > 7))
  789. return -EINVAL;
  790. rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
  791. if (!RAR_SUCCESS(rar))
  792. return -EBUSY;
  793. /* Start the release command */
  794. if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
  795. p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
  796. else
  797. p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR_MEM(RAR_IDX(rar)));
  798. /* Copy the caller's buffer pointers to the command */
  799. for (i = 0; i < num_buffers; i++)
  800. p->buf[i] = cpu_to_le64(buffers[i]);
  801. p->bpid = d->bpid;
  802. if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
  803. /*
  804. * Set the verb byte, have to substitute in the valid-bit
  805. * and the number of buffers.
  806. */
  807. dma_wmb();
  808. p->verb = d->verb | RAR_VB(rar) | num_buffers;
  809. } else {
  810. p->verb = d->verb | RAR_VB(rar) | num_buffers;
  811. dma_wmb();
  812. qbman_write_register(s, QBMAN_CINH_SWP_RCR_AM_RT +
  813. RAR_IDX(rar) * 4, QMAN_RT_MODE);
  814. }
  815. return 0;
  816. }
  817. struct qbman_acquire_desc {
  818. u8 verb;
  819. u8 reserved;
  820. __le16 bpid;
  821. u8 num;
  822. u8 reserved2[59];
  823. };
  824. struct qbman_acquire_rslt {
  825. u8 verb;
  826. u8 rslt;
  827. __le16 reserved;
  828. u8 num;
  829. u8 reserved2[3];
  830. __le64 buf[7];
  831. };
  832. /**
  833. * qbman_swp_acquire() - Issue a buffer acquire command
  834. * @s: the software portal object
  835. * @bpid: the buffer pool index
  836. * @buffers: a pointer pointing to the acquired buffer addresses
  837. * @num_buffers: number of buffers to be acquired, must be less than 8
  838. *
  839. * Return 0 for success, or negative error code if the acquire command
  840. * fails.
  841. */
  842. int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
  843. unsigned int num_buffers)
  844. {
  845. struct qbman_acquire_desc *p;
  846. struct qbman_acquire_rslt *r;
  847. int i;
  848. if (!num_buffers || (num_buffers > 7))
  849. return -EINVAL;
  850. /* Start the management command */
  851. p = qbman_swp_mc_start(s);
  852. if (!p)
  853. return -EBUSY;
  854. /* Encode the caller-provided attributes */
  855. p->bpid = cpu_to_le16(bpid);
  856. p->num = num_buffers;
  857. /* Complete the management command */
  858. r = qbman_swp_mc_complete(s, p, QBMAN_MC_ACQUIRE);
  859. if (unlikely(!r)) {
  860. pr_err("qbman: acquire from BPID %d failed, no response\n",
  861. bpid);
  862. return -EIO;
  863. }
  864. /* Decode the outcome */
  865. WARN_ON((r->verb & 0x7f) != QBMAN_MC_ACQUIRE);
  866. /* Determine success or failure */
  867. if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
  868. pr_err("qbman: acquire from BPID 0x%x failed, code=0x%02x\n",
  869. bpid, r->rslt);
  870. return -EIO;
  871. }
  872. WARN_ON(r->num > num_buffers);
  873. /* Copy the acquired buffers to the caller's array */
  874. for (i = 0; i < r->num; i++)
  875. buffers[i] = le64_to_cpu(r->buf[i]);
  876. return (int)r->num;
  877. }
  878. struct qbman_alt_fq_state_desc {
  879. u8 verb;
  880. u8 reserved[3];
  881. __le32 fqid;
  882. u8 reserved2[56];
  883. };
  884. struct qbman_alt_fq_state_rslt {
  885. u8 verb;
  886. u8 rslt;
  887. u8 reserved[62];
  888. };
  889. #define ALT_FQ_FQID_MASK 0x00FFFFFF
  890. int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
  891. u8 alt_fq_verb)
  892. {
  893. struct qbman_alt_fq_state_desc *p;
  894. struct qbman_alt_fq_state_rslt *r;
  895. /* Start the management command */
  896. p = qbman_swp_mc_start(s);
  897. if (!p)
  898. return -EBUSY;
  899. p->fqid = cpu_to_le32(fqid & ALT_FQ_FQID_MASK);
  900. /* Complete the management command */
  901. r = qbman_swp_mc_complete(s, p, alt_fq_verb);
  902. if (unlikely(!r)) {
  903. pr_err("qbman: mgmt cmd failed, no response (verb=0x%x)\n",
  904. alt_fq_verb);
  905. return -EIO;
  906. }
  907. /* Decode the outcome */
  908. WARN_ON((r->verb & QBMAN_RESULT_MASK) != alt_fq_verb);
  909. /* Determine success or failure */
  910. if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
  911. pr_err("qbman: ALT FQID %d failed: verb = 0x%08x code = 0x%02x\n",
  912. fqid, r->verb, r->rslt);
  913. return -EIO;
  914. }
  915. return 0;
  916. }
  917. struct qbman_cdan_ctrl_desc {
  918. u8 verb;
  919. u8 reserved;
  920. __le16 ch;
  921. u8 we;
  922. u8 ctrl;
  923. __le16 reserved2;
  924. __le64 cdan_ctx;
  925. u8 reserved3[48];
  926. };
  927. struct qbman_cdan_ctrl_rslt {
  928. u8 verb;
  929. u8 rslt;
  930. __le16 ch;
  931. u8 reserved[60];
  932. };
  933. int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
  934. u8 we_mask, u8 cdan_en,
  935. u64 ctx)
  936. {
  937. struct qbman_cdan_ctrl_desc *p = NULL;
  938. struct qbman_cdan_ctrl_rslt *r = NULL;
  939. /* Start the management command */
  940. p = qbman_swp_mc_start(s);
  941. if (!p)
  942. return -EBUSY;
  943. /* Encode the caller-provided attributes */
  944. p->ch = cpu_to_le16(channelid);
  945. p->we = we_mask;
  946. if (cdan_en)
  947. p->ctrl = 1;
  948. else
  949. p->ctrl = 0;
  950. p->cdan_ctx = cpu_to_le64(ctx);
  951. /* Complete the management command */
  952. r = qbman_swp_mc_complete(s, p, QBMAN_WQCHAN_CONFIGURE);
  953. if (unlikely(!r)) {
  954. pr_err("qbman: wqchan config failed, no response\n");
  955. return -EIO;
  956. }
  957. WARN_ON((r->verb & 0x7f) != QBMAN_WQCHAN_CONFIGURE);
  958. /* Determine success or failure */
  959. if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
  960. pr_err("qbman: CDAN cQID %d failed: code = 0x%02x\n",
  961. channelid, r->rslt);
  962. return -EIO;
  963. }
  964. return 0;
  965. }
  966. #define QBMAN_RESPONSE_VERB_MASK 0x7f
  967. #define QBMAN_FQ_QUERY_NP 0x45
  968. #define QBMAN_BP_QUERY 0x32
  969. struct qbman_fq_query_desc {
  970. u8 verb;
  971. u8 reserved[3];
  972. __le32 fqid;
  973. u8 reserved2[56];
  974. };
  975. int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
  976. struct qbman_fq_query_np_rslt *r)
  977. {
  978. struct qbman_fq_query_desc *p;
  979. void *resp;
  980. p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
  981. if (!p)
  982. return -EBUSY;
  983. /* FQID is a 24 bit value */
  984. p->fqid = cpu_to_le32(fqid & 0x00FFFFFF);
  985. resp = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
  986. if (!resp) {
  987. pr_err("qbman: Query FQID %d NP fields failed, no response\n",
  988. fqid);
  989. return -EIO;
  990. }
  991. *r = *(struct qbman_fq_query_np_rslt *)resp;
  992. /* Decode the outcome */
  993. WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
  994. /* Determine success or failure */
  995. if (r->rslt != QBMAN_MC_RSLT_OK) {
  996. pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
  997. p->fqid, r->rslt);
  998. return -EIO;
  999. }
  1000. return 0;
  1001. }
  1002. u32 qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
  1003. {
  1004. return (le32_to_cpu(r->frm_cnt) & 0x00FFFFFF);
  1005. }
  1006. u32 qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
  1007. {
  1008. return le32_to_cpu(r->byte_cnt);
  1009. }
  1010. struct qbman_bp_query_desc {
  1011. u8 verb;
  1012. u8 reserved;
  1013. __le16 bpid;
  1014. u8 reserved2[60];
  1015. };
  1016. int qbman_bp_query(struct qbman_swp *s, u16 bpid,
  1017. struct qbman_bp_query_rslt *r)
  1018. {
  1019. struct qbman_bp_query_desc *p;
  1020. void *resp;
  1021. p = (struct qbman_bp_query_desc *)qbman_swp_mc_start(s);
  1022. if (!p)
  1023. return -EBUSY;
  1024. p->bpid = cpu_to_le16(bpid);
  1025. resp = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
  1026. if (!resp) {
  1027. pr_err("qbman: Query BPID %d fields failed, no response\n",
  1028. bpid);
  1029. return -EIO;
  1030. }
  1031. *r = *(struct qbman_bp_query_rslt *)resp;
  1032. /* Decode the outcome */
  1033. WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_BP_QUERY);
  1034. /* Determine success or failure */
  1035. if (r->rslt != QBMAN_MC_RSLT_OK) {
  1036. pr_err("Query fields of BPID 0x%x failed, code=0x%02x\n",
  1037. bpid, r->rslt);
  1038. return -EIO;
  1039. }
  1040. return 0;
  1041. }
  1042. u32 qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt *a)
  1043. {
  1044. return le32_to_cpu(a->fill);
  1045. }