interrupt.c 24 KB

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