Lines Matching full:bus

112 #include "bus.h"
147 * sdio bus power cycle to clear (rev 9) */
222 #define I_BUSPWR (1 << 17) /* SDIO Bus Power Change (rev 9) */
389 /* dongle SDIO bus specific header info */
436 /* Private data for SDIO bus interaction */
476 u8 sdpcm_ver; /* Bus protocol reported by dongle */
494 s32 idleclock; /* How to set bus driver when idle */
504 spinlock_t txq_lock; /* protect bus->txq */
523 u8 tx_hdrlen; /* sdio bus header length for tx packet */
676 static bool data_ok(struct brcmf_sdio *bus) in data_ok() argument
681 if (bus->ctrl_frame_stat) in data_ok()
684 return (bus->tx_max - bus->tx_seq - tx_rsv) != 0 && in data_ok()
685 ((bus->tx_max - bus->tx_seq - tx_rsv) & 0x80) == 0; in data_ok()
690 static bool txctl_ok(struct brcmf_sdio *bus) in txctl_ok() argument
692 return (bus->tx_max - bus->tx_seq) != 0 && in txctl_ok()
693 ((bus->tx_max - bus->tx_seq) & 0x80) == 0; in txctl_ok()
697 brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) in brcmf_sdio_kso_control() argument
706 sdio_retune_crc_disable(bus->sdiodev->func1); in brcmf_sdio_kso_control()
710 sdio_retune_hold_now(bus->sdiodev->func1); in brcmf_sdio_kso_control()
714 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err); in brcmf_sdio_kso_control()
721 if (!on && bus->ci->chip == CY_CC_43012_CHIP_ID) in brcmf_sdio_kso_control()
748 rd_val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
760 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, in brcmf_sdio_kso_control()
773 sdio_retune_release(bus->sdiodev->func1); in brcmf_sdio_kso_control()
775 sdio_retune_crc_enable(bus->sdiodev->func1); in brcmf_sdio_kso_control()
783 static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok) in brcmf_sdio_htclk() argument
793 if (bus->sr_enabled) { in brcmf_sdio_htclk()
794 bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); in brcmf_sdio_htclk()
801 bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; in brcmf_sdio_htclk()
803 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
811 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
819 if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { in brcmf_sdio_htclk()
821 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
829 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
832 bus->clkstate = CLK_PENDING; in brcmf_sdio_htclk()
835 } else if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
837 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
840 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
847 while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
848 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
860 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
867 bus->clkstate = CLK_AVAIL; in brcmf_sdio_htclk()
871 if (!bus->alp_only) { in brcmf_sdio_htclk()
880 if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
882 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
885 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
889 bus->clkstate = CLK_SDONLY; in brcmf_sdio_htclk()
890 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
903 static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) in brcmf_sdio_sdclk() argument
908 bus->clkstate = CLK_SDONLY; in brcmf_sdio_sdclk()
910 bus->clkstate = CLK_NONE; in brcmf_sdio_sdclk()
916 static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) in brcmf_sdio_clkctl() argument
919 uint oldstate = bus->clkstate; in brcmf_sdio_clkctl()
925 if (bus->clkstate == target) in brcmf_sdio_clkctl()
931 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
932 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
934 brcmf_sdio_htclk(bus, true, pendok); in brcmf_sdio_clkctl()
939 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
940 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
941 else if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
942 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
945 bus->clkstate, target); in brcmf_sdio_clkctl()
950 if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
951 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
953 brcmf_sdio_sdclk(bus, false); in brcmf_sdio_clkctl()
957 brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); in brcmf_sdio_clkctl()
964 brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) in brcmf_sdio_bus_sleep() argument
971 (bus->sleeping ? "SLEEP" : "WAKE")); in brcmf_sdio_bus_sleep()
973 /* If SR is enabled control bus state with KSO */ in brcmf_sdio_bus_sleep()
974 if (bus->sr_enabled) { in brcmf_sdio_bus_sleep()
976 if (sleep == bus->sleeping) in brcmf_sdio_bus_sleep()
981 clkcsr = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_bus_sleep()
986 brcmf_sdiod_writeb(bus->sdiodev, in brcmf_sdio_bus_sleep()
990 err = brcmf_sdio_kso_control(bus, false); in brcmf_sdio_bus_sleep()
992 err = brcmf_sdio_kso_control(bus, true); in brcmf_sdio_bus_sleep()
995 brcmf_err("error while changing bus sleep state %d\n", in brcmf_sdio_bus_sleep()
1004 if (!bus->sr_enabled) in brcmf_sdio_bus_sleep()
1005 brcmf_sdio_clkctl(bus, CLK_NONE, pendok); in brcmf_sdio_bus_sleep()
1007 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); in brcmf_sdio_bus_sleep()
1008 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_bus_sleep()
1010 bus->sleeping = sleep; in brcmf_sdio_bus_sleep()
1025 static int brcmf_sdio_readshared(struct brcmf_sdio *bus, in brcmf_sdio_readshared() argument
1034 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1035 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_readshared()
1041 shaddr = bus->ci->rambase + bus->ci->ramsize - 4; in brcmf_sdio_readshared()
1042 if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci)) in brcmf_sdio_readshared()
1043 shaddr -= bus->ci->srsize; in brcmf_sdio_readshared()
1044 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, in brcmf_sdio_readshared()
1063 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, in brcmf_sdio_readshared()
1068 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1090 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1094 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1098 if (brcmf_sdio_readshared(bus, &sh) == 0) in brcmf_sdio_get_console_addr()
1099 bus->console_addr = sh.console_addr; in brcmf_sdio_get_console_addr()
1102 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1107 static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus) in brcmf_sdio_hostmail() argument
1109 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_hostmail()
1110 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_hostmail()
1127 bus->sdcnt.f1regdata += 2; in brcmf_sdio_hostmail()
1138 bus->rx_seq); in brcmf_sdio_hostmail()
1139 if (!bus->rxskip) in brcmf_sdio_hostmail()
1142 bus->rxskip = false; in brcmf_sdio_hostmail()
1150 bus->sdpcm_ver = in brcmf_sdio_hostmail()
1153 if (bus->sdpcm_ver != SDPCM_PROT_VERSION) in brcmf_sdio_hostmail()
1156 bus->sdpcm_ver, SDPCM_PROT_VERSION); in brcmf_sdio_hostmail()
1159 bus->sdpcm_ver); in brcmf_sdio_hostmail()
1165 brcmf_sdio_get_console_addr(bus); in brcmf_sdio_hostmail()
1177 if (fcbits & ~bus->flowcontrol) in brcmf_sdio_hostmail()
1178 bus->sdcnt.fc_xoff++; in brcmf_sdio_hostmail()
1180 if (bus->flowcontrol & ~fcbits) in brcmf_sdio_hostmail()
1181 bus->sdcnt.fc_xon++; in brcmf_sdio_hostmail()
1183 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hostmail()
1184 bus->flowcontrol = fcbits; in brcmf_sdio_hostmail()
1200 static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx) in brcmf_sdio_rxfail() argument
1202 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_rxfail()
1203 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_rxfail()
1214 brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func2); in brcmf_sdio_rxfail()
1216 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, in brcmf_sdio_rxfail()
1218 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1222 hi = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCHI, in brcmf_sdio_rxfail()
1224 lo = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCLO, in brcmf_sdio_rxfail()
1226 bus->sdcnt.f1regdata += 2; in brcmf_sdio_rxfail()
1244 bus->sdcnt.rxrtx++; in brcmf_sdio_rxfail()
1248 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1250 bus->rxskip = true; in brcmf_sdio_rxfail()
1254 bus->cur_read.len = 0; in brcmf_sdio_rxfail()
1257 static void brcmf_sdio_txfail(struct brcmf_sdio *bus) in brcmf_sdio_txfail() argument
1259 struct brcmf_sdio_dev *sdiodev = bus->sdiodev; in brcmf_sdio_txfail()
1264 bus->sdcnt.tx_sderrs++; in brcmf_sdio_txfail()
1268 bus->sdcnt.f1regdata++; in brcmf_sdio_txfail()
1273 bus->sdcnt.f1regdata += 2; in brcmf_sdio_txfail()
1280 static uint brcmf_sdio_glom_len(struct brcmf_sdio *bus) in brcmf_sdio_glom_len() argument
1286 skb_queue_walk(&bus->glom, p) in brcmf_sdio_glom_len()
1291 static void brcmf_sdio_free_glom(struct brcmf_sdio *bus) in brcmf_sdio_free_glom() argument
1295 skb_queue_walk_safe(&bus->glom, cur, next) { in brcmf_sdio_free_glom()
1296 skb_unlink(cur, &bus->glom); in brcmf_sdio_free_glom()
1302 * brcmfmac sdio bus specific header
1369 static int brcmf_sdio_hdparse(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdparse() argument
1384 bus->rxpending = false; in brcmf_sdio_hdparse()
1389 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1390 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1398 (roundup(len, bus->blocksize) != rd->len)) { in brcmf_sdio_hdparse()
1421 bus->sdcnt.rx_toolong++; in brcmf_sdio_hdparse()
1422 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1440 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1441 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1447 bus->sdcnt.rx_badseq++; in brcmf_sdio_hdparse()
1462 if (bus->flowcontrol != fc) { in brcmf_sdio_hdparse()
1463 if (~bus->flowcontrol & fc) in brcmf_sdio_hdparse()
1464 bus->sdcnt.fc_xoff++; in brcmf_sdio_hdparse()
1465 if (bus->flowcontrol & ~fc) in brcmf_sdio_hdparse()
1466 bus->sdcnt.fc_xon++; in brcmf_sdio_hdparse()
1467 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hdparse()
1468 bus->flowcontrol = fc; in brcmf_sdio_hdparse()
1471 if ((u8)(tx_seq_max - bus->tx_seq) > 0x40) { in brcmf_sdio_hdparse()
1473 tx_seq_max = bus->tx_seq + 2; in brcmf_sdio_hdparse()
1475 bus->tx_max = tx_seq_max; in brcmf_sdio_hdparse()
1486 static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdpack() argument
1495 if (bus->txglom) { in brcmf_sdio_hdpack()
1510 trace_brcmf_sdpcm_hdr(SDPCM_TX + !!(bus->txglom), header); in brcmf_sdio_hdpack()
1513 static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq) in brcmf_sdio_rxglom() argument
1529 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_rxglom()
1532 if (bus->glomd) { in brcmf_sdio_rxglom()
1534 dlen = (u16) (bus->glomd->len); in brcmf_sdio_rxglom()
1535 dptr = bus->glomd->data; in brcmf_sdio_rxglom()
1554 if (sublen % bus->sgentry_align) { in brcmf_sdio_rxglom()
1556 sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1564 (roundup(totlen, bus->blocksize) - totlen); in brcmf_sdio_rxglom()
1565 totlen = roundup(totlen, bus->blocksize); in brcmf_sdio_rxglom()
1569 pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align); in brcmf_sdio_rxglom()
1575 skb_queue_tail(&bus->glom, pnext); in brcmf_sdio_rxglom()
1578 pkt_align(pnext, sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1582 in bus structure */ in brcmf_sdio_rxglom()
1586 if (BRCMF_GLOM_ON() && bus->cur_read.len && in brcmf_sdio_rxglom()
1587 totlen != bus->cur_read.len) { in brcmf_sdio_rxglom()
1589 bus->cur_read.len, totlen, rxseq); in brcmf_sdio_rxglom()
1593 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1598 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_rxglom()
1599 bus->glomd = NULL; in brcmf_sdio_rxglom()
1600 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1605 if (!skb_queue_empty(&bus->glom)) { in brcmf_sdio_rxglom()
1608 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1615 pfirst = skb_peek(&bus->glom); in brcmf_sdio_rxglom()
1616 dlen = (u16) brcmf_sdio_glom_len(bus); in brcmf_sdio_rxglom()
1622 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1623 errcode = brcmf_sdiod_recv_chain(bus->sdiodev, in brcmf_sdio_rxglom()
1624 &bus->glom, dlen); in brcmf_sdio_rxglom()
1625 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1626 bus->sdcnt.f2rxdata++; in brcmf_sdio_rxglom()
1633 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1634 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1635 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1636 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1637 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1647 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1648 errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new, in brcmf_sdio_rxglom()
1650 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1651 bus->cur_read.len = rd_new.len_nxtfrm << 4; in brcmf_sdio_rxglom()
1658 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1665 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1666 errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new, in brcmf_sdio_rxglom()
1668 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1677 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1678 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1679 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1680 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1681 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1682 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1688 skb_queue_walk_safe(&bus->glom, pfirst, pnext) { in brcmf_sdio_rxglom()
1701 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1710 bus->glom.qlen, pfirst, pfirst->data, in brcmf_sdio_rxglom()
1713 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1715 brcmf_rx_event(bus->sdiodev->dev, pfirst); in brcmf_sdio_rxglom()
1717 brcmf_rx_frame(bus->sdiodev->dev, pfirst, in brcmf_sdio_rxglom()
1719 bus->sdcnt.rxglompkts++; in brcmf_sdio_rxglom()
1722 bus->sdcnt.rxglomframes++; in brcmf_sdio_rxglom()
1727 static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition, in brcmf_sdio_dcmd_resp_wait() argument
1734 add_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1744 remove_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1749 static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus) in brcmf_sdio_dcmd_resp_wake() argument
1751 wake_up_interruptible(&bus->dcmd_resp_wait); in brcmf_sdio_dcmd_resp_wake()
1756 brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff) in brcmf_sdio_read_control() argument
1763 if (bus->rxblen) in brcmf_sdio_read_control()
1764 buf = vzalloc(bus->rxblen); in brcmf_sdio_read_control()
1768 rbuf = bus->rxbuf; in brcmf_sdio_read_control()
1769 pad = ((unsigned long)rbuf % bus->head_align); in brcmf_sdio_read_control()
1771 rbuf += (bus->head_align - pad); in brcmf_sdio_read_control()
1780 if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { in brcmf_sdio_read_control()
1781 pad = bus->blocksize - (rdlen % bus->blocksize); in brcmf_sdio_read_control()
1782 if ((pad <= bus->roundup) && (pad < bus->blocksize) && in brcmf_sdio_read_control()
1783 ((len + pad) < bus->sdiodev->bus_if->maxctl)) in brcmf_sdio_read_control()
1785 } else if (rdlen % bus->head_align) { in brcmf_sdio_read_control()
1786 rdlen += bus->head_align - (rdlen % bus->head_align); in brcmf_sdio_read_control()
1790 if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1792 rdlen, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1793 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1797 if ((len - doff) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1799 len, len - doff, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1800 bus->sdcnt.rx_toolong++; in brcmf_sdio_read_control()
1801 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1806 sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen); in brcmf_sdio_read_control()
1807 bus->sdcnt.f2rxdata++; in brcmf_sdio_read_control()
1813 bus->sdcnt.rxc_errors++; in brcmf_sdio_read_control()
1814 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_read_control()
1825 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1826 if (bus->rxctl) { in brcmf_sdio_read_control()
1828 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1832 bus->rxctl = buf + doff; in brcmf_sdio_read_control()
1833 bus->rxctl_orig = buf; in brcmf_sdio_read_control()
1834 bus->rxlen = len - doff; in brcmf_sdio_read_control()
1835 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1839 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_read_control()
1843 static void brcmf_sdio_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen) in brcmf_sdio_pad() argument
1845 if (bus->roundup && bus->blocksize && *rdlen > bus->blocksize) { in brcmf_sdio_pad()
1846 *pad = bus->blocksize - (*rdlen % bus->blocksize); in brcmf_sdio_pad()
1847 if (*pad <= bus->roundup && *pad < bus->blocksize && in brcmf_sdio_pad()
1850 } else if (*rdlen % bus->head_align) { in brcmf_sdio_pad()
1851 *rdlen += bus->head_align - (*rdlen % bus->head_align); in brcmf_sdio_pad()
1855 static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_readframes() argument
1862 struct brcmf_sdio_hdrinfo *rd = &bus->cur_read, rd_new; in brcmf_sdio_readframes()
1868 bus->rxpending = true; in brcmf_sdio_readframes()
1870 for (rd->seq_num = bus->rx_seq, rxleft = maxframes; in brcmf_sdio_readframes()
1871 !bus->rxskip && rxleft && bus->sdiodev->state == BRCMF_SDIOD_DATA; in brcmf_sdio_readframes()
1875 if (bus->glomd || !skb_queue_empty(&bus->glom)) { in brcmf_sdio_readframes()
1878 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_readframes()
1879 cnt = brcmf_sdio_rxglom(bus, rd->seq_num); in brcmf_sdio_readframes()
1888 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1890 ret = brcmf_sdiod_recv_buf(bus->sdiodev, in brcmf_sdio_readframes()
1891 bus->rxhdr, BRCMF_FIRSTREAD); in brcmf_sdio_readframes()
1892 bus->sdcnt.f2rxhdrs++; in brcmf_sdio_readframes()
1896 bus->sdcnt.rx_hdrfail++; in brcmf_sdio_readframes()
1897 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1898 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1903 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1906 if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd, in brcmf_sdio_readframes()
1908 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1909 if (!bus->rxpending) in brcmf_sdio_readframes()
1916 brcmf_sdio_read_control(bus, bus->rxhdr, in brcmf_sdio_readframes()
1924 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1932 brcmf_sdio_pad(bus, &pad, &rd->len_left); in brcmf_sdio_readframes()
1935 bus->head_align); in brcmf_sdio_readframes()
1939 brcmf_sdio_rxfail(bus, false, in brcmf_sdio_readframes()
1941 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1945 pkt_align(pkt, rd->len_left, bus->head_align); in brcmf_sdio_readframes()
1947 ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt); in brcmf_sdio_readframes()
1948 bus->sdcnt.f2rxdata++; in brcmf_sdio_readframes()
1949 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1955 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1956 brcmf_sdio_rxfail(bus, true, in brcmf_sdio_readframes()
1958 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1964 memcpy(pkt->data, bus->rxhdr, head_read); in brcmf_sdio_readframes()
1967 memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN); in brcmf_sdio_readframes()
1969 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1970 if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new, in brcmf_sdio_readframes()
1973 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1974 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1978 bus->sdcnt.rx_readahead_cnt++; in brcmf_sdio_readframes()
1984 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1985 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1989 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1997 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
2005 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2006 brcmf_sdio_rxfail(bus, false, true); in brcmf_sdio_readframes()
2007 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2018 if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_HWHDR_LEN])) { in brcmf_sdio_readframes()
2026 bus->glomd = pkt; in brcmf_sdio_readframes()
2030 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2031 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_readframes()
2032 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2049 brcmf_rx_event(bus->sdiodev->dev, pkt); in brcmf_sdio_readframes()
2051 brcmf_rx_frame(bus->sdiodev->dev, pkt, in brcmf_sdio_readframes()
2068 if (bus->rxskip) in brcmf_sdio_readframes()
2070 bus->rx_seq = rd->seq_num; in brcmf_sdio_readframes()
2076 brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus) in brcmf_sdio_wait_event_wakeup() argument
2078 wake_up_interruptible(&bus->ctrl_wait); in brcmf_sdio_wait_event_wakeup()
2082 static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt) in brcmf_sdio_txpkt_hdalign() argument
2091 head_pad = ((unsigned long)dat_buf % bus->head_align); in brcmf_sdio_txpkt_hdalign()
2094 stats = &bus->sdiodev->bus_if->stats; in brcmf_sdio_txpkt_hdalign()
2105 memset(dat_buf, 0, head_pad + bus->tx_hdrlen); in brcmf_sdio_txpkt_hdalign()
2111 * bus layer usage.
2118 static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus, in brcmf_sdio_txpkt_prep_sg() argument
2129 sdiodev = bus->sdiodev; in brcmf_sdio_txpkt_prep_sg()
2132 WARN_ON(blksize % bus->sgentry_align); in brcmf_sdio_txpkt_prep_sg()
2137 tail_chop = pkt->len % bus->sgentry_align; in brcmf_sdio_txpkt_prep_sg()
2139 tail_pad = bus->sgentry_align - tail_chop; in brcmf_sdio_txpkt_prep_sg()
2145 bus->head_align); in brcmf_sdio_txpkt_prep_sg()
2148 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); in brcmf_sdio_txpkt_prep_sg()
2176 * @bus: brcmf_sdio structure pointer
2187 brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt_prep() argument
2196 txseq = bus->tx_seq; in brcmf_sdio_txpkt_prep()
2208 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_next); in brcmf_sdio_txpkt_prep()
2213 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad); in brcmf_sdio_txpkt_prep()
2219 if (bus->txglom && pktq->qlen > 1) { in brcmf_sdio_txpkt_prep()
2220 ret = brcmf_sdio_txpkt_prep_sg(bus, pktq, in brcmf_sdio_txpkt_prep()
2229 hd_info.dat_offset = head_pad + bus->tx_hdrlen; in brcmf_sdio_txpkt_prep()
2233 brcmf_sdio_hdpack(bus, pkt_next->data, &hd_info); in brcmf_sdio_txpkt_prep()
2242 head_pad + bus->tx_hdrlen, in brcmf_sdio_txpkt_prep()
2248 if (bus->txglom) in brcmf_sdio_txpkt_prep()
2255 * @bus: brcmf_sdio structure pointer
2263 brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq) in brcmf_sdio_txpkt_postp() argument
2282 hdr = pkt_next->data + bus->tx_hdrlen - SDPCM_SWHDR_LEN; in brcmf_sdio_txpkt_postp()
2287 if (bus->txglom) { in brcmf_sdio_txpkt_postp()
2297 static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt() argument
2305 ret = brcmf_sdio_txpkt_prep(bus, pktq, chan); in brcmf_sdio_txpkt()
2309 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_txpkt()
2310 ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq); in brcmf_sdio_txpkt()
2311 bus->sdcnt.f2txdata++; in brcmf_sdio_txpkt()
2314 brcmf_sdio_txfail(bus); in brcmf_sdio_txpkt()
2316 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_txpkt()
2319 brcmf_sdio_txpkt_postp(bus, pktq); in brcmf_sdio_txpkt()
2321 bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP; in brcmf_sdio_txpkt()
2324 brcmf_proto_bcdc_txcomplete(bus->sdiodev->dev, pkt_next, in brcmf_sdio_txpkt()
2330 static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_sendfromq() argument
2334 u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus); in brcmf_sdio_sendfromq()
2342 tx_prec_map = ~bus->flowcontrol; in brcmf_sdio_sendfromq()
2345 for (cnt = 0; (cnt < maxframes) && data_ok(bus);) { in brcmf_sdio_sendfromq()
2347 if (bus->txglom) in brcmf_sdio_sendfromq()
2348 pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, in brcmf_sdio_sendfromq()
2349 bus->sdiodev->txglomsz); in brcmf_sdio_sendfromq()
2351 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); in brcmf_sdio_sendfromq()
2353 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2355 pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, in brcmf_sdio_sendfromq()
2361 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2365 ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); in brcmf_sdio_sendfromq()
2370 if (!bus->intr) { in brcmf_sdio_sendfromq()
2372 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_sendfromq()
2373 intstatus = brcmf_sdiod_readl(bus->sdiodev, in brcmf_sdio_sendfromq()
2375 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_sendfromq()
2377 bus->sdcnt.f2txdata++; in brcmf_sdio_sendfromq()
2380 if (intstatus & bus->hostintmask) in brcmf_sdio_sendfromq()
2381 atomic_set(&bus->ipend, 1); in brcmf_sdio_sendfromq()
2386 if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) && in brcmf_sdio_sendfromq()
2387 bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { in brcmf_sdio_sendfromq()
2388 bus->txoff = false; in brcmf_sdio_sendfromq()
2389 brcmf_proto_bcdc_txflowblock(bus->sdiodev->dev, false); in brcmf_sdio_sendfromq()
2395 static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len) in brcmf_sdio_tx_ctrlframe() argument
2405 /* Back the pointer to make room for bus header */ in brcmf_sdio_tx_ctrlframe()
2406 frame -= bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2407 len += bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2410 doff = ((unsigned long)frame % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2414 memset(frame + bus->tx_hdrlen, 0, doff); in brcmf_sdio_tx_ctrlframe()
2419 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { in brcmf_sdio_tx_ctrlframe()
2420 pad = bus->blocksize - (len % bus->blocksize); in brcmf_sdio_tx_ctrlframe()
2421 if ((pad > bus->roundup) || (pad >= bus->blocksize)) in brcmf_sdio_tx_ctrlframe()
2423 } else if (len % bus->head_align) { in brcmf_sdio_tx_ctrlframe()
2424 pad = bus->head_align - (len % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2430 hd_info.dat_offset = doff + bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2431 hd_info.seq_num = bus->tx_seq; in brcmf_sdio_tx_ctrlframe()
2434 brcmf_sdio_hdpack(bus, frame, &hd_info); in brcmf_sdio_tx_ctrlframe()
2436 if (bus->txglom) in brcmf_sdio_tx_ctrlframe()
2446 ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); in brcmf_sdio_tx_ctrlframe()
2449 brcmf_sdio_txfail(bus); in brcmf_sdio_tx_ctrlframe()
2451 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; in brcmf_sdio_tx_ctrlframe()
2469 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_stop() local
2470 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_bus_stop()
2477 if (bus->watchdog_tsk) { in brcmf_sdio_bus_stop()
2478 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_bus_stop()
2479 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_bus_stop()
2480 bus->watchdog_tsk = NULL; in brcmf_sdio_bus_stop()
2487 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_stop()
2493 local_hostintmask = bus->hostintmask; in brcmf_sdio_bus_stop()
2494 bus->hostintmask = 0; in brcmf_sdio_bus_stop()
2501 bpreq |= brcmf_chip_is_ulp(bus->ci) ? in brcmf_sdio_bus_stop()
2511 /* Turn off the bus (F2), free any pending packets */ in brcmf_sdio_bus_stop()
2522 brcmu_pktq_flush(&bus->txq, true, NULL, NULL); in brcmf_sdio_bus_stop()
2525 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_bus_stop()
2526 brcmf_sdio_free_glom(bus); in brcmf_sdio_bus_stop()
2529 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2530 bus->rxlen = 0; in brcmf_sdio_bus_stop()
2531 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2532 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_bus_stop()
2535 bus->rxskip = false; in brcmf_sdio_bus_stop()
2536 bus->tx_seq = bus->rx_seq = 0; in brcmf_sdio_bus_stop()
2539 static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) in brcmf_sdio_clrintr() argument
2544 sdiodev = bus->sdiodev; in brcmf_sdio_clrintr()
2547 if (!sdiodev->irq_en && !atomic_read(&bus->ipend)) { in brcmf_sdio_clrintr()
2548 enable_irq(sdiodev->settings->bus.sdio.oob_irq_nr); in brcmf_sdio_clrintr()
2555 static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) in brcmf_sdio_intr_rstatus() argument
2557 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_intr_rstatus()
2564 val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret); in brcmf_sdio_intr_rstatus()
2565 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2569 val &= bus->hostintmask; in brcmf_sdio_intr_rstatus()
2570 atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); in brcmf_sdio_intr_rstatus()
2574 brcmf_sdiod_writel(bus->sdiodev, addr, val, &ret); in brcmf_sdio_intr_rstatus()
2575 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2576 atomic_or(val, &bus->intstatus); in brcmf_sdio_intr_rstatus()
2582 static void brcmf_sdio_dpc(struct brcmf_sdio *bus) in brcmf_sdio_dpc() argument
2584 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_dpc()
2586 u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus); in brcmf_sdio_dpc()
2588 uint txlimit = bus->txbound; /* Tx frames to send before resched */ in brcmf_sdio_dpc()
2594 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2597 if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { in brcmf_sdio_dpc()
2602 devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_dpc()
2607 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_dpc()
2614 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_dpc()
2617 brcmf_sdiod_writeb(bus->sdiodev, in brcmf_sdio_dpc()
2619 bus->clkstate = CLK_AVAIL; in brcmf_sdio_dpc()
2624 brcmf_sdio_bus_sleep(bus, false, true); in brcmf_sdio_dpc()
2627 if (atomic_read(&bus->ipend) > 0) { in brcmf_sdio_dpc()
2628 atomic_set(&bus->ipend, 0); in brcmf_sdio_dpc()
2629 err = brcmf_sdio_intr_rstatus(bus); in brcmf_sdio_dpc()
2633 intstatus = atomic_xchg(&bus->intstatus, 0); in brcmf_sdio_dpc()
2645 bus->sdcnt.f1regdata += 2; in brcmf_sdio_dpc()
2646 atomic_set(&bus->fcstate, in brcmf_sdio_dpc()
2648 intstatus |= (newstatus & bus->hostintmask); in brcmf_sdio_dpc()
2654 intstatus |= brcmf_sdio_hostmail(bus); in brcmf_sdio_dpc()
2657 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2682 if (bus->rxskip) in brcmf_sdio_dpc()
2686 if ((intstatus & I_HMB_FRAME_IND) && (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_dpc()
2687 brcmf_sdio_readframes(bus, bus->rxbound); in brcmf_sdio_dpc()
2688 if (!bus->rxpending) in brcmf_sdio_dpc()
2694 atomic_or(intstatus, &bus->intstatus); in brcmf_sdio_dpc()
2696 brcmf_sdio_clrintr(bus); in brcmf_sdio_dpc()
2698 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && in brcmf_sdio_dpc()
2699 txctl_ok(bus)) { in brcmf_sdio_dpc()
2700 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2701 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2702 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, in brcmf_sdio_dpc()
2703 bus->ctrl_frame_len); in brcmf_sdio_dpc()
2704 bus->ctrl_frame_err = err; in brcmf_sdio_dpc()
2706 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2711 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2712 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2715 if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2716 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit && in brcmf_sdio_dpc()
2717 data_ok(bus)) { in brcmf_sdio_dpc()
2718 framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : in brcmf_sdio_dpc()
2720 brcmf_sdio_sendfromq(bus, framecnt); in brcmf_sdio_dpc()
2723 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { in brcmf_sdio_dpc()
2725 atomic_set(&bus->intstatus, 0); in brcmf_sdio_dpc()
2726 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2727 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2728 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2729 bus->ctrl_frame_err = -ENODEV; in brcmf_sdio_dpc()
2731 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2732 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2734 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2736 } else if (atomic_read(&bus->intstatus) || in brcmf_sdio_dpc()
2737 atomic_read(&bus->ipend) > 0 || in brcmf_sdio_dpc()
2738 (!atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2739 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && in brcmf_sdio_dpc()
2740 data_ok(bus))) { in brcmf_sdio_dpc()
2741 bus->dpc_triggered = true; in brcmf_sdio_dpc()
2749 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_gettxq() local
2751 return &bus->txq; in brcmf_sdio_bus_gettxq()
2802 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txdata() local
2809 skb_push(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2822 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); in brcmf_sdio_bus_txdata()
2823 bus->sdcnt.fcqueued++; in brcmf_sdio_bus_txdata()
2826 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2829 if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) { in brcmf_sdio_bus_txdata()
2830 skb_pull(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2831 brcmf_err("out of bus->txq !!!\n"); in brcmf_sdio_bus_txdata()
2837 if (pktq_len(&bus->txq) >= TXHI) { in brcmf_sdio_bus_txdata()
2838 bus->txoff = true; in brcmf_sdio_bus_txdata()
2841 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2844 if (pktq_plen(&bus->txq, prec) > qcount[prec]) in brcmf_sdio_bus_txdata()
2845 qcount[prec] = pktq_plen(&bus->txq, prec); in brcmf_sdio_bus_txdata()
2848 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txdata()
2855 static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) in brcmf_sdio_readconsole() argument
2857 struct brcmf_console *c = &bus->console; in brcmf_sdio_readconsole()
2863 if (bus->console_addr == 0) in brcmf_sdio_readconsole()
2867 addr = bus->console_addr + offsetof(struct rte_console, log_le); in brcmf_sdio_readconsole()
2868 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, in brcmf_sdio_readconsole()
2894 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize); in brcmf_sdio_readconsole()
2937 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txctl() local
2945 bus->ctrl_frame_buf = msg; in brcmf_sdio_bus_txctl()
2946 bus->ctrl_frame_len = msglen; in brcmf_sdio_bus_txctl()
2948 bus->ctrl_frame_stat = true; in brcmf_sdio_bus_txctl()
2950 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txctl()
2951 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, in brcmf_sdio_bus_txctl()
2954 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2955 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_txctl()
2956 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2958 bus->ctrl_frame_stat = false; in brcmf_sdio_bus_txctl()
2961 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_txctl()
2965 bus->ctrl_frame_err); in brcmf_sdio_bus_txctl()
2967 ret = bus->ctrl_frame_err; in brcmf_sdio_bus_txctl()
2971 bus->sdcnt.tx_ctlerrs++; in brcmf_sdio_bus_txctl()
2973 bus->sdcnt.tx_ctlpkts++; in brcmf_sdio_bus_txctl()
2979 static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_dump_console() argument
2989 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2996 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
3003 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
3018 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, in brcmf_sdio_dump_console()
3036 static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_trap_info() argument
3047 error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, in brcmf_sdio_trap_info()
3084 static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_assert_info() argument
3099 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_assert_info()
3101 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3107 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3112 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_assert_info()
3119 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3124 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_checkdied()
3136 brcmf_sdio_trap_info(NULL, bus, &sh); in brcmf_sdio_checkdied()
3142 static int brcmf_sdio_died_dump(struct seq_file *seq, struct brcmf_sdio *bus) in brcmf_sdio_died_dump() argument
3147 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_died_dump()
3151 error = brcmf_sdio_assert_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3155 error = brcmf_sdio_trap_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3159 error = brcmf_sdio_dump_console(seq, bus, &sh); in brcmf_sdio_died_dump()
3168 struct brcmf_sdio *bus = bus_if->bus_priv.sdio->bus; in brcmf_sdio_forensic_read() local
3170 return brcmf_sdio_died_dump(seq, bus); in brcmf_sdio_forensic_read()
3177 struct brcmf_sdio_count *sdcnt = &sdiodev->bus->sdcnt; in brcmf_debugfs_sdio_count_read()
3217 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_debugfs_create() local
3223 bus->console_interval = BRCMF_CONSOLE; in brcmf_sdio_debugfs_create()
3229 &bus->console_interval); in brcmf_sdio_debugfs_create()
3232 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3251 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_rxctl() local
3258 timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); in brcmf_sdio_bus_rxctl()
3260 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3261 rxlen = bus->rxlen; in brcmf_sdio_bus_rxctl()
3262 memcpy(msg, bus->rxctl, min(msglen, rxlen)); in brcmf_sdio_bus_rxctl()
3263 bus->rxctl = NULL; in brcmf_sdio_bus_rxctl()
3264 buf = bus->rxctl_orig; in brcmf_sdio_bus_rxctl()
3265 bus->rxctl_orig = NULL; in brcmf_sdio_bus_rxctl()
3266 bus->rxlen = 0; in brcmf_sdio_bus_rxctl()
3267 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3275 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3281 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3285 bus->sdcnt.rx_ctlpkts++; in brcmf_sdio_bus_rxctl()
3287 bus->sdcnt.rx_ctlerrs++; in brcmf_sdio_bus_rxctl()
3346 static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, in brcmf_sdio_download_code_file() argument
3353 err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase, in brcmf_sdio_download_code_file()
3357 err, (int)fw->size, bus->ci->rambase); in brcmf_sdio_download_code_file()
3358 else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, in brcmf_sdio_download_code_file()
3365 static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, in brcmf_sdio_download_nvram() argument
3373 address = bus->ci->ramsize - varsz + bus->ci->rambase; in brcmf_sdio_download_nvram()
3374 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); in brcmf_sdio_download_nvram()
3378 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) in brcmf_sdio_download_nvram()
3384 static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus, in brcmf_sdio_download_firmware() argument
3391 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_download_firmware()
3392 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_download_firmware()
3397 bcmerror = brcmf_sdio_download_code_file(bus, fw); in brcmf_sdio_download_firmware()
3405 bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen); in brcmf_sdio_download_firmware()
3413 if (!brcmf_chip_set_active(bus->ci, rstvec)) { in brcmf_sdio_download_firmware()
3420 brcmf_sdio_clkctl(bus, CLK_SDONLY, false); in brcmf_sdio_download_firmware()
3421 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_download_firmware()
3425 static bool brcmf_sdio_aos_no_decode(struct brcmf_sdio *bus) in brcmf_sdio_aos_no_decode() argument
3427 if (bus->ci->chip == CY_CC_43012_CHIP_ID || in brcmf_sdio_aos_no_decode()
3428 bus->ci->chip == CY_CC_43752_CHIP_ID) in brcmf_sdio_aos_no_decode()
3434 static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) in brcmf_sdio_sr_init() argument
3444 if (brcmf_chip_is_ulp(bus->ci)) { in brcmf_sdio_sr_init()
3452 if (brcmf_sdio_aos_no_decode(bus)) { in brcmf_sdio_sr_init()
3459 val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); in brcmf_sdio_sr_init()
3465 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); in brcmf_sdio_sr_init()
3472 brcmf_sdiod_func0_wb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, in brcmf_sdio_sr_init()
3480 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_sr_init()
3488 bus->sr_enabled = true; in brcmf_sdio_sr_init()
3493 static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) in brcmf_sdio_kso_init() argument
3495 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_kso_init()
3505 val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); in brcmf_sdio_kso_init()
3514 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_init()
3530 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_preinit() local
3531 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_bus_preinit()
3541 bus_if->maxctl += bus->roundup; in brcmf_sdio_bus_preinit()
3543 value += bus->head_align; in brcmf_sdio_bus_preinit()
3544 bus->rxbuf = kmalloc(value, GFP_ATOMIC); in brcmf_sdio_bus_preinit()
3545 if (bus->rxbuf) in brcmf_sdio_bus_preinit()
3546 bus->rxblen = value; in brcmf_sdio_bus_preinit()
3549 * a device perspective, ie. bus:txglom affects the in brcmf_sdio_bus_preinit()
3550 * bus transfers from device to host. in brcmf_sdio_bus_preinit()
3555 err = brcmf_iovar_data_set(dev, "bus:txglom", &iovar, in brcmf_sdio_bus_preinit()
3559 value = sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_bus_preinit()
3562 err = brcmf_iovar_data_set(dev, "bus:txglomalign", &iovar, in brcmf_sdio_bus_preinit()
3569 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_bus_preinit()
3571 bus->txglom = false; in brcmf_sdio_bus_preinit()
3573 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", in brcmf_sdio_bus_preinit()
3576 /* bus:rxglom is allowed to fail */ in brcmf_sdio_bus_preinit()
3579 bus->txglom = true; in brcmf_sdio_bus_preinit()
3580 bus->tx_hdrlen += SDPCM_HWEXT_LEN; in brcmf_sdio_bus_preinit()
3583 brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); in brcmf_sdio_bus_preinit()
3593 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_ramsize() local
3595 return bus->ci->ramsize - bus->ci->srsize; in brcmf_sdio_bus_get_ramsize()
3603 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_memdump() local
3609 brcmf_dbg(INFO, "dump at 0x%08x: size=%zu\n", bus->ci->rambase, in brcmf_sdio_bus_get_memdump()
3612 address = bus->ci->rambase; in brcmf_sdio_bus_get_memdump()
3634 void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) in brcmf_sdio_trigger_dpc() argument
3636 if (!bus->dpc_triggered) { in brcmf_sdio_trigger_dpc()
3637 bus->dpc_triggered = true; in brcmf_sdio_trigger_dpc()
3638 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_trigger_dpc()
3642 void brcmf_sdio_isr(struct brcmf_sdio *bus, bool in_isr) in brcmf_sdio_isr() argument
3646 if (!bus) { in brcmf_sdio_isr()
3647 brcmf_err("bus is null pointer, exiting\n"); in brcmf_sdio_isr()
3652 bus->sdcnt.intrcount++; in brcmf_sdio_isr()
3654 atomic_set(&bus->ipend, 1); in brcmf_sdio_isr()
3656 if (brcmf_sdio_intr_rstatus(bus)) { in brcmf_sdio_isr()
3661 if (!bus->intr) in brcmf_sdio_isr()
3664 bus->dpc_triggered = true; in brcmf_sdio_isr()
3665 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_isr()
3668 static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) in brcmf_sdio_bus_watchdog() argument
3673 if (!bus->sr_enabled && in brcmf_sdio_bus_watchdog()
3674 bus->poll && (++bus->polltick >= bus->pollrate)) { in brcmf_sdio_bus_watchdog()
3678 bus->polltick = 0; in brcmf_sdio_bus_watchdog()
3681 if (!bus->intr || in brcmf_sdio_bus_watchdog()
3682 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { in brcmf_sdio_bus_watchdog()
3684 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3687 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3688 devpend = brcmf_sdiod_func0_rb(bus->sdiodev, in brcmf_sdio_bus_watchdog()
3690 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3698 bus->sdcnt.pollcnt++; in brcmf_sdio_bus_watchdog()
3699 atomic_set(&bus->ipend, 1); in brcmf_sdio_bus_watchdog()
3701 bus->dpc_triggered = true; in brcmf_sdio_bus_watchdog()
3702 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_bus_watchdog()
3707 bus->sdcnt.lastintrs = bus->sdcnt.intrcount; in brcmf_sdio_bus_watchdog()
3711 if (bus->sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() && in brcmf_sdio_bus_watchdog()
3712 bus->console_interval != 0) { in brcmf_sdio_bus_watchdog()
3713 bus->console.count += jiffies_to_msecs(BRCMF_WD_POLL); in brcmf_sdio_bus_watchdog()
3714 if (bus->console.count >= bus->console_interval) { in brcmf_sdio_bus_watchdog()
3715 bus->console.count -= bus->console_interval; in brcmf_sdio_bus_watchdog()
3716 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3718 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_watchdog()
3719 if (brcmf_sdio_readconsole(bus) < 0) in brcmf_sdio_bus_watchdog()
3721 bus->console_interval = 0; in brcmf_sdio_bus_watchdog()
3722 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3728 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3730 if ((!bus->dpc_running) && (bus->idletime > 0) && in brcmf_sdio_bus_watchdog()
3731 (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_bus_watchdog()
3732 bus->idlecount++; in brcmf_sdio_bus_watchdog()
3733 if (bus->idlecount > bus->idletime) { in brcmf_sdio_bus_watchdog()
3735 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3738 bus->console_interval == 0) in brcmf_sdio_bus_watchdog()
3740 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_bus_watchdog()
3741 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3742 brcmf_sdio_bus_sleep(bus, true, false); in brcmf_sdio_bus_watchdog()
3743 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3746 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3749 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3755 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, in brcmf_sdio_dataworker() local
3758 bus->dpc_running = true; in brcmf_sdio_dataworker()
3760 while (READ_ONCE(bus->dpc_triggered)) { in brcmf_sdio_dataworker()
3761 bus->dpc_triggered = false; in brcmf_sdio_dataworker()
3762 brcmf_sdio_dpc(bus); in brcmf_sdio_dataworker()
3763 bus->idlecount = 0; in brcmf_sdio_dataworker()
3765 bus->dpc_running = false; in brcmf_sdio_dataworker()
3766 if (brcmf_sdiod_freezing(bus->sdiodev)) { in brcmf_sdio_dataworker()
3767 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); in brcmf_sdio_dataworker()
3768 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_dataworker()
3769 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_dataworker()
3892 struct brcmf_core *core = sdiodev->bus->sdio_core; in brcmf_sdio_buscore_activate()
3947 brcmf_sdio_probe_attach(struct brcmf_sdio *bus) in brcmf_sdio_probe_attach() argument
3957 sdiodev = bus->sdiodev; in brcmf_sdio_probe_attach()
3982 bus->ci = brcmf_chip_attach(sdiodev, sdiodev->func1->device, in brcmf_sdio_probe_attach()
3984 if (IS_ERR(bus->ci)) { in brcmf_sdio_probe_attach()
3986 bus->ci = NULL; in brcmf_sdio_probe_attach()
3991 bus->sdio_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in brcmf_sdio_probe_attach()
3992 if (!bus->sdio_core) in brcmf_sdio_probe_attach()
3996 sdiodev->cc_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_CHIPCOMMON); in brcmf_sdio_probe_attach()
4002 bus->ci->chip, in brcmf_sdio_probe_attach()
4003 bus->ci->chiprev); in brcmf_sdio_probe_attach()
4011 bus->head_align = ALIGNMENT; in brcmf_sdio_probe_attach()
4012 bus->sgentry_align = ALIGNMENT; in brcmf_sdio_probe_attach()
4013 if (sdiodev->settings->bus.sdio.sd_head_align > ALIGNMENT) in brcmf_sdio_probe_attach()
4014 bus->head_align = sdiodev->settings->bus.sdio.sd_head_align; in brcmf_sdio_probe_attach()
4015 if (sdiodev->settings->bus.sdio.sd_sgentry_align > ALIGNMENT) in brcmf_sdio_probe_attach()
4016 bus->sgentry_align = in brcmf_sdio_probe_attach()
4017 sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_probe_attach()
4030 (sdiodev->settings->bus.sdio.oob_irq_supported))) in brcmf_sdio_probe_attach()
4033 if (brcmf_sdio_kso_init(bus)) { in brcmf_sdio_probe_attach()
4038 if (sdiodev->settings->bus.sdio.drive_strength) in brcmf_sdio_probe_attach()
4039 drivestrength = sdiodev->settings->bus.sdio.drive_strength; in brcmf_sdio_probe_attach()
4042 brcmf_sdio_drivestrengthinit(sdiodev, bus->ci, drivestrength); in brcmf_sdio_probe_attach()
4056 reg_addr = CORE_CC_REG(brcmf_chip_get_pmu(bus->ci)->base, pmucontrol); in brcmf_sdio_probe_attach()
4069 brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); in brcmf_sdio_probe_attach()
4072 bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); in brcmf_sdio_probe_attach()
4073 if (!bus->hdrbuf) in brcmf_sdio_probe_attach()
4076 bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], in brcmf_sdio_probe_attach()
4077 bus->head_align); in brcmf_sdio_probe_attach()
4080 bus->intr = true; in brcmf_sdio_probe_attach()
4081 bus->poll = false; in brcmf_sdio_probe_attach()
4082 if (bus->poll) in brcmf_sdio_probe_attach()
4083 bus->pollrate = 1; in brcmf_sdio_probe_attach()
4095 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog_thread() local
4100 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4104 brcmf_sdiod_freezer_uncount(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4105 wait = wait_for_completion_interruptible(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
4106 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4107 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4109 brcmf_sdio_bus_watchdog(bus); in brcmf_sdio_watchdog_thread()
4111 bus->sdcnt.tickcnt++; in brcmf_sdio_watchdog_thread()
4112 reinit_completion(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
4122 struct brcmf_sdio *bus = from_timer(bus, t, timer); in brcmf_sdio_watchdog() local
4124 if (bus->watchdog_tsk) { in brcmf_sdio_watchdog()
4125 complete(&bus->watchdog_wait); in brcmf_sdio_watchdog()
4127 if (bus->wd_active) in brcmf_sdio_watchdog()
4128 mod_timer(&bus->timer, in brcmf_sdio_watchdog()
4209 struct brcmf_sdio *bus = sdiod->bus; in brcmf_sdio_firmware_callback() local
4210 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_firmware_callback()
4229 bus->alp_only = true; in brcmf_sdio_firmware_callback()
4230 err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len); in brcmf_sdio_firmware_callback()
4233 bus->alp_only = false; in brcmf_sdio_firmware_callback()
4236 bus->sdcnt.tickcnt = 0; in brcmf_sdio_firmware_callback()
4237 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_firmware_callback()
4242 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_firmware_callback()
4243 if (bus->clkstate != CLK_AVAIL) in brcmf_sdio_firmware_callback()
4250 bpreq |= brcmf_chip_is_ulp(bus->ci) ? in brcmf_sdio_firmware_callback()
4271 bus->hostintmask = HOSTINTMASK; in brcmf_sdio_firmware_callback()
4273 bus->hostintmask, NULL); in brcmf_sdio_firmware_callback()
4356 if (brcmf_chip_sr_capable(bus->ci)) { in brcmf_sdio_firmware_callback()
4357 brcmf_sdio_sr_init(bus); in brcmf_sdio_firmware_callback()
4365 /* Assign bus interface call back */ in brcmf_sdio_firmware_callback()
4368 sdiod->bus_if->chip = bus->ci->chip; in brcmf_sdio_firmware_callback()
4369 sdiod->bus_if->chiprev = bus->ci->chiprev; in brcmf_sdio_firmware_callback()
4372 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_firmware_callback()
4381 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_firmware_callback()
4408 brcmf_sdio_checkdied(bus); in brcmf_sdio_firmware_callback()
4418 brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus) in brcmf_sdio_prepare_fw_request() argument
4422 { ".bin", bus->sdiodev->fw_name }, in brcmf_sdio_prepare_fw_request()
4423 { ".txt", bus->sdiodev->nvram_name }, in brcmf_sdio_prepare_fw_request()
4424 { ".clm_blob", bus->sdiodev->clm_name }, in brcmf_sdio_prepare_fw_request()
4427 fwreq = brcmf_fw_alloc_request(bus->ci->chip, bus->ci->chiprev, in brcmf_sdio_prepare_fw_request()
4438 fwreq->board_types[0] = bus->sdiodev->settings->board_type; in brcmf_sdio_prepare_fw_request()
4446 struct brcmf_sdio *bus; in brcmf_sdio_probe() local
4452 /* Allocate private bus interface state */ in brcmf_sdio_probe()
4453 bus = kzalloc(sizeof(*bus), GFP_ATOMIC); in brcmf_sdio_probe()
4454 if (!bus) in brcmf_sdio_probe()
4457 bus->sdiodev = sdiodev; in brcmf_sdio_probe()
4458 sdiodev->bus = bus; in brcmf_sdio_probe()
4459 skb_queue_head_init(&bus->glom); in brcmf_sdio_probe()
4460 bus->txbound = BRCMF_TXBOUND; in brcmf_sdio_probe()
4461 bus->rxbound = BRCMF_RXBOUND; in brcmf_sdio_probe()
4462 bus->txminmax = BRCMF_TXMINMAX; in brcmf_sdio_probe()
4463 bus->tx_seq = SDPCM_SEQ_WRAP - 1; in brcmf_sdio_probe()
4473 INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); in brcmf_sdio_probe()
4474 bus->brcmf_wq = wq; in brcmf_sdio_probe()
4477 if (!(brcmf_sdio_probe_attach(bus))) { in brcmf_sdio_probe()
4482 spin_lock_init(&bus->rxctl_lock); in brcmf_sdio_probe()
4483 spin_lock_init(&bus->txq_lock); in brcmf_sdio_probe()
4484 init_waitqueue_head(&bus->ctrl_wait); in brcmf_sdio_probe()
4485 init_waitqueue_head(&bus->dcmd_resp_wait); in brcmf_sdio_probe()
4488 timer_setup(&bus->timer, brcmf_sdio_watchdog, 0); in brcmf_sdio_probe()
4490 init_completion(&bus->watchdog_wait); in brcmf_sdio_probe()
4491 bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, in brcmf_sdio_probe()
4492 bus, "brcmf_wdog/%s", in brcmf_sdio_probe()
4494 if (IS_ERR(bus->watchdog_tsk)) { in brcmf_sdio_probe()
4496 bus->watchdog_tsk = NULL; in brcmf_sdio_probe()
4499 bus->dpc_triggered = false; in brcmf_sdio_probe()
4500 bus->dpc_running = false; in brcmf_sdio_probe()
4502 /* default sdio bus header length for tx packet */ in brcmf_sdio_probe()
4503 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_probe()
4506 bus->blocksize = bus->sdiodev->func2->cur_blksize; in brcmf_sdio_probe()
4507 bus->roundup = min(max_roundup, bus->blocksize); in brcmf_sdio_probe()
4509 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_probe()
4512 sdio_disable_func(bus->sdiodev->func2); in brcmf_sdio_probe()
4514 bus->rxflow = false; in brcmf_sdio_probe()
4517 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); in brcmf_sdio_probe()
4519 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_probe()
4522 bus->clkstate = CLK_SDONLY; in brcmf_sdio_probe()
4523 bus->idletime = BRCMF_IDLE_INTERVAL; in brcmf_sdio_probe()
4524 bus->idleclock = BRCMF_IDLE_ACTIVE; in brcmf_sdio_probe()
4527 bus->sr_enabled = false; in brcmf_sdio_probe()
4531 fwreq = brcmf_sdio_prepare_fw_request(bus); in brcmf_sdio_probe()
4545 return bus; in brcmf_sdio_probe()
4548 brcmf_sdio_remove(bus); in brcmf_sdio_probe()
4553 void brcmf_sdio_remove(struct brcmf_sdio *bus) in brcmf_sdio_remove() argument
4557 if (bus) { in brcmf_sdio_remove()
4559 if (bus->watchdog_tsk) { in brcmf_sdio_remove()
4560 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_remove()
4561 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_remove()
4562 bus->watchdog_tsk = NULL; in brcmf_sdio_remove()
4566 brcmf_sdiod_intr_unregister(bus->sdiodev); in brcmf_sdio_remove()
4568 brcmf_detach(bus->sdiodev->dev); in brcmf_sdio_remove()
4569 brcmf_free(bus->sdiodev->dev); in brcmf_sdio_remove()
4571 cancel_work_sync(&bus->datawork); in brcmf_sdio_remove()
4572 if (bus->brcmf_wq) in brcmf_sdio_remove()
4573 destroy_workqueue(bus->brcmf_wq); in brcmf_sdio_remove()
4575 if (bus->ci) { in brcmf_sdio_remove()
4576 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { in brcmf_sdio_remove()
4577 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_remove()
4578 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_remove()
4579 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_remove()
4585 brcmf_chip_set_passive(bus->ci); in brcmf_sdio_remove()
4586 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_remove()
4587 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_remove()
4589 brcmf_chip_detach(bus->ci); in brcmf_sdio_remove()
4591 if (bus->sdiodev->settings) in brcmf_sdio_remove()
4592 brcmf_release_module_param(bus->sdiodev->settings); in brcmf_sdio_remove()
4594 release_firmware(bus->sdiodev->clm_fw); in brcmf_sdio_remove()
4595 bus->sdiodev->clm_fw = NULL; in brcmf_sdio_remove()
4596 kfree(bus->rxbuf); in brcmf_sdio_remove()
4597 kfree(bus->hdrbuf); in brcmf_sdio_remove()
4598 kfree(bus); in brcmf_sdio_remove()
4604 void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, bool active) in brcmf_sdio_wd_timer() argument
4607 if (!active && bus->wd_active) { in brcmf_sdio_wd_timer()
4608 del_timer_sync(&bus->timer); in brcmf_sdio_wd_timer()
4609 bus->wd_active = false; in brcmf_sdio_wd_timer()
4614 if (bus->sdiodev->state != BRCMF_SDIOD_DATA) in brcmf_sdio_wd_timer()
4618 if (!bus->wd_active) { in brcmf_sdio_wd_timer()
4622 bus->timer.expires = jiffies + BRCMF_WD_POLL; in brcmf_sdio_wd_timer()
4623 add_timer(&bus->timer); in brcmf_sdio_wd_timer()
4624 bus->wd_active = true; in brcmf_sdio_wd_timer()
4627 mod_timer(&bus->timer, jiffies + BRCMF_WD_POLL); in brcmf_sdio_wd_timer()
4632 int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep) in brcmf_sdio_sleep() argument
4636 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_sleep()
4637 ret = brcmf_sdio_bus_sleep(bus, sleep, false); in brcmf_sdio_sleep()
4638 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_sleep()