qbman_portal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * Copyright (C) 2014 Freescale Semiconductor
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include "qbman_portal.h"
  7. /* QBMan portal management command codes */
  8. #define QBMAN_MC_ACQUIRE 0x30
  9. #define QBMAN_WQCHAN_CONFIGURE 0x46
  10. /* CINH register offsets */
  11. #define QBMAN_CINH_SWP_EQAR 0x8c0
  12. #define QBMAN_CINH_SWP_DCAP 0xac0
  13. #define QBMAN_CINH_SWP_SDQCR 0xb00
  14. #define QBMAN_CINH_SWP_RAR 0xcc0
  15. /* CENA register offsets */
  16. #define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((uint32_t)(n) << 6))
  17. #define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((uint32_t)(n) << 6))
  18. #define QBMAN_CENA_SWP_RCR(n) (0x400 + ((uint32_t)(n) << 6))
  19. #define QBMAN_CENA_SWP_CR 0x600
  20. #define QBMAN_CENA_SWP_RR(vb) (0x700 + ((uint32_t)(vb) >> 1))
  21. #define QBMAN_CENA_SWP_VDQCR 0x780
  22. /* Reverse mapping of QBMAN_CENA_SWP_DQRR() */
  23. #define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)p & 0xff) >> 6)
  24. /*******************************/
  25. /* Pre-defined attribute codes */
  26. /*******************************/
  27. struct qb_attr_code code_generic_verb = QB_CODE(0, 0, 7);
  28. struct qb_attr_code code_generic_rslt = QB_CODE(0, 8, 8);
  29. /*************************/
  30. /* SDQCR attribute codes */
  31. /*************************/
  32. /* we put these here because at least some of them are required by
  33. * qbman_swp_init() */
  34. struct qb_attr_code code_sdqcr_dct = QB_CODE(0, 24, 2);
  35. struct qb_attr_code code_sdqcr_fc = QB_CODE(0, 29, 1);
  36. struct qb_attr_code code_sdqcr_tok = QB_CODE(0, 16, 8);
  37. #define CODE_SDQCR_DQSRC(n) QB_CODE(0, n, 1)
  38. enum qbman_sdqcr_dct {
  39. qbman_sdqcr_dct_null = 0,
  40. qbman_sdqcr_dct_prio_ics,
  41. qbman_sdqcr_dct_active_ics,
  42. qbman_sdqcr_dct_active
  43. };
  44. enum qbman_sdqcr_fc {
  45. qbman_sdqcr_fc_one = 0,
  46. qbman_sdqcr_fc_up_to_3 = 1
  47. };
  48. /*********************************/
  49. /* Portal constructor/destructor */
  50. /*********************************/
  51. /* Software portals should always be in the power-on state when we initialise,
  52. * due to the CCSR-based portal reset functionality that MC has. */
  53. struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
  54. {
  55. int ret;
  56. struct qbman_swp *p = malloc(sizeof(struct qbman_swp));
  57. if (!p)
  58. return NULL;
  59. p->desc = d;
  60. #ifdef QBMAN_CHECKING
  61. p->mc.check = swp_mc_can_start;
  62. #endif
  63. p->mc.valid_bit = QB_VALID_BIT;
  64. p->sdq = 0;
  65. qb_attr_code_encode(&code_sdqcr_dct, &p->sdq, qbman_sdqcr_dct_prio_ics);
  66. qb_attr_code_encode(&code_sdqcr_fc, &p->sdq, qbman_sdqcr_fc_up_to_3);
  67. qb_attr_code_encode(&code_sdqcr_tok, &p->sdq, 0xbb);
  68. atomic_set(&p->vdq.busy, 1);
  69. p->vdq.valid_bit = QB_VALID_BIT;
  70. p->dqrr.next_idx = 0;
  71. p->dqrr.valid_bit = QB_VALID_BIT;
  72. ret = qbman_swp_sys_init(&p->sys, d);
  73. if (ret) {
  74. free(p);
  75. printf("qbman_swp_sys_init() failed %d\n", ret);
  76. return NULL;
  77. }
  78. qbman_cinh_write(&p->sys, QBMAN_CINH_SWP_SDQCR, p->sdq);
  79. return p;
  80. }
  81. /***********************/
  82. /* Management commands */
  83. /***********************/
  84. /*
  85. * Internal code common to all types of management commands.
  86. */
  87. void *qbman_swp_mc_start(struct qbman_swp *p)
  88. {
  89. void *ret;
  90. int *return_val;
  91. #ifdef QBMAN_CHECKING
  92. BUG_ON(p->mc.check != swp_mc_can_start);
  93. #endif
  94. ret = qbman_cena_write_start(&p->sys, QBMAN_CENA_SWP_CR);
  95. #ifdef QBMAN_CHECKING
  96. return_val = (int *)ret;
  97. if (!(*return_val))
  98. p->mc.check = swp_mc_can_submit;
  99. #endif
  100. return ret;
  101. }
  102. void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, uint32_t cmd_verb)
  103. {
  104. uint32_t *v = cmd;
  105. #ifdef QBMAN_CHECKING
  106. BUG_ON(p->mc.check != swp_mc_can_submit);
  107. #endif
  108. lwsync();
  109. /* TBD: "|=" is going to hurt performance. Need to move as many fields
  110. * out of word zero, and for those that remain, the "OR" needs to occur
  111. * at the caller side. This debug check helps to catch cases where the
  112. * caller wants to OR but has forgotten to do so. */
  113. BUG_ON((*v & cmd_verb) != *v);
  114. *v = cmd_verb | p->mc.valid_bit;
  115. qbman_cena_write_complete(&p->sys, QBMAN_CENA_SWP_CR, cmd);
  116. /* TODO: add prefetch support for GPP */
  117. #ifdef QBMAN_CHECKING
  118. p->mc.check = swp_mc_can_poll;
  119. #endif
  120. }
  121. void *qbman_swp_mc_result(struct qbman_swp *p)
  122. {
  123. uint32_t *ret, verb;
  124. #ifdef QBMAN_CHECKING
  125. BUG_ON(p->mc.check != swp_mc_can_poll);
  126. #endif
  127. ret = qbman_cena_read(&p->sys, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
  128. /* Remove the valid-bit - command completed iff the rest is non-zero */
  129. verb = ret[0] & ~QB_VALID_BIT;
  130. if (!verb)
  131. return NULL;
  132. #ifdef QBMAN_CHECKING
  133. p->mc.check = swp_mc_can_start;
  134. #endif
  135. p->mc.valid_bit ^= QB_VALID_BIT;
  136. return ret;
  137. }
  138. /***********/
  139. /* Enqueue */
  140. /***********/
  141. /* These should be const, eventually */
  142. static struct qb_attr_code code_eq_cmd = QB_CODE(0, 0, 2);
  143. static struct qb_attr_code code_eq_orp_en = QB_CODE(0, 2, 1);
  144. static struct qb_attr_code code_eq_tgt_id = QB_CODE(2, 0, 24);
  145. /* static struct qb_attr_code code_eq_tag = QB_CODE(3, 0, 32); */
  146. static struct qb_attr_code code_eq_qd_en = QB_CODE(0, 4, 1);
  147. static struct qb_attr_code code_eq_qd_bin = QB_CODE(4, 0, 16);
  148. static struct qb_attr_code code_eq_qd_pri = QB_CODE(4, 16, 4);
  149. static struct qb_attr_code code_eq_rsp_stash = QB_CODE(5, 16, 1);
  150. static struct qb_attr_code code_eq_rsp_lo = QB_CODE(6, 0, 32);
  151. enum qbman_eq_cmd_e {
  152. /* No enqueue, primarily for plugging ORP gaps for dropped frames */
  153. qbman_eq_cmd_empty,
  154. /* DMA an enqueue response once complete */
  155. qbman_eq_cmd_respond,
  156. /* DMA an enqueue response only if the enqueue fails */
  157. qbman_eq_cmd_respond_reject
  158. };
  159. void qbman_eq_desc_clear(struct qbman_eq_desc *d)
  160. {
  161. memset(d, 0, sizeof(*d));
  162. }
  163. void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
  164. {
  165. uint32_t *cl = qb_cl(d);
  166. qb_attr_code_encode(&code_eq_orp_en, cl, 0);
  167. qb_attr_code_encode(&code_eq_cmd, cl,
  168. respond_success ? qbman_eq_cmd_respond :
  169. qbman_eq_cmd_respond_reject);
  170. }
  171. void qbman_eq_desc_set_response(struct qbman_eq_desc *d,
  172. dma_addr_t storage_phys,
  173. int stash)
  174. {
  175. uint32_t *cl = qb_cl(d);
  176. qb_attr_code_encode_64(&code_eq_rsp_lo, (uint64_t *)cl, storage_phys);
  177. qb_attr_code_encode(&code_eq_rsp_stash, cl, !!stash);
  178. }
  179. void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, uint32_t qdid,
  180. uint32_t qd_bin, uint32_t qd_prio)
  181. {
  182. uint32_t *cl = qb_cl(d);
  183. qb_attr_code_encode(&code_eq_qd_en, cl, 1);
  184. qb_attr_code_encode(&code_eq_tgt_id, cl, qdid);
  185. qb_attr_code_encode(&code_eq_qd_bin, cl, qd_bin);
  186. qb_attr_code_encode(&code_eq_qd_pri, cl, qd_prio);
  187. }
  188. #define EQAR_IDX(eqar) ((eqar) & 0x7)
  189. #define EQAR_VB(eqar) ((eqar) & 0x80)
  190. #define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
  191. int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
  192. const struct qbman_fd *fd)
  193. {
  194. uint32_t *p;
  195. const uint32_t *cl = qb_cl(d);
  196. uint32_t eqar = qbman_cinh_read(&s->sys, QBMAN_CINH_SWP_EQAR);
  197. debug("EQAR=%08x\n", eqar);
  198. if (!EQAR_SUCCESS(eqar))
  199. return -EBUSY;
  200. p = qbman_cena_write_start(&s->sys,
  201. QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)));
  202. word_copy(&p[1], &cl[1], 7);
  203. word_copy(&p[8], fd, sizeof(*fd) >> 2);
  204. lwsync();
  205. /* Set the verb byte, have to substitute in the valid-bit */
  206. p[0] = cl[0] | EQAR_VB(eqar);
  207. qbman_cena_write_complete(&s->sys,
  208. QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)),
  209. p);
  210. return 0;
  211. }
  212. /***************************/
  213. /* Volatile (pull) dequeue */
  214. /***************************/
  215. /* These should be const, eventually */
  216. static struct qb_attr_code code_pull_dct = QB_CODE(0, 0, 2);
  217. static struct qb_attr_code code_pull_dt = QB_CODE(0, 2, 2);
  218. static struct qb_attr_code code_pull_rls = QB_CODE(0, 4, 1);
  219. static struct qb_attr_code code_pull_stash = QB_CODE(0, 5, 1);
  220. static struct qb_attr_code code_pull_numframes = QB_CODE(0, 8, 4);
  221. static struct qb_attr_code code_pull_token = QB_CODE(0, 16, 8);
  222. static struct qb_attr_code code_pull_dqsource = QB_CODE(1, 0, 24);
  223. static struct qb_attr_code code_pull_rsp_lo = QB_CODE(2, 0, 32);
  224. enum qb_pull_dt_e {
  225. qb_pull_dt_channel,
  226. qb_pull_dt_workqueue,
  227. qb_pull_dt_framequeue
  228. };
  229. void qbman_pull_desc_clear(struct qbman_pull_desc *d)
  230. {
  231. memset(d, 0, sizeof(*d));
  232. }
  233. void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
  234. struct ldpaa_dq *storage,
  235. dma_addr_t storage_phys,
  236. int stash)
  237. {
  238. uint32_t *cl = qb_cl(d);
  239. /* Squiggle the pointer 'storage' into the extra 2 words of the
  240. * descriptor (which aren't copied to the hw command) */
  241. *(void **)&cl[4] = storage;
  242. if (!storage) {
  243. qb_attr_code_encode(&code_pull_rls, cl, 0);
  244. return;
  245. }
  246. qb_attr_code_encode(&code_pull_rls, cl, 1);
  247. qb_attr_code_encode(&code_pull_stash, cl, !!stash);
  248. qb_attr_code_encode_64(&code_pull_rsp_lo, (uint64_t *)cl, storage_phys);
  249. }
  250. void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, uint8_t numframes)
  251. {
  252. uint32_t *cl = qb_cl(d);
  253. BUG_ON(!numframes || (numframes > 16));
  254. qb_attr_code_encode(&code_pull_numframes, cl,
  255. (uint32_t)(numframes - 1));
  256. }
  257. void qbman_pull_desc_set_token(struct qbman_pull_desc *d, uint8_t token)
  258. {
  259. uint32_t *cl = qb_cl(d);
  260. qb_attr_code_encode(&code_pull_token, cl, token);
  261. }
  262. void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, uint32_t fqid)
  263. {
  264. uint32_t *cl = qb_cl(d);
  265. qb_attr_code_encode(&code_pull_dct, cl, 1);
  266. qb_attr_code_encode(&code_pull_dt, cl, qb_pull_dt_framequeue);
  267. qb_attr_code_encode(&code_pull_dqsource, cl, fqid);
  268. }
  269. int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d)
  270. {
  271. uint32_t *p;
  272. uint32_t *cl = qb_cl(d);
  273. if (!atomic_dec_and_test(&s->vdq.busy)) {
  274. atomic_inc(&s->vdq.busy);
  275. return -EBUSY;
  276. }
  277. s->vdq.storage = *(void **)&cl[4];
  278. s->vdq.token = qb_attr_code_decode(&code_pull_token, cl);
  279. p = qbman_cena_write_start(&s->sys, QBMAN_CENA_SWP_VDQCR);
  280. word_copy(&p[1], &cl[1], 3);
  281. lwsync();
  282. /* Set the verb byte, have to substitute in the valid-bit */
  283. p[0] = cl[0] | s->vdq.valid_bit;
  284. s->vdq.valid_bit ^= QB_VALID_BIT;
  285. qbman_cena_write_complete(&s->sys, QBMAN_CENA_SWP_VDQCR, p);
  286. return 0;
  287. }
  288. /****************/
  289. /* Polling DQRR */
  290. /****************/
  291. static struct qb_attr_code code_dqrr_verb = QB_CODE(0, 0, 8);
  292. static struct qb_attr_code code_dqrr_response = QB_CODE(0, 0, 7);
  293. static struct qb_attr_code code_dqrr_stat = QB_CODE(0, 8, 8);
  294. #define QBMAN_DQRR_RESPONSE_DQ 0x60
  295. #define QBMAN_DQRR_RESPONSE_FQRN 0x21
  296. #define QBMAN_DQRR_RESPONSE_FQRNI 0x22
  297. #define QBMAN_DQRR_RESPONSE_FQPN 0x24
  298. #define QBMAN_DQRR_RESPONSE_FQDAN 0x25
  299. #define QBMAN_DQRR_RESPONSE_CDAN 0x26
  300. #define QBMAN_DQRR_RESPONSE_CSCN_MEM 0x27
  301. #define QBMAN_DQRR_RESPONSE_CGCU 0x28
  302. #define QBMAN_DQRR_RESPONSE_BPSCN 0x29
  303. #define QBMAN_DQRR_RESPONSE_CSCN_WQ 0x2a
  304. /* NULL return if there are no unconsumed DQRR entries. Returns a DQRR entry
  305. * only once, so repeated calls can return a sequence of DQRR entries, without
  306. * requiring they be consumed immediately or in any particular order. */
  307. const struct ldpaa_dq *qbman_swp_dqrr_next(struct qbman_swp *s)
  308. {
  309. uint32_t verb;
  310. uint32_t response_verb;
  311. uint32_t flags;
  312. const struct ldpaa_dq *dq;
  313. const uint32_t *p;
  314. dq = qbman_cena_read(&s->sys, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  315. p = qb_cl(dq);
  316. verb = qb_attr_code_decode(&code_dqrr_verb, p);
  317. /* If the valid-bit isn't of the expected polarity, nothing there. Note,
  318. * in the DQRR reset bug workaround, we shouldn't need to skip these
  319. * check, because we've already determined that a new entry is available
  320. * and we've invalidated the cacheline before reading it, so the
  321. * valid-bit behaviour is repaired and should tell us what we already
  322. * knew from reading PI.
  323. */
  324. if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
  325. qbman_cena_invalidate_prefetch(&s->sys,
  326. QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  327. return NULL;
  328. }
  329. /* There's something there. Move "next_idx" attention to the next ring
  330. * entry (and prefetch it) before returning what we found. */
  331. s->dqrr.next_idx++;
  332. s->dqrr.next_idx &= QBMAN_DQRR_SIZE - 1; /* Wrap around at 4 */
  333. /* TODO: it's possible to do all this without conditionals, optimise it
  334. * later. */
  335. if (!s->dqrr.next_idx)
  336. s->dqrr.valid_bit ^= QB_VALID_BIT;
  337. /* If this is the final response to a volatile dequeue command
  338. indicate that the vdq is no longer busy */
  339. flags = ldpaa_dq_flags(dq);
  340. response_verb = qb_attr_code_decode(&code_dqrr_response, &verb);
  341. if ((response_verb == QBMAN_DQRR_RESPONSE_DQ) &&
  342. (flags & LDPAA_DQ_STAT_VOLATILE) &&
  343. (flags & LDPAA_DQ_STAT_EXPIRED))
  344. atomic_inc(&s->vdq.busy);
  345. qbman_cena_invalidate_prefetch(&s->sys,
  346. QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  347. return dq;
  348. }
  349. /* Consume DQRR entries previously returned from qbman_swp_dqrr_next(). */
  350. void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct ldpaa_dq *dq)
  351. {
  352. qbman_cinh_write(&s->sys, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
  353. }
  354. /*********************************/
  355. /* Polling user-provided storage */
  356. /*********************************/
  357. void qbman_dq_entry_set_oldtoken(struct ldpaa_dq *dq,
  358. unsigned int num_entries,
  359. uint8_t oldtoken)
  360. {
  361. memset(dq, oldtoken, num_entries * sizeof(*dq));
  362. }
  363. int qbman_dq_entry_has_newtoken(struct qbman_swp *s,
  364. const struct ldpaa_dq *dq,
  365. uint8_t newtoken)
  366. {
  367. /* To avoid converting the little-endian DQ entry to host-endian prior
  368. * to us knowing whether there is a valid entry or not (and run the
  369. * risk of corrupting the incoming hardware LE write), we detect in
  370. * hardware endianness rather than host. This means we need a different
  371. * "code" depending on whether we are BE or LE in software, which is
  372. * where DQRR_TOK_OFFSET comes in... */
  373. static struct qb_attr_code code_dqrr_tok_detect =
  374. QB_CODE(0, DQRR_TOK_OFFSET, 8);
  375. /* The user trying to poll for a result treats "dq" as const. It is
  376. * however the same address that was provided to us non-const in the
  377. * first place, for directing hardware DMA to. So we can cast away the
  378. * const because it is mutable from our perspective. */
  379. uint32_t *p = qb_cl((struct ldpaa_dq *)dq);
  380. uint32_t token;
  381. token = qb_attr_code_decode(&code_dqrr_tok_detect, &p[1]);
  382. if (token != newtoken)
  383. return 0;
  384. /* Only now do we convert from hardware to host endianness. Also, as we
  385. * are returning success, the user has promised not to call us again, so
  386. * there's no risk of us converting the endianness twice... */
  387. make_le32_n(p, 16);
  388. /* VDQCR "no longer busy" hook - not quite the same as DQRR, because the
  389. * fact "VDQCR" shows busy doesn't mean that the result we're looking at
  390. * is from the same command. Eg. we may be looking at our 10th dequeue
  391. * result from our first VDQCR command, yet the second dequeue command
  392. * could have been kicked off already, after seeing the 1st result. Ie.
  393. * the result we're looking at is not necessarily proof that we can
  394. * reset "busy". We instead base the decision on whether the current
  395. * result is sitting at the first 'storage' location of the busy
  396. * command. */
  397. if (s->vdq.storage == dq) {
  398. s->vdq.storage = NULL;
  399. atomic_inc(&s->vdq.busy);
  400. }
  401. return 1;
  402. }
  403. /********************************/
  404. /* Categorising dequeue entries */
  405. /********************************/
  406. static inline int __qbman_dq_entry_is_x(const struct ldpaa_dq *dq, uint32_t x)
  407. {
  408. const uint32_t *p = qb_cl(dq);
  409. uint32_t response_verb = qb_attr_code_decode(&code_dqrr_response, p);
  410. return response_verb == x;
  411. }
  412. int qbman_dq_entry_is_DQ(const struct ldpaa_dq *dq)
  413. {
  414. return __qbman_dq_entry_is_x(dq, QBMAN_DQRR_RESPONSE_DQ);
  415. }
  416. /*********************************/
  417. /* Parsing frame dequeue results */
  418. /*********************************/
  419. /* These APIs assume qbman_dq_entry_is_DQ() is TRUE */
  420. uint32_t ldpaa_dq_flags(const struct ldpaa_dq *dq)
  421. {
  422. const uint32_t *p = qb_cl(dq);
  423. return qb_attr_code_decode(&code_dqrr_stat, p);
  424. }
  425. const struct dpaa_fd *ldpaa_dq_fd(const struct ldpaa_dq *dq)
  426. {
  427. const uint32_t *p = qb_cl(dq);
  428. return (const struct dpaa_fd *)&p[8];
  429. }
  430. /******************/
  431. /* Buffer release */
  432. /******************/
  433. /* These should be const, eventually */
  434. /* static struct qb_attr_code code_release_num = QB_CODE(0, 0, 3); */
  435. static struct qb_attr_code code_release_set_me = QB_CODE(0, 5, 1);
  436. static struct qb_attr_code code_release_bpid = QB_CODE(0, 16, 16);
  437. void qbman_release_desc_clear(struct qbman_release_desc *d)
  438. {
  439. uint32_t *cl;
  440. memset(d, 0, sizeof(*d));
  441. cl = qb_cl(d);
  442. qb_attr_code_encode(&code_release_set_me, cl, 1);
  443. }
  444. void qbman_release_desc_set_bpid(struct qbman_release_desc *d, uint32_t bpid)
  445. {
  446. uint32_t *cl = qb_cl(d);
  447. qb_attr_code_encode(&code_release_bpid, cl, bpid);
  448. }
  449. #define RAR_IDX(rar) ((rar) & 0x7)
  450. #define RAR_VB(rar) ((rar) & 0x80)
  451. #define RAR_SUCCESS(rar) ((rar) & 0x100)
  452. int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
  453. const uint64_t *buffers, unsigned int num_buffers)
  454. {
  455. uint32_t *p;
  456. const uint32_t *cl = qb_cl(d);
  457. uint32_t rar = qbman_cinh_read(&s->sys, QBMAN_CINH_SWP_RAR);
  458. debug("RAR=%08x\n", rar);
  459. if (!RAR_SUCCESS(rar))
  460. return -EBUSY;
  461. BUG_ON(!num_buffers || (num_buffers > 7));
  462. /* Start the release command */
  463. p = qbman_cena_write_start(&s->sys,
  464. QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
  465. /* Copy the caller's buffer pointers to the command */
  466. u64_to_le32_copy(&p[2], buffers, num_buffers);
  467. lwsync();
  468. /* Set the verb byte, have to substitute in the valid-bit and the number
  469. * of buffers. */
  470. p[0] = cl[0] | RAR_VB(rar) | num_buffers;
  471. qbman_cena_write_complete(&s->sys,
  472. QBMAN_CENA_SWP_RCR(RAR_IDX(rar)),
  473. p);
  474. return 0;
  475. }
  476. /*******************/
  477. /* Buffer acquires */
  478. /*******************/
  479. /* These should be const, eventually */
  480. static struct qb_attr_code code_acquire_bpid = QB_CODE(0, 16, 16);
  481. static struct qb_attr_code code_acquire_num = QB_CODE(1, 0, 3);
  482. static struct qb_attr_code code_acquire_r_num = QB_CODE(1, 0, 3);
  483. int qbman_swp_acquire(struct qbman_swp *s, uint32_t bpid, uint64_t *buffers,
  484. unsigned int num_buffers)
  485. {
  486. uint32_t *p;
  487. uint32_t verb, rslt, num;
  488. BUG_ON(!num_buffers || (num_buffers > 7));
  489. /* Start the management command */
  490. p = qbman_swp_mc_start(s);
  491. if (!p)
  492. return -EBUSY;
  493. /* Encode the caller-provided attributes */
  494. qb_attr_code_encode(&code_acquire_bpid, p, bpid);
  495. qb_attr_code_encode(&code_acquire_num, p, num_buffers);
  496. /* Complete the management command */
  497. p = qbman_swp_mc_complete(s, p, p[0] | QBMAN_MC_ACQUIRE);
  498. /* Decode the outcome */
  499. verb = qb_attr_code_decode(&code_generic_verb, p);
  500. rslt = qb_attr_code_decode(&code_generic_rslt, p);
  501. num = qb_attr_code_decode(&code_acquire_r_num, p);
  502. BUG_ON(verb != QBMAN_MC_ACQUIRE);
  503. /* Determine success or failure */
  504. if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
  505. printf("Acquire buffers from BPID 0x%x failed, code=0x%02x\n",
  506. bpid, rslt);
  507. return -EIO;
  508. }
  509. BUG_ON(num > num_buffers);
  510. /* Copy the acquired buffers to the caller's array */
  511. u64_from_le32_copy(buffers, &p[2], num);
  512. return (int)num;
  513. }