qman_ccsr.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * ALTERNATIVELY, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL") as published by the Free Software
  16. * Foundation, either version 2 of that License or (at your option) any
  17. * later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "qman_priv.h"
  31. u16 qman_ip_rev;
  32. EXPORT_SYMBOL(qman_ip_rev);
  33. u16 qm_channel_pool1 = QMAN_CHANNEL_POOL1;
  34. EXPORT_SYMBOL(qm_channel_pool1);
  35. /* Register offsets */
  36. #define REG_QCSP_LIO_CFG(n) (0x0000 + ((n) * 0x10))
  37. #define REG_QCSP_IO_CFG(n) (0x0004 + ((n) * 0x10))
  38. #define REG_QCSP_DD_CFG(n) (0x000c + ((n) * 0x10))
  39. #define REG_DD_CFG 0x0200
  40. #define REG_DCP_CFG(n) (0x0300 + ((n) * 0x10))
  41. #define REG_DCP_DD_CFG(n) (0x0304 + ((n) * 0x10))
  42. #define REG_DCP_DLM_AVG(n) (0x030c + ((n) * 0x10))
  43. #define REG_PFDR_FPC 0x0400
  44. #define REG_PFDR_FP_HEAD 0x0404
  45. #define REG_PFDR_FP_TAIL 0x0408
  46. #define REG_PFDR_FP_LWIT 0x0410
  47. #define REG_PFDR_CFG 0x0414
  48. #define REG_SFDR_CFG 0x0500
  49. #define REG_SFDR_IN_USE 0x0504
  50. #define REG_WQ_CS_CFG(n) (0x0600 + ((n) * 0x04))
  51. #define REG_WQ_DEF_ENC_WQID 0x0630
  52. #define REG_WQ_SC_DD_CFG(n) (0x640 + ((n) * 0x04))
  53. #define REG_WQ_PC_DD_CFG(n) (0x680 + ((n) * 0x04))
  54. #define REG_WQ_DC0_DD_CFG(n) (0x6c0 + ((n) * 0x04))
  55. #define REG_WQ_DC1_DD_CFG(n) (0x700 + ((n) * 0x04))
  56. #define REG_WQ_DCn_DD_CFG(n) (0x6c0 + ((n) * 0x40)) /* n=2,3 */
  57. #define REG_CM_CFG 0x0800
  58. #define REG_ECSR 0x0a00
  59. #define REG_ECIR 0x0a04
  60. #define REG_EADR 0x0a08
  61. #define REG_ECIR2 0x0a0c
  62. #define REG_EDATA(n) (0x0a10 + ((n) * 0x04))
  63. #define REG_SBEC(n) (0x0a80 + ((n) * 0x04))
  64. #define REG_MCR 0x0b00
  65. #define REG_MCP(n) (0x0b04 + ((n) * 0x04))
  66. #define REG_MISC_CFG 0x0be0
  67. #define REG_HID_CFG 0x0bf0
  68. #define REG_IDLE_STAT 0x0bf4
  69. #define REG_IP_REV_1 0x0bf8
  70. #define REG_IP_REV_2 0x0bfc
  71. #define REG_FQD_BARE 0x0c00
  72. #define REG_PFDR_BARE 0x0c20
  73. #define REG_offset_BAR 0x0004 /* relative to REG_[FQD|PFDR]_BARE */
  74. #define REG_offset_AR 0x0010 /* relative to REG_[FQD|PFDR]_BARE */
  75. #define REG_QCSP_BARE 0x0c80
  76. #define REG_QCSP_BAR 0x0c84
  77. #define REG_CI_SCHED_CFG 0x0d00
  78. #define REG_SRCIDR 0x0d04
  79. #define REG_LIODNR 0x0d08
  80. #define REG_CI_RLM_AVG 0x0d14
  81. #define REG_ERR_ISR 0x0e00
  82. #define REG_ERR_IER 0x0e04
  83. #define REG_REV3_QCSP_LIO_CFG(n) (0x1000 + ((n) * 0x10))
  84. #define REG_REV3_QCSP_IO_CFG(n) (0x1004 + ((n) * 0x10))
  85. #define REG_REV3_QCSP_DD_CFG(n) (0x100c + ((n) * 0x10))
  86. /* Assists for QMAN_MCR */
  87. #define MCR_INIT_PFDR 0x01000000
  88. #define MCR_get_rslt(v) (u8)((v) >> 24)
  89. #define MCR_rslt_idle(r) (!(r) || ((r) >= 0xf0))
  90. #define MCR_rslt_ok(r) ((r) == 0xf0)
  91. #define MCR_rslt_eaccess(r) ((r) == 0xf8)
  92. #define MCR_rslt_inval(r) ((r) == 0xff)
  93. /*
  94. * Corenet initiator settings. Stash request queues are 4-deep to match cores
  95. * ability to snarf. Stash priority is 3, other priorities are 2.
  96. */
  97. #define QM_CI_SCHED_CFG_SRCCIV 4
  98. #define QM_CI_SCHED_CFG_SRQ_W 3
  99. #define QM_CI_SCHED_CFG_RW_W 2
  100. #define QM_CI_SCHED_CFG_BMAN_W 2
  101. /* write SRCCIV enable */
  102. #define QM_CI_SCHED_CFG_SRCCIV_EN BIT(31)
  103. /* Follows WQ_CS_CFG0-5 */
  104. enum qm_wq_class {
  105. qm_wq_portal = 0,
  106. qm_wq_pool = 1,
  107. qm_wq_fman0 = 2,
  108. qm_wq_fman1 = 3,
  109. qm_wq_caam = 4,
  110. qm_wq_pme = 5,
  111. qm_wq_first = qm_wq_portal,
  112. qm_wq_last = qm_wq_pme
  113. };
  114. /* Follows FQD_[BARE|BAR|AR] and PFDR_[BARE|BAR|AR] */
  115. enum qm_memory {
  116. qm_memory_fqd,
  117. qm_memory_pfdr
  118. };
  119. /* Used by all error interrupt registers except 'inhibit' */
  120. #define QM_EIRQ_CIDE 0x20000000 /* Corenet Initiator Data Error */
  121. #define QM_EIRQ_CTDE 0x10000000 /* Corenet Target Data Error */
  122. #define QM_EIRQ_CITT 0x08000000 /* Corenet Invalid Target Transaction */
  123. #define QM_EIRQ_PLWI 0x04000000 /* PFDR Low Watermark */
  124. #define QM_EIRQ_MBEI 0x02000000 /* Multi-bit ECC Error */
  125. #define QM_EIRQ_SBEI 0x01000000 /* Single-bit ECC Error */
  126. #define QM_EIRQ_PEBI 0x00800000 /* PFDR Enqueues Blocked Interrupt */
  127. #define QM_EIRQ_IFSI 0x00020000 /* Invalid FQ Flow Control State */
  128. #define QM_EIRQ_ICVI 0x00010000 /* Invalid Command Verb */
  129. #define QM_EIRQ_IDDI 0x00000800 /* Invalid Dequeue (Direct-connect) */
  130. #define QM_EIRQ_IDFI 0x00000400 /* Invalid Dequeue FQ */
  131. #define QM_EIRQ_IDSI 0x00000200 /* Invalid Dequeue Source */
  132. #define QM_EIRQ_IDQI 0x00000100 /* Invalid Dequeue Queue */
  133. #define QM_EIRQ_IECE 0x00000010 /* Invalid Enqueue Configuration */
  134. #define QM_EIRQ_IEOI 0x00000008 /* Invalid Enqueue Overflow */
  135. #define QM_EIRQ_IESI 0x00000004 /* Invalid Enqueue State */
  136. #define QM_EIRQ_IECI 0x00000002 /* Invalid Enqueue Channel */
  137. #define QM_EIRQ_IEQI 0x00000001 /* Invalid Enqueue Queue */
  138. /* QMAN_ECIR valid error bit */
  139. #define PORTAL_ECSR_ERR (QM_EIRQ_IEQI | QM_EIRQ_IESI | QM_EIRQ_IEOI | \
  140. QM_EIRQ_IDQI | QM_EIRQ_IDSI | QM_EIRQ_IDFI | \
  141. QM_EIRQ_IDDI | QM_EIRQ_ICVI | QM_EIRQ_IFSI)
  142. #define FQID_ECSR_ERR (QM_EIRQ_IEQI | QM_EIRQ_IECI | QM_EIRQ_IESI | \
  143. QM_EIRQ_IEOI | QM_EIRQ_IDQI | QM_EIRQ_IDFI | \
  144. QM_EIRQ_IFSI)
  145. struct qm_ecir {
  146. u32 info; /* res[30-31], ptyp[29], pnum[24-28], fqid[0-23] */
  147. };
  148. static bool qm_ecir_is_dcp(const struct qm_ecir *p)
  149. {
  150. return p->info & BIT(29);
  151. }
  152. static int qm_ecir_get_pnum(const struct qm_ecir *p)
  153. {
  154. return (p->info >> 24) & 0x1f;
  155. }
  156. static int qm_ecir_get_fqid(const struct qm_ecir *p)
  157. {
  158. return p->info & (BIT(24) - 1);
  159. }
  160. struct qm_ecir2 {
  161. u32 info; /* ptyp[31], res[10-30], pnum[0-9] */
  162. };
  163. static bool qm_ecir2_is_dcp(const struct qm_ecir2 *p)
  164. {
  165. return p->info & BIT(31);
  166. }
  167. static int qm_ecir2_get_pnum(const struct qm_ecir2 *p)
  168. {
  169. return p->info & (BIT(10) - 1);
  170. }
  171. struct qm_eadr {
  172. u32 info; /* memid[24-27], eadr[0-11] */
  173. /* v3: memid[24-28], eadr[0-15] */
  174. };
  175. static int qm_eadr_get_memid(const struct qm_eadr *p)
  176. {
  177. return (p->info >> 24) & 0xf;
  178. }
  179. static int qm_eadr_get_eadr(const struct qm_eadr *p)
  180. {
  181. return p->info & (BIT(12) - 1);
  182. }
  183. static int qm_eadr_v3_get_memid(const struct qm_eadr *p)
  184. {
  185. return (p->info >> 24) & 0x1f;
  186. }
  187. static int qm_eadr_v3_get_eadr(const struct qm_eadr *p)
  188. {
  189. return p->info & (BIT(16) - 1);
  190. }
  191. struct qman_hwerr_txt {
  192. u32 mask;
  193. const char *txt;
  194. };
  195. static const struct qman_hwerr_txt qman_hwerr_txts[] = {
  196. { QM_EIRQ_CIDE, "Corenet Initiator Data Error" },
  197. { QM_EIRQ_CTDE, "Corenet Target Data Error" },
  198. { QM_EIRQ_CITT, "Corenet Invalid Target Transaction" },
  199. { QM_EIRQ_PLWI, "PFDR Low Watermark" },
  200. { QM_EIRQ_MBEI, "Multi-bit ECC Error" },
  201. { QM_EIRQ_SBEI, "Single-bit ECC Error" },
  202. { QM_EIRQ_PEBI, "PFDR Enqueues Blocked Interrupt" },
  203. { QM_EIRQ_ICVI, "Invalid Command Verb" },
  204. { QM_EIRQ_IFSI, "Invalid Flow Control State" },
  205. { QM_EIRQ_IDDI, "Invalid Dequeue (Direct-connect)" },
  206. { QM_EIRQ_IDFI, "Invalid Dequeue FQ" },
  207. { QM_EIRQ_IDSI, "Invalid Dequeue Source" },
  208. { QM_EIRQ_IDQI, "Invalid Dequeue Queue" },
  209. { QM_EIRQ_IECE, "Invalid Enqueue Configuration" },
  210. { QM_EIRQ_IEOI, "Invalid Enqueue Overflow" },
  211. { QM_EIRQ_IESI, "Invalid Enqueue State" },
  212. { QM_EIRQ_IECI, "Invalid Enqueue Channel" },
  213. { QM_EIRQ_IEQI, "Invalid Enqueue Queue" },
  214. };
  215. struct qman_error_info_mdata {
  216. u16 addr_mask;
  217. u16 bits;
  218. const char *txt;
  219. };
  220. static const struct qman_error_info_mdata error_mdata[] = {
  221. { 0x01FF, 24, "FQD cache tag memory 0" },
  222. { 0x01FF, 24, "FQD cache tag memory 1" },
  223. { 0x01FF, 24, "FQD cache tag memory 2" },
  224. { 0x01FF, 24, "FQD cache tag memory 3" },
  225. { 0x0FFF, 512, "FQD cache memory" },
  226. { 0x07FF, 128, "SFDR memory" },
  227. { 0x01FF, 72, "WQ context memory" },
  228. { 0x00FF, 240, "CGR memory" },
  229. { 0x00FF, 302, "Internal Order Restoration List memory" },
  230. { 0x01FF, 256, "SW portal ring memory" },
  231. };
  232. #define QMAN_ERRS_TO_DISABLE (QM_EIRQ_PLWI | QM_EIRQ_PEBI)
  233. /*
  234. * TODO: unimplemented registers
  235. *
  236. * Keeping a list here of QMan registers I have not yet covered;
  237. * QCSP_DD_IHRSR, QCSP_DD_IHRFR, QCSP_DD_HASR,
  238. * DCP_DD_IHRSR, DCP_DD_IHRFR, DCP_DD_HASR, CM_CFG,
  239. * QMAN_EECC, QMAN_SBET, QMAN_EINJ, QMAN_SBEC0-12
  240. */
  241. /* Pointer to the start of the QMan's CCSR space */
  242. static u32 __iomem *qm_ccsr_start;
  243. /* A SDQCR mask comprising all the available/visible pool channels */
  244. static u32 qm_pools_sdqcr;
  245. static inline u32 qm_ccsr_in(u32 offset)
  246. {
  247. return ioread32be(qm_ccsr_start + offset/4);
  248. }
  249. static inline void qm_ccsr_out(u32 offset, u32 val)
  250. {
  251. iowrite32be(val, qm_ccsr_start + offset/4);
  252. }
  253. u32 qm_get_pools_sdqcr(void)
  254. {
  255. return qm_pools_sdqcr;
  256. }
  257. enum qm_dc_portal {
  258. qm_dc_portal_fman0 = 0,
  259. qm_dc_portal_fman1 = 1
  260. };
  261. static void qm_set_dc(enum qm_dc_portal portal, int ed, u8 sernd)
  262. {
  263. DPAA_ASSERT(!ed || portal == qm_dc_portal_fman0 ||
  264. portal == qm_dc_portal_fman1);
  265. if ((qman_ip_rev & 0xFF00) >= QMAN_REV30)
  266. qm_ccsr_out(REG_DCP_CFG(portal),
  267. (ed ? 0x1000 : 0) | (sernd & 0x3ff));
  268. else
  269. qm_ccsr_out(REG_DCP_CFG(portal),
  270. (ed ? 0x100 : 0) | (sernd & 0x1f));
  271. }
  272. static void qm_set_wq_scheduling(enum qm_wq_class wq_class,
  273. u8 cs_elev, u8 csw2, u8 csw3, u8 csw4,
  274. u8 csw5, u8 csw6, u8 csw7)
  275. {
  276. qm_ccsr_out(REG_WQ_CS_CFG(wq_class), ((cs_elev & 0xff) << 24) |
  277. ((csw2 & 0x7) << 20) | ((csw3 & 0x7) << 16) |
  278. ((csw4 & 0x7) << 12) | ((csw5 & 0x7) << 8) |
  279. ((csw6 & 0x7) << 4) | (csw7 & 0x7));
  280. }
  281. static void qm_set_hid(void)
  282. {
  283. qm_ccsr_out(REG_HID_CFG, 0);
  284. }
  285. static void qm_set_corenet_initiator(void)
  286. {
  287. qm_ccsr_out(REG_CI_SCHED_CFG, QM_CI_SCHED_CFG_SRCCIV_EN |
  288. (QM_CI_SCHED_CFG_SRCCIV << 24) |
  289. (QM_CI_SCHED_CFG_SRQ_W << 8) |
  290. (QM_CI_SCHED_CFG_RW_W << 4) |
  291. QM_CI_SCHED_CFG_BMAN_W);
  292. }
  293. static void qm_get_version(u16 *id, u8 *major, u8 *minor)
  294. {
  295. u32 v = qm_ccsr_in(REG_IP_REV_1);
  296. *id = (v >> 16);
  297. *major = (v >> 8) & 0xff;
  298. *minor = v & 0xff;
  299. }
  300. #define PFDR_AR_EN BIT(31)
  301. static void qm_set_memory(enum qm_memory memory, u64 ba, u32 size)
  302. {
  303. u32 offset = (memory == qm_memory_fqd) ? REG_FQD_BARE : REG_PFDR_BARE;
  304. u32 exp = ilog2(size);
  305. /* choke if size isn't within range */
  306. DPAA_ASSERT((size >= 4096) && (size <= 1024*1024*1024) &&
  307. is_power_of_2(size));
  308. /* choke if 'ba' has lower-alignment than 'size' */
  309. DPAA_ASSERT(!(ba & (size - 1)));
  310. qm_ccsr_out(offset, upper_32_bits(ba));
  311. qm_ccsr_out(offset + REG_offset_BAR, lower_32_bits(ba));
  312. qm_ccsr_out(offset + REG_offset_AR, PFDR_AR_EN | (exp - 1));
  313. }
  314. static void qm_set_pfdr_threshold(u32 th, u8 k)
  315. {
  316. qm_ccsr_out(REG_PFDR_FP_LWIT, th & 0xffffff);
  317. qm_ccsr_out(REG_PFDR_CFG, k);
  318. }
  319. static void qm_set_sfdr_threshold(u16 th)
  320. {
  321. qm_ccsr_out(REG_SFDR_CFG, th & 0x3ff);
  322. }
  323. static int qm_init_pfdr(struct device *dev, u32 pfdr_start, u32 num)
  324. {
  325. u8 rslt = MCR_get_rslt(qm_ccsr_in(REG_MCR));
  326. DPAA_ASSERT(pfdr_start && !(pfdr_start & 7) && !(num & 7) && num);
  327. /* Make sure the command interface is 'idle' */
  328. if (!MCR_rslt_idle(rslt)) {
  329. dev_crit(dev, "QMAN_MCR isn't idle");
  330. WARN_ON(1);
  331. }
  332. /* Write the MCR command params then the verb */
  333. qm_ccsr_out(REG_MCP(0), pfdr_start);
  334. /*
  335. * TODO: remove this - it's a workaround for a model bug that is
  336. * corrected in more recent versions. We use the workaround until
  337. * everyone has upgraded.
  338. */
  339. qm_ccsr_out(REG_MCP(1), pfdr_start + num - 16);
  340. dma_wmb();
  341. qm_ccsr_out(REG_MCR, MCR_INIT_PFDR);
  342. /* Poll for the result */
  343. do {
  344. rslt = MCR_get_rslt(qm_ccsr_in(REG_MCR));
  345. } while (!MCR_rslt_idle(rslt));
  346. if (MCR_rslt_ok(rslt))
  347. return 0;
  348. if (MCR_rslt_eaccess(rslt))
  349. return -EACCES;
  350. if (MCR_rslt_inval(rslt))
  351. return -EINVAL;
  352. dev_crit(dev, "Unexpected result from MCR_INIT_PFDR: %02x\n", rslt);
  353. return -ENODEV;
  354. }
  355. /*
  356. * Ideally we would use the DMA API to turn rmem->base into a DMA address
  357. * (especially if iommu translations ever get involved). Unfortunately, the
  358. * DMA API currently does not allow mapping anything that is not backed with
  359. * a struct page.
  360. */
  361. static dma_addr_t fqd_a, pfdr_a;
  362. static size_t fqd_sz, pfdr_sz;
  363. static int qman_fqd(struct reserved_mem *rmem)
  364. {
  365. fqd_a = rmem->base;
  366. fqd_sz = rmem->size;
  367. WARN_ON(!(fqd_a && fqd_sz));
  368. return 0;
  369. }
  370. RESERVEDMEM_OF_DECLARE(qman_fqd, "fsl,qman-fqd", qman_fqd);
  371. static int qman_pfdr(struct reserved_mem *rmem)
  372. {
  373. pfdr_a = rmem->base;
  374. pfdr_sz = rmem->size;
  375. WARN_ON(!(pfdr_a && pfdr_sz));
  376. return 0;
  377. }
  378. RESERVEDMEM_OF_DECLARE(qman_pfdr, "fsl,qman-pfdr", qman_pfdr);
  379. static unsigned int qm_get_fqid_maxcnt(void)
  380. {
  381. return fqd_sz / 64;
  382. }
  383. /*
  384. * Flush this memory range from data cache so that QMAN originated
  385. * transactions for this memory region could be marked non-coherent.
  386. */
  387. static int zero_priv_mem(struct device *dev, struct device_node *node,
  388. phys_addr_t addr, size_t sz)
  389. {
  390. /* map as cacheable, non-guarded */
  391. void __iomem *tmpp = ioremap_prot(addr, sz, 0);
  392. memset_io(tmpp, 0, sz);
  393. flush_dcache_range((unsigned long)tmpp,
  394. (unsigned long)tmpp + sz);
  395. iounmap(tmpp);
  396. return 0;
  397. }
  398. static void log_edata_bits(struct device *dev, u32 bit_count)
  399. {
  400. u32 i, j, mask = 0xffffffff;
  401. dev_warn(dev, "ErrInt, EDATA:\n");
  402. i = bit_count / 32;
  403. if (bit_count % 32) {
  404. i++;
  405. mask = ~(mask << bit_count % 32);
  406. }
  407. j = 16 - i;
  408. dev_warn(dev, " 0x%08x\n", qm_ccsr_in(REG_EDATA(j)) & mask);
  409. j++;
  410. for (; j < 16; j++)
  411. dev_warn(dev, " 0x%08x\n", qm_ccsr_in(REG_EDATA(j)));
  412. }
  413. static void log_additional_error_info(struct device *dev, u32 isr_val,
  414. u32 ecsr_val)
  415. {
  416. struct qm_ecir ecir_val;
  417. struct qm_eadr eadr_val;
  418. int memid;
  419. ecir_val.info = qm_ccsr_in(REG_ECIR);
  420. /* Is portal info valid */
  421. if ((qman_ip_rev & 0xFF00) >= QMAN_REV30) {
  422. struct qm_ecir2 ecir2_val;
  423. ecir2_val.info = qm_ccsr_in(REG_ECIR2);
  424. if (ecsr_val & PORTAL_ECSR_ERR) {
  425. dev_warn(dev, "ErrInt: %s id %d\n",
  426. qm_ecir2_is_dcp(&ecir2_val) ? "DCP" : "SWP",
  427. qm_ecir2_get_pnum(&ecir2_val));
  428. }
  429. if (ecsr_val & (FQID_ECSR_ERR | QM_EIRQ_IECE))
  430. dev_warn(dev, "ErrInt: ecir.fqid 0x%x\n",
  431. qm_ecir_get_fqid(&ecir_val));
  432. if (ecsr_val & (QM_EIRQ_SBEI|QM_EIRQ_MBEI)) {
  433. eadr_val.info = qm_ccsr_in(REG_EADR);
  434. memid = qm_eadr_v3_get_memid(&eadr_val);
  435. dev_warn(dev, "ErrInt: EADR Memory: %s, 0x%x\n",
  436. error_mdata[memid].txt,
  437. error_mdata[memid].addr_mask
  438. & qm_eadr_v3_get_eadr(&eadr_val));
  439. log_edata_bits(dev, error_mdata[memid].bits);
  440. }
  441. } else {
  442. if (ecsr_val & PORTAL_ECSR_ERR) {
  443. dev_warn(dev, "ErrInt: %s id %d\n",
  444. qm_ecir_is_dcp(&ecir_val) ? "DCP" : "SWP",
  445. qm_ecir_get_pnum(&ecir_val));
  446. }
  447. if (ecsr_val & FQID_ECSR_ERR)
  448. dev_warn(dev, "ErrInt: ecir.fqid 0x%x\n",
  449. qm_ecir_get_fqid(&ecir_val));
  450. if (ecsr_val & (QM_EIRQ_SBEI|QM_EIRQ_MBEI)) {
  451. eadr_val.info = qm_ccsr_in(REG_EADR);
  452. memid = qm_eadr_get_memid(&eadr_val);
  453. dev_warn(dev, "ErrInt: EADR Memory: %s, 0x%x\n",
  454. error_mdata[memid].txt,
  455. error_mdata[memid].addr_mask
  456. & qm_eadr_get_eadr(&eadr_val));
  457. log_edata_bits(dev, error_mdata[memid].bits);
  458. }
  459. }
  460. }
  461. static irqreturn_t qman_isr(int irq, void *ptr)
  462. {
  463. u32 isr_val, ier_val, ecsr_val, isr_mask, i;
  464. struct device *dev = ptr;
  465. ier_val = qm_ccsr_in(REG_ERR_IER);
  466. isr_val = qm_ccsr_in(REG_ERR_ISR);
  467. ecsr_val = qm_ccsr_in(REG_ECSR);
  468. isr_mask = isr_val & ier_val;
  469. if (!isr_mask)
  470. return IRQ_NONE;
  471. for (i = 0; i < ARRAY_SIZE(qman_hwerr_txts); i++) {
  472. if (qman_hwerr_txts[i].mask & isr_mask) {
  473. dev_err_ratelimited(dev, "ErrInt: %s\n",
  474. qman_hwerr_txts[i].txt);
  475. if (qman_hwerr_txts[i].mask & ecsr_val) {
  476. log_additional_error_info(dev, isr_mask,
  477. ecsr_val);
  478. /* Re-arm error capture registers */
  479. qm_ccsr_out(REG_ECSR, ecsr_val);
  480. }
  481. if (qman_hwerr_txts[i].mask & QMAN_ERRS_TO_DISABLE) {
  482. dev_dbg(dev, "Disabling error 0x%x\n",
  483. qman_hwerr_txts[i].mask);
  484. ier_val &= ~qman_hwerr_txts[i].mask;
  485. qm_ccsr_out(REG_ERR_IER, ier_val);
  486. }
  487. }
  488. }
  489. qm_ccsr_out(REG_ERR_ISR, isr_val);
  490. return IRQ_HANDLED;
  491. }
  492. static int qman_init_ccsr(struct device *dev)
  493. {
  494. int i, err;
  495. /* FQD memory */
  496. qm_set_memory(qm_memory_fqd, fqd_a, fqd_sz);
  497. /* PFDR memory */
  498. qm_set_memory(qm_memory_pfdr, pfdr_a, pfdr_sz);
  499. err = qm_init_pfdr(dev, 8, pfdr_sz / 64 - 8);
  500. if (err)
  501. return err;
  502. /* thresholds */
  503. qm_set_pfdr_threshold(512, 64);
  504. qm_set_sfdr_threshold(128);
  505. /* clear stale PEBI bit from interrupt status register */
  506. qm_ccsr_out(REG_ERR_ISR, QM_EIRQ_PEBI);
  507. /* corenet initiator settings */
  508. qm_set_corenet_initiator();
  509. /* HID settings */
  510. qm_set_hid();
  511. /* Set scheduling weights to defaults */
  512. for (i = qm_wq_first; i <= qm_wq_last; i++)
  513. qm_set_wq_scheduling(i, 0, 0, 0, 0, 0, 0, 0);
  514. /* We are not prepared to accept ERNs for hardware enqueues */
  515. qm_set_dc(qm_dc_portal_fman0, 1, 0);
  516. qm_set_dc(qm_dc_portal_fman1, 1, 0);
  517. return 0;
  518. }
  519. #define LIO_CFG_LIODN_MASK 0x0fff0000
  520. void qman_liodn_fixup(u16 channel)
  521. {
  522. static int done;
  523. static u32 liodn_offset;
  524. u32 before, after;
  525. int idx = channel - QM_CHANNEL_SWPORTAL0;
  526. if ((qman_ip_rev & 0xFF00) >= QMAN_REV30)
  527. before = qm_ccsr_in(REG_REV3_QCSP_LIO_CFG(idx));
  528. else
  529. before = qm_ccsr_in(REG_QCSP_LIO_CFG(idx));
  530. if (!done) {
  531. liodn_offset = before & LIO_CFG_LIODN_MASK;
  532. done = 1;
  533. return;
  534. }
  535. after = (before & (~LIO_CFG_LIODN_MASK)) | liodn_offset;
  536. if ((qman_ip_rev & 0xFF00) >= QMAN_REV30)
  537. qm_ccsr_out(REG_REV3_QCSP_LIO_CFG(idx), after);
  538. else
  539. qm_ccsr_out(REG_QCSP_LIO_CFG(idx), after);
  540. }
  541. #define IO_CFG_SDEST_MASK 0x00ff0000
  542. void qman_set_sdest(u16 channel, unsigned int cpu_idx)
  543. {
  544. int idx = channel - QM_CHANNEL_SWPORTAL0;
  545. u32 before, after;
  546. if ((qman_ip_rev & 0xFF00) >= QMAN_REV30) {
  547. before = qm_ccsr_in(REG_REV3_QCSP_IO_CFG(idx));
  548. /* Each pair of vcpu share the same SRQ(SDEST) */
  549. cpu_idx /= 2;
  550. after = (before & (~IO_CFG_SDEST_MASK)) | (cpu_idx << 16);
  551. qm_ccsr_out(REG_REV3_QCSP_IO_CFG(idx), after);
  552. } else {
  553. before = qm_ccsr_in(REG_QCSP_IO_CFG(idx));
  554. after = (before & (~IO_CFG_SDEST_MASK)) | (cpu_idx << 16);
  555. qm_ccsr_out(REG_QCSP_IO_CFG(idx), after);
  556. }
  557. }
  558. static int qman_resource_init(struct device *dev)
  559. {
  560. int pool_chan_num, cgrid_num;
  561. int ret, i;
  562. switch (qman_ip_rev >> 8) {
  563. case 1:
  564. pool_chan_num = 15;
  565. cgrid_num = 256;
  566. break;
  567. case 2:
  568. pool_chan_num = 3;
  569. cgrid_num = 64;
  570. break;
  571. case 3:
  572. pool_chan_num = 15;
  573. cgrid_num = 256;
  574. break;
  575. default:
  576. return -ENODEV;
  577. }
  578. ret = gen_pool_add(qm_qpalloc, qm_channel_pool1 | DPAA_GENALLOC_OFF,
  579. pool_chan_num, -1);
  580. if (ret) {
  581. dev_err(dev, "Failed to seed pool channels (%d)\n", ret);
  582. return ret;
  583. }
  584. ret = gen_pool_add(qm_cgralloc, DPAA_GENALLOC_OFF, cgrid_num, -1);
  585. if (ret) {
  586. dev_err(dev, "Failed to seed CGRID range (%d)\n", ret);
  587. return ret;
  588. }
  589. /* parse pool channels into the SDQCR mask */
  590. for (i = 0; i < cgrid_num; i++)
  591. qm_pools_sdqcr |= QM_SDQCR_CHANNELS_POOL_CONV(i);
  592. ret = gen_pool_add(qm_fqalloc, QM_FQID_RANGE_START | DPAA_GENALLOC_OFF,
  593. qm_get_fqid_maxcnt() - QM_FQID_RANGE_START, -1);
  594. if (ret) {
  595. dev_err(dev, "Failed to seed FQID range (%d)\n", ret);
  596. return ret;
  597. }
  598. return 0;
  599. }
  600. static int fsl_qman_probe(struct platform_device *pdev)
  601. {
  602. struct device *dev = &pdev->dev;
  603. struct device_node *node = dev->of_node;
  604. struct resource *res;
  605. int ret, err_irq;
  606. u16 id;
  607. u8 major, minor;
  608. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  609. if (!res) {
  610. dev_err(dev, "Can't get %s property 'IORESOURCE_MEM'\n",
  611. node->full_name);
  612. return -ENXIO;
  613. }
  614. qm_ccsr_start = devm_ioremap(dev, res->start, resource_size(res));
  615. if (!qm_ccsr_start)
  616. return -ENXIO;
  617. qm_get_version(&id, &major, &minor);
  618. if (major == 1 && minor == 0) {
  619. dev_err(dev, "Rev1.0 on P4080 rev1 is not supported!\n");
  620. return -ENODEV;
  621. } else if (major == 1 && minor == 1)
  622. qman_ip_rev = QMAN_REV11;
  623. else if (major == 1 && minor == 2)
  624. qman_ip_rev = QMAN_REV12;
  625. else if (major == 2 && minor == 0)
  626. qman_ip_rev = QMAN_REV20;
  627. else if (major == 3 && minor == 0)
  628. qman_ip_rev = QMAN_REV30;
  629. else if (major == 3 && minor == 1)
  630. qman_ip_rev = QMAN_REV31;
  631. else {
  632. dev_err(dev, "Unknown QMan version\n");
  633. return -ENODEV;
  634. }
  635. if ((qman_ip_rev & 0xff00) >= QMAN_REV30)
  636. qm_channel_pool1 = QMAN_CHANNEL_POOL1_REV3;
  637. ret = zero_priv_mem(dev, node, fqd_a, fqd_sz);
  638. WARN_ON(ret);
  639. if (ret)
  640. return -ENODEV;
  641. ret = qman_init_ccsr(dev);
  642. if (ret) {
  643. dev_err(dev, "CCSR setup failed\n");
  644. return ret;
  645. }
  646. err_irq = platform_get_irq(pdev, 0);
  647. if (err_irq <= 0) {
  648. dev_info(dev, "Can't get %s property 'interrupts'\n",
  649. node->full_name);
  650. return -ENODEV;
  651. }
  652. ret = devm_request_irq(dev, err_irq, qman_isr, IRQF_SHARED, "qman-err",
  653. dev);
  654. if (ret) {
  655. dev_err(dev, "devm_request_irq() failed %d for '%s'\n",
  656. ret, node->full_name);
  657. return ret;
  658. }
  659. /*
  660. * Write-to-clear any stale bits, (eg. starvation being asserted prior
  661. * to resource allocation during driver init).
  662. */
  663. qm_ccsr_out(REG_ERR_ISR, 0xffffffff);
  664. /* Enable Error Interrupts */
  665. qm_ccsr_out(REG_ERR_IER, 0xffffffff);
  666. qm_fqalloc = devm_gen_pool_create(dev, 0, -1, "qman-fqalloc");
  667. if (IS_ERR(qm_fqalloc)) {
  668. ret = PTR_ERR(qm_fqalloc);
  669. dev_err(dev, "qman-fqalloc pool init failed (%d)\n", ret);
  670. return ret;
  671. }
  672. qm_qpalloc = devm_gen_pool_create(dev, 0, -1, "qman-qpalloc");
  673. if (IS_ERR(qm_qpalloc)) {
  674. ret = PTR_ERR(qm_qpalloc);
  675. dev_err(dev, "qman-qpalloc pool init failed (%d)\n", ret);
  676. return ret;
  677. }
  678. qm_cgralloc = devm_gen_pool_create(dev, 0, -1, "qman-cgralloc");
  679. if (IS_ERR(qm_cgralloc)) {
  680. ret = PTR_ERR(qm_cgralloc);
  681. dev_err(dev, "qman-cgralloc pool init failed (%d)\n", ret);
  682. return ret;
  683. }
  684. ret = qman_resource_init(dev);
  685. if (ret)
  686. return ret;
  687. ret = qman_alloc_fq_table(qm_get_fqid_maxcnt());
  688. if (ret)
  689. return ret;
  690. ret = qman_wq_alloc();
  691. if (ret)
  692. return ret;
  693. return 0;
  694. }
  695. static const struct of_device_id fsl_qman_ids[] = {
  696. {
  697. .compatible = "fsl,qman",
  698. },
  699. {}
  700. };
  701. static struct platform_driver fsl_qman_driver = {
  702. .driver = {
  703. .name = KBUILD_MODNAME,
  704. .of_match_table = fsl_qman_ids,
  705. .suppress_bind_attrs = true,
  706. },
  707. .probe = fsl_qman_probe,
  708. };
  709. builtin_platform_driver(fsl_qman_driver);