t7xx_dpmaif.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, MediaTek Inc.
  4. * Copyright (c) 2021-2022, Intel Corporation.
  5. *
  6. * Authors:
  7. * Amir Hanania <[email protected]>
  8. * Haijun Liu <[email protected]>
  9. * Moises Veleta <[email protected]>
  10. * Ricardo Martinez <[email protected]>
  11. *
  12. * Contributors:
  13. * Andy Shevchenko <[email protected]>
  14. * Chiranjeevi Rapolu <[email protected]>
  15. * Eliot Lee <[email protected]>
  16. * Sreehari Kancharla <[email protected]>
  17. */
  18. #include <linux/bits.h>
  19. #include <linux/bitfield.h>
  20. #include <linux/bitops.h>
  21. #include <linux/delay.h>
  22. #include <linux/dev_printk.h>
  23. #include <linux/io.h>
  24. #include <linux/iopoll.h>
  25. #include <linux/types.h>
  26. #include "t7xx_dpmaif.h"
  27. #include "t7xx_reg.h"
  28. #define ioread32_poll_timeout_atomic(addr, val, cond, delay_us, timeout_us) \
  29. readx_poll_timeout_atomic(ioread32, addr, val, cond, delay_us, timeout_us)
  30. static int t7xx_dpmaif_init_intr(struct dpmaif_hw_info *hw_info)
  31. {
  32. struct dpmaif_isr_en_mask *isr_en_msk = &hw_info->isr_en_mask;
  33. u32 value, ul_intr_enable, dl_intr_enable;
  34. int ret;
  35. ul_intr_enable = DP_UL_INT_ERR_MSK | DP_UL_INT_QDONE_MSK;
  36. isr_en_msk->ap_ul_l2intr_en_msk = ul_intr_enable;
  37. iowrite32(DPMAIF_AP_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
  38. /* Set interrupt enable mask */
  39. iowrite32(ul_intr_enable, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMCR0);
  40. iowrite32(~ul_intr_enable, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMSR0);
  41. /* Check mask status */
  42. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
  43. value, (value & ul_intr_enable) != ul_intr_enable, 0,
  44. DPMAIF_CHECK_INIT_TIMEOUT_US);
  45. if (ret)
  46. return ret;
  47. dl_intr_enable = DP_DL_INT_PITCNT_LEN_ERR | DP_DL_INT_BATCNT_LEN_ERR;
  48. isr_en_msk->ap_dl_l2intr_err_en_msk = dl_intr_enable;
  49. ul_intr_enable = DPMAIF_DL_INT_DLQ0_QDONE | DPMAIF_DL_INT_DLQ0_PITCNT_LEN |
  50. DPMAIF_DL_INT_DLQ1_QDONE | DPMAIF_DL_INT_DLQ1_PITCNT_LEN;
  51. isr_en_msk->ap_ul_l2intr_en_msk = ul_intr_enable;
  52. iowrite32(DPMAIF_AP_APDL_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
  53. /* Set DL ISR PD enable mask */
  54. iowrite32(~ul_intr_enable, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  55. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMR0,
  56. value, (value & ul_intr_enable) != ul_intr_enable, 0,
  57. DPMAIF_CHECK_INIT_TIMEOUT_US);
  58. if (ret)
  59. return ret;
  60. isr_en_msk->ap_udl_ip_busy_en_msk = DPMAIF_UDL_IP_BUSY;
  61. iowrite32(DPMAIF_AP_IP_BUSY_MASK, hw_info->pcie_base + DPMAIF_AP_IP_BUSY);
  62. iowrite32(isr_en_msk->ap_udl_ip_busy_en_msk,
  63. hw_info->pcie_base + DPMAIF_AO_AP_DLUL_IP_BUSY_MASK);
  64. value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_AP_L1TIMR0);
  65. value |= DPMAIF_DL_INT_Q2APTOP | DPMAIF_DL_INT_Q2TOQ1;
  66. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_UL_AP_L1TIMR0);
  67. iowrite32(DPMA_HPC_ALL_INT_MASK, hw_info->pcie_base + DPMAIF_HPC_INTR_MASK);
  68. return 0;
  69. }
  70. static void t7xx_dpmaif_mask_ulq_intr(struct dpmaif_hw_info *hw_info, unsigned int q_num)
  71. {
  72. struct dpmaif_isr_en_mask *isr_en_msk;
  73. u32 value, ul_int_que_done;
  74. int ret;
  75. isr_en_msk = &hw_info->isr_en_mask;
  76. ul_int_que_done = BIT(q_num + DP_UL_INT_DONE_OFFSET) & DP_UL_INT_QDONE_MSK;
  77. isr_en_msk->ap_ul_l2intr_en_msk &= ~ul_int_que_done;
  78. iowrite32(ul_int_que_done, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMSR0);
  79. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
  80. value, (value & ul_int_que_done) == ul_int_que_done, 0,
  81. DPMAIF_CHECK_TIMEOUT_US);
  82. if (ret)
  83. dev_err(hw_info->dev,
  84. "Could not mask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
  85. value);
  86. }
  87. void t7xx_dpmaif_unmask_ulq_intr(struct dpmaif_hw_info *hw_info, unsigned int q_num)
  88. {
  89. struct dpmaif_isr_en_mask *isr_en_msk;
  90. u32 value, ul_int_que_done;
  91. int ret;
  92. isr_en_msk = &hw_info->isr_en_mask;
  93. ul_int_que_done = BIT(q_num + DP_UL_INT_DONE_OFFSET) & DP_UL_INT_QDONE_MSK;
  94. isr_en_msk->ap_ul_l2intr_en_msk |= ul_int_que_done;
  95. iowrite32(ul_int_que_done, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMCR0);
  96. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
  97. value, (value & ul_int_que_done) != ul_int_que_done, 0,
  98. DPMAIF_CHECK_TIMEOUT_US);
  99. if (ret)
  100. dev_err(hw_info->dev,
  101. "Could not unmask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
  102. value);
  103. }
  104. void t7xx_dpmaif_dl_unmask_batcnt_len_err_intr(struct dpmaif_hw_info *hw_info)
  105. {
  106. hw_info->isr_en_mask.ap_dl_l2intr_en_msk |= DP_DL_INT_BATCNT_LEN_ERR;
  107. iowrite32(DP_DL_INT_BATCNT_LEN_ERR, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
  108. }
  109. void t7xx_dpmaif_dl_unmask_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info)
  110. {
  111. hw_info->isr_en_mask.ap_dl_l2intr_en_msk |= DP_DL_INT_PITCNT_LEN_ERR;
  112. iowrite32(DP_DL_INT_PITCNT_LEN_ERR, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
  113. }
  114. static u32 t7xx_update_dlq_intr(struct dpmaif_hw_info *hw_info, u32 q_done)
  115. {
  116. u32 value;
  117. value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0);
  118. iowrite32(q_done, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  119. return value;
  120. }
  121. static int t7xx_mask_dlq_intr(struct dpmaif_hw_info *hw_info, unsigned int qno)
  122. {
  123. u32 value, q_done;
  124. int ret;
  125. q_done = qno == DPF_RX_QNO0 ? DPMAIF_DL_INT_DLQ0_QDONE : DPMAIF_DL_INT_DLQ1_QDONE;
  126. iowrite32(q_done, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  127. ret = read_poll_timeout_atomic(t7xx_update_dlq_intr, value, value & q_done,
  128. 0, DPMAIF_CHECK_TIMEOUT_US, false, hw_info, q_done);
  129. if (ret) {
  130. dev_err(hw_info->dev,
  131. "Could not mask the DL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
  132. value);
  133. return -ETIMEDOUT;
  134. }
  135. hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~q_done;
  136. return 0;
  137. }
  138. void t7xx_dpmaif_dlq_unmask_rx_done(struct dpmaif_hw_info *hw_info, unsigned int qno)
  139. {
  140. u32 mask;
  141. mask = qno == DPF_RX_QNO0 ? DPMAIF_DL_INT_DLQ0_QDONE : DPMAIF_DL_INT_DLQ1_QDONE;
  142. iowrite32(mask, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
  143. hw_info->isr_en_mask.ap_dl_l2intr_en_msk |= mask;
  144. }
  145. void t7xx_dpmaif_clr_ip_busy_sts(struct dpmaif_hw_info *hw_info)
  146. {
  147. u32 ip_busy_sts;
  148. ip_busy_sts = ioread32(hw_info->pcie_base + DPMAIF_AP_IP_BUSY);
  149. iowrite32(ip_busy_sts, hw_info->pcie_base + DPMAIF_AP_IP_BUSY);
  150. }
  151. static void t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info,
  152. unsigned int qno)
  153. {
  154. if (qno == DPF_RX_QNO0)
  155. iowrite32(DPMAIF_DL_INT_DLQ0_PITCNT_LEN,
  156. hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  157. else
  158. iowrite32(DPMAIF_DL_INT_DLQ1_PITCNT_LEN,
  159. hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  160. }
  161. void t7xx_dpmaif_dlq_unmask_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info,
  162. unsigned int qno)
  163. {
  164. if (qno == DPF_RX_QNO0)
  165. iowrite32(DPMAIF_DL_INT_DLQ0_PITCNT_LEN,
  166. hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
  167. else
  168. iowrite32(DPMAIF_DL_INT_DLQ1_PITCNT_LEN,
  169. hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
  170. }
  171. void t7xx_dpmaif_ul_clr_all_intr(struct dpmaif_hw_info *hw_info)
  172. {
  173. iowrite32(DPMAIF_AP_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
  174. }
  175. void t7xx_dpmaif_dl_clr_all_intr(struct dpmaif_hw_info *hw_info)
  176. {
  177. iowrite32(DPMAIF_AP_APDL_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
  178. }
  179. static void t7xx_dpmaif_set_intr_para(struct dpmaif_hw_intr_st_para *para,
  180. enum dpmaif_hw_intr_type intr_type, unsigned int intr_queue)
  181. {
  182. para->intr_types[para->intr_cnt] = intr_type;
  183. para->intr_queues[para->intr_cnt] = intr_queue;
  184. para->intr_cnt++;
  185. }
  186. /* The para->intr_cnt counter is set to zero before this function is called.
  187. * It does not check for overflow as there is no risk of overflowing intr_types or intr_queues.
  188. */
  189. static void t7xx_dpmaif_hw_check_tx_intr(struct dpmaif_hw_info *hw_info,
  190. unsigned int intr_status,
  191. struct dpmaif_hw_intr_st_para *para)
  192. {
  193. unsigned long value;
  194. value = FIELD_GET(DP_UL_INT_QDONE_MSK, intr_status);
  195. if (value) {
  196. unsigned int index;
  197. t7xx_dpmaif_set_intr_para(para, DPF_INTR_UL_DONE, value);
  198. for_each_set_bit(index, &value, DPMAIF_TXQ_NUM)
  199. t7xx_dpmaif_mask_ulq_intr(hw_info, index);
  200. }
  201. value = FIELD_GET(DP_UL_INT_EMPTY_MSK, intr_status);
  202. if (value)
  203. t7xx_dpmaif_set_intr_para(para, DPF_INTR_UL_DRB_EMPTY, value);
  204. value = FIELD_GET(DP_UL_INT_MD_NOTREADY_MSK, intr_status);
  205. if (value)
  206. t7xx_dpmaif_set_intr_para(para, DPF_INTR_UL_MD_NOTREADY, value);
  207. value = FIELD_GET(DP_UL_INT_MD_PWR_NOTREADY_MSK, intr_status);
  208. if (value)
  209. t7xx_dpmaif_set_intr_para(para, DPF_INTR_UL_MD_PWR_NOTREADY, value);
  210. value = FIELD_GET(DP_UL_INT_ERR_MSK, intr_status);
  211. if (value)
  212. t7xx_dpmaif_set_intr_para(para, DPF_INTR_UL_LEN_ERR, value);
  213. /* Clear interrupt status */
  214. iowrite32(intr_status, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
  215. }
  216. /* The para->intr_cnt counter is set to zero before this function is called.
  217. * It does not check for overflow as there is no risk of overflowing intr_types or intr_queues.
  218. */
  219. static void t7xx_dpmaif_hw_check_rx_intr(struct dpmaif_hw_info *hw_info,
  220. unsigned int intr_status,
  221. struct dpmaif_hw_intr_st_para *para, int qno)
  222. {
  223. if (qno == DPF_RX_QNO_DFT) {
  224. if (intr_status & DP_DL_INT_SKB_LEN_ERR)
  225. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_SKB_LEN_ERR, DPF_RX_QNO_DFT);
  226. if (intr_status & DP_DL_INT_BATCNT_LEN_ERR) {
  227. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_BATCNT_LEN_ERR, DPF_RX_QNO_DFT);
  228. hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~DP_DL_INT_BATCNT_LEN_ERR;
  229. iowrite32(DP_DL_INT_BATCNT_LEN_ERR,
  230. hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  231. }
  232. if (intr_status & DP_DL_INT_PITCNT_LEN_ERR) {
  233. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_PITCNT_LEN_ERR, DPF_RX_QNO_DFT);
  234. hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~DP_DL_INT_PITCNT_LEN_ERR;
  235. iowrite32(DP_DL_INT_PITCNT_LEN_ERR,
  236. hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
  237. }
  238. if (intr_status & DP_DL_INT_PKT_EMPTY_MSK)
  239. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_PKT_EMPTY_SET, DPF_RX_QNO_DFT);
  240. if (intr_status & DP_DL_INT_FRG_EMPTY_MSK)
  241. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_FRG_EMPTY_SET, DPF_RX_QNO_DFT);
  242. if (intr_status & DP_DL_INT_MTU_ERR_MSK)
  243. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_MTU_ERR, DPF_RX_QNO_DFT);
  244. if (intr_status & DP_DL_INT_FRG_LEN_ERR_MSK)
  245. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_FRGCNT_LEN_ERR, DPF_RX_QNO_DFT);
  246. if (intr_status & DP_DL_INT_Q0_PITCNT_LEN_ERR) {
  247. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_Q0_PITCNT_LEN_ERR, BIT(qno));
  248. t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr(hw_info, qno);
  249. }
  250. if (intr_status & DP_DL_INT_HPC_ENT_TYPE_ERR)
  251. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_HPC_ENT_TYPE_ERR,
  252. DPF_RX_QNO_DFT);
  253. if (intr_status & DP_DL_INT_Q0_DONE) {
  254. /* Mask RX done interrupt immediately after it occurs, do not clear
  255. * the interrupt if the mask operation fails.
  256. */
  257. if (!t7xx_mask_dlq_intr(hw_info, qno))
  258. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_Q0_DONE, BIT(qno));
  259. else
  260. intr_status &= ~DP_DL_INT_Q0_DONE;
  261. }
  262. } else {
  263. if (intr_status & DP_DL_INT_Q1_PITCNT_LEN_ERR) {
  264. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_Q1_PITCNT_LEN_ERR, BIT(qno));
  265. t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr(hw_info, qno);
  266. }
  267. if (intr_status & DP_DL_INT_Q1_DONE) {
  268. if (!t7xx_mask_dlq_intr(hw_info, qno))
  269. t7xx_dpmaif_set_intr_para(para, DPF_INTR_DL_Q1_DONE, BIT(qno));
  270. else
  271. intr_status &= ~DP_DL_INT_Q1_DONE;
  272. }
  273. }
  274. intr_status |= DP_DL_INT_BATCNT_LEN_ERR;
  275. /* Clear interrupt status */
  276. iowrite32(intr_status, hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
  277. }
  278. /**
  279. * t7xx_dpmaif_hw_get_intr_cnt() - Reads interrupt status and count from HW.
  280. * @hw_info: Pointer to struct hw_info.
  281. * @para: Pointer to struct dpmaif_hw_intr_st_para.
  282. * @qno: Queue number.
  283. *
  284. * Reads RX/TX interrupt status from HW and clears UL/DL status as needed.
  285. *
  286. * Return: Interrupt count.
  287. */
  288. int t7xx_dpmaif_hw_get_intr_cnt(struct dpmaif_hw_info *hw_info,
  289. struct dpmaif_hw_intr_st_para *para, int qno)
  290. {
  291. u32 rx_intr_status, tx_intr_status = 0;
  292. u32 rx_intr_qdone, tx_intr_qdone = 0;
  293. rx_intr_status = ioread32(hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
  294. rx_intr_qdone = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMR0);
  295. /* TX interrupt status */
  296. if (qno == DPF_RX_QNO_DFT) {
  297. /* All ULQ and DLQ0 interrupts use the same source no need to check ULQ interrupts
  298. * when a DLQ1 interrupt has occurred.
  299. */
  300. tx_intr_status = ioread32(hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
  301. tx_intr_qdone = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0);
  302. }
  303. t7xx_dpmaif_clr_ip_busy_sts(hw_info);
  304. if (qno == DPF_RX_QNO_DFT) {
  305. /* Do not schedule bottom half again or clear UL interrupt status when we
  306. * have already masked it.
  307. */
  308. tx_intr_status &= ~tx_intr_qdone;
  309. if (tx_intr_status)
  310. t7xx_dpmaif_hw_check_tx_intr(hw_info, tx_intr_status, para);
  311. }
  312. if (rx_intr_status) {
  313. if (qno == DPF_RX_QNO0) {
  314. rx_intr_status &= DP_DL_Q0_STATUS_MASK;
  315. if (rx_intr_qdone & DPMAIF_DL_INT_DLQ0_QDONE)
  316. /* Do not schedule bottom half again or clear DL
  317. * queue done interrupt status when we have already masked it.
  318. */
  319. rx_intr_status &= ~DP_DL_INT_Q0_DONE;
  320. } else {
  321. rx_intr_status &= DP_DL_Q1_STATUS_MASK;
  322. if (rx_intr_qdone & DPMAIF_DL_INT_DLQ1_QDONE)
  323. rx_intr_status &= ~DP_DL_INT_Q1_DONE;
  324. }
  325. if (rx_intr_status)
  326. t7xx_dpmaif_hw_check_rx_intr(hw_info, rx_intr_status, para, qno);
  327. }
  328. return para->intr_cnt;
  329. }
  330. static int t7xx_dpmaif_sram_init(struct dpmaif_hw_info *hw_info)
  331. {
  332. u32 value;
  333. value = ioread32(hw_info->pcie_base + DPMAIF_AP_MEM_CLR);
  334. value |= DPMAIF_MEM_CLR;
  335. iowrite32(value, hw_info->pcie_base + DPMAIF_AP_MEM_CLR);
  336. return ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_AP_MEM_CLR,
  337. value, !(value & DPMAIF_MEM_CLR), 0,
  338. DPMAIF_CHECK_INIT_TIMEOUT_US);
  339. }
  340. static void t7xx_dpmaif_hw_reset(struct dpmaif_hw_info *hw_info)
  341. {
  342. iowrite32(DPMAIF_AP_AO_RST_BIT, hw_info->pcie_base + DPMAIF_AP_AO_RGU_ASSERT);
  343. udelay(2);
  344. iowrite32(DPMAIF_AP_RST_BIT, hw_info->pcie_base + DPMAIF_AP_RGU_ASSERT);
  345. udelay(2);
  346. iowrite32(DPMAIF_AP_AO_RST_BIT, hw_info->pcie_base + DPMAIF_AP_AO_RGU_DEASSERT);
  347. udelay(2);
  348. iowrite32(DPMAIF_AP_RST_BIT, hw_info->pcie_base + DPMAIF_AP_RGU_DEASSERT);
  349. udelay(2);
  350. }
  351. static int t7xx_dpmaif_hw_config(struct dpmaif_hw_info *hw_info)
  352. {
  353. u32 ap_port_mode;
  354. int ret;
  355. t7xx_dpmaif_hw_reset(hw_info);
  356. ret = t7xx_dpmaif_sram_init(hw_info);
  357. if (ret)
  358. return ret;
  359. ap_port_mode = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  360. ap_port_mode |= DPMAIF_PORT_MODE_PCIE;
  361. iowrite32(ap_port_mode, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  362. iowrite32(DPMAIF_CG_EN, hw_info->pcie_base + DPMAIF_AP_CG_EN);
  363. return 0;
  364. }
  365. static void t7xx_dpmaif_pcie_dpmaif_sign(struct dpmaif_hw_info *hw_info)
  366. {
  367. iowrite32(DPMAIF_PCIE_MODE_SET_VALUE, hw_info->pcie_base + DPMAIF_UL_RESERVE_AO_RW);
  368. }
  369. static void t7xx_dpmaif_dl_performance(struct dpmaif_hw_info *hw_info)
  370. {
  371. u32 enable_bat_cache, enable_pit_burst;
  372. enable_bat_cache = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  373. enable_bat_cache |= DPMAIF_DL_BAT_CACHE_PRI;
  374. iowrite32(enable_bat_cache, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  375. enable_pit_burst = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  376. enable_pit_burst |= DPMAIF_DL_BURST_PIT_EN;
  377. iowrite32(enable_pit_burst, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  378. }
  379. /* DPMAIF DL DLQ part HW setting */
  380. static void t7xx_dpmaif_hw_hpc_cntl_set(struct dpmaif_hw_info *hw_info)
  381. {
  382. unsigned int value;
  383. value = DPMAIF_HPC_DLQ_PATH_MODE | DPMAIF_HPC_ADD_MODE_DF << 2;
  384. value |= DPMAIF_HASH_PRIME_DF << 4;
  385. value |= DPMAIF_HPC_TOTAL_NUM << 8;
  386. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_HPC_CNTL);
  387. }
  388. static void t7xx_dpmaif_hw_agg_cfg_set(struct dpmaif_hw_info *hw_info)
  389. {
  390. unsigned int value;
  391. value = DPMAIF_AGG_MAX_LEN_DF | DPMAIF_AGG_TBL_ENT_NUM_DF << 16;
  392. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_DLQ_AGG_CFG);
  393. }
  394. static void t7xx_dpmaif_hw_hash_bit_choose_set(struct dpmaif_hw_info *hw_info)
  395. {
  396. iowrite32(DPMAIF_DLQ_HASH_BIT_CHOOSE_DF,
  397. hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_INIT_CON5);
  398. }
  399. static void t7xx_dpmaif_hw_mid_pit_timeout_thres_set(struct dpmaif_hw_info *hw_info)
  400. {
  401. iowrite32(DPMAIF_MID_TIMEOUT_THRES_DF, hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_TIMEOUT0);
  402. }
  403. static void t7xx_dpmaif_hw_dlq_timeout_thres_set(struct dpmaif_hw_info *hw_info)
  404. {
  405. unsigned int value, i;
  406. /* Each register holds two DLQ threshold timeout values */
  407. for (i = 0; i < DPMAIF_HPC_MAX_TOTAL_NUM / 2; i++) {
  408. value = FIELD_PREP(DPMAIF_DLQ_LOW_TIMEOUT_THRES_MKS, DPMAIF_DLQ_TIMEOUT_THRES_DF);
  409. value |= FIELD_PREP(DPMAIF_DLQ_HIGH_TIMEOUT_THRES_MSK,
  410. DPMAIF_DLQ_TIMEOUT_THRES_DF);
  411. iowrite32(value,
  412. hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_TIMEOUT1 + sizeof(u32) * i);
  413. }
  414. }
  415. static void t7xx_dpmaif_hw_dlq_start_prs_thres_set(struct dpmaif_hw_info *hw_info)
  416. {
  417. iowrite32(DPMAIF_DLQ_PRS_THRES_DF, hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_TRIG_THRES);
  418. }
  419. static void t7xx_dpmaif_dl_dlq_hpc_hw_init(struct dpmaif_hw_info *hw_info)
  420. {
  421. t7xx_dpmaif_hw_hpc_cntl_set(hw_info);
  422. t7xx_dpmaif_hw_agg_cfg_set(hw_info);
  423. t7xx_dpmaif_hw_hash_bit_choose_set(hw_info);
  424. t7xx_dpmaif_hw_mid_pit_timeout_thres_set(hw_info);
  425. t7xx_dpmaif_hw_dlq_timeout_thres_set(hw_info);
  426. t7xx_dpmaif_hw_dlq_start_prs_thres_set(hw_info);
  427. }
  428. static int t7xx_dpmaif_dl_bat_init_done(struct dpmaif_hw_info *hw_info, bool frg_en)
  429. {
  430. u32 value, dl_bat_init = 0;
  431. int ret;
  432. if (frg_en)
  433. dl_bat_init = DPMAIF_DL_BAT_FRG_INIT;
  434. dl_bat_init |= DPMAIF_DL_BAT_INIT_ALLSET;
  435. dl_bat_init |= DPMAIF_DL_BAT_INIT_EN;
  436. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
  437. value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY), 0,
  438. DPMAIF_CHECK_INIT_TIMEOUT_US);
  439. if (ret) {
  440. dev_err(hw_info->dev, "Data plane modem DL BAT is not ready\n");
  441. return ret;
  442. }
  443. iowrite32(dl_bat_init, hw_info->pcie_base + DPMAIF_DL_BAT_INIT);
  444. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
  445. value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY), 0,
  446. DPMAIF_CHECK_INIT_TIMEOUT_US);
  447. if (ret)
  448. dev_err(hw_info->dev, "Data plane modem DL BAT initialization failed\n");
  449. return ret;
  450. }
  451. static void t7xx_dpmaif_dl_set_bat_base_addr(struct dpmaif_hw_info *hw_info,
  452. dma_addr_t addr)
  453. {
  454. iowrite32(lower_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON0);
  455. iowrite32(upper_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON3);
  456. }
  457. static void t7xx_dpmaif_dl_set_bat_size(struct dpmaif_hw_info *hw_info, unsigned int size)
  458. {
  459. unsigned int value;
  460. value = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  461. value &= ~DPMAIF_BAT_SIZE_MSK;
  462. value |= size & DPMAIF_BAT_SIZE_MSK;
  463. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  464. }
  465. static void t7xx_dpmaif_dl_bat_en(struct dpmaif_hw_info *hw_info, bool enable)
  466. {
  467. unsigned int value;
  468. value = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  469. if (enable)
  470. value |= DPMAIF_BAT_EN_MSK;
  471. else
  472. value &= ~DPMAIF_BAT_EN_MSK;
  473. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  474. }
  475. static void t7xx_dpmaif_dl_set_ao_bid_maxcnt(struct dpmaif_hw_info *hw_info)
  476. {
  477. unsigned int value;
  478. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
  479. value &= ~DPMAIF_BAT_BID_MAXCNT_MSK;
  480. value |= FIELD_PREP(DPMAIF_BAT_BID_MAXCNT_MSK, DPMAIF_HW_PKT_BIDCNT);
  481. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
  482. }
  483. static void t7xx_dpmaif_dl_set_ao_mtu(struct dpmaif_hw_info *hw_info)
  484. {
  485. iowrite32(DPMAIF_HW_MTU_SIZE, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON1);
  486. }
  487. static void t7xx_dpmaif_dl_set_ao_pit_chknum(struct dpmaif_hw_info *hw_info)
  488. {
  489. unsigned int value;
  490. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
  491. value &= ~DPMAIF_PIT_CHK_NUM_MSK;
  492. value |= FIELD_PREP(DPMAIF_PIT_CHK_NUM_MSK, DPMAIF_HW_CHK_PIT_NUM);
  493. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
  494. }
  495. static void t7xx_dpmaif_dl_set_ao_remain_minsz(struct dpmaif_hw_info *hw_info)
  496. {
  497. unsigned int value;
  498. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
  499. value &= ~DPMAIF_BAT_REMAIN_MINSZ_MSK;
  500. value |= FIELD_PREP(DPMAIF_BAT_REMAIN_MINSZ_MSK,
  501. DPMAIF_HW_BAT_REMAIN / DPMAIF_BAT_REMAIN_SZ_BASE);
  502. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
  503. }
  504. static void t7xx_dpmaif_dl_set_ao_bat_bufsz(struct dpmaif_hw_info *hw_info)
  505. {
  506. unsigned int value;
  507. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
  508. value &= ~DPMAIF_BAT_BUF_SZ_MSK;
  509. value |= FIELD_PREP(DPMAIF_BAT_BUF_SZ_MSK,
  510. DPMAIF_HW_BAT_PKTBUF / DPMAIF_BAT_BUFFER_SZ_BASE);
  511. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
  512. }
  513. static void t7xx_dpmaif_dl_set_ao_bat_rsv_length(struct dpmaif_hw_info *hw_info)
  514. {
  515. unsigned int value;
  516. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
  517. value &= ~DPMAIF_BAT_RSV_LEN_MSK;
  518. value |= DPMAIF_HW_BAT_RSVLEN;
  519. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
  520. }
  521. static void t7xx_dpmaif_dl_set_pkt_alignment(struct dpmaif_hw_info *hw_info)
  522. {
  523. unsigned int value;
  524. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  525. value &= ~DPMAIF_PKT_ALIGN_MSK;
  526. value |= DPMAIF_PKT_ALIGN_EN;
  527. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  528. }
  529. static void t7xx_dpmaif_dl_set_pkt_checksum(struct dpmaif_hw_info *hw_info)
  530. {
  531. unsigned int value;
  532. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  533. value |= DPMAIF_DL_PKT_CHECKSUM_EN;
  534. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  535. }
  536. static void t7xx_dpmaif_dl_set_ao_frg_check_thres(struct dpmaif_hw_info *hw_info)
  537. {
  538. unsigned int value;
  539. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
  540. value &= ~DPMAIF_FRG_CHECK_THRES_MSK;
  541. value |= DPMAIF_HW_CHK_FRG_NUM;
  542. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
  543. }
  544. static void t7xx_dpmaif_dl_set_ao_frg_bufsz(struct dpmaif_hw_info *hw_info)
  545. {
  546. unsigned int value;
  547. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
  548. value &= ~DPMAIF_FRG_BUF_SZ_MSK;
  549. value |= FIELD_PREP(DPMAIF_FRG_BUF_SZ_MSK,
  550. DPMAIF_HW_FRG_PKTBUF / DPMAIF_FRG_BUFFER_SZ_BASE);
  551. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
  552. }
  553. static void t7xx_dpmaif_dl_frg_ao_en(struct dpmaif_hw_info *hw_info, bool enable)
  554. {
  555. unsigned int value;
  556. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
  557. if (enable)
  558. value |= DPMAIF_FRG_EN_MSK;
  559. else
  560. value &= ~DPMAIF_FRG_EN_MSK;
  561. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
  562. }
  563. static void t7xx_dpmaif_dl_set_ao_bat_check_thres(struct dpmaif_hw_info *hw_info)
  564. {
  565. unsigned int value;
  566. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  567. value &= ~DPMAIF_BAT_CHECK_THRES_MSK;
  568. value |= FIELD_PREP(DPMAIF_BAT_CHECK_THRES_MSK, DPMAIF_HW_CHK_BAT_NUM);
  569. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
  570. }
  571. static void t7xx_dpmaif_dl_set_pit_seqnum(struct dpmaif_hw_info *hw_info)
  572. {
  573. unsigned int value;
  574. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PIT_SEQ_END);
  575. value &= ~DPMAIF_DL_PIT_SEQ_MSK;
  576. value |= DPMAIF_DL_PIT_SEQ_VALUE;
  577. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PIT_SEQ_END);
  578. }
  579. static void t7xx_dpmaif_dl_set_dlq_pit_base_addr(struct dpmaif_hw_info *hw_info,
  580. dma_addr_t addr)
  581. {
  582. iowrite32(lower_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON0);
  583. iowrite32(upper_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON4);
  584. }
  585. static void t7xx_dpmaif_dl_set_dlq_pit_size(struct dpmaif_hw_info *hw_info, unsigned int size)
  586. {
  587. unsigned int value;
  588. value = ioread32(hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON1);
  589. value &= ~DPMAIF_PIT_SIZE_MSK;
  590. value |= size & DPMAIF_PIT_SIZE_MSK;
  591. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON1);
  592. iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON2);
  593. iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON3);
  594. iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON5);
  595. iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON6);
  596. }
  597. static void t7xx_dpmaif_dl_dlq_pit_en(struct dpmaif_hw_info *hw_info)
  598. {
  599. unsigned int value;
  600. value = ioread32(hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON3);
  601. value |= DPMAIF_DLQPIT_EN_MSK;
  602. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON3);
  603. }
  604. static void t7xx_dpmaif_dl_dlq_pit_init_done(struct dpmaif_hw_info *hw_info,
  605. unsigned int pit_idx)
  606. {
  607. unsigned int dl_pit_init;
  608. int timeout;
  609. u32 value;
  610. dl_pit_init = DPMAIF_DL_PIT_INIT_ALLSET;
  611. dl_pit_init |= (pit_idx << DPMAIF_DLQPIT_CHAN_OFS);
  612. dl_pit_init |= DPMAIF_DL_PIT_INIT_EN;
  613. timeout = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT,
  614. value, !(value & DPMAIF_DL_PIT_INIT_NOT_READY),
  615. DPMAIF_CHECK_DELAY_US,
  616. DPMAIF_CHECK_INIT_TIMEOUT_US);
  617. if (timeout) {
  618. dev_err(hw_info->dev, "Data plane modem DL PIT is not ready\n");
  619. return;
  620. }
  621. iowrite32(dl_pit_init, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT);
  622. timeout = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT,
  623. value, !(value & DPMAIF_DL_PIT_INIT_NOT_READY),
  624. DPMAIF_CHECK_DELAY_US,
  625. DPMAIF_CHECK_INIT_TIMEOUT_US);
  626. if (timeout)
  627. dev_err(hw_info->dev, "Data plane modem DL PIT initialization failed\n");
  628. }
  629. static void t7xx_dpmaif_config_dlq_pit_hw(struct dpmaif_hw_info *hw_info, unsigned int q_num,
  630. struct dpmaif_dl *dl_que)
  631. {
  632. t7xx_dpmaif_dl_set_dlq_pit_base_addr(hw_info, dl_que->pit_base);
  633. t7xx_dpmaif_dl_set_dlq_pit_size(hw_info, dl_que->pit_size_cnt);
  634. t7xx_dpmaif_dl_dlq_pit_en(hw_info);
  635. t7xx_dpmaif_dl_dlq_pit_init_done(hw_info, q_num);
  636. }
  637. static void t7xx_dpmaif_config_all_dlq_hw(struct dpmaif_hw_info *hw_info)
  638. {
  639. int i;
  640. for (i = 0; i < DPMAIF_RXQ_NUM; i++)
  641. t7xx_dpmaif_config_dlq_pit_hw(hw_info, i, &hw_info->dl_que[i]);
  642. }
  643. static void t7xx_dpmaif_dl_all_q_en(struct dpmaif_hw_info *hw_info, bool enable)
  644. {
  645. u32 dl_bat_init, value;
  646. int timeout;
  647. value = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  648. if (enable)
  649. value |= DPMAIF_BAT_EN_MSK;
  650. else
  651. value &= ~DPMAIF_BAT_EN_MSK;
  652. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
  653. dl_bat_init = DPMAIF_DL_BAT_INIT_ONLY_ENABLE_BIT;
  654. dl_bat_init |= DPMAIF_DL_BAT_INIT_EN;
  655. timeout = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
  656. value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY), 0,
  657. DPMAIF_CHECK_TIMEOUT_US);
  658. if (timeout)
  659. dev_err(hw_info->dev, "Timeout updating BAT setting to HW\n");
  660. iowrite32(dl_bat_init, hw_info->pcie_base + DPMAIF_DL_BAT_INIT);
  661. timeout = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
  662. value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY), 0,
  663. DPMAIF_CHECK_TIMEOUT_US);
  664. if (timeout)
  665. dev_err(hw_info->dev, "Data plane modem DL BAT is not ready\n");
  666. }
  667. static int t7xx_dpmaif_config_dlq_hw(struct dpmaif_hw_info *hw_info)
  668. {
  669. struct dpmaif_dl *dl_que;
  670. int ret;
  671. t7xx_dpmaif_dl_dlq_hpc_hw_init(hw_info);
  672. dl_que = &hw_info->dl_que[0]; /* All queues share one BAT/frag BAT table */
  673. if (!dl_que->que_started)
  674. return -EBUSY;
  675. t7xx_dpmaif_dl_set_ao_remain_minsz(hw_info);
  676. t7xx_dpmaif_dl_set_ao_bat_bufsz(hw_info);
  677. t7xx_dpmaif_dl_set_ao_frg_bufsz(hw_info);
  678. t7xx_dpmaif_dl_set_ao_bat_rsv_length(hw_info);
  679. t7xx_dpmaif_dl_set_ao_bid_maxcnt(hw_info);
  680. t7xx_dpmaif_dl_set_pkt_alignment(hw_info);
  681. t7xx_dpmaif_dl_set_pit_seqnum(hw_info);
  682. t7xx_dpmaif_dl_set_ao_mtu(hw_info);
  683. t7xx_dpmaif_dl_set_ao_pit_chknum(hw_info);
  684. t7xx_dpmaif_dl_set_ao_bat_check_thres(hw_info);
  685. t7xx_dpmaif_dl_set_ao_frg_check_thres(hw_info);
  686. t7xx_dpmaif_dl_frg_ao_en(hw_info, true);
  687. t7xx_dpmaif_dl_set_bat_base_addr(hw_info, dl_que->frg_base);
  688. t7xx_dpmaif_dl_set_bat_size(hw_info, dl_que->frg_size_cnt);
  689. t7xx_dpmaif_dl_bat_en(hw_info, true);
  690. ret = t7xx_dpmaif_dl_bat_init_done(hw_info, true);
  691. if (ret)
  692. return ret;
  693. t7xx_dpmaif_dl_set_bat_base_addr(hw_info, dl_que->bat_base);
  694. t7xx_dpmaif_dl_set_bat_size(hw_info, dl_que->bat_size_cnt);
  695. t7xx_dpmaif_dl_bat_en(hw_info, false);
  696. ret = t7xx_dpmaif_dl_bat_init_done(hw_info, false);
  697. if (ret)
  698. return ret;
  699. /* Init PIT (two PIT table) */
  700. t7xx_dpmaif_config_all_dlq_hw(hw_info);
  701. t7xx_dpmaif_dl_all_q_en(hw_info, true);
  702. t7xx_dpmaif_dl_set_pkt_checksum(hw_info);
  703. return 0;
  704. }
  705. static void t7xx_dpmaif_ul_update_drb_size(struct dpmaif_hw_info *hw_info,
  706. unsigned int q_num, unsigned int size)
  707. {
  708. unsigned int value;
  709. value = ioread32(hw_info->pcie_base + DPMAIF_UL_DRBSIZE_ADDRH_n(q_num));
  710. value &= ~DPMAIF_DRB_SIZE_MSK;
  711. value |= size & DPMAIF_DRB_SIZE_MSK;
  712. iowrite32(value, hw_info->pcie_base + DPMAIF_UL_DRBSIZE_ADDRH_n(q_num));
  713. }
  714. static void t7xx_dpmaif_ul_update_drb_base_addr(struct dpmaif_hw_info *hw_info,
  715. unsigned int q_num, dma_addr_t addr)
  716. {
  717. iowrite32(lower_32_bits(addr), hw_info->pcie_base + DPMAIF_ULQSAR_n(q_num));
  718. iowrite32(upper_32_bits(addr), hw_info->pcie_base + DPMAIF_UL_DRB_ADDRH_n(q_num));
  719. }
  720. static void t7xx_dpmaif_ul_rdy_en(struct dpmaif_hw_info *hw_info,
  721. unsigned int q_num, bool ready)
  722. {
  723. u32 value;
  724. value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
  725. if (ready)
  726. value |= BIT(q_num);
  727. else
  728. value &= ~BIT(q_num);
  729. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
  730. }
  731. static void t7xx_dpmaif_ul_arb_en(struct dpmaif_hw_info *hw_info,
  732. unsigned int q_num, bool enable)
  733. {
  734. u32 value;
  735. value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
  736. if (enable)
  737. value |= BIT(q_num + 8);
  738. else
  739. value &= ~BIT(q_num + 8);
  740. iowrite32(value, hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
  741. }
  742. static void t7xx_dpmaif_config_ulq_hw(struct dpmaif_hw_info *hw_info)
  743. {
  744. struct dpmaif_ul *ul_que;
  745. int i;
  746. for (i = 0; i < DPMAIF_TXQ_NUM; i++) {
  747. ul_que = &hw_info->ul_que[i];
  748. if (ul_que->que_started) {
  749. t7xx_dpmaif_ul_update_drb_size(hw_info, i, ul_que->drb_size_cnt *
  750. DPMAIF_UL_DRB_SIZE_WORD);
  751. t7xx_dpmaif_ul_update_drb_base_addr(hw_info, i, ul_que->drb_base);
  752. t7xx_dpmaif_ul_rdy_en(hw_info, i, true);
  753. t7xx_dpmaif_ul_arb_en(hw_info, i, true);
  754. } else {
  755. t7xx_dpmaif_ul_arb_en(hw_info, i, false);
  756. }
  757. }
  758. }
  759. static int t7xx_dpmaif_hw_init_done(struct dpmaif_hw_info *hw_info)
  760. {
  761. u32 ap_cfg;
  762. int ret;
  763. ap_cfg = ioread32(hw_info->pcie_base + DPMAIF_AP_OVERWRITE_CFG);
  764. ap_cfg |= DPMAIF_SRAM_SYNC;
  765. iowrite32(ap_cfg, hw_info->pcie_base + DPMAIF_AP_OVERWRITE_CFG);
  766. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_AP_OVERWRITE_CFG,
  767. ap_cfg, !(ap_cfg & DPMAIF_SRAM_SYNC), 0,
  768. DPMAIF_CHECK_TIMEOUT_US);
  769. if (ret)
  770. return ret;
  771. iowrite32(DPMAIF_UL_INIT_DONE, hw_info->pcie_base + DPMAIF_AO_UL_INIT_SET);
  772. iowrite32(DPMAIF_DL_INIT_DONE, hw_info->pcie_base + DPMAIF_AO_DL_INIT_SET);
  773. return 0;
  774. }
  775. static bool t7xx_dpmaif_dl_idle_check(struct dpmaif_hw_info *hw_info)
  776. {
  777. u32 dpmaif_dl_is_busy = ioread32(hw_info->pcie_base + DPMAIF_DL_CHK_BUSY);
  778. return !(dpmaif_dl_is_busy & DPMAIF_DL_IDLE_STS);
  779. }
  780. static void t7xx_dpmaif_ul_all_q_en(struct dpmaif_hw_info *hw_info, bool enable)
  781. {
  782. u32 ul_arb_en = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
  783. if (enable)
  784. ul_arb_en |= DPMAIF_UL_ALL_QUE_ARB_EN;
  785. else
  786. ul_arb_en &= ~DPMAIF_UL_ALL_QUE_ARB_EN;
  787. iowrite32(ul_arb_en, hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
  788. }
  789. static bool t7xx_dpmaif_ul_idle_check(struct dpmaif_hw_info *hw_info)
  790. {
  791. u32 dpmaif_ul_is_busy = ioread32(hw_info->pcie_base + DPMAIF_UL_CHK_BUSY);
  792. return !(dpmaif_ul_is_busy & DPMAIF_UL_IDLE_STS);
  793. }
  794. void t7xx_dpmaif_ul_update_hw_drb_cnt(struct dpmaif_hw_info *hw_info, unsigned int q_num,
  795. unsigned int drb_entry_cnt)
  796. {
  797. u32 ul_update, value;
  798. int err;
  799. ul_update = drb_entry_cnt & DPMAIF_UL_ADD_COUNT_MASK;
  800. ul_update |= DPMAIF_UL_ADD_UPDATE;
  801. err = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_ULQ_ADD_DESC_CH_n(q_num),
  802. value, !(value & DPMAIF_UL_ADD_NOT_READY), 0,
  803. DPMAIF_CHECK_TIMEOUT_US);
  804. if (err) {
  805. dev_err(hw_info->dev, "UL add is not ready\n");
  806. return;
  807. }
  808. iowrite32(ul_update, hw_info->pcie_base + DPMAIF_ULQ_ADD_DESC_CH_n(q_num));
  809. err = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_ULQ_ADD_DESC_CH_n(q_num),
  810. value, !(value & DPMAIF_UL_ADD_NOT_READY), 0,
  811. DPMAIF_CHECK_TIMEOUT_US);
  812. if (err)
  813. dev_err(hw_info->dev, "Timeout updating UL add\n");
  814. }
  815. unsigned int t7xx_dpmaif_ul_get_rd_idx(struct dpmaif_hw_info *hw_info, unsigned int q_num)
  816. {
  817. unsigned int value = ioread32(hw_info->pcie_base + DPMAIF_ULQ_STA0_n(q_num));
  818. return FIELD_GET(DPMAIF_UL_DRB_RIDX_MSK, value) / DPMAIF_UL_DRB_SIZE_WORD;
  819. }
  820. int t7xx_dpmaif_dlq_add_pit_remain_cnt(struct dpmaif_hw_info *hw_info, unsigned int dlq_pit_idx,
  821. unsigned int pit_remain_cnt)
  822. {
  823. u32 dl_update, value;
  824. int ret;
  825. dl_update = pit_remain_cnt & DPMAIF_PIT_REM_CNT_MSK;
  826. dl_update |= DPMAIF_DL_ADD_UPDATE | (dlq_pit_idx << DPMAIF_ADD_DLQ_PIT_CHAN_OFS);
  827. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_DLQPIT_ADD,
  828. value, !(value & DPMAIF_DL_ADD_NOT_READY), 0,
  829. DPMAIF_CHECK_TIMEOUT_US);
  830. if (ret) {
  831. dev_err(hw_info->dev, "Data plane modem is not ready to add dlq\n");
  832. return ret;
  833. }
  834. iowrite32(dl_update, hw_info->pcie_base + DPMAIF_DL_DLQPIT_ADD);
  835. ret = ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_DLQPIT_ADD,
  836. value, !(value & DPMAIF_DL_ADD_NOT_READY), 0,
  837. DPMAIF_CHECK_TIMEOUT_US);
  838. if (ret) {
  839. dev_err(hw_info->dev, "Data plane modem add dlq failed\n");
  840. return ret;
  841. }
  842. return 0;
  843. }
  844. unsigned int t7xx_dpmaif_dl_dlq_pit_get_wr_idx(struct dpmaif_hw_info *hw_info,
  845. unsigned int dlq_pit_idx)
  846. {
  847. u32 value;
  848. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_DLQ_WR_IDX +
  849. dlq_pit_idx * DLQ_PIT_IDX_SIZE);
  850. return value & DPMAIF_DL_RD_WR_IDX_MSK;
  851. }
  852. static int t7xx_dl_add_timedout(struct dpmaif_hw_info *hw_info)
  853. {
  854. u32 value;
  855. return ioread32_poll_timeout_atomic(hw_info->pcie_base + DPMAIF_DL_BAT_ADD,
  856. value, !(value & DPMAIF_DL_ADD_NOT_READY), 0,
  857. DPMAIF_CHECK_TIMEOUT_US);
  858. }
  859. int t7xx_dpmaif_dl_snd_hw_bat_cnt(struct dpmaif_hw_info *hw_info, unsigned int bat_entry_cnt)
  860. {
  861. unsigned int value;
  862. if (t7xx_dl_add_timedout(hw_info)) {
  863. dev_err(hw_info->dev, "DL add BAT not ready\n");
  864. return -EBUSY;
  865. }
  866. value = bat_entry_cnt & DPMAIF_DL_ADD_COUNT_MASK;
  867. value |= DPMAIF_DL_ADD_UPDATE;
  868. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_ADD);
  869. if (t7xx_dl_add_timedout(hw_info)) {
  870. dev_err(hw_info->dev, "DL add BAT timeout\n");
  871. return -EBUSY;
  872. }
  873. return 0;
  874. }
  875. unsigned int t7xx_dpmaif_dl_get_bat_rd_idx(struct dpmaif_hw_info *hw_info, unsigned int q_num)
  876. {
  877. u32 value;
  878. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_BAT_RD_IDX);
  879. return value & DPMAIF_DL_RD_WR_IDX_MSK;
  880. }
  881. unsigned int t7xx_dpmaif_dl_get_bat_wr_idx(struct dpmaif_hw_info *hw_info, unsigned int q_num)
  882. {
  883. u32 value;
  884. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_BAT_WR_IDX);
  885. return value & DPMAIF_DL_RD_WR_IDX_MSK;
  886. }
  887. int t7xx_dpmaif_dl_snd_hw_frg_cnt(struct dpmaif_hw_info *hw_info, unsigned int frg_entry_cnt)
  888. {
  889. unsigned int value;
  890. if (t7xx_dl_add_timedout(hw_info)) {
  891. dev_err(hw_info->dev, "Data plane modem is not ready to add frag DLQ\n");
  892. return -EBUSY;
  893. }
  894. value = frg_entry_cnt & DPMAIF_DL_ADD_COUNT_MASK;
  895. value |= DPMAIF_DL_FRG_ADD_UPDATE | DPMAIF_DL_ADD_UPDATE;
  896. iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_ADD);
  897. if (t7xx_dl_add_timedout(hw_info)) {
  898. dev_err(hw_info->dev, "Data plane modem add frag DLQ failed");
  899. return -EBUSY;
  900. }
  901. return 0;
  902. }
  903. unsigned int t7xx_dpmaif_dl_get_frg_rd_idx(struct dpmaif_hw_info *hw_info, unsigned int q_num)
  904. {
  905. u32 value;
  906. value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_FRGBAT_RD_IDX);
  907. return value & DPMAIF_DL_RD_WR_IDX_MSK;
  908. }
  909. static void t7xx_dpmaif_set_queue_property(struct dpmaif_hw_info *hw_info,
  910. struct dpmaif_hw_params *init_para)
  911. {
  912. struct dpmaif_dl *dl_que;
  913. struct dpmaif_ul *ul_que;
  914. int i;
  915. for (i = 0; i < DPMAIF_RXQ_NUM; i++) {
  916. dl_que = &hw_info->dl_que[i];
  917. dl_que->bat_base = init_para->pkt_bat_base_addr[i];
  918. dl_que->bat_size_cnt = init_para->pkt_bat_size_cnt[i];
  919. dl_que->pit_base = init_para->pit_base_addr[i];
  920. dl_que->pit_size_cnt = init_para->pit_size_cnt[i];
  921. dl_que->frg_base = init_para->frg_bat_base_addr[i];
  922. dl_que->frg_size_cnt = init_para->frg_bat_size_cnt[i];
  923. dl_que->que_started = true;
  924. }
  925. for (i = 0; i < DPMAIF_TXQ_NUM; i++) {
  926. ul_que = &hw_info->ul_que[i];
  927. ul_que->drb_base = init_para->drb_base_addr[i];
  928. ul_que->drb_size_cnt = init_para->drb_size_cnt[i];
  929. ul_que->que_started = true;
  930. }
  931. }
  932. /**
  933. * t7xx_dpmaif_hw_stop_all_txq() - Stop all TX queues.
  934. * @hw_info: Pointer to struct hw_info.
  935. *
  936. * Disable HW UL queues. Checks busy UL queues to go to idle
  937. * with an attempt count of 1000000.
  938. *
  939. * Return:
  940. * * 0 - Success
  941. * * -ETIMEDOUT - Timed out checking busy queues
  942. */
  943. int t7xx_dpmaif_hw_stop_all_txq(struct dpmaif_hw_info *hw_info)
  944. {
  945. int count = 0;
  946. t7xx_dpmaif_ul_all_q_en(hw_info, false);
  947. while (t7xx_dpmaif_ul_idle_check(hw_info)) {
  948. if (++count >= DPMAIF_MAX_CHECK_COUNT) {
  949. dev_err(hw_info->dev, "Failed to stop TX, status: 0x%x\n",
  950. ioread32(hw_info->pcie_base + DPMAIF_UL_CHK_BUSY));
  951. return -ETIMEDOUT;
  952. }
  953. }
  954. return 0;
  955. }
  956. /**
  957. * t7xx_dpmaif_hw_stop_all_rxq() - Stop all RX queues.
  958. * @hw_info: Pointer to struct hw_info.
  959. *
  960. * Disable HW DL queue. Checks busy UL queues to go to idle
  961. * with an attempt count of 1000000.
  962. * Check that HW PIT write index equals read index with the same
  963. * attempt count.
  964. *
  965. * Return:
  966. * * 0 - Success.
  967. * * -ETIMEDOUT - Timed out checking busy queues.
  968. */
  969. int t7xx_dpmaif_hw_stop_all_rxq(struct dpmaif_hw_info *hw_info)
  970. {
  971. unsigned int wr_idx, rd_idx;
  972. int count = 0;
  973. t7xx_dpmaif_dl_all_q_en(hw_info, false);
  974. while (t7xx_dpmaif_dl_idle_check(hw_info)) {
  975. if (++count >= DPMAIF_MAX_CHECK_COUNT) {
  976. dev_err(hw_info->dev, "Failed to stop RX, status: 0x%x\n",
  977. ioread32(hw_info->pcie_base + DPMAIF_DL_CHK_BUSY));
  978. return -ETIMEDOUT;
  979. }
  980. }
  981. /* Check middle PIT sync done */
  982. count = 0;
  983. do {
  984. wr_idx = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PIT_WR_IDX);
  985. wr_idx &= DPMAIF_DL_RD_WR_IDX_MSK;
  986. rd_idx = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PIT_RD_IDX);
  987. rd_idx &= DPMAIF_DL_RD_WR_IDX_MSK;
  988. if (wr_idx == rd_idx)
  989. return 0;
  990. } while (++count < DPMAIF_MAX_CHECK_COUNT);
  991. dev_err(hw_info->dev, "Check middle PIT sync fail\n");
  992. return -ETIMEDOUT;
  993. }
  994. void t7xx_dpmaif_start_hw(struct dpmaif_hw_info *hw_info)
  995. {
  996. t7xx_dpmaif_ul_all_q_en(hw_info, true);
  997. t7xx_dpmaif_dl_all_q_en(hw_info, true);
  998. }
  999. /**
  1000. * t7xx_dpmaif_hw_init() - Initialize HW data path API.
  1001. * @hw_info: Pointer to struct hw_info.
  1002. * @init_param: Pointer to struct dpmaif_hw_params.
  1003. *
  1004. * Configures port mode, clock config, HW interrupt initialization, and HW queue.
  1005. *
  1006. * Return:
  1007. * * 0 - Success.
  1008. * * -ERROR - Error code from failure sub-initializations.
  1009. */
  1010. int t7xx_dpmaif_hw_init(struct dpmaif_hw_info *hw_info, struct dpmaif_hw_params *init_param)
  1011. {
  1012. int ret;
  1013. ret = t7xx_dpmaif_hw_config(hw_info);
  1014. if (ret) {
  1015. dev_err(hw_info->dev, "DPMAIF HW config failed\n");
  1016. return ret;
  1017. }
  1018. ret = t7xx_dpmaif_init_intr(hw_info);
  1019. if (ret) {
  1020. dev_err(hw_info->dev, "DPMAIF HW interrupts init failed\n");
  1021. return ret;
  1022. }
  1023. t7xx_dpmaif_set_queue_property(hw_info, init_param);
  1024. t7xx_dpmaif_pcie_dpmaif_sign(hw_info);
  1025. t7xx_dpmaif_dl_performance(hw_info);
  1026. ret = t7xx_dpmaif_config_dlq_hw(hw_info);
  1027. if (ret) {
  1028. dev_err(hw_info->dev, "DPMAIF HW dlq config failed\n");
  1029. return ret;
  1030. }
  1031. t7xx_dpmaif_config_ulq_hw(hw_info);
  1032. ret = t7xx_dpmaif_hw_init_done(hw_info);
  1033. if (ret)
  1034. dev_err(hw_info->dev, "DPMAIF HW queue init failed\n");
  1035. return ret;
  1036. }
  1037. bool t7xx_dpmaif_ul_clr_done(struct dpmaif_hw_info *hw_info, unsigned int qno)
  1038. {
  1039. u32 intr_status;
  1040. intr_status = ioread32(hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
  1041. intr_status &= BIT(DP_UL_INT_DONE_OFFSET + qno);
  1042. if (intr_status) {
  1043. iowrite32(intr_status, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
  1044. return true;
  1045. }
  1046. return false;
  1047. }