qbman_sys.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2014 Freescale Semiconductor
  4. */
  5. /* qbman_sys_decl.h and qbman_sys.h are the two platform-specific files in the
  6. * driver. They are only included via qbman_private.h, which is itself a
  7. * platform-independent file and is included by all the other driver source.
  8. *
  9. * qbman_sys_decl.h is included prior to all other declarations and logic, and
  10. * it exists to provide compatibility with any linux interfaces our
  11. * single-source driver code is dependent on (eg. kmalloc). Ie. this file
  12. * provides linux compatibility.
  13. *
  14. * This qbman_sys.h header, on the other hand, is included *after* any common
  15. * and platform-neutral declarations and logic in qbman_private.h, and exists to
  16. * implement any platform-specific logic of the qbman driver itself. Ie. it is
  17. * *not* to provide linux compatibility.
  18. */
  19. /* Trace the 3 different classes of read/write access to QBMan. #undef as
  20. * required. */
  21. #undef QBMAN_CCSR_TRACE
  22. #undef QBMAN_CINH_TRACE
  23. #undef QBMAN_CENA_TRACE
  24. /* Temporarily define this to get around the fact that cache enabled mapping is
  25. * not working right now. Will remove this after uboot could map the cache
  26. * enabled portal memory.
  27. */
  28. #define QBMAN_CINH_ONLY
  29. static inline void word_copy(void *d, const void *s, unsigned int cnt)
  30. {
  31. uint32_t *dd = d;
  32. const uint32_t *ss = s;
  33. while (cnt--)
  34. *(dd++) = *(ss++);
  35. }
  36. /* Currently, the CENA support code expects each 32-bit word to be written in
  37. * host order, and these are converted to hardware (little-endian) order on
  38. * command submission. However, 64-bit quantities are must be written (and read)
  39. * as two 32-bit words with the least-significant word first, irrespective of
  40. * host endianness. */
  41. static inline void u64_to_le32_copy(void *d, const uint64_t *s,
  42. unsigned int cnt)
  43. {
  44. uint32_t *dd = d;
  45. const uint32_t *ss = (const uint32_t *)s;
  46. while (cnt--) {
  47. /* TBD: the toolchain was choking on the use of 64-bit types up
  48. * until recently so this works entirely with 32-bit variables.
  49. * When 64-bit types become usable again, investigate better
  50. * ways of doing this. */
  51. #if defined(__BIG_ENDIAN)
  52. *(dd++) = ss[1];
  53. *(dd++) = ss[0];
  54. ss += 2;
  55. #else
  56. *(dd++) = *(ss++);
  57. *(dd++) = *(ss++);
  58. #endif
  59. }
  60. }
  61. static inline void u64_from_le32_copy(uint64_t *d, const void *s,
  62. unsigned int cnt)
  63. {
  64. const uint32_t *ss = s;
  65. uint32_t *dd = (uint32_t *)d;
  66. while (cnt--) {
  67. #if defined(__BIG_ENDIAN)
  68. dd[1] = *(ss++);
  69. dd[0] = *(ss++);
  70. dd += 2;
  71. #else
  72. *(dd++) = *(ss++);
  73. *(dd++) = *(ss++);
  74. #endif
  75. }
  76. }
  77. /* Convert a host-native 32bit value into little endian */
  78. #if defined(__BIG_ENDIAN)
  79. static inline uint32_t make_le32(uint32_t val)
  80. {
  81. return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
  82. ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
  83. }
  84. #else
  85. #define make_le32(val) (val)
  86. #endif
  87. static inline void make_le32_n(uint32_t *val, unsigned int num)
  88. {
  89. while (num--) {
  90. *val = make_le32(*val);
  91. val++;
  92. }
  93. }
  94. /******************/
  95. /* Portal access */
  96. /******************/
  97. struct qbman_swp_sys {
  98. /* On GPP, the sys support for qbman_swp is here. The CENA region isi
  99. * not an mmap() of the real portal registers, but an allocated
  100. * place-holder, because the actual writes/reads to/from the portal are
  101. * marshalled from these allocated areas using QBMan's "MC access
  102. * registers". CINH accesses are atomic so there's no need for a
  103. * place-holder. */
  104. void *cena;
  105. void __iomem *addr_cena;
  106. void __iomem *addr_cinh;
  107. };
  108. /* P_OFFSET is (ACCESS_CMD,0,12) - offset within the portal
  109. * C is (ACCESS_CMD,12,1) - is inhibited? (0==CENA, 1==CINH)
  110. * SWP_IDX is (ACCESS_CMD,16,10) - Software portal index
  111. * P is (ACCESS_CMD,28,1) - (0==special portal, 1==any portal)
  112. * T is (ACCESS_CMD,29,1) - Command type (0==READ, 1==WRITE)
  113. * E is (ACCESS_CMD,31,1) - Command execute (1 to issue, poll for 0==complete)
  114. */
  115. static inline void qbman_cinh_write(struct qbman_swp_sys *s, uint32_t offset,
  116. uint32_t val)
  117. {
  118. __raw_writel(val, s->addr_cinh + offset);
  119. #ifdef QBMAN_CINH_TRACE
  120. pr_info("qbman_cinh_write(%p:0x%03x) 0x%08x\n",
  121. s->addr_cinh, offset, val);
  122. #endif
  123. }
  124. static inline uint32_t qbman_cinh_read(struct qbman_swp_sys *s, uint32_t offset)
  125. {
  126. uint32_t reg = __raw_readl(s->addr_cinh + offset);
  127. #ifdef QBMAN_CINH_TRACE
  128. pr_info("qbman_cinh_read(%p:0x%03x) 0x%08x\n",
  129. s->addr_cinh, offset, reg);
  130. #endif
  131. return reg;
  132. }
  133. static inline void *qbman_cena_write_start(struct qbman_swp_sys *s,
  134. uint32_t offset)
  135. {
  136. void *shadow = s->cena + offset;
  137. #ifdef QBMAN_CENA_TRACE
  138. pr_info("qbman_cena_write_start(%p:0x%03x) %p\n",
  139. s->addr_cena, offset, shadow);
  140. #endif
  141. BUG_ON(offset & 63);
  142. dcbz(shadow);
  143. return shadow;
  144. }
  145. static inline void qbman_cena_write_complete(struct qbman_swp_sys *s,
  146. uint32_t offset, void *cmd)
  147. {
  148. const uint32_t *shadow = cmd;
  149. int loop;
  150. #ifdef QBMAN_CENA_TRACE
  151. pr_info("qbman_cena_write_complete(%p:0x%03x) %p\n",
  152. s->addr_cena, offset, shadow);
  153. hexdump(cmd, 64);
  154. #endif
  155. for (loop = 15; loop >= 0; loop--)
  156. #ifdef QBMAN_CINH_ONLY
  157. __raw_writel(shadow[loop], s->addr_cinh +
  158. offset + loop * 4);
  159. #else
  160. __raw_writel(shadow[loop], s->addr_cena +
  161. offset + loop * 4);
  162. #endif
  163. }
  164. static inline void *qbman_cena_read(struct qbman_swp_sys *s, uint32_t offset)
  165. {
  166. uint32_t *shadow = s->cena + offset;
  167. unsigned int loop;
  168. #ifdef QBMAN_CENA_TRACE
  169. pr_info("qbman_cena_read(%p:0x%03x) %p\n",
  170. s->addr_cena, offset, shadow);
  171. #endif
  172. for (loop = 0; loop < 16; loop++)
  173. #ifdef QBMAN_CINH_ONLY
  174. shadow[loop] = __raw_readl(s->addr_cinh + offset
  175. + loop * 4);
  176. #else
  177. shadow[loop] = __raw_readl(s->addr_cena + offset
  178. + loop * 4);
  179. #endif
  180. #ifdef QBMAN_CENA_TRACE
  181. hexdump(shadow, 64);
  182. #endif
  183. return shadow;
  184. }
  185. static inline void qbman_cena_invalidate_prefetch(struct qbman_swp_sys *s,
  186. uint32_t offset)
  187. {
  188. }
  189. /******************/
  190. /* Portal support */
  191. /******************/
  192. /* The SWP_CFG portal register is special, in that it is used by the
  193. * platform-specific code rather than the platform-independent code in
  194. * qbman_portal.c. So use of it is declared locally here. */
  195. #define QBMAN_CINH_SWP_CFG 0xd00
  196. /* For MC portal use, we always configure with
  197. * DQRR_MF is (SWP_CFG,20,3) - DQRR max fill (<- 0x4)
  198. * EST is (SWP_CFG,16,3) - EQCR_CI stashing threshold (<- 0x0)
  199. * RPM is (SWP_CFG,12,2) - RCR production notification mode (<- 0x3)
  200. * DCM is (SWP_CFG,10,2) - DQRR consumption notification mode (<- 0x2)
  201. * EPM is (SWP_CFG,8,2) - EQCR production notification mode (<- 0x3)
  202. * SD is (SWP_CFG,5,1) - memory stashing drop enable (<- FALSE)
  203. * SP is (SWP_CFG,4,1) - memory stashing priority (<- TRUE)
  204. * SE is (SWP_CFG,3,1) - memory stashing enable (<- 0x0)
  205. * DP is (SWP_CFG,2,1) - dequeue stashing priority (<- TRUE)
  206. * DE is (SWP_CFG,1,1) - dequeue stashing enable (<- 0x0)
  207. * EP is (SWP_CFG,0,1) - EQCR_CI stashing priority (<- FALSE)
  208. */
  209. static inline uint32_t qbman_set_swp_cfg(uint8_t max_fill, uint8_t wn,
  210. uint8_t est, uint8_t rpm, uint8_t dcm,
  211. uint8_t epm, int sd, int sp, int se,
  212. int dp, int de, int ep)
  213. {
  214. uint32_t reg;
  215. reg = e32_uint8_t(20, (uint32_t)(3 + (max_fill >> 3)), max_fill) |
  216. e32_uint8_t(16, 3, est) | e32_uint8_t(12, 2, rpm) |
  217. e32_uint8_t(10, 2, dcm) | e32_uint8_t(8, 2, epm) |
  218. e32_int(5, 1, sd) | e32_int(4, 1, sp) | e32_int(3, 1, se) |
  219. e32_int(2, 1, dp) | e32_int(1, 1, de) | e32_int(0, 1, ep) |
  220. e32_uint8_t(14, 1, wn);
  221. return reg;
  222. }
  223. static inline int qbman_swp_sys_init(struct qbman_swp_sys *s,
  224. const struct qbman_swp_desc *d,
  225. uint8_t dqrr_size)
  226. {
  227. uint32_t reg;
  228. s->addr_cena = d->cena_bar;
  229. s->addr_cinh = d->cinh_bar;
  230. s->cena = (void *)valloc(CONFIG_SYS_PAGE_SIZE);
  231. if (!s->cena) {
  232. printf("Could not allocate page for cena shadow\n");
  233. return -1;
  234. }
  235. memset((void *)s->cena, 0x00, CONFIG_SYS_PAGE_SIZE);
  236. #ifdef QBMAN_CHECKING
  237. /* We should never be asked to initialise for a portal that isn't in
  238. * the power-on state. (Ie. don't forget to reset portals when they are
  239. * decommissioned!)
  240. */
  241. reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
  242. BUG_ON(reg);
  243. #endif
  244. #ifdef QBMAN_CINH_ONLY
  245. reg = qbman_set_swp_cfg(dqrr_size, 1, 0, 3, 2, 3, 0, 1, 0, 1, 0, 0);
  246. #else
  247. reg = qbman_set_swp_cfg(dqrr_size, 0, 0, 3, 2, 3, 0, 1, 0, 1, 0, 0);
  248. #endif
  249. qbman_cinh_write(s, QBMAN_CINH_SWP_CFG, reg);
  250. reg = qbman_cinh_read(s, QBMAN_CINH_SWP_CFG);
  251. if (!reg) {
  252. printf("The portal is not enabled!\n");
  253. free(s->cena);
  254. return -1;
  255. }
  256. return 0;
  257. }
  258. static inline void qbman_swp_sys_finish(struct qbman_swp_sys *s)
  259. {
  260. free((void *)s->cena);
  261. }