aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/brcm80211/brcmfmac
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-04-01 14:27:28 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-01 14:27:28 -0400
commit45eb5168873c93b4f1c3c3867fea65aad4c6abd6 (patch)
tree4949e1083f214ce51565d41614df912cba017219 /drivers/net/wireless/brcm80211/brcmfmac
parentb9600d2d0901cd0f91cb372e72bd53d22f49638d (diff)
parent9374e7d2fdcad3c36dafc8d3effd554bc702c4b6 (diff)
Merge tag 'wireless-drivers-next-for-davem-2015-04-01' of git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next
Kalle Valo says: ==================== Major changes: ath9k: * add Active Interference Cancellation, a method implemented in the HW to counter WLAN RX > sensitivity degradation when BT is transmitting at the same time. This feature is supported by cards like WB222 based on AR9462. iwlwifi: * Location Aware Regulatory was added by Arik * 8000 device family work * update to the BT Coex firmware API brmcfmac: * add new BCM43455 and BCM43457 SDIO device support * add new BCM43430 SDIO device support wil6210: * take care of AP bridging * fix NAPI behavior * found approach to achieve 4*n+2 alignment of Rx frames rt2x00: * add new rt2800usb device DWA 130 rtlwifi: * add USB ID for D-Link DWA-131 * add USB ID ASUS N10 WiFi dongle mwifiex: * throughput enhancements ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireless/brcm80211/brcmfmac')
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/chip.c310
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/chip.h12
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c5
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/msgbuf.h8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/pcie.c24
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/sdio.c199
7 files changed, 381 insertions, 185 deletions
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
index c438ccdb6ed8..9b508bd3b839 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
@@ -29,6 +29,7 @@
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/platform_data/brcmfmac-sdio.h> 31#include <linux/platform_data/brcmfmac-sdio.h>
32#include <linux/pm_runtime.h>
32#include <linux/suspend.h> 33#include <linux/suspend.h>
33#include <linux/errno.h> 34#include <linux/errno.h>
34#include <linux/module.h> 35#include <linux/module.h>
@@ -1006,6 +1007,7 @@ static int brcmf_sdiod_remove(struct brcmf_sdio_dev *sdiodev)
1006 sg_free_table(&sdiodev->sgtable); 1007 sg_free_table(&sdiodev->sgtable);
1007 sdiodev->sbwad = 0; 1008 sdiodev->sbwad = 0;
1008 1009
1010 pm_runtime_allow(sdiodev->func[1]->card->host->parent);
1009 return 0; 1011 return 0;
1010} 1012}
1011 1013
@@ -1074,7 +1076,7 @@ static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
1074 ret = -ENODEV; 1076 ret = -ENODEV;
1075 goto out; 1077 goto out;
1076 } 1078 }
1077 1079 pm_runtime_forbid(host->parent);
1078out: 1080out:
1079 if (ret) 1081 if (ret)
1080 brcmf_sdiod_remove(sdiodev); 1082 brcmf_sdiod_remove(sdiodev);
@@ -1096,6 +1098,8 @@ static const struct sdio_device_id brcmf_sdmmc_ids[] = {
1096 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43341), 1098 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43341),
1097 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43362), 1099 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43362),
1098 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4335_4339), 1100 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4335_4339),
1101 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43430),
1102 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4345),
1099 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4354), 1103 BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4354),
1100 { /* end: all zeroes */ } 1104 { /* end: all zeroes */ }
1101}; 1105};
@@ -1194,7 +1198,7 @@ static void brcmf_ops_sdio_remove(struct sdio_func *func)
1194 brcmf_dbg(SDIO, "sdio device ID: 0x%04x\n", func->device); 1198 brcmf_dbg(SDIO, "sdio device ID: 0x%04x\n", func->device);
1195 brcmf_dbg(SDIO, "Function: %d\n", func->num); 1199 brcmf_dbg(SDIO, "Function: %d\n", func->num);
1196 1200
1197 if (func->num != 1 && func->num != 2) 1201 if (func->num != 1)
1198 return; 1202 return;
1199 1203
1200 bus_if = dev_get_drvdata(&func->dev); 1204 bus_if = dev_get_drvdata(&func->dev);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/brcm80211/brcmfmac/chip.c
index 04d2ca0d87d6..ab2fac8b2760 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/chip.c
@@ -100,9 +100,6 @@
100#define BCM4329_CORE_SOCRAM_BASE 0x18003000 100#define BCM4329_CORE_SOCRAM_BASE 0x18003000
101/* ARM Cortex M3 core, ID 0x82a */ 101/* ARM Cortex M3 core, ID 0x82a */
102#define BCM4329_CORE_ARM_BASE 0x18002000 102#define BCM4329_CORE_ARM_BASE 0x18002000
103#define BCM4329_RAMSIZE 0x48000
104/* bcm43143 */
105#define BCM43143_RAMSIZE 0x70000
106 103
107#define CORE_SB(base, field) \ 104#define CORE_SB(base, field) \
108 (base + SBCONFIGOFF + offsetof(struct sbconfig, field)) 105 (base + SBCONFIGOFF + offsetof(struct sbconfig, field))
@@ -150,6 +147,78 @@ struct sbconfig {
150 u32 sbidhigh; /* identification */ 147 u32 sbidhigh; /* identification */
151}; 148};
152 149
150/* bankidx and bankinfo reg defines corerev >= 8 */
151#define SOCRAM_BANKINFO_RETNTRAM_MASK 0x00010000
152#define SOCRAM_BANKINFO_SZMASK 0x0000007f
153#define SOCRAM_BANKIDX_ROM_MASK 0x00000100
154
155#define SOCRAM_BANKIDX_MEMTYPE_SHIFT 8
156/* socram bankinfo memtype */
157#define SOCRAM_MEMTYPE_RAM 0
158#define SOCRAM_MEMTYPE_R0M 1
159#define SOCRAM_MEMTYPE_DEVRAM 2
160
161#define SOCRAM_BANKINFO_SZBASE 8192
162#define SRCI_LSS_MASK 0x00f00000
163#define SRCI_LSS_SHIFT 20
164#define SRCI_SRNB_MASK 0xf0
165#define SRCI_SRNB_SHIFT 4
166#define SRCI_SRBSZ_MASK 0xf
167#define SRCI_SRBSZ_SHIFT 0
168#define SR_BSZ_BASE 14
169
170struct sbsocramregs {
171 u32 coreinfo;
172 u32 bwalloc;
173 u32 extracoreinfo;
174 u32 biststat;
175 u32 bankidx;
176 u32 standbyctrl;
177
178 u32 errlogstatus; /* rev 6 */
179 u32 errlogaddr; /* rev 6 */
180 /* used for patching rev 3 & 5 */
181 u32 cambankidx;
182 u32 cambankstandbyctrl;
183 u32 cambankpatchctrl;
184 u32 cambankpatchtblbaseaddr;
185 u32 cambankcmdreg;
186 u32 cambankdatareg;
187 u32 cambankmaskreg;
188 u32 PAD[1];
189 u32 bankinfo; /* corev 8 */
190 u32 bankpda;
191 u32 PAD[14];
192 u32 extmemconfig;
193 u32 extmemparitycsr;
194 u32 extmemparityerrdata;
195 u32 extmemparityerrcnt;
196 u32 extmemwrctrlandsize;
197 u32 PAD[84];
198 u32 workaround;
199 u32 pwrctl; /* corerev >= 2 */
200 u32 PAD[133];
201 u32 sr_control; /* corerev >= 15 */
202 u32 sr_status; /* corerev >= 15 */
203 u32 sr_address; /* corerev >= 15 */
204 u32 sr_data; /* corerev >= 15 */
205};
206
207#define SOCRAMREGOFFS(_f) offsetof(struct sbsocramregs, _f)
208
209#define ARMCR4_CAP (0x04)
210#define ARMCR4_BANKIDX (0x40)
211#define ARMCR4_BANKINFO (0x44)
212#define ARMCR4_BANKPDA (0x4C)
213
214#define ARMCR4_TCBBNB_MASK 0xf0
215#define ARMCR4_TCBBNB_SHIFT 4
216#define ARMCR4_TCBANB_MASK 0xf
217#define ARMCR4_TCBANB_SHIFT 0
218
219#define ARMCR4_BSZ_MASK 0x3f
220#define ARMCR4_BSZ_MULT 8192
221
153struct brcmf_core_priv { 222struct brcmf_core_priv {
154 struct brcmf_core pub; 223 struct brcmf_core pub;
155 u32 wrapbase; 224 u32 wrapbase;
@@ -419,13 +488,13 @@ static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip_priv *ci,
419 return &core->pub; 488 return &core->pub;
420} 489}
421 490
422#ifdef DEBUG
423/* safety check for chipinfo */ 491/* safety check for chipinfo */
424static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci) 492static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
425{ 493{
426 struct brcmf_core_priv *core; 494 struct brcmf_core_priv *core;
427 bool need_socram = false; 495 bool need_socram = false;
428 bool has_socram = false; 496 bool has_socram = false;
497 bool cpu_found = false;
429 int idx = 1; 498 int idx = 1;
430 499
431 list_for_each_entry(core, &ci->cores, list) { 500 list_for_each_entry(core, &ci->cores, list) {
@@ -435,22 +504,24 @@ static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
435 504
436 switch (core->pub.id) { 505 switch (core->pub.id) {
437 case BCMA_CORE_ARM_CM3: 506 case BCMA_CORE_ARM_CM3:
507 cpu_found = true;
438 need_socram = true; 508 need_socram = true;
439 break; 509 break;
440 case BCMA_CORE_INTERNAL_MEM: 510 case BCMA_CORE_INTERNAL_MEM:
441 has_socram = true; 511 has_socram = true;
442 break; 512 break;
443 case BCMA_CORE_ARM_CR4: 513 case BCMA_CORE_ARM_CR4:
444 if (ci->pub.rambase == 0) { 514 cpu_found = true;
445 brcmf_err("RAM base not provided with ARM CR4 core\n");
446 return -ENOMEM;
447 }
448 break; 515 break;
449 default: 516 default:
450 break; 517 break;
451 } 518 }
452 } 519 }
453 520
521 if (!cpu_found) {
522 brcmf_err("CPU core not detected\n");
523 return -ENXIO;
524 }
454 /* check RAM core presence for ARM CM3 core */ 525 /* check RAM core presence for ARM CM3 core */
455 if (need_socram && !has_socram) { 526 if (need_socram && !has_socram) {
456 brcmf_err("RAM core not provided with ARM CM3 core\n"); 527 brcmf_err("RAM core not provided with ARM CM3 core\n");
@@ -458,56 +529,164 @@ static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
458 } 529 }
459 return 0; 530 return 0;
460} 531}
461#else /* DEBUG */ 532
462static inline int brcmf_chip_cores_check(struct brcmf_chip_priv *ci) 533static u32 brcmf_chip_core_read32(struct brcmf_core_priv *core, u16 reg)
463{ 534{
464 return 0; 535 return core->chip->ops->read32(core->chip->ctx, core->pub.base + reg);
465} 536}
466#endif
467 537
468static void brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci) 538static void brcmf_chip_core_write32(struct brcmf_core_priv *core,
539 u16 reg, u32 val)
469{ 540{
470 switch (ci->pub.chip) { 541 core->chip->ops->write32(core->chip->ctx, core->pub.base + reg, val);
471 case BRCM_CC_4329_CHIP_ID: 542}
472 ci->pub.ramsize = BCM4329_RAMSIZE; 543
473 break; 544static bool brcmf_chip_socram_banksize(struct brcmf_core_priv *core, u8 idx,
474 case BRCM_CC_43143_CHIP_ID: 545 u32 *banksize)
475 ci->pub.ramsize = BCM43143_RAMSIZE; 546{
476 break; 547 u32 bankinfo;
477 case BRCM_CC_43241_CHIP_ID: 548 u32 bankidx = (SOCRAM_MEMTYPE_RAM << SOCRAM_BANKIDX_MEMTYPE_SHIFT);
478 ci->pub.ramsize = 0x90000; 549
479 break; 550 bankidx |= idx;
480 case BRCM_CC_4330_CHIP_ID: 551 brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankidx), bankidx);
481 ci->pub.ramsize = 0x48000; 552 bankinfo = brcmf_chip_core_read32(core, SOCRAMREGOFFS(bankinfo));
482 break; 553 *banksize = (bankinfo & SOCRAM_BANKINFO_SZMASK) + 1;
554 *banksize *= SOCRAM_BANKINFO_SZBASE;
555 return !!(bankinfo & SOCRAM_BANKINFO_RETNTRAM_MASK);
556}
557
558static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
559 u32 *srsize)
560{
561 u32 coreinfo;
562 uint nb, banksize, lss;
563 bool retent;
564 int i;
565
566 *ramsize = 0;
567 *srsize = 0;
568
569 if (WARN_ON(sr->pub.rev < 4))
570 return;
571
572 if (!brcmf_chip_iscoreup(&sr->pub))
573 brcmf_chip_resetcore(&sr->pub, 0, 0, 0);
574
575 /* Get info for determining size */
576 coreinfo = brcmf_chip_core_read32(sr, SOCRAMREGOFFS(coreinfo));
577 nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
578
579 if ((sr->pub.rev <= 7) || (sr->pub.rev == 12)) {
580 banksize = (coreinfo & SRCI_SRBSZ_MASK);
581 lss = (coreinfo & SRCI_LSS_MASK) >> SRCI_LSS_SHIFT;
582 if (lss != 0)
583 nb--;
584 *ramsize = nb * (1 << (banksize + SR_BSZ_BASE));
585 if (lss != 0)
586 *ramsize += (1 << ((lss - 1) + SR_BSZ_BASE));
587 } else {
588 nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
589 for (i = 0; i < nb; i++) {
590 retent = brcmf_chip_socram_banksize(sr, i, &banksize);
591 *ramsize += banksize;
592 if (retent)
593 *srsize += banksize;
594 }
595 }
596
597 /* hardcoded save&restore memory sizes */
598 switch (sr->chip->pub.chip) {
483 case BRCM_CC_4334_CHIP_ID: 599 case BRCM_CC_4334_CHIP_ID:
484 case BRCM_CC_43340_CHIP_ID: 600 if (sr->chip->pub.chiprev < 2)
485 ci->pub.ramsize = 0x80000; 601 *srsize = (32 * 1024);
486 break; 602 break;
487 case BRCM_CC_4335_CHIP_ID: 603 case BRCM_CC_43430_CHIP_ID:
488 ci->pub.ramsize = 0xc0000; 604 /* assume sr for now as we can not check
489 ci->pub.rambase = 0x180000; 605 * firmware sr capability at this point.
606 */
607 *srsize = (64 * 1024);
490 break; 608 break;
491 case BRCM_CC_43362_CHIP_ID: 609 default:
492 ci->pub.ramsize = 0x3c000;
493 break; 610 break;
611 }
612}
613
614/** Return the TCM-RAM size of the ARMCR4 core. */
615static u32 brcmf_chip_tcm_ramsize(struct brcmf_core_priv *cr4)
616{
617 u32 corecap;
618 u32 memsize = 0;
619 u32 nab;
620 u32 nbb;
621 u32 totb;
622 u32 bxinfo;
623 u32 idx;
624
625 corecap = brcmf_chip_core_read32(cr4, ARMCR4_CAP);
626
627 nab = (corecap & ARMCR4_TCBANB_MASK) >> ARMCR4_TCBANB_SHIFT;
628 nbb = (corecap & ARMCR4_TCBBNB_MASK) >> ARMCR4_TCBBNB_SHIFT;
629 totb = nab + nbb;
630
631 for (idx = 0; idx < totb; idx++) {
632 brcmf_chip_core_write32(cr4, ARMCR4_BANKIDX, idx);
633 bxinfo = brcmf_chip_core_read32(cr4, ARMCR4_BANKINFO);
634 memsize += ((bxinfo & ARMCR4_BSZ_MASK) + 1) * ARMCR4_BSZ_MULT;
635 }
636
637 return memsize;
638}
639
640static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci)
641{
642 switch (ci->pub.chip) {
643 case BRCM_CC_4345_CHIP_ID:
644 return 0x198000;
645 case BRCM_CC_4335_CHIP_ID:
494 case BRCM_CC_4339_CHIP_ID: 646 case BRCM_CC_4339_CHIP_ID:
495 case BRCM_CC_4354_CHIP_ID: 647 case BRCM_CC_4354_CHIP_ID:
496 case BRCM_CC_4356_CHIP_ID: 648 case BRCM_CC_4356_CHIP_ID:
497 case BRCM_CC_43567_CHIP_ID: 649 case BRCM_CC_43567_CHIP_ID:
498 case BRCM_CC_43569_CHIP_ID: 650 case BRCM_CC_43569_CHIP_ID:
499 case BRCM_CC_43570_CHIP_ID: 651 case BRCM_CC_43570_CHIP_ID:
500 ci->pub.ramsize = 0xc0000;
501 ci->pub.rambase = 0x180000;
502 break;
503 case BRCM_CC_43602_CHIP_ID: 652 case BRCM_CC_43602_CHIP_ID:
504 ci->pub.ramsize = 0xf0000; 653 return 0x180000;
505 ci->pub.rambase = 0x180000;
506 break;
507 default: 654 default:
508 brcmf_err("unknown chip: %s\n", ci->pub.name); 655 brcmf_err("unknown chip: %s\n", ci->pub.name);
509 break; 656 break;
510 } 657 }
658 return 0;
659}
660
661static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
662{
663 struct brcmf_core_priv *mem_core;
664 struct brcmf_core *mem;
665
666 mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_ARM_CR4);
667 if (mem) {
668 mem_core = container_of(mem, struct brcmf_core_priv, pub);
669 ci->pub.ramsize = brcmf_chip_tcm_ramsize(mem_core);
670 ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
671 if (!ci->pub.rambase) {
672 brcmf_err("RAM base not provided with ARM CR4 core\n");
673 return -EINVAL;
674 }
675 } else {
676 mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_INTERNAL_MEM);
677 mem_core = container_of(mem, struct brcmf_core_priv, pub);
678 brcmf_chip_socram_ramsize(mem_core, &ci->pub.ramsize,
679 &ci->pub.srsize);
680 }
681 brcmf_dbg(INFO, "RAM: base=0x%x size=%d (0x%x) sr=%d (0x%x)\n",
682 ci->pub.rambase, ci->pub.ramsize, ci->pub.ramsize,
683 ci->pub.srsize, ci->pub.srsize);
684
685 if (!ci->pub.ramsize) {
686 brcmf_err("RAM size is undetermined\n");
687 return -ENOMEM;
688 }
689 return 0;
511} 690}
512 691
513static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip_priv *ci, u32 *eromaddr, 692static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip_priv *ci, u32 *eromaddr,
@@ -660,6 +839,7 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
660 struct brcmf_core *core; 839 struct brcmf_core *core;
661 u32 regdata; 840 u32 regdata;
662 u32 socitype; 841 u32 socitype;
842 int ret;
663 843
664 /* Get CC core rev 844 /* Get CC core rev
665 * Chipid is assume to be at offset 0 from SI_ENUM_BASE 845 * Chipid is assume to be at offset 0 from SI_ENUM_BASE
@@ -712,9 +892,13 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
712 return -ENODEV; 892 return -ENODEV;
713 } 893 }
714 894
715 brcmf_chip_get_raminfo(ci); 895 ret = brcmf_chip_cores_check(ci);
896 if (ret)
897 return ret;
716 898
717 return brcmf_chip_cores_check(ci); 899 /* assure chip is passive for core access */
900 brcmf_chip_set_passive(&ci->pub);
901 return brcmf_chip_get_raminfo(ci);
718} 902}
719 903
720static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id) 904static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
@@ -778,12 +962,6 @@ static int brcmf_chip_setup(struct brcmf_chip_priv *chip)
778 if (chip->ops->setup) 962 if (chip->ops->setup)
779 ret = chip->ops->setup(chip->ctx, pub); 963 ret = chip->ops->setup(chip->ctx, pub);
780 964
781 /*
782 * Make sure any on-chip ARM is off (in case strapping is wrong),
783 * or downloaded code was already running.
784 */
785 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
786 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CR4);
787 return ret; 965 return ret;
788} 966}
789 967
@@ -799,7 +977,7 @@ struct brcmf_chip *brcmf_chip_attach(void *ctx,
799 err = -EINVAL; 977 err = -EINVAL;
800 if (WARN_ON(!ops->prepare)) 978 if (WARN_ON(!ops->prepare))
801 err = -EINVAL; 979 err = -EINVAL;
802 if (WARN_ON(!ops->exit_dl)) 980 if (WARN_ON(!ops->activate))
803 err = -EINVAL; 981 err = -EINVAL;
804 if (err < 0) 982 if (err < 0)
805 return ERR_PTR(-EINVAL); 983 return ERR_PTR(-EINVAL);
@@ -897,9 +1075,10 @@ void brcmf_chip_resetcore(struct brcmf_core *pub, u32 prereset, u32 reset,
897} 1075}
898 1076
899static void 1077static void
900brcmf_chip_cm3_enterdl(struct brcmf_chip_priv *chip) 1078brcmf_chip_cm3_set_passive(struct brcmf_chip_priv *chip)
901{ 1079{
902 struct brcmf_core *core; 1080 struct brcmf_core *core;
1081 struct brcmf_core_priv *sr;
903 1082
904 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3); 1083 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
905 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211); 1084 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
@@ -909,9 +1088,16 @@ brcmf_chip_cm3_enterdl(struct brcmf_chip_priv *chip)
909 D11_BCMA_IOCTL_PHYCLOCKEN); 1088 D11_BCMA_IOCTL_PHYCLOCKEN);
910 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM); 1089 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
911 brcmf_chip_resetcore(core, 0, 0, 0); 1090 brcmf_chip_resetcore(core, 0, 0, 0);
1091
1092 /* disable bank #3 remap for this device */
1093 if (chip->pub.chip == BRCM_CC_43430_CHIP_ID) {
1094 sr = container_of(core, struct brcmf_core_priv, pub);
1095 brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankidx), 3);
1096 brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankpda), 0);
1097 }
912} 1098}
913 1099
914static bool brcmf_chip_cm3_exitdl(struct brcmf_chip_priv *chip) 1100static bool brcmf_chip_cm3_set_active(struct brcmf_chip_priv *chip)
915{ 1101{
916 struct brcmf_core *core; 1102 struct brcmf_core *core;
917 1103
@@ -921,7 +1107,7 @@ static bool brcmf_chip_cm3_exitdl(struct brcmf_chip_priv *chip)
921 return false; 1107 return false;
922 } 1108 }
923 1109
924 chip->ops->exit_dl(chip->ctx, &chip->pub, 0); 1110 chip->ops->activate(chip->ctx, &chip->pub, 0);
925 1111
926 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CM3); 1112 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CM3);
927 brcmf_chip_resetcore(core, 0, 0, 0); 1113 brcmf_chip_resetcore(core, 0, 0, 0);
@@ -930,7 +1116,7 @@ static bool brcmf_chip_cm3_exitdl(struct brcmf_chip_priv *chip)
930} 1116}
931 1117
932static inline void 1118static inline void
933brcmf_chip_cr4_enterdl(struct brcmf_chip_priv *chip) 1119brcmf_chip_cr4_set_passive(struct brcmf_chip_priv *chip)
934{ 1120{
935 struct brcmf_core *core; 1121 struct brcmf_core *core;
936 1122
@@ -943,11 +1129,11 @@ brcmf_chip_cr4_enterdl(struct brcmf_chip_priv *chip)
943 D11_BCMA_IOCTL_PHYCLOCKEN); 1129 D11_BCMA_IOCTL_PHYCLOCKEN);
944} 1130}
945 1131
946static bool brcmf_chip_cr4_exitdl(struct brcmf_chip_priv *chip, u32 rstvec) 1132static bool brcmf_chip_cr4_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
947{ 1133{
948 struct brcmf_core *core; 1134 struct brcmf_core *core;
949 1135
950 chip->ops->exit_dl(chip->ctx, &chip->pub, rstvec); 1136 chip->ops->activate(chip->ctx, &chip->pub, rstvec);
951 1137
952 /* restore ARM */ 1138 /* restore ARM */
953 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CR4); 1139 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CR4);
@@ -956,7 +1142,7 @@ static bool brcmf_chip_cr4_exitdl(struct brcmf_chip_priv *chip, u32 rstvec)
956 return true; 1142 return true;
957} 1143}
958 1144
959void brcmf_chip_enter_download(struct brcmf_chip *pub) 1145void brcmf_chip_set_passive(struct brcmf_chip *pub)
960{ 1146{
961 struct brcmf_chip_priv *chip; 1147 struct brcmf_chip_priv *chip;
962 struct brcmf_core *arm; 1148 struct brcmf_core *arm;
@@ -966,14 +1152,14 @@ void brcmf_chip_enter_download(struct brcmf_chip *pub)
966 chip = container_of(pub, struct brcmf_chip_priv, pub); 1152 chip = container_of(pub, struct brcmf_chip_priv, pub);
967 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4); 1153 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
968 if (arm) { 1154 if (arm) {
969 brcmf_chip_cr4_enterdl(chip); 1155 brcmf_chip_cr4_set_passive(chip);
970 return; 1156 return;
971 } 1157 }
972 1158
973 brcmf_chip_cm3_enterdl(chip); 1159 brcmf_chip_cm3_set_passive(chip);
974} 1160}
975 1161
976bool brcmf_chip_exit_download(struct brcmf_chip *pub, u32 rstvec) 1162bool brcmf_chip_set_active(struct brcmf_chip *pub, u32 rstvec)
977{ 1163{
978 struct brcmf_chip_priv *chip; 1164 struct brcmf_chip_priv *chip;
979 struct brcmf_core *arm; 1165 struct brcmf_core *arm;
@@ -983,9 +1169,9 @@ bool brcmf_chip_exit_download(struct brcmf_chip *pub, u32 rstvec)
983 chip = container_of(pub, struct brcmf_chip_priv, pub); 1169 chip = container_of(pub, struct brcmf_chip_priv, pub);
984 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4); 1170 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
985 if (arm) 1171 if (arm)
986 return brcmf_chip_cr4_exitdl(chip, rstvec); 1172 return brcmf_chip_cr4_set_active(chip, rstvec);
987 1173
988 return brcmf_chip_cm3_exitdl(chip); 1174 return brcmf_chip_cm3_set_active(chip);
989} 1175}
990 1176
991bool brcmf_chip_sr_capable(struct brcmf_chip *pub) 1177bool brcmf_chip_sr_capable(struct brcmf_chip *pub)
@@ -1016,6 +1202,10 @@ bool brcmf_chip_sr_capable(struct brcmf_chip *pub)
1016 addr = CORE_CC_REG(base, chipcontrol_data); 1202 addr = CORE_CC_REG(base, chipcontrol_data);
1017 reg = chip->ops->read32(chip->ctx, addr); 1203 reg = chip->ops->read32(chip->ctx, addr);
1018 return (reg & pmu_cc3_mask) != 0; 1204 return (reg & pmu_cc3_mask) != 0;
1205 case BRCM_CC_43430_CHIP_ID:
1206 addr = CORE_CC_REG(base, sr_control1);
1207 reg = chip->ops->read32(chip->ctx, addr);
1208 return reg != 0;
1019 default: 1209 default:
1020 addr = CORE_CC_REG(base, pmucapabilities_ext); 1210 addr = CORE_CC_REG(base, pmucapabilities_ext);
1021 reg = chip->ops->read32(chip->ctx, addr); 1211 reg = chip->ops->read32(chip->ctx, addr);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/chip.h b/drivers/net/wireless/brcm80211/brcmfmac/chip.h
index c32908da90c8..60dcb38fc77a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/chip.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/chip.h
@@ -30,7 +30,8 @@
30 * @pmucaps: PMU capabilities. 30 * @pmucaps: PMU capabilities.
31 * @pmurev: PMU revision. 31 * @pmurev: PMU revision.
32 * @rambase: RAM base address (only applicable for ARM CR4 chips). 32 * @rambase: RAM base address (only applicable for ARM CR4 chips).
33 * @ramsize: amount of RAM on chip. 33 * @ramsize: amount of RAM on chip including retention.
34 * @srsize: amount of retention RAM on chip.
34 * @name: string representation of the chip identifier. 35 * @name: string representation of the chip identifier.
35 */ 36 */
36struct brcmf_chip { 37struct brcmf_chip {
@@ -41,6 +42,7 @@ struct brcmf_chip {
41 u32 pmurev; 42 u32 pmurev;
42 u32 rambase; 43 u32 rambase;
43 u32 ramsize; 44 u32 ramsize;
45 u32 srsize;
44 char name[8]; 46 char name[8];
45}; 47};
46 48
@@ -64,7 +66,7 @@ struct brcmf_core {
64 * @write32: write 32-bit value over bus. 66 * @write32: write 32-bit value over bus.
65 * @prepare: prepare bus for core configuration. 67 * @prepare: prepare bus for core configuration.
66 * @setup: bus-specific core setup. 68 * @setup: bus-specific core setup.
67 * @exit_dl: exit download state. 69 * @active: chip becomes active.
68 * The callback should use the provided @rstvec when non-zero. 70 * The callback should use the provided @rstvec when non-zero.
69 */ 71 */
70struct brcmf_buscore_ops { 72struct brcmf_buscore_ops {
@@ -72,7 +74,7 @@ struct brcmf_buscore_ops {
72 void (*write32)(void *ctx, u32 addr, u32 value); 74 void (*write32)(void *ctx, u32 addr, u32 value);
73 int (*prepare)(void *ctx); 75 int (*prepare)(void *ctx);
74 int (*setup)(void *ctx, struct brcmf_chip *chip); 76 int (*setup)(void *ctx, struct brcmf_chip *chip);
75 void (*exit_dl)(void *ctx, struct brcmf_chip *chip, u32 rstvec); 77 void (*activate)(void *ctx, struct brcmf_chip *chip, u32 rstvec);
76}; 78};
77 79
78struct brcmf_chip *brcmf_chip_attach(void *ctx, 80struct brcmf_chip *brcmf_chip_attach(void *ctx,
@@ -84,8 +86,8 @@ bool brcmf_chip_iscoreup(struct brcmf_core *core);
84void brcmf_chip_coredisable(struct brcmf_core *core, u32 prereset, u32 reset); 86void brcmf_chip_coredisable(struct brcmf_core *core, u32 prereset, u32 reset);
85void brcmf_chip_resetcore(struct brcmf_core *core, u32 prereset, u32 reset, 87void brcmf_chip_resetcore(struct brcmf_core *core, u32 prereset, u32 reset,
86 u32 postreset); 88 u32 postreset);
87void brcmf_chip_enter_download(struct brcmf_chip *ci); 89void brcmf_chip_set_passive(struct brcmf_chip *ci);
88bool brcmf_chip_exit_download(struct brcmf_chip *ci, u32 rstvec); 90bool brcmf_chip_set_active(struct brcmf_chip *ci, u32 rstvec);
89bool brcmf_chip_sr_capable(struct brcmf_chip *pub); 91bool brcmf_chip_sr_capable(struct brcmf_chip *pub);
90 92
91#endif /* BRCMF_AXIDMP_H */ 93#endif /* BRCMF_AXIDMP_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
index 6262612dec45..4ec9811f49c8 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
@@ -481,10 +481,9 @@ static int brcmf_msgbuf_ioctl_resp_wait(struct brcmf_msgbuf *msgbuf)
481 481
482static void brcmf_msgbuf_ioctl_resp_wake(struct brcmf_msgbuf *msgbuf) 482static void brcmf_msgbuf_ioctl_resp_wake(struct brcmf_msgbuf *msgbuf)
483{ 483{
484 if (waitqueue_active(&msgbuf->ioctl_resp_wait)) { 484 msgbuf->ctl_completed = true;
485 msgbuf->ctl_completed = true; 485 if (waitqueue_active(&msgbuf->ioctl_resp_wait))
486 wake_up(&msgbuf->ioctl_resp_wait); 486 wake_up(&msgbuf->ioctl_resp_wait);
487 }
488} 487}
489 488
490 489
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.h b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.h
index 77a51b8c1e12..3d513e407e3d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.h
@@ -17,11 +17,11 @@
17 17
18#ifdef CONFIG_BRCMFMAC_PROTO_MSGBUF 18#ifdef CONFIG_BRCMFMAC_PROTO_MSGBUF
19 19
20#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT_MAX_ITEM 20 20#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT_MAX_ITEM 64
21#define BRCMF_H2D_MSGRING_RXPOST_SUBMIT_MAX_ITEM 256 21#define BRCMF_H2D_MSGRING_RXPOST_SUBMIT_MAX_ITEM 512
22#define BRCMF_D2H_MSGRING_CONTROL_COMPLETE_MAX_ITEM 20 22#define BRCMF_D2H_MSGRING_CONTROL_COMPLETE_MAX_ITEM 64
23#define BRCMF_D2H_MSGRING_TX_COMPLETE_MAX_ITEM 1024 23#define BRCMF_D2H_MSGRING_TX_COMPLETE_MAX_ITEM 1024
24#define BRCMF_D2H_MSGRING_RX_COMPLETE_MAX_ITEM 256 24#define BRCMF_D2H_MSGRING_RX_COMPLETE_MAX_ITEM 512
25#define BRCMF_H2D_TXFLOWRING_MAX_ITEM 512 25#define BRCMF_H2D_TXFLOWRING_MAX_ITEM 512
26 26
27#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT_ITEMSIZE 40 27#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT_ITEMSIZE 40
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
index 61c053a729be..1831ecd0813e 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
@@ -47,8 +47,6 @@ enum brcmf_pcie_state {
47 47
48#define BRCMF_PCIE_43602_FW_NAME "brcm/brcmfmac43602-pcie.bin" 48#define BRCMF_PCIE_43602_FW_NAME "brcm/brcmfmac43602-pcie.bin"
49#define BRCMF_PCIE_43602_NVRAM_NAME "brcm/brcmfmac43602-pcie.txt" 49#define BRCMF_PCIE_43602_NVRAM_NAME "brcm/brcmfmac43602-pcie.txt"
50#define BRCMF_PCIE_4354_FW_NAME "brcm/brcmfmac4354-pcie.bin"
51#define BRCMF_PCIE_4354_NVRAM_NAME "brcm/brcmfmac4354-pcie.txt"
52#define BRCMF_PCIE_4356_FW_NAME "brcm/brcmfmac4356-pcie.bin" 50#define BRCMF_PCIE_4356_FW_NAME "brcm/brcmfmac4356-pcie.bin"
53#define BRCMF_PCIE_4356_NVRAM_NAME "brcm/brcmfmac4356-pcie.txt" 51#define BRCMF_PCIE_4356_NVRAM_NAME "brcm/brcmfmac4356-pcie.txt"
54#define BRCMF_PCIE_43570_FW_NAME "brcm/brcmfmac43570-pcie.bin" 52#define BRCMF_PCIE_43570_FW_NAME "brcm/brcmfmac43570-pcie.bin"
@@ -187,8 +185,8 @@ enum brcmf_pcie_state {
187 185
188MODULE_FIRMWARE(BRCMF_PCIE_43602_FW_NAME); 186MODULE_FIRMWARE(BRCMF_PCIE_43602_FW_NAME);
189MODULE_FIRMWARE(BRCMF_PCIE_43602_NVRAM_NAME); 187MODULE_FIRMWARE(BRCMF_PCIE_43602_NVRAM_NAME);
190MODULE_FIRMWARE(BRCMF_PCIE_4354_FW_NAME); 188MODULE_FIRMWARE(BRCMF_PCIE_4356_FW_NAME);
191MODULE_FIRMWARE(BRCMF_PCIE_4354_NVRAM_NAME); 189MODULE_FIRMWARE(BRCMF_PCIE_4356_NVRAM_NAME);
192MODULE_FIRMWARE(BRCMF_PCIE_43570_FW_NAME); 190MODULE_FIRMWARE(BRCMF_PCIE_43570_FW_NAME);
193MODULE_FIRMWARE(BRCMF_PCIE_43570_NVRAM_NAME); 191MODULE_FIRMWARE(BRCMF_PCIE_43570_NVRAM_NAME);
194 192
@@ -509,8 +507,6 @@ static void brcmf_pcie_attach(struct brcmf_pciedev_info *devinfo)
509 507
510static int brcmf_pcie_enter_download_state(struct brcmf_pciedev_info *devinfo) 508static int brcmf_pcie_enter_download_state(struct brcmf_pciedev_info *devinfo)
511{ 509{
512 brcmf_chip_enter_download(devinfo->ci);
513
514 if (devinfo->ci->chip == BRCM_CC_43602_CHIP_ID) { 510 if (devinfo->ci->chip == BRCM_CC_43602_CHIP_ID) {
515 brcmf_pcie_select_core(devinfo, BCMA_CORE_ARM_CR4); 511 brcmf_pcie_select_core(devinfo, BCMA_CORE_ARM_CR4);
516 brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKIDX, 512 brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKIDX,
@@ -536,7 +532,7 @@ static int brcmf_pcie_exit_download_state(struct brcmf_pciedev_info *devinfo,
536 brcmf_chip_resetcore(core, 0, 0, 0); 532 brcmf_chip_resetcore(core, 0, 0, 0);
537 } 533 }
538 534
539 return !brcmf_chip_exit_download(devinfo->ci, resetintr); 535 return !brcmf_chip_set_active(devinfo->ci, resetintr);
540} 536}
541 537
542 538
@@ -653,10 +649,9 @@ static void brcmf_pcie_bus_console_read(struct brcmf_pciedev_info *devinfo)
653 console->log_str[console->log_idx] = ch; 649 console->log_str[console->log_idx] = ch;
654 console->log_idx++; 650 console->log_idx++;
655 } 651 }
656
657 if (ch == '\n') { 652 if (ch == '\n') {
658 console->log_str[console->log_idx] = 0; 653 console->log_str[console->log_idx] = 0;
659 brcmf_dbg(PCIE, "CONSOLE: %s\n", console->log_str); 654 brcmf_dbg(PCIE, "CONSOLE: %s", console->log_str);
660 console->log_idx = 0; 655 console->log_idx = 0;
661 } 656 }
662 } 657 }
@@ -1328,10 +1323,6 @@ static int brcmf_pcie_get_fwnames(struct brcmf_pciedev_info *devinfo)
1328 fw_name = BRCMF_PCIE_43602_FW_NAME; 1323 fw_name = BRCMF_PCIE_43602_FW_NAME;
1329 nvram_name = BRCMF_PCIE_43602_NVRAM_NAME; 1324 nvram_name = BRCMF_PCIE_43602_NVRAM_NAME;
1330 break; 1325 break;
1331 case BRCM_CC_4354_CHIP_ID:
1332 fw_name = BRCMF_PCIE_4354_FW_NAME;
1333 nvram_name = BRCMF_PCIE_4354_NVRAM_NAME;
1334 break;
1335 case BRCM_CC_4356_CHIP_ID: 1326 case BRCM_CC_4356_CHIP_ID:
1336 fw_name = BRCMF_PCIE_4356_FW_NAME; 1327 fw_name = BRCMF_PCIE_4356_FW_NAME;
1337 nvram_name = BRCMF_PCIE_4356_NVRAM_NAME; 1328 nvram_name = BRCMF_PCIE_4356_NVRAM_NAME;
@@ -1566,8 +1557,8 @@ static int brcmf_pcie_buscoreprep(void *ctx)
1566} 1557}
1567 1558
1568 1559
1569static void brcmf_pcie_buscore_exitdl(void *ctx, struct brcmf_chip *chip, 1560static void brcmf_pcie_buscore_activate(void *ctx, struct brcmf_chip *chip,
1570 u32 rstvec) 1561 u32 rstvec)
1571{ 1562{
1572 struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)ctx; 1563 struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)ctx;
1573 1564
@@ -1577,7 +1568,7 @@ static void brcmf_pcie_buscore_exitdl(void *ctx, struct brcmf_chip *chip,
1577 1568
1578static const struct brcmf_buscore_ops brcmf_pcie_buscore_ops = { 1569static const struct brcmf_buscore_ops brcmf_pcie_buscore_ops = {
1579 .prepare = brcmf_pcie_buscoreprep, 1570 .prepare = brcmf_pcie_buscoreprep,
1580 .exit_dl = brcmf_pcie_buscore_exitdl, 1571 .activate = brcmf_pcie_buscore_activate,
1581 .read32 = brcmf_pcie_buscore_read32, 1572 .read32 = brcmf_pcie_buscore_read32,
1582 .write32 = brcmf_pcie_buscore_write32, 1573 .write32 = brcmf_pcie_buscore_write32,
1583}; 1574};
@@ -1856,7 +1847,6 @@ cleanup:
1856 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, 0 } 1847 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, 0 }
1857 1848
1858static struct pci_device_id brcmf_pcie_devid_table[] = { 1849static struct pci_device_id brcmf_pcie_devid_table[] = {
1859 BRCMF_PCIE_DEVICE(BRCM_PCIE_4354_DEVICE_ID),
1860 BRCMF_PCIE_DEVICE(BRCM_PCIE_4356_DEVICE_ID), 1850 BRCMF_PCIE_DEVICE(BRCM_PCIE_4356_DEVICE_ID),
1861 BRCMF_PCIE_DEVICE(BRCM_PCIE_43567_DEVICE_ID), 1851 BRCMF_PCIE_DEVICE(BRCM_PCIE_43567_DEVICE_ID),
1862 BRCMF_PCIE_DEVICE(BRCM_PCIE_43570_DEVICE_ID), 1852 BRCMF_PCIE_DEVICE(BRCM_PCIE_43570_DEVICE_ID),
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
index 257ee70feb5b..ab0c89833013 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
@@ -432,8 +432,6 @@ struct brcmf_sdio {
432 struct brcmf_sdio_dev *sdiodev; /* sdio device handler */ 432 struct brcmf_sdio_dev *sdiodev; /* sdio device handler */
433 struct brcmf_chip *ci; /* Chip info struct */ 433 struct brcmf_chip *ci; /* Chip info struct */
434 434
435 u32 ramsize; /* Size of RAM in SOCRAM (bytes) */
436
437 u32 hostintmask; /* Copy of Host Interrupt Mask */ 435 u32 hostintmask; /* Copy of Host Interrupt Mask */
438 atomic_t intstatus; /* Intstatus bits (events) pending */ 436 atomic_t intstatus; /* Intstatus bits (events) pending */
439 atomic_t fcstate; /* State of dongle flow-control */ 437 atomic_t fcstate; /* State of dongle flow-control */
@@ -485,10 +483,9 @@ struct brcmf_sdio {
485#endif /* DEBUG */ 483#endif /* DEBUG */
486 484
487 uint clkstate; /* State of sd and backplane clock(s) */ 485 uint clkstate; /* State of sd and backplane clock(s) */
488 bool activity; /* Activity flag for clock down */
489 s32 idletime; /* Control for activity timeout */ 486 s32 idletime; /* Control for activity timeout */
490 s32 idlecount; /* Activity timeout counter */ 487 s32 idlecount; /* Activity timeout counter */
491 s32 idleclock; /* How to set bus driver when idle */ 488 s32 idleclock; /* How to set bus driver when idle */
492 bool rxflow_mode; /* Rx flow control mode */ 489 bool rxflow_mode; /* Rx flow control mode */
493 bool rxflow; /* Is rx flow control on */ 490 bool rxflow; /* Is rx flow control on */
494 bool alp_only; /* Don't use HT clock (ALP only) */ 491 bool alp_only; /* Don't use HT clock (ALP only) */
@@ -510,7 +507,8 @@ struct brcmf_sdio {
510 507
511 struct workqueue_struct *brcmf_wq; 508 struct workqueue_struct *brcmf_wq;
512 struct work_struct datawork; 509 struct work_struct datawork;
513 atomic_t dpc_tskcnt; 510 bool dpc_triggered;
511 bool dpc_running;
514 512
515 bool txoff; /* Transmit flow-controlled */ 513 bool txoff; /* Transmit flow-controlled */
516 struct brcmf_sdio_count sdcnt; 514 struct brcmf_sdio_count sdcnt;
@@ -617,6 +615,10 @@ static const struct sdiod_drive_str sdiod_drvstr_tab2_3v3[] = {
617#define BCM43362_NVRAM_NAME "brcm/brcmfmac43362-sdio.txt" 615#define BCM43362_NVRAM_NAME "brcm/brcmfmac43362-sdio.txt"
618#define BCM4339_FIRMWARE_NAME "brcm/brcmfmac4339-sdio.bin" 616#define BCM4339_FIRMWARE_NAME "brcm/brcmfmac4339-sdio.bin"
619#define BCM4339_NVRAM_NAME "brcm/brcmfmac4339-sdio.txt" 617#define BCM4339_NVRAM_NAME "brcm/brcmfmac4339-sdio.txt"
618#define BCM43430_FIRMWARE_NAME "brcm/brcmfmac43430-sdio.bin"
619#define BCM43430_NVRAM_NAME "brcm/brcmfmac43430-sdio.txt"
620#define BCM43455_FIRMWARE_NAME "brcm/brcmfmac43455-sdio.bin"
621#define BCM43455_NVRAM_NAME "brcm/brcmfmac43455-sdio.txt"
620#define BCM4354_FIRMWARE_NAME "brcm/brcmfmac4354-sdio.bin" 622#define BCM4354_FIRMWARE_NAME "brcm/brcmfmac4354-sdio.bin"
621#define BCM4354_NVRAM_NAME "brcm/brcmfmac4354-sdio.txt" 623#define BCM4354_NVRAM_NAME "brcm/brcmfmac4354-sdio.txt"
622 624
@@ -640,6 +642,10 @@ MODULE_FIRMWARE(BCM43362_FIRMWARE_NAME);
640MODULE_FIRMWARE(BCM43362_NVRAM_NAME); 642MODULE_FIRMWARE(BCM43362_NVRAM_NAME);
641MODULE_FIRMWARE(BCM4339_FIRMWARE_NAME); 643MODULE_FIRMWARE(BCM4339_FIRMWARE_NAME);
642MODULE_FIRMWARE(BCM4339_NVRAM_NAME); 644MODULE_FIRMWARE(BCM4339_NVRAM_NAME);
645MODULE_FIRMWARE(BCM43430_FIRMWARE_NAME);
646MODULE_FIRMWARE(BCM43430_NVRAM_NAME);
647MODULE_FIRMWARE(BCM43455_FIRMWARE_NAME);
648MODULE_FIRMWARE(BCM43455_NVRAM_NAME);
643MODULE_FIRMWARE(BCM4354_FIRMWARE_NAME); 649MODULE_FIRMWARE(BCM4354_FIRMWARE_NAME);
644MODULE_FIRMWARE(BCM4354_NVRAM_NAME); 650MODULE_FIRMWARE(BCM4354_NVRAM_NAME);
645 651
@@ -669,6 +675,8 @@ static const struct brcmf_firmware_names brcmf_fwname_data[] = {
669 { BRCM_CC_4335_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4335) }, 675 { BRCM_CC_4335_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4335) },
670 { BRCM_CC_43362_CHIP_ID, 0xFFFFFFFE, BRCMF_FIRMWARE_NVRAM(BCM43362) }, 676 { BRCM_CC_43362_CHIP_ID, 0xFFFFFFFE, BRCMF_FIRMWARE_NVRAM(BCM43362) },
671 { BRCM_CC_4339_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4339) }, 677 { BRCM_CC_4339_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4339) },
678 { BRCM_CC_43430_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM43430) },
679 { BRCM_CC_4345_CHIP_ID, 0xFFFFFFC0, BRCMF_FIRMWARE_NVRAM(BCM43455) },
672 { BRCM_CC_4354_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4354) } 680 { BRCM_CC_4354_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4354) }
673}; 681};
674 682
@@ -959,13 +967,8 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
959 brcmf_dbg(SDIO, "Enter\n"); 967 brcmf_dbg(SDIO, "Enter\n");
960 968
961 /* Early exit if we're already there */ 969 /* Early exit if we're already there */
962 if (bus->clkstate == target) { 970 if (bus->clkstate == target)
963 if (target == CLK_AVAIL) {
964 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
965 bus->activity = true;
966 }
967 return 0; 971 return 0;
968 }
969 972
970 switch (target) { 973 switch (target) {
971 case CLK_AVAIL: 974 case CLK_AVAIL:
@@ -974,8 +977,6 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
974 brcmf_sdio_sdclk(bus, true); 977 brcmf_sdio_sdclk(bus, true);
975 /* Now request HT Avail on the backplane */ 978 /* Now request HT Avail on the backplane */
976 brcmf_sdio_htclk(bus, true, pendok); 979 brcmf_sdio_htclk(bus, true, pendok);
977 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
978 bus->activity = true;
979 break; 980 break;
980 981
981 case CLK_SDONLY: 982 case CLK_SDONLY:
@@ -987,7 +988,6 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
987 else 988 else
988 brcmf_err("request for %d -> %d\n", 989 brcmf_err("request for %d -> %d\n",
989 bus->clkstate, target); 990 bus->clkstate, target);
990 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
991 break; 991 break;
992 992
993 case CLK_NONE: 993 case CLK_NONE:
@@ -996,7 +996,6 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
996 brcmf_sdio_htclk(bus, false, false); 996 brcmf_sdio_htclk(bus, false, false);
997 /* Now remove the SD clock */ 997 /* Now remove the SD clock */
998 brcmf_sdio_sdclk(bus, false); 998 brcmf_sdio_sdclk(bus, false);
999 brcmf_sdio_wd_timer(bus, 0);
1000 break; 999 break;
1001 } 1000 }
1002#ifdef DEBUG 1001#ifdef DEBUG
@@ -1024,17 +1023,6 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)
1024 1023
1025 /* Going to sleep */ 1024 /* Going to sleep */
1026 if (sleep) { 1025 if (sleep) {
1027 /* Don't sleep if something is pending */
1028 if (atomic_read(&bus->intstatus) ||
1029 atomic_read(&bus->ipend) > 0 ||
1030 bus->ctrl_frame_stat ||
1031 (!atomic_read(&bus->fcstate) &&
1032 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) &&
1033 data_ok(bus))) {
1034 err = -EBUSY;
1035 goto done;
1036 }
1037
1038 clkcsr = brcmf_sdiod_regrb(bus->sdiodev, 1026 clkcsr = brcmf_sdiod_regrb(bus->sdiodev,
1039 SBSDIO_FUNC1_CHIPCLKCSR, 1027 SBSDIO_FUNC1_CHIPCLKCSR,
1040 &err); 1028 &err);
@@ -1045,11 +1033,7 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)
1045 SBSDIO_ALP_AVAIL_REQ, &err); 1033 SBSDIO_ALP_AVAIL_REQ, &err);
1046 } 1034 }
1047 err = brcmf_sdio_kso_control(bus, false); 1035 err = brcmf_sdio_kso_control(bus, false);
1048 /* disable watchdog */
1049 if (!err)
1050 brcmf_sdio_wd_timer(bus, 0);
1051 } else { 1036 } else {
1052 bus->idlecount = 0;
1053 err = brcmf_sdio_kso_control(bus, true); 1037 err = brcmf_sdio_kso_control(bus, true);
1054 } 1038 }
1055 if (err) { 1039 if (err) {
@@ -1066,6 +1050,7 @@ end:
1066 brcmf_sdio_clkctl(bus, CLK_NONE, pendok); 1050 brcmf_sdio_clkctl(bus, CLK_NONE, pendok);
1067 } else { 1051 } else {
1068 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); 1052 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok);
1053 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
1069 } 1054 }
1070 bus->sleeping = sleep; 1055 bus->sleeping = sleep;
1071 brcmf_dbg(SDIO, "new state %s\n", 1056 brcmf_dbg(SDIO, "new state %s\n",
@@ -1085,44 +1070,47 @@ static inline bool brcmf_sdio_valid_shared_address(u32 addr)
1085static int brcmf_sdio_readshared(struct brcmf_sdio *bus, 1070static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
1086 struct sdpcm_shared *sh) 1071 struct sdpcm_shared *sh)
1087{ 1072{
1088 u32 addr; 1073 u32 addr = 0;
1089 int rv; 1074 int rv;
1090 u32 shaddr = 0; 1075 u32 shaddr = 0;
1091 struct sdpcm_shared_le sh_le; 1076 struct sdpcm_shared_le sh_le;
1092 __le32 addr_le; 1077 __le32 addr_le;
1093 1078
1094 shaddr = bus->ci->rambase + bus->ramsize - 4; 1079 sdio_claim_host(bus->sdiodev->func[1]);
1080 brcmf_sdio_bus_sleep(bus, false, false);
1095 1081
1096 /* 1082 /*
1097 * Read last word in socram to determine 1083 * Read last word in socram to determine
1098 * address of sdpcm_shared structure 1084 * address of sdpcm_shared structure
1099 */ 1085 */
1100 sdio_claim_host(bus->sdiodev->func[1]); 1086 shaddr = bus->ci->rambase + bus->ci->ramsize - 4;
1101 brcmf_sdio_bus_sleep(bus, false, false); 1087 if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci))
1102 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, (u8 *)&addr_le, 4); 1088 shaddr -= bus->ci->srsize;
1103 sdio_release_host(bus->sdiodev->func[1]); 1089 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr,
1090 (u8 *)&addr_le, 4);
1104 if (rv < 0) 1091 if (rv < 0)
1105 return rv; 1092 goto fail;
1106
1107 addr = le32_to_cpu(addr_le);
1108
1109 brcmf_dbg(SDIO, "sdpcm_shared address 0x%08X\n", addr);
1110 1093
1111 /* 1094 /*
1112 * Check if addr is valid. 1095 * Check if addr is valid.
1113 * NVRAM length at the end of memory should have been overwritten. 1096 * NVRAM length at the end of memory should have been overwritten.
1114 */ 1097 */
1098 addr = le32_to_cpu(addr_le);
1115 if (!brcmf_sdio_valid_shared_address(addr)) { 1099 if (!brcmf_sdio_valid_shared_address(addr)) {
1116 brcmf_err("invalid sdpcm_shared address 0x%08X\n", 1100 brcmf_err("invalid sdpcm_shared address 0x%08X\n", addr);
1117 addr); 1101 rv = -EINVAL;
1118 return -EINVAL; 1102 goto fail;
1119 } 1103 }
1120 1104
1105 brcmf_dbg(INFO, "sdpcm_shared address 0x%08X\n", addr);
1106
1121 /* Read hndrte_shared structure */ 1107 /* Read hndrte_shared structure */
1122 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, 1108 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le,
1123 sizeof(struct sdpcm_shared_le)); 1109 sizeof(struct sdpcm_shared_le));
1124 if (rv < 0) 1110 if (rv < 0)
1125 return rv; 1111 goto fail;
1112
1113 sdio_release_host(bus->sdiodev->func[1]);
1126 1114
1127 /* Endianness */ 1115 /* Endianness */
1128 sh->flags = le32_to_cpu(sh_le.flags); 1116 sh->flags = le32_to_cpu(sh_le.flags);
@@ -1139,8 +1127,13 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
1139 sh->flags & SDPCM_SHARED_VERSION_MASK); 1127 sh->flags & SDPCM_SHARED_VERSION_MASK);
1140 return -EPROTO; 1128 return -EPROTO;
1141 } 1129 }
1142
1143 return 0; 1130 return 0;
1131
1132fail:
1133 brcmf_err("unable to obtain sdpcm_shared info: rv=%d (addr=0x%x)\n",
1134 rv, addr);
1135 sdio_release_host(bus->sdiodev->func[1]);
1136 return rv;
1144} 1137}
1145 1138
1146static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) 1139static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus)
@@ -2721,11 +2714,14 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
2721 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && 2714 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) &&
2722 data_ok(bus)) { 2715 data_ok(bus)) {
2723 sdio_claim_host(bus->sdiodev->func[1]); 2716 sdio_claim_host(bus->sdiodev->func[1]);
2724 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, 2717 if (bus->ctrl_frame_stat) {
2725 bus->ctrl_frame_len); 2718 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf,
2719 bus->ctrl_frame_len);
2720 bus->ctrl_frame_err = err;
2721 wmb();
2722 bus->ctrl_frame_stat = false;
2723 }
2726 sdio_release_host(bus->sdiodev->func[1]); 2724 sdio_release_host(bus->sdiodev->func[1]);
2727 bus->ctrl_frame_err = err;
2728 bus->ctrl_frame_stat = false;
2729 brcmf_sdio_wait_event_wakeup(bus); 2725 brcmf_sdio_wait_event_wakeup(bus);
2730 } 2726 }
2731 /* Send queued frames (limit 1 if rx may still be pending) */ 2727 /* Send queued frames (limit 1 if rx may still be pending) */
@@ -2740,12 +2736,22 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
2740 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { 2736 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) {
2741 brcmf_err("failed backplane access over SDIO, halting operation\n"); 2737 brcmf_err("failed backplane access over SDIO, halting operation\n");
2742 atomic_set(&bus->intstatus, 0); 2738 atomic_set(&bus->intstatus, 0);
2739 if (bus->ctrl_frame_stat) {
2740 sdio_claim_host(bus->sdiodev->func[1]);
2741 if (bus->ctrl_frame_stat) {
2742 bus->ctrl_frame_err = -ENODEV;
2743 wmb();
2744 bus->ctrl_frame_stat = false;
2745 brcmf_sdio_wait_event_wakeup(bus);
2746 }
2747 sdio_release_host(bus->sdiodev->func[1]);
2748 }
2743 } else if (atomic_read(&bus->intstatus) || 2749 } else if (atomic_read(&bus->intstatus) ||
2744 atomic_read(&bus->ipend) > 0 || 2750 atomic_read(&bus->ipend) > 0 ||
2745 (!atomic_read(&bus->fcstate) && 2751 (!atomic_read(&bus->fcstate) &&
2746 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && 2752 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) &&
2747 data_ok(bus))) { 2753 data_ok(bus))) {
2748 atomic_inc(&bus->dpc_tskcnt); 2754 bus->dpc_triggered = true;
2749 } 2755 }
2750} 2756}
2751 2757
@@ -2941,20 +2947,27 @@ brcmf_sdio_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
2941 /* Send from dpc */ 2947 /* Send from dpc */
2942 bus->ctrl_frame_buf = msg; 2948 bus->ctrl_frame_buf = msg;
2943 bus->ctrl_frame_len = msglen; 2949 bus->ctrl_frame_len = msglen;
2950 wmb();
2944 bus->ctrl_frame_stat = true; 2951 bus->ctrl_frame_stat = true;
2945 2952
2946 brcmf_sdio_trigger_dpc(bus); 2953 brcmf_sdio_trigger_dpc(bus);
2947 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, 2954 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat,
2948 msecs_to_jiffies(CTL_DONE_TIMEOUT)); 2955 msecs_to_jiffies(CTL_DONE_TIMEOUT));
2949 2956 ret = 0;
2950 if (!bus->ctrl_frame_stat) { 2957 if (bus->ctrl_frame_stat) {
2958 sdio_claim_host(bus->sdiodev->func[1]);
2959 if (bus->ctrl_frame_stat) {
2960 brcmf_dbg(SDIO, "ctrl_frame timeout\n");
2961 bus->ctrl_frame_stat = false;
2962 ret = -ETIMEDOUT;
2963 }
2964 sdio_release_host(bus->sdiodev->func[1]);
2965 }
2966 if (!ret) {
2951 brcmf_dbg(SDIO, "ctrl_frame complete, err=%d\n", 2967 brcmf_dbg(SDIO, "ctrl_frame complete, err=%d\n",
2952 bus->ctrl_frame_err); 2968 bus->ctrl_frame_err);
2969 rmb();
2953 ret = bus->ctrl_frame_err; 2970 ret = bus->ctrl_frame_err;
2954 } else {
2955 brcmf_dbg(SDIO, "ctrl_frame timeout\n");
2956 bus->ctrl_frame_stat = false;
2957 ret = -ETIMEDOUT;
2958 } 2971 }
2959 2972
2960 if (ret) 2973 if (ret)
@@ -3358,9 +3371,6 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,
3358 sdio_claim_host(bus->sdiodev->func[1]); 3371 sdio_claim_host(bus->sdiodev->func[1]);
3359 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); 3372 brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
3360 3373
3361 /* Keep arm in reset */
3362 brcmf_chip_enter_download(bus->ci);
3363
3364 rstvec = get_unaligned_le32(fw->data); 3374 rstvec = get_unaligned_le32(fw->data);
3365 brcmf_dbg(SDIO, "firmware rstvec: %x\n", rstvec); 3375 brcmf_dbg(SDIO, "firmware rstvec: %x\n", rstvec);
3366 3376
@@ -3380,7 +3390,7 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,
3380 } 3390 }
3381 3391
3382 /* Take arm out of reset */ 3392 /* Take arm out of reset */
3383 if (!brcmf_chip_exit_download(bus->ci, rstvec)) { 3393 if (!brcmf_chip_set_active(bus->ci, rstvec)) {
3384 brcmf_err("error getting out of ARM core reset\n"); 3394 brcmf_err("error getting out of ARM core reset\n");
3385 goto err; 3395 goto err;
3386 } 3396 }
@@ -3525,8 +3535,8 @@ done:
3525 3535
3526void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) 3536void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus)
3527{ 3537{
3528 if (atomic_read(&bus->dpc_tskcnt) == 0) { 3538 if (!bus->dpc_triggered) {
3529 atomic_inc(&bus->dpc_tskcnt); 3539 bus->dpc_triggered = true;
3530 queue_work(bus->brcmf_wq, &bus->datawork); 3540 queue_work(bus->brcmf_wq, &bus->datawork);
3531 } 3541 }
3532} 3542}
@@ -3557,11 +3567,11 @@ void brcmf_sdio_isr(struct brcmf_sdio *bus)
3557 if (!bus->intr) 3567 if (!bus->intr)
3558 brcmf_err("isr w/o interrupt configured!\n"); 3568 brcmf_err("isr w/o interrupt configured!\n");
3559 3569
3560 atomic_inc(&bus->dpc_tskcnt); 3570 bus->dpc_triggered = true;
3561 queue_work(bus->brcmf_wq, &bus->datawork); 3571 queue_work(bus->brcmf_wq, &bus->datawork);
3562} 3572}
3563 3573
3564static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) 3574static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
3565{ 3575{
3566 brcmf_dbg(TIMER, "Enter\n"); 3576 brcmf_dbg(TIMER, "Enter\n");
3567 3577
@@ -3577,7 +3587,7 @@ static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
3577 if (!bus->intr || 3587 if (!bus->intr ||
3578 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { 3588 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) {
3579 3589
3580 if (atomic_read(&bus->dpc_tskcnt) == 0) { 3590 if (!bus->dpc_triggered) {
3581 u8 devpend; 3591 u8 devpend;
3582 3592
3583 sdio_claim_host(bus->sdiodev->func[1]); 3593 sdio_claim_host(bus->sdiodev->func[1]);
@@ -3595,7 +3605,7 @@ static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
3595 bus->sdcnt.pollcnt++; 3605 bus->sdcnt.pollcnt++;
3596 atomic_set(&bus->ipend, 1); 3606 atomic_set(&bus->ipend, 1);
3597 3607
3598 atomic_inc(&bus->dpc_tskcnt); 3608 bus->dpc_triggered = true;
3599 queue_work(bus->brcmf_wq, &bus->datawork); 3609 queue_work(bus->brcmf_wq, &bus->datawork);
3600 } 3610 }
3601 } 3611 }
@@ -3622,22 +3632,25 @@ static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
3622#endif /* DEBUG */ 3632#endif /* DEBUG */
3623 3633
3624 /* On idle timeout clear activity flag and/or turn off clock */ 3634 /* On idle timeout clear activity flag and/or turn off clock */
3625 if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { 3635 if (!bus->dpc_triggered) {
3626 if (++bus->idlecount >= bus->idletime) { 3636 rmb();
3627 bus->idlecount = 0; 3637 if ((!bus->dpc_running) && (bus->idletime > 0) &&
3628 if (bus->activity) { 3638 (bus->clkstate == CLK_AVAIL)) {
3629 bus->activity = false; 3639 bus->idlecount++;
3630 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); 3640 if (bus->idlecount > bus->idletime) {
3631 } else {
3632 brcmf_dbg(SDIO, "idle\n"); 3641 brcmf_dbg(SDIO, "idle\n");
3633 sdio_claim_host(bus->sdiodev->func[1]); 3642 sdio_claim_host(bus->sdiodev->func[1]);
3643 brcmf_sdio_wd_timer(bus, 0);
3644 bus->idlecount = 0;
3634 brcmf_sdio_bus_sleep(bus, true, false); 3645 brcmf_sdio_bus_sleep(bus, true, false);
3635 sdio_release_host(bus->sdiodev->func[1]); 3646 sdio_release_host(bus->sdiodev->func[1]);
3636 } 3647 }
3648 } else {
3649 bus->idlecount = 0;
3637 } 3650 }
3651 } else {
3652 bus->idlecount = 0;
3638 } 3653 }
3639
3640 return (atomic_read(&bus->ipend) > 0);
3641} 3654}
3642 3655
3643static void brcmf_sdio_dataworker(struct work_struct *work) 3656static void brcmf_sdio_dataworker(struct work_struct *work)
@@ -3645,10 +3658,14 @@ static void brcmf_sdio_dataworker(struct work_struct *work)
3645 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, 3658 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio,
3646 datawork); 3659 datawork);
3647 3660
3648 while (atomic_read(&bus->dpc_tskcnt)) { 3661 bus->dpc_running = true;
3649 atomic_set(&bus->dpc_tskcnt, 0); 3662 wmb();
3663 while (ACCESS_ONCE(bus->dpc_triggered)) {
3664 bus->dpc_triggered = false;
3650 brcmf_sdio_dpc(bus); 3665 brcmf_sdio_dpc(bus);
3666 bus->idlecount = 0;
3651 } 3667 }
3668 bus->dpc_running = false;
3652 if (brcmf_sdiod_freezing(bus->sdiodev)) { 3669 if (brcmf_sdiod_freezing(bus->sdiodev)) {
3653 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); 3670 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN);
3654 brcmf_sdiod_try_freeze(bus->sdiodev); 3671 brcmf_sdiod_try_freeze(bus->sdiodev);
@@ -3771,8 +3788,8 @@ static int brcmf_sdio_buscoreprep(void *ctx)
3771 return 0; 3788 return 0;
3772} 3789}
3773 3790
3774static void brcmf_sdio_buscore_exitdl(void *ctx, struct brcmf_chip *chip, 3791static void brcmf_sdio_buscore_activate(void *ctx, struct brcmf_chip *chip,
3775 u32 rstvec) 3792 u32 rstvec)
3776{ 3793{
3777 struct brcmf_sdio_dev *sdiodev = ctx; 3794 struct brcmf_sdio_dev *sdiodev = ctx;
3778 struct brcmf_core *core; 3795 struct brcmf_core *core;
@@ -3815,7 +3832,7 @@ static void brcmf_sdio_buscore_write32(void *ctx, u32 addr, u32 val)
3815 3832
3816static const struct brcmf_buscore_ops brcmf_sdio_buscore_ops = { 3833static const struct brcmf_buscore_ops brcmf_sdio_buscore_ops = {
3817 .prepare = brcmf_sdio_buscoreprep, 3834 .prepare = brcmf_sdio_buscoreprep,
3818 .exit_dl = brcmf_sdio_buscore_exitdl, 3835 .activate = brcmf_sdio_buscore_activate,
3819 .read32 = brcmf_sdio_buscore_read32, 3836 .read32 = brcmf_sdio_buscore_read32,
3820 .write32 = brcmf_sdio_buscore_write32, 3837 .write32 = brcmf_sdio_buscore_write32,
3821}; 3838};
@@ -3869,13 +3886,6 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
3869 drivestrength = DEFAULT_SDIO_DRIVE_STRENGTH; 3886 drivestrength = DEFAULT_SDIO_DRIVE_STRENGTH;
3870 brcmf_sdio_drivestrengthinit(bus->sdiodev, bus->ci, drivestrength); 3887 brcmf_sdio_drivestrengthinit(bus->sdiodev, bus->ci, drivestrength);
3871 3888
3872 /* Get info on the SOCRAM cores... */
3873 bus->ramsize = bus->ci->ramsize;
3874 if (!(bus->ramsize)) {
3875 brcmf_err("failed to find SOCRAM memory!\n");
3876 goto fail;
3877 }
3878
3879 /* Set card control so an SDIO card reset does a WLAN backplane reset */ 3889 /* Set card control so an SDIO card reset does a WLAN backplane reset */
3880 reg_val = brcmf_sdiod_regrb(bus->sdiodev, 3890 reg_val = brcmf_sdiod_regrb(bus->sdiodev,
3881 SDIO_CCCR_BRCM_CARDCTRL, &err); 3891 SDIO_CCCR_BRCM_CARDCTRL, &err);
@@ -4148,7 +4158,8 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
4148 bus->watchdog_tsk = NULL; 4158 bus->watchdog_tsk = NULL;
4149 } 4159 }
4150 /* Initialize DPC thread */ 4160 /* Initialize DPC thread */
4151 atomic_set(&bus->dpc_tskcnt, 0); 4161 bus->dpc_triggered = false;
4162 bus->dpc_running = false;
4152 4163
4153 /* Assign bus interface call back */ 4164 /* Assign bus interface call back */
4154 bus->sdiodev->bus_if->dev = bus->sdiodev->dev; 4165 bus->sdiodev->bus_if->dev = bus->sdiodev->dev;
@@ -4243,14 +4254,14 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
4243 if (bus->ci) { 4254 if (bus->ci) {
4244 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { 4255 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) {
4245 sdio_claim_host(bus->sdiodev->func[1]); 4256 sdio_claim_host(bus->sdiodev->func[1]);
4257 brcmf_sdio_wd_timer(bus, 0);
4246 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); 4258 brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
4247 /* Leave the device in state where it is 4259 /* Leave the device in state where it is
4248 * 'quiet'. This is done by putting it in 4260 * 'passive'. This is done by resetting all
4249 * download_state which essentially resets 4261 * necessary cores.
4250 * all necessary cores.
4251 */ 4262 */
4252 msleep(20); 4263 msleep(20);
4253 brcmf_chip_enter_download(bus->ci); 4264 brcmf_chip_set_passive(bus->ci);
4254 brcmf_sdio_clkctl(bus, CLK_NONE, false); 4265 brcmf_sdio_clkctl(bus, CLK_NONE, false);
4255 sdio_release_host(bus->sdiodev->func[1]); 4266 sdio_release_host(bus->sdiodev->func[1]);
4256 } 4267 }