• Home
  • Raw
  • Download

Lines Matching refs:bus

655 static bool data_ok(struct brcmf_sdio *bus)  in data_ok()  argument
657 return (u8)(bus->tx_max - bus->tx_seq) != 0 && in data_ok()
658 ((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0; in data_ok()
665 static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset) in r_sdreg32() argument
670 core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in r_sdreg32()
671 *regvar = brcmf_sdiod_regrl(bus->sdiodev, core->base + offset, &ret); in r_sdreg32()
676 static int w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset) in w_sdreg32() argument
681 core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in w_sdreg32()
682 brcmf_sdiod_regwl(bus->sdiodev, core->base + reg_offset, regval, &ret); in w_sdreg32()
688 brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) in brcmf_sdio_kso_control() argument
699 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
726 rd_val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
737 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
754 static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok) in brcmf_sdio_htclk() argument
764 if (bus->sr_enabled) { in brcmf_sdio_htclk()
765 bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); in brcmf_sdio_htclk()
772 bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; in brcmf_sdio_htclk()
774 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
782 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
790 if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { in brcmf_sdio_htclk()
792 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
801 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
804 bus->clkstate = CLK_PENDING; in brcmf_sdio_htclk()
807 } else if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
809 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
812 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
819 while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
820 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
832 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
839 bus->clkstate = CLK_AVAIL; in brcmf_sdio_htclk()
843 if (!bus->alp_only) { in brcmf_sdio_htclk()
852 if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
854 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_htclk()
857 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
861 bus->clkstate = CLK_SDONLY; in brcmf_sdio_htclk()
862 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
875 static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) in brcmf_sdio_sdclk() argument
880 bus->clkstate = CLK_SDONLY; in brcmf_sdio_sdclk()
882 bus->clkstate = CLK_NONE; in brcmf_sdio_sdclk()
888 static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) in brcmf_sdio_clkctl() argument
891 uint oldstate = bus->clkstate; in brcmf_sdio_clkctl()
897 if (bus->clkstate == target) in brcmf_sdio_clkctl()
903 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
904 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
906 brcmf_sdio_htclk(bus, true, pendok); in brcmf_sdio_clkctl()
911 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
912 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
913 else if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
914 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
917 bus->clkstate, target); in brcmf_sdio_clkctl()
922 if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
923 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
925 brcmf_sdio_sdclk(bus, false); in brcmf_sdio_clkctl()
929 brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); in brcmf_sdio_clkctl()
936 brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) in brcmf_sdio_bus_sleep() argument
943 (bus->sleeping ? "SLEEP" : "WAKE")); in brcmf_sdio_bus_sleep()
946 if (bus->sr_enabled) { in brcmf_sdio_bus_sleep()
948 if (sleep == bus->sleeping) in brcmf_sdio_bus_sleep()
953 clkcsr = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_bus_sleep()
958 brcmf_sdiod_regwb(bus->sdiodev, in brcmf_sdio_bus_sleep()
962 err = brcmf_sdio_kso_control(bus, false); in brcmf_sdio_bus_sleep()
964 err = brcmf_sdio_kso_control(bus, true); in brcmf_sdio_bus_sleep()
976 if (!bus->sr_enabled) in brcmf_sdio_bus_sleep()
977 brcmf_sdio_clkctl(bus, CLK_NONE, pendok); in brcmf_sdio_bus_sleep()
979 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); in brcmf_sdio_bus_sleep()
980 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_bus_sleep()
982 bus->sleeping = sleep; in brcmf_sdio_bus_sleep()
997 static int brcmf_sdio_readshared(struct brcmf_sdio *bus, in brcmf_sdio_readshared() argument
1006 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readshared()
1007 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_readshared()
1013 shaddr = bus->ci->rambase + bus->ci->ramsize - 4; in brcmf_sdio_readshared()
1014 if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci)) in brcmf_sdio_readshared()
1015 shaddr -= bus->ci->srsize; in brcmf_sdio_readshared()
1016 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, in brcmf_sdio_readshared()
1035 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, in brcmf_sdio_readshared()
1040 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readshared()
1062 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readshared()
1066 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1070 if (brcmf_sdio_readshared(bus, &sh) == 0) in brcmf_sdio_get_console_addr()
1071 bus->console_addr = sh.console_addr; in brcmf_sdio_get_console_addr()
1074 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1079 static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus) in brcmf_sdio_hostmail() argument
1089 ret = r_sdreg32(bus, &hmb_data, in brcmf_sdio_hostmail()
1093 w_sdreg32(bus, SMB_INT_ACK, in brcmf_sdio_hostmail()
1095 bus->sdcnt.f1regdata += 2; in brcmf_sdio_hostmail()
1100 bus->rx_seq); in brcmf_sdio_hostmail()
1101 if (!bus->rxskip) in brcmf_sdio_hostmail()
1104 bus->rxskip = false; in brcmf_sdio_hostmail()
1112 bus->sdpcm_ver = in brcmf_sdio_hostmail()
1115 if (bus->sdpcm_ver != SDPCM_PROT_VERSION) in brcmf_sdio_hostmail()
1118 bus->sdpcm_ver, SDPCM_PROT_VERSION); in brcmf_sdio_hostmail()
1121 bus->sdpcm_ver); in brcmf_sdio_hostmail()
1127 brcmf_sdio_get_console_addr(bus); in brcmf_sdio_hostmail()
1139 if (fcbits & ~bus->flowcontrol) in brcmf_sdio_hostmail()
1140 bus->sdcnt.fc_xoff++; in brcmf_sdio_hostmail()
1142 if (bus->flowcontrol & ~fcbits) in brcmf_sdio_hostmail()
1143 bus->sdcnt.fc_xon++; in brcmf_sdio_hostmail()
1145 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hostmail()
1146 bus->flowcontrol = fcbits; in brcmf_sdio_hostmail()
1161 static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx) in brcmf_sdio_rxfail() argument
1173 brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2); in brcmf_sdio_rxfail()
1175 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, in brcmf_sdio_rxfail()
1177 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1181 hi = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_rxfail()
1183 lo = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_rxfail()
1185 bus->sdcnt.f1regdata += 2; in brcmf_sdio_rxfail()
1203 bus->sdcnt.rxrtx++; in brcmf_sdio_rxfail()
1204 err = w_sdreg32(bus, SMB_NAK, in brcmf_sdio_rxfail()
1207 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1209 bus->rxskip = true; in brcmf_sdio_rxfail()
1213 bus->cur_read.len = 0; in brcmf_sdio_rxfail()
1216 static void brcmf_sdio_txfail(struct brcmf_sdio *bus) in brcmf_sdio_txfail() argument
1218 struct brcmf_sdio_dev *sdiodev = bus->sdiodev; in brcmf_sdio_txfail()
1223 bus->sdcnt.tx_sderrs++; in brcmf_sdio_txfail()
1227 bus->sdcnt.f1regdata++; in brcmf_sdio_txfail()
1232 bus->sdcnt.f1regdata += 2; in brcmf_sdio_txfail()
1239 static uint brcmf_sdio_glom_len(struct brcmf_sdio *bus) in brcmf_sdio_glom_len() argument
1245 skb_queue_walk(&bus->glom, p) in brcmf_sdio_glom_len()
1250 static void brcmf_sdio_free_glom(struct brcmf_sdio *bus) in brcmf_sdio_free_glom() argument
1254 skb_queue_walk_safe(&bus->glom, cur, next) { in brcmf_sdio_free_glom()
1255 skb_unlink(cur, &bus->glom); in brcmf_sdio_free_glom()
1328 static int brcmf_sdio_hdparse(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdparse() argument
1343 bus->rxpending = false; in brcmf_sdio_hdparse()
1348 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1349 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1357 (roundup(len, bus->blocksize) != rd->len)) { in brcmf_sdio_hdparse()
1380 bus->sdcnt.rx_toolong++; in brcmf_sdio_hdparse()
1381 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1399 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1400 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1406 bus->sdcnt.rx_badseq++; in brcmf_sdio_hdparse()
1421 if (bus->flowcontrol != fc) { in brcmf_sdio_hdparse()
1422 if (~bus->flowcontrol & fc) in brcmf_sdio_hdparse()
1423 bus->sdcnt.fc_xoff++; in brcmf_sdio_hdparse()
1424 if (bus->flowcontrol & ~fc) in brcmf_sdio_hdparse()
1425 bus->sdcnt.fc_xon++; in brcmf_sdio_hdparse()
1426 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hdparse()
1427 bus->flowcontrol = fc; in brcmf_sdio_hdparse()
1430 if ((u8)(tx_seq_max - bus->tx_seq) > 0x40) { in brcmf_sdio_hdparse()
1432 tx_seq_max = bus->tx_seq + 2; in brcmf_sdio_hdparse()
1434 bus->tx_max = tx_seq_max; in brcmf_sdio_hdparse()
1445 static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdpack() argument
1454 if (bus->txglom) { in brcmf_sdio_hdpack()
1469 trace_brcmf_sdpcm_hdr(SDPCM_TX + !!(bus->txglom), header); in brcmf_sdio_hdpack()
1472 static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq) in brcmf_sdio_rxglom() argument
1488 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_rxglom()
1491 if (bus->glomd) { in brcmf_sdio_rxglom()
1493 dlen = (u16) (bus->glomd->len); in brcmf_sdio_rxglom()
1494 dptr = bus->glomd->data; in brcmf_sdio_rxglom()
1513 if (sublen % bus->sgentry_align) { in brcmf_sdio_rxglom()
1515 sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1523 (roundup(totlen, bus->blocksize) - totlen); in brcmf_sdio_rxglom()
1524 totlen = roundup(totlen, bus->blocksize); in brcmf_sdio_rxglom()
1528 pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align); in brcmf_sdio_rxglom()
1534 skb_queue_tail(&bus->glom, pnext); in brcmf_sdio_rxglom()
1537 pkt_align(pnext, sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1545 if (BRCMF_GLOM_ON() && bus->cur_read.len && in brcmf_sdio_rxglom()
1546 totlen != bus->cur_read.len) { in brcmf_sdio_rxglom()
1548 bus->cur_read.len, totlen, rxseq); in brcmf_sdio_rxglom()
1552 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1557 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_rxglom()
1558 bus->glomd = NULL; in brcmf_sdio_rxglom()
1559 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1564 if (!skb_queue_empty(&bus->glom)) { in brcmf_sdio_rxglom()
1567 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1574 pfirst = skb_peek(&bus->glom); in brcmf_sdio_rxglom()
1575 dlen = (u16) brcmf_sdio_glom_len(bus); in brcmf_sdio_rxglom()
1581 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1582 errcode = brcmf_sdiod_recv_chain(bus->sdiodev, in brcmf_sdio_rxglom()
1583 &bus->glom, dlen); in brcmf_sdio_rxglom()
1584 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1585 bus->sdcnt.f2rxdata++; in brcmf_sdio_rxglom()
1592 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1593 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1594 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1595 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1596 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1606 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1607 errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new, in brcmf_sdio_rxglom()
1609 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1610 bus->cur_read.len = rd_new.len_nxtfrm << 4; in brcmf_sdio_rxglom()
1618 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1625 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1626 errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new, in brcmf_sdio_rxglom()
1628 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1637 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1638 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1639 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1640 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1641 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_rxglom()
1642 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1648 skb_queue_walk_safe(&bus->glom, pfirst, pnext) { in brcmf_sdio_rxglom()
1661 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1670 bus->glom.qlen, pfirst, pfirst->data, in brcmf_sdio_rxglom()
1673 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1675 brcmf_rx_event(bus->sdiodev->dev, pfirst); in brcmf_sdio_rxglom()
1677 brcmf_rx_frame(bus->sdiodev->dev, pfirst, in brcmf_sdio_rxglom()
1679 bus->sdcnt.rxglompkts++; in brcmf_sdio_rxglom()
1682 bus->sdcnt.rxglomframes++; in brcmf_sdio_rxglom()
1687 static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition, in brcmf_sdio_dcmd_resp_wait() argument
1694 add_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1704 remove_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1709 static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus) in brcmf_sdio_dcmd_resp_wake() argument
1711 wake_up_interruptible(&bus->dcmd_resp_wait); in brcmf_sdio_dcmd_resp_wake()
1716 brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff) in brcmf_sdio_read_control() argument
1724 if (bus->rxblen) in brcmf_sdio_read_control()
1725 buf = vzalloc(bus->rxblen); in brcmf_sdio_read_control()
1729 rbuf = bus->rxbuf; in brcmf_sdio_read_control()
1730 pad = ((unsigned long)rbuf % bus->head_align); in brcmf_sdio_read_control()
1732 rbuf += (bus->head_align - pad); in brcmf_sdio_read_control()
1741 if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { in brcmf_sdio_read_control()
1742 pad = bus->blocksize - (rdlen % bus->blocksize); in brcmf_sdio_read_control()
1743 if ((pad <= bus->roundup) && (pad < bus->blocksize) && in brcmf_sdio_read_control()
1744 ((len + pad) < bus->sdiodev->bus_if->maxctl)) in brcmf_sdio_read_control()
1746 } else if (rdlen % bus->head_align) { in brcmf_sdio_read_control()
1747 rdlen += bus->head_align - (rdlen % bus->head_align); in brcmf_sdio_read_control()
1751 if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1753 rdlen, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1754 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1758 if ((len - doff) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1760 len, len - doff, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1761 bus->sdcnt.rx_toolong++; in brcmf_sdio_read_control()
1762 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1767 sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen); in brcmf_sdio_read_control()
1768 bus->sdcnt.f2rxdata++; in brcmf_sdio_read_control()
1774 bus->sdcnt.rxc_errors++; in brcmf_sdio_read_control()
1775 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_read_control()
1786 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1787 if (bus->rxctl) { in brcmf_sdio_read_control()
1789 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1793 bus->rxctl = buf + doff; in brcmf_sdio_read_control()
1794 bus->rxctl_orig = buf; in brcmf_sdio_read_control()
1795 bus->rxlen = len - doff; in brcmf_sdio_read_control()
1796 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1800 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_read_control()
1804 static void brcmf_sdio_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen) in brcmf_sdio_pad() argument
1806 if (bus->roundup && bus->blocksize && *rdlen > bus->blocksize) { in brcmf_sdio_pad()
1807 *pad = bus->blocksize - (*rdlen % bus->blocksize); in brcmf_sdio_pad()
1808 if (*pad <= bus->roundup && *pad < bus->blocksize && in brcmf_sdio_pad()
1811 } else if (*rdlen % bus->head_align) { in brcmf_sdio_pad()
1812 *rdlen += bus->head_align - (*rdlen % bus->head_align); in brcmf_sdio_pad()
1816 static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_readframes() argument
1823 struct brcmf_sdio_hdrinfo *rd = &bus->cur_read, rd_new; in brcmf_sdio_readframes()
1829 bus->rxpending = true; in brcmf_sdio_readframes()
1831 for (rd->seq_num = bus->rx_seq, rxleft = maxframes; in brcmf_sdio_readframes()
1832 !bus->rxskip && rxleft && bus->sdiodev->state == BRCMF_SDIOD_DATA; in brcmf_sdio_readframes()
1836 if (bus->glomd || !skb_queue_empty(&bus->glom)) { in brcmf_sdio_readframes()
1839 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_readframes()
1840 cnt = brcmf_sdio_rxglom(bus, rd->seq_num); in brcmf_sdio_readframes()
1849 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1851 ret = brcmf_sdiod_recv_buf(bus->sdiodev, in brcmf_sdio_readframes()
1852 bus->rxhdr, BRCMF_FIRSTREAD); in brcmf_sdio_readframes()
1853 bus->sdcnt.f2rxhdrs++; in brcmf_sdio_readframes()
1857 bus->sdcnt.rx_hdrfail++; in brcmf_sdio_readframes()
1858 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1859 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1864 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1867 if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd, in brcmf_sdio_readframes()
1869 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1870 if (!bus->rxpending) in brcmf_sdio_readframes()
1877 brcmf_sdio_read_control(bus, bus->rxhdr, in brcmf_sdio_readframes()
1885 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1893 brcmf_sdio_pad(bus, &pad, &rd->len_left); in brcmf_sdio_readframes()
1896 bus->head_align); in brcmf_sdio_readframes()
1900 brcmf_sdio_rxfail(bus, false, in brcmf_sdio_readframes()
1902 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1906 pkt_align(pkt, rd->len_left, bus->head_align); in brcmf_sdio_readframes()
1908 ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt); in brcmf_sdio_readframes()
1909 bus->sdcnt.f2rxdata++; in brcmf_sdio_readframes()
1910 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1916 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1917 brcmf_sdio_rxfail(bus, true, in brcmf_sdio_readframes()
1919 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1925 memcpy(pkt->data, bus->rxhdr, head_read); in brcmf_sdio_readframes()
1928 memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN); in brcmf_sdio_readframes()
1930 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1931 if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new, in brcmf_sdio_readframes()
1937 bus->sdcnt.rx_readahead_cnt++; in brcmf_sdio_readframes()
1943 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1944 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1948 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1956 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1964 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1965 brcmf_sdio_rxfail(bus, false, true); in brcmf_sdio_readframes()
1966 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1977 if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_HWHDR_LEN])) { in brcmf_sdio_readframes()
1985 bus->glomd = pkt; in brcmf_sdio_readframes()
1989 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
1990 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_readframes()
1991 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_readframes()
2008 brcmf_rx_event(bus->sdiodev->dev, pkt); in brcmf_sdio_readframes()
2010 brcmf_rx_frame(bus->sdiodev->dev, pkt, in brcmf_sdio_readframes()
2027 if (bus->rxskip) in brcmf_sdio_readframes()
2029 bus->rx_seq = rd->seq_num; in brcmf_sdio_readframes()
2035 brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus) in brcmf_sdio_wait_event_wakeup() argument
2037 wake_up_interruptible(&bus->ctrl_wait); in brcmf_sdio_wait_event_wakeup()
2041 static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt) in brcmf_sdio_txpkt_hdalign() argument
2050 head_pad = ((unsigned long)dat_buf % bus->head_align); in brcmf_sdio_txpkt_hdalign()
2053 stats = &bus->sdiodev->bus_if->stats; in brcmf_sdio_txpkt_hdalign()
2064 memset(dat_buf, 0, head_pad + bus->tx_hdrlen); in brcmf_sdio_txpkt_hdalign()
2077 static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus, in brcmf_sdio_txpkt_prep_sg() argument
2088 sdiodev = bus->sdiodev; in brcmf_sdio_txpkt_prep_sg()
2091 WARN_ON(blksize % bus->sgentry_align); in brcmf_sdio_txpkt_prep_sg()
2096 tail_chop = pkt->len % bus->sgentry_align; in brcmf_sdio_txpkt_prep_sg()
2098 tail_pad = bus->sgentry_align - tail_chop; in brcmf_sdio_txpkt_prep_sg()
2104 bus->head_align); in brcmf_sdio_txpkt_prep_sg()
2107 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); in brcmf_sdio_txpkt_prep_sg()
2146 brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt_prep() argument
2155 txseq = bus->tx_seq; in brcmf_sdio_txpkt_prep()
2167 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_next); in brcmf_sdio_txpkt_prep()
2172 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad); in brcmf_sdio_txpkt_prep()
2178 if (bus->txglom && pktq->qlen > 1) { in brcmf_sdio_txpkt_prep()
2179 ret = brcmf_sdio_txpkt_prep_sg(bus, pktq, in brcmf_sdio_txpkt_prep()
2188 hd_info.dat_offset = head_pad + bus->tx_hdrlen; in brcmf_sdio_txpkt_prep()
2192 brcmf_sdio_hdpack(bus, pkt_next->data, &hd_info); in brcmf_sdio_txpkt_prep()
2201 head_pad + bus->tx_hdrlen, in brcmf_sdio_txpkt_prep()
2207 if (bus->txglom) in brcmf_sdio_txpkt_prep()
2222 brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq) in brcmf_sdio_txpkt_postp() argument
2241 hdr = pkt_next->data + bus->tx_hdrlen - SDPCM_SWHDR_LEN; in brcmf_sdio_txpkt_postp()
2246 if (bus->txglom) { in brcmf_sdio_txpkt_postp()
2256 static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt() argument
2264 ret = brcmf_sdio_txpkt_prep(bus, pktq, chan); in brcmf_sdio_txpkt()
2268 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_txpkt()
2269 ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq); in brcmf_sdio_txpkt()
2270 bus->sdcnt.f2txdata++; in brcmf_sdio_txpkt()
2273 brcmf_sdio_txfail(bus); in brcmf_sdio_txpkt()
2275 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_txpkt()
2278 brcmf_sdio_txpkt_postp(bus, pktq); in brcmf_sdio_txpkt()
2280 bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP; in brcmf_sdio_txpkt()
2283 brcmf_proto_bcdc_txcomplete(bus->sdiodev->dev, pkt_next, in brcmf_sdio_txpkt()
2289 static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_sendfromq() argument
2300 tx_prec_map = ~bus->flowcontrol; in brcmf_sdio_sendfromq()
2303 for (cnt = 0; (cnt < maxframes) && data_ok(bus);) { in brcmf_sdio_sendfromq()
2305 if (bus->txglom) in brcmf_sdio_sendfromq()
2306 pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, in brcmf_sdio_sendfromq()
2307 bus->sdiodev->txglomsz); in brcmf_sdio_sendfromq()
2309 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); in brcmf_sdio_sendfromq()
2311 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2313 pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, in brcmf_sdio_sendfromq()
2319 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2323 ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); in brcmf_sdio_sendfromq()
2328 if (!bus->intr) { in brcmf_sdio_sendfromq()
2330 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_sendfromq()
2331 ret = r_sdreg32(bus, &intstatus, in brcmf_sdio_sendfromq()
2334 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_sendfromq()
2335 bus->sdcnt.f2txdata++; in brcmf_sdio_sendfromq()
2338 if (intstatus & bus->hostintmask) in brcmf_sdio_sendfromq()
2339 atomic_set(&bus->ipend, 1); in brcmf_sdio_sendfromq()
2344 if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) && in brcmf_sdio_sendfromq()
2345 bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { in brcmf_sdio_sendfromq()
2346 bus->txoff = false; in brcmf_sdio_sendfromq()
2347 brcmf_proto_bcdc_txflowblock(bus->sdiodev->dev, false); in brcmf_sdio_sendfromq()
2353 static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len) in brcmf_sdio_tx_ctrlframe() argument
2364 frame -= bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2365 len += bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2368 doff = ((unsigned long)frame % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2372 memset(frame + bus->tx_hdrlen, 0, doff); in brcmf_sdio_tx_ctrlframe()
2377 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { in brcmf_sdio_tx_ctrlframe()
2378 pad = bus->blocksize - (len % bus->blocksize); in brcmf_sdio_tx_ctrlframe()
2379 if ((pad > bus->roundup) || (pad >= bus->blocksize)) in brcmf_sdio_tx_ctrlframe()
2381 } else if (len % bus->head_align) { in brcmf_sdio_tx_ctrlframe()
2382 pad = bus->head_align - (len % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2388 hd_info.dat_offset = doff + bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2389 hd_info.seq_num = bus->tx_seq; in brcmf_sdio_tx_ctrlframe()
2392 brcmf_sdio_hdpack(bus, frame, &hd_info); in brcmf_sdio_tx_ctrlframe()
2394 if (bus->txglom) in brcmf_sdio_tx_ctrlframe()
2404 ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); in brcmf_sdio_tx_ctrlframe()
2407 brcmf_sdio_txfail(bus); in brcmf_sdio_tx_ctrlframe()
2409 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; in brcmf_sdio_tx_ctrlframe()
2422 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_stop() local
2426 if (bus->watchdog_tsk) { in brcmf_sdio_bus_stop()
2427 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_bus_stop()
2428 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_bus_stop()
2429 bus->watchdog_tsk = NULL; in brcmf_sdio_bus_stop()
2436 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_stop()
2439 w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask)); in brcmf_sdio_bus_stop()
2440 local_hostintmask = bus->hostintmask; in brcmf_sdio_bus_stop()
2441 bus->hostintmask = 0; in brcmf_sdio_bus_stop()
2458 w_sdreg32(bus, local_hostintmask, in brcmf_sdio_bus_stop()
2464 brcmu_pktq_flush(&bus->txq, true, NULL, NULL); in brcmf_sdio_bus_stop()
2467 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_bus_stop()
2468 brcmf_sdio_free_glom(bus); in brcmf_sdio_bus_stop()
2471 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2472 bus->rxlen = 0; in brcmf_sdio_bus_stop()
2473 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2474 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_bus_stop()
2477 bus->rxskip = false; in brcmf_sdio_bus_stop()
2478 bus->tx_seq = bus->rx_seq = 0; in brcmf_sdio_bus_stop()
2481 static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) in brcmf_sdio_clrintr() argument
2486 sdiodev = bus->sdiodev; in brcmf_sdio_clrintr()
2489 if (!sdiodev->irq_en && !atomic_read(&bus->ipend)) { in brcmf_sdio_clrintr()
2490 enable_irq(sdiodev->settings->bus.sdio.oob_irq_nr); in brcmf_sdio_clrintr()
2497 static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) in brcmf_sdio_intr_rstatus() argument
2504 buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in brcmf_sdio_intr_rstatus()
2507 val = brcmf_sdiod_regrl(bus->sdiodev, addr, &ret); in brcmf_sdio_intr_rstatus()
2508 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2512 val &= bus->hostintmask; in brcmf_sdio_intr_rstatus()
2513 atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); in brcmf_sdio_intr_rstatus()
2517 brcmf_sdiod_regwl(bus->sdiodev, addr, val, &ret); in brcmf_sdio_intr_rstatus()
2518 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2519 atomic_or(val, &bus->intstatus); in brcmf_sdio_intr_rstatus()
2525 static void brcmf_sdio_dpc(struct brcmf_sdio *bus) in brcmf_sdio_dpc() argument
2529 uint txlimit = bus->txbound; /* Tx frames to send before resched */ in brcmf_sdio_dpc()
2535 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2538 if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { in brcmf_sdio_dpc()
2543 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_dpc()
2548 clkctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_dpc()
2555 devctl = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_dpc()
2558 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_dpc()
2560 bus->clkstate = CLK_AVAIL; in brcmf_sdio_dpc()
2565 brcmf_sdio_bus_sleep(bus, false, true); in brcmf_sdio_dpc()
2568 if (atomic_read(&bus->ipend) > 0) { in brcmf_sdio_dpc()
2569 atomic_set(&bus->ipend, 0); in brcmf_sdio_dpc()
2570 err = brcmf_sdio_intr_rstatus(bus); in brcmf_sdio_dpc()
2574 intstatus = atomic_xchg(&bus->intstatus, 0); in brcmf_sdio_dpc()
2582 err = w_sdreg32(bus, I_HMB_FC_CHANGE, in brcmf_sdio_dpc()
2585 err = r_sdreg32(bus, &newstatus, in brcmf_sdio_dpc()
2587 bus->sdcnt.f1regdata += 2; in brcmf_sdio_dpc()
2588 atomic_set(&bus->fcstate, in brcmf_sdio_dpc()
2590 intstatus |= (newstatus & bus->hostintmask); in brcmf_sdio_dpc()
2596 intstatus |= brcmf_sdio_hostmail(bus); in brcmf_sdio_dpc()
2599 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2624 if (bus->rxskip) in brcmf_sdio_dpc()
2628 if ((intstatus & I_HMB_FRAME_IND) && (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_dpc()
2629 brcmf_sdio_readframes(bus, bus->rxbound); in brcmf_sdio_dpc()
2630 if (!bus->rxpending) in brcmf_sdio_dpc()
2636 atomic_or(intstatus, &bus->intstatus); in brcmf_sdio_dpc()
2638 brcmf_sdio_clrintr(bus); in brcmf_sdio_dpc()
2640 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && in brcmf_sdio_dpc()
2641 data_ok(bus)) { in brcmf_sdio_dpc()
2642 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2643 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2644 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, in brcmf_sdio_dpc()
2645 bus->ctrl_frame_len); in brcmf_sdio_dpc()
2646 bus->ctrl_frame_err = err; in brcmf_sdio_dpc()
2648 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2650 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2651 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2654 if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2655 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit && in brcmf_sdio_dpc()
2656 data_ok(bus)) { in brcmf_sdio_dpc()
2657 framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : in brcmf_sdio_dpc()
2659 brcmf_sdio_sendfromq(bus, framecnt); in brcmf_sdio_dpc()
2662 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { in brcmf_sdio_dpc()
2664 atomic_set(&bus->intstatus, 0); in brcmf_sdio_dpc()
2665 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2666 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2667 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2668 bus->ctrl_frame_err = -ENODEV; in brcmf_sdio_dpc()
2670 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2671 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2673 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_dpc()
2675 } else if (atomic_read(&bus->intstatus) || in brcmf_sdio_dpc()
2676 atomic_read(&bus->ipend) > 0 || in brcmf_sdio_dpc()
2677 (!atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2678 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && in brcmf_sdio_dpc()
2679 data_ok(bus))) { in brcmf_sdio_dpc()
2680 bus->dpc_triggered = true; in brcmf_sdio_dpc()
2688 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_gettxq() local
2690 return &bus->txq; in brcmf_sdio_bus_gettxq()
2741 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txdata() local
2748 skb_push(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2755 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); in brcmf_sdio_bus_txdata()
2756 bus->sdcnt.fcqueued++; in brcmf_sdio_bus_txdata()
2759 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2762 if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) { in brcmf_sdio_bus_txdata()
2763 skb_pull(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2770 if (pktq_len(&bus->txq) >= TXHI) { in brcmf_sdio_bus_txdata()
2771 bus->txoff = true; in brcmf_sdio_bus_txdata()
2774 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2777 if (pktq_plen(&bus->txq, prec) > qcount[prec]) in brcmf_sdio_bus_txdata()
2778 qcount[prec] = pktq_plen(&bus->txq, prec); in brcmf_sdio_bus_txdata()
2781 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txdata()
2788 static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) in brcmf_sdio_readconsole() argument
2790 struct brcmf_console *c = &bus->console; in brcmf_sdio_readconsole()
2796 if (bus->console_addr == 0) in brcmf_sdio_readconsole()
2800 addr = bus->console_addr + offsetof(struct rte_console, log_le); in brcmf_sdio_readconsole()
2801 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, in brcmf_sdio_readconsole()
2827 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize); in brcmf_sdio_readconsole()
2870 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txctl() local
2878 bus->ctrl_frame_buf = msg; in brcmf_sdio_bus_txctl()
2879 bus->ctrl_frame_len = msglen; in brcmf_sdio_bus_txctl()
2881 bus->ctrl_frame_stat = true; in brcmf_sdio_bus_txctl()
2883 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txctl()
2884 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, in brcmf_sdio_bus_txctl()
2887 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2888 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_txctl()
2889 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2891 bus->ctrl_frame_stat = false; in brcmf_sdio_bus_txctl()
2894 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_txctl()
2898 bus->ctrl_frame_err); in brcmf_sdio_bus_txctl()
2900 ret = bus->ctrl_frame_err; in brcmf_sdio_bus_txctl()
2904 bus->sdcnt.tx_ctlerrs++; in brcmf_sdio_bus_txctl()
2906 bus->sdcnt.tx_ctlpkts++; in brcmf_sdio_bus_txctl()
2912 static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_dump_console() argument
2922 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2929 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2936 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2951 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, in brcmf_sdio_dump_console()
2969 static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_trap_info() argument
2980 error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, in brcmf_sdio_trap_info()
3003 static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_assert_info() argument
3018 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_assert_info()
3020 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3026 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3031 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_assert_info()
3038 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3043 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_checkdied()
3059 static int brcmf_sdio_died_dump(struct seq_file *seq, struct brcmf_sdio *bus) in brcmf_sdio_died_dump() argument
3064 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_died_dump()
3068 error = brcmf_sdio_assert_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3072 error = brcmf_sdio_trap_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3076 error = brcmf_sdio_dump_console(seq, bus, &sh); in brcmf_sdio_died_dump()
3085 struct brcmf_sdio *bus = bus_if->bus_priv.sdio->bus; in brcmf_sdio_forensic_read() local
3087 return brcmf_sdio_died_dump(seq, bus); in brcmf_sdio_forensic_read()
3094 struct brcmf_sdio_count *sdcnt = &sdiodev->bus->sdcnt; in brcmf_debugfs_sdio_count_read()
3129 static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) in brcmf_sdio_debugfs_create() argument
3131 struct brcmf_pub *drvr = bus->sdiodev->bus_if->drvr; in brcmf_sdio_debugfs_create()
3137 bus->console_interval = BRCMF_CONSOLE; in brcmf_sdio_debugfs_create()
3143 &bus->console_interval); in brcmf_sdio_debugfs_create()
3146 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3151 static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) in brcmf_sdio_debugfs_create() argument
3165 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_rxctl() local
3172 timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); in brcmf_sdio_bus_rxctl()
3174 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3175 rxlen = bus->rxlen; in brcmf_sdio_bus_rxctl()
3176 memcpy(msg, bus->rxctl, min(msglen, rxlen)); in brcmf_sdio_bus_rxctl()
3177 bus->rxctl = NULL; in brcmf_sdio_bus_rxctl()
3178 buf = bus->rxctl_orig; in brcmf_sdio_bus_rxctl()
3179 bus->rxctl_orig = NULL; in brcmf_sdio_bus_rxctl()
3180 bus->rxlen = 0; in brcmf_sdio_bus_rxctl()
3181 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3189 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3195 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3199 bus->sdcnt.rx_ctlpkts++; in brcmf_sdio_bus_rxctl()
3201 bus->sdcnt.rx_ctlerrs++; in brcmf_sdio_bus_rxctl()
3260 static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, in brcmf_sdio_download_code_file() argument
3267 err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase, in brcmf_sdio_download_code_file()
3271 err, (int)fw->size, bus->ci->rambase); in brcmf_sdio_download_code_file()
3272 else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, in brcmf_sdio_download_code_file()
3279 static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, in brcmf_sdio_download_nvram() argument
3287 address = bus->ci->ramsize - varsz + bus->ci->rambase; in brcmf_sdio_download_nvram()
3288 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); in brcmf_sdio_download_nvram()
3292 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) in brcmf_sdio_download_nvram()
3298 static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus, in brcmf_sdio_download_firmware() argument
3305 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_download_firmware()
3306 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_download_firmware()
3311 bcmerror = brcmf_sdio_download_code_file(bus, fw); in brcmf_sdio_download_firmware()
3319 bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen); in brcmf_sdio_download_firmware()
3327 if (!brcmf_chip_set_active(bus->ci, rstvec)) { in brcmf_sdio_download_firmware()
3333 brcmf_sdio_clkctl(bus, CLK_SDONLY, false); in brcmf_sdio_download_firmware()
3334 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_download_firmware()
3338 static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) in brcmf_sdio_sr_init() argument
3345 val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); in brcmf_sdio_sr_init()
3352 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); in brcmf_sdio_sr_init()
3359 brcmf_sdiod_regwb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, in brcmf_sdio_sr_init()
3368 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_sr_init()
3376 bus->sr_enabled = true; in brcmf_sdio_sr_init()
3381 static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) in brcmf_sdio_kso_init() argument
3389 if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12) in brcmf_sdio_kso_init()
3392 val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); in brcmf_sdio_kso_init()
3401 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_init()
3417 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_preinit() local
3426 if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12) { in brcmf_sdio_bus_preinit()
3433 value = sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_bus_preinit()
3443 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_bus_preinit()
3445 bus->txglom = false; in brcmf_sdio_bus_preinit()
3447 pad_size = bus->sdiodev->func[2]->cur_blksize << 1; in brcmf_sdio_bus_preinit()
3448 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", in brcmf_sdio_bus_preinit()
3454 bus->txglom = true; in brcmf_sdio_bus_preinit()
3455 bus->tx_hdrlen += SDPCM_HWEXT_LEN; in brcmf_sdio_bus_preinit()
3458 brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); in brcmf_sdio_bus_preinit()
3468 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_ramsize() local
3470 return bus->ci->ramsize - bus->ci->srsize; in brcmf_sdio_bus_get_ramsize()
3478 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_memdump() local
3484 brcmf_dbg(INFO, "dump at 0x%08x: size=%zu\n", bus->ci->rambase, in brcmf_sdio_bus_get_memdump()
3487 address = bus->ci->rambase; in brcmf_sdio_bus_get_memdump()
3509 void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) in brcmf_sdio_trigger_dpc() argument
3511 if (!bus->dpc_triggered) { in brcmf_sdio_trigger_dpc()
3512 bus->dpc_triggered = true; in brcmf_sdio_trigger_dpc()
3513 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_trigger_dpc()
3517 void brcmf_sdio_isr(struct brcmf_sdio *bus) in brcmf_sdio_isr() argument
3521 if (!bus) { in brcmf_sdio_isr()
3527 bus->sdcnt.intrcount++; in brcmf_sdio_isr()
3529 atomic_set(&bus->ipend, 1); in brcmf_sdio_isr()
3531 if (brcmf_sdio_intr_rstatus(bus)) { in brcmf_sdio_isr()
3536 if (!bus->intr) in brcmf_sdio_isr()
3539 bus->dpc_triggered = true; in brcmf_sdio_isr()
3540 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_isr()
3543 static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) in brcmf_sdio_bus_watchdog() argument
3548 if (!bus->sr_enabled && in brcmf_sdio_bus_watchdog()
3549 bus->poll && (++bus->polltick >= bus->pollrate)) { in brcmf_sdio_bus_watchdog()
3553 bus->polltick = 0; in brcmf_sdio_bus_watchdog()
3556 if (!bus->intr || in brcmf_sdio_bus_watchdog()
3557 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { in brcmf_sdio_bus_watchdog()
3559 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3562 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3563 devpend = brcmf_sdiod_regrb(bus->sdiodev, in brcmf_sdio_bus_watchdog()
3566 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3574 bus->sdcnt.pollcnt++; in brcmf_sdio_bus_watchdog()
3575 atomic_set(&bus->ipend, 1); in brcmf_sdio_bus_watchdog()
3577 bus->dpc_triggered = true; in brcmf_sdio_bus_watchdog()
3578 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_bus_watchdog()
3583 bus->sdcnt.lastintrs = bus->sdcnt.intrcount; in brcmf_sdio_bus_watchdog()
3587 if (bus->sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() && in brcmf_sdio_bus_watchdog()
3588 bus->console_interval != 0) { in brcmf_sdio_bus_watchdog()
3589 bus->console.count += jiffies_to_msecs(BRCMF_WD_POLL); in brcmf_sdio_bus_watchdog()
3590 if (bus->console.count >= bus->console_interval) { in brcmf_sdio_bus_watchdog()
3591 bus->console.count -= bus->console_interval; in brcmf_sdio_bus_watchdog()
3592 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3594 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_watchdog()
3595 if (brcmf_sdio_readconsole(bus) < 0) in brcmf_sdio_bus_watchdog()
3597 bus->console_interval = 0; in brcmf_sdio_bus_watchdog()
3598 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3604 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3606 if ((!bus->dpc_running) && (bus->idletime > 0) && in brcmf_sdio_bus_watchdog()
3607 (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_bus_watchdog()
3608 bus->idlecount++; in brcmf_sdio_bus_watchdog()
3609 if (bus->idlecount > bus->idletime) { in brcmf_sdio_bus_watchdog()
3611 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3612 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_bus_watchdog()
3613 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3614 brcmf_sdio_bus_sleep(bus, true, false); in brcmf_sdio_bus_watchdog()
3615 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_bus_watchdog()
3618 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3621 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3627 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, in brcmf_sdio_dataworker() local
3630 bus->dpc_running = true; in brcmf_sdio_dataworker()
3632 while (ACCESS_ONCE(bus->dpc_triggered)) { in brcmf_sdio_dataworker()
3633 bus->dpc_triggered = false; in brcmf_sdio_dataworker()
3634 brcmf_sdio_dpc(bus); in brcmf_sdio_dataworker()
3635 bus->idlecount = 0; in brcmf_sdio_dataworker()
3637 bus->dpc_running = false; in brcmf_sdio_dataworker()
3638 if (brcmf_sdiod_freezing(bus->sdiodev)) { in brcmf_sdio_dataworker()
3639 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); in brcmf_sdio_dataworker()
3640 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_dataworker()
3641 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_dataworker()
3811 brcmf_sdio_probe_attach(struct brcmf_sdio *bus) in brcmf_sdio_probe_attach() argument
3820 sdiodev = bus->sdiodev; in brcmf_sdio_probe_attach()
3843 bus->ci = brcmf_chip_attach(sdiodev, &brcmf_sdio_buscore_ops); in brcmf_sdio_probe_attach()
3844 if (IS_ERR(bus->ci)) { in brcmf_sdio_probe_attach()
3846 bus->ci = NULL; in brcmf_sdio_probe_attach()
3851 bus->ci->chip, in brcmf_sdio_probe_attach()
3852 bus->ci->chiprev); in brcmf_sdio_probe_attach()
3860 bus->head_align = ALIGNMENT; in brcmf_sdio_probe_attach()
3861 bus->sgentry_align = ALIGNMENT; in brcmf_sdio_probe_attach()
3862 if (sdiodev->settings->bus.sdio.sd_head_align > ALIGNMENT) in brcmf_sdio_probe_attach()
3863 bus->head_align = sdiodev->settings->bus.sdio.sd_head_align; in brcmf_sdio_probe_attach()
3864 if (sdiodev->settings->bus.sdio.sd_sgentry_align > ALIGNMENT) in brcmf_sdio_probe_attach()
3865 bus->sgentry_align = in brcmf_sdio_probe_attach()
3866 sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_probe_attach()
3879 (sdiodev->settings->bus.sdio.oob_irq_supported))) in brcmf_sdio_probe_attach()
3883 if (brcmf_sdio_kso_init(bus)) { in brcmf_sdio_probe_attach()
3888 if (sdiodev->settings->bus.sdio.drive_strength) in brcmf_sdio_probe_attach()
3889 drivestrength = sdiodev->settings->bus.sdio.drive_strength; in brcmf_sdio_probe_attach()
3892 brcmf_sdio_drivestrengthinit(sdiodev, bus->ci, drivestrength); in brcmf_sdio_probe_attach()
3906 reg_addr = CORE_CC_REG(brcmf_chip_get_pmu(bus->ci)->base, pmucontrol); in brcmf_sdio_probe_attach()
3919 brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); in brcmf_sdio_probe_attach()
3922 bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); in brcmf_sdio_probe_attach()
3923 if (!bus->hdrbuf) in brcmf_sdio_probe_attach()
3926 bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], in brcmf_sdio_probe_attach()
3927 bus->head_align); in brcmf_sdio_probe_attach()
3930 bus->intr = true; in brcmf_sdio_probe_attach()
3931 bus->poll = false; in brcmf_sdio_probe_attach()
3932 if (bus->poll) in brcmf_sdio_probe_attach()
3933 bus->pollrate = 1; in brcmf_sdio_probe_attach()
3945 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog_thread() local
3950 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3954 brcmf_sdiod_freezer_uncount(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3955 wait = wait_for_completion_interruptible(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
3956 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3957 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_watchdog_thread()
3959 brcmf_sdio_bus_watchdog(bus); in brcmf_sdio_watchdog_thread()
3961 bus->sdcnt.tickcnt++; in brcmf_sdio_watchdog_thread()
3962 reinit_completion(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
3972 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog() local
3974 if (bus->watchdog_tsk) { in brcmf_sdio_watchdog()
3975 complete(&bus->watchdog_wait); in brcmf_sdio_watchdog()
3977 if (bus->wd_active) in brcmf_sdio_watchdog()
3978 mod_timer(&bus->timer, in brcmf_sdio_watchdog()
4001 struct brcmf_sdio *bus; in brcmf_sdio_firmware_callback() local
4013 bus = sdiodev->bus; in brcmf_sdio_firmware_callback()
4016 bus->alp_only = true; in brcmf_sdio_firmware_callback()
4017 err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len); in brcmf_sdio_firmware_callback()
4020 bus->alp_only = false; in brcmf_sdio_firmware_callback()
4023 bus->sdcnt.tickcnt = 0; in brcmf_sdio_firmware_callback()
4024 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_firmware_callback()
4029 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_firmware_callback()
4030 if (bus->clkstate != CLK_AVAIL) in brcmf_sdio_firmware_callback()
4045 w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, in brcmf_sdio_firmware_callback()
4055 bus->hostintmask = HOSTINTMASK; in brcmf_sdio_firmware_callback()
4056 w_sdreg32(bus, bus->hostintmask, in brcmf_sdio_firmware_callback()
4066 if (brcmf_chip_sr_capable(bus->ci)) { in brcmf_sdio_firmware_callback()
4067 brcmf_sdio_sr_init(bus); in brcmf_sdio_firmware_callback()
4076 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_firmware_callback()
4085 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_firmware_callback()
4107 struct brcmf_sdio *bus; in brcmf_sdio_probe() local
4113 bus = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); in brcmf_sdio_probe()
4114 if (!bus) in brcmf_sdio_probe()
4117 bus->sdiodev = sdiodev; in brcmf_sdio_probe()
4118 sdiodev->bus = bus; in brcmf_sdio_probe()
4119 skb_queue_head_init(&bus->glom); in brcmf_sdio_probe()
4120 bus->txbound = BRCMF_TXBOUND; in brcmf_sdio_probe()
4121 bus->rxbound = BRCMF_RXBOUND; in brcmf_sdio_probe()
4122 bus->txminmax = BRCMF_TXMINMAX; in brcmf_sdio_probe()
4123 bus->tx_seq = SDPCM_SEQ_WRAP - 1; in brcmf_sdio_probe()
4133 INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); in brcmf_sdio_probe()
4134 bus->brcmf_wq = wq; in brcmf_sdio_probe()
4137 if (!(brcmf_sdio_probe_attach(bus))) { in brcmf_sdio_probe()
4142 spin_lock_init(&bus->rxctl_lock); in brcmf_sdio_probe()
4143 spin_lock_init(&bus->txq_lock); in brcmf_sdio_probe()
4144 init_waitqueue_head(&bus->ctrl_wait); in brcmf_sdio_probe()
4145 init_waitqueue_head(&bus->dcmd_resp_wait); in brcmf_sdio_probe()
4148 init_timer(&bus->timer); in brcmf_sdio_probe()
4149 bus->timer.data = (unsigned long)bus; in brcmf_sdio_probe()
4150 bus->timer.function = brcmf_sdio_watchdog; in brcmf_sdio_probe()
4153 init_completion(&bus->watchdog_wait); in brcmf_sdio_probe()
4154 bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, in brcmf_sdio_probe()
4155 bus, "brcmf_wdog/%s", in brcmf_sdio_probe()
4157 if (IS_ERR(bus->watchdog_tsk)) { in brcmf_sdio_probe()
4159 bus->watchdog_tsk = NULL; in brcmf_sdio_probe()
4162 bus->dpc_triggered = false; in brcmf_sdio_probe()
4163 bus->dpc_running = false; in brcmf_sdio_probe()
4166 bus->sdiodev->bus_if->dev = bus->sdiodev->dev; in brcmf_sdio_probe()
4167 bus->sdiodev->bus_if->ops = &brcmf_sdio_bus_ops; in brcmf_sdio_probe()
4168 bus->sdiodev->bus_if->chip = bus->ci->chip; in brcmf_sdio_probe()
4169 bus->sdiodev->bus_if->chiprev = bus->ci->chiprev; in brcmf_sdio_probe()
4172 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_probe()
4175 ret = brcmf_attach(bus->sdiodev->dev, bus->sdiodev->settings); in brcmf_sdio_probe()
4182 bus->blocksize = bus->sdiodev->func[2]->cur_blksize; in brcmf_sdio_probe()
4183 bus->roundup = min(max_roundup, bus->blocksize); in brcmf_sdio_probe()
4186 if (bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_probe()
4187 bus->sdiodev->bus_if->maxctl += bus->roundup; in brcmf_sdio_probe()
4188 bus->rxblen = in brcmf_sdio_probe()
4189 roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN), in brcmf_sdio_probe()
4190 ALIGNMENT) + bus->head_align; in brcmf_sdio_probe()
4191 bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); in brcmf_sdio_probe()
4192 if (!(bus->rxbuf)) { in brcmf_sdio_probe()
4198 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_probe()
4201 sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]); in brcmf_sdio_probe()
4203 bus->rxflow = false; in brcmf_sdio_probe()
4206 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); in brcmf_sdio_probe()
4208 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_probe()
4211 bus->clkstate = CLK_SDONLY; in brcmf_sdio_probe()
4212 bus->idletime = BRCMF_IDLE_INTERVAL; in brcmf_sdio_probe()
4213 bus->idleclock = BRCMF_IDLE_ACTIVE; in brcmf_sdio_probe()
4216 bus->sr_enabled = false; in brcmf_sdio_probe()
4218 brcmf_sdio_debugfs_create(bus); in brcmf_sdio_probe()
4221 ret = brcmf_fw_map_chip_to_name(bus->ci->chip, bus->ci->chiprev, in brcmf_sdio_probe()
4236 return bus; in brcmf_sdio_probe()
4239 brcmf_sdio_remove(bus); in brcmf_sdio_probe()
4244 void brcmf_sdio_remove(struct brcmf_sdio *bus) in brcmf_sdio_remove() argument
4248 if (bus) { in brcmf_sdio_remove()
4250 if (bus->watchdog_tsk) { in brcmf_sdio_remove()
4251 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_remove()
4252 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_remove()
4253 bus->watchdog_tsk = NULL; in brcmf_sdio_remove()
4257 brcmf_sdiod_intr_unregister(bus->sdiodev); in brcmf_sdio_remove()
4259 brcmf_detach(bus->sdiodev->dev); in brcmf_sdio_remove()
4261 cancel_work_sync(&bus->datawork); in brcmf_sdio_remove()
4262 if (bus->brcmf_wq) in brcmf_sdio_remove()
4263 destroy_workqueue(bus->brcmf_wq); in brcmf_sdio_remove()
4265 if (bus->ci) { in brcmf_sdio_remove()
4266 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { in brcmf_sdio_remove()
4267 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_remove()
4268 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_remove()
4269 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_remove()
4275 brcmf_chip_set_passive(bus->ci); in brcmf_sdio_remove()
4276 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_remove()
4277 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_remove()
4279 brcmf_chip_detach(bus->ci); in brcmf_sdio_remove()
4281 if (bus->sdiodev->settings) in brcmf_sdio_remove()
4282 brcmf_release_module_param(bus->sdiodev->settings); in brcmf_sdio_remove()
4284 kfree(bus->rxbuf); in brcmf_sdio_remove()
4285 kfree(bus->hdrbuf); in brcmf_sdio_remove()
4286 kfree(bus); in brcmf_sdio_remove()
4292 void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, bool active) in brcmf_sdio_wd_timer() argument
4295 if (!active && bus->wd_active) { in brcmf_sdio_wd_timer()
4296 del_timer_sync(&bus->timer); in brcmf_sdio_wd_timer()
4297 bus->wd_active = false; in brcmf_sdio_wd_timer()
4302 if (bus->sdiodev->state != BRCMF_SDIOD_DATA) in brcmf_sdio_wd_timer()
4306 if (!bus->wd_active) { in brcmf_sdio_wd_timer()
4310 bus->timer.expires = jiffies + BRCMF_WD_POLL; in brcmf_sdio_wd_timer()
4311 add_timer(&bus->timer); in brcmf_sdio_wd_timer()
4312 bus->wd_active = true; in brcmf_sdio_wd_timer()
4315 mod_timer(&bus->timer, jiffies + BRCMF_WD_POLL); in brcmf_sdio_wd_timer()
4320 int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep) in brcmf_sdio_sleep() argument
4324 sdio_claim_host(bus->sdiodev->func[1]); in brcmf_sdio_sleep()
4325 ret = brcmf_sdio_bus_sleep(bus, sleep, false); in brcmf_sdio_sleep()
4326 sdio_release_host(bus->sdiodev->func[1]); in brcmf_sdio_sleep()