qbman_portal.c 18 KB

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