interrupt.c 16 KB

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