hif.c 18 KB

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