hif.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /*
  2. * Copyright (c) 2007-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "hif.h"
  17. #include <linux/export.h>
  18. #include "core.h"
  19. #include "target.h"
  20. #include "hif-ops.h"
  21. #include "debug.h"
  22. #define MAILBOX_FOR_BLOCK_SIZE 1
  23. #define ATH6KL_TIME_QUANTUM 10 /* in ms */
  24. static int ath6kl_hif_cp_scat_dma_buf(struct hif_scatter_req *req,
  25. bool from_dma)
  26. {
  27. u8 *buf;
  28. int i;
  29. buf = req->virt_dma_buf;
  30. for (i = 0; i < req->scat_entries; i++) {
  31. if (from_dma)
  32. memcpy(req->scat_list[i].buf, buf,
  33. req->scat_list[i].len);
  34. else
  35. memcpy(buf, req->scat_list[i].buf,
  36. req->scat_list[i].len);
  37. buf += req->scat_list[i].len;
  38. }
  39. return 0;
  40. }
  41. int ath6kl_hif_rw_comp_handler(void *context, int status)
  42. {
  43. struct htc_packet *packet = context;
  44. ath6kl_dbg(ATH6KL_DBG_HIF, "hif rw completion pkt 0x%p status %d\n",
  45. packet, status);
  46. packet->status = status;
  47. packet->completion(packet->context, packet);
  48. return 0;
  49. }
  50. EXPORT_SYMBOL(ath6kl_hif_rw_comp_handler);
  51. #define REG_DUMP_COUNT_AR6003 60
  52. #define REGISTER_DUMP_LEN_MAX 60
  53. static void ath6kl_hif_dump_fw_crash(struct ath6kl *ar)
  54. {
  55. __le32 regdump_val[REGISTER_DUMP_LEN_MAX];
  56. u32 i, address, regdump_addr = 0;
  57. int ret;
  58. if (ar->target_type != TARGET_TYPE_AR6003)
  59. return;
  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. REG_DUMP_COUNT_AR6003 * (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(REG_DUMP_COUNT_AR6003 % 4);
  84. for (i = 0; i < REG_DUMP_COUNT_AR6003 / 4; i++) {
  85. ath6kl_info("%d: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x\n",
  86. 4 * 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. return ret;
  108. }
  109. /* mailbox recv message polling */
  110. int ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev, u32 *lk_ahd,
  111. int timeout)
  112. {
  113. struct ath6kl_irq_proc_registers *rg;
  114. int status = 0, i;
  115. u8 htc_mbox = 1 << HTC_MAILBOX;
  116. for (i = timeout / ATH6KL_TIME_QUANTUM; i > 0; i--) {
  117. /* this is the standard HIF way, load the reg table */
  118. status = hif_read_write_sync(dev->ar, HOST_INT_STATUS_ADDRESS,
  119. (u8 *) &dev->irq_proc_reg,
  120. sizeof(dev->irq_proc_reg),
  121. HIF_RD_SYNC_BYTE_INC);
  122. if (status) {
  123. ath6kl_err("failed to read reg table\n");
  124. return status;
  125. }
  126. /* check for MBOX data and valid lookahead */
  127. if (dev->irq_proc_reg.host_int_status & htc_mbox) {
  128. if (dev->irq_proc_reg.rx_lkahd_valid &
  129. htc_mbox) {
  130. /*
  131. * Mailbox has a message and the look ahead
  132. * is valid.
  133. */
  134. rg = &dev->irq_proc_reg;
  135. *lk_ahd =
  136. le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
  137. break;
  138. }
  139. }
  140. /* delay a little */
  141. mdelay(ATH6KL_TIME_QUANTUM);
  142. ath6kl_dbg(ATH6KL_DBG_HIF, "hif retry mbox poll try %d\n", i);
  143. }
  144. if (i == 0) {
  145. ath6kl_err("timeout waiting for recv message\n");
  146. status = -ETIME;
  147. /* check if the target asserted */
  148. if (dev->irq_proc_reg.counter_int_status &
  149. ATH6KL_TARGET_DEBUG_INTR_MASK)
  150. /*
  151. * Target failure handler will be called in case of
  152. * an assert.
  153. */
  154. ath6kl_hif_proc_dbg_intr(dev);
  155. }
  156. return status;
  157. }
  158. /*
  159. * Disable packet reception (used in case the host runs out of buffers)
  160. * using the interrupt enable registers through the host I/F
  161. */
  162. int ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx)
  163. {
  164. struct ath6kl_irq_enable_reg regs;
  165. int status = 0;
  166. ath6kl_dbg(ATH6KL_DBG_HIF, "hif rx %s\n",
  167. enable_rx ? "enable" : "disable");
  168. /* take the lock to protect interrupt enable shadows */
  169. spin_lock_bh(&dev->lock);
  170. if (enable_rx)
  171. dev->irq_en_reg.int_status_en |=
  172. SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
  173. else
  174. dev->irq_en_reg.int_status_en &=
  175. ~SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
  176. memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
  177. spin_unlock_bh(&dev->lock);
  178. status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
  179. &regs.int_status_en,
  180. sizeof(struct ath6kl_irq_enable_reg),
  181. HIF_WR_SYNC_BYTE_INC);
  182. return status;
  183. }
  184. int ath6kl_hif_submit_scat_req(struct ath6kl_device *dev,
  185. struct hif_scatter_req *scat_req, bool read)
  186. {
  187. int status = 0;
  188. if (read) {
  189. scat_req->req = HIF_RD_SYNC_BLOCK_FIX;
  190. scat_req->addr = dev->ar->mbox_info.htc_addr;
  191. } else {
  192. scat_req->req = HIF_WR_ASYNC_BLOCK_INC;
  193. scat_req->addr =
  194. (scat_req->len > HIF_MBOX_WIDTH) ?
  195. dev->ar->mbox_info.htc_ext_addr :
  196. dev->ar->mbox_info.htc_addr;
  197. }
  198. ath6kl_dbg(ATH6KL_DBG_HIF,
  199. "hif submit scatter request entries %d len %d mbox 0x%x %s %s\n",
  200. scat_req->scat_entries, scat_req->len,
  201. scat_req->addr, !read ? "async" : "sync",
  202. (read) ? "rd" : "wr");
  203. if (!read && scat_req->virt_scat) {
  204. status = ath6kl_hif_cp_scat_dma_buf(scat_req, false);
  205. if (status) {
  206. scat_req->status = status;
  207. scat_req->complete(dev->ar->htc_target, scat_req);
  208. return 0;
  209. }
  210. }
  211. status = ath6kl_hif_scat_req_rw(dev->ar, scat_req);
  212. if (read) {
  213. /* in sync mode, we can touch the scatter request */
  214. scat_req->status = status;
  215. if (!status && scat_req->virt_scat)
  216. scat_req->status =
  217. ath6kl_hif_cp_scat_dma_buf(scat_req, true);
  218. }
  219. return status;
  220. }
  221. static int ath6kl_hif_proc_counter_intr(struct ath6kl_device *dev)
  222. {
  223. u8 counter_int_status;
  224. ath6kl_dbg(ATH6KL_DBG_IRQ, "counter interrupt\n");
  225. counter_int_status = dev->irq_proc_reg.counter_int_status &
  226. dev->irq_en_reg.cntr_int_status_en;
  227. ath6kl_dbg(ATH6KL_DBG_IRQ,
  228. "valid interrupt source(s) in COUNTER_INT_STATUS: 0x%x\n",
  229. counter_int_status);
  230. /*
  231. * NOTE: other modules like GMBOX may use the counter interrupt for
  232. * credit flow control on other counters, we only need to check for
  233. * the debug assertion counter interrupt.
  234. */
  235. if (counter_int_status & ATH6KL_TARGET_DEBUG_INTR_MASK)
  236. return ath6kl_hif_proc_dbg_intr(dev);
  237. return 0;
  238. }
  239. static int ath6kl_hif_proc_err_intr(struct ath6kl_device *dev)
  240. {
  241. int status;
  242. u8 error_int_status;
  243. u8 reg_buf[4];
  244. ath6kl_dbg(ATH6KL_DBG_IRQ, "error interrupt\n");
  245. error_int_status = dev->irq_proc_reg.error_int_status & 0x0F;
  246. if (!error_int_status) {
  247. WARN_ON(1);
  248. return -EIO;
  249. }
  250. ath6kl_dbg(ATH6KL_DBG_IRQ,
  251. "valid interrupt source(s) in ERROR_INT_STATUS: 0x%x\n",
  252. error_int_status);
  253. if (MS(ERROR_INT_STATUS_WAKEUP, error_int_status))
  254. ath6kl_dbg(ATH6KL_DBG_IRQ, "error : wakeup\n");
  255. if (MS(ERROR_INT_STATUS_RX_UNDERFLOW, error_int_status))
  256. ath6kl_err("rx underflow\n");
  257. if (MS(ERROR_INT_STATUS_TX_OVERFLOW, error_int_status))
  258. ath6kl_err("tx overflow\n");
  259. /* Clear the interrupt */
  260. dev->irq_proc_reg.error_int_status &= ~error_int_status;
  261. /* set W1C value to clear the interrupt, this hits the register first */
  262. reg_buf[0] = error_int_status;
  263. reg_buf[1] = 0;
  264. reg_buf[2] = 0;
  265. reg_buf[3] = 0;
  266. status = hif_read_write_sync(dev->ar, ERROR_INT_STATUS_ADDRESS,
  267. reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
  268. if (status)
  269. WARN_ON(1);
  270. return status;
  271. }
  272. static int ath6kl_hif_proc_cpu_intr(struct ath6kl_device *dev)
  273. {
  274. int status;
  275. u8 cpu_int_status;
  276. u8 reg_buf[4];
  277. ath6kl_dbg(ATH6KL_DBG_IRQ, "cpu interrupt\n");
  278. cpu_int_status = dev->irq_proc_reg.cpu_int_status &
  279. dev->irq_en_reg.cpu_int_status_en;
  280. if (!cpu_int_status) {
  281. WARN_ON(1);
  282. return -EIO;
  283. }
  284. ath6kl_dbg(ATH6KL_DBG_IRQ,
  285. "valid interrupt source(s) in CPU_INT_STATUS: 0x%x\n",
  286. cpu_int_status);
  287. /* Clear the interrupt */
  288. dev->irq_proc_reg.cpu_int_status &= ~cpu_int_status;
  289. /*
  290. * Set up the register transfer buffer to hit the register 4 times ,
  291. * this is done to make the access 4-byte aligned to mitigate issues
  292. * with host bus interconnects that restrict bus transfer lengths to
  293. * be a multiple of 4-bytes.
  294. */
  295. /* set W1C value to clear the interrupt, this hits the register first */
  296. reg_buf[0] = cpu_int_status;
  297. /* the remaining are set to zero which have no-effect */
  298. reg_buf[1] = 0;
  299. reg_buf[2] = 0;
  300. reg_buf[3] = 0;
  301. status = hif_read_write_sync(dev->ar, CPU_INT_STATUS_ADDRESS,
  302. reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
  303. if (status)
  304. WARN_ON(1);
  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. /* Update only those registers that are enabled */
  352. host_int_status = dev->irq_proc_reg.host_int_status &
  353. dev->irq_en_reg.int_status_en;
  354. /* Look at mbox status */
  355. if (host_int_status & htc_mbox) {
  356. /*
  357. * Mask out pending mbox value, we use "lookAhead as
  358. * the real flag for mbox processing.
  359. */
  360. host_int_status &= ~htc_mbox;
  361. if (dev->irq_proc_reg.rx_lkahd_valid &
  362. htc_mbox) {
  363. rg = &dev->irq_proc_reg;
  364. lk_ahd = le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
  365. if (!lk_ahd)
  366. ath6kl_err("lookAhead is zero!\n");
  367. }
  368. }
  369. }
  370. if (!host_int_status && !lk_ahd) {
  371. *done = true;
  372. goto out;
  373. }
  374. if (lk_ahd) {
  375. int fetched = 0;
  376. ath6kl_dbg(ATH6KL_DBG_IRQ,
  377. "pending mailbox msg, lk_ahd: 0x%X\n", lk_ahd);
  378. /*
  379. * Mailbox Interrupt, the HTC layer may issue async
  380. * requests to empty the mailbox. When emptying the recv
  381. * mailbox we use the async handler above called from the
  382. * completion routine of the callers read request. This can
  383. * improve performance by reducing context switching when
  384. * we rapidly pull packets.
  385. */
  386. status = ath6kl_htc_rxmsg_pending_handler(dev->htc_cnxt,
  387. lk_ahd, &fetched);
  388. if (status)
  389. goto out;
  390. if (!fetched)
  391. /*
  392. * HTC could not pull any messages out due to lack
  393. * of resources.
  394. */
  395. dev->htc_cnxt->chk_irq_status_cnt = 0;
  396. }
  397. /* now handle the rest of them */
  398. ath6kl_dbg(ATH6KL_DBG_IRQ,
  399. "valid interrupt source(s) for other interrupts: 0x%x\n",
  400. host_int_status);
  401. if (MS(HOST_INT_STATUS_CPU, host_int_status)) {
  402. /* CPU Interrupt */
  403. status = ath6kl_hif_proc_cpu_intr(dev);
  404. if (status)
  405. goto out;
  406. }
  407. if (MS(HOST_INT_STATUS_ERROR, host_int_status)) {
  408. /* Error Interrupt */
  409. status = ath6kl_hif_proc_err_intr(dev);
  410. if (status)
  411. goto out;
  412. }
  413. if (MS(HOST_INT_STATUS_COUNTER, host_int_status))
  414. /* Counter Interrupt */
  415. status = ath6kl_hif_proc_counter_intr(dev);
  416. out:
  417. /*
  418. * An optimization to bypass reading the IRQ status registers
  419. * unecessarily which can re-wake the target, if upper layers
  420. * determine that we are in a low-throughput mode, we can rely on
  421. * taking another interrupt rather than re-checking the status
  422. * registers which can re-wake the target.
  423. *
  424. * NOTE : for host interfaces that makes use of detecting pending
  425. * mbox messages at hif can not use this optimization due to
  426. * possible side effects, SPI requires the host to drain all
  427. * messages from the mailbox before exiting the ISR routine.
  428. */
  429. ath6kl_dbg(ATH6KL_DBG_IRQ,
  430. "bypassing irq status re-check, forcing done\n");
  431. if (!dev->htc_cnxt->chk_irq_status_cnt)
  432. *done = true;
  433. ath6kl_dbg(ATH6KL_DBG_IRQ,
  434. "proc_pending_irqs: (done:%d, status=%d\n", *done, status);
  435. return status;
  436. }
  437. /* interrupt handler, kicks off all interrupt processing */
  438. int ath6kl_hif_intr_bh_handler(struct ath6kl *ar)
  439. {
  440. struct ath6kl_device *dev = ar->htc_target->dev;
  441. unsigned long timeout;
  442. int status = 0;
  443. bool done = false;
  444. /*
  445. * Reset counter used to flag a re-scan of IRQ status registers on
  446. * the target.
  447. */
  448. dev->htc_cnxt->chk_irq_status_cnt = 0;
  449. /*
  450. * IRQ processing is synchronous, interrupt status registers can be
  451. * re-read.
  452. */
  453. timeout = jiffies + msecs_to_jiffies(ATH6KL_HIF_COMMUNICATION_TIMEOUT);
  454. while (time_before(jiffies, timeout) && !done) {
  455. status = proc_pending_irqs(dev, &done);
  456. if (status)
  457. break;
  458. }
  459. return status;
  460. }
  461. EXPORT_SYMBOL(ath6kl_hif_intr_bh_handler);
  462. static int ath6kl_hif_enable_intrs(struct ath6kl_device *dev)
  463. {
  464. struct ath6kl_irq_enable_reg regs;
  465. int status;
  466. spin_lock_bh(&dev->lock);
  467. /* Enable all but ATH6KL CPU interrupts */
  468. dev->irq_en_reg.int_status_en =
  469. SM(INT_STATUS_ENABLE_ERROR, 0x01) |
  470. SM(INT_STATUS_ENABLE_CPU, 0x01) |
  471. SM(INT_STATUS_ENABLE_COUNTER, 0x01);
  472. /*
  473. * NOTE: There are some cases where HIF can do detection of
  474. * pending mbox messages which is disabled now.
  475. */
  476. dev->irq_en_reg.int_status_en |= SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
  477. /* Set up the CPU Interrupt status Register */
  478. dev->irq_en_reg.cpu_int_status_en = 0;
  479. /* Set up the Error Interrupt status Register */
  480. dev->irq_en_reg.err_int_status_en =
  481. SM(ERROR_STATUS_ENABLE_RX_UNDERFLOW, 0x01) |
  482. SM(ERROR_STATUS_ENABLE_TX_OVERFLOW, 0x1);
  483. /*
  484. * Enable Counter interrupt status register to get fatal errors for
  485. * debugging.
  486. */
  487. dev->irq_en_reg.cntr_int_status_en = SM(COUNTER_INT_STATUS_ENABLE_BIT,
  488. ATH6KL_TARGET_DEBUG_INTR_MASK);
  489. memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
  490. spin_unlock_bh(&dev->lock);
  491. status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
  492. &regs.int_status_en, sizeof(regs),
  493. HIF_WR_SYNC_BYTE_INC);
  494. if (status)
  495. ath6kl_err("failed to update interrupt ctl reg err: %d\n",
  496. status);
  497. return status;
  498. }
  499. int ath6kl_hif_disable_intrs(struct ath6kl_device *dev)
  500. {
  501. struct ath6kl_irq_enable_reg regs;
  502. spin_lock_bh(&dev->lock);
  503. /* Disable all interrupts */
  504. dev->irq_en_reg.int_status_en = 0;
  505. dev->irq_en_reg.cpu_int_status_en = 0;
  506. dev->irq_en_reg.err_int_status_en = 0;
  507. dev->irq_en_reg.cntr_int_status_en = 0;
  508. memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
  509. spin_unlock_bh(&dev->lock);
  510. return hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
  511. &regs.int_status_en, sizeof(regs),
  512. HIF_WR_SYNC_BYTE_INC);
  513. }
  514. /* enable device interrupts */
  515. int ath6kl_hif_unmask_intrs(struct ath6kl_device *dev)
  516. {
  517. int status = 0;
  518. /*
  519. * Make sure interrupt are disabled before unmasking at the HIF
  520. * layer. The rationale here is that between device insertion
  521. * (where we clear the interrupts the first time) and when HTC
  522. * is finally ready to handle interrupts, other software can perform
  523. * target "soft" resets. The ATH6KL interrupt enables reset back to an
  524. * "enabled" state when this happens.
  525. */
  526. ath6kl_hif_disable_intrs(dev);
  527. /* unmask the host controller interrupts */
  528. ath6kl_hif_irq_enable(dev->ar);
  529. status = ath6kl_hif_enable_intrs(dev);
  530. return status;
  531. }
  532. /* disable all device interrupts */
  533. int ath6kl_hif_mask_intrs(struct ath6kl_device *dev)
  534. {
  535. /*
  536. * Mask the interrupt at the HIF layer to avoid any stray interrupt
  537. * taken while we zero out our shadow registers in
  538. * ath6kl_hif_disable_intrs().
  539. */
  540. ath6kl_hif_irq_disable(dev->ar);
  541. return ath6kl_hif_disable_intrs(dev);
  542. }
  543. int ath6kl_hif_setup(struct ath6kl_device *dev)
  544. {
  545. int status = 0;
  546. spin_lock_init(&dev->lock);
  547. /*
  548. * NOTE: we actually get the block size of a mailbox other than 0,
  549. * for SDIO the block size on mailbox 0 is artificially set to 1.
  550. * So we use the block size that is set for the other 3 mailboxes.
  551. */
  552. dev->htc_cnxt->block_sz = dev->ar->mbox_info.block_size;
  553. /* must be a power of 2 */
  554. if ((dev->htc_cnxt->block_sz & (dev->htc_cnxt->block_sz - 1)) != 0) {
  555. WARN_ON(1);
  556. status = -EINVAL;
  557. goto fail_setup;
  558. }
  559. /* assemble mask, used for padding to a block */
  560. dev->htc_cnxt->block_mask = dev->htc_cnxt->block_sz - 1;
  561. ath6kl_dbg(ATH6KL_DBG_HIF, "hif block size %d mbox addr 0x%x\n",
  562. dev->htc_cnxt->block_sz, dev->ar->mbox_info.htc_addr);
  563. /* usb doesn't support enabling interrupts */
  564. /* FIXME: remove check once USB support is implemented */
  565. if (dev->ar->hif_type == ATH6KL_HIF_TYPE_USB)
  566. return 0;
  567. status = ath6kl_hif_disable_intrs(dev);
  568. fail_setup:
  569. return status;
  570. }