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