hif.c 18 KB

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