interrupt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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_TX_EDMA BIT_TX_STATUS_IRQ
  44. #define WIL6210_IMC_RX_EDMA BIT_RX_STATUS_IRQ
  45. #define WIL6210_IMC_MISC_NO_HALP (ISR_MISC_FW_READY | \
  46. ISR_MISC_MBOX_EVT | \
  47. ISR_MISC_FW_ERROR)
  48. #define WIL6210_IMC_MISC (WIL6210_IMC_MISC_NO_HALP | \
  49. BIT_DMA_EP_MISC_ICR_HALP)
  50. #define WIL6210_IRQ_PSEUDO_MASK (u32)(~(BIT_DMA_PSEUDO_CAUSE_RX | \
  51. BIT_DMA_PSEUDO_CAUSE_TX | \
  52. BIT_DMA_PSEUDO_CAUSE_MISC))
  53. #if defined(CONFIG_WIL6210_ISR_COR)
  54. /* configure to Clear-On-Read mode */
  55. #define WIL_ICR_ICC_VALUE (0xFFFFFFFFUL)
  56. #define WIL_ICR_ICC_MISC_VALUE (0xF7FFFFFFUL)
  57. static inline void wil_icr_clear(u32 x, void __iomem *addr)
  58. {
  59. }
  60. #else /* defined(CONFIG_WIL6210_ISR_COR) */
  61. /* configure to Write-1-to-Clear mode */
  62. #define WIL_ICR_ICC_VALUE (0UL)
  63. #define WIL_ICR_ICC_MISC_VALUE (0UL)
  64. static inline void wil_icr_clear(u32 x, void __iomem *addr)
  65. {
  66. writel(x, addr);
  67. }
  68. #endif /* defined(CONFIG_WIL6210_ISR_COR) */
  69. static inline u32 wil_ioread32_and_clear(void __iomem *addr)
  70. {
  71. u32 x = readl(addr);
  72. wil_icr_clear(x, addr);
  73. return x;
  74. }
  75. static void wil6210_mask_irq_tx(struct wil6210_priv *wil)
  76. {
  77. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, IMS),
  78. WIL6210_IRQ_DISABLE);
  79. }
  80. static void wil6210_mask_irq_tx_edma(struct wil6210_priv *wil)
  81. {
  82. wil_w(wil, RGF_INT_GEN_TX_ICR + offsetof(struct RGF_ICR, IMS),
  83. WIL6210_IRQ_DISABLE);
  84. }
  85. static void wil6210_mask_irq_rx(struct wil6210_priv *wil)
  86. {
  87. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, IMS),
  88. WIL6210_IRQ_DISABLE);
  89. }
  90. static void wil6210_mask_irq_rx_edma(struct wil6210_priv *wil)
  91. {
  92. wil_w(wil, RGF_INT_GEN_RX_ICR + offsetof(struct RGF_ICR, IMS),
  93. WIL6210_IRQ_DISABLE);
  94. }
  95. static void wil6210_mask_irq_misc(struct wil6210_priv *wil, bool mask_halp)
  96. {
  97. wil_dbg_irq(wil, "mask_irq_misc: mask_halp(%s)\n",
  98. mask_halp ? "true" : "false");
  99. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMS),
  100. mask_halp ? WIL6210_IRQ_DISABLE : WIL6210_IRQ_DISABLE_NO_HALP);
  101. }
  102. void wil6210_mask_halp(struct wil6210_priv *wil)
  103. {
  104. wil_dbg_irq(wil, "mask_halp\n");
  105. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMS),
  106. BIT_DMA_EP_MISC_ICR_HALP);
  107. }
  108. static void wil6210_mask_irq_pseudo(struct wil6210_priv *wil)
  109. {
  110. wil_dbg_irq(wil, "mask_irq_pseudo\n");
  111. wil_w(wil, RGF_DMA_PSEUDO_CAUSE_MASK_SW, WIL6210_IRQ_DISABLE);
  112. clear_bit(wil_status_irqen, wil->status);
  113. }
  114. void wil6210_unmask_irq_tx(struct wil6210_priv *wil)
  115. {
  116. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, IMC),
  117. WIL6210_IMC_TX);
  118. }
  119. void wil6210_unmask_irq_tx_edma(struct wil6210_priv *wil)
  120. {
  121. wil_w(wil, RGF_INT_GEN_TX_ICR + offsetof(struct RGF_ICR, IMC),
  122. WIL6210_IMC_TX_EDMA);
  123. }
  124. void wil6210_unmask_irq_rx(struct wil6210_priv *wil)
  125. {
  126. bool unmask_rx_htrsh = atomic_read(&wil->connected_vifs) > 0;
  127. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, IMC),
  128. unmask_rx_htrsh ? WIL6210_IMC_RX : WIL6210_IMC_RX_NO_RX_HTRSH);
  129. }
  130. void wil6210_unmask_irq_rx_edma(struct wil6210_priv *wil)
  131. {
  132. wil_w(wil, RGF_INT_GEN_RX_ICR + offsetof(struct RGF_ICR, IMC),
  133. WIL6210_IMC_RX_EDMA);
  134. }
  135. static void wil6210_unmask_irq_misc(struct wil6210_priv *wil, bool unmask_halp)
  136. {
  137. wil_dbg_irq(wil, "unmask_irq_misc: unmask_halp(%s)\n",
  138. unmask_halp ? "true" : "false");
  139. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMC),
  140. unmask_halp ? WIL6210_IMC_MISC : WIL6210_IMC_MISC_NO_HALP);
  141. }
  142. static void wil6210_unmask_halp(struct wil6210_priv *wil)
  143. {
  144. wil_dbg_irq(wil, "unmask_halp\n");
  145. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, IMC),
  146. BIT_DMA_EP_MISC_ICR_HALP);
  147. }
  148. static void wil6210_unmask_irq_pseudo(struct wil6210_priv *wil)
  149. {
  150. wil_dbg_irq(wil, "unmask_irq_pseudo\n");
  151. set_bit(wil_status_irqen, wil->status);
  152. wil_w(wil, RGF_DMA_PSEUDO_CAUSE_MASK_SW, WIL6210_IRQ_PSEUDO_MASK);
  153. }
  154. void wil_mask_irq(struct wil6210_priv *wil)
  155. {
  156. wil_dbg_irq(wil, "mask_irq\n");
  157. wil6210_mask_irq_tx(wil);
  158. wil6210_mask_irq_tx_edma(wil);
  159. wil6210_mask_irq_rx(wil);
  160. wil6210_mask_irq_rx_edma(wil);
  161. wil6210_mask_irq_misc(wil, true);
  162. wil6210_mask_irq_pseudo(wil);
  163. }
  164. void wil_unmask_irq(struct wil6210_priv *wil)
  165. {
  166. wil_dbg_irq(wil, "unmask_irq\n");
  167. wil_w(wil, RGF_DMA_EP_RX_ICR + offsetof(struct RGF_ICR, ICC),
  168. WIL_ICR_ICC_VALUE);
  169. wil_w(wil, RGF_DMA_EP_TX_ICR + offsetof(struct RGF_ICR, ICC),
  170. WIL_ICR_ICC_VALUE);
  171. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICC),
  172. WIL_ICR_ICC_MISC_VALUE);
  173. wil_w(wil, RGF_INT_GEN_TX_ICR + offsetof(struct RGF_ICR, ICC),
  174. WIL_ICR_ICC_VALUE);
  175. wil_w(wil, RGF_INT_GEN_RX_ICR + offsetof(struct RGF_ICR, ICC),
  176. WIL_ICR_ICC_VALUE);
  177. wil6210_unmask_irq_pseudo(wil);
  178. if (wil->use_enhanced_dma_hw) {
  179. wil6210_unmask_irq_tx_edma(wil);
  180. wil6210_unmask_irq_rx_edma(wil);
  181. } else {
  182. wil6210_unmask_irq_tx(wil);
  183. wil6210_unmask_irq_rx(wil);
  184. }
  185. wil6210_unmask_irq_misc(wil, true);
  186. }
  187. void wil_configure_interrupt_moderation_edma(struct wil6210_priv *wil)
  188. {
  189. u32 moderation;
  190. wil_s(wil, RGF_INT_GEN_IDLE_TIME_LIMIT, WIL_EDMA_IDLE_TIME_LIMIT_USEC);
  191. wil_s(wil, RGF_INT_GEN_TIME_UNIT_LIMIT, WIL_EDMA_TIME_UNIT_CLK_CYCLES);
  192. /* Update RX and TX moderation */
  193. moderation = wil->rx_max_burst_duration |
  194. (WIL_EDMA_AGG_WATERMARK << WIL_EDMA_AGG_WATERMARK_POS);
  195. wil_w(wil, RGF_INT_CTRL_INT_GEN_CFG_0, moderation);
  196. wil_w(wil, RGF_INT_CTRL_INT_GEN_CFG_1, moderation);
  197. /* Treat special events as regular
  198. * (set bit 0 to 0x1 and clear bits 1-8)
  199. */
  200. wil_c(wil, RGF_INT_COUNT_ON_SPECIAL_EVT, 0x1FE);
  201. wil_s(wil, RGF_INT_COUNT_ON_SPECIAL_EVT, 0x1);
  202. }
  203. void wil_configure_interrupt_moderation(struct wil6210_priv *wil)
  204. {
  205. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  206. wil_dbg_irq(wil, "configure_interrupt_moderation\n");
  207. /* disable interrupt moderation for monitor
  208. * to get better timestamp precision
  209. */
  210. if (wdev->iftype == NL80211_IFTYPE_MONITOR)
  211. return;
  212. /* Disable and clear tx counter before (re)configuration */
  213. wil_w(wil, RGF_DMA_ITR_TX_CNT_CTL, BIT_DMA_ITR_TX_CNT_CTL_CLR);
  214. wil_w(wil, RGF_DMA_ITR_TX_CNT_TRSH, wil->tx_max_burst_duration);
  215. wil_info(wil, "set ITR_TX_CNT_TRSH = %d usec\n",
  216. wil->tx_max_burst_duration);
  217. /* Configure TX max burst duration timer to use usec units */
  218. wil_w(wil, RGF_DMA_ITR_TX_CNT_CTL,
  219. BIT_DMA_ITR_TX_CNT_CTL_EN | BIT_DMA_ITR_TX_CNT_CTL_EXT_TIC_SEL);
  220. /* Disable and clear tx idle counter before (re)configuration */
  221. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_CTL, BIT_DMA_ITR_TX_IDL_CNT_CTL_CLR);
  222. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_TRSH, wil->tx_interframe_timeout);
  223. wil_info(wil, "set ITR_TX_IDL_CNT_TRSH = %d usec\n",
  224. wil->tx_interframe_timeout);
  225. /* Configure TX max burst duration timer to use usec units */
  226. wil_w(wil, RGF_DMA_ITR_TX_IDL_CNT_CTL, BIT_DMA_ITR_TX_IDL_CNT_CTL_EN |
  227. BIT_DMA_ITR_TX_IDL_CNT_CTL_EXT_TIC_SEL);
  228. /* Disable and clear rx counter before (re)configuration */
  229. wil_w(wil, RGF_DMA_ITR_RX_CNT_CTL, BIT_DMA_ITR_RX_CNT_CTL_CLR);
  230. wil_w(wil, RGF_DMA_ITR_RX_CNT_TRSH, wil->rx_max_burst_duration);
  231. wil_info(wil, "set ITR_RX_CNT_TRSH = %d usec\n",
  232. wil->rx_max_burst_duration);
  233. /* Configure TX max burst duration timer to use usec units */
  234. wil_w(wil, RGF_DMA_ITR_RX_CNT_CTL,
  235. BIT_DMA_ITR_RX_CNT_CTL_EN | BIT_DMA_ITR_RX_CNT_CTL_EXT_TIC_SEL);
  236. /* Disable and clear rx idle counter before (re)configuration */
  237. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_CTL, BIT_DMA_ITR_RX_IDL_CNT_CTL_CLR);
  238. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_TRSH, wil->rx_interframe_timeout);
  239. wil_info(wil, "set ITR_RX_IDL_CNT_TRSH = %d usec\n",
  240. wil->rx_interframe_timeout);
  241. /* Configure TX max burst duration timer to use usec units */
  242. wil_w(wil, RGF_DMA_ITR_RX_IDL_CNT_CTL, BIT_DMA_ITR_RX_IDL_CNT_CTL_EN |
  243. BIT_DMA_ITR_RX_IDL_CNT_CTL_EXT_TIC_SEL);
  244. }
  245. static irqreturn_t wil6210_irq_rx(int irq, void *cookie)
  246. {
  247. struct wil6210_priv *wil = cookie;
  248. u32 isr = wil_ioread32_and_clear(wil->csr +
  249. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  250. offsetof(struct RGF_ICR, ICR));
  251. bool need_unmask = true;
  252. trace_wil6210_irq_rx(isr);
  253. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  254. if (unlikely(!isr)) {
  255. wil_err_ratelimited(wil, "spurious IRQ: RX\n");
  256. return IRQ_NONE;
  257. }
  258. wil6210_mask_irq_rx(wil);
  259. /* RX_DONE and RX_HTRSH interrupts are the same if interrupt
  260. * moderation is not used. Interrupt moderation may cause RX
  261. * buffer overflow while RX_DONE is delayed. The required
  262. * action is always the same - should empty the accumulated
  263. * packets from the RX ring.
  264. */
  265. if (likely(isr & (BIT_DMA_EP_RX_ICR_RX_DONE |
  266. BIT_DMA_EP_RX_ICR_RX_HTRSH))) {
  267. wil_dbg_irq(wil, "RX done / RX_HTRSH received, ISR (0x%x)\n",
  268. isr);
  269. isr &= ~(BIT_DMA_EP_RX_ICR_RX_DONE |
  270. BIT_DMA_EP_RX_ICR_RX_HTRSH);
  271. if (likely(test_bit(wil_status_fwready, wil->status))) {
  272. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  273. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  274. need_unmask = false;
  275. napi_schedule(&wil->napi_rx);
  276. } else {
  277. wil_err_ratelimited(
  278. wil,
  279. "Got Rx interrupt while stopping interface\n");
  280. }
  281. } else {
  282. wil_err_ratelimited(wil, "Got Rx interrupt while in reset\n");
  283. }
  284. }
  285. if (unlikely(isr))
  286. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  287. /* Rx IRQ will be enabled when NAPI processing finished */
  288. atomic_inc(&wil->isr_count_rx);
  289. if (unlikely(need_unmask))
  290. wil6210_unmask_irq_rx(wil);
  291. return IRQ_HANDLED;
  292. }
  293. static irqreturn_t wil6210_irq_rx_edma(int irq, void *cookie)
  294. {
  295. struct wil6210_priv *wil = cookie;
  296. u32 isr = wil_ioread32_and_clear(wil->csr +
  297. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  298. offsetof(struct RGF_ICR, ICR));
  299. bool need_unmask = true;
  300. trace_wil6210_irq_rx(isr);
  301. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  302. if (unlikely(!isr)) {
  303. wil_err(wil, "spurious IRQ: RX\n");
  304. return IRQ_NONE;
  305. }
  306. wil6210_mask_irq_rx_edma(wil);
  307. if (likely(isr & BIT_RX_STATUS_IRQ)) {
  308. wil_dbg_irq(wil, "RX status ring\n");
  309. isr &= ~BIT_RX_STATUS_IRQ;
  310. if (likely(test_bit(wil_status_fwready, wil->status))) {
  311. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  312. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  313. need_unmask = false;
  314. napi_schedule(&wil->napi_rx);
  315. } else {
  316. wil_err(wil,
  317. "Got Rx interrupt while stopping interface\n");
  318. }
  319. } else {
  320. wil_err(wil, "Got Rx interrupt while in reset\n");
  321. }
  322. }
  323. if (unlikely(isr))
  324. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  325. /* Rx IRQ will be enabled when NAPI processing finished */
  326. atomic_inc(&wil->isr_count_rx);
  327. if (unlikely(need_unmask))
  328. wil6210_unmask_irq_rx_edma(wil);
  329. return IRQ_HANDLED;
  330. }
  331. static irqreturn_t wil6210_irq_tx_edma(int irq, void *cookie)
  332. {
  333. struct wil6210_priv *wil = cookie;
  334. u32 isr = wil_ioread32_and_clear(wil->csr +
  335. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  336. offsetof(struct RGF_ICR, ICR));
  337. bool need_unmask = true;
  338. trace_wil6210_irq_tx(isr);
  339. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  340. if (unlikely(!isr)) {
  341. wil_err(wil, "spurious IRQ: TX\n");
  342. return IRQ_NONE;
  343. }
  344. wil6210_mask_irq_tx_edma(wil);
  345. if (likely(isr & BIT_TX_STATUS_IRQ)) {
  346. wil_dbg_irq(wil, "TX status ring\n");
  347. isr &= ~BIT_TX_STATUS_IRQ;
  348. if (likely(test_bit(wil_status_fwready, wil->status))) {
  349. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  350. need_unmask = false;
  351. napi_schedule(&wil->napi_tx);
  352. } else {
  353. wil_err(wil, "Got Tx status ring IRQ while in reset\n");
  354. }
  355. }
  356. if (unlikely(isr))
  357. wil_err(wil, "un-handled TX ISR bits 0x%08x\n", isr);
  358. /* Tx IRQ will be enabled when NAPI processing finished */
  359. atomic_inc(&wil->isr_count_tx);
  360. if (unlikely(need_unmask))
  361. wil6210_unmask_irq_tx_edma(wil);
  362. return IRQ_HANDLED;
  363. }
  364. static irqreturn_t wil6210_irq_tx(int irq, void *cookie)
  365. {
  366. struct wil6210_priv *wil = cookie;
  367. u32 isr = wil_ioread32_and_clear(wil->csr +
  368. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  369. offsetof(struct RGF_ICR, ICR));
  370. bool need_unmask = true;
  371. trace_wil6210_irq_tx(isr);
  372. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  373. if (unlikely(!isr)) {
  374. wil_err_ratelimited(wil, "spurious IRQ: TX\n");
  375. return IRQ_NONE;
  376. }
  377. wil6210_mask_irq_tx(wil);
  378. if (likely(isr & BIT_DMA_EP_TX_ICR_TX_DONE)) {
  379. wil_dbg_irq(wil, "TX done\n");
  380. isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE;
  381. /* clear also all VRING interrupts */
  382. isr &= ~(BIT(25) - 1UL);
  383. if (likely(test_bit(wil_status_fwready, wil->status))) {
  384. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  385. need_unmask = false;
  386. napi_schedule(&wil->napi_tx);
  387. } else {
  388. wil_err_ratelimited(wil, "Got Tx interrupt while in reset\n");
  389. }
  390. }
  391. if (unlikely(isr))
  392. wil_err_ratelimited(wil, "un-handled TX ISR bits 0x%08x\n",
  393. isr);
  394. /* Tx IRQ will be enabled when NAPI processing finished */
  395. atomic_inc(&wil->isr_count_tx);
  396. if (unlikely(need_unmask))
  397. wil6210_unmask_irq_tx(wil);
  398. return IRQ_HANDLED;
  399. }
  400. static void wil_notify_fw_error(struct wil6210_priv *wil)
  401. {
  402. struct device *dev = &wil->main_ndev->dev;
  403. char *envp[3] = {
  404. [0] = "SOURCE=wil6210",
  405. [1] = "EVENT=FW_ERROR",
  406. [2] = NULL,
  407. };
  408. wil_err(wil, "Notify about firmware error\n");
  409. kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
  410. }
  411. static void wil_cache_mbox_regs(struct wil6210_priv *wil)
  412. {
  413. /* make shadow copy of registers that should not change on run time */
  414. wil_memcpy_fromio_32(&wil->mbox_ctl, wil->csr + HOST_MBOX,
  415. sizeof(struct wil6210_mbox_ctl));
  416. wil_mbox_ring_le2cpus(&wil->mbox_ctl.rx);
  417. wil_mbox_ring_le2cpus(&wil->mbox_ctl.tx);
  418. }
  419. static bool wil_validate_mbox_regs(struct wil6210_priv *wil)
  420. {
  421. size_t min_size = sizeof(struct wil6210_mbox_hdr) +
  422. sizeof(struct wmi_cmd_hdr);
  423. if (wil->mbox_ctl.rx.entry_size < min_size) {
  424. wil_err(wil, "rx mbox entry too small (%d)\n",
  425. wil->mbox_ctl.rx.entry_size);
  426. return false;
  427. }
  428. if (wil->mbox_ctl.tx.entry_size < min_size) {
  429. wil_err(wil, "tx mbox entry too small (%d)\n",
  430. wil->mbox_ctl.tx.entry_size);
  431. return false;
  432. }
  433. return true;
  434. }
  435. static irqreturn_t wil6210_irq_misc(int irq, void *cookie)
  436. {
  437. struct wil6210_priv *wil = cookie;
  438. u32 isr = wil_ioread32_and_clear(wil->csr +
  439. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  440. offsetof(struct RGF_ICR, ICR));
  441. trace_wil6210_irq_misc(isr);
  442. wil_dbg_irq(wil, "ISR MISC 0x%08x\n", isr);
  443. if (!isr) {
  444. wil_err(wil, "spurious IRQ: MISC\n");
  445. return IRQ_NONE;
  446. }
  447. wil6210_mask_irq_misc(wil, false);
  448. if (isr & ISR_MISC_FW_ERROR) {
  449. u32 fw_assert_code = wil_r(wil, wil->rgf_fw_assert_code_addr);
  450. u32 ucode_assert_code =
  451. wil_r(wil, wil->rgf_ucode_assert_code_addr);
  452. wil_err(wil,
  453. "Firmware error detected, assert codes FW 0x%08x, UCODE 0x%08x\n",
  454. fw_assert_code, ucode_assert_code);
  455. clear_bit(wil_status_fwready, wil->status);
  456. /*
  457. * do not clear @isr here - we do 2-nd part in thread
  458. * there, user space get notified, and it should be done
  459. * in non-atomic context
  460. */
  461. }
  462. if (isr & ISR_MISC_FW_READY) {
  463. wil_dbg_irq(wil, "IRQ: FW ready\n");
  464. wil_cache_mbox_regs(wil);
  465. if (wil_validate_mbox_regs(wil))
  466. set_bit(wil_status_mbox_ready, wil->status);
  467. /**
  468. * Actual FW ready indicated by the
  469. * WMI_FW_READY_EVENTID
  470. */
  471. isr &= ~ISR_MISC_FW_READY;
  472. }
  473. if (isr & BIT_DMA_EP_MISC_ICR_HALP) {
  474. wil_dbg_irq(wil, "irq_misc: HALP IRQ invoked\n");
  475. wil6210_mask_halp(wil);
  476. isr &= ~BIT_DMA_EP_MISC_ICR_HALP;
  477. complete(&wil->halp.comp);
  478. }
  479. wil->isr_misc = isr;
  480. if (isr) {
  481. return IRQ_WAKE_THREAD;
  482. } else {
  483. wil6210_unmask_irq_misc(wil, false);
  484. return IRQ_HANDLED;
  485. }
  486. }
  487. static irqreturn_t wil6210_irq_misc_thread(int irq, void *cookie)
  488. {
  489. struct wil6210_priv *wil = cookie;
  490. u32 isr = wil->isr_misc;
  491. trace_wil6210_irq_misc_thread(isr);
  492. wil_dbg_irq(wil, "Thread ISR MISC 0x%08x\n", isr);
  493. if (isr & ISR_MISC_FW_ERROR) {
  494. wil->recovery_state = fw_recovery_pending;
  495. wil_fw_core_dump(wil);
  496. wil_notify_fw_error(wil);
  497. isr &= ~ISR_MISC_FW_ERROR;
  498. if (wil->platform_ops.notify) {
  499. wil_err(wil, "notify platform driver about FW crash");
  500. wil->platform_ops.notify(wil->platform_handle,
  501. WIL_PLATFORM_EVT_FW_CRASH);
  502. } else {
  503. wil_fw_error_recovery(wil);
  504. }
  505. }
  506. if (isr & ISR_MISC_MBOX_EVT) {
  507. wil_dbg_irq(wil, "MBOX event\n");
  508. wmi_recv_cmd(wil);
  509. isr &= ~ISR_MISC_MBOX_EVT;
  510. }
  511. if (isr)
  512. wil_dbg_irq(wil, "un-handled MISC ISR bits 0x%08x\n", isr);
  513. wil->isr_misc = 0;
  514. wil6210_unmask_irq_misc(wil, false);
  515. /* in non-triple MSI case, this is done inside wil6210_thread_irq
  516. * because it has to be done after unmasking the pseudo.
  517. */
  518. if (wil->n_msi == 3 && wil->suspend_resp_rcvd) {
  519. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  520. wil->suspend_resp_comp = true;
  521. wake_up_interruptible(&wil->wq);
  522. }
  523. return IRQ_HANDLED;
  524. }
  525. /**
  526. * thread IRQ handler
  527. */
  528. static irqreturn_t wil6210_thread_irq(int irq, void *cookie)
  529. {
  530. struct wil6210_priv *wil = cookie;
  531. wil_dbg_irq(wil, "Thread IRQ\n");
  532. /* Discover real IRQ cause */
  533. if (wil->isr_misc)
  534. wil6210_irq_misc_thread(irq, cookie);
  535. wil6210_unmask_irq_pseudo(wil);
  536. if (wil->suspend_resp_rcvd) {
  537. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  538. wil->suspend_resp_comp = true;
  539. wake_up_interruptible(&wil->wq);
  540. }
  541. return IRQ_HANDLED;
  542. }
  543. /* DEBUG
  544. * There is subtle bug in hardware that causes IRQ to raise when it should be
  545. * masked. It is quite rare and hard to debug.
  546. *
  547. * Catch irq issue if it happens and print all I can.
  548. */
  549. static int wil6210_debug_irq_mask(struct wil6210_priv *wil, u32 pseudo_cause)
  550. {
  551. u32 icm_rx, icr_rx, imv_rx;
  552. u32 icm_tx, icr_tx, imv_tx;
  553. u32 icm_misc, icr_misc, imv_misc;
  554. if (!test_bit(wil_status_irqen, wil->status)) {
  555. if (wil->use_enhanced_dma_hw) {
  556. icm_rx = wil_ioread32_and_clear(wil->csr +
  557. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  558. offsetof(struct RGF_ICR, ICM));
  559. icr_rx = wil_ioread32_and_clear(wil->csr +
  560. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  561. offsetof(struct RGF_ICR, ICR));
  562. imv_rx = wil_r(wil, RGF_INT_GEN_RX_ICR +
  563. offsetof(struct RGF_ICR, IMV));
  564. icm_tx = wil_ioread32_and_clear(wil->csr +
  565. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  566. offsetof(struct RGF_ICR, ICM));
  567. icr_tx = wil_ioread32_and_clear(wil->csr +
  568. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  569. offsetof(struct RGF_ICR, ICR));
  570. imv_tx = wil_r(wil, RGF_INT_GEN_TX_ICR +
  571. offsetof(struct RGF_ICR, IMV));
  572. } else {
  573. icm_rx = wil_ioread32_and_clear(wil->csr +
  574. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  575. offsetof(struct RGF_ICR, ICM));
  576. icr_rx = wil_ioread32_and_clear(wil->csr +
  577. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  578. offsetof(struct RGF_ICR, ICR));
  579. imv_rx = wil_r(wil, RGF_DMA_EP_RX_ICR +
  580. offsetof(struct RGF_ICR, IMV));
  581. icm_tx = wil_ioread32_and_clear(wil->csr +
  582. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  583. offsetof(struct RGF_ICR, ICM));
  584. icr_tx = wil_ioread32_and_clear(wil->csr +
  585. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  586. offsetof(struct RGF_ICR, ICR));
  587. imv_tx = wil_r(wil, RGF_DMA_EP_TX_ICR +
  588. offsetof(struct RGF_ICR, IMV));
  589. }
  590. icm_misc = wil_ioread32_and_clear(wil->csr +
  591. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  592. offsetof(struct RGF_ICR, ICM));
  593. icr_misc = wil_ioread32_and_clear(wil->csr +
  594. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  595. offsetof(struct RGF_ICR, ICR));
  596. imv_misc = wil_r(wil, RGF_DMA_EP_MISC_ICR +
  597. offsetof(struct RGF_ICR, IMV));
  598. /* HALP interrupt can be unmasked when misc interrupts are
  599. * masked
  600. */
  601. if (icr_misc & BIT_DMA_EP_MISC_ICR_HALP)
  602. return 0;
  603. wil_err(wil, "IRQ when it should be masked: pseudo 0x%08x\n"
  604. "Rx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  605. "Tx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  606. "Misc icm:icr:imv 0x%08x 0x%08x 0x%08x\n",
  607. pseudo_cause,
  608. icm_rx, icr_rx, imv_rx,
  609. icm_tx, icr_tx, imv_tx,
  610. icm_misc, icr_misc, imv_misc);
  611. return -EINVAL;
  612. }
  613. return 0;
  614. }
  615. static irqreturn_t wil6210_hardirq(int irq, void *cookie)
  616. {
  617. irqreturn_t rc = IRQ_HANDLED;
  618. struct wil6210_priv *wil = cookie;
  619. u32 pseudo_cause = wil_r(wil, RGF_DMA_PSEUDO_CAUSE);
  620. /**
  621. * pseudo_cause is Clear-On-Read, no need to ACK
  622. */
  623. if (unlikely((pseudo_cause == 0) || ((pseudo_cause & 0xff) == 0xff)))
  624. return IRQ_NONE;
  625. /* IRQ mask debug */
  626. if (unlikely(wil6210_debug_irq_mask(wil, pseudo_cause)))
  627. return IRQ_NONE;
  628. trace_wil6210_irq_pseudo(pseudo_cause);
  629. wil_dbg_irq(wil, "Pseudo IRQ 0x%08x\n", pseudo_cause);
  630. wil6210_mask_irq_pseudo(wil);
  631. /* Discover real IRQ cause
  632. * There are 2 possible phases for every IRQ:
  633. * - hard IRQ handler called right here
  634. * - threaded handler called later
  635. *
  636. * Hard IRQ handler reads and clears ISR.
  637. *
  638. * If threaded handler requested, hard IRQ handler
  639. * returns IRQ_WAKE_THREAD and saves ISR register value
  640. * for the threaded handler use.
  641. *
  642. * voting for wake thread - need at least 1 vote
  643. */
  644. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_RX) &&
  645. (wil->txrx_ops.irq_rx(irq, cookie) == IRQ_WAKE_THREAD))
  646. rc = IRQ_WAKE_THREAD;
  647. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_TX) &&
  648. (wil->txrx_ops.irq_tx(irq, cookie) == IRQ_WAKE_THREAD))
  649. rc = IRQ_WAKE_THREAD;
  650. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_MISC) &&
  651. (wil6210_irq_misc(irq, cookie) == IRQ_WAKE_THREAD))
  652. rc = IRQ_WAKE_THREAD;
  653. /* if thread is requested, it will unmask IRQ */
  654. if (rc != IRQ_WAKE_THREAD)
  655. wil6210_unmask_irq_pseudo(wil);
  656. return rc;
  657. }
  658. static int wil6210_request_3msi(struct wil6210_priv *wil, int irq)
  659. {
  660. int rc;
  661. /* IRQ's are in the following order:
  662. * - Tx
  663. * - Rx
  664. * - Misc
  665. */
  666. rc = request_irq(irq, wil->txrx_ops.irq_tx, IRQF_SHARED,
  667. WIL_NAME "_tx", wil);
  668. if (rc)
  669. return rc;
  670. rc = request_irq(irq + 1, wil->txrx_ops.irq_rx, IRQF_SHARED,
  671. WIL_NAME "_rx", wil);
  672. if (rc)
  673. goto free0;
  674. rc = request_threaded_irq(irq + 2, wil6210_irq_misc,
  675. wil6210_irq_misc_thread,
  676. IRQF_SHARED, WIL_NAME "_misc", wil);
  677. if (rc)
  678. goto free1;
  679. return 0;
  680. free1:
  681. free_irq(irq + 1, wil);
  682. free0:
  683. free_irq(irq, wil);
  684. return rc;
  685. }
  686. /* can't use wil_ioread32_and_clear because ICC value is not set yet */
  687. static inline void wil_clear32(void __iomem *addr)
  688. {
  689. u32 x = readl(addr);
  690. writel(x, addr);
  691. }
  692. void wil6210_clear_irq(struct wil6210_priv *wil)
  693. {
  694. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_RX_ICR) +
  695. offsetof(struct RGF_ICR, ICR));
  696. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_TX_ICR) +
  697. offsetof(struct RGF_ICR, ICR));
  698. wil_clear32(wil->csr + HOSTADDR(RGF_INT_GEN_RX_ICR) +
  699. offsetof(struct RGF_ICR, ICR));
  700. wil_clear32(wil->csr + HOSTADDR(RGF_INT_GEN_TX_ICR) +
  701. offsetof(struct RGF_ICR, ICR));
  702. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  703. offsetof(struct RGF_ICR, ICR));
  704. wmb(); /* make sure write completed */
  705. }
  706. void wil6210_set_halp(struct wil6210_priv *wil)
  707. {
  708. wil_dbg_irq(wil, "set_halp\n");
  709. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICS),
  710. BIT_DMA_EP_MISC_ICR_HALP);
  711. }
  712. void wil6210_clear_halp(struct wil6210_priv *wil)
  713. {
  714. wil_dbg_irq(wil, "clear_halp\n");
  715. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICR),
  716. BIT_DMA_EP_MISC_ICR_HALP);
  717. wil6210_unmask_halp(wil);
  718. }
  719. int wil6210_init_irq(struct wil6210_priv *wil, int irq)
  720. {
  721. int rc;
  722. wil_dbg_misc(wil, "init_irq: %s, n_msi=%d\n",
  723. wil->n_msi ? "MSI" : "INTx", wil->n_msi);
  724. if (wil->use_enhanced_dma_hw) {
  725. wil->txrx_ops.irq_tx = wil6210_irq_tx_edma;
  726. wil->txrx_ops.irq_rx = wil6210_irq_rx_edma;
  727. } else {
  728. wil->txrx_ops.irq_tx = wil6210_irq_tx;
  729. wil->txrx_ops.irq_rx = wil6210_irq_rx;
  730. }
  731. if (wil->n_msi == 3)
  732. rc = wil6210_request_3msi(wil, irq);
  733. else
  734. rc = request_threaded_irq(irq, wil6210_hardirq,
  735. wil6210_thread_irq,
  736. wil->n_msi ? 0 : IRQF_SHARED,
  737. WIL_NAME, wil);
  738. return rc;
  739. }
  740. void wil6210_fini_irq(struct wil6210_priv *wil, int irq)
  741. {
  742. wil_dbg_misc(wil, "fini_irq:\n");
  743. wil_mask_irq(wil);
  744. free_irq(irq, wil);
  745. if (wil->n_msi == 3) {
  746. free_irq(irq + 1, wil);
  747. free_irq(irq + 2, wil);
  748. }
  749. }