interrupt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/interrupt.h>
  18. #include "wil6210.h"
  19. #include "trace.h"
  20. /**
  21. * Theory of operation:
  22. *
  23. * There is ISR pseudo-cause register,
  24. * dma_rgf->DMA_RGF.PSEUDO_CAUSE.PSEUDO_CAUSE
  25. * Its bits represents OR'ed bits from 3 real ISR registers:
  26. * TX, RX, and MISC.
  27. *
  28. * Registers may be configured to either "write 1 to clear" or
  29. * "clear on read" mode
  30. *
  31. * When handling interrupt, one have to mask/unmask interrupts for the
  32. * real ISR registers, or hardware may malfunction.
  33. *
  34. */
  35. #define WIL6210_IRQ_DISABLE (0xFFFFFFFFUL)
  36. #define WIL6210_IRQ_DISABLE_NO_HALP (0xF7FFFFFFUL)
  37. #define WIL6210_IMC_RX (BIT_DMA_EP_RX_ICR_RX_DONE | \
  38. BIT_DMA_EP_RX_ICR_RX_HTRSH)
  39. #define WIL6210_IMC_RX_NO_RX_HTRSH (WIL6210_IMC_RX & \
  40. (~(BIT_DMA_EP_RX_ICR_RX_HTRSH)))
  41. #define WIL6210_IMC_TX (BIT_DMA_EP_TX_ICR_TX_DONE | \
  42. BIT_DMA_EP_TX_ICR_TX_DONE_N(0))
  43. #define WIL6210_IMC_MISC_NO_HALP (ISR_MISC_FW_READY | \
  44. ISR_MISC_MBOX_EVT | \
  45. ISR_MISC_FW_ERROR)
  46. #define WIL6210_IMC_MISC (WIL6210_IMC_MISC_NO_HALP | \
  47. BIT_DMA_EP_MISC_ICR_HALP)
  48. #define WIL6210_IRQ_PSEUDO_MASK (u32)(~(BIT_DMA_PSEUDO_CAUSE_RX | \
  49. BIT_DMA_PSEUDO_CAUSE_TX | \
  50. BIT_DMA_PSEUDO_CAUSE_MISC))
  51. #if defined(CONFIG_WIL6210_ISR_COR)
  52. /* configure to Clear-On-Read mode */
  53. #define WIL_ICR_ICC_VALUE (0xFFFFFFFFUL)
  54. #define WIL_ICR_ICC_MISC_VALUE (0xF7FFFFFFUL)
  55. static inline void wil_icr_clear(u32 x, void __iomem *addr)
  56. {
  57. }
  58. #else /* defined(CONFIG_WIL6210_ISR_COR) */
  59. /* configure to Write-1-to-Clear mode */
  60. #define WIL_ICR_ICC_VALUE (0UL)
  61. #define WIL_ICR_ICC_MISC_VALUE (0UL)
  62. static inline void wil_icr_clear(u32 x, void __iomem *addr)
  63. {
  64. writel(x, addr);
  65. }
  66. #endif /* defined(CONFIG_WIL6210_ISR_COR) */
  67. static inline u32 wil_ioread32_and_clear(void __iomem *addr)
  68. {
  69. u32 x = readl(addr);
  70. wil_icr_clear(x, addr);
  71. return x;
  72. }
  73. static void wil6210_mask_irq_tx(struct wil6210_priv *wil)
  74. {
  75. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, IMS),
  76. WIL6210_IRQ_DISABLE);
  77. }
  78. static void wil6210_mask_irq_rx(struct wil6210_priv *wil)
  79. {
  80. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, IMS),
  81. WIL6210_IRQ_DISABLE);
  82. }
  83. static void wil6210_mask_irq_misc(struct wil6210_priv *wil, bool mask_halp)
  84. {
  85. wil_dbg_irq(wil, "mask_irq_misc: mask_halp(%s)\n",
  86. mask_halp ? "true" : "false");
  87. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMS),
  88. mask_halp ? WIL6210_IRQ_DISABLE : WIL6210_IRQ_DISABLE_NO_HALP);
  89. }
  90. void wil6210_mask_halp(struct wil6210_priv *wil)
  91. {
  92. wil_dbg_irq(wil, "mask_halp\n");
  93. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMS),
  94. BIT_DMA_EP_MISC_ICR_HALP);
  95. }
  96. static void wil6210_mask_irq_pseudo(struct wil6210_priv *wil)
  97. {
  98. wil_dbg_irq(wil, "mask_irq_pseudo\n");
  99. wil_w(wil, RGF_DMA_PSEUDO_CAUSE_MASK_SW, WIL6210_IRQ_DISABLE);
  100. clear_bit(wil_status_irqen, wil->status);
  101. }
  102. void wil6210_unmask_irq_tx(struct wil6210_priv *wil)
  103. {
  104. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, IMC),
  105. WIL6210_IMC_TX);
  106. }
  107. void wil6210_unmask_irq_rx(struct wil6210_priv *wil)
  108. {
  109. bool unmask_rx_htrsh = atomic_read(&wil->connected_vifs) > 0;
  110. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, IMC),
  111. unmask_rx_htrsh ? WIL6210_IMC_RX : WIL6210_IMC_RX_NO_RX_HTRSH);
  112. }
  113. static void wil6210_unmask_irq_misc(struct wil6210_priv *wil, bool unmask_halp)
  114. {
  115. wil_dbg_irq(wil, "unmask_irq_misc: unmask_halp(%s)\n",
  116. unmask_halp ? "true" : "false");
  117. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMC),
  118. unmask_halp ? WIL6210_IMC_MISC : WIL6210_IMC_MISC_NO_HALP);
  119. }
  120. static void wil6210_unmask_halp(struct wil6210_priv *wil)
  121. {
  122. wil_dbg_irq(wil, "unmask_halp\n");
  123. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMC),
  124. BIT_DMA_EP_MISC_ICR_HALP);
  125. }
  126. static void wil6210_unmask_irq_pseudo(struct wil6210_priv *wil)
  127. {
  128. wil_dbg_irq(wil, "unmask_irq_pseudo\n");
  129. set_bit(wil_status_irqen, wil->status);
  130. wil_w(wil, RGF_DMA_PSEUDO_CAUSE_MASK_SW, WIL6210_IRQ_PSEUDO_MASK);
  131. }
  132. void wil_mask_irq(struct wil6210_priv *wil)
  133. {
  134. wil_dbg_irq(wil, "mask_irq\n");
  135. wil6210_mask_irq_tx(wil);
  136. wil6210_mask_irq_rx(wil);
  137. wil6210_mask_irq_misc(wil, true);
  138. wil6210_mask_irq_pseudo(wil);
  139. }
  140. void wil_unmask_irq(struct wil6210_priv *wil)
  141. {
  142. wil_dbg_irq(wil, "unmask_irq\n");
  143. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, ICC),
  144. WIL_ICR_ICC_VALUE);
  145. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, ICC),
  146. WIL_ICR_ICC_VALUE);
  147. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICC),
  148. WIL_ICR_ICC_MISC_VALUE);
  149. wil6210_unmask_irq_pseudo(wil);
  150. wil6210_unmask_irq_tx(wil);
  151. wil6210_unmask_irq_rx(wil);
  152. wil6210_unmask_irq_misc(wil, true);
  153. }
  154. void wil_configure_interrupt_moderation(struct wil6210_priv *wil)
  155. {
  156. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  157. wil_dbg_irq(wil, "configure_interrupt_moderation\n");
  158. /* disable interrupt moderation for monitor
  159. * to get better timestamp precision
  160. */
  161. if (wdev->iftype == NL80211_IFTYPE_MONITOR)
  162. return;
  163. /* Disable and clear tx counter before (re)configuration */
  164. wil_w(wil, RGF_DMA_ITR_TX_CNT_CTL, BIT_DMA_ITR_TX_CNT_CTL_CLR);
  165. wil_w(wil, RGF_DMA_ITR_TX_CNT_TRSH, wil->tx_max_burst_duration);
  166. wil_info(wil, "set ITR_TX_CNT_TRSH = %d usec\n",
  167. wil->tx_max_burst_duration);
  168. /* Configure TX max burst duration timer to use usec units */
  169. wil_w(wil, RGF_DMA_ITR_TX_CNT_CTL,
  170. BIT_DMA_ITR_TX_CNT_CTL_EN | BIT_DMA_ITR_TX_CNT_CTL_EXT_TIC_SEL);
  171. /* Disable and clear tx idle counter before (re)configuration */
  172. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_CTL, BIT_DMA_ITR_TX_IDL_CNT_CTL_CLR);
  173. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_TRSH, wil->tx_interframe_timeout);
  174. wil_info(wil, "set ITR_TX_IDL_CNT_TRSH = %d usec\n",
  175. wil->tx_interframe_timeout);
  176. /* Configure TX max burst duration timer to use usec units */
  177. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_CTL, BIT_DMA_ITR_TX_IDL_CNT_CTL_EN |
  178. BIT_DMA_ITR_TX_IDL_CNT_CTL_EXT_TIC_SEL);
  179. /* Disable and clear rx counter before (re)configuration */
  180. wil_w(wil, RGF_DMA_ITR_RX_CNT_CTL, BIT_DMA_ITR_RX_CNT_CTL_CLR);
  181. wil_w(wil, RGF_DMA_ITR_RX_CNT_TRSH, wil->rx_max_burst_duration);
  182. wil_info(wil, "set ITR_RX_CNT_TRSH = %d usec\n",
  183. wil->rx_max_burst_duration);
  184. /* Configure TX max burst duration timer to use usec units */
  185. wil_w(wil, RGF_DMA_ITR_RX_CNT_CTL,
  186. BIT_DMA_ITR_RX_CNT_CTL_EN | BIT_DMA_ITR_RX_CNT_CTL_EXT_TIC_SEL);
  187. /* Disable and clear rx idle counter before (re)configuration */
  188. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_CTL, BIT_DMA_ITR_RX_IDL_CNT_CTL_CLR);
  189. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_TRSH, wil->rx_interframe_timeout);
  190. wil_info(wil, "set ITR_RX_IDL_CNT_TRSH = %d usec\n",
  191. wil->rx_interframe_timeout);
  192. /* Configure TX max burst duration timer to use usec units */
  193. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_CTL, BIT_DMA_ITR_RX_IDL_CNT_CTL_EN |
  194. BIT_DMA_ITR_RX_IDL_CNT_CTL_EXT_TIC_SEL);
  195. }
  196. static irqreturn_t wil6210_irq_rx(int irq, void *cookie)
  197. {
  198. struct wil6210_priv *wil = cookie;
  199. u32 isr = wil_ioread32_and_clear(wil->csr +
  200. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  201. offsetof(struct RGF_ICR, ICR));
  202. bool need_unmask = true;
  203. trace_wil6210_irq_rx(isr);
  204. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  205. if (unlikely(!isr)) {
  206. wil_err_ratelimited(wil, "spurious IRQ: RX\n");
  207. return IRQ_NONE;
  208. }
  209. wil6210_mask_irq_rx(wil);
  210. /* RX_DONE and RX_HTRSH interrupts are the same if interrupt
  211. * moderation is not used. Interrupt moderation may cause RX
  212. * buffer overflow while RX_DONE is delayed. The required
  213. * action is always the same - should empty the accumulated
  214. * packets from the RX ring.
  215. */
  216. if (likely(isr & (BIT_DMA_EP_RX_ICR_RX_DONE |
  217. BIT_DMA_EP_RX_ICR_RX_HTRSH))) {
  218. wil_dbg_irq(wil, "RX done / RX_HTRSH received, ISR (0x%x)\n",
  219. isr);
  220. isr &= ~(BIT_DMA_EP_RX_ICR_RX_DONE |
  221. BIT_DMA_EP_RX_ICR_RX_HTRSH);
  222. if (likely(test_bit(wil_status_fwready, wil->status))) {
  223. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  224. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  225. need_unmask = false;
  226. napi_schedule(&wil->napi_rx);
  227. } else {
  228. wil_err_ratelimited(
  229. wil,
  230. "Got Rx interrupt while stopping interface\n");
  231. }
  232. } else {
  233. wil_err_ratelimited(wil, "Got Rx interrupt while in reset\n");
  234. }
  235. }
  236. if (unlikely(isr))
  237. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  238. /* Rx IRQ will be enabled when NAPI processing finished */
  239. atomic_inc(&wil->isr_count_rx);
  240. if (unlikely(need_unmask))
  241. wil6210_unmask_irq_rx(wil);
  242. return IRQ_HANDLED;
  243. }
  244. static irqreturn_t wil6210_irq_tx(int irq, void *cookie)
  245. {
  246. struct wil6210_priv *wil = cookie;
  247. u32 isr = wil_ioread32_and_clear(wil->csr +
  248. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  249. offsetof(struct RGF_ICR, ICR));
  250. bool need_unmask = true;
  251. trace_wil6210_irq_tx(isr);
  252. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  253. if (unlikely(!isr)) {
  254. wil_err_ratelimited(wil, "spurious IRQ: TX\n");
  255. return IRQ_NONE;
  256. }
  257. wil6210_mask_irq_tx(wil);
  258. if (likely(isr & BIT_DMA_EP_TX_ICR_TX_DONE)) {
  259. wil_dbg_irq(wil, "TX done\n");
  260. isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE;
  261. /* clear also all VRING interrupts */
  262. isr &= ~(BIT(25) - 1UL);
  263. if (likely(test_bit(wil_status_fwready, wil->status))) {
  264. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  265. need_unmask = false;
  266. napi_schedule(&wil->napi_tx);
  267. } else {
  268. wil_err_ratelimited(wil, "Got Tx interrupt while in reset\n");
  269. }
  270. }
  271. if (unlikely(isr))
  272. wil_err_ratelimited(wil, "un-handled TX ISR bits 0x%08x\n",
  273. isr);
  274. /* Tx IRQ will be enabled when NAPI processing finished */
  275. atomic_inc(&wil->isr_count_tx);
  276. if (unlikely(need_unmask))
  277. wil6210_unmask_irq_tx(wil);
  278. return IRQ_HANDLED;
  279. }
  280. static void wil_notify_fw_error(struct wil6210_priv *wil)
  281. {
  282. struct device *dev = &wil->main_ndev->dev;
  283. char *envp[3] = {
  284. [0] = "SOURCE=wil6210",
  285. [1] = "EVENT=FW_ERROR",
  286. [2] = NULL,
  287. };
  288. wil_err(wil, "Notify about firmware error\n");
  289. kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
  290. }
  291. static void wil_cache_mbox_regs(struct wil6210_priv *wil)
  292. {
  293. /* make shadow copy of registers that should not change on run time */
  294. wil_memcpy_fromio_32(&wil->mbox_ctl, wil->csr + HOST_MBOX,
  295. sizeof(struct wil6210_mbox_ctl));
  296. wil_mbox_ring_le2cpus(&wil->mbox_ctl.rx);
  297. wil_mbox_ring_le2cpus(&wil->mbox_ctl.tx);
  298. }
  299. static bool wil_validate_mbox_regs(struct wil6210_priv *wil)
  300. {
  301. size_t min_size = sizeof(struct wil6210_mbox_hdr) +
  302. sizeof(struct wmi_cmd_hdr);
  303. if (wil->mbox_ctl.rx.entry_size < min_size) {
  304. wil_err(wil, "rx mbox entry too small (%d)\n",
  305. wil->mbox_ctl.rx.entry_size);
  306. return false;
  307. }
  308. if (wil->mbox_ctl.tx.entry_size < min_size) {
  309. wil_err(wil, "tx mbox entry too small (%d)\n",
  310. wil->mbox_ctl.tx.entry_size);
  311. return false;
  312. }
  313. return true;
  314. }
  315. static irqreturn_t wil6210_irq_misc(int irq, void *cookie)
  316. {
  317. struct wil6210_priv *wil = cookie;
  318. u32 isr = wil_ioread32_and_clear(wil->csr +
  319. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  320. offsetof(struct RGF_ICR, ICR));
  321. trace_wil6210_irq_misc(isr);
  322. wil_dbg_irq(wil, "ISR MISC 0x%08x\n", isr);
  323. if (!isr) {
  324. wil_err(wil, "spurious IRQ: MISC\n");
  325. return IRQ_NONE;
  326. }
  327. wil6210_mask_irq_misc(wil, false);
  328. if (isr & ISR_MISC_FW_ERROR) {
  329. u32 fw_assert_code = wil_r(wil, wil->rgf_fw_assert_code_addr);
  330. u32 ucode_assert_code =
  331. wil_r(wil, wil->rgf_ucode_assert_code_addr);
  332. wil_err(wil,
  333. "Firmware error detected, assert codes FW 0x%08x, UCODE 0x%08x\n",
  334. fw_assert_code, ucode_assert_code);
  335. clear_bit(wil_status_fwready, wil->status);
  336. /*
  337. * do not clear @isr here - we do 2-nd part in thread
  338. * there, user space get notified, and it should be done
  339. * in non-atomic context
  340. */
  341. }
  342. if (isr & ISR_MISC_FW_READY) {
  343. wil_dbg_irq(wil, "IRQ: FW ready\n");
  344. wil_cache_mbox_regs(wil);
  345. if (wil_validate_mbox_regs(wil))
  346. set_bit(wil_status_mbox_ready, wil->status);
  347. /**
  348. * Actual FW ready indicated by the
  349. * WMI_FW_READY_EVENTID
  350. */
  351. isr &= ~ISR_MISC_FW_READY;
  352. }
  353. if (isr & BIT_DMA_EP_MISC_ICR_HALP) {
  354. wil_dbg_irq(wil, "irq_misc: HALP IRQ invoked\n");
  355. wil6210_mask_halp(wil);
  356. isr &= ~BIT_DMA_EP_MISC_ICR_HALP;
  357. complete(&wil->halp.comp);
  358. }
  359. wil->isr_misc = isr;
  360. if (isr) {
  361. return IRQ_WAKE_THREAD;
  362. } else {
  363. wil6210_unmask_irq_misc(wil, false);
  364. return IRQ_HANDLED;
  365. }
  366. }
  367. static irqreturn_t wil6210_irq_misc_thread(int irq, void *cookie)
  368. {
  369. struct wil6210_priv *wil = cookie;
  370. u32 isr = wil->isr_misc;
  371. trace_wil6210_irq_misc_thread(isr);
  372. wil_dbg_irq(wil, "Thread ISR MISC 0x%08x\n", isr);
  373. if (isr & ISR_MISC_FW_ERROR) {
  374. wil->recovery_state = fw_recovery_pending;
  375. wil_fw_core_dump(wil);
  376. wil_notify_fw_error(wil);
  377. isr &= ~ISR_MISC_FW_ERROR;
  378. if (wil->platform_ops.notify) {
  379. wil_err(wil, "notify platform driver about FW crash");
  380. wil->platform_ops.notify(wil->platform_handle,
  381. WIL_PLATFORM_EVT_FW_CRASH);
  382. } else {
  383. wil_fw_error_recovery(wil);
  384. }
  385. }
  386. if (isr & ISR_MISC_MBOX_EVT) {
  387. wil_dbg_irq(wil, "MBOX event\n");
  388. wmi_recv_cmd(wil);
  389. isr &= ~ISR_MISC_MBOX_EVT;
  390. }
  391. if (isr)
  392. wil_dbg_irq(wil, "un-handled MISC ISR bits 0x%08x\n", isr);
  393. wil->isr_misc = 0;
  394. wil6210_unmask_irq_misc(wil, false);
  395. return IRQ_HANDLED;
  396. }
  397. /**
  398. * thread IRQ handler
  399. */
  400. static irqreturn_t wil6210_thread_irq(int irq, void *cookie)
  401. {
  402. struct wil6210_priv *wil = cookie;
  403. wil_dbg_irq(wil, "Thread IRQ\n");
  404. /* Discover real IRQ cause */
  405. if (wil->isr_misc)
  406. wil6210_irq_misc_thread(irq, cookie);
  407. wil6210_unmask_irq_pseudo(wil);
  408. if (wil->suspend_resp_rcvd) {
  409. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  410. wil->suspend_resp_comp = true;
  411. wake_up_interruptible(&wil->wq);
  412. }
  413. return IRQ_HANDLED;
  414. }
  415. /* DEBUG
  416. * There is subtle bug in hardware that causes IRQ to raise when it should be
  417. * masked. It is quite rare and hard to debug.
  418. *
  419. * Catch irq issue if it happens and print all I can.
  420. */
  421. static int wil6210_debug_irq_mask(struct wil6210_priv *wil, u32 pseudo_cause)
  422. {
  423. if (!test_bit(wil_status_irqen, wil->status)) {
  424. u32 icm_rx = wil_ioread32_and_clear(wil->csr +
  425. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  426. offsetof(struct RGF_ICR, ICM));
  427. u32 icr_rx = wil_ioread32_and_clear(wil->csr +
  428. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  429. offsetof(struct RGF_ICR, ICR));
  430. u32 imv_rx = wil_r(wil, RGF_DMA_EP_RX_ICR +
  431. offsetof(struct RGF_ICR, IMV));
  432. u32 icm_tx = wil_ioread32_and_clear(wil->csr +
  433. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  434. offsetof(struct RGF_ICR, ICM));
  435. u32 icr_tx = wil_ioread32_and_clear(wil->csr +
  436. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  437. offsetof(struct RGF_ICR, ICR));
  438. u32 imv_tx = wil_r(wil, RGF_DMA_EP_TX_ICR +
  439. offsetof(struct RGF_ICR, IMV));
  440. u32 icm_misc = wil_ioread32_and_clear(wil->csr +
  441. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  442. offsetof(struct RGF_ICR, ICM));
  443. u32 icr_misc = wil_ioread32_and_clear(wil->csr +
  444. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  445. offsetof(struct RGF_ICR, ICR));
  446. u32 imv_misc = wil_r(wil, RGF_DMA_EP_MISC_ICR +
  447. offsetof(struct RGF_ICR, IMV));
  448. /* HALP interrupt can be unmasked when misc interrupts are
  449. * masked
  450. */
  451. if (icr_misc & BIT_DMA_EP_MISC_ICR_HALP)
  452. return 0;
  453. wil_err(wil, "IRQ when it should be masked: pseudo 0x%08x\n"
  454. "Rx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  455. "Tx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  456. "Misc icm:icr:imv 0x%08x 0x%08x 0x%08x\n",
  457. pseudo_cause,
  458. icm_rx, icr_rx, imv_rx,
  459. icm_tx, icr_tx, imv_tx,
  460. icm_misc, icr_misc, imv_misc);
  461. return -EINVAL;
  462. }
  463. return 0;
  464. }
  465. static irqreturn_t wil6210_hardirq(int irq, void *cookie)
  466. {
  467. irqreturn_t rc = IRQ_HANDLED;
  468. struct wil6210_priv *wil = cookie;
  469. u32 pseudo_cause = wil_r(wil, RGF_DMA_PSEUDO_CAUSE);
  470. /**
  471. * pseudo_cause is Clear-On-Read, no need to ACK
  472. */
  473. if (unlikely((pseudo_cause == 0) || ((pseudo_cause & 0xff) == 0xff)))
  474. return IRQ_NONE;
  475. /* IRQ mask debug */
  476. if (unlikely(wil6210_debug_irq_mask(wil, pseudo_cause)))
  477. return IRQ_NONE;
  478. trace_wil6210_irq_pseudo(pseudo_cause);
  479. wil_dbg_irq(wil, "Pseudo IRQ 0x%08x\n", pseudo_cause);
  480. wil6210_mask_irq_pseudo(wil);
  481. /* Discover real IRQ cause
  482. * There are 2 possible phases for every IRQ:
  483. * - hard IRQ handler called right here
  484. * - threaded handler called later
  485. *
  486. * Hard IRQ handler reads and clears ISR.
  487. *
  488. * If threaded handler requested, hard IRQ handler
  489. * returns IRQ_WAKE_THREAD and saves ISR register value
  490. * for the threaded handler use.
  491. *
  492. * voting for wake thread - need at least 1 vote
  493. */
  494. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_RX) &&
  495. (wil6210_irq_rx(irq, cookie) == IRQ_WAKE_THREAD))
  496. rc = IRQ_WAKE_THREAD;
  497. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_TX) &&
  498. (wil6210_irq_tx(irq, cookie) == IRQ_WAKE_THREAD))
  499. rc = IRQ_WAKE_THREAD;
  500. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_MISC) &&
  501. (wil6210_irq_misc(irq, cookie) == IRQ_WAKE_THREAD))
  502. rc = IRQ_WAKE_THREAD;
  503. /* if thread is requested, it will unmask IRQ */
  504. if (rc != IRQ_WAKE_THREAD)
  505. wil6210_unmask_irq_pseudo(wil);
  506. return rc;
  507. }
  508. /* can't use wil_ioread32_and_clear because ICC value is not set yet */
  509. static inline void wil_clear32(void __iomem *addr)
  510. {
  511. u32 x = readl(addr);
  512. writel(x, addr);
  513. }
  514. void wil6210_clear_irq(struct wil6210_priv *wil)
  515. {
  516. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_RX_ICR) +
  517. offsetof(struct RGF_ICR, ICR));
  518. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_TX_ICR) +
  519. offsetof(struct RGF_ICR, ICR));
  520. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  521. offsetof(struct RGF_ICR, ICR));
  522. wmb(); /* make sure write completed */
  523. }
  524. void wil6210_set_halp(struct wil6210_priv *wil)
  525. {
  526. wil_dbg_irq(wil, "set_halp\n");
  527. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICS),
  528. BIT_DMA_EP_MISC_ICR_HALP);
  529. }
  530. void wil6210_clear_halp(struct wil6210_priv *wil)
  531. {
  532. wil_dbg_irq(wil, "clear_halp\n");
  533. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICR),
  534. BIT_DMA_EP_MISC_ICR_HALP);
  535. wil6210_unmask_halp(wil);
  536. }
  537. int wil6210_init_irq(struct wil6210_priv *wil, int irq, bool use_msi)
  538. {
  539. int rc;
  540. wil_dbg_misc(wil, "init_irq: %s\n", use_msi ? "MSI" : "INTx");
  541. rc = request_threaded_irq(irq, wil6210_hardirq,
  542. wil6210_thread_irq,
  543. use_msi ? 0 : IRQF_SHARED,
  544. WIL_NAME, wil);
  545. return rc;
  546. }
  547. void wil6210_fini_irq(struct wil6210_priv *wil, int irq)
  548. {
  549. wil_dbg_misc(wil, "fini_irq:\n");
  550. wil_mask_irq(wil);
  551. free_irq(irq, wil);
  552. }