htc_hif.c 21 KB

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