This source file includes following definitions.
- ath6kl_hif_cp_scat_dma_buf
- ath6kl_hif_rw_comp_handler
- ath6kl_hif_dump_fw_crash
- ath6kl_hif_proc_dbg_intr
- ath6kl_hif_poll_mboxmsg_rx
- ath6kl_hif_rx_control
- ath6kl_hif_submit_scat_req
- ath6kl_hif_proc_counter_intr
- ath6kl_hif_proc_err_intr
- ath6kl_hif_proc_cpu_intr
- proc_pending_irqs
- ath6kl_hif_intr_bh_handler
- ath6kl_hif_enable_intrs
- ath6kl_hif_disable_intrs
- ath6kl_hif_unmask_intrs
- ath6kl_hif_mask_intrs
- ath6kl_hif_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include "hif.h"
18
19 #include <linux/export.h>
20
21 #include "core.h"
22 #include "target.h"
23 #include "hif-ops.h"
24 #include "debug.h"
25 #include "trace.h"
26
27 #define MAILBOX_FOR_BLOCK_SIZE 1
28
29 #define ATH6KL_TIME_QUANTUM 10
30
31 static int ath6kl_hif_cp_scat_dma_buf(struct hif_scatter_req *req,
32 bool from_dma)
33 {
34 u8 *buf;
35 int i;
36
37 buf = req->virt_dma_buf;
38
39 for (i = 0; i < req->scat_entries; i++) {
40 if (from_dma)
41 memcpy(req->scat_list[i].buf, buf,
42 req->scat_list[i].len);
43 else
44 memcpy(buf, req->scat_list[i].buf,
45 req->scat_list[i].len);
46
47 buf += req->scat_list[i].len;
48 }
49
50 return 0;
51 }
52
53 int ath6kl_hif_rw_comp_handler(void *context, int status)
54 {
55 struct htc_packet *packet = context;
56
57 ath6kl_dbg(ATH6KL_DBG_HIF, "hif rw completion pkt 0x%p status %d\n",
58 packet, status);
59
60 packet->status = status;
61 packet->completion(packet->context, packet);
62
63 return 0;
64 }
65 EXPORT_SYMBOL(ath6kl_hif_rw_comp_handler);
66
67 #define REGISTER_DUMP_COUNT 60
68 #define REGISTER_DUMP_LEN_MAX 60
69
70 static void ath6kl_hif_dump_fw_crash(struct ath6kl *ar)
71 {
72 __le32 regdump_val[REGISTER_DUMP_LEN_MAX];
73 u32 i, address, regdump_addr = 0;
74 int ret;
75
76
77 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
78 address = TARG_VTOP(ar->target_type, address);
79
80
81 ret = ath6kl_diag_read32(ar, address, ®dump_addr);
82
83 if (ret || !regdump_addr) {
84 ath6kl_warn("failed to get ptr to register dump area: %d\n",
85 ret);
86 return;
87 }
88
89 ath6kl_dbg(ATH6KL_DBG_IRQ, "register dump data address 0x%x\n",
90 regdump_addr);
91 regdump_addr = TARG_VTOP(ar->target_type, regdump_addr);
92
93
94 ret = ath6kl_diag_read(ar, regdump_addr, (u8 *)®dump_val[0],
95 REGISTER_DUMP_COUNT * (sizeof(u32)));
96 if (ret) {
97 ath6kl_warn("failed to get register dump: %d\n", ret);
98 return;
99 }
100
101 ath6kl_info("crash dump:\n");
102 ath6kl_info("hw 0x%x fw %s\n", ar->wiphy->hw_version,
103 ar->wiphy->fw_version);
104
105 BUILD_BUG_ON(REGISTER_DUMP_COUNT % 4);
106
107 for (i = 0; i < REGISTER_DUMP_COUNT; i += 4) {
108 ath6kl_info("%d: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x\n",
109 i,
110 le32_to_cpu(regdump_val[i]),
111 le32_to_cpu(regdump_val[i + 1]),
112 le32_to_cpu(regdump_val[i + 2]),
113 le32_to_cpu(regdump_val[i + 3]));
114 }
115 }
116
117 static int ath6kl_hif_proc_dbg_intr(struct ath6kl_device *dev)
118 {
119 u32 dummy;
120 int ret;
121
122 ath6kl_warn("firmware crashed\n");
123
124
125
126
127
128 ret = hif_read_write_sync(dev->ar, COUNT_DEC_ADDRESS,
129 (u8 *)&dummy, 4, HIF_RD_SYNC_BYTE_INC);
130 if (ret)
131 ath6kl_warn("Failed to clear debug interrupt: %d\n", ret);
132
133 ath6kl_hif_dump_fw_crash(dev->ar);
134 ath6kl_read_fwlogs(dev->ar);
135 ath6kl_recovery_err_notify(dev->ar, ATH6KL_FW_ASSERT);
136
137 return ret;
138 }
139
140
141 int ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev, u32 *lk_ahd,
142 int timeout)
143 {
144 struct ath6kl_irq_proc_registers *rg;
145 int status = 0, i;
146 u8 htc_mbox = 1 << HTC_MAILBOX;
147
148 for (i = timeout / ATH6KL_TIME_QUANTUM; i > 0; i--) {
149
150 status = hif_read_write_sync(dev->ar, HOST_INT_STATUS_ADDRESS,
151 (u8 *) &dev->irq_proc_reg,
152 sizeof(dev->irq_proc_reg),
153 HIF_RD_SYNC_BYTE_INC);
154
155 if (status) {
156 ath6kl_err("failed to read reg table\n");
157 return status;
158 }
159
160
161 if (dev->irq_proc_reg.host_int_status & htc_mbox) {
162 if (dev->irq_proc_reg.rx_lkahd_valid &
163 htc_mbox) {
164
165
166
167
168 rg = &dev->irq_proc_reg;
169 *lk_ahd =
170 le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
171 break;
172 }
173 }
174
175
176 mdelay(ATH6KL_TIME_QUANTUM);
177 ath6kl_dbg(ATH6KL_DBG_HIF, "hif retry mbox poll try %d\n", i);
178 }
179
180 if (i == 0) {
181 ath6kl_err("timeout waiting for recv message\n");
182 status = -ETIME;
183
184 if (dev->irq_proc_reg.counter_int_status &
185 ATH6KL_TARGET_DEBUG_INTR_MASK)
186
187
188
189
190 ath6kl_hif_proc_dbg_intr(dev);
191 }
192
193 return status;
194 }
195
196
197
198
199
200 int ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx)
201 {
202 struct ath6kl_irq_enable_reg regs;
203 int status = 0;
204
205 ath6kl_dbg(ATH6KL_DBG_HIF, "hif rx %s\n",
206 enable_rx ? "enable" : "disable");
207
208
209 spin_lock_bh(&dev->lock);
210
211 if (enable_rx)
212 dev->irq_en_reg.int_status_en |=
213 SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
214 else
215 dev->irq_en_reg.int_status_en &=
216 ~SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
217
218 memcpy(®s, &dev->irq_en_reg, sizeof(regs));
219
220 spin_unlock_bh(&dev->lock);
221
222 status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
223 ®s.int_status_en,
224 sizeof(struct ath6kl_irq_enable_reg),
225 HIF_WR_SYNC_BYTE_INC);
226
227 return status;
228 }
229
230 int ath6kl_hif_submit_scat_req(struct ath6kl_device *dev,
231 struct hif_scatter_req *scat_req, bool read)
232 {
233 int status = 0;
234
235 if (read) {
236 scat_req->req = HIF_RD_SYNC_BLOCK_FIX;
237 scat_req->addr = dev->ar->mbox_info.htc_addr;
238 } else {
239 scat_req->req = HIF_WR_ASYNC_BLOCK_INC;
240
241 scat_req->addr =
242 (scat_req->len > HIF_MBOX_WIDTH) ?
243 dev->ar->mbox_info.htc_ext_addr :
244 dev->ar->mbox_info.htc_addr;
245 }
246
247 ath6kl_dbg(ATH6KL_DBG_HIF,
248 "hif submit scatter request entries %d len %d mbox 0x%x %s %s\n",
249 scat_req->scat_entries, scat_req->len,
250 scat_req->addr, !read ? "async" : "sync",
251 (read) ? "rd" : "wr");
252
253 if (!read && scat_req->virt_scat) {
254 status = ath6kl_hif_cp_scat_dma_buf(scat_req, false);
255 if (status) {
256 scat_req->status = status;
257 scat_req->complete(dev->ar->htc_target, scat_req);
258 return 0;
259 }
260 }
261
262 status = ath6kl_hif_scat_req_rw(dev->ar, scat_req);
263
264 if (read) {
265
266 scat_req->status = status;
267 if (!status && scat_req->virt_scat)
268 scat_req->status =
269 ath6kl_hif_cp_scat_dma_buf(scat_req, true);
270 }
271
272 return status;
273 }
274
275 static int ath6kl_hif_proc_counter_intr(struct ath6kl_device *dev)
276 {
277 u8 counter_int_status;
278
279 ath6kl_dbg(ATH6KL_DBG_IRQ, "counter interrupt\n");
280
281 counter_int_status = dev->irq_proc_reg.counter_int_status &
282 dev->irq_en_reg.cntr_int_status_en;
283
284 ath6kl_dbg(ATH6KL_DBG_IRQ,
285 "valid interrupt source(s) in COUNTER_INT_STATUS: 0x%x\n",
286 counter_int_status);
287
288
289
290
291
292
293 if (counter_int_status & ATH6KL_TARGET_DEBUG_INTR_MASK)
294 return ath6kl_hif_proc_dbg_intr(dev);
295
296 return 0;
297 }
298
299 static int ath6kl_hif_proc_err_intr(struct ath6kl_device *dev)
300 {
301 int status;
302 u8 error_int_status;
303 u8 reg_buf[4];
304
305 ath6kl_dbg(ATH6KL_DBG_IRQ, "error interrupt\n");
306
307 error_int_status = dev->irq_proc_reg.error_int_status & 0x0F;
308 if (!error_int_status) {
309 WARN_ON(1);
310 return -EIO;
311 }
312
313 ath6kl_dbg(ATH6KL_DBG_IRQ,
314 "valid interrupt source(s) in ERROR_INT_STATUS: 0x%x\n",
315 error_int_status);
316
317 if (MS(ERROR_INT_STATUS_WAKEUP, error_int_status))
318 ath6kl_dbg(ATH6KL_DBG_IRQ, "error : wakeup\n");
319
320 if (MS(ERROR_INT_STATUS_RX_UNDERFLOW, error_int_status))
321 ath6kl_err("rx underflow\n");
322
323 if (MS(ERROR_INT_STATUS_TX_OVERFLOW, error_int_status))
324 ath6kl_err("tx overflow\n");
325
326
327 dev->irq_proc_reg.error_int_status &= ~error_int_status;
328
329
330 reg_buf[0] = error_int_status;
331 reg_buf[1] = 0;
332 reg_buf[2] = 0;
333 reg_buf[3] = 0;
334
335 status = hif_read_write_sync(dev->ar, ERROR_INT_STATUS_ADDRESS,
336 reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
337
338 WARN_ON(status);
339
340 return status;
341 }
342
343 static int ath6kl_hif_proc_cpu_intr(struct ath6kl_device *dev)
344 {
345 int status;
346 u8 cpu_int_status;
347 u8 reg_buf[4];
348
349 ath6kl_dbg(ATH6KL_DBG_IRQ, "cpu interrupt\n");
350
351 cpu_int_status = dev->irq_proc_reg.cpu_int_status &
352 dev->irq_en_reg.cpu_int_status_en;
353 if (!cpu_int_status) {
354 WARN_ON(1);
355 return -EIO;
356 }
357
358 ath6kl_dbg(ATH6KL_DBG_IRQ,
359 "valid interrupt source(s) in CPU_INT_STATUS: 0x%x\n",
360 cpu_int_status);
361
362
363 dev->irq_proc_reg.cpu_int_status &= ~cpu_int_status;
364
365
366
367
368
369
370
371
372
373 reg_buf[0] = cpu_int_status;
374
375 reg_buf[1] = 0;
376 reg_buf[2] = 0;
377 reg_buf[3] = 0;
378
379 status = hif_read_write_sync(dev->ar, CPU_INT_STATUS_ADDRESS,
380 reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
381
382 WARN_ON(status);
383
384 return status;
385 }
386
387
388 static int proc_pending_irqs(struct ath6kl_device *dev, bool *done)
389 {
390 struct ath6kl_irq_proc_registers *rg;
391 int status = 0;
392 u8 host_int_status = 0;
393 u32 lk_ahd = 0;
394 u8 htc_mbox = 1 << HTC_MAILBOX;
395
396 ath6kl_dbg(ATH6KL_DBG_IRQ, "proc_pending_irqs: (dev: 0x%p)\n", dev);
397
398
399
400
401
402
403
404
405
406
407
408
409
410 if (dev->irq_en_reg.int_status_en) {
411
412
413
414
415
416
417
418
419
420
421
422
423
424
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
433 ath6kl_dump_registers(dev, &dev->irq_proc_reg,
434 &dev->irq_en_reg);
435 trace_ath6kl_sdio_irq(&dev->irq_en_reg,
436 sizeof(dev->irq_en_reg));
437
438
439 host_int_status = dev->irq_proc_reg.host_int_status &
440 dev->irq_en_reg.int_status_en;
441
442
443 if (host_int_status & htc_mbox) {
444
445
446
447
448 host_int_status &= ~htc_mbox;
449 if (dev->irq_proc_reg.rx_lkahd_valid &
450 htc_mbox) {
451 rg = &dev->irq_proc_reg;
452 lk_ahd = le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
453 if (!lk_ahd)
454 ath6kl_err("lookAhead is zero!\n");
455 }
456 }
457 }
458
459 if (!host_int_status && !lk_ahd) {
460 *done = true;
461 goto out;
462 }
463
464 if (lk_ahd) {
465 int fetched = 0;
466
467 ath6kl_dbg(ATH6KL_DBG_IRQ,
468 "pending mailbox msg, lk_ahd: 0x%X\n", lk_ahd);
469
470
471
472
473
474
475
476
477 status = ath6kl_htc_rxmsg_pending_handler(dev->htc_cnxt,
478 lk_ahd, &fetched);
479 if (status)
480 goto out;
481
482 if (!fetched)
483
484
485
486
487 dev->htc_cnxt->chk_irq_status_cnt = 0;
488 }
489
490
491 ath6kl_dbg(ATH6KL_DBG_IRQ,
492 "valid interrupt source(s) for other interrupts: 0x%x\n",
493 host_int_status);
494
495 if (MS(HOST_INT_STATUS_CPU, host_int_status)) {
496
497 status = ath6kl_hif_proc_cpu_intr(dev);
498 if (status)
499 goto out;
500 }
501
502 if (MS(HOST_INT_STATUS_ERROR, host_int_status)) {
503
504 status = ath6kl_hif_proc_err_intr(dev);
505 if (status)
506 goto out;
507 }
508
509 if (MS(HOST_INT_STATUS_COUNTER, host_int_status))
510
511 status = ath6kl_hif_proc_counter_intr(dev);
512
513 out:
514
515
516
517
518
519
520
521
522
523
524
525
526
527 ath6kl_dbg(ATH6KL_DBG_IRQ,
528 "bypassing irq status re-check, forcing done\n");
529
530 if (!dev->htc_cnxt->chk_irq_status_cnt)
531 *done = true;
532
533 ath6kl_dbg(ATH6KL_DBG_IRQ,
534 "proc_pending_irqs: (done:%d, status=%d\n", *done, status);
535
536 return status;
537 }
538
539
540 int ath6kl_hif_intr_bh_handler(struct ath6kl *ar)
541 {
542 struct ath6kl_device *dev = ar->htc_target->dev;
543 unsigned long timeout;
544 int status = 0;
545 bool done = false;
546
547
548
549
550
551 dev->htc_cnxt->chk_irq_status_cnt = 0;
552
553
554
555
556
557 timeout = jiffies + msecs_to_jiffies(ATH6KL_HIF_COMMUNICATION_TIMEOUT);
558 while (time_before(jiffies, timeout) && !done) {
559 status = proc_pending_irqs(dev, &done);
560 if (status)
561 break;
562 }
563
564 return status;
565 }
566 EXPORT_SYMBOL(ath6kl_hif_intr_bh_handler);
567
568 static int ath6kl_hif_enable_intrs(struct ath6kl_device *dev)
569 {
570 struct ath6kl_irq_enable_reg regs;
571 int status;
572
573 spin_lock_bh(&dev->lock);
574
575
576 dev->irq_en_reg.int_status_en =
577 SM(INT_STATUS_ENABLE_ERROR, 0x01) |
578 SM(INT_STATUS_ENABLE_CPU, 0x01) |
579 SM(INT_STATUS_ENABLE_COUNTER, 0x01);
580
581
582
583
584
585 dev->irq_en_reg.int_status_en |= SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
586
587
588 dev->irq_en_reg.cpu_int_status_en = 0;
589
590
591 dev->irq_en_reg.err_int_status_en =
592 SM(ERROR_STATUS_ENABLE_RX_UNDERFLOW, 0x01) |
593 SM(ERROR_STATUS_ENABLE_TX_OVERFLOW, 0x1);
594
595
596
597
598
599 dev->irq_en_reg.cntr_int_status_en = SM(COUNTER_INT_STATUS_ENABLE_BIT,
600 ATH6KL_TARGET_DEBUG_INTR_MASK);
601 memcpy(®s, &dev->irq_en_reg, sizeof(regs));
602
603 spin_unlock_bh(&dev->lock);
604
605 status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
606 ®s.int_status_en, sizeof(regs),
607 HIF_WR_SYNC_BYTE_INC);
608
609 if (status)
610 ath6kl_err("failed to update interrupt ctl reg err: %d\n",
611 status);
612
613 return status;
614 }
615
616 int ath6kl_hif_disable_intrs(struct ath6kl_device *dev)
617 {
618 struct ath6kl_irq_enable_reg regs;
619
620 spin_lock_bh(&dev->lock);
621
622 dev->irq_en_reg.int_status_en = 0;
623 dev->irq_en_reg.cpu_int_status_en = 0;
624 dev->irq_en_reg.err_int_status_en = 0;
625 dev->irq_en_reg.cntr_int_status_en = 0;
626 memcpy(®s, &dev->irq_en_reg, sizeof(regs));
627 spin_unlock_bh(&dev->lock);
628
629 return hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
630 ®s.int_status_en, sizeof(regs),
631 HIF_WR_SYNC_BYTE_INC);
632 }
633
634
635 int ath6kl_hif_unmask_intrs(struct ath6kl_device *dev)
636 {
637 int status = 0;
638
639
640
641
642
643
644
645
646
647 ath6kl_hif_disable_intrs(dev);
648
649
650 ath6kl_hif_irq_enable(dev->ar);
651 status = ath6kl_hif_enable_intrs(dev);
652
653 return status;
654 }
655
656
657 int ath6kl_hif_mask_intrs(struct ath6kl_device *dev)
658 {
659
660
661
662
663
664 ath6kl_hif_irq_disable(dev->ar);
665
666 return ath6kl_hif_disable_intrs(dev);
667 }
668
669 int ath6kl_hif_setup(struct ath6kl_device *dev)
670 {
671 int status = 0;
672
673 spin_lock_init(&dev->lock);
674
675
676
677
678
679
680 dev->htc_cnxt->block_sz = dev->ar->mbox_info.block_size;
681
682
683 if ((dev->htc_cnxt->block_sz & (dev->htc_cnxt->block_sz - 1)) != 0) {
684 WARN_ON(1);
685 status = -EINVAL;
686 goto fail_setup;
687 }
688
689
690 dev->htc_cnxt->block_mask = dev->htc_cnxt->block_sz - 1;
691
692 ath6kl_dbg(ATH6KL_DBG_HIF, "hif block size %d mbox addr 0x%x\n",
693 dev->htc_cnxt->block_sz, dev->ar->mbox_info.htc_addr);
694
695 status = ath6kl_hif_disable_intrs(dev);
696
697 fail_setup:
698 return status;
699 }