Lines Matching full:bus

112 #include "bus.h"
149 * sdio bus power cycle to clear (rev 9) */
224 #define I_BUSPWR (1 << 17) /* SDIO Bus Power Change (rev 9) */
391 /* dongle SDIO bus specific header info */
438 /* Private data for SDIO bus interaction */
478 u8 sdpcm_ver; /* Bus protocol reported by dongle */
496 s32 idleclock; /* How to set bus driver when idle */
506 spinlock_t txq_lock; /* protect bus->txq */
525 u8 tx_hdrlen; /* sdio bus header length for tx packet */
665 static bool data_ok(struct brcmf_sdio *bus) in data_ok() argument
670 if (bus->ctrl_frame_stat) in data_ok()
673 return (bus->tx_max - bus->tx_seq - tx_rsv) != 0 && in data_ok()
674 ((bus->tx_max - bus->tx_seq - tx_rsv) & 0x80) == 0; in data_ok()
679 static bool txctl_ok(struct brcmf_sdio *bus) in txctl_ok() argument
681 return (bus->tx_max - bus->tx_seq) != 0 && in txctl_ok()
682 ((bus->tx_max - bus->tx_seq) & 0x80) == 0; in txctl_ok()
686 brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) in brcmf_sdio_kso_control() argument
695 sdio_retune_crc_disable(bus->sdiodev->func1); in brcmf_sdio_kso_control()
699 sdio_retune_hold_now(bus->sdiodev->func1); in brcmf_sdio_kso_control()
703 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err); in brcmf_sdio_kso_control()
710 if (!on && bus->ci->chip == CY_CC_43012_CHIP_ID) in brcmf_sdio_kso_control()
737 rd_val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
749 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, in brcmf_sdio_kso_control()
762 sdio_retune_release(bus->sdiodev->func1); in brcmf_sdio_kso_control()
764 sdio_retune_crc_enable(bus->sdiodev->func1); in brcmf_sdio_kso_control()
772 static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok) in brcmf_sdio_htclk() argument
782 if (bus->sr_enabled) { in brcmf_sdio_htclk()
783 bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); in brcmf_sdio_htclk()
790 bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; in brcmf_sdio_htclk()
792 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
800 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
808 if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { in brcmf_sdio_htclk()
810 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
818 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
821 bus->clkstate = CLK_PENDING; in brcmf_sdio_htclk()
824 } else if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
826 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
829 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
836 while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
837 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
849 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
856 bus->clkstate = CLK_AVAIL; in brcmf_sdio_htclk()
860 if (!bus->alp_only) { in brcmf_sdio_htclk()
869 if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
871 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
874 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
878 bus->clkstate = CLK_SDONLY; in brcmf_sdio_htclk()
879 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
892 static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) in brcmf_sdio_sdclk() argument
897 bus->clkstate = CLK_SDONLY; in brcmf_sdio_sdclk()
899 bus->clkstate = CLK_NONE; in brcmf_sdio_sdclk()
905 static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) in brcmf_sdio_clkctl() argument
908 uint oldstate = bus->clkstate; in brcmf_sdio_clkctl()
914 if (bus->clkstate == target) in brcmf_sdio_clkctl()
920 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
921 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
923 brcmf_sdio_htclk(bus, true, pendok); in brcmf_sdio_clkctl()
928 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
929 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
930 else if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
931 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
934 bus->clkstate, target); in brcmf_sdio_clkctl()
939 if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
940 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
942 brcmf_sdio_sdclk(bus, false); in brcmf_sdio_clkctl()
946 brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); in brcmf_sdio_clkctl()
953 brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) in brcmf_sdio_bus_sleep() argument
960 (bus->sleeping ? "SLEEP" : "WAKE")); in brcmf_sdio_bus_sleep()
962 /* If SR is enabled control bus state with KSO */ in brcmf_sdio_bus_sleep()
963 if (bus->sr_enabled) { in brcmf_sdio_bus_sleep()
965 if (sleep == bus->sleeping) in brcmf_sdio_bus_sleep()
970 clkcsr = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_bus_sleep()
975 brcmf_sdiod_writeb(bus->sdiodev, in brcmf_sdio_bus_sleep()
979 err = brcmf_sdio_kso_control(bus, false); in brcmf_sdio_bus_sleep()
981 err = brcmf_sdio_kso_control(bus, true); in brcmf_sdio_bus_sleep()
984 brcmf_err("error while changing bus sleep state %d\n", in brcmf_sdio_bus_sleep()
993 if (!bus->sr_enabled) in brcmf_sdio_bus_sleep()
994 brcmf_sdio_clkctl(bus, CLK_NONE, pendok); in brcmf_sdio_bus_sleep()
996 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); in brcmf_sdio_bus_sleep()
997 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_bus_sleep()
999 bus->sleeping = sleep; in brcmf_sdio_bus_sleep()
1014 static int brcmf_sdio_readshared(struct brcmf_sdio *bus, in brcmf_sdio_readshared() argument
1023 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1024 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_readshared()
1030 shaddr = bus->ci->rambase + bus->ci->ramsize - 4; in brcmf_sdio_readshared()
1031 if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci)) in brcmf_sdio_readshared()
1032 shaddr -= bus->ci->srsize; in brcmf_sdio_readshared()
1033 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, in brcmf_sdio_readshared()
1052 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, in brcmf_sdio_readshared()
1057 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1079 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1083 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1087 if (brcmf_sdio_readshared(bus, &sh) == 0) in brcmf_sdio_get_console_addr()
1088 bus->console_addr = sh.console_addr; in brcmf_sdio_get_console_addr()
1091 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1096 static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus) in brcmf_sdio_hostmail() argument
1098 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_hostmail()
1099 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_hostmail()
1116 bus->sdcnt.f1regdata += 2; in brcmf_sdio_hostmail()
1127 bus->rx_seq); in brcmf_sdio_hostmail()
1128 if (!bus->rxskip) in brcmf_sdio_hostmail()
1131 bus->rxskip = false; in brcmf_sdio_hostmail()
1139 bus->sdpcm_ver = in brcmf_sdio_hostmail()
1142 if (bus->sdpcm_ver != SDPCM_PROT_VERSION) in brcmf_sdio_hostmail()
1145 bus->sdpcm_ver, SDPCM_PROT_VERSION); in brcmf_sdio_hostmail()
1148 bus->sdpcm_ver); in brcmf_sdio_hostmail()
1154 brcmf_sdio_get_console_addr(bus); in brcmf_sdio_hostmail()
1166 if (fcbits & ~bus->flowcontrol) in brcmf_sdio_hostmail()
1167 bus->sdcnt.fc_xoff++; in brcmf_sdio_hostmail()
1169 if (bus->flowcontrol & ~fcbits) in brcmf_sdio_hostmail()
1170 bus->sdcnt.fc_xon++; in brcmf_sdio_hostmail()
1172 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hostmail()
1173 bus->flowcontrol = fcbits; in brcmf_sdio_hostmail()
1189 static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx) in brcmf_sdio_rxfail() argument
1191 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_rxfail()
1192 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_rxfail()
1203 brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func2); in brcmf_sdio_rxfail()
1205 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, in brcmf_sdio_rxfail()
1207 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1211 hi = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCHI, in brcmf_sdio_rxfail()
1213 lo = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCLO, in brcmf_sdio_rxfail()
1215 bus->sdcnt.f1regdata += 2; in brcmf_sdio_rxfail()
1233 bus->sdcnt.rxrtx++; in brcmf_sdio_rxfail()
1237 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1239 bus->rxskip = true; in brcmf_sdio_rxfail()
1243 bus->cur_read.len = 0; in brcmf_sdio_rxfail()
1246 static void brcmf_sdio_txfail(struct brcmf_sdio *bus) in brcmf_sdio_txfail() argument
1248 struct brcmf_sdio_dev *sdiodev = bus->sdiodev; in brcmf_sdio_txfail()
1253 bus->sdcnt.tx_sderrs++; in brcmf_sdio_txfail()
1257 bus->sdcnt.f1regdata++; in brcmf_sdio_txfail()
1262 bus->sdcnt.f1regdata += 2; in brcmf_sdio_txfail()
1269 static uint brcmf_sdio_glom_len(struct brcmf_sdio *bus) in brcmf_sdio_glom_len() argument
1275 skb_queue_walk(&bus->glom, p) in brcmf_sdio_glom_len()
1280 static void brcmf_sdio_free_glom(struct brcmf_sdio *bus) in brcmf_sdio_free_glom() argument
1284 skb_queue_walk_safe(&bus->glom, cur, next) { in brcmf_sdio_free_glom()
1285 skb_unlink(cur, &bus->glom); in brcmf_sdio_free_glom()
1291 * brcmfmac sdio bus specific header
1358 static int brcmf_sdio_hdparse(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdparse() argument
1373 bus->rxpending = false; in brcmf_sdio_hdparse()
1378 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1379 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1387 (roundup(len, bus->blocksize) != rd->len)) { in brcmf_sdio_hdparse()
1410 bus->sdcnt.rx_toolong++; in brcmf_sdio_hdparse()
1411 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1429 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1430 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1436 bus->sdcnt.rx_badseq++; in brcmf_sdio_hdparse()
1451 if (bus->flowcontrol != fc) { in brcmf_sdio_hdparse()
1452 if (~bus->flowcontrol & fc) in brcmf_sdio_hdparse()
1453 bus->sdcnt.fc_xoff++; in brcmf_sdio_hdparse()
1454 if (bus->flowcontrol & ~fc) in brcmf_sdio_hdparse()
1455 bus->sdcnt.fc_xon++; in brcmf_sdio_hdparse()
1456 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hdparse()
1457 bus->flowcontrol = fc; in brcmf_sdio_hdparse()
1460 if ((u8)(tx_seq_max - bus->tx_seq) > 0x40) { in brcmf_sdio_hdparse()
1462 tx_seq_max = bus->tx_seq + 2; in brcmf_sdio_hdparse()
1464 bus->tx_max = tx_seq_max; in brcmf_sdio_hdparse()
1475 static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdpack() argument
1484 if (bus->txglom) { in brcmf_sdio_hdpack()
1499 trace_brcmf_sdpcm_hdr(SDPCM_TX + !!(bus->txglom), header); in brcmf_sdio_hdpack()
1502 static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq) in brcmf_sdio_rxglom() argument
1518 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_rxglom()
1521 if (bus->glomd) { in brcmf_sdio_rxglom()
1523 dlen = (u16) (bus->glomd->len); in brcmf_sdio_rxglom()
1524 dptr = bus->glomd->data; in brcmf_sdio_rxglom()
1543 if (sublen % bus->sgentry_align) { in brcmf_sdio_rxglom()
1545 sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1553 (roundup(totlen, bus->blocksize) - totlen); in brcmf_sdio_rxglom()
1554 totlen = roundup(totlen, bus->blocksize); in brcmf_sdio_rxglom()
1558 pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align); in brcmf_sdio_rxglom()
1564 skb_queue_tail(&bus->glom, pnext); in brcmf_sdio_rxglom()
1567 pkt_align(pnext, sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1571 in bus structure */ in brcmf_sdio_rxglom()
1575 if (BRCMF_GLOM_ON() && bus->cur_read.len && in brcmf_sdio_rxglom()
1576 totlen != bus->cur_read.len) { in brcmf_sdio_rxglom()
1578 bus->cur_read.len, totlen, rxseq); in brcmf_sdio_rxglom()
1582 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1587 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_rxglom()
1588 bus->glomd = NULL; in brcmf_sdio_rxglom()
1589 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1594 if (!skb_queue_empty(&bus->glom)) { in brcmf_sdio_rxglom()
1597 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1604 pfirst = skb_peek(&bus->glom); in brcmf_sdio_rxglom()
1605 dlen = (u16) brcmf_sdio_glom_len(bus); in brcmf_sdio_rxglom()
1611 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1612 errcode = brcmf_sdiod_recv_chain(bus->sdiodev, in brcmf_sdio_rxglom()
1613 &bus->glom, dlen); in brcmf_sdio_rxglom()
1614 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1615 bus->sdcnt.f2rxdata++; in brcmf_sdio_rxglom()
1622 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1623 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1624 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1625 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1626 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1636 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1637 errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new, in brcmf_sdio_rxglom()
1639 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1640 bus->cur_read.len = rd_new.len_nxtfrm << 4; in brcmf_sdio_rxglom()
1647 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1654 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1655 errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new, in brcmf_sdio_rxglom()
1657 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1666 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1667 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1668 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1669 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1670 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1671 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1677 skb_queue_walk_safe(&bus->glom, pfirst, pnext) { in brcmf_sdio_rxglom()
1690 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1699 bus->glom.qlen, pfirst, pfirst->data, in brcmf_sdio_rxglom()
1702 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1704 brcmf_rx_event(bus->sdiodev->dev, pfirst); in brcmf_sdio_rxglom()
1706 brcmf_rx_frame(bus->sdiodev->dev, pfirst, in brcmf_sdio_rxglom()
1708 bus->sdcnt.rxglompkts++; in brcmf_sdio_rxglom()
1711 bus->sdcnt.rxglomframes++; in brcmf_sdio_rxglom()
1716 static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition, in brcmf_sdio_dcmd_resp_wait() argument
1723 add_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1733 remove_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1738 static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus) in brcmf_sdio_dcmd_resp_wake() argument
1740 wake_up_interruptible(&bus->dcmd_resp_wait); in brcmf_sdio_dcmd_resp_wake()
1745 brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff) in brcmf_sdio_read_control() argument
1752 if (bus->rxblen) in brcmf_sdio_read_control()
1753 buf = vzalloc(bus->rxblen); in brcmf_sdio_read_control()
1757 rbuf = bus->rxbuf; in brcmf_sdio_read_control()
1758 pad = ((unsigned long)rbuf % bus->head_align); in brcmf_sdio_read_control()
1760 rbuf += (bus->head_align - pad); in brcmf_sdio_read_control()
1769 if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { in brcmf_sdio_read_control()
1770 pad = bus->blocksize - (rdlen % bus->blocksize); in brcmf_sdio_read_control()
1771 if ((pad <= bus->roundup) && (pad < bus->blocksize) && in brcmf_sdio_read_control()
1772 ((len + pad) < bus->sdiodev->bus_if->maxctl)) in brcmf_sdio_read_control()
1774 } else if (rdlen % bus->head_align) { in brcmf_sdio_read_control()
1775 rdlen += bus->head_align - (rdlen % bus->head_align); in brcmf_sdio_read_control()
1779 if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1781 rdlen, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1782 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1786 if ((len - doff) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1788 len, len - doff, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1789 bus->sdcnt.rx_toolong++; in brcmf_sdio_read_control()
1790 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1795 sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen); in brcmf_sdio_read_control()
1796 bus->sdcnt.f2rxdata++; in brcmf_sdio_read_control()
1802 bus->sdcnt.rxc_errors++; in brcmf_sdio_read_control()
1803 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_read_control()
1814 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1815 if (bus->rxctl) { in brcmf_sdio_read_control()
1817 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1821 bus->rxctl = buf + doff; in brcmf_sdio_read_control()
1822 bus->rxctl_orig = buf; in brcmf_sdio_read_control()
1823 bus->rxlen = len - doff; in brcmf_sdio_read_control()
1824 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1828 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_read_control()
1832 static void brcmf_sdio_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen) in brcmf_sdio_pad() argument
1834 if (bus->roundup && bus->blocksize && *rdlen > bus->blocksize) { in brcmf_sdio_pad()
1835 *pad = bus->blocksize - (*rdlen % bus->blocksize); in brcmf_sdio_pad()
1836 if (*pad <= bus->roundup && *pad < bus->blocksize && in brcmf_sdio_pad()
1839 } else if (*rdlen % bus->head_align) { in brcmf_sdio_pad()
1840 *rdlen += bus->head_align - (*rdlen % bus->head_align); in brcmf_sdio_pad()
1844 static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_readframes() argument
1851 struct brcmf_sdio_hdrinfo *rd = &bus->cur_read, rd_new; in brcmf_sdio_readframes()
1857 bus->rxpending = true; in brcmf_sdio_readframes()
1859 for (rd->seq_num = bus->rx_seq, rxleft = maxframes; in brcmf_sdio_readframes()
1860 !bus->rxskip && rxleft && bus->sdiodev->state == BRCMF_SDIOD_DATA; in brcmf_sdio_readframes()
1864 if (bus->glomd || !skb_queue_empty(&bus->glom)) { in brcmf_sdio_readframes()
1867 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_readframes()
1868 cnt = brcmf_sdio_rxglom(bus, rd->seq_num); in brcmf_sdio_readframes()
1877 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1879 ret = brcmf_sdiod_recv_buf(bus->sdiodev, in brcmf_sdio_readframes()
1880 bus->rxhdr, BRCMF_FIRSTREAD); in brcmf_sdio_readframes()
1881 bus->sdcnt.f2rxhdrs++; in brcmf_sdio_readframes()
1885 bus->sdcnt.rx_hdrfail++; in brcmf_sdio_readframes()
1886 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1887 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1892 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1895 if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd, in brcmf_sdio_readframes()
1897 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1898 if (!bus->rxpending) in brcmf_sdio_readframes()
1905 brcmf_sdio_read_control(bus, bus->rxhdr, in brcmf_sdio_readframes()
1913 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1921 brcmf_sdio_pad(bus, &pad, &rd->len_left); in brcmf_sdio_readframes()
1924 bus->head_align); in brcmf_sdio_readframes()
1928 brcmf_sdio_rxfail(bus, false, in brcmf_sdio_readframes()
1930 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1934 pkt_align(pkt, rd->len_left, bus->head_align); in brcmf_sdio_readframes()
1936 ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt); in brcmf_sdio_readframes()
1937 bus->sdcnt.f2rxdata++; in brcmf_sdio_readframes()
1938 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1944 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1945 brcmf_sdio_rxfail(bus, true, in brcmf_sdio_readframes()
1947 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1953 memcpy(pkt->data, bus->rxhdr, head_read); in brcmf_sdio_readframes()
1956 memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN); in brcmf_sdio_readframes()
1958 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1959 if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new, in brcmf_sdio_readframes()
1962 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1963 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1967 bus->sdcnt.rx_readahead_cnt++; 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 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1986 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1994 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1995 brcmf_sdio_rxfail(bus, false, true); in brcmf_sdio_readframes()
1996 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2007 if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_HWHDR_LEN])) { in brcmf_sdio_readframes()
2015 bus->glomd = pkt; in brcmf_sdio_readframes()
2019 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2020 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_readframes()
2021 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2038 brcmf_rx_event(bus->sdiodev->dev, pkt); in brcmf_sdio_readframes()
2040 brcmf_rx_frame(bus->sdiodev->dev, pkt, in brcmf_sdio_readframes()
2057 if (bus->rxskip) in brcmf_sdio_readframes()
2059 bus->rx_seq = rd->seq_num; in brcmf_sdio_readframes()
2065 brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus) in brcmf_sdio_wait_event_wakeup() argument
2067 wake_up_interruptible(&bus->ctrl_wait); in brcmf_sdio_wait_event_wakeup()
2071 static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt) in brcmf_sdio_txpkt_hdalign() argument
2080 head_pad = ((unsigned long)dat_buf % bus->head_align); in brcmf_sdio_txpkt_hdalign()
2083 stats = &bus->sdiodev->bus_if->stats; in brcmf_sdio_txpkt_hdalign()
2094 memset(dat_buf, 0, head_pad + bus->tx_hdrlen); in brcmf_sdio_txpkt_hdalign()
2100 * bus layer usage.
2107 static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus, in brcmf_sdio_txpkt_prep_sg() argument
2118 sdiodev = bus->sdiodev; in brcmf_sdio_txpkt_prep_sg()
2121 WARN_ON(blksize % bus->sgentry_align); in brcmf_sdio_txpkt_prep_sg()
2126 tail_chop = pkt->len % bus->sgentry_align; in brcmf_sdio_txpkt_prep_sg()
2128 tail_pad = bus->sgentry_align - tail_chop; in brcmf_sdio_txpkt_prep_sg()
2134 bus->head_align); in brcmf_sdio_txpkt_prep_sg()
2137 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); in brcmf_sdio_txpkt_prep_sg()
2165 * @bus: brcmf_sdio structure pointer
2176 brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt_prep() argument
2185 txseq = bus->tx_seq; in brcmf_sdio_txpkt_prep()
2197 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_next); in brcmf_sdio_txpkt_prep()
2202 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad); in brcmf_sdio_txpkt_prep()
2208 if (bus->txglom && pktq->qlen > 1) { in brcmf_sdio_txpkt_prep()
2209 ret = brcmf_sdio_txpkt_prep_sg(bus, pktq, in brcmf_sdio_txpkt_prep()
2218 hd_info.dat_offset = head_pad + bus->tx_hdrlen; in brcmf_sdio_txpkt_prep()
2222 brcmf_sdio_hdpack(bus, pkt_next->data, &hd_info); in brcmf_sdio_txpkt_prep()
2231 head_pad + bus->tx_hdrlen, in brcmf_sdio_txpkt_prep()
2237 if (bus->txglom) in brcmf_sdio_txpkt_prep()
2244 * @bus: brcmf_sdio structure pointer
2252 brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq) in brcmf_sdio_txpkt_postp() argument
2271 hdr = pkt_next->data + bus->tx_hdrlen - SDPCM_SWHDR_LEN; in brcmf_sdio_txpkt_postp()
2276 if (bus->txglom) { in brcmf_sdio_txpkt_postp()
2286 static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt() argument
2294 ret = brcmf_sdio_txpkt_prep(bus, pktq, chan); in brcmf_sdio_txpkt()
2298 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_txpkt()
2299 ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq); in brcmf_sdio_txpkt()
2300 bus->sdcnt.f2txdata++; in brcmf_sdio_txpkt()
2303 brcmf_sdio_txfail(bus); in brcmf_sdio_txpkt()
2305 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_txpkt()
2308 brcmf_sdio_txpkt_postp(bus, pktq); in brcmf_sdio_txpkt()
2310 bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP; in brcmf_sdio_txpkt()
2313 brcmf_proto_bcdc_txcomplete(bus->sdiodev->dev, pkt_next, in brcmf_sdio_txpkt()
2319 static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_sendfromq() argument
2323 u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus); in brcmf_sdio_sendfromq()
2331 tx_prec_map = ~bus->flowcontrol; in brcmf_sdio_sendfromq()
2334 for (cnt = 0; (cnt < maxframes) && data_ok(bus);) { in brcmf_sdio_sendfromq()
2336 if (bus->txglom) in brcmf_sdio_sendfromq()
2337 pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, in brcmf_sdio_sendfromq()
2338 bus->sdiodev->txglomsz); in brcmf_sdio_sendfromq()
2340 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); in brcmf_sdio_sendfromq()
2342 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2344 pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, in brcmf_sdio_sendfromq()
2350 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2354 ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); in brcmf_sdio_sendfromq()
2359 if (!bus->intr) { in brcmf_sdio_sendfromq()
2361 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_sendfromq()
2362 intstatus = brcmf_sdiod_readl(bus->sdiodev, in brcmf_sdio_sendfromq()
2364 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_sendfromq()
2366 bus->sdcnt.f2txdata++; in brcmf_sdio_sendfromq()
2369 if (intstatus & bus->hostintmask) in brcmf_sdio_sendfromq()
2370 atomic_set(&bus->ipend, 1); in brcmf_sdio_sendfromq()
2375 if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) && in brcmf_sdio_sendfromq()
2376 bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { in brcmf_sdio_sendfromq()
2377 bus->txoff = false; in brcmf_sdio_sendfromq()
2378 brcmf_proto_bcdc_txflowblock(bus->sdiodev->dev, false); in brcmf_sdio_sendfromq()
2384 static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len) in brcmf_sdio_tx_ctrlframe() argument
2394 /* Back the pointer to make room for bus header */ in brcmf_sdio_tx_ctrlframe()
2395 frame -= bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2396 len += bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2399 doff = ((unsigned long)frame % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2403 memset(frame + bus->tx_hdrlen, 0, doff); in brcmf_sdio_tx_ctrlframe()
2408 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { in brcmf_sdio_tx_ctrlframe()
2409 pad = bus->blocksize - (len % bus->blocksize); in brcmf_sdio_tx_ctrlframe()
2410 if ((pad > bus->roundup) || (pad >= bus->blocksize)) in brcmf_sdio_tx_ctrlframe()
2412 } else if (len % bus->head_align) { in brcmf_sdio_tx_ctrlframe()
2413 pad = bus->head_align - (len % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2419 hd_info.dat_offset = doff + bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2420 hd_info.seq_num = bus->tx_seq; in brcmf_sdio_tx_ctrlframe()
2423 brcmf_sdio_hdpack(bus, frame, &hd_info); in brcmf_sdio_tx_ctrlframe()
2425 if (bus->txglom) in brcmf_sdio_tx_ctrlframe()
2435 ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); in brcmf_sdio_tx_ctrlframe()
2438 brcmf_sdio_txfail(bus); in brcmf_sdio_tx_ctrlframe()
2440 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; in brcmf_sdio_tx_ctrlframe()
2458 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_stop() local
2459 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_bus_stop()
2466 if (bus->watchdog_tsk) { in brcmf_sdio_bus_stop()
2467 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_bus_stop()
2468 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_bus_stop()
2469 bus->watchdog_tsk = NULL; in brcmf_sdio_bus_stop()
2476 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_stop()
2482 local_hostintmask = bus->hostintmask; in brcmf_sdio_bus_stop()
2483 bus->hostintmask = 0; in brcmf_sdio_bus_stop()
2490 bpreq |= brcmf_chip_is_ulp(bus->ci) ? in brcmf_sdio_bus_stop()
2500 /* Turn off the bus (F2), free any pending packets */ in brcmf_sdio_bus_stop()
2511 brcmu_pktq_flush(&bus->txq, true, NULL, NULL); in brcmf_sdio_bus_stop()
2514 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_bus_stop()
2515 brcmf_sdio_free_glom(bus); in brcmf_sdio_bus_stop()
2518 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2519 bus->rxlen = 0; in brcmf_sdio_bus_stop()
2520 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2521 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_bus_stop()
2524 bus->rxskip = false; in brcmf_sdio_bus_stop()
2525 bus->tx_seq = bus->rx_seq = 0; in brcmf_sdio_bus_stop()
2528 static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) in brcmf_sdio_clrintr() argument
2533 sdiodev = bus->sdiodev; in brcmf_sdio_clrintr()
2536 if (!sdiodev->irq_en && !atomic_read(&bus->ipend)) { in brcmf_sdio_clrintr()
2537 enable_irq(sdiodev->settings->bus.sdio.oob_irq_nr); in brcmf_sdio_clrintr()
2544 static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) in brcmf_sdio_intr_rstatus() argument
2546 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_intr_rstatus()
2553 val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret); in brcmf_sdio_intr_rstatus()
2554 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2558 val &= bus->hostintmask; in brcmf_sdio_intr_rstatus()
2559 atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); in brcmf_sdio_intr_rstatus()
2563 brcmf_sdiod_writel(bus->sdiodev, addr, val, &ret); in brcmf_sdio_intr_rstatus()
2564 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2565 atomic_or(val, &bus->intstatus); in brcmf_sdio_intr_rstatus()
2571 static void brcmf_sdio_dpc(struct brcmf_sdio *bus) in brcmf_sdio_dpc() argument
2573 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_dpc()
2575 u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus); in brcmf_sdio_dpc()
2577 uint txlimit = bus->txbound; /* Tx frames to send before resched */ in brcmf_sdio_dpc()
2583 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2586 if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { in brcmf_sdio_dpc()
2591 devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_dpc()
2596 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_dpc()
2603 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_dpc()
2606 brcmf_sdiod_writeb(bus->sdiodev, in brcmf_sdio_dpc()
2608 bus->clkstate = CLK_AVAIL; in brcmf_sdio_dpc()
2613 brcmf_sdio_bus_sleep(bus, false, true); in brcmf_sdio_dpc()
2616 if (atomic_read(&bus->ipend) > 0) { in brcmf_sdio_dpc()
2617 atomic_set(&bus->ipend, 0); in brcmf_sdio_dpc()
2618 err = brcmf_sdio_intr_rstatus(bus); in brcmf_sdio_dpc()
2622 intstatus = atomic_xchg(&bus->intstatus, 0); in brcmf_sdio_dpc()
2634 bus->sdcnt.f1regdata += 2; in brcmf_sdio_dpc()
2635 atomic_set(&bus->fcstate, in brcmf_sdio_dpc()
2637 intstatus |= (newstatus & bus->hostintmask); in brcmf_sdio_dpc()
2643 intstatus |= brcmf_sdio_hostmail(bus); in brcmf_sdio_dpc()
2646 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2671 if (bus->rxskip) in brcmf_sdio_dpc()
2675 if ((intstatus & I_HMB_FRAME_IND) && (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_dpc()
2676 brcmf_sdio_readframes(bus, bus->rxbound); in brcmf_sdio_dpc()
2677 if (!bus->rxpending) in brcmf_sdio_dpc()
2683 atomic_or(intstatus, &bus->intstatus); in brcmf_sdio_dpc()
2685 brcmf_sdio_clrintr(bus); in brcmf_sdio_dpc()
2687 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && in brcmf_sdio_dpc()
2688 txctl_ok(bus)) { in brcmf_sdio_dpc()
2689 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2690 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2691 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, in brcmf_sdio_dpc()
2692 bus->ctrl_frame_len); in brcmf_sdio_dpc()
2693 bus->ctrl_frame_err = err; in brcmf_sdio_dpc()
2695 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2700 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2701 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2704 if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2705 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit && in brcmf_sdio_dpc()
2706 data_ok(bus)) { in brcmf_sdio_dpc()
2707 framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : in brcmf_sdio_dpc()
2709 brcmf_sdio_sendfromq(bus, framecnt); in brcmf_sdio_dpc()
2712 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { in brcmf_sdio_dpc()
2714 atomic_set(&bus->intstatus, 0); in brcmf_sdio_dpc()
2715 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2716 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2717 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2718 bus->ctrl_frame_err = -ENODEV; in brcmf_sdio_dpc()
2720 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2721 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2723 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2725 } else if (atomic_read(&bus->intstatus) || in brcmf_sdio_dpc()
2726 atomic_read(&bus->ipend) > 0 || in brcmf_sdio_dpc()
2727 (!atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2728 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && in brcmf_sdio_dpc()
2729 data_ok(bus))) { in brcmf_sdio_dpc()
2730 bus->dpc_triggered = true; in brcmf_sdio_dpc()
2738 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_gettxq() local
2740 return &bus->txq; in brcmf_sdio_bus_gettxq()
2791 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txdata() local
2798 skb_push(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2811 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); in brcmf_sdio_bus_txdata()
2812 bus->sdcnt.fcqueued++; in brcmf_sdio_bus_txdata()
2815 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2818 if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) { in brcmf_sdio_bus_txdata()
2819 skb_pull(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2820 brcmf_err("out of bus->txq !!!\n"); in brcmf_sdio_bus_txdata()
2826 if (pktq_len(&bus->txq) >= TXHI) { in brcmf_sdio_bus_txdata()
2827 bus->txoff = true; in brcmf_sdio_bus_txdata()
2830 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2833 if (pktq_plen(&bus->txq, prec) > qcount[prec]) in brcmf_sdio_bus_txdata()
2834 qcount[prec] = pktq_plen(&bus->txq, prec); in brcmf_sdio_bus_txdata()
2837 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txdata()
2844 static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) in brcmf_sdio_readconsole() argument
2846 struct brcmf_console *c = &bus->console; in brcmf_sdio_readconsole()
2852 if (bus->console_addr == 0) in brcmf_sdio_readconsole()
2856 addr = bus->console_addr + offsetof(struct rte_console, log_le); in brcmf_sdio_readconsole()
2857 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, in brcmf_sdio_readconsole()
2883 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize); in brcmf_sdio_readconsole()
2926 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txctl() local
2934 bus->ctrl_frame_buf = msg; in brcmf_sdio_bus_txctl()
2935 bus->ctrl_frame_len = msglen; in brcmf_sdio_bus_txctl()
2937 bus->ctrl_frame_stat = true; in brcmf_sdio_bus_txctl()
2939 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txctl()
2940 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, in brcmf_sdio_bus_txctl()
2943 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2944 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_txctl()
2945 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2947 bus->ctrl_frame_stat = false; in brcmf_sdio_bus_txctl()
2950 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_txctl()
2954 bus->ctrl_frame_err); in brcmf_sdio_bus_txctl()
2956 ret = bus->ctrl_frame_err; in brcmf_sdio_bus_txctl()
2960 bus->sdcnt.tx_ctlerrs++; in brcmf_sdio_bus_txctl()
2962 bus->sdcnt.tx_ctlpkts++; in brcmf_sdio_bus_txctl()
2968 static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_dump_console() argument
2978 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2985 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2992 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
3007 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, in brcmf_sdio_dump_console()
3025 static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_trap_info() argument
3036 error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, in brcmf_sdio_trap_info()
3073 static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_assert_info() argument
3088 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_assert_info()
3090 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3096 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3101 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_assert_info()
3108 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3113 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_checkdied()
3125 brcmf_sdio_trap_info(NULL, bus, &sh); in brcmf_sdio_checkdied()
3131 static int brcmf_sdio_died_dump(struct seq_file *seq, struct brcmf_sdio *bus) in brcmf_sdio_died_dump() argument
3136 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_died_dump()
3140 error = brcmf_sdio_assert_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3144 error = brcmf_sdio_trap_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3148 error = brcmf_sdio_dump_console(seq, bus, &sh); in brcmf_sdio_died_dump()
3157 struct brcmf_sdio *bus = bus_if->bus_priv.sdio->bus; in brcmf_sdio_forensic_read() local
3159 return brcmf_sdio_died_dump(seq, bus); in brcmf_sdio_forensic_read()
3166 struct brcmf_sdio_count *sdcnt = &sdiodev->bus->sdcnt; in brcmf_debugfs_sdio_count_read()
3206 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_debugfs_create() local
3212 bus->console_interval = BRCMF_CONSOLE; in brcmf_sdio_debugfs_create()
3218 &bus->console_interval); in brcmf_sdio_debugfs_create()
3221 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3240 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_rxctl() local
3247 timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); in brcmf_sdio_bus_rxctl()
3249 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3250 rxlen = bus->rxlen; in brcmf_sdio_bus_rxctl()
3251 memcpy(msg, bus->rxctl, min(msglen, rxlen)); in brcmf_sdio_bus_rxctl()
3252 bus->rxctl = NULL; in brcmf_sdio_bus_rxctl()
3253 buf = bus->rxctl_orig; in brcmf_sdio_bus_rxctl()
3254 bus->rxctl_orig = NULL; in brcmf_sdio_bus_rxctl()
3255 bus->rxlen = 0; in brcmf_sdio_bus_rxctl()
3256 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3264 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3270 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3274 bus->sdcnt.rx_ctlpkts++; in brcmf_sdio_bus_rxctl()
3276 bus->sdcnt.rx_ctlerrs++; in brcmf_sdio_bus_rxctl()
3335 static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, in brcmf_sdio_download_code_file() argument
3342 err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase, in brcmf_sdio_download_code_file()
3346 err, (int)fw->size, bus->ci->rambase); in brcmf_sdio_download_code_file()
3347 else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, in brcmf_sdio_download_code_file()
3354 static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, in brcmf_sdio_download_nvram() argument
3362 address = bus->ci->ramsize - varsz + bus->ci->rambase; in brcmf_sdio_download_nvram()
3363 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); in brcmf_sdio_download_nvram()
3367 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) in brcmf_sdio_download_nvram()
3373 static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus, in brcmf_sdio_download_firmware() argument
3380 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_download_firmware()
3381 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_download_firmware()
3386 bcmerror = brcmf_sdio_download_code_file(bus, fw); in brcmf_sdio_download_firmware()
3394 bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen); in brcmf_sdio_download_firmware()
3402 if (!brcmf_chip_set_active(bus->ci, rstvec)) { in brcmf_sdio_download_firmware()
3408 brcmf_sdio_clkctl(bus, CLK_SDONLY, false); in brcmf_sdio_download_firmware()
3409 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_download_firmware()
3413 static bool brcmf_sdio_aos_no_decode(struct brcmf_sdio *bus) in brcmf_sdio_aos_no_decode() argument
3415 if (bus->ci->chip == CY_CC_43012_CHIP_ID) in brcmf_sdio_aos_no_decode()
3421 static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) in brcmf_sdio_sr_init() argument
3431 if (brcmf_chip_is_ulp(bus->ci)) { in brcmf_sdio_sr_init()
3439 if (brcmf_sdio_aos_no_decode(bus)) { in brcmf_sdio_sr_init()
3446 val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); in brcmf_sdio_sr_init()
3452 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); in brcmf_sdio_sr_init()
3459 brcmf_sdiod_func0_wb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, in brcmf_sdio_sr_init()
3467 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_sr_init()
3475 bus->sr_enabled = true; in brcmf_sdio_sr_init()
3480 static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) in brcmf_sdio_kso_init() argument
3482 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_kso_init()
3492 val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); in brcmf_sdio_kso_init()
3501 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_init()
3517 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_preinit() local
3518 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_bus_preinit()
3527 bus_if->maxctl += bus->roundup; in brcmf_sdio_bus_preinit()
3529 value += bus->head_align; in brcmf_sdio_bus_preinit()
3530 bus->rxbuf = kmalloc(value, GFP_ATOMIC); in brcmf_sdio_bus_preinit()
3531 if (bus->rxbuf) in brcmf_sdio_bus_preinit()
3532 bus->rxblen = value; in brcmf_sdio_bus_preinit()
3535 * a device perspective, ie. bus:txglom affects the in brcmf_sdio_bus_preinit()
3536 * bus transfers from device to host. in brcmf_sdio_bus_preinit()
3541 err = brcmf_iovar_data_set(dev, "bus:txglom", &value, in brcmf_sdio_bus_preinit()
3545 value = sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_bus_preinit()
3548 err = brcmf_iovar_data_set(dev, "bus:txglomalign", &value, in brcmf_sdio_bus_preinit()
3555 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_bus_preinit()
3557 bus->txglom = false; in brcmf_sdio_bus_preinit()
3559 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", in brcmf_sdio_bus_preinit()
3562 /* bus:rxglom is allowed to fail */ in brcmf_sdio_bus_preinit()
3565 bus->txglom = true; in brcmf_sdio_bus_preinit()
3566 bus->tx_hdrlen += SDPCM_HWEXT_LEN; in brcmf_sdio_bus_preinit()
3569 brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); in brcmf_sdio_bus_preinit()
3579 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_ramsize() local
3581 return bus->ci->ramsize - bus->ci->srsize; in brcmf_sdio_bus_get_ramsize()
3589 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_memdump() local
3595 brcmf_dbg(INFO, "dump at 0x%08x: size=%zu\n", bus->ci->rambase, in brcmf_sdio_bus_get_memdump()
3598 address = bus->ci->rambase; in brcmf_sdio_bus_get_memdump()
3620 void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) in brcmf_sdio_trigger_dpc() argument
3622 if (!bus->dpc_triggered) { in brcmf_sdio_trigger_dpc()
3623 bus->dpc_triggered = true; in brcmf_sdio_trigger_dpc()
3624 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_trigger_dpc()
3628 void brcmf_sdio_isr(struct brcmf_sdio *bus, bool in_isr) in brcmf_sdio_isr() argument
3632 if (!bus) { in brcmf_sdio_isr()
3633 brcmf_err("bus is null pointer, exiting\n"); in brcmf_sdio_isr()
3638 bus->sdcnt.intrcount++; in brcmf_sdio_isr()
3640 atomic_set(&bus->ipend, 1); in brcmf_sdio_isr()
3642 if (brcmf_sdio_intr_rstatus(bus)) { in brcmf_sdio_isr()
3647 if (!bus->intr) in brcmf_sdio_isr()
3650 bus->dpc_triggered = true; in brcmf_sdio_isr()
3651 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_isr()
3654 static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) in brcmf_sdio_bus_watchdog() argument
3659 if (!bus->sr_enabled && in brcmf_sdio_bus_watchdog()
3660 bus->poll && (++bus->polltick >= bus->pollrate)) { in brcmf_sdio_bus_watchdog()
3664 bus->polltick = 0; in brcmf_sdio_bus_watchdog()
3667 if (!bus->intr || in brcmf_sdio_bus_watchdog()
3668 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { in brcmf_sdio_bus_watchdog()
3670 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3673 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3674 devpend = brcmf_sdiod_func0_rb(bus->sdiodev, in brcmf_sdio_bus_watchdog()
3676 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3684 bus->sdcnt.pollcnt++; in brcmf_sdio_bus_watchdog()
3685 atomic_set(&bus->ipend, 1); in brcmf_sdio_bus_watchdog()
3687 bus->dpc_triggered = true; in brcmf_sdio_bus_watchdog()
3688 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_bus_watchdog()
3693 bus->sdcnt.lastintrs = bus->sdcnt.intrcount; in brcmf_sdio_bus_watchdog()
3697 if (bus->sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() && in brcmf_sdio_bus_watchdog()
3698 bus->console_interval != 0) { in brcmf_sdio_bus_watchdog()
3699 bus->console.count += jiffies_to_msecs(BRCMF_WD_POLL); in brcmf_sdio_bus_watchdog()
3700 if (bus->console.count >= bus->console_interval) { in brcmf_sdio_bus_watchdog()
3701 bus->console.count -= bus->console_interval; in brcmf_sdio_bus_watchdog()
3702 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3704 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_watchdog()
3705 if (brcmf_sdio_readconsole(bus) < 0) in brcmf_sdio_bus_watchdog()
3707 bus->console_interval = 0; in brcmf_sdio_bus_watchdog()
3708 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3714 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3716 if ((!bus->dpc_running) && (bus->idletime > 0) && in brcmf_sdio_bus_watchdog()
3717 (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_bus_watchdog()
3718 bus->idlecount++; in brcmf_sdio_bus_watchdog()
3719 if (bus->idlecount > bus->idletime) { in brcmf_sdio_bus_watchdog()
3721 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3724 bus->console_interval == 0) in brcmf_sdio_bus_watchdog()
3726 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_bus_watchdog()
3727 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3728 brcmf_sdio_bus_sleep(bus, true, false); in brcmf_sdio_bus_watchdog()
3729 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3732 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3735 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3741 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, in brcmf_sdio_dataworker() local
3744 bus->dpc_running = true; in brcmf_sdio_dataworker()
3746 while (READ_ONCE(bus->dpc_triggered)) { in brcmf_sdio_dataworker()
3747 bus->dpc_triggered = false; in brcmf_sdio_dataworker()
3748 brcmf_sdio_dpc(bus); in brcmf_sdio_dataworker()
3749 bus->idlecount = 0; in brcmf_sdio_dataworker()
3751 bus->dpc_running = false; in brcmf_sdio_dataworker()
3752 if (brcmf_sdiod_freezing(bus->sdiodev)) { in brcmf_sdio_dataworker()
3753 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); in brcmf_sdio_dataworker()
3754 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_dataworker()
3755 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_dataworker()
3878 struct brcmf_core *core = sdiodev->bus->sdio_core; in brcmf_sdio_buscore_activate()
3933 brcmf_sdio_probe_attach(struct brcmf_sdio *bus) in brcmf_sdio_probe_attach() argument
3942 sdiodev = bus->sdiodev; in brcmf_sdio_probe_attach()
3965 bus->ci = brcmf_chip_attach(sdiodev, &brcmf_sdio_buscore_ops); in brcmf_sdio_probe_attach()
3966 if (IS_ERR(bus->ci)) { in brcmf_sdio_probe_attach()
3968 bus->ci = NULL; in brcmf_sdio_probe_attach()
3973 bus->sdio_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in brcmf_sdio_probe_attach()
3974 if (!bus->sdio_core) in brcmf_sdio_probe_attach()
3978 sdiodev->cc_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_CHIPCOMMON); in brcmf_sdio_probe_attach()
3984 bus->ci->chip, in brcmf_sdio_probe_attach()
3985 bus->ci->chiprev); in brcmf_sdio_probe_attach()
3993 bus->head_align = ALIGNMENT; in brcmf_sdio_probe_attach()
3994 bus->sgentry_align = ALIGNMENT; in brcmf_sdio_probe_attach()
3995 if (sdiodev->settings->bus.sdio.sd_head_align > ALIGNMENT) in brcmf_sdio_probe_attach()
3996 bus->head_align = sdiodev->settings->bus.sdio.sd_head_align; in brcmf_sdio_probe_attach()
3997 if (sdiodev->settings->bus.sdio.sd_sgentry_align > ALIGNMENT) in brcmf_sdio_probe_attach()
3998 bus->sgentry_align = in brcmf_sdio_probe_attach()
3999 sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_probe_attach()
4012 (sdiodev->settings->bus.sdio.oob_irq_supported))) in brcmf_sdio_probe_attach()
4016 if (brcmf_sdio_kso_init(bus)) { in brcmf_sdio_probe_attach()
4021 if (sdiodev->settings->bus.sdio.drive_strength) in brcmf_sdio_probe_attach()
4022 drivestrength = sdiodev->settings->bus.sdio.drive_strength; in brcmf_sdio_probe_attach()
4025 brcmf_sdio_drivestrengthinit(sdiodev, bus->ci, drivestrength); in brcmf_sdio_probe_attach()
4039 reg_addr = CORE_CC_REG(brcmf_chip_get_pmu(bus->ci)->base, pmucontrol); in brcmf_sdio_probe_attach()
4052 brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); in brcmf_sdio_probe_attach()
4055 bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); in brcmf_sdio_probe_attach()
4056 if (!bus->hdrbuf) in brcmf_sdio_probe_attach()
4059 bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], in brcmf_sdio_probe_attach()
4060 bus->head_align); in brcmf_sdio_probe_attach()
4063 bus->intr = true; in brcmf_sdio_probe_attach()
4064 bus->poll = false; in brcmf_sdio_probe_attach()
4065 if (bus->poll) in brcmf_sdio_probe_attach()
4066 bus->pollrate = 1; in brcmf_sdio_probe_attach()
4078 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog_thread() local
4083 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4087 brcmf_sdiod_freezer_uncount(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4088 wait = wait_for_completion_interruptible(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
4089 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4090 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4092 brcmf_sdio_bus_watchdog(bus); in brcmf_sdio_watchdog_thread()
4094 bus->sdcnt.tickcnt++; in brcmf_sdio_watchdog_thread()
4095 reinit_completion(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
4105 struct brcmf_sdio *bus = from_timer(bus, t, timer); in brcmf_sdio_watchdog() local
4107 if (bus->watchdog_tsk) { in brcmf_sdio_watchdog()
4108 complete(&bus->watchdog_wait); in brcmf_sdio_watchdog()
4110 if (bus->wd_active) in brcmf_sdio_watchdog()
4111 mod_timer(&bus->timer, in brcmf_sdio_watchdog()
4189 struct brcmf_sdio *bus = sdiod->bus; in brcmf_sdio_firmware_callback() local
4190 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_firmware_callback()
4208 bus->alp_only = true; in brcmf_sdio_firmware_callback()
4209 err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len); in brcmf_sdio_firmware_callback()
4212 bus->alp_only = false; in brcmf_sdio_firmware_callback()
4215 bus->sdcnt.tickcnt = 0; in brcmf_sdio_firmware_callback()
4216 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_firmware_callback()
4221 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_firmware_callback()
4222 if (bus->clkstate != CLK_AVAIL) in brcmf_sdio_firmware_callback()
4229 bpreq |= brcmf_chip_is_ulp(bus->ci) ? in brcmf_sdio_firmware_callback()
4250 bus->hostintmask = HOSTINTMASK; in brcmf_sdio_firmware_callback()
4252 bus->hostintmask, NULL); in brcmf_sdio_firmware_callback()
4334 if (brcmf_chip_sr_capable(bus->ci)) { in brcmf_sdio_firmware_callback()
4335 brcmf_sdio_sr_init(bus); in brcmf_sdio_firmware_callback()
4343 /* Assign bus interface call back */ in brcmf_sdio_firmware_callback()
4346 sdiod->bus_if->chip = bus->ci->chip; in brcmf_sdio_firmware_callback()
4347 sdiod->bus_if->chiprev = bus->ci->chiprev; in brcmf_sdio_firmware_callback()
4350 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_firmware_callback()
4359 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_firmware_callback()
4386 brcmf_sdio_checkdied(bus); in brcmf_sdio_firmware_callback()
4396 brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus) in brcmf_sdio_prepare_fw_request() argument
4400 { ".bin", bus->sdiodev->fw_name }, in brcmf_sdio_prepare_fw_request()
4401 { ".txt", bus->sdiodev->nvram_name }, in brcmf_sdio_prepare_fw_request()
4404 fwreq = brcmf_fw_alloc_request(bus->ci->chip, bus->ci->chiprev, in brcmf_sdio_prepare_fw_request()
4413 fwreq->board_type = bus->sdiodev->settings->board_type; in brcmf_sdio_prepare_fw_request()
4421 struct brcmf_sdio *bus; in brcmf_sdio_probe() local
4427 /* Allocate private bus interface state */ in brcmf_sdio_probe()
4428 bus = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); in brcmf_sdio_probe()
4429 if (!bus) in brcmf_sdio_probe()
4432 bus->sdiodev = sdiodev; in brcmf_sdio_probe()
4433 sdiodev->bus = bus; in brcmf_sdio_probe()
4434 skb_queue_head_init(&bus->glom); in brcmf_sdio_probe()
4435 bus->txbound = BRCMF_TXBOUND; in brcmf_sdio_probe()
4436 bus->rxbound = BRCMF_RXBOUND; in brcmf_sdio_probe()
4437 bus->txminmax = BRCMF_TXMINMAX; in brcmf_sdio_probe()
4438 bus->tx_seq = SDPCM_SEQ_WRAP - 1; in brcmf_sdio_probe()
4448 INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); in brcmf_sdio_probe()
4449 bus->brcmf_wq = wq; in brcmf_sdio_probe()
4452 if (!(brcmf_sdio_probe_attach(bus))) { in brcmf_sdio_probe()
4457 spin_lock_init(&bus->rxctl_lock); in brcmf_sdio_probe()
4458 spin_lock_init(&bus->txq_lock); in brcmf_sdio_probe()
4459 init_waitqueue_head(&bus->ctrl_wait); in brcmf_sdio_probe()
4460 init_waitqueue_head(&bus->dcmd_resp_wait); in brcmf_sdio_probe()
4463 timer_setup(&bus->timer, brcmf_sdio_watchdog, 0); in brcmf_sdio_probe()
4465 init_completion(&bus->watchdog_wait); in brcmf_sdio_probe()
4466 bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, in brcmf_sdio_probe()
4467 bus, "brcmf_wdog/%s", in brcmf_sdio_probe()
4469 if (IS_ERR(bus->watchdog_tsk)) { in brcmf_sdio_probe()
4471 bus->watchdog_tsk = NULL; in brcmf_sdio_probe()
4474 bus->dpc_triggered = false; in brcmf_sdio_probe()
4475 bus->dpc_running = false; in brcmf_sdio_probe()
4477 /* default sdio bus header length for tx packet */ in brcmf_sdio_probe()
4478 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_probe()
4481 bus->blocksize = bus->sdiodev->func2->cur_blksize; in brcmf_sdio_probe()
4482 bus->roundup = min(max_roundup, bus->blocksize); in brcmf_sdio_probe()
4484 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_probe()
4487 sdio_disable_func(bus->sdiodev->func2); in brcmf_sdio_probe()
4489 bus->rxflow = false; in brcmf_sdio_probe()
4492 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); in brcmf_sdio_probe()
4494 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_probe()
4497 bus->clkstate = CLK_SDONLY; in brcmf_sdio_probe()
4498 bus->idletime = BRCMF_IDLE_INTERVAL; in brcmf_sdio_probe()
4499 bus->idleclock = BRCMF_IDLE_ACTIVE; in brcmf_sdio_probe()
4502 bus->sr_enabled = false; in brcmf_sdio_probe()
4506 fwreq = brcmf_sdio_prepare_fw_request(bus); in brcmf_sdio_probe()
4520 return bus; in brcmf_sdio_probe()
4523 brcmf_sdio_remove(bus); in brcmf_sdio_probe()
4528 void brcmf_sdio_remove(struct brcmf_sdio *bus) in brcmf_sdio_remove() argument
4532 if (bus) { in brcmf_sdio_remove()
4534 if (bus->watchdog_tsk) { in brcmf_sdio_remove()
4535 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_remove()
4536 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_remove()
4537 bus->watchdog_tsk = NULL; in brcmf_sdio_remove()
4541 brcmf_sdiod_intr_unregister(bus->sdiodev); in brcmf_sdio_remove()
4543 brcmf_detach(bus->sdiodev->dev); in brcmf_sdio_remove()
4545 cancel_work_sync(&bus->datawork); in brcmf_sdio_remove()
4546 if (bus->brcmf_wq) in brcmf_sdio_remove()
4547 destroy_workqueue(bus->brcmf_wq); in brcmf_sdio_remove()
4549 if (bus->ci) { in brcmf_sdio_remove()
4550 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { in brcmf_sdio_remove()
4551 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_remove()
4552 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_remove()
4553 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_remove()
4559 brcmf_chip_set_passive(bus->ci); in brcmf_sdio_remove()
4560 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_remove()
4561 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_remove()
4563 brcmf_chip_detach(bus->ci); in brcmf_sdio_remove()
4565 if (bus->sdiodev->settings) in brcmf_sdio_remove()
4566 brcmf_release_module_param(bus->sdiodev->settings); in brcmf_sdio_remove()
4568 kfree(bus->rxbuf); in brcmf_sdio_remove()
4569 kfree(bus->hdrbuf); in brcmf_sdio_remove()
4570 kfree(bus); in brcmf_sdio_remove()
4576 void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, bool active) in brcmf_sdio_wd_timer() argument
4579 if (!active && bus->wd_active) { in brcmf_sdio_wd_timer()
4580 del_timer_sync(&bus->timer); in brcmf_sdio_wd_timer()
4581 bus->wd_active = false; in brcmf_sdio_wd_timer()
4586 if (bus->sdiodev->state != BRCMF_SDIOD_DATA) in brcmf_sdio_wd_timer()
4590 if (!bus->wd_active) { in brcmf_sdio_wd_timer()
4594 bus->timer.expires = jiffies + BRCMF_WD_POLL; in brcmf_sdio_wd_timer()
4595 add_timer(&bus->timer); in brcmf_sdio_wd_timer()
4596 bus->wd_active = true; in brcmf_sdio_wd_timer()
4599 mod_timer(&bus->timer, jiffies + BRCMF_WD_POLL); in brcmf_sdio_wd_timer()
4604 int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep) in brcmf_sdio_sleep() argument
4608 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_sleep()
4609 ret = brcmf_sdio_bus_sleep(bus, sleep, false); in brcmf_sdio_sleep()
4610 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_sleep()