hif.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * Copyright (c) 2007-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  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 "hif.h"
  18. #include <linux/export.h>
  19. #include "core.h"
  20. #include "target.h"
  21. #include "hif-ops.h"
  22. #include "debug.h"
  23. #include "trace.h"
  24. #define MAILBOX_FOR_BLOCK_SIZE 1
  25. #define ATH6KL_TIME_QUANTUM 10 /* in ms */
  26. static int ath6kl_hif_cp_scat_dma_buf(struct hif_scatter_req *req,
  27. bool from_dma)
  28. {
  29. u8 *buf;
  30. int i;
  31. buf = req->virt_dma_buf;
  32. for (i = 0; i < req->scat_entries; i++) {
  33. if (from_dma)
  34. memcpy(req->scat_list[i].buf, buf,
  35. req->scat_list[i].len);
  36. else
  37. memcpy(buf, req->scat_list[i].buf,
  38. req->scat_list[i].len);
  39. buf += req->scat_list[i].len;
  40. }
  41. return 0;
  42. }
  43. int ath6kl_hif_rw_comp_handler(void *context, int status)
  44. {
  45. struct htc_packet *packet = context;
  46. ath6kl_dbg(ATH6KL_DBG_HIF, "hif rw completion pkt 0x%p status %d\n",
  47. packet, status);
  48. packet->status = status;
  49. packet->completion(packet->context, packet);
  50. return 0;
  51. }
  52. EXPORT_SYMBOL(ath6kl_hif_rw_comp_handler);
  53. #define REGISTER_DUMP_COUNT 60
  54. #define REGISTER_DUMP_LEN_MAX 60
  55. static void ath6kl_hif_dump_fw_crash(struct ath6kl *ar)
  56. {
  57. __le32 regdump_val[REGISTER_DUMP_LEN_MAX];
  58. u32 i, address, regdump_addr = 0;
  59. int ret;
  60. /* the reg dump pointer is copied to the host interest area */
  61. address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
  62. address = TARG_VTOP(ar->target_type, address);
  63. /* read RAM location through diagnostic window */
  64. ret = ath6kl_diag_read32(ar, address, &regdump_addr);
  65. if (ret || !regdump_addr) {
  66. ath6kl_warn("failed to get ptr to register dump area: %d\n",
  67. ret);
  68. return;
  69. }
  70. ath6kl_dbg(ATH6KL_DBG_IRQ, "register dump data address 0x%x\n",
  71. regdump_addr);
  72. regdump_addr = TARG_VTOP(ar->target_type, regdump_addr);
  73. /* fetch register dump data */
  74. ret = ath6kl_diag_read(ar, regdump_addr, (u8 *)&regdump_val[0],
  75. REGISTER_DUMP_COUNT * (sizeof(u32)));
  76. if (ret) {
  77. ath6kl_warn("failed to get register dump: %d\n", ret);
  78. return;
  79. }
  80. ath6kl_info("crash dump:\n");
  81. ath6kl_info("hw 0x%x fw %s\n", ar->wiphy->hw_version,
  82. ar->wiphy->fw_version);
  83. BUILD_BUG_ON(REGISTER_DUMP_COUNT % 4);
  84. for (i = 0; i < REGISTER_DUMP_COUNT; i += 4) {
  85. ath6kl_info("%d: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x\n",
  86. i,
  87. le32_to_cpu(regdump_val[i]),
  88. le32_to_cpu(regdump_val[i + 1]),
  89. le32_to_cpu(regdump_val[i + 2]),
  90. le32_to_cpu(regdump_val[i + 3]));
  91. }
  92. }
  93. static int ath6kl_hif_proc_dbg_intr(struct ath6kl_device *dev)
  94. {
  95. u32 dummy;
  96. int ret;
  97. ath6kl_warn("firmware crashed\n");
  98. /*
  99. * read counter to clear the interrupt, the debug error interrupt is
  100. * counter 0.
  101. */
  102. ret = hif_read_write_sync(dev->ar, COUNT_DEC_ADDRESS,
  103. (u8 *)&dummy, 4, HIF_RD_SYNC_BYTE_INC);
  104. if (ret)
  105. ath6kl_warn("Failed to clear debug interrupt: %d\n", ret);
  106. ath6kl_hif_dump_fw_crash(dev->ar);
  107. ath6kl_read_fwlogs(dev->ar);
  108. ath6kl_recovery_err_notify(dev->ar, ATH6KL_FW_ASSERT);
  109. return ret;
  110. }
  111. /* mailbox recv message polling */
  112. int ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev, u32 *lk_ahd,
  113. int timeout)
  114. {
  115. struct ath6kl_irq_proc_registers *rg;
  116. int status = 0, i;
  117. u8 htc_mbox = 1 << HTC_MAILBOX;
  118. for (i = timeout / ATH6KL_TIME_QUANTUM; i > 0; i--) {
  119. /* this is the standard HIF way, load the reg table */
  120. status = hif_read_write_sync(dev->ar, HOST_INT_STATUS_ADDRESS,
  121. (u8 *) &dev->irq_proc_reg,
  122. sizeof(dev->irq_proc_reg),
  123. HIF_RD_SYNC_BYTE_INC);
  124. if (status) {
  125. ath6kl_err("failed to read reg table\n");
  126. return status;
  127. }
  128. /* check for MBOX data and valid lookahead */
  129. if (dev->irq_proc_reg.host_int_status & htc_mbox) {
  130. if (dev->irq_proc_reg.rx_lkahd_valid &
  131. htc_mbox) {
  132. /*
  133. * Mailbox has a message and the look ahead
  134. * is valid.
  135. */
  136. rg = &dev->irq_proc_reg;
  137. *lk_ahd =
  138. le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
  139. break;
  140. }
  141. }
  142. /* delay a little */
  143. mdelay(ATH6KL_TIME_QUANTUM);
  144. ath6kl_dbg(ATH6KL_DBG_HIF, "hif retry mbox poll try %d\n", i);
  145. }
  146. if (i == 0) {
  147. ath6kl_err("timeout waiting for recv message\n");
  148. status = -ETIME;
  149. /* check if the target asserted */
  150. if (dev->irq_proc_reg.counter_int_status &
  151. ATH6KL_TARGET_DEBUG_INTR_MASK)
  152. /*
  153. * Target failure handler will be called in case of
  154. * an assert.
  155. */
  156. ath6kl_hif_proc_dbg_intr(dev);
  157. }
  158. return status;
  159. }
  160. /*
  161. * Disable packet reception (used in case the host runs out of buffers)
  162. * using the interrupt enable registers through the host I/F
  163. */
  164. int ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx)
  165. {
  166. struct ath6kl_irq_enable_reg regs;
  167. int status = 0;
  168. ath6kl_dbg(ATH6KL_DBG_HIF, "hif rx %s\n",
  169. enable_rx ? "enable" : "disable");
  170. /* take the lock to protect interrupt enable shadows */
  171. spin_lock_bh(&dev->lock);
  172. if (enable_rx)
  173. dev->irq_en_reg.int_status_en |=
  174. SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
  175. else
  176. dev->irq_en_reg.int_status_en &=
  177. ~SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
  178. memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
  179. spin_unlock_bh(&dev->lock);
  180. status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
  181. &regs.int_status_en,
  182. sizeof(struct ath6kl_irq_enable_reg),
  183. HIF_WR_SYNC_BYTE_INC);
  184. return status;
  185. }
  186. int ath6kl_hif_submit_scat_req(struct ath6kl_device *dev,
  187. struct hif_scatter_req *scat_req, bool read)
  188. {
  189. int status = 0;
  190. if (read) {
  191. scat_req->req = HIF_RD_SYNC_BLOCK_FIX;
  192. scat_req->addr = dev->ar->mbox_info.htc_addr;
  193. } else {
  194. scat_req->req = HIF_WR_ASYNC_BLOCK_INC;
  195. scat_req->addr =
  196. (scat_req->len > HIF_MBOX_WIDTH) ?
  197. dev->ar->mbox_info.htc_ext_addr :
  198. dev->ar->mbox_info.htc_addr;
  199. }
  200. ath6kl_dbg(ATH6KL_DBG_HIF,
  201. "hif submit scatter request entries %d len %d mbox 0x%x %s %s\n",
  202. scat_req->scat_entries, scat_req->len,
  203. scat_req->addr, !read ? "async" : "sync",
  204. (read) ? "rd" : "wr");
  205. if (!read && scat_req->virt_scat) {
  206. status = ath6kl_hif_cp_scat_dma_buf(scat_req, false);
  207. if (status) {
  208. scat_req->status = status;
  209. scat_req->complete(dev->ar->htc_target, scat_req);
  210. return 0;
  211. }
  212. }
  213. status = ath6kl_hif_scat_req_rw(dev->ar, scat_req);
  214. if (read) {
  215. /* in sync mode, we can touch the scatter request */
  216. scat_req->status = status;
  217. if (!status && scat_req->virt_scat)
  218. scat_req->status =
  219. ath6kl_hif_cp_scat_dma_buf(scat_req, true);
  220. }
  221. return status;
  222. }
  223. static int ath6kl_hif_proc_counter_intr(struct ath6kl_device *dev)
  224. {
  225. u8 counter_int_status;
  226. ath6kl_dbg(ATH6KL_DBG_IRQ, "counter interrupt\n");
  227. counter_int_status = dev->irq_proc_reg.counter_int_status &
  228. dev->irq_en_reg.cntr_int_status_en;
  229. ath6kl_dbg(ATH6KL_DBG_IRQ,
  230. "valid interrupt source(s) in COUNTER_INT_STATUS: 0x%x\n",
  231. counter_int_status);
  232. /*
  233. * NOTE: other modules like GMBOX may use the counter interrupt for
  234. * credit flow control on other counters, we only need to check for
  235. * the debug assertion counter interrupt.
  236. */
  237. if (counter_int_status & ATH6KL_TARGET_DEBUG_INTR_MASK)
  238. return ath6kl_hif_proc_dbg_intr(dev);
  239. return 0;
  240. }
  241. static int ath6kl_hif_proc_err_intr(struct ath6kl_device *dev)
  242. {
  243. int status;
  244. u8 error_int_status;
  245. u8 reg_buf[4];
  246. ath6kl_dbg(ATH6KL_DBG_IRQ, "error interrupt\n");
  247. error_int_status = dev->irq_proc_reg.error_int_status & 0x0F;
  248. if (!error_int_status) {
  249. WARN_ON(1);
  250. return -EIO;
  251. }
  252. ath6kl_dbg(ATH6KL_DBG_IRQ,
  253. "valid interrupt source(s) in ERROR_INT_STATUS: 0x%x\n",
  254. error_int_status);
  255. if (MS(ERROR_INT_STATUS_WAKEUP, error_int_status))
  256. ath6kl_dbg(ATH6KL_DBG_IRQ, "error : wakeup\n");
  257. if (MS(ERROR_INT_STATUS_RX_UNDERFLOW, error_int_status))
  258. ath6kl_err("rx underflow\n");
  259. if (MS(ERROR_INT_STATUS_TX_OVERFLOW, error_int_status))
  260. ath6kl_err("tx overflow\n");
  261. /* Clear the interrupt */
  262. dev->irq_proc_reg.error_int_status &= ~error_int_status;
  263. /* set W1C value to clear the interrupt, this hits the register first */
  264. reg_buf[0] = error_int_status;
  265. reg_buf[1] = 0;
  266. reg_buf[2] = 0;
  267. reg_buf[3] = 0;
  268. status = hif_read_write_sync(dev->ar, ERROR_INT_STATUS_ADDRESS,
  269. reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
  270. WARN_ON(status);
  271. return status;
  272. }
  273. static int ath6kl_hif_proc_cpu_intr(struct ath6kl_device *dev)
  274. {
  275. int status;
  276. u8 cpu_int_status;
  277. u8 reg_buf[4];
  278. ath6kl_dbg(ATH6KL_DBG_IRQ, "cpu interrupt\n");
  279. cpu_int_status = dev->irq_proc_reg.cpu_int_status &
  280. dev->irq_en_reg.cpu_int_status_en;
  281. if (!cpu_int_status) {
  282. WARN_ON(1);
  283. return -EIO;
  284. }
  285. ath6kl_dbg(ATH6KL_DBG_IRQ,
  286. "valid interrupt source(s) in CPU_INT_STATUS: 0x%x\n",
  287. cpu_int_status);
  288. /* Clear the interrupt */
  289. dev->irq_proc_reg.cpu_int_status &= ~cpu_int_status;
  290. /*
  291. * Set up the register transfer buffer to hit the register 4 times ,
  292. * this is done to make the access 4-byte aligned to mitigate issues
  293. * with host bus interconnects that restrict bus transfer lengths to
  294. * be a multiple of 4-bytes.
  295. */
  296. /* set W1C value to clear the interrupt, this hits the register first */
  297. reg_buf[0] = cpu_int_status;
  298. /* the remaining are set to zero which have no-effect */
  299. reg_buf[1] = 0;
  300. reg_buf[2] = 0;
  301. reg_buf[3] = 0;
  302. status = hif_read_write_sync(dev->ar, CPU_INT_STATUS_ADDRESS,
  303. reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
  304. WARN_ON(status);
  305. return status;
  306. }
  307. /* process pending interrupts synchronously */
  308. static int proc_pending_irqs(struct ath6kl_device *dev, bool *done)
  309. {
  310. struct ath6kl_irq_proc_registers *rg;
  311. int status = 0;
  312. u8 host_int_status = 0;
  313. u32 lk_ahd = 0;
  314. u8 htc_mbox = 1 << HTC_MAILBOX;
  315. ath6kl_dbg(ATH6KL_DBG_IRQ, "proc_pending_irqs: (dev: 0x%p)\n", dev);
  316. /*
  317. * NOTE: HIF implementation guarantees that the context of this
  318. * call allows us to perform SYNCHRONOUS I/O, that is we can block,
  319. * sleep or call any API that can block or switch thread/task
  320. * contexts. This is a fully schedulable context.
  321. */
  322. /*
  323. * Process pending intr only when int_status_en is clear, it may
  324. * result in unnecessary bus transaction otherwise. Target may be
  325. * unresponsive at the time.
  326. */
  327. if (dev->irq_en_reg.int_status_en) {
  328. /*
  329. * Read the first 28 bytes of the HTC register table. This
  330. * will yield us the value of different int status
  331. * registers and the lookahead registers.
  332. *
  333. * length = sizeof(int_status) + sizeof(cpu_int_status)
  334. * + sizeof(error_int_status) +
  335. * sizeof(counter_int_status) +
  336. * sizeof(mbox_frame) + sizeof(rx_lkahd_valid)
  337. * + sizeof(hole) + sizeof(rx_lkahd) +
  338. * sizeof(int_status_en) +
  339. * sizeof(cpu_int_status_en) +
  340. * sizeof(err_int_status_en) +
  341. * sizeof(cntr_int_status_en);
  342. */
  343. status = hif_read_write_sync(dev->ar, HOST_INT_STATUS_ADDRESS,
  344. (u8 *) &dev->irq_proc_reg,
  345. sizeof(dev->irq_proc_reg),
  346. HIF_RD_SYNC_BYTE_INC);
  347. if (status)
  348. goto out;
  349. ath6kl_dump_registers(dev, &dev->irq_proc_reg,
  350. &dev->irq_en_reg);
  351. trace_ath6kl_sdio_irq(&dev->irq_en_reg,
  352. sizeof(dev->irq_en_reg));
  353. /* Update only those registers that are enabled */
  354. host_int_status = dev->irq_proc_reg.host_int_status &
  355. dev->irq_en_reg.int_status_en;
  356. /* Look at mbox status */
  357. if (host_int_status & htc_mbox) {
  358. /*
  359. * Mask out pending mbox value, we use "lookAhead as
  360. * the real flag for mbox processing.
  361. */
  362. host_int_status &= ~htc_mbox;
  363. if (dev->irq_proc_reg.rx_lkahd_valid &
  364. htc_mbox) {
  365. rg = &dev->irq_proc_reg;
  366. lk_ahd = le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
  367. if (!lk_ahd)
  368. ath6kl_err("lookAhead is zero!\n");
  369. }
  370. }
  371. }
  372. if (!host_int_status && !lk_ahd) {
  373. *done = true;
  374. goto out;
  375. }
  376. if (lk_ahd) {
  377. int fetched = 0;
  378. ath6kl_dbg(ATH6KL_DBG_IRQ,
  379. "pending mailbox msg, lk_ahd: 0x%X\n", lk_ahd);
  380. /*
  381. * Mailbox Interrupt, the HTC layer may issue async
  382. * requests to empty the mailbox. When emptying the recv
  383. * mailbox we use the async handler above called from the
  384. * completion routine of the callers read request. This can
  385. * improve performance by reducing context switching when
  386. * we rapidly pull packets.
  387. */
  388. status = ath6kl_htc_rxmsg_pending_handler(dev->htc_cnxt,
  389. lk_ahd, &fetched);
  390. if (status)
  391. goto out;
  392. if (!fetched)
  393. /*
  394. * HTC could not pull any messages out due to lack
  395. * of resources.
  396. */
  397. dev->htc_cnxt->chk_irq_status_cnt = 0;
  398. }
  399. /* now handle the rest of them */
  400. ath6kl_dbg(ATH6KL_DBG_IRQ,
  401. "valid interrupt source(s) for other interrupts: 0x%x\n",
  402. host_int_status);
  403. if (MS(HOST_INT_STATUS_CPU, host_int_status)) {
  404. /* CPU Interrupt */
  405. status = ath6kl_hif_proc_cpu_intr(dev);
  406. if (status)
  407. goto out;
  408. }
  409. if (MS(HOST_INT_STATUS_ERROR, host_int_status)) {
  410. /* Error Interrupt */
  411. status = ath6kl_hif_proc_err_intr(dev);
  412. if (status)
  413. goto out;
  414. }
  415. if (MS(HOST_INT_STATUS_COUNTER, host_int_status))
  416. /* Counter Interrupt */
  417. status = ath6kl_hif_proc_counter_intr(dev);
  418. out:
  419. /*
  420. * An optimization to bypass reading the IRQ status registers
  421. * unecessarily which can re-wake the target, if upper layers
  422. * determine that we are in a low-throughput mode, we can rely on
  423. * taking another interrupt rather than re-checking the status
  424. * registers which can re-wake the target.
  425. *
  426. * NOTE : for host interfaces that makes use of detecting pending
  427. * mbox messages at hif can not use this optimization due to
  428. * possible side effects, SPI requires the host to drain all
  429. * messages from the mailbox before exiting the ISR routine.
  430. */
  431. ath6kl_dbg(ATH6KL_DBG_IRQ,
  432. "bypassing irq status re-check, forcing done\n");
  433. if (!dev->htc_cnxt->chk_irq_status_cnt)
  434. *done = true;
  435. ath6kl_dbg(ATH6KL_DBG_IRQ,
  436. "proc_pending_irqs: (done:%d, status=%d\n", *done, status);
  437. return status;
  438. }
  439. /* interrupt handler, kicks off all interrupt processing */
  440. int ath6kl_hif_intr_bh_handler(struct ath6kl *ar)
  441. {
  442. struct ath6kl_device *dev = ar->htc_target->dev;
  443. unsigned long timeout;
  444. int status = 0;
  445. bool done = false;
  446. /*
  447. * Reset counter used to flag a re-scan of IRQ status registers on
  448. * the target.
  449. */
  450. dev->htc_cnxt->chk_irq_status_cnt = 0;
  451. /*
  452. * IRQ processing is synchronous, interrupt status registers can be
  453. * re-read.
  454. */
  455. timeout = jiffies + msecs_to_jiffies(ATH6KL_HIF_COMMUNICATION_TIMEOUT);
  456. while (time_before(jiffies, timeout) && !done) {
  457. status = proc_pending_irqs(dev, &done);
  458. if (status)
  459. break;
  460. }
  461. return status;
  462. }
  463. EXPORT_SYMBOL(ath6kl_hif_intr_bh_handler);
  464. static int ath6kl_hif_enable_intrs(struct ath6kl_device *dev)
  465. {
  466. struct ath6kl_irq_enable_reg regs;
  467. int status;
  468. spin_lock_bh(&dev->lock);
  469. /* Enable all but ATH6KL CPU interrupts */
  470. dev->irq_en_reg.int_status_en =
  471. SM(INT_STATUS_ENABLE_ERROR, 0x01) |
  472. SM(INT_STATUS_ENABLE_CPU, 0x01) |
  473. SM(INT_STATUS_ENABLE_COUNTER, 0x01);
  474. /*
  475. * NOTE: There are some cases where HIF can do detection of
  476. * pending mbox messages which is disabled now.
  477. */
  478. dev->irq_en_reg.int_status_en |= SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
  479. /* Set up the CPU Interrupt status Register */
  480. dev->irq_en_reg.cpu_int_status_en = 0;
  481. /* Set up the Error Interrupt status Register */
  482. dev->irq_en_reg.err_int_status_en =
  483. SM(ERROR_STATUS_ENABLE_RX_UNDERFLOW, 0x01) |
  484. SM(ERROR_STATUS_ENABLE_TX_OVERFLOW, 0x1);
  485. /*
  486. * Enable Counter interrupt status register to get fatal errors for
  487. * debugging.
  488. */
  489. dev->irq_en_reg.cntr_int_status_en = SM(COUNTER_INT_STATUS_ENABLE_BIT,
  490. ATH6KL_TARGET_DEBUG_INTR_MASK);
  491. memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
  492. spin_unlock_bh(&dev->lock);
  493. status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
  494. &regs.int_status_en, sizeof(regs),
  495. HIF_WR_SYNC_BYTE_INC);
  496. if (status)
  497. ath6kl_err("failed to update interrupt ctl reg err: %d\n",
  498. status);
  499. return status;
  500. }
  501. int ath6kl_hif_disable_intrs(struct ath6kl_device *dev)
  502. {
  503. struct ath6kl_irq_enable_reg regs;
  504. spin_lock_bh(&dev->lock);
  505. /* Disable all interrupts */
  506. dev->irq_en_reg.int_status_en = 0;
  507. dev->irq_en_reg.cpu_int_status_en = 0;
  508. dev->irq_en_reg.err_int_status_en = 0;
  509. dev->irq_en_reg.cntr_int_status_en = 0;
  510. memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
  511. spin_unlock_bh(&dev->lock);
  512. return hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
  513. &regs.int_status_en, sizeof(regs),
  514. HIF_WR_SYNC_BYTE_INC);
  515. }
  516. /* enable device interrupts */
  517. int ath6kl_hif_unmask_intrs(struct ath6kl_device *dev)
  518. {
  519. int status = 0;
  520. /*
  521. * Make sure interrupt are disabled before unmasking at the HIF
  522. * layer. The rationale here is that between device insertion
  523. * (where we clear the interrupts the first time) and when HTC
  524. * is finally ready to handle interrupts, other software can perform
  525. * target "soft" resets. The ATH6KL interrupt enables reset back to an
  526. * "enabled" state when this happens.
  527. */
  528. ath6kl_hif_disable_intrs(dev);
  529. /* unmask the host controller interrupts */
  530. ath6kl_hif_irq_enable(dev->ar);
  531. status = ath6kl_hif_enable_intrs(dev);
  532. return status;
  533. }
  534. /* disable all device interrupts */
  535. int ath6kl_hif_mask_intrs(struct ath6kl_device *dev)
  536. {
  537. /*
  538. * Mask the interrupt at the HIF layer to avoid any stray interrupt
  539. * taken while we zero out our shadow registers in
  540. * ath6kl_hif_disable_intrs().
  541. */
  542. ath6kl_hif_irq_disable(dev->ar);
  543. return ath6kl_hif_disable_intrs(dev);
  544. }
  545. int ath6kl_hif_setup(struct ath6kl_device *dev)
  546. {
  547. int status = 0;
  548. spin_lock_init(&dev->lock);
  549. /*
  550. * NOTE: we actually get the block size of a mailbox other than 0,
  551. * for SDIO the block size on mailbox 0 is artificially set to 1.
  552. * So we use the block size that is set for the other 3 mailboxes.
  553. */
  554. dev->htc_cnxt->block_sz = dev->ar->mbox_info.block_size;
  555. /* must be a power of 2 */
  556. if ((dev->htc_cnxt->block_sz & (dev->htc_cnxt->block_sz - 1)) != 0) {
  557. WARN_ON(1);
  558. status = -EINVAL;
  559. goto fail_setup;
  560. }
  561. /* assemble mask, used for padding to a block */
  562. dev->htc_cnxt->block_mask = dev->htc_cnxt->block_sz - 1;
  563. ath6kl_dbg(ATH6KL_DBG_HIF, "hif block size %d mbox addr 0x%x\n",
  564. dev->htc_cnxt->block_sz, dev->ar->mbox_info.htc_addr);
  565. status = ath6kl_hif_disable_intrs(dev);
  566. fail_setup:
  567. return status;
  568. }