interrupt.c 17 KB

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