interrupt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * Copyright (c) 2012-2017 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, "mask_irq_misc: mask_halp(%s)\n",
  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, "mask_halp\n");
  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, "mask_irq_pseudo\n");
  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, "unmask_irq_misc: unmask_halp(%s)\n",
  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, "unmask_halp\n");
  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, "unmask_irq_pseudo\n");
  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, "mask_irq\n");
  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, "unmask_irq\n");
  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, "configure_interrupt_moderation\n");
  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_ratelimited(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_ratelimited(
  227. wil,
  228. "Got Rx interrupt while stopping interface\n");
  229. }
  230. } else {
  231. wil_err_ratelimited(wil, "Got Rx interrupt while in reset\n");
  232. }
  233. }
  234. if (unlikely(isr))
  235. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  236. /* Rx IRQ will be enabled when NAPI processing finished */
  237. atomic_inc(&wil->isr_count_rx);
  238. if (unlikely(need_unmask))
  239. wil6210_unmask_irq_rx(wil);
  240. return IRQ_HANDLED;
  241. }
  242. static irqreturn_t wil6210_irq_tx(int irq, void *cookie)
  243. {
  244. struct wil6210_priv *wil = cookie;
  245. u32 isr = wil_ioread32_and_clear(wil->csr +
  246. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  247. offsetof(struct RGF_ICR, ICR));
  248. bool need_unmask = true;
  249. trace_wil6210_irq_tx(isr);
  250. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  251. if (unlikely(!isr)) {
  252. wil_err_ratelimited(wil, "spurious IRQ: TX\n");
  253. return IRQ_NONE;
  254. }
  255. wil6210_mask_irq_tx(wil);
  256. if (likely(isr & BIT_DMA_EP_TX_ICR_TX_DONE)) {
  257. wil_dbg_irq(wil, "TX done\n");
  258. isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE;
  259. /* clear also all VRING interrupts */
  260. isr &= ~(BIT(25) - 1UL);
  261. if (likely(test_bit(wil_status_fwready, wil->status))) {
  262. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  263. need_unmask = false;
  264. napi_schedule(&wil->napi_tx);
  265. } else {
  266. wil_err_ratelimited(wil, "Got Tx interrupt while in reset\n");
  267. }
  268. }
  269. if (unlikely(isr))
  270. wil_err_ratelimited(wil, "un-handled TX ISR bits 0x%08x\n",
  271. isr);
  272. /* Tx IRQ will be enabled when NAPI processing finished */
  273. atomic_inc(&wil->isr_count_tx);
  274. if (unlikely(need_unmask))
  275. wil6210_unmask_irq_tx(wil);
  276. return IRQ_HANDLED;
  277. }
  278. static void wil_notify_fw_error(struct wil6210_priv *wil)
  279. {
  280. struct device *dev = &wil_to_ndev(wil)->dev;
  281. char *envp[3] = {
  282. [0] = "SOURCE=wil6210",
  283. [1] = "EVENT=FW_ERROR",
  284. [2] = NULL,
  285. };
  286. wil_err(wil, "Notify about firmware error\n");
  287. kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
  288. }
  289. static void wil_cache_mbox_regs(struct wil6210_priv *wil)
  290. {
  291. /* make shadow copy of registers that should not change on run time */
  292. wil_memcpy_fromio_32(&wil->mbox_ctl, wil->csr + HOST_MBOX,
  293. sizeof(struct wil6210_mbox_ctl));
  294. wil_mbox_ring_le2cpus(&wil->mbox_ctl.rx);
  295. wil_mbox_ring_le2cpus(&wil->mbox_ctl.tx);
  296. }
  297. static irqreturn_t wil6210_irq_misc(int irq, void *cookie)
  298. {
  299. struct wil6210_priv *wil = cookie;
  300. u32 isr = wil_ioread32_and_clear(wil->csr +
  301. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  302. offsetof(struct RGF_ICR, ICR));
  303. trace_wil6210_irq_misc(isr);
  304. wil_dbg_irq(wil, "ISR MISC 0x%08x\n", isr);
  305. if (!isr) {
  306. wil_err(wil, "spurious IRQ: MISC\n");
  307. return IRQ_NONE;
  308. }
  309. wil6210_mask_irq_misc(wil, false);
  310. if (isr & ISR_MISC_FW_ERROR) {
  311. u32 fw_assert_code = wil_r(wil, RGF_FW_ASSERT_CODE);
  312. u32 ucode_assert_code = wil_r(wil, RGF_UCODE_ASSERT_CODE);
  313. wil_err(wil,
  314. "Firmware error detected, assert codes FW 0x%08x, UCODE 0x%08x\n",
  315. fw_assert_code, ucode_assert_code);
  316. clear_bit(wil_status_fwready, wil->status);
  317. /*
  318. * do not clear @isr here - we do 2-nd part in thread
  319. * there, user space get notified, and it should be done
  320. * in non-atomic context
  321. */
  322. }
  323. if (isr & ISR_MISC_FW_READY) {
  324. wil_dbg_irq(wil, "IRQ: FW ready\n");
  325. wil_cache_mbox_regs(wil);
  326. set_bit(wil_status_mbox_ready, wil->status);
  327. /**
  328. * Actual FW ready indicated by the
  329. * WMI_FW_READY_EVENTID
  330. */
  331. isr &= ~ISR_MISC_FW_READY;
  332. }
  333. if (isr & BIT_DMA_EP_MISC_ICR_HALP) {
  334. wil_dbg_irq(wil, "irq_misc: HALP IRQ invoked\n");
  335. wil6210_mask_halp(wil);
  336. isr &= ~BIT_DMA_EP_MISC_ICR_HALP;
  337. complete(&wil->halp.comp);
  338. }
  339. wil->isr_misc = isr;
  340. if (isr) {
  341. return IRQ_WAKE_THREAD;
  342. } else {
  343. wil6210_unmask_irq_misc(wil, false);
  344. return IRQ_HANDLED;
  345. }
  346. }
  347. static irqreturn_t wil6210_irq_misc_thread(int irq, void *cookie)
  348. {
  349. struct wil6210_priv *wil = cookie;
  350. u32 isr = wil->isr_misc;
  351. trace_wil6210_irq_misc_thread(isr);
  352. wil_dbg_irq(wil, "Thread ISR MISC 0x%08x\n", isr);
  353. if (isr & ISR_MISC_FW_ERROR) {
  354. wil->recovery_state = fw_recovery_pending;
  355. wil_fw_core_dump(wil);
  356. wil_notify_fw_error(wil);
  357. isr &= ~ISR_MISC_FW_ERROR;
  358. if (wil->platform_ops.notify) {
  359. wil_err(wil, "notify platform driver about FW crash");
  360. wil->platform_ops.notify(wil->platform_handle,
  361. WIL_PLATFORM_EVT_FW_CRASH);
  362. } else {
  363. wil_fw_error_recovery(wil);
  364. }
  365. }
  366. if (isr & ISR_MISC_MBOX_EVT) {
  367. wil_dbg_irq(wil, "MBOX event\n");
  368. wmi_recv_cmd(wil);
  369. isr &= ~ISR_MISC_MBOX_EVT;
  370. }
  371. if (isr)
  372. wil_dbg_irq(wil, "un-handled MISC ISR bits 0x%08x\n", isr);
  373. wil->isr_misc = 0;
  374. wil6210_unmask_irq_misc(wil, false);
  375. return IRQ_HANDLED;
  376. }
  377. /**
  378. * thread IRQ handler
  379. */
  380. static irqreturn_t wil6210_thread_irq(int irq, void *cookie)
  381. {
  382. struct wil6210_priv *wil = cookie;
  383. wil_dbg_irq(wil, "Thread IRQ\n");
  384. /* Discover real IRQ cause */
  385. if (wil->isr_misc)
  386. wil6210_irq_misc_thread(irq, cookie);
  387. wil6210_unmask_irq_pseudo(wil);
  388. if (wil->suspend_resp_rcvd) {
  389. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  390. wil->suspend_resp_comp = true;
  391. wake_up_interruptible(&wil->wq);
  392. }
  393. return IRQ_HANDLED;
  394. }
  395. /* DEBUG
  396. * There is subtle bug in hardware that causes IRQ to raise when it should be
  397. * masked. It is quite rare and hard to debug.
  398. *
  399. * Catch irq issue if it happens and print all I can.
  400. */
  401. static int wil6210_debug_irq_mask(struct wil6210_priv *wil, u32 pseudo_cause)
  402. {
  403. if (!test_bit(wil_status_irqen, wil->status)) {
  404. u32 icm_rx = wil_ioread32_and_clear(wil->csr +
  405. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  406. offsetof(struct RGF_ICR, ICM));
  407. u32 icr_rx = wil_ioread32_and_clear(wil->csr +
  408. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  409. offsetof(struct RGF_ICR, ICR));
  410. u32 imv_rx = wil_r(wil, RGF_DMA_EP_RX_ICR +
  411. offsetof(struct RGF_ICR, IMV));
  412. u32 icm_tx = wil_ioread32_and_clear(wil->csr +
  413. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  414. offsetof(struct RGF_ICR, ICM));
  415. u32 icr_tx = wil_ioread32_and_clear(wil->csr +
  416. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  417. offsetof(struct RGF_ICR, ICR));
  418. u32 imv_tx = wil_r(wil, RGF_DMA_EP_TX_ICR +
  419. offsetof(struct RGF_ICR, IMV));
  420. u32 icm_misc = wil_ioread32_and_clear(wil->csr +
  421. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  422. offsetof(struct RGF_ICR, ICM));
  423. u32 icr_misc = wil_ioread32_and_clear(wil->csr +
  424. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  425. offsetof(struct RGF_ICR, ICR));
  426. u32 imv_misc = wil_r(wil, RGF_DMA_EP_MISC_ICR +
  427. offsetof(struct RGF_ICR, IMV));
  428. /* HALP interrupt can be unmasked when misc interrupts are
  429. * masked
  430. */
  431. if (icr_misc & BIT_DMA_EP_MISC_ICR_HALP)
  432. return 0;
  433. wil_err(wil, "IRQ when it should be masked: pseudo 0x%08x\n"
  434. "Rx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  435. "Tx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  436. "Misc icm:icr:imv 0x%08x 0x%08x 0x%08x\n",
  437. pseudo_cause,
  438. icm_rx, icr_rx, imv_rx,
  439. icm_tx, icr_tx, imv_tx,
  440. icm_misc, icr_misc, imv_misc);
  441. return -EINVAL;
  442. }
  443. return 0;
  444. }
  445. static irqreturn_t wil6210_hardirq(int irq, void *cookie)
  446. {
  447. irqreturn_t rc = IRQ_HANDLED;
  448. struct wil6210_priv *wil = cookie;
  449. u32 pseudo_cause = wil_r(wil, RGF_DMA_PSEUDO_CAUSE);
  450. /**
  451. * pseudo_cause is Clear-On-Read, no need to ACK
  452. */
  453. if (unlikely((pseudo_cause == 0) || ((pseudo_cause & 0xff) == 0xff)))
  454. return IRQ_NONE;
  455. /* FIXME: IRQ mask debug */
  456. if (unlikely(wil6210_debug_irq_mask(wil, pseudo_cause)))
  457. return IRQ_NONE;
  458. trace_wil6210_irq_pseudo(pseudo_cause);
  459. wil_dbg_irq(wil, "Pseudo IRQ 0x%08x\n", pseudo_cause);
  460. wil6210_mask_irq_pseudo(wil);
  461. /* Discover real IRQ cause
  462. * There are 2 possible phases for every IRQ:
  463. * - hard IRQ handler called right here
  464. * - threaded handler called later
  465. *
  466. * Hard IRQ handler reads and clears ISR.
  467. *
  468. * If threaded handler requested, hard IRQ handler
  469. * returns IRQ_WAKE_THREAD and saves ISR register value
  470. * for the threaded handler use.
  471. *
  472. * voting for wake thread - need at least 1 vote
  473. */
  474. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_RX) &&
  475. (wil6210_irq_rx(irq, cookie) == IRQ_WAKE_THREAD))
  476. rc = IRQ_WAKE_THREAD;
  477. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_TX) &&
  478. (wil6210_irq_tx(irq, cookie) == IRQ_WAKE_THREAD))
  479. rc = IRQ_WAKE_THREAD;
  480. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_MISC) &&
  481. (wil6210_irq_misc(irq, cookie) == IRQ_WAKE_THREAD))
  482. rc = IRQ_WAKE_THREAD;
  483. /* if thread is requested, it will unmask IRQ */
  484. if (rc != IRQ_WAKE_THREAD)
  485. wil6210_unmask_irq_pseudo(wil);
  486. return rc;
  487. }
  488. /* can't use wil_ioread32_and_clear because ICC value is not set yet */
  489. static inline void wil_clear32(void __iomem *addr)
  490. {
  491. u32 x = readl(addr);
  492. writel(x, addr);
  493. }
  494. void wil6210_clear_irq(struct wil6210_priv *wil)
  495. {
  496. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_RX_ICR) +
  497. offsetof(struct RGF_ICR, ICR));
  498. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_TX_ICR) +
  499. offsetof(struct RGF_ICR, ICR));
  500. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  501. offsetof(struct RGF_ICR, ICR));
  502. wmb(); /* make sure write completed */
  503. }
  504. void wil6210_set_halp(struct wil6210_priv *wil)
  505. {
  506. wil_dbg_irq(wil, "set_halp\n");
  507. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICS),
  508. BIT_DMA_EP_MISC_ICR_HALP);
  509. }
  510. void wil6210_clear_halp(struct wil6210_priv *wil)
  511. {
  512. wil_dbg_irq(wil, "clear_halp\n");
  513. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICR),
  514. BIT_DMA_EP_MISC_ICR_HALP);
  515. wil6210_unmask_halp(wil);
  516. }
  517. int wil6210_init_irq(struct wil6210_priv *wil, int irq, bool use_msi)
  518. {
  519. int rc;
  520. wil_dbg_misc(wil, "init_irq: %s\n", use_msi ? "MSI" : "INTx");
  521. rc = request_threaded_irq(irq, wil6210_hardirq,
  522. wil6210_thread_irq,
  523. use_msi ? 0 : IRQF_SHARED,
  524. WIL_NAME, wil);
  525. return rc;
  526. }
  527. void wil6210_fini_irq(struct wil6210_priv *wil, int irq)
  528. {
  529. wil_dbg_misc(wil, "fini_irq:\n");
  530. wil_mask_irq(wil);
  531. free_irq(irq, wil);
  532. }