interrupt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  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;
  249. bool need_unmask = true;
  250. wil6210_mask_irq_rx(wil);
  251. isr = wil_ioread32_and_clear(wil->csr +
  252. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  253. offsetof(struct RGF_ICR, ICR));
  254. trace_wil6210_irq_rx(isr);
  255. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  256. if (unlikely(!isr)) {
  257. wil_err_ratelimited(wil, "spurious IRQ: RX\n");
  258. wil6210_unmask_irq_rx(wil);
  259. return IRQ_NONE;
  260. }
  261. /* RX_DONE and RX_HTRSH interrupts are the same if interrupt
  262. * moderation is not used. Interrupt moderation may cause RX
  263. * buffer overflow while RX_DONE is delayed. The required
  264. * action is always the same - should empty the accumulated
  265. * packets from the RX ring.
  266. */
  267. if (likely(isr & (BIT_DMA_EP_RX_ICR_RX_DONE |
  268. BIT_DMA_EP_RX_ICR_RX_HTRSH))) {
  269. wil_dbg_irq(wil, "RX done / RX_HTRSH received, ISR (0x%x)\n",
  270. isr);
  271. isr &= ~(BIT_DMA_EP_RX_ICR_RX_DONE |
  272. BIT_DMA_EP_RX_ICR_RX_HTRSH);
  273. if (likely(test_bit(wil_status_fwready, wil->status))) {
  274. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  275. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  276. need_unmask = false;
  277. napi_schedule(&wil->napi_rx);
  278. } else {
  279. wil_err_ratelimited(
  280. wil,
  281. "Got Rx interrupt while stopping interface\n");
  282. }
  283. } else {
  284. wil_err_ratelimited(wil, "Got Rx interrupt while in reset\n");
  285. }
  286. }
  287. if (unlikely(isr))
  288. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  289. /* Rx IRQ will be enabled when NAPI processing finished */
  290. atomic_inc(&wil->isr_count_rx);
  291. if (unlikely(need_unmask))
  292. wil6210_unmask_irq_rx(wil);
  293. return IRQ_HANDLED;
  294. }
  295. static irqreturn_t wil6210_irq_rx_edma(int irq, void *cookie)
  296. {
  297. struct wil6210_priv *wil = cookie;
  298. u32 isr;
  299. bool need_unmask = true;
  300. wil6210_mask_irq_rx_edma(wil);
  301. isr = wil_ioread32_and_clear(wil->csr +
  302. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  303. offsetof(struct RGF_ICR, ICR));
  304. trace_wil6210_irq_rx(isr);
  305. wil_dbg_irq(wil, "ISR RX 0x%08x\n", isr);
  306. if (unlikely(!isr)) {
  307. wil_err(wil, "spurious IRQ: RX\n");
  308. wil6210_unmask_irq_rx_edma(wil);
  309. return IRQ_NONE;
  310. }
  311. if (likely(isr & BIT_RX_STATUS_IRQ)) {
  312. wil_dbg_irq(wil, "RX status ring\n");
  313. isr &= ~BIT_RX_STATUS_IRQ;
  314. if (likely(test_bit(wil_status_fwready, wil->status))) {
  315. if (likely(test_bit(wil_status_napi_en, wil->status))) {
  316. wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
  317. need_unmask = false;
  318. napi_schedule(&wil->napi_rx);
  319. } else {
  320. wil_err(wil,
  321. "Got Rx interrupt while stopping interface\n");
  322. }
  323. } else {
  324. wil_err(wil, "Got Rx interrupt while in reset\n");
  325. }
  326. }
  327. if (unlikely(isr))
  328. wil_err(wil, "un-handled RX ISR bits 0x%08x\n", isr);
  329. /* Rx IRQ will be enabled when NAPI processing finished */
  330. atomic_inc(&wil->isr_count_rx);
  331. if (unlikely(need_unmask))
  332. wil6210_unmask_irq_rx_edma(wil);
  333. return IRQ_HANDLED;
  334. }
  335. static irqreturn_t wil6210_irq_tx_edma(int irq, void *cookie)
  336. {
  337. struct wil6210_priv *wil = cookie;
  338. u32 isr;
  339. bool need_unmask = true;
  340. wil6210_mask_irq_tx_edma(wil);
  341. isr = wil_ioread32_and_clear(wil->csr +
  342. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  343. offsetof(struct RGF_ICR, ICR));
  344. trace_wil6210_irq_tx(isr);
  345. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  346. if (unlikely(!isr)) {
  347. wil_err(wil, "spurious IRQ: TX\n");
  348. wil6210_unmask_irq_tx_edma(wil);
  349. return IRQ_NONE;
  350. }
  351. if (likely(isr & BIT_TX_STATUS_IRQ)) {
  352. wil_dbg_irq(wil, "TX status ring\n");
  353. isr &= ~BIT_TX_STATUS_IRQ;
  354. if (likely(test_bit(wil_status_fwready, wil->status))) {
  355. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  356. need_unmask = false;
  357. napi_schedule(&wil->napi_tx);
  358. } else {
  359. wil_err(wil, "Got Tx status ring IRQ while in reset\n");
  360. }
  361. }
  362. if (unlikely(isr))
  363. wil_err(wil, "un-handled TX ISR bits 0x%08x\n", isr);
  364. /* Tx IRQ will be enabled when NAPI processing finished */
  365. atomic_inc(&wil->isr_count_tx);
  366. if (unlikely(need_unmask))
  367. wil6210_unmask_irq_tx_edma(wil);
  368. return IRQ_HANDLED;
  369. }
  370. static irqreturn_t wil6210_irq_tx(int irq, void *cookie)
  371. {
  372. struct wil6210_priv *wil = cookie;
  373. u32 isr;
  374. bool need_unmask = true;
  375. wil6210_mask_irq_tx(wil);
  376. isr = wil_ioread32_and_clear(wil->csr +
  377. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  378. offsetof(struct RGF_ICR, ICR));
  379. trace_wil6210_irq_tx(isr);
  380. wil_dbg_irq(wil, "ISR TX 0x%08x\n", isr);
  381. if (unlikely(!isr)) {
  382. wil_err_ratelimited(wil, "spurious IRQ: TX\n");
  383. wil6210_unmask_irq_tx(wil);
  384. return IRQ_NONE;
  385. }
  386. if (likely(isr & BIT_DMA_EP_TX_ICR_TX_DONE)) {
  387. wil_dbg_irq(wil, "TX done\n");
  388. isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE;
  389. /* clear also all VRING interrupts */
  390. isr &= ~(BIT(25) - 1UL);
  391. if (likely(test_bit(wil_status_fwready, wil->status))) {
  392. wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
  393. need_unmask = false;
  394. napi_schedule(&wil->napi_tx);
  395. } else {
  396. wil_err_ratelimited(wil, "Got Tx interrupt while in reset\n");
  397. }
  398. }
  399. if (unlikely(isr))
  400. wil_err_ratelimited(wil, "un-handled TX ISR bits 0x%08x\n",
  401. isr);
  402. /* Tx IRQ will be enabled when NAPI processing finished */
  403. atomic_inc(&wil->isr_count_tx);
  404. if (unlikely(need_unmask))
  405. wil6210_unmask_irq_tx(wil);
  406. return IRQ_HANDLED;
  407. }
  408. static void wil_notify_fw_error(struct wil6210_priv *wil)
  409. {
  410. struct device *dev = &wil->main_ndev->dev;
  411. char *envp[3] = {
  412. [0] = "SOURCE=wil6210",
  413. [1] = "EVENT=FW_ERROR",
  414. [2] = NULL,
  415. };
  416. wil_err(wil, "Notify about firmware error\n");
  417. kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
  418. }
  419. static void wil_cache_mbox_regs(struct wil6210_priv *wil)
  420. {
  421. /* make shadow copy of registers that should not change on run time */
  422. wil_memcpy_fromio_32(&wil->mbox_ctl, wil->csr + HOST_MBOX,
  423. sizeof(struct wil6210_mbox_ctl));
  424. wil_mbox_ring_le2cpus(&wil->mbox_ctl.rx);
  425. wil_mbox_ring_le2cpus(&wil->mbox_ctl.tx);
  426. }
  427. static bool wil_validate_mbox_regs(struct wil6210_priv *wil)
  428. {
  429. size_t min_size = sizeof(struct wil6210_mbox_hdr) +
  430. sizeof(struct wmi_cmd_hdr);
  431. if (wil->mbox_ctl.rx.entry_size < min_size) {
  432. wil_err(wil, "rx mbox entry too small (%d)\n",
  433. wil->mbox_ctl.rx.entry_size);
  434. return false;
  435. }
  436. if (wil->mbox_ctl.tx.entry_size < min_size) {
  437. wil_err(wil, "tx mbox entry too small (%d)\n",
  438. wil->mbox_ctl.tx.entry_size);
  439. return false;
  440. }
  441. return true;
  442. }
  443. static irqreturn_t wil6210_irq_misc(int irq, void *cookie)
  444. {
  445. struct wil6210_priv *wil = cookie;
  446. u32 isr;
  447. wil6210_mask_irq_misc(wil, false);
  448. isr = wil_ioread32_and_clear(wil->csr +
  449. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  450. offsetof(struct RGF_ICR, ICR));
  451. trace_wil6210_irq_misc(isr);
  452. wil_dbg_irq(wil, "ISR MISC 0x%08x\n", isr);
  453. if (!isr) {
  454. wil_err(wil, "spurious IRQ: MISC\n");
  455. wil6210_unmask_irq_misc(wil, false);
  456. return IRQ_NONE;
  457. }
  458. if (isr & ISR_MISC_FW_ERROR) {
  459. u32 fw_assert_code = wil_r(wil, wil->rgf_fw_assert_code_addr);
  460. u32 ucode_assert_code =
  461. wil_r(wil, wil->rgf_ucode_assert_code_addr);
  462. wil_err(wil,
  463. "Firmware error detected, assert codes FW 0x%08x, UCODE 0x%08x\n",
  464. fw_assert_code, ucode_assert_code);
  465. clear_bit(wil_status_fwready, wil->status);
  466. /*
  467. * do not clear @isr here - we do 2-nd part in thread
  468. * there, user space get notified, and it should be done
  469. * in non-atomic context
  470. */
  471. }
  472. if (isr & ISR_MISC_FW_READY) {
  473. wil_dbg_irq(wil, "IRQ: FW ready\n");
  474. wil_cache_mbox_regs(wil);
  475. if (wil_validate_mbox_regs(wil))
  476. set_bit(wil_status_mbox_ready, wil->status);
  477. /**
  478. * Actual FW ready indicated by the
  479. * WMI_FW_READY_EVENTID
  480. */
  481. isr &= ~ISR_MISC_FW_READY;
  482. }
  483. if (isr & BIT_DMA_EP_MISC_ICR_HALP) {
  484. wil_dbg_irq(wil, "irq_misc: HALP IRQ invoked\n");
  485. wil6210_mask_halp(wil);
  486. isr &= ~BIT_DMA_EP_MISC_ICR_HALP;
  487. complete(&wil->halp.comp);
  488. }
  489. wil->isr_misc = isr;
  490. if (isr) {
  491. return IRQ_WAKE_THREAD;
  492. } else {
  493. wil6210_unmask_irq_misc(wil, false);
  494. return IRQ_HANDLED;
  495. }
  496. }
  497. static irqreturn_t wil6210_irq_misc_thread(int irq, void *cookie)
  498. {
  499. struct wil6210_priv *wil = cookie;
  500. u32 isr = wil->isr_misc;
  501. trace_wil6210_irq_misc_thread(isr);
  502. wil_dbg_irq(wil, "Thread ISR MISC 0x%08x\n", isr);
  503. if (isr & ISR_MISC_FW_ERROR) {
  504. wil->recovery_state = fw_recovery_pending;
  505. wil_fw_core_dump(wil);
  506. wil_notify_fw_error(wil);
  507. isr &= ~ISR_MISC_FW_ERROR;
  508. if (wil->platform_ops.notify) {
  509. wil_err(wil, "notify platform driver about FW crash");
  510. wil->platform_ops.notify(wil->platform_handle,
  511. WIL_PLATFORM_EVT_FW_CRASH);
  512. } else {
  513. wil_fw_error_recovery(wil);
  514. }
  515. }
  516. if (isr & ISR_MISC_MBOX_EVT) {
  517. wil_dbg_irq(wil, "MBOX event\n");
  518. wmi_recv_cmd(wil);
  519. isr &= ~ISR_MISC_MBOX_EVT;
  520. }
  521. if (isr)
  522. wil_dbg_irq(wil, "un-handled MISC ISR bits 0x%08x\n", isr);
  523. wil->isr_misc = 0;
  524. wil6210_unmask_irq_misc(wil, false);
  525. /* in non-triple MSI case, this is done inside wil6210_thread_irq
  526. * because it has to be done after unmasking the pseudo.
  527. */
  528. if (wil->n_msi == 3 && wil->suspend_resp_rcvd) {
  529. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  530. wil->suspend_resp_comp = true;
  531. wake_up_interruptible(&wil->wq);
  532. }
  533. return IRQ_HANDLED;
  534. }
  535. /**
  536. * thread IRQ handler
  537. */
  538. static irqreturn_t wil6210_thread_irq(int irq, void *cookie)
  539. {
  540. struct wil6210_priv *wil = cookie;
  541. wil_dbg_irq(wil, "Thread IRQ\n");
  542. /* Discover real IRQ cause */
  543. if (wil->isr_misc)
  544. wil6210_irq_misc_thread(irq, cookie);
  545. wil6210_unmask_irq_pseudo(wil);
  546. if (wil->suspend_resp_rcvd) {
  547. wil_dbg_irq(wil, "set suspend_resp_comp to true\n");
  548. wil->suspend_resp_comp = true;
  549. wake_up_interruptible(&wil->wq);
  550. }
  551. return IRQ_HANDLED;
  552. }
  553. /* DEBUG
  554. * There is subtle bug in hardware that causes IRQ to raise when it should be
  555. * masked. It is quite rare and hard to debug.
  556. *
  557. * Catch irq issue if it happens and print all I can.
  558. */
  559. static int wil6210_debug_irq_mask(struct wil6210_priv *wil, u32 pseudo_cause)
  560. {
  561. u32 icm_rx, icr_rx, imv_rx;
  562. u32 icm_tx, icr_tx, imv_tx;
  563. u32 icm_misc, icr_misc, imv_misc;
  564. if (!test_bit(wil_status_irqen, wil->status)) {
  565. if (wil->use_enhanced_dma_hw) {
  566. icm_rx = wil_ioread32_and_clear(wil->csr +
  567. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  568. offsetof(struct RGF_ICR, ICM));
  569. icr_rx = wil_ioread32_and_clear(wil->csr +
  570. HOSTADDR(RGF_INT_GEN_RX_ICR) +
  571. offsetof(struct RGF_ICR, ICR));
  572. imv_rx = wil_r(wil, RGF_INT_GEN_RX_ICR +
  573. offsetof(struct RGF_ICR, IMV));
  574. icm_tx = wil_ioread32_and_clear(wil->csr +
  575. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  576. offsetof(struct RGF_ICR, ICM));
  577. icr_tx = wil_ioread32_and_clear(wil->csr +
  578. HOSTADDR(RGF_INT_GEN_TX_ICR) +
  579. offsetof(struct RGF_ICR, ICR));
  580. imv_tx = wil_r(wil, RGF_INT_GEN_TX_ICR +
  581. offsetof(struct RGF_ICR, IMV));
  582. } else {
  583. icm_rx = wil_ioread32_and_clear(wil->csr +
  584. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  585. offsetof(struct RGF_ICR, ICM));
  586. icr_rx = wil_ioread32_and_clear(wil->csr +
  587. HOSTADDR(RGF_DMA_EP_RX_ICR) +
  588. offsetof(struct RGF_ICR, ICR));
  589. imv_rx = wil_r(wil, RGF_DMA_EP_RX_ICR +
  590. offsetof(struct RGF_ICR, IMV));
  591. icm_tx = wil_ioread32_and_clear(wil->csr +
  592. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  593. offsetof(struct RGF_ICR, ICM));
  594. icr_tx = wil_ioread32_and_clear(wil->csr +
  595. HOSTADDR(RGF_DMA_EP_TX_ICR) +
  596. offsetof(struct RGF_ICR, ICR));
  597. imv_tx = wil_r(wil, RGF_DMA_EP_TX_ICR +
  598. offsetof(struct RGF_ICR, IMV));
  599. }
  600. icm_misc = wil_ioread32_and_clear(wil->csr +
  601. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  602. offsetof(struct RGF_ICR, ICM));
  603. icr_misc = wil_ioread32_and_clear(wil->csr +
  604. HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  605. offsetof(struct RGF_ICR, ICR));
  606. imv_misc = wil_r(wil, RGF_DMA_EP_MISC_ICR +
  607. offsetof(struct RGF_ICR, IMV));
  608. /* HALP interrupt can be unmasked when misc interrupts are
  609. * masked
  610. */
  611. if (icr_misc & BIT_DMA_EP_MISC_ICR_HALP)
  612. return 0;
  613. wil_err(wil, "IRQ when it should be masked: pseudo 0x%08x\n"
  614. "Rx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  615. "Tx icm:icr:imv 0x%08x 0x%08x 0x%08x\n"
  616. "Misc icm:icr:imv 0x%08x 0x%08x 0x%08x\n",
  617. pseudo_cause,
  618. icm_rx, icr_rx, imv_rx,
  619. icm_tx, icr_tx, imv_tx,
  620. icm_misc, icr_misc, imv_misc);
  621. return -EINVAL;
  622. }
  623. return 0;
  624. }
  625. static irqreturn_t wil6210_hardirq(int irq, void *cookie)
  626. {
  627. irqreturn_t rc = IRQ_HANDLED;
  628. struct wil6210_priv *wil = cookie;
  629. u32 pseudo_cause = wil_r(wil, RGF_DMA_PSEUDO_CAUSE);
  630. /**
  631. * pseudo_cause is Clear-On-Read, no need to ACK
  632. */
  633. if (unlikely((pseudo_cause == 0) || ((pseudo_cause & 0xff) == 0xff)))
  634. return IRQ_NONE;
  635. /* IRQ mask debug */
  636. if (unlikely(wil6210_debug_irq_mask(wil, pseudo_cause)))
  637. return IRQ_NONE;
  638. trace_wil6210_irq_pseudo(pseudo_cause);
  639. wil_dbg_irq(wil, "Pseudo IRQ 0x%08x\n", pseudo_cause);
  640. wil6210_mask_irq_pseudo(wil);
  641. /* Discover real IRQ cause
  642. * There are 2 possible phases for every IRQ:
  643. * - hard IRQ handler called right here
  644. * - threaded handler called later
  645. *
  646. * Hard IRQ handler reads and clears ISR.
  647. *
  648. * If threaded handler requested, hard IRQ handler
  649. * returns IRQ_WAKE_THREAD and saves ISR register value
  650. * for the threaded handler use.
  651. *
  652. * voting for wake thread - need at least 1 vote
  653. */
  654. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_RX) &&
  655. (wil->txrx_ops.irq_rx(irq, cookie) == IRQ_WAKE_THREAD))
  656. rc = IRQ_WAKE_THREAD;
  657. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_TX) &&
  658. (wil->txrx_ops.irq_tx(irq, cookie) == IRQ_WAKE_THREAD))
  659. rc = IRQ_WAKE_THREAD;
  660. if ((pseudo_cause & BIT_DMA_PSEUDO_CAUSE_MISC) &&
  661. (wil6210_irq_misc(irq, cookie) == IRQ_WAKE_THREAD))
  662. rc = IRQ_WAKE_THREAD;
  663. /* if thread is requested, it will unmask IRQ */
  664. if (rc != IRQ_WAKE_THREAD)
  665. wil6210_unmask_irq_pseudo(wil);
  666. return rc;
  667. }
  668. static int wil6210_request_3msi(struct wil6210_priv *wil, int irq)
  669. {
  670. int rc;
  671. /* IRQ's are in the following order:
  672. * - Tx
  673. * - Rx
  674. * - Misc
  675. */
  676. rc = request_irq(irq, wil->txrx_ops.irq_tx, IRQF_SHARED,
  677. WIL_NAME "_tx", wil);
  678. if (rc)
  679. return rc;
  680. rc = request_irq(irq + 1, wil->txrx_ops.irq_rx, IRQF_SHARED,
  681. WIL_NAME "_rx", wil);
  682. if (rc)
  683. goto free0;
  684. rc = request_threaded_irq(irq + 2, wil6210_irq_misc,
  685. wil6210_irq_misc_thread,
  686. IRQF_SHARED, WIL_NAME "_misc", wil);
  687. if (rc)
  688. goto free1;
  689. return 0;
  690. free1:
  691. free_irq(irq + 1, wil);
  692. free0:
  693. free_irq(irq, wil);
  694. return rc;
  695. }
  696. /* can't use wil_ioread32_and_clear because ICC value is not set yet */
  697. static inline void wil_clear32(void __iomem *addr)
  698. {
  699. u32 x = readl(addr);
  700. writel(x, addr);
  701. }
  702. void wil6210_clear_irq(struct wil6210_priv *wil)
  703. {
  704. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_RX_ICR) +
  705. offsetof(struct RGF_ICR, ICR));
  706. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_TX_ICR) +
  707. offsetof(struct RGF_ICR, ICR));
  708. wil_clear32(wil->csr + HOSTADDR(RGF_INT_GEN_RX_ICR) +
  709. offsetof(struct RGF_ICR, ICR));
  710. wil_clear32(wil->csr + HOSTADDR(RGF_INT_GEN_TX_ICR) +
  711. offsetof(struct RGF_ICR, ICR));
  712. wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_MISC_ICR) +
  713. offsetof(struct RGF_ICR, ICR));
  714. wmb(); /* make sure write completed */
  715. }
  716. void wil6210_set_halp(struct wil6210_priv *wil)
  717. {
  718. wil_dbg_irq(wil, "set_halp\n");
  719. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICS),
  720. BIT_DMA_EP_MISC_ICR_HALP);
  721. }
  722. void wil6210_clear_halp(struct wil6210_priv *wil)
  723. {
  724. wil_dbg_irq(wil, "clear_halp\n");
  725. wil_w(wil, RGF_DMA_EP_MISC_ICR + offsetof(struct RGF_ICR, ICR),
  726. BIT_DMA_EP_MISC_ICR_HALP);
  727. wil6210_unmask_halp(wil);
  728. }
  729. int wil6210_init_irq(struct wil6210_priv *wil, int irq)
  730. {
  731. int rc;
  732. wil_dbg_misc(wil, "init_irq: %s, n_msi=%d\n",
  733. wil->n_msi ? "MSI" : "INTx", wil->n_msi);
  734. if (wil->use_enhanced_dma_hw) {
  735. wil->txrx_ops.irq_tx = wil6210_irq_tx_edma;
  736. wil->txrx_ops.irq_rx = wil6210_irq_rx_edma;
  737. } else {
  738. wil->txrx_ops.irq_tx = wil6210_irq_tx;
  739. wil->txrx_ops.irq_rx = wil6210_irq_rx;
  740. }
  741. if (wil->n_msi == 3)
  742. rc = wil6210_request_3msi(wil, irq);
  743. else
  744. rc = request_threaded_irq(irq, wil6210_hardirq,
  745. wil6210_thread_irq,
  746. wil->n_msi ? 0 : IRQF_SHARED,
  747. WIL_NAME, wil);
  748. return rc;
  749. }
  750. void wil6210_fini_irq(struct wil6210_priv *wil, int irq)
  751. {
  752. wil_dbg_misc(wil, "fini_irq:\n");
  753. wil_mask_irq(wil);
  754. free_irq(irq, wil);
  755. if (wil->n_msi == 3) {
  756. free_irq(irq + 1, wil);
  757. free_irq(irq + 2, wil);
  758. }
  759. }