interrupt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/interrupt.h>
  7. #include "wil6210.h"
  8. #include "trace.h"
  9. /*
  10. * Theory of operation:
  11. *
  12. * There is ISR pseudo-cause register,
  13. * dma_rgf->DMA_RGF.PSEUDO_CAUSE.PSEUDO_CAUSE
  14. * Its bits represents OR'ed bits from 3 real ISR registers:
  15. * TX, RX, and MISC.
  16. *
  17. * Registers may be configured to either "write 1 to clear" or
  18. * "clear on read" mode
  19. *
  20. * When handling interrupt, one have to mask/unmask interrupts for the
  21. * real ISR registers, or hardware may malfunction.
  22. *
  23. */
  24. #define WIL6210_IRQ_DISABLE (0xFFFFFFFFUL)
  25. #define WIL6210_IRQ_DISABLE_NO_HALP (0xF7FFFFFFUL)
  26. #define WIL6210_IMC_RX (BIT_DMA_EP_RX_ICR_RX_DONE | \
  27. BIT_DMA_EP_RX_ICR_RX_HTRSH)
  28. #define WIL6210_IMC_RX_NO_RX_HTRSH (WIL6210_IMC_RX & \
  29. (~(BIT_DMA_EP_RX_ICR_RX_HTRSH)))
  30. #define WIL6210_IMC_TX (BIT_DMA_EP_TX_ICR_TX_DONE | \
  31. BIT_DMA_EP_TX_ICR_TX_DONE_N(0))
  32. #define WIL6210_IMC_TX_EDMA BIT_TX_STATUS_IRQ
  33. #define WIL6210_IMC_RX_EDMA BIT_RX_STATUS_IRQ
  34. #define WIL6210_IMC_MISC_NO_HALP (ISR_MISC_FW_READY | \
  35. ISR_MISC_MBOX_EVT | \
  36. ISR_MISC_FW_ERROR)
  37. #define WIL6210_IMC_MISC (WIL6210_IMC_MISC_NO_HALP | \
  38. BIT_DMA_EP_MISC_ICR_HALP)
  39. #define WIL6210_IRQ_PSEUDO_MASK (u32)(~(BIT_DMA_PSEUDO_CAUSE_RX | \
  40. BIT_DMA_PSEUDO_CAUSE_TX | \
  41. BIT_DMA_PSEUDO_CAUSE_MISC))
  42. #if defined(CONFIG_WIL6210_ISR_COR)
  43. /* configure to Clear-On-Read mode */
  44. #define WIL_ICR_ICC_VALUE (0xFFFFFFFFUL)
  45. #define WIL_ICR_ICC_MISC_VALUE (0xF7FFFFFFUL)
  46. static inline void wil_icr_clear(u32 x, void __iomem *addr)
  47. {
  48. }
  49. #else /* defined(CONFIG_WIL6210_ISR_COR) */
  50. /* configure to Write-1-to-Clear mode */
  51. #define WIL_ICR_ICC_VALUE (0UL)
  52. #define WIL_ICR_ICC_MISC_VALUE (0UL)
  53. static inline void wil_icr_clear(u32 x, void __iomem *addr)
  54. {
  55. writel(x, addr);
  56. }
  57. #endif /* defined(CONFIG_WIL6210_ISR_COR) */
  58. static inline u32 wil_ioread32_and_clear(void __iomem *addr)
  59. {
  60. u32 x = readl(addr);
  61. wil_icr_clear(x, addr);
  62. return x;
  63. }
  64. static void wil6210_mask_irq_tx(struct wil6210_priv *wil)
  65. {
  66. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, IMS),
  67. WIL6210_IRQ_DISABLE);
  68. }
  69. static void wil6210_mask_irq_tx_edma(struct wil6210_priv *wil)
  70. {
  71. wil_w(wil, RGF_INT_GEN_TX_ICR + offsetof(struct RGF_ICR, IMS),
  72. WIL6210_IRQ_DISABLE);
  73. }
  74. static void wil6210_mask_irq_rx(struct wil6210_priv *wil)
  75. {
  76. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, IMS),
  77. WIL6210_IRQ_DISABLE);
  78. }
  79. static void wil6210_mask_irq_rx_edma(struct wil6210_priv *wil)
  80. {
  81. wil_w(wil, RGF_INT_GEN_RX_ICR + offsetof(struct RGF_ICR, IMS),
  82. WIL6210_IRQ_DISABLE);
  83. }
  84. static void wil6210_mask_irq_misc(struct wil6210_priv *wil, bool mask_halp)
  85. {
  86. wil_dbg_irq(wil, "mask_irq_misc: mask_halp(%s)\n",
  87. mask_halp ? "true" : "false");
  88. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMS),
  89. mask_halp ? WIL6210_IRQ_DISABLE : WIL6210_IRQ_DISABLE_NO_HALP);
  90. }
  91. void wil6210_mask_halp(struct wil6210_priv *wil)
  92. {
  93. wil_dbg_irq(wil, "mask_halp\n");
  94. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMS),
  95. BIT_DMA_EP_MISC_ICR_HALP);
  96. }
  97. static void wil6210_mask_irq_pseudo(struct wil6210_priv *wil)
  98. {
  99. wil_dbg_irq(wil, "mask_irq_pseudo\n");
  100. wil_w(wil, RGF_DMA_PSEUDO_CAUSE_MASK_SW, WIL6210_IRQ_DISABLE);
  101. clear_bit(wil_status_irqen, wil->status);
  102. }
  103. void wil6210_unmask_irq_tx(struct wil6210_priv *wil)
  104. {
  105. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, IMC),
  106. WIL6210_IMC_TX);
  107. }
  108. void wil6210_unmask_irq_tx_edma(struct wil6210_priv *wil)
  109. {
  110. wil_w(wil, RGF_INT_GEN_TX_ICR + offsetof(struct RGF_ICR, IMC),
  111. WIL6210_IMC_TX_EDMA);
  112. }
  113. void wil6210_unmask_irq_rx(struct wil6210_priv *wil)
  114. {
  115. bool unmask_rx_htrsh = atomic_read(&wil->connected_vifs) > 0;
  116. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, IMC),
  117. unmask_rx_htrsh ? WIL6210_IMC_RX : WIL6210_IMC_RX_NO_RX_HTRSH);
  118. }
  119. void wil6210_unmask_irq_rx_edma(struct wil6210_priv *wil)
  120. {
  121. wil_w(wil, RGF_INT_GEN_RX_ICR + offsetof(struct RGF_ICR, IMC),
  122. WIL6210_IMC_RX_EDMA);
  123. }
  124. static void wil6210_unmask_irq_misc(struct wil6210_priv *wil, bool unmask_halp)
  125. {
  126. wil_dbg_irq(wil, "unmask_irq_misc: unmask_halp(%s)\n",
  127. unmask_halp ? "true" : "false");
  128. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMC),
  129. unmask_halp ? WIL6210_IMC_MISC : WIL6210_IMC_MISC_NO_HALP);
  130. }
  131. static void wil6210_unmask_halp(struct wil6210_priv *wil)
  132. {
  133. wil_dbg_irq(wil, "unmask_halp\n");
  134. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMC),
  135. BIT_DMA_EP_MISC_ICR_HALP);
  136. }
  137. static void wil6210_unmask_irq_pseudo(struct wil6210_priv *wil)
  138. {
  139. wil_dbg_irq(wil, "unmask_irq_pseudo\n");
  140. set_bit(wil_status_irqen, wil->status);
  141. wil_w(wil, RGF_DMA_PSEUDO_CAUSE_MASK_SW, WIL6210_IRQ_PSEUDO_MASK);
  142. }
  143. void wil_mask_irq(struct wil6210_priv *wil)
  144. {
  145. wil_dbg_irq(wil, "mask_irq\n");
  146. wil6210_mask_irq_tx(wil);
  147. if (wil->use_enhanced_dma_hw)
  148. wil6210_mask_irq_tx_edma(wil);
  149. wil6210_mask_irq_rx(wil);
  150. if (wil->use_enhanced_dma_hw)
  151. wil6210_mask_irq_rx_edma(wil);
  152. wil6210_mask_irq_misc(wil, true);
  153. wil6210_mask_irq_pseudo(wil);
  154. }
  155. void wil_unmask_irq(struct wil6210_priv *wil)
  156. {
  157. wil_dbg_irq(wil, "unmask_irq\n");
  158. if (wil->use_enhanced_dma_hw) {
  159. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, ICC),
  160. WIL_ICR_ICC_VALUE);
  161. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, ICC),
  162. WIL_ICR_ICC_VALUE);
  163. }
  164. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICC),
  165. WIL_ICR_ICC_MISC_VALUE);
  166. wil_w(wil, RGF_INT_GEN_TX_ICR + offsetof(struct RGF_ICR, ICC),
  167. WIL_ICR_ICC_VALUE);
  168. wil_w(wil, RGF_INT_GEN_RX_ICR + offsetof(struct RGF_ICR, ICC),
  169. WIL_ICR_ICC_VALUE);
  170. wil6210_unmask_irq_pseudo(wil);
  171. if (wil->use_enhanced_dma_hw) {
  172. wil6210_unmask_irq_tx_edma(wil);
  173. wil6210_unmask_irq_rx_edma(wil);
  174. } else {
  175. wil6210_unmask_irq_tx(wil);
  176. wil6210_unmask_irq_rx(wil);
  177. }
  178. wil6210_unmask_irq_misc(wil, true);
  179. }
  180. void wil_configure_interrupt_moderation_edma(struct wil6210_priv *wil)
  181. {
  182. u32 moderation;
  183. wil_s(wil, RGF_INT_GEN_IDLE_TIME_LIMIT, WIL_EDMA_IDLE_TIME_LIMIT_USEC);
  184. wil_s(wil, RGF_INT_GEN_TIME_UNIT_LIMIT, WIL_EDMA_TIME_UNIT_CLK_CYCLES);
  185. /* Update RX and TX moderation */
  186. moderation = wil->rx_max_burst_duration |
  187. (WIL_EDMA_AGG_WATERMARK << WIL_EDMA_AGG_WATERMARK_POS);
  188. wil_w(wil, RGF_INT_CTRL_INT_GEN_CFG_0, moderation);
  189. wil_w(wil, RGF_INT_CTRL_INT_GEN_CFG_1, moderation);
  190. /* Treat special events as regular
  191. * (set bit 0 to 0x1 and clear bits 1-8)
  192. */
  193. wil_c(wil, RGF_INT_COUNT_ON_SPECIAL_EVT, 0x1FE);
  194. wil_s(wil, RGF_INT_COUNT_ON_SPECIAL_EVT, 0x1);
  195. }
  196. void wil_configure_interrupt_moderation(struct wil6210_priv *wil)
  197. {
  198. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  199. wil_dbg_irq(wil, "configure_interrupt_moderation\n");
  200. /* disable interrupt moderation for monitor
  201. * to get better timestamp precision
  202. */
  203. if (wdev->iftype == NL80211_IFTYPE_MONITOR)
  204. return;
  205. /* Disable and clear tx counter before (re)configuration */
  206. wil_w(wil, RGF_DMA_ITR_TX_CNT_CTL, BIT_DMA_ITR_TX_CNT_CTL_CLR);
  207. wil_w(wil, RGF_DMA_ITR_TX_CNT_TRSH, wil->tx_max_burst_duration);
  208. wil_info(wil, "set ITR_TX_CNT_TRSH = %d usec\n",
  209. wil->tx_max_burst_duration);
  210. /* Configure TX max burst duration timer to use usec units */
  211. wil_w(wil, RGF_DMA_ITR_TX_CNT_CTL,
  212. BIT_DMA_ITR_TX_CNT_CTL_EN | BIT_DMA_ITR_TX_CNT_CTL_EXT_TIC_SEL);
  213. /* Disable and clear tx idle counter before (re)configuration */
  214. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_CTL, BIT_DMA_ITR_TX_IDL_CNT_CTL_CLR);
  215. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_TRSH, wil->tx_interframe_timeout);
  216. wil_info(wil, "set ITR_TX_IDL_CNT_TRSH = %d usec\n",
  217. wil->tx_interframe_timeout);
  218. /* Configure TX max burst duration timer to use usec units */
  219. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_CTL, BIT_DMA_ITR_TX_IDL_CNT_CTL_EN |
  220. BIT_DMA_ITR_TX_IDL_CNT_CTL_EXT_TIC_SEL);
  221. /* Disable and clear rx counter before (re)configuration */
  222. wil_w(wil, RGF_DMA_ITR_RX_CNT_CTL, BIT_DMA_ITR_RX_CNT_CTL_CLR);
  223. wil_w(wil, RGF_DMA_ITR_RX_CNT_TRSH, wil->rx_max_burst_duration);
  224. wil_info(wil, "set ITR_RX_CNT_TRSH = %d usec\n",
  225. wil->rx_max_burst_duration);
  226. /* Configure TX max burst duration timer to use usec units */
  227. wil_w(wil, RGF_DMA_ITR_RX_CNT_CTL,
  228. BIT_DMA_ITR_RX_CNT_CTL_EN | BIT_DMA_ITR_RX_CNT_CTL_EXT_TIC_SEL);
  229. /* Disable and clear rx idle counter before (re)configuration */
  230. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_CTL, BIT_DMA_ITR_RX_IDL_CNT_CTL_CLR);
  231. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_TRSH, wil->rx_interframe_timeout);
  232. wil_info(wil, "set ITR_RX_IDL_CNT_TRSH = %d usec\n",
  233. wil->rx_interframe_timeout);
  234. /* Configure TX max burst duration timer to use usec units */
  235. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_CTL, BIT_DMA_ITR_RX_IDL_CNT_CTL_EN |
  236. BIT_DMA_ITR_RX_IDL_CNT_CTL_EXT_TIC_SEL);
  237. }
  238. static irqreturn_t wil6210_irq_rx(int irq, void *cookie)
  239. {
  240. struct wil6210_priv *wil = cookie;
  241. u32 isr;
  242. bool need_unmask = true;
  243. wil6210_mask_irq_rx(wil);
  244. isr = wil_ioread32_and_clear(wil->csr +
  245. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  246. offsetof(struct RGF_ICR, ICR));
  247. trace_wil6210_irq_rx(isr);
  248. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  249. if (unlikely(!isr)) {
  250. wil_err_ratelimited(wil, "spurious IRQ: RX\n");
  251. wil6210_unmask_irq_rx(wil);
  252. return IRQ_NONE;
  253. }
  254. /* RX_DONE and RX_HTRSH interrupts are the same if interrupt
  255. * moderation is not used. Interrupt moderation may cause RX
  256. * buffer overflow while RX_DONE is delayed. The required
  257. * action is always the same - should empty the accumulated
  258. * packets from the RX ring.
  259. */
  260. if (likely(isr & (BIT_DMA_EP_RX_ICR_RX_DONE |
  261. BIT_DMA_EP_RX_ICR_RX_HTRSH))) {
  262. wil_dbg_irq(wil, "RX done / RX_HTRSH received, ISR (0x%x)\n",
  263. isr);
  264. isr &= ~(BIT_DMA_EP_RX_ICR_RX_DONE |
  265. BIT_DMA_EP_RX_ICR_RX_HTRSH);
  266. if (likely(test_bit(wil_status_fwready, wil->status))) {
  267. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  268. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  269. need_unmask = false;
  270. napi_schedule(&wil->napi_rx);
  271. } else {
  272. wil_err_ratelimited(
  273. wil,
  274. "Got Rx interrupt while stopping interface\n");
  275. }
  276. } else {
  277. wil_err_ratelimited(wil, "Got Rx interrupt while in reset\n");
  278. }
  279. }
  280. if (unlikely(isr))
  281. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  282. /* Rx IRQ will be enabled when NAPI processing finished */
  283. atomic_inc(&wil->isr_count_rx);
  284. if (unlikely(need_unmask))
  285. wil6210_unmask_irq_rx(wil);
  286. return IRQ_HANDLED;
  287. }
  288. static irqreturn_t wil6210_irq_rx_edma(int irq, void *cookie)
  289. {
  290. struct wil6210_priv *wil = cookie;
  291. u32 isr;
  292. bool need_unmask = true;
  293. wil6210_mask_irq_rx_edma(wil);
  294. isr = wil_ioread32_and_clear(wil->csr +
  295. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  296. offsetof(struct RGF_ICR, ICR));
  297. trace_wil6210_irq_rx(isr);
  298. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  299. if (unlikely(!isr)) {
  300. wil_err(wil, "spurious IRQ: RX\n");
  301. wil6210_unmask_irq_rx_edma(wil);
  302. return IRQ_NONE;
  303. }
  304. if (likely(isr & BIT_RX_STATUS_IRQ)) {
  305. wil_dbg_irq(wil, "RX status ring\n");
  306. isr &= ~BIT_RX_STATUS_IRQ;
  307. if (likely(test_bit(wil_status_fwready, wil->status))) {
  308. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  309. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  310. need_unmask = false;
  311. napi_schedule(&wil->napi_rx);
  312. } else {
  313. wil_err(wil,
  314. "Got Rx interrupt while stopping interface\n");
  315. }
  316. } else {
  317. wil_err(wil, "Got Rx interrupt while in reset\n");
  318. }
  319. }
  320. if (unlikely(isr))
  321. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  322. /* Rx IRQ will be enabled when NAPI processing finished */
  323. atomic_inc(&wil->isr_count_rx);
  324. if (unlikely(need_unmask))
  325. wil6210_unmask_irq_rx_edma(wil);
  326. return IRQ_HANDLED;
  327. }
  328. static irqreturn_t wil6210_irq_tx_edma(int irq, void *cookie)
  329. {
  330. struct wil6210_priv *wil = cookie;
  331. u32 isr;
  332. bool need_unmask = true;
  333. wil6210_mask_irq_tx_edma(wil);
  334. isr = wil_ioread32_and_clear(wil->csr +
  335. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  336. offsetof(struct RGF_ICR, ICR));
  337. trace_wil6210_irq_tx(isr);
  338. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  339. if (unlikely(!isr)) {
  340. wil_err(wil, "spurious IRQ: TX\n");
  341. wil6210_unmask_irq_tx_edma(wil);
  342. return IRQ_NONE;
  343. }
  344. if (likely(isr & BIT_TX_STATUS_IRQ)) {
  345. wil_dbg_irq(wil, "TX status ring\n");
  346. isr &= ~BIT_TX_STATUS_IRQ;
  347. if (likely(test_bit(wil_status_fwready, wil->status))) {
  348. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  349. need_unmask = false;
  350. napi_schedule(&wil->napi_tx);
  351. } else {
  352. wil_err(wil, "Got Tx status ring IRQ while in reset\n");
  353. }
  354. }
  355. if (unlikely(isr))
  356. wil_err(wil, "un-handled TX ISR bits 0x%08x\n", isr);
  357. /* Tx IRQ will be enabled when NAPI processing finished */
  358. atomic_inc(&wil->isr_count_tx);
  359. if (unlikely(need_unmask))
  360. wil6210_unmask_irq_tx_edma(wil);
  361. return IRQ_HANDLED;
  362. }
  363. static irqreturn_t wil6210_irq_tx(int irq, void *cookie)
  364. {
  365. struct wil6210_priv *wil = cookie;
  366. u32 isr;
  367. bool need_unmask = true;
  368. wil6210_mask_irq_tx(wil);
  369. isr = wil_ioread32_and_clear(wil->csr +
  370. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  371. offsetof(struct RGF_ICR, ICR));
  372. trace_wil6210_irq_tx(isr);
  373. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  374. if (unlikely(!isr)) {
  375. wil_err_ratelimited(wil, "spurious IRQ: TX\n");
  376. wil6210_unmask_irq_tx(wil);
  377. return IRQ_NONE;
  378. }
  379. if (likely(isr & BIT_DMA_EP_TX_ICR_TX_DONE)) {
  380. wil_dbg_irq(wil, "TX done\n");
  381. isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE;
  382. /* clear also all VRING interrupts */
  383. isr &= ~(BIT(25) - 1UL);
  384. if (likely(test_bit(wil_status_fwready, wil->status))) {
  385. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  386. need_unmask = false;
  387. napi_schedule(&wil->napi_tx);
  388. } else {
  389. wil_err_ratelimited(wil, "Got Tx interrupt while in reset\n");
  390. }
  391. }
  392. if (unlikely(isr))
  393. wil_err_ratelimited(wil, "un-handled TX ISR bits 0x%08x\n",
  394. isr);
  395. /* Tx IRQ will be enabled when NAPI processing finished */
  396. atomic_inc(&wil->isr_count_tx);
  397. if (unlikely(need_unmask))
  398. wil6210_unmask_irq_tx(wil);
  399. return IRQ_HANDLED;
  400. }
  401. static void wil_notify_fw_error(struct wil6210_priv *wil)
  402. {
  403. struct device *dev = &wil->main_ndev->dev;
  404. char *envp[3] = {
  405. [0] = "SOURCE=wil6210",
  406. [1] = "EVENT=FW_ERROR",
  407. [2] = NULL,
  408. };
  409. wil_err(wil, "Notify about firmware error\n");
  410. kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
  411. }
  412. static void wil_cache_mbox_regs(struct wil6210_priv *wil)
  413. {
  414. /* make shadow copy of registers that should not change on run time */
  415. wil_memcpy_fromio_32(&wil->mbox_ctl, wil->csr + HOST_MBOX,
  416. sizeof(struct wil6210_mbox_ctl));
  417. wil_mbox_ring_le2cpus(&wil->mbox_ctl.rx);
  418. wil_mbox_ring_le2cpus(&wil->mbox_ctl.tx);
  419. }
  420. static bool wil_validate_mbox_regs(struct wil6210_priv *wil)
  421. {
  422. size_t min_size = sizeof(struct wil6210_mbox_hdr) +
  423. sizeof(struct wmi_cmd_hdr);
  424. if (wil->mbox_ctl.rx.entry_size < min_size) {
  425. wil_err(wil, "rx mbox entry too small (%d)\n",
  426. wil->mbox_ctl.rx.entry_size);
  427. return false;
  428. }
  429. if (wil->mbox_ctl.tx.entry_size < min_size) {
  430. wil_err(wil, "tx mbox entry too small (%d)\n",
  431. wil->mbox_ctl.tx.entry_size);
  432. return false;
  433. }
  434. return true;
  435. }
  436. static irqreturn_t wil6210_irq_misc(int irq, void *cookie)
  437. {
  438. struct wil6210_priv *wil = cookie;
  439. u32 isr;
  440. wil6210_mask_irq_misc(wil, false);
  441. isr = wil_ioread32_and_clear(wil->csr +
  442. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  443. offsetof(struct RGF_ICR, ICR));
  444. trace_wil6210_irq_misc(isr);
  445. wil_dbg_irq(wil, "ISR MISC 0x%08x\n", isr);
  446. if (!isr) {
  447. wil_err(wil, "spurious IRQ: MISC\n");
  448. wil6210_unmask_irq_misc(wil, false);
  449. return IRQ_NONE;
  450. }
  451. if (isr & ISR_MISC_FW_ERROR) {
  452. u32 fw_assert_code = wil_r(wil, wil->rgf_fw_assert_code_addr);
  453. u32 ucode_assert_code =
  454. wil_r(wil, wil->rgf_ucode_assert_code_addr);
  455. wil_err(wil,
  456. "Firmware error detected, assert codes FW 0x%08x, UCODE 0x%08x\n",
  457. fw_assert_code, ucode_assert_code);
  458. clear_bit(wil_status_fwready, wil->status);
  459. /*
  460. * do not clear @isr here - we do 2-nd part in thread
  461. * there, user space get notified, and it should be done
  462. * in non-atomic context
  463. */
  464. }
  465. if (isr & ISR_MISC_FW_READY) {
  466. wil_dbg_irq(wil, "IRQ: FW ready\n");
  467. wil_cache_mbox_regs(wil);
  468. if (wil_validate_mbox_regs(wil))
  469. set_bit(wil_status_mbox_ready, wil->status);
  470. /**
  471. * Actual FW ready indicated by the
  472. * WMI_FW_READY_EVENTID
  473. */
  474. isr &= ~ISR_MISC_FW_READY;
  475. }
  476. if (isr & BIT_DMA_EP_MISC_ICR_HALP) {
  477. isr &= ~BIT_DMA_EP_MISC_ICR_HALP;
  478. if (wil->halp.handle_icr) {
  479. /* no need to handle HALP ICRs until next vote */
  480. wil->halp.handle_icr = false;
  481. wil_dbg_irq(wil, "irq_misc: HALP IRQ invoked\n");
  482. wil6210_mask_irq_misc(wil, true);
  483. complete(&wil->halp.comp);
  484. }
  485. }
  486. wil->isr_misc = isr;
  487. if (isr) {
  488. return IRQ_WAKE_THREAD;
  489. } else {
  490. wil6210_unmask_irq_misc(wil, false);
  491. return IRQ_HANDLED;
  492. }
  493. }
  494. static irqreturn_t wil6210_irq_misc_thread(int irq, void *cookie)
  495. {
  496. struct wil6210_priv *wil = cookie;
  497. u32 isr = wil->isr_misc;
  498. trace_wil6210_irq_misc_thread(isr);
  499. wil_dbg_irq(wil, "Thread ISR MISC 0x%08x\n", isr);
  500. if (isr & ISR_MISC_FW_ERROR) {
  501. wil->recovery_state = fw_recovery_pending;
  502. wil_fw_core_dump(wil);
  503. wil_notify_fw_error(wil);
  504. isr &= ~ISR_MISC_FW_ERROR;
  505. if (wil->platform_ops.notify) {
  506. wil_err(wil, "notify platform driver about FW crash");
  507. wil->platform_ops.notify(wil->platform_handle,
  508. WIL_PLATFORM_EVT_FW_CRASH);
  509. } else {
  510. wil_fw_error_recovery(wil);
  511. }
  512. }
  513. if (isr & ISR_MISC_MBOX_EVT) {
  514. wil_dbg_irq(wil, "MBOX event\n");
  515. wmi_recv_cmd(wil);
  516. isr &= ~ISR_MISC_MBOX_EVT;
  517. }
  518. if (isr)
  519. wil_dbg_irq(wil, "un-handled MISC ISR bits 0x%08x\n", isr);
  520. wil->isr_misc = 0;
  521. wil6210_unmask_irq_misc(wil, false);
  522. /* in non-triple MSI case, this is done inside wil6210_thread_irq
  523. * because it has to be done after unmasking the pseudo.
  524. */
  525. if (wil->n_msi == 3 && wil->suspend_resp_rcvd) {
  526. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  527. wil->suspend_resp_comp = true;
  528. wake_up_interruptible(&wil->wq);
  529. }
  530. return IRQ_HANDLED;
  531. }
  532. /* thread IRQ handler */
  533. static irqreturn_t wil6210_thread_irq(int irq, void *cookie)
  534. {
  535. struct wil6210_priv *wil = cookie;
  536. wil_dbg_irq(wil, "Thread IRQ\n");
  537. /* Discover real IRQ cause */
  538. if (wil->isr_misc)
  539. wil6210_irq_misc_thread(irq, cookie);
  540. wil6210_unmask_irq_pseudo(wil);
  541. if (wil->suspend_resp_rcvd) {
  542. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  543. wil->suspend_resp_comp = true;
  544. wake_up_interruptible(&wil->wq);
  545. }
  546. return IRQ_HANDLED;
  547. }
  548. /* DEBUG
  549. * There is subtle bug in hardware that causes IRQ to raise when it should be
  550. * masked. It is quite rare and hard to debug.
  551. *
  552. * Catch irq issue if it happens and print all I can.
  553. */
  554. static int wil6210_debug_irq_mask(struct wil6210_priv *wil, u32 pseudo_cause)
  555. {
  556. u32 icm_rx, icr_rx, imv_rx;
  557. u32 icm_tx, icr_tx, imv_tx;
  558. u32 icm_misc, icr_misc, imv_misc;
  559. if (!test_bit(wil_status_irqen, wil->status)) {
  560. if (wil->use_enhanced_dma_hw) {
  561. icm_rx = wil_ioread32_and_clear(wil->csr +
  562. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  563. offsetof(struct RGF_ICR, ICM));
  564. icr_rx = wil_ioread32_and_clear(wil->csr +
  565. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  566. offsetof(struct RGF_ICR, ICR));
  567. imv_rx = wil_r(wil, RGF_INT_GEN_RX_ICR +
  568. offsetof(struct RGF_ICR, IMV));
  569. icm_tx = wil_ioread32_and_clear(wil->csr +
  570. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  571. offsetof(struct RGF_ICR, ICM));
  572. icr_tx = wil_ioread32_and_clear(wil->csr +
  573. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  574. offsetof(struct RGF_ICR, ICR));
  575. imv_tx = wil_r(wil, RGF_INT_GEN_TX_ICR +
  576. offsetof(struct RGF_ICR, IMV));
  577. } else {
  578. icm_rx = wil_ioread32_and_clear(wil->csr +
  579. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  580. offsetof(struct RGF_ICR, ICM));
  581. icr_rx = wil_ioread32_and_clear(wil->csr +
  582. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  583. offsetof(struct RGF_ICR, ICR));
  584. imv_rx = wil_r(wil, RGF_DMA_EP_RX_ICR +
  585. offsetof(struct RGF_ICR, IMV));
  586. icm_tx = wil_ioread32_and_clear(wil->csr +
  587. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  588. offsetof(struct RGF_ICR, ICM));
  589. icr_tx = wil_ioread32_and_clear(wil->csr +
  590. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  591. offsetof(struct RGF_ICR, ICR));
  592. imv_tx = wil_r(wil, RGF_DMA_EP_TX_ICR +
  593. offsetof(struct RGF_ICR, IMV));
  594. }
  595. icm_misc = wil_ioread32_and_clear(wil->csr +
  596. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  597. offsetof(struct RGF_ICR, ICM));
  598. icr_misc = wil_ioread32_and_clear(wil->csr +
  599. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  600. offsetof(struct RGF_ICR, ICR));
  601. imv_misc = wil_r(wil, RGF_DMA_EP_MISC_ICR +
  602. offsetof(struct RGF_ICR, IMV));
  603. /* HALP interrupt can be unmasked when misc interrupts are
  604. * masked
  605. */
  606. if (icr_misc & BIT_DMA_EP_MISC_ICR_HALP)
  607. return 0;
  608. wil_err(wil, "IRQ when it should be masked: pseudo 0x%08x\n"
  609. "Rx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  610. "Tx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  611. "Misc icm:icr:imv 0x%08x 0x%08x 0x%08x\n",
  612. pseudo_cause,
  613. icm_rx, icr_rx, imv_rx,
  614. icm_tx, icr_tx, imv_tx,
  615. icm_misc, icr_misc, imv_misc);
  616. return -EINVAL;
  617. }
  618. return 0;
  619. }
  620. static irqreturn_t wil6210_hardirq(int irq, void *cookie)
  621. {
  622. irqreturn_t rc = IRQ_HANDLED;
  623. struct wil6210_priv *wil = cookie;
  624. u32 pseudo_cause = wil_r(wil, RGF_DMA_PSEUDO_CAUSE);
  625. /**
  626. * pseudo_cause is Clear-On-Read, no need to ACK
  627. */
  628. if (unlikely((pseudo_cause == 0) || ((pseudo_cause & 0xff) == 0xff)))
  629. return IRQ_NONE;
  630. /* IRQ mask debug */
  631. if (unlikely(wil6210_debug_irq_mask(wil, pseudo_cause)))
  632. return IRQ_NONE;
  633. trace_wil6210_irq_pseudo(pseudo_cause);
  634. wil_dbg_irq(wil, "Pseudo IRQ 0x%08x\n", pseudo_cause);
  635. wil6210_mask_irq_pseudo(wil);
  636. /* Discover real IRQ cause
  637. * There are 2 possible phases for every IRQ:
  638. * - hard IRQ handler called right here
  639. * - threaded handler called later
  640. *
  641. * Hard IRQ handler reads and clears ISR.
  642. *
  643. * If threaded handler requested, hard IRQ handler
  644. * returns IRQ_WAKE_THREAD and saves ISR register value
  645. * for the threaded handler use.
  646. *
  647. * voting for wake thread - need at least 1 vote
  648. */
  649. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_RX) &&
  650. (wil->txrx_ops.irq_rx(irq, cookie) == IRQ_WAKE_THREAD))
  651. rc = IRQ_WAKE_THREAD;
  652. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_TX) &&
  653. (wil->txrx_ops.irq_tx(irq, cookie) == IRQ_WAKE_THREAD))
  654. rc = IRQ_WAKE_THREAD;
  655. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_MISC) &&
  656. (wil6210_irq_misc(irq, cookie) == IRQ_WAKE_THREAD))
  657. rc = IRQ_WAKE_THREAD;
  658. /* if thread is requested, it will unmask IRQ */
  659. if (rc != IRQ_WAKE_THREAD)
  660. wil6210_unmask_irq_pseudo(wil);
  661. return rc;
  662. }
  663. static int wil6210_request_3msi(struct wil6210_priv *wil, int irq)
  664. {
  665. int rc;
  666. /* IRQ's are in the following order:
  667. * - Tx
  668. * - Rx
  669. * - Misc
  670. */
  671. rc = request_irq(irq, wil->txrx_ops.irq_tx, IRQF_SHARED,
  672. WIL_NAME "_tx", wil);
  673. if (rc)
  674. return rc;
  675. rc = request_irq(irq + 1, wil->txrx_ops.irq_rx, IRQF_SHARED,
  676. WIL_NAME "_rx", wil);
  677. if (rc)
  678. goto free0;
  679. rc = request_threaded_irq(irq + 2, wil6210_irq_misc,
  680. wil6210_irq_misc_thread,
  681. IRQF_SHARED, WIL_NAME "_misc", wil);
  682. if (rc)
  683. goto free1;
  684. return 0;
  685. free1:
  686. free_irq(irq + 1, wil);
  687. free0:
  688. free_irq(irq, wil);
  689. return rc;
  690. }
  691. /* can't use wil_ioread32_and_clear because ICC value is not set yet */
  692. static inline void wil_clear32(void __iomem *addr)
  693. {
  694. u32 x = readl(addr);
  695. writel(x, addr);
  696. }
  697. void wil6210_clear_irq(struct wil6210_priv *wil)
  698. {
  699. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_RX_ICR) +
  700. offsetof(struct RGF_ICR, ICR));
  701. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_TX_ICR) +
  702. offsetof(struct RGF_ICR, ICR));
  703. if (wil->use_enhanced_dma_hw) {
  704. wil_clear32(wil->csr + HOSTADDR(RGF_INT_GEN_RX_ICR) +
  705. offsetof(struct RGF_ICR, ICR));
  706. wil_clear32(wil->csr + HOSTADDR(RGF_INT_GEN_TX_ICR) +
  707. offsetof(struct RGF_ICR, ICR));
  708. }
  709. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  710. offsetof(struct RGF_ICR, ICR));
  711. wmb(); /* make sure write completed */
  712. }
  713. void wil6210_set_halp(struct wil6210_priv *wil)
  714. {
  715. wil_dbg_irq(wil, "set_halp\n");
  716. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICS),
  717. BIT_DMA_EP_MISC_ICR_HALP);
  718. }
  719. void wil6210_clear_halp(struct wil6210_priv *wil)
  720. {
  721. wil_dbg_irq(wil, "clear_halp\n");
  722. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICR),
  723. BIT_DMA_EP_MISC_ICR_HALP);
  724. wil6210_unmask_halp(wil);
  725. }
  726. int wil6210_init_irq(struct wil6210_priv *wil, int irq)
  727. {
  728. int rc;
  729. wil_dbg_misc(wil, "init_irq: %s, n_msi=%d\n",
  730. wil->n_msi ? "MSI" : "INTx", wil->n_msi);
  731. if (wil->use_enhanced_dma_hw) {
  732. wil->txrx_ops.irq_tx = wil6210_irq_tx_edma;
  733. wil->txrx_ops.irq_rx = wil6210_irq_rx_edma;
  734. } else {
  735. wil->txrx_ops.irq_tx = wil6210_irq_tx;
  736. wil->txrx_ops.irq_rx = wil6210_irq_rx;
  737. }
  738. if (wil->n_msi == 3)
  739. rc = wil6210_request_3msi(wil, irq);
  740. else
  741. rc = request_threaded_irq(irq, wil6210_hardirq,
  742. wil6210_thread_irq,
  743. wil->n_msi ? 0 : IRQF_SHARED,
  744. WIL_NAME, wil);
  745. return rc;
  746. }
  747. void wil6210_fini_irq(struct wil6210_priv *wil, int irq)
  748. {
  749. wil_dbg_misc(wil, "fini_irq:\n");
  750. wil_mask_irq(wil);
  751. free_irq(irq, wil);
  752. if (wil->n_msi == 3) {
  753. free_irq(irq + 1, wil);
  754. free_irq(irq + 2, wil);
  755. }
  756. }