Lines Matching refs:bus
734 static bool data_ok(struct brcmf_sdio *bus) in data_ok() argument
736 return (u8)(bus->tx_max - bus->tx_seq) != 0 && in data_ok()
737 ((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0; in data_ok()
744 static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset) in r_sdreg32() argument
749 core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in r_sdreg32()
750 *regvar = brcmf_sdiod_regrl(bus->sdiodev, core->base + offset, &ret); in r_sdreg32()
755 static int w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset) in w_sdreg32() argument
760 core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in w_sdreg32()
761 brcmf_sdiod_regwl(bus->sdiodev, core->base + reg_offset, regval, &ret); in w_sdreg32()
767 brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) in brcmf_sdio_kso_control() argument
777 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
804 rd_val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
810 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
827 static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok) in brcmf_sdio_htclk() argument
837 if (bus->sr_enabled) { in brcmf_sdio_htclk()
838 bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); in brcmf_sdio_htclk()
845 bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; in brcmf_sdio_htclk()
847 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
855 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
863 if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { in brcmf_sdio_htclk()
865 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
874 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
877 bus->clkstate = CLK_PENDING; in brcmf_sdio_htclk()
880 } else if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
882 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
885 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
892 while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
893 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
905 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
912 bus->clkstate = CLK_AVAIL; in brcmf_sdio_htclk()
916 if (!bus->alp_only) { in brcmf_sdio_htclk()
925 if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
927 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
930 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
934 bus->clkstate = CLK_SDONLY; in brcmf_sdio_htclk()
935 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
948 static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) in brcmf_sdio_sdclk() argument
953 bus->clkstate = CLK_SDONLY; in brcmf_sdio_sdclk()
955 bus->clkstate = CLK_NONE; in brcmf_sdio_sdclk()
961 static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) in brcmf_sdio_clkctl() argument
964 uint oldstate = bus->clkstate; in brcmf_sdio_clkctl()
970 if (bus->clkstate == target) in brcmf_sdio_clkctl()
976 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
977 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
979 brcmf_sdio_htclk(bus, true, pendok); in brcmf_sdio_clkctl()
984 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
985 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
986 else if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
987 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
990 bus->clkstate, target); in brcmf_sdio_clkctl()
995 if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
996 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
998 brcmf_sdio_sdclk(bus, false); in brcmf_sdio_clkctl()
1002 brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); in brcmf_sdio_clkctl()
1009 brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) in brcmf_sdio_bus_sleep() argument
1016 (bus->sleeping ? "SLEEP" : "WAKE")); in brcmf_sdio_bus_sleep()
1019 if (bus->sr_enabled) { in brcmf_sdio_bus_sleep()
1021 if (sleep == bus->sleeping) in brcmf_sdio_bus_sleep()
1026 clkcsr = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_bus_sleep()
1031 brcmf_sdiod_regwb(bus->sdiodev, in brcmf_sdio_bus_sleep()
1035 err = brcmf_sdio_kso_control(bus, false); in brcmf_sdio_bus_sleep()
1037 err = brcmf_sdio_kso_control(bus, true); in brcmf_sdio_bus_sleep()
1049 if (!bus->sr_enabled) in brcmf_sdio_bus_sleep()
1050 brcmf_sdio_clkctl(bus, CLK_NONE, pendok); in brcmf_sdio_bus_sleep()
1052 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); in brcmf_sdio_bus_sleep()
1053 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); in brcmf_sdio_bus_sleep()
1055 bus->sleeping = sleep; in brcmf_sdio_bus_sleep()
1070 static int brcmf_sdio_readshared(struct brcmf_sdio *bus, in brcmf_sdio_readshared() argument
1079 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readshared()
1080 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_readshared()
1086 shaddr = bus->ci->rambase + bus->ci->ramsize - 4; in brcmf_sdio_readshared()
1087 if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci)) in brcmf_sdio_readshared()
1088 shaddr -= bus->ci->srsize; in brcmf_sdio_readshared()
1089 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, in brcmf_sdio_readshared()
1108 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, in brcmf_sdio_readshared()
1113 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readshared()
1135 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readshared()
1139 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1143 if (brcmf_sdio_readshared(bus, &sh) == 0) in brcmf_sdio_get_console_addr()
1144 bus->console_addr = sh.console_addr; in brcmf_sdio_get_console_addr()
1147 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1152 static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus) in brcmf_sdio_hostmail() argument
1162 ret = r_sdreg32(bus, &hmb_data, in brcmf_sdio_hostmail()
1166 w_sdreg32(bus, SMB_INT_ACK, in brcmf_sdio_hostmail()
1168 bus->sdcnt.f1regdata += 2; in brcmf_sdio_hostmail()
1173 bus->rx_seq); in brcmf_sdio_hostmail()
1174 if (!bus->rxskip) in brcmf_sdio_hostmail()
1177 bus->rxskip = false; in brcmf_sdio_hostmail()
1185 bus->sdpcm_ver = in brcmf_sdio_hostmail()
1188 if (bus->sdpcm_ver != SDPCM_PROT_VERSION) in brcmf_sdio_hostmail()
1191 bus->sdpcm_ver, SDPCM_PROT_VERSION); in brcmf_sdio_hostmail()
1194 bus->sdpcm_ver); in brcmf_sdio_hostmail()
1200 brcmf_sdio_get_console_addr(bus); in brcmf_sdio_hostmail()
1212 if (fcbits & ~bus->flowcontrol) in brcmf_sdio_hostmail()
1213 bus->sdcnt.fc_xoff++; in brcmf_sdio_hostmail()
1215 if (bus->flowcontrol & ~fcbits) in brcmf_sdio_hostmail()
1216 bus->sdcnt.fc_xon++; in brcmf_sdio_hostmail()
1218 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hostmail()
1219 bus->flowcontrol = fcbits; in brcmf_sdio_hostmail()
1234 static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx) in brcmf_sdio_rxfail() argument
1246 brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2); in brcmf_sdio_rxfail()
1248 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, in brcmf_sdio_rxfail()
1250 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1254 hi = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_rxfail()
1256 lo = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_rxfail()
1258 bus->sdcnt.f1regdata += 2; in brcmf_sdio_rxfail()
1276 bus->sdcnt.rxrtx++; in brcmf_sdio_rxfail()
1277 err = w_sdreg32(bus, SMB_NAK, in brcmf_sdio_rxfail()
1280 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1282 bus->rxskip = true; in brcmf_sdio_rxfail()
1286 bus->cur_read.len = 0; in brcmf_sdio_rxfail()
1289 static void brcmf_sdio_txfail(struct brcmf_sdio *bus) in brcmf_sdio_txfail() argument
1291 struct brcmf_sdio_dev *sdiodev = bus->sdiodev; in brcmf_sdio_txfail()
1296 bus->sdcnt.tx_sderrs++; in brcmf_sdio_txfail()
1300 bus->sdcnt.f1regdata++; in brcmf_sdio_txfail()
1305 bus->sdcnt.f1regdata += 2; in brcmf_sdio_txfail()
1312 static uint brcmf_sdio_glom_len(struct brcmf_sdio *bus) in brcmf_sdio_glom_len() argument
1318 skb_queue_walk(&bus->glom, p) in brcmf_sdio_glom_len()
1323 static void brcmf_sdio_free_glom(struct brcmf_sdio *bus) in brcmf_sdio_free_glom() argument
1327 skb_queue_walk_safe(&bus->glom, cur, next) { in brcmf_sdio_free_glom()
1328 skb_unlink(cur, &bus->glom); in brcmf_sdio_free_glom()
1390 static int brcmf_sdio_hdparse(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdparse() argument
1405 bus->rxpending = false; in brcmf_sdio_hdparse()
1410 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1411 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1419 (roundup(len, bus->blocksize) != rd->len)) { in brcmf_sdio_hdparse()
1442 bus->sdcnt.rx_toolong++; in brcmf_sdio_hdparse()
1443 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1461 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1462 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1469 bus->sdcnt.rx_badseq++; in brcmf_sdio_hdparse()
1484 if (bus->flowcontrol != fc) { in brcmf_sdio_hdparse()
1485 if (~bus->flowcontrol & fc) in brcmf_sdio_hdparse()
1486 bus->sdcnt.fc_xoff++; in brcmf_sdio_hdparse()
1487 if (bus->flowcontrol & ~fc) in brcmf_sdio_hdparse()
1488 bus->sdcnt.fc_xon++; in brcmf_sdio_hdparse()
1489 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hdparse()
1490 bus->flowcontrol = fc; in brcmf_sdio_hdparse()
1493 if ((u8)(tx_seq_max - bus->tx_seq) > 0x40) { in brcmf_sdio_hdparse()
1495 tx_seq_max = bus->tx_seq + 2; in brcmf_sdio_hdparse()
1497 bus->tx_max = tx_seq_max; in brcmf_sdio_hdparse()
1508 static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdpack() argument
1517 if (bus->txglom) { in brcmf_sdio_hdpack()
1532 trace_brcmf_sdpcm_hdr(SDPCM_TX + !!(bus->txglom), header); in brcmf_sdio_hdpack()
1535 static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq) in brcmf_sdio_rxglom() argument
1551 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_rxglom()
1554 if (bus->glomd) { in brcmf_sdio_rxglom()
1556 dlen = (u16) (bus->glomd->len); in brcmf_sdio_rxglom()
1557 dptr = bus->glomd->data; in brcmf_sdio_rxglom()
1576 if (sublen % bus->sgentry_align) { in brcmf_sdio_rxglom()
1578 sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1586 (roundup(totlen, bus->blocksize) - totlen); in brcmf_sdio_rxglom()
1587 totlen = roundup(totlen, bus->blocksize); in brcmf_sdio_rxglom()
1591 pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align); in brcmf_sdio_rxglom()
1597 skb_queue_tail(&bus->glom, pnext); in brcmf_sdio_rxglom()
1600 pkt_align(pnext, sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1608 if (BRCMF_GLOM_ON() && bus->cur_read.len && in brcmf_sdio_rxglom()
1609 totlen != bus->cur_read.len) { in brcmf_sdio_rxglom()
1611 bus->cur_read.len, totlen, rxseq); in brcmf_sdio_rxglom()
1615 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1620 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_rxglom()
1621 bus->glomd = NULL; in brcmf_sdio_rxglom()
1622 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1627 if (!skb_queue_empty(&bus->glom)) { in brcmf_sdio_rxglom()
1630 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1637 pfirst = skb_peek(&bus->glom); in brcmf_sdio_rxglom()
1638 dlen = (u16) brcmf_sdio_glom_len(bus); in brcmf_sdio_rxglom()
1644 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1645 errcode = brcmf_sdiod_recv_chain(bus->sdiodev, in brcmf_sdio_rxglom()
1646 &bus->glom, dlen); in brcmf_sdio_rxglom()
1647 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1648 bus->sdcnt.f2rxdata++; in brcmf_sdio_rxglom()
1655 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1656 if (bus->glomerr++ < 3) { in brcmf_sdio_rxglom()
1657 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_rxglom()
1659 bus->glomerr = 0; in brcmf_sdio_rxglom()
1660 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1661 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1662 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1664 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1674 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1675 errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new, in brcmf_sdio_rxglom()
1677 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1678 bus->cur_read.len = rd_new.len_nxtfrm << 4; in brcmf_sdio_rxglom()
1686 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1693 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1694 errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new, in brcmf_sdio_rxglom()
1696 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1706 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1707 if (bus->glomerr++ < 3) { in brcmf_sdio_rxglom()
1710 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_rxglom()
1712 bus->glomerr = 0; in brcmf_sdio_rxglom()
1713 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1714 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1715 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1717 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1718 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1724 skb_queue_walk_safe(&bus->glom, pfirst, pnext) { in brcmf_sdio_rxglom()
1737 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1746 bus->glom.qlen, pfirst, pfirst->data, in brcmf_sdio_rxglom()
1749 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1750 brcmf_rx_frame(bus->sdiodev->dev, pfirst); in brcmf_sdio_rxglom()
1751 bus->sdcnt.rxglompkts++; in brcmf_sdio_rxglom()
1754 bus->sdcnt.rxglomframes++; in brcmf_sdio_rxglom()
1759 static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition, in brcmf_sdio_dcmd_resp_wait() argument
1766 add_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1776 remove_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1781 static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus) in brcmf_sdio_dcmd_resp_wake() argument
1783 if (waitqueue_active(&bus->dcmd_resp_wait)) in brcmf_sdio_dcmd_resp_wake()
1784 wake_up_interruptible(&bus->dcmd_resp_wait); in brcmf_sdio_dcmd_resp_wake()
1789 brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff) in brcmf_sdio_read_control() argument
1797 if (bus->rxblen) in brcmf_sdio_read_control()
1798 buf = vzalloc(bus->rxblen); in brcmf_sdio_read_control()
1802 rbuf = bus->rxbuf; in brcmf_sdio_read_control()
1803 pad = ((unsigned long)rbuf % bus->head_align); in brcmf_sdio_read_control()
1805 rbuf += (bus->head_align - pad); in brcmf_sdio_read_control()
1814 if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { in brcmf_sdio_read_control()
1815 pad = bus->blocksize - (rdlen % bus->blocksize); in brcmf_sdio_read_control()
1816 if ((pad <= bus->roundup) && (pad < bus->blocksize) && in brcmf_sdio_read_control()
1817 ((len + pad) < bus->sdiodev->bus_if->maxctl)) in brcmf_sdio_read_control()
1819 } else if (rdlen % bus->head_align) { in brcmf_sdio_read_control()
1820 rdlen += bus->head_align - (rdlen % bus->head_align); in brcmf_sdio_read_control()
1824 if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1826 rdlen, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1827 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1831 if ((len - doff) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1833 len, len - doff, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1834 bus->sdcnt.rx_toolong++; in brcmf_sdio_read_control()
1835 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1840 sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen); in brcmf_sdio_read_control()
1841 bus->sdcnt.f2rxdata++; in brcmf_sdio_read_control()
1847 bus->sdcnt.rxc_errors++; in brcmf_sdio_read_control()
1848 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_read_control()
1859 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1860 if (bus->rxctl) { in brcmf_sdio_read_control()
1862 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1866 bus->rxctl = buf + doff; in brcmf_sdio_read_control()
1867 bus->rxctl_orig = buf; in brcmf_sdio_read_control()
1868 bus->rxlen = len - doff; in brcmf_sdio_read_control()
1869 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1873 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_read_control()
1877 static void brcmf_sdio_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen) in brcmf_sdio_pad() argument
1879 if (bus->roundup && bus->blocksize && *rdlen > bus->blocksize) { in brcmf_sdio_pad()
1880 *pad = bus->blocksize - (*rdlen % bus->blocksize); in brcmf_sdio_pad()
1881 if (*pad <= bus->roundup && *pad < bus->blocksize && in brcmf_sdio_pad()
1884 } else if (*rdlen % bus->head_align) { in brcmf_sdio_pad()
1885 *rdlen += bus->head_align - (*rdlen % bus->head_align); in brcmf_sdio_pad()
1889 static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_readframes() argument
1896 struct brcmf_sdio_hdrinfo *rd = &bus->cur_read, rd_new; in brcmf_sdio_readframes()
1902 bus->rxpending = true; in brcmf_sdio_readframes()
1904 for (rd->seq_num = bus->rx_seq, rxleft = maxframes; in brcmf_sdio_readframes()
1905 !bus->rxskip && rxleft && bus->sdiodev->state == BRCMF_SDIOD_DATA; in brcmf_sdio_readframes()
1909 if (bus->glomd || !skb_queue_empty(&bus->glom)) { in brcmf_sdio_readframes()
1912 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_readframes()
1913 cnt = brcmf_sdio_rxglom(bus, rd->seq_num); in brcmf_sdio_readframes()
1922 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1924 ret = brcmf_sdiod_recv_buf(bus->sdiodev, in brcmf_sdio_readframes()
1925 bus->rxhdr, BRCMF_FIRSTREAD); in brcmf_sdio_readframes()
1926 bus->sdcnt.f2rxhdrs++; in brcmf_sdio_readframes()
1930 bus->sdcnt.rx_hdrfail++; in brcmf_sdio_readframes()
1931 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1932 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1937 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1940 if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd, in brcmf_sdio_readframes()
1942 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1943 if (!bus->rxpending) in brcmf_sdio_readframes()
1950 brcmf_sdio_read_control(bus, bus->rxhdr, in brcmf_sdio_readframes()
1958 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1966 brcmf_sdio_pad(bus, &pad, &rd->len_left); in brcmf_sdio_readframes()
1969 bus->head_align); in brcmf_sdio_readframes()
1973 brcmf_sdio_rxfail(bus, false, in brcmf_sdio_readframes()
1975 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1979 pkt_align(pkt, rd->len_left, bus->head_align); in brcmf_sdio_readframes()
1981 ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt); in brcmf_sdio_readframes()
1982 bus->sdcnt.f2rxdata++; in brcmf_sdio_readframes()
1983 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1989 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1990 brcmf_sdio_rxfail(bus, true, in brcmf_sdio_readframes()
1992 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1998 memcpy(pkt->data, bus->rxhdr, head_read); in brcmf_sdio_readframes()
2001 memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN); in brcmf_sdio_readframes()
2003 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2004 if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new, in brcmf_sdio_readframes()
2009 bus->sdcnt.rx_readahead_cnt++; in brcmf_sdio_readframes()
2015 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
2016 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2020 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2028 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
2036 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2037 brcmf_sdio_rxfail(bus, false, true); in brcmf_sdio_readframes()
2038 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2049 if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_HWHDR_LEN])) { in brcmf_sdio_readframes()
2057 bus->glomd = pkt; in brcmf_sdio_readframes()
2061 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2062 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_readframes()
2063 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2088 brcmf_rx_frame(bus->sdiodev->dev, pkt); in brcmf_sdio_readframes()
2098 if (bus->rxskip) in brcmf_sdio_readframes()
2100 bus->rx_seq = rd->seq_num; in brcmf_sdio_readframes()
2106 brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus) in brcmf_sdio_wait_event_wakeup() argument
2108 if (waitqueue_active(&bus->ctrl_wait)) in brcmf_sdio_wait_event_wakeup()
2109 wake_up_interruptible(&bus->ctrl_wait); in brcmf_sdio_wait_event_wakeup()
2113 static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt) in brcmf_sdio_txpkt_hdalign() argument
2121 head_pad = ((unsigned long)dat_buf % bus->head_align); in brcmf_sdio_txpkt_hdalign()
2124 bus->sdiodev->bus_if->tx_realloc++; in brcmf_sdio_txpkt_hdalign()
2131 memset(dat_buf, 0, head_pad + bus->tx_hdrlen); in brcmf_sdio_txpkt_hdalign()
2145 static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus, in brcmf_sdio_txpkt_prep_sg() argument
2156 sdiodev = bus->sdiodev; in brcmf_sdio_txpkt_prep_sg()
2159 WARN_ON(blksize % bus->sgentry_align); in brcmf_sdio_txpkt_prep_sg()
2164 tail_chop = pkt->len % bus->sgentry_align; in brcmf_sdio_txpkt_prep_sg()
2166 tail_pad = bus->sgentry_align - tail_chop; in brcmf_sdio_txpkt_prep_sg()
2172 bus->head_align); in brcmf_sdio_txpkt_prep_sg()
2175 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); in brcmf_sdio_txpkt_prep_sg()
2214 brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt_prep() argument
2223 txseq = bus->tx_seq; in brcmf_sdio_txpkt_prep()
2235 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_next); in brcmf_sdio_txpkt_prep()
2240 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad); in brcmf_sdio_txpkt_prep()
2246 if (bus->txglom && pktq->qlen > 1) { in brcmf_sdio_txpkt_prep()
2247 ret = brcmf_sdio_txpkt_prep_sg(bus, pktq, in brcmf_sdio_txpkt_prep()
2256 hd_info.dat_offset = head_pad + bus->tx_hdrlen; in brcmf_sdio_txpkt_prep()
2260 brcmf_sdio_hdpack(bus, pkt_next->data, &hd_info); in brcmf_sdio_txpkt_prep()
2269 head_pad + bus->tx_hdrlen, in brcmf_sdio_txpkt_prep()
2275 if (bus->txglom) in brcmf_sdio_txpkt_prep()
2290 brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq) in brcmf_sdio_txpkt_postp() argument
2309 hdr = pkt_next->data + bus->tx_hdrlen - SDPCM_SWHDR_LEN; in brcmf_sdio_txpkt_postp()
2314 if (bus->txglom) { in brcmf_sdio_txpkt_postp()
2324 static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt() argument
2332 ret = brcmf_sdio_txpkt_prep(bus, pktq, chan); in brcmf_sdio_txpkt()
2336 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_txpkt()
2337 ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq); in brcmf_sdio_txpkt()
2338 bus->sdcnt.f2txdata++; in brcmf_sdio_txpkt()
2341 brcmf_sdio_txfail(bus); in brcmf_sdio_txpkt()
2343 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_txpkt()
2346 brcmf_sdio_txpkt_postp(bus, pktq); in brcmf_sdio_txpkt()
2348 bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP; in brcmf_sdio_txpkt()
2351 brcmf_txcomplete(bus->sdiodev->dev, pkt_next, ret == 0); in brcmf_sdio_txpkt()
2356 static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_sendfromq() argument
2367 tx_prec_map = ~bus->flowcontrol; in brcmf_sdio_sendfromq()
2370 for (cnt = 0; (cnt < maxframes) && data_ok(bus);) { in brcmf_sdio_sendfromq()
2372 if (bus->txglom) in brcmf_sdio_sendfromq()
2373 pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, in brcmf_sdio_sendfromq()
2374 bus->sdiodev->txglomsz); in brcmf_sdio_sendfromq()
2376 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); in brcmf_sdio_sendfromq()
2378 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2380 pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, in brcmf_sdio_sendfromq()
2386 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2390 ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); in brcmf_sdio_sendfromq()
2395 if (!bus->intr) { in brcmf_sdio_sendfromq()
2397 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_sendfromq()
2398 ret = r_sdreg32(bus, &intstatus, in brcmf_sdio_sendfromq()
2401 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_sendfromq()
2402 bus->sdcnt.f2txdata++; in brcmf_sdio_sendfromq()
2405 if (intstatus & bus->hostintmask) in brcmf_sdio_sendfromq()
2406 atomic_set(&bus->ipend, 1); in brcmf_sdio_sendfromq()
2411 if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) && in brcmf_sdio_sendfromq()
2412 bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { in brcmf_sdio_sendfromq()
2413 bus->txoff = false; in brcmf_sdio_sendfromq()
2414 brcmf_txflowblock(bus->sdiodev->dev, false); in brcmf_sdio_sendfromq()
2420 static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len) in brcmf_sdio_tx_ctrlframe() argument
2431 frame -= bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2432 len += bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2435 doff = ((unsigned long)frame % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2439 memset(frame + bus->tx_hdrlen, 0, doff); in brcmf_sdio_tx_ctrlframe()
2444 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { in brcmf_sdio_tx_ctrlframe()
2445 pad = bus->blocksize - (len % bus->blocksize); in brcmf_sdio_tx_ctrlframe()
2446 if ((pad > bus->roundup) || (pad >= bus->blocksize)) in brcmf_sdio_tx_ctrlframe()
2448 } else if (len % bus->head_align) { in brcmf_sdio_tx_ctrlframe()
2449 pad = bus->head_align - (len % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2455 hd_info.dat_offset = doff + bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2456 hd_info.seq_num = bus->tx_seq; in brcmf_sdio_tx_ctrlframe()
2459 brcmf_sdio_hdpack(bus, frame, &hd_info); in brcmf_sdio_tx_ctrlframe()
2461 if (bus->txglom) in brcmf_sdio_tx_ctrlframe()
2471 ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); in brcmf_sdio_tx_ctrlframe()
2474 brcmf_sdio_txfail(bus); in brcmf_sdio_tx_ctrlframe()
2476 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; in brcmf_sdio_tx_ctrlframe()
2489 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_stop() local
2493 if (bus->watchdog_tsk) { in brcmf_sdio_bus_stop()
2494 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_bus_stop()
2495 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_bus_stop()
2496 bus->watchdog_tsk = NULL; in brcmf_sdio_bus_stop()
2503 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_stop()
2506 w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask)); in brcmf_sdio_bus_stop()
2507 local_hostintmask = bus->hostintmask; in brcmf_sdio_bus_stop()
2508 bus->hostintmask = 0; in brcmf_sdio_bus_stop()
2525 w_sdreg32(bus, local_hostintmask, in brcmf_sdio_bus_stop()
2531 brcmu_pktq_flush(&bus->txq, true, NULL, NULL); in brcmf_sdio_bus_stop()
2534 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_bus_stop()
2535 brcmf_sdio_free_glom(bus); in brcmf_sdio_bus_stop()
2538 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2539 bus->rxlen = 0; in brcmf_sdio_bus_stop()
2540 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2541 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_bus_stop()
2544 bus->rxskip = false; in brcmf_sdio_bus_stop()
2545 bus->tx_seq = bus->rx_seq = 0; in brcmf_sdio_bus_stop()
2548 static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) in brcmf_sdio_clrintr() argument
2552 if (bus->sdiodev->oob_irq_requested) { in brcmf_sdio_clrintr()
2553 spin_lock_irqsave(&bus->sdiodev->irq_en_lock, flags); in brcmf_sdio_clrintr()
2554 if (!bus->sdiodev->irq_en && !atomic_read(&bus->ipend)) { in brcmf_sdio_clrintr()
2555 enable_irq(bus->sdiodev->pdata->oob_irq_nr); in brcmf_sdio_clrintr()
2556 bus->sdiodev->irq_en = true; in brcmf_sdio_clrintr()
2558 spin_unlock_irqrestore(&bus->sdiodev->irq_en_lock, flags); in brcmf_sdio_clrintr()
2571 static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) in brcmf_sdio_intr_rstatus() argument
2578 buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in brcmf_sdio_intr_rstatus()
2581 val = brcmf_sdiod_regrl(bus->sdiodev, addr, &ret); in brcmf_sdio_intr_rstatus()
2582 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2586 val &= bus->hostintmask; in brcmf_sdio_intr_rstatus()
2587 atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); in brcmf_sdio_intr_rstatus()
2591 brcmf_sdiod_regwl(bus->sdiodev, addr, val, &ret); in brcmf_sdio_intr_rstatus()
2592 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2593 atomic_orr(val, &bus->intstatus); in brcmf_sdio_intr_rstatus()
2599 static void brcmf_sdio_dpc(struct brcmf_sdio *bus) in brcmf_sdio_dpc() argument
2603 uint txlimit = bus->txbound; /* Tx frames to send before resched */ in brcmf_sdio_dpc()
2609 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2612 if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { in brcmf_sdio_dpc()
2617 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_dpc()
2622 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_dpc()
2629 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_dpc()
2632 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_dpc()
2634 bus->clkstate = CLK_AVAIL; in brcmf_sdio_dpc()
2639 brcmf_sdio_bus_sleep(bus, false, true); in brcmf_sdio_dpc()
2642 if (atomic_read(&bus->ipend) > 0) { in brcmf_sdio_dpc()
2643 atomic_set(&bus->ipend, 0); in brcmf_sdio_dpc()
2644 err = brcmf_sdio_intr_rstatus(bus); in brcmf_sdio_dpc()
2648 intstatus = atomic_xchg(&bus->intstatus, 0); in brcmf_sdio_dpc()
2656 err = w_sdreg32(bus, I_HMB_FC_CHANGE, in brcmf_sdio_dpc()
2659 err = r_sdreg32(bus, &newstatus, in brcmf_sdio_dpc()
2661 bus->sdcnt.f1regdata += 2; in brcmf_sdio_dpc()
2662 atomic_set(&bus->fcstate, in brcmf_sdio_dpc()
2664 intstatus |= (newstatus & bus->hostintmask); in brcmf_sdio_dpc()
2670 intstatus |= brcmf_sdio_hostmail(bus); in brcmf_sdio_dpc()
2673 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2698 if (bus->rxskip) in brcmf_sdio_dpc()
2702 if ((intstatus & I_HMB_FRAME_IND) && (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_dpc()
2703 brcmf_sdio_readframes(bus, bus->rxbound); in brcmf_sdio_dpc()
2704 if (!bus->rxpending) in brcmf_sdio_dpc()
2710 atomic_orr(intstatus, &bus->intstatus); in brcmf_sdio_dpc()
2712 brcmf_sdio_clrintr(bus); in brcmf_sdio_dpc()
2714 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && in brcmf_sdio_dpc()
2715 data_ok(bus)) { in brcmf_sdio_dpc()
2716 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2717 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2718 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, in brcmf_sdio_dpc()
2719 bus->ctrl_frame_len); in brcmf_sdio_dpc()
2720 bus->ctrl_frame_err = err; in brcmf_sdio_dpc()
2722 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2724 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2725 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2728 if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2729 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit && in brcmf_sdio_dpc()
2730 data_ok(bus)) { in brcmf_sdio_dpc()
2731 framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : in brcmf_sdio_dpc()
2733 brcmf_sdio_sendfromq(bus, framecnt); in brcmf_sdio_dpc()
2736 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { in brcmf_sdio_dpc()
2738 atomic_set(&bus->intstatus, 0); in brcmf_sdio_dpc()
2739 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2740 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2741 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2742 bus->ctrl_frame_err = -ENODEV; in brcmf_sdio_dpc()
2744 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2745 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2747 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2749 } else if (atomic_read(&bus->intstatus) || in brcmf_sdio_dpc()
2750 atomic_read(&bus->ipend) > 0 || in brcmf_sdio_dpc()
2751 (!atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2752 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && in brcmf_sdio_dpc()
2753 data_ok(bus))) { in brcmf_sdio_dpc()
2754 bus->dpc_triggered = true; in brcmf_sdio_dpc()
2762 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_gettxq() local
2764 return &bus->txq; in brcmf_sdio_bus_gettxq()
2815 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txdata() local
2820 skb_push(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2827 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); in brcmf_sdio_bus_txdata()
2828 bus->sdcnt.fcqueued++; in brcmf_sdio_bus_txdata()
2831 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2834 if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) { in brcmf_sdio_bus_txdata()
2835 skb_pull(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2842 if (pktq_len(&bus->txq) >= TXHI) { in brcmf_sdio_bus_txdata()
2843 bus->txoff = true; in brcmf_sdio_bus_txdata()
2846 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2849 if (pktq_plen(&bus->txq, prec) > qcount[prec]) in brcmf_sdio_bus_txdata()
2850 qcount[prec] = pktq_plen(&bus->txq, prec); in brcmf_sdio_bus_txdata()
2853 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txdata()
2860 static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) in brcmf_sdio_readconsole() argument
2862 struct brcmf_console *c = &bus->console; in brcmf_sdio_readconsole()
2868 if (bus->console_addr == 0) in brcmf_sdio_readconsole()
2872 addr = bus->console_addr + offsetof(struct rte_console, log_le); in brcmf_sdio_readconsole()
2873 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, in brcmf_sdio_readconsole()
2899 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize); in brcmf_sdio_readconsole()
2942 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txctl() local
2948 bus->ctrl_frame_buf = msg; in brcmf_sdio_bus_txctl()
2949 bus->ctrl_frame_len = msglen; in brcmf_sdio_bus_txctl()
2951 bus->ctrl_frame_stat = true; in brcmf_sdio_bus_txctl()
2953 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txctl()
2954 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, in brcmf_sdio_bus_txctl()
2957 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2958 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_txctl()
2959 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2961 bus->ctrl_frame_stat = false; in brcmf_sdio_bus_txctl()
2964 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_txctl()
2968 bus->ctrl_frame_err); in brcmf_sdio_bus_txctl()
2970 ret = bus->ctrl_frame_err; in brcmf_sdio_bus_txctl()
2974 bus->sdcnt.tx_ctlerrs++; in brcmf_sdio_bus_txctl()
2976 bus->sdcnt.tx_ctlpkts++; in brcmf_sdio_bus_txctl()
2982 static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_dump_console() argument
2992 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2999 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
3006 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
3021 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, in brcmf_sdio_dump_console()
3039 static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_trap_info() argument
3050 error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, in brcmf_sdio_trap_info()
3073 static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_assert_info() argument
3088 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_assert_info()
3090 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3096 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3101 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_assert_info()
3108 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3113 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_checkdied()
3129 static int brcmf_sdio_died_dump(struct seq_file *seq, struct brcmf_sdio *bus) in brcmf_sdio_died_dump() argument
3134 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_died_dump()
3138 error = brcmf_sdio_assert_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3142 error = brcmf_sdio_trap_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3146 error = brcmf_sdio_dump_console(seq, bus, &sh); in brcmf_sdio_died_dump()
3155 struct brcmf_sdio *bus = bus_if->bus_priv.sdio->bus; in brcmf_sdio_forensic_read() local
3157 return brcmf_sdio_died_dump(seq, bus); in brcmf_sdio_forensic_read()
3164 struct brcmf_sdio_count *sdcnt = &sdiodev->bus->sdcnt; in brcmf_debugfs_sdio_count_read()
3199 static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) in brcmf_sdio_debugfs_create() argument
3201 struct brcmf_pub *drvr = bus->sdiodev->bus_if->drvr; in brcmf_sdio_debugfs_create()
3211 &bus->console_interval); in brcmf_sdio_debugfs_create()
3214 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3219 static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) in brcmf_sdio_debugfs_create() argument
3233 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_rxctl() local
3238 timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); in brcmf_sdio_bus_rxctl()
3240 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3241 rxlen = bus->rxlen; in brcmf_sdio_bus_rxctl()
3242 memcpy(msg, bus->rxctl, min(msglen, rxlen)); in brcmf_sdio_bus_rxctl()
3243 bus->rxctl = NULL; in brcmf_sdio_bus_rxctl()
3244 buf = bus->rxctl_orig; in brcmf_sdio_bus_rxctl()
3245 bus->rxctl_orig = NULL; in brcmf_sdio_bus_rxctl()
3246 bus->rxlen = 0; in brcmf_sdio_bus_rxctl()
3247 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3255 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3261 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3265 bus->sdcnt.rx_ctlpkts++; in brcmf_sdio_bus_rxctl()
3267 bus->sdcnt.rx_ctlerrs++; in brcmf_sdio_bus_rxctl()
3326 static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, in brcmf_sdio_download_code_file() argument
3333 err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase, in brcmf_sdio_download_code_file()
3337 err, (int)fw->size, bus->ci->rambase); in brcmf_sdio_download_code_file()
3338 else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, in brcmf_sdio_download_code_file()
3345 static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, in brcmf_sdio_download_nvram() argument
3353 address = bus->ci->ramsize - varsz + bus->ci->rambase; in brcmf_sdio_download_nvram()
3354 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); in brcmf_sdio_download_nvram()
3358 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) in brcmf_sdio_download_nvram()
3364 static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus, in brcmf_sdio_download_firmware() argument
3371 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_download_firmware()
3372 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_download_firmware()
3377 bcmerror = brcmf_sdio_download_code_file(bus, fw); in brcmf_sdio_download_firmware()
3385 bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen); in brcmf_sdio_download_firmware()
3393 if (!brcmf_chip_set_active(bus->ci, rstvec)) { in brcmf_sdio_download_firmware()
3399 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_download_firmware()
3403 brcmf_sdio_clkctl(bus, CLK_SDONLY, false); in brcmf_sdio_download_firmware()
3404 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_download_firmware()
3408 static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) in brcmf_sdio_sr_init() argument
3415 val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); in brcmf_sdio_sr_init()
3422 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); in brcmf_sdio_sr_init()
3429 brcmf_sdiod_regwb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, in brcmf_sdio_sr_init()
3438 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_sr_init()
3446 bus->sr_enabled = true; in brcmf_sdio_sr_init()
3451 static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) in brcmf_sdio_kso_init() argument
3459 if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12) in brcmf_sdio_kso_init()
3462 val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); in brcmf_sdio_kso_init()
3471 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_init()
3487 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_preinit() local
3496 if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12) { in brcmf_sdio_bus_preinit()
3515 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_bus_preinit()
3517 bus->txglom = false; in brcmf_sdio_bus_preinit()
3519 pad_size = bus->sdiodev->func[2]->cur_blksize << 1; in brcmf_sdio_bus_preinit()
3520 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", in brcmf_sdio_bus_preinit()
3526 bus->txglom = true; in brcmf_sdio_bus_preinit()
3527 bus->tx_hdrlen += SDPCM_HWEXT_LEN; in brcmf_sdio_bus_preinit()
3530 brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); in brcmf_sdio_bus_preinit()
3536 void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) in brcmf_sdio_trigger_dpc() argument
3538 if (!bus->dpc_triggered) { in brcmf_sdio_trigger_dpc()
3539 bus->dpc_triggered = true; in brcmf_sdio_trigger_dpc()
3540 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_trigger_dpc()
3544 void brcmf_sdio_isr(struct brcmf_sdio *bus) in brcmf_sdio_isr() argument
3548 if (!bus) { in brcmf_sdio_isr()
3553 if (bus->sdiodev->state != BRCMF_SDIOD_DATA) { in brcmf_sdio_isr()
3558 bus->sdcnt.intrcount++; in brcmf_sdio_isr()
3560 atomic_set(&bus->ipend, 1); in brcmf_sdio_isr()
3562 if (brcmf_sdio_intr_rstatus(bus)) { in brcmf_sdio_isr()
3567 if (!bus->intr) in brcmf_sdio_isr()
3570 bus->dpc_triggered = true; in brcmf_sdio_isr()
3571 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_isr()
3574 static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) in brcmf_sdio_bus_watchdog() argument
3579 if (!bus->sr_enabled && in brcmf_sdio_bus_watchdog()
3580 bus->poll && (++bus->polltick >= bus->pollrate)) { in brcmf_sdio_bus_watchdog()
3584 bus->polltick = 0; in brcmf_sdio_bus_watchdog()
3587 if (!bus->intr || in brcmf_sdio_bus_watchdog()
3588 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { in brcmf_sdio_bus_watchdog()
3590 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3593 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3594 devpend = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_bus_watchdog()
3597 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3605 bus->sdcnt.pollcnt++; in brcmf_sdio_bus_watchdog()
3606 atomic_set(&bus->ipend, 1); in brcmf_sdio_bus_watchdog()
3608 bus->dpc_triggered = true; in brcmf_sdio_bus_watchdog()
3609 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_bus_watchdog()
3614 bus->sdcnt.lastintrs = bus->sdcnt.intrcount; in brcmf_sdio_bus_watchdog()
3618 if (bus->sdiodev->state == BRCMF_SDIOD_DATA && in brcmf_sdio_bus_watchdog()
3619 bus->console_interval != 0) { in brcmf_sdio_bus_watchdog()
3620 bus->console.count += BRCMF_WD_POLL_MS; in brcmf_sdio_bus_watchdog()
3621 if (bus->console.count >= bus->console_interval) { in brcmf_sdio_bus_watchdog()
3622 bus->console.count -= bus->console_interval; in brcmf_sdio_bus_watchdog()
3623 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3625 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_watchdog()
3626 if (brcmf_sdio_readconsole(bus) < 0) in brcmf_sdio_bus_watchdog()
3628 bus->console_interval = 0; in brcmf_sdio_bus_watchdog()
3629 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3635 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3637 if ((!bus->dpc_running) && (bus->idletime > 0) && in brcmf_sdio_bus_watchdog()
3638 (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_bus_watchdog()
3639 bus->idlecount++; in brcmf_sdio_bus_watchdog()
3640 if (bus->idlecount > bus->idletime) { in brcmf_sdio_bus_watchdog()
3642 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3643 brcmf_sdio_wd_timer(bus, 0); in brcmf_sdio_bus_watchdog()
3644 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3645 brcmf_sdio_bus_sleep(bus, true, false); in brcmf_sdio_bus_watchdog()
3646 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3649 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3652 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3658 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, in brcmf_sdio_dataworker() local
3661 bus->dpc_running = true; in brcmf_sdio_dataworker()
3663 while (ACCESS_ONCE(bus->dpc_triggered)) { in brcmf_sdio_dataworker()
3664 bus->dpc_triggered = false; in brcmf_sdio_dataworker()
3665 brcmf_sdio_dpc(bus); in brcmf_sdio_dataworker()
3666 bus->idlecount = 0; in brcmf_sdio_dataworker()
3668 bus->dpc_running = false; in brcmf_sdio_dataworker()
3669 if (brcmf_sdiod_freezing(bus->sdiodev)) { in brcmf_sdio_dataworker()
3670 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); in brcmf_sdio_dataworker()
3671 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_dataworker()
3672 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_dataworker()
3841 brcmf_sdio_probe_attach(struct brcmf_sdio *bus) in brcmf_sdio_probe_attach() argument
3849 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_probe_attach()
3852 brcmf_sdiod_regrl(bus->sdiodev, SI_ENUM_BASE, NULL)); in brcmf_sdio_probe_attach()
3859 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_probe_attach()
3862 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_probe_attach()
3871 bus->ci = brcmf_chip_attach(bus->sdiodev, &brcmf_sdio_buscore_ops); in brcmf_sdio_probe_attach()
3872 if (IS_ERR(bus->ci)) { in brcmf_sdio_probe_attach()
3874 bus->ci = NULL; in brcmf_sdio_probe_attach()
3878 if (brcmf_sdio_kso_init(bus)) { in brcmf_sdio_probe_attach()
3883 if ((bus->sdiodev->pdata) && (bus->sdiodev->pdata->drive_strength)) in brcmf_sdio_probe_attach()
3884 drivestrength = bus->sdiodev->pdata->drive_strength; in brcmf_sdio_probe_attach()
3887 brcmf_sdio_drivestrengthinit(bus->sdiodev, bus->ci, drivestrength); in brcmf_sdio_probe_attach()
3890 reg_val = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_probe_attach()
3897 brcmf_sdiod_regwb(bus->sdiodev, in brcmf_sdio_probe_attach()
3903 reg_addr = CORE_CC_REG(brcmf_chip_get_chipcommon(bus->ci)->base, in brcmf_sdio_probe_attach()
3905 reg_val = brcmf_sdiod_regrl(bus->sdiodev, reg_addr, &err); in brcmf_sdio_probe_attach()
3911 brcmf_sdiod_regwl(bus->sdiodev, reg_addr, reg_val, &err); in brcmf_sdio_probe_attach()
3915 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_probe_attach()
3917 brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); in brcmf_sdio_probe_attach()
3920 bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); in brcmf_sdio_probe_attach()
3921 if (!bus->hdrbuf) in brcmf_sdio_probe_attach()
3924 bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], in brcmf_sdio_probe_attach()
3925 bus->head_align); in brcmf_sdio_probe_attach()
3928 bus->intr = true; in brcmf_sdio_probe_attach()
3929 bus->poll = false; in brcmf_sdio_probe_attach()
3930 if (bus->poll) in brcmf_sdio_probe_attach()
3931 bus->pollrate = 1; in brcmf_sdio_probe_attach()
3936 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_probe_attach()
3943 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog_thread() local
3948 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3952 brcmf_sdiod_freezer_uncount(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3953 wait = wait_for_completion_interruptible(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
3954 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3955 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3957 brcmf_sdio_bus_watchdog(bus); in brcmf_sdio_watchdog_thread()
3959 bus->sdcnt.tickcnt++; in brcmf_sdio_watchdog_thread()
3960 reinit_completion(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
3970 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog() local
3972 if (bus->watchdog_tsk) { in brcmf_sdio_watchdog()
3973 complete(&bus->watchdog_wait); in brcmf_sdio_watchdog()
3975 if (bus->wd_timer_valid) in brcmf_sdio_watchdog()
3976 mod_timer(&bus->timer, in brcmf_sdio_watchdog()
3997 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_firmware_callback() local
4007 bus->alp_only = true; in brcmf_sdio_firmware_callback()
4008 err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len); in brcmf_sdio_firmware_callback()
4011 bus->alp_only = false; in brcmf_sdio_firmware_callback()
4014 bus->sdcnt.tickcnt = 0; in brcmf_sdio_firmware_callback()
4015 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); in brcmf_sdio_firmware_callback()
4020 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_firmware_callback()
4021 if (bus->clkstate != CLK_AVAIL) in brcmf_sdio_firmware_callback()
4036 w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, in brcmf_sdio_firmware_callback()
4046 bus->hostintmask = HOSTINTMASK; in brcmf_sdio_firmware_callback()
4047 w_sdreg32(bus, bus->hostintmask, in brcmf_sdio_firmware_callback()
4057 if (brcmf_chip_sr_capable(bus->ci)) { in brcmf_sdio_firmware_callback()
4058 brcmf_sdio_sr_init(bus); in brcmf_sdio_firmware_callback()
4073 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_firmware_callback()
4094 struct brcmf_sdio *bus; in brcmf_sdio_probe() local
4100 bus = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); in brcmf_sdio_probe()
4101 if (!bus) in brcmf_sdio_probe()
4104 bus->sdiodev = sdiodev; in brcmf_sdio_probe()
4105 sdiodev->bus = bus; in brcmf_sdio_probe()
4106 skb_queue_head_init(&bus->glom); in brcmf_sdio_probe()
4107 bus->txbound = BRCMF_TXBOUND; in brcmf_sdio_probe()
4108 bus->rxbound = BRCMF_RXBOUND; in brcmf_sdio_probe()
4109 bus->txminmax = BRCMF_TXMINMAX; in brcmf_sdio_probe()
4110 bus->tx_seq = SDPCM_SEQ_WRAP - 1; in brcmf_sdio_probe()
4115 bus->head_align = ALIGNMENT; in brcmf_sdio_probe()
4116 bus->sgentry_align = ALIGNMENT; in brcmf_sdio_probe()
4119 bus->head_align = sdiodev->pdata->sd_head_align; in brcmf_sdio_probe()
4121 bus->sgentry_align = sdiodev->pdata->sd_sgentry_align; in brcmf_sdio_probe()
4132 INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); in brcmf_sdio_probe()
4133 bus->brcmf_wq = wq; in brcmf_sdio_probe()
4136 if (!(brcmf_sdio_probe_attach(bus))) { in brcmf_sdio_probe()
4141 spin_lock_init(&bus->rxctl_lock); in brcmf_sdio_probe()
4142 spin_lock_init(&bus->txq_lock); in brcmf_sdio_probe()
4143 init_waitqueue_head(&bus->ctrl_wait); in brcmf_sdio_probe()
4144 init_waitqueue_head(&bus->dcmd_resp_wait); in brcmf_sdio_probe()
4147 init_timer(&bus->timer); in brcmf_sdio_probe()
4148 bus->timer.data = (unsigned long)bus; in brcmf_sdio_probe()
4149 bus->timer.function = brcmf_sdio_watchdog; in brcmf_sdio_probe()
4152 init_completion(&bus->watchdog_wait); in brcmf_sdio_probe()
4153 bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, in brcmf_sdio_probe()
4154 bus, "brcmf_wdog/%s", in brcmf_sdio_probe()
4156 if (IS_ERR(bus->watchdog_tsk)) { in brcmf_sdio_probe()
4158 bus->watchdog_tsk = NULL; in brcmf_sdio_probe()
4161 bus->dpc_triggered = false; in brcmf_sdio_probe()
4162 bus->dpc_running = false; in brcmf_sdio_probe()
4165 bus->sdiodev->bus_if->dev = bus->sdiodev->dev; in brcmf_sdio_probe()
4166 bus->sdiodev->bus_if->ops = &brcmf_sdio_bus_ops; in brcmf_sdio_probe()
4167 bus->sdiodev->bus_if->chip = bus->ci->chip; in brcmf_sdio_probe()
4168 bus->sdiodev->bus_if->chiprev = bus->ci->chiprev; in brcmf_sdio_probe()
4171 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_probe()
4174 ret = brcmf_attach(bus->sdiodev->dev); in brcmf_sdio_probe()
4181 bus->blocksize = bus->sdiodev->func[2]->cur_blksize; in brcmf_sdio_probe()
4182 bus->roundup = min(max_roundup, bus->blocksize); in brcmf_sdio_probe()
4185 if (bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_probe()
4186 bus->sdiodev->bus_if->maxctl += bus->roundup; in brcmf_sdio_probe()
4187 bus->rxblen = in brcmf_sdio_probe()
4188 roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN), in brcmf_sdio_probe()
4189 ALIGNMENT) + bus->head_align; in brcmf_sdio_probe()
4190 bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); in brcmf_sdio_probe()
4191 if (!(bus->rxbuf)) { in brcmf_sdio_probe()
4197 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_probe()
4200 sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]); in brcmf_sdio_probe()
4202 bus->rxflow = false; in brcmf_sdio_probe()
4205 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); in brcmf_sdio_probe()
4207 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_probe()
4210 bus->clkstate = CLK_SDONLY; in brcmf_sdio_probe()
4211 bus->idletime = BRCMF_IDLE_INTERVAL; in brcmf_sdio_probe()
4212 bus->idleclock = BRCMF_IDLE_ACTIVE; in brcmf_sdio_probe()
4215 bus->sr_enabled = false; in brcmf_sdio_probe()
4217 brcmf_sdio_debugfs_create(bus); in brcmf_sdio_probe()
4220 ret = brcmf_sdio_get_fwnames(bus->ci, sdiodev); in brcmf_sdio_probe()
4232 return bus; in brcmf_sdio_probe()
4235 brcmf_sdio_remove(bus); in brcmf_sdio_probe()
4240 void brcmf_sdio_remove(struct brcmf_sdio *bus) in brcmf_sdio_remove() argument
4244 if (bus) { in brcmf_sdio_remove()
4246 brcmf_sdiod_intr_unregister(bus->sdiodev); in brcmf_sdio_remove()
4248 brcmf_detach(bus->sdiodev->dev); in brcmf_sdio_remove()
4250 cancel_work_sync(&bus->datawork); in brcmf_sdio_remove()
4251 if (bus->brcmf_wq) in brcmf_sdio_remove()
4252 destroy_workqueue(bus->brcmf_wq); in brcmf_sdio_remove()
4254 if (bus->ci) { in brcmf_sdio_remove()
4255 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { in brcmf_sdio_remove()
4256 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_remove()
4257 brcmf_sdio_wd_timer(bus, 0); in brcmf_sdio_remove()
4258 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_remove()
4264 brcmf_chip_set_passive(bus->ci); in brcmf_sdio_remove()
4265 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_remove()
4266 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_remove()
4268 brcmf_chip_detach(bus->ci); in brcmf_sdio_remove()
4271 kfree(bus->rxbuf); in brcmf_sdio_remove()
4272 kfree(bus->hdrbuf); in brcmf_sdio_remove()
4273 kfree(bus); in brcmf_sdio_remove()
4279 void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, uint wdtick) in brcmf_sdio_wd_timer() argument
4282 if (!wdtick && bus->wd_timer_valid) { in brcmf_sdio_wd_timer()
4283 del_timer_sync(&bus->timer); in brcmf_sdio_wd_timer()
4284 bus->wd_timer_valid = false; in brcmf_sdio_wd_timer()
4285 bus->save_ms = wdtick; in brcmf_sdio_wd_timer()
4290 if (bus->sdiodev->state != BRCMF_SDIOD_DATA) in brcmf_sdio_wd_timer()
4294 if (bus->save_ms != BRCMF_WD_POLL_MS) { in brcmf_sdio_wd_timer()
4295 if (bus->wd_timer_valid) in brcmf_sdio_wd_timer()
4297 del_timer_sync(&bus->timer); in brcmf_sdio_wd_timer()
4302 bus->timer.expires = in brcmf_sdio_wd_timer()
4304 add_timer(&bus->timer); in brcmf_sdio_wd_timer()
4308 mod_timer(&bus->timer, in brcmf_sdio_wd_timer()
4312 bus->wd_timer_valid = true; in brcmf_sdio_wd_timer()
4313 bus->save_ms = wdtick; in brcmf_sdio_wd_timer()
4317 int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep) in brcmf_sdio_sleep() argument
4321 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_sleep()
4322 ret = brcmf_sdio_bus_sleep(bus, sleep, false); in brcmf_sdio_sleep()
4323 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_sleep()