interrupt.c 18 KB

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