Lines Matching full:bus
96 #include "bus.h"
133 * sdio bus power cycle to clear (rev 9) */
208 #define I_BUSPWR (1 << 17) /* SDIO Bus Power Change (rev 9) */
384 /* dongle SDIO bus specific header info */
431 /* Private data for SDIO bus interaction */
471 u8 sdpcm_ver; /* Bus protocol reported by dongle */
489 s32 idleclock; /* How to set bus driver when idle */
499 spinlock_t txq_lock; /* protect bus->txq */
518 u8 tx_hdrlen; /* sdio bus header length for tx packet */
654 static bool data_ok(struct brcmf_sdio *bus) in data_ok() argument
656 return (u8)(bus->tx_max - bus->tx_seq) != 0 && in data_ok()
657 ((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0; in data_ok()
661 brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) in brcmf_sdio_kso_control() argument
670 sdio_retune_crc_disable(bus->sdiodev->func1); in brcmf_sdio_kso_control()
674 sdio_retune_hold_now(bus->sdiodev->func1); in brcmf_sdio_kso_control()
678 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err); in brcmf_sdio_kso_control()
685 if (!on && bus->ci->chip == CY_CC_43012_CHIP_ID) in brcmf_sdio_kso_control()
712 rd_val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_control()
724 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, in brcmf_sdio_kso_control()
737 sdio_retune_release(bus->sdiodev->func1); in brcmf_sdio_kso_control()
739 sdio_retune_crc_enable(bus->sdiodev->func1); in brcmf_sdio_kso_control()
747 static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok) in brcmf_sdio_htclk() argument
757 if (bus->sr_enabled) { in brcmf_sdio_htclk()
758 bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); in brcmf_sdio_htclk()
765 bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; in brcmf_sdio_htclk()
767 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
775 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
783 if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { in brcmf_sdio_htclk()
785 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
793 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
796 bus->clkstate = CLK_PENDING; in brcmf_sdio_htclk()
799 } else if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
801 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
804 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
811 while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
812 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
824 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { in brcmf_sdio_htclk()
831 bus->clkstate = CLK_AVAIL; in brcmf_sdio_htclk()
835 if (!bus->alp_only) { in brcmf_sdio_htclk()
844 if (bus->clkstate == CLK_PENDING) { in brcmf_sdio_htclk()
846 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_htclk()
849 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_htclk()
853 bus->clkstate = CLK_SDONLY; in brcmf_sdio_htclk()
854 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_htclk()
867 static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) in brcmf_sdio_sdclk() argument
872 bus->clkstate = CLK_SDONLY; in brcmf_sdio_sdclk()
874 bus->clkstate = CLK_NONE; in brcmf_sdio_sdclk()
880 static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) in brcmf_sdio_clkctl() argument
883 uint oldstate = bus->clkstate; in brcmf_sdio_clkctl()
889 if (bus->clkstate == target) in brcmf_sdio_clkctl()
895 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
896 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
898 brcmf_sdio_htclk(bus, true, pendok); in brcmf_sdio_clkctl()
903 if (bus->clkstate == CLK_NONE) in brcmf_sdio_clkctl()
904 brcmf_sdio_sdclk(bus, true); in brcmf_sdio_clkctl()
905 else if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
906 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
909 bus->clkstate, target); in brcmf_sdio_clkctl()
914 if (bus->clkstate == CLK_AVAIL) in brcmf_sdio_clkctl()
915 brcmf_sdio_htclk(bus, false, false); in brcmf_sdio_clkctl()
917 brcmf_sdio_sdclk(bus, false); in brcmf_sdio_clkctl()
921 brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); in brcmf_sdio_clkctl()
928 brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) in brcmf_sdio_bus_sleep() argument
935 (bus->sleeping ? "SLEEP" : "WAKE")); in brcmf_sdio_bus_sleep()
937 /* If SR is enabled control bus state with KSO */ in brcmf_sdio_bus_sleep()
938 if (bus->sr_enabled) { in brcmf_sdio_bus_sleep()
940 if (sleep == bus->sleeping) in brcmf_sdio_bus_sleep()
945 clkcsr = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_bus_sleep()
950 brcmf_sdiod_writeb(bus->sdiodev, in brcmf_sdio_bus_sleep()
954 err = brcmf_sdio_kso_control(bus, false); in brcmf_sdio_bus_sleep()
956 err = brcmf_sdio_kso_control(bus, true); in brcmf_sdio_bus_sleep()
959 brcmf_err("error while changing bus sleep state %d\n", in brcmf_sdio_bus_sleep()
968 if (!bus->sr_enabled) in brcmf_sdio_bus_sleep()
969 brcmf_sdio_clkctl(bus, CLK_NONE, pendok); in brcmf_sdio_bus_sleep()
971 brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); in brcmf_sdio_bus_sleep()
972 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_bus_sleep()
974 bus->sleeping = sleep; in brcmf_sdio_bus_sleep()
989 static int brcmf_sdio_readshared(struct brcmf_sdio *bus, in brcmf_sdio_readshared() argument
998 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
999 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_readshared()
1005 shaddr = bus->ci->rambase + bus->ci->ramsize - 4; in brcmf_sdio_readshared()
1006 if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci)) in brcmf_sdio_readshared()
1007 shaddr -= bus->ci->srsize; in brcmf_sdio_readshared()
1008 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, in brcmf_sdio_readshared()
1027 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, in brcmf_sdio_readshared()
1032 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1054 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readshared()
1058 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1062 if (brcmf_sdio_readshared(bus, &sh) == 0) in brcmf_sdio_get_console_addr()
1063 bus->console_addr = sh.console_addr; in brcmf_sdio_get_console_addr()
1066 static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus) in brcmf_sdio_get_console_addr() argument
1071 static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus) in brcmf_sdio_hostmail() argument
1073 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_hostmail()
1074 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_hostmail()
1091 bus->sdcnt.f1regdata += 2; in brcmf_sdio_hostmail()
1102 bus->rx_seq); in brcmf_sdio_hostmail()
1103 if (!bus->rxskip) in brcmf_sdio_hostmail()
1106 bus->rxskip = false; in brcmf_sdio_hostmail()
1114 bus->sdpcm_ver = in brcmf_sdio_hostmail()
1117 if (bus->sdpcm_ver != SDPCM_PROT_VERSION) in brcmf_sdio_hostmail()
1120 bus->sdpcm_ver, SDPCM_PROT_VERSION); in brcmf_sdio_hostmail()
1123 bus->sdpcm_ver); in brcmf_sdio_hostmail()
1129 brcmf_sdio_get_console_addr(bus); in brcmf_sdio_hostmail()
1141 if (fcbits & ~bus->flowcontrol) in brcmf_sdio_hostmail()
1142 bus->sdcnt.fc_xoff++; in brcmf_sdio_hostmail()
1144 if (bus->flowcontrol & ~fcbits) in brcmf_sdio_hostmail()
1145 bus->sdcnt.fc_xon++; in brcmf_sdio_hostmail()
1147 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hostmail()
1148 bus->flowcontrol = fcbits; in brcmf_sdio_hostmail()
1164 static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx) in brcmf_sdio_rxfail() argument
1166 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_rxfail()
1167 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_rxfail()
1178 brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func2); in brcmf_sdio_rxfail()
1180 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, in brcmf_sdio_rxfail()
1182 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1186 hi = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCHI, in brcmf_sdio_rxfail()
1188 lo = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCLO, in brcmf_sdio_rxfail()
1190 bus->sdcnt.f1regdata += 2; in brcmf_sdio_rxfail()
1208 bus->sdcnt.rxrtx++; in brcmf_sdio_rxfail()
1212 bus->sdcnt.f1regdata++; in brcmf_sdio_rxfail()
1214 bus->rxskip = true; in brcmf_sdio_rxfail()
1218 bus->cur_read.len = 0; in brcmf_sdio_rxfail()
1221 static void brcmf_sdio_txfail(struct brcmf_sdio *bus) in brcmf_sdio_txfail() argument
1223 struct brcmf_sdio_dev *sdiodev = bus->sdiodev; in brcmf_sdio_txfail()
1228 bus->sdcnt.tx_sderrs++; in brcmf_sdio_txfail()
1232 bus->sdcnt.f1regdata++; in brcmf_sdio_txfail()
1237 bus->sdcnt.f1regdata += 2; in brcmf_sdio_txfail()
1244 static uint brcmf_sdio_glom_len(struct brcmf_sdio *bus) in brcmf_sdio_glom_len() argument
1250 skb_queue_walk(&bus->glom, p) in brcmf_sdio_glom_len()
1255 static void brcmf_sdio_free_glom(struct brcmf_sdio *bus) in brcmf_sdio_free_glom() argument
1259 skb_queue_walk_safe(&bus->glom, cur, next) { in brcmf_sdio_free_glom()
1260 skb_unlink(cur, &bus->glom); in brcmf_sdio_free_glom()
1266 * brcmfmac sdio bus specific header
1333 static int brcmf_sdio_hdparse(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdparse() argument
1348 bus->rxpending = false; in brcmf_sdio_hdparse()
1353 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1354 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1362 (roundup(len, bus->blocksize) != rd->len)) { in brcmf_sdio_hdparse()
1385 bus->sdcnt.rx_toolong++; in brcmf_sdio_hdparse()
1386 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1404 bus->sdcnt.rx_badhdr++; in brcmf_sdio_hdparse()
1405 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_hdparse()
1411 bus->sdcnt.rx_badseq++; in brcmf_sdio_hdparse()
1426 if (bus->flowcontrol != fc) { in brcmf_sdio_hdparse()
1427 if (~bus->flowcontrol & fc) in brcmf_sdio_hdparse()
1428 bus->sdcnt.fc_xoff++; in brcmf_sdio_hdparse()
1429 if (bus->flowcontrol & ~fc) in brcmf_sdio_hdparse()
1430 bus->sdcnt.fc_xon++; in brcmf_sdio_hdparse()
1431 bus->sdcnt.fc_rcvd++; in brcmf_sdio_hdparse()
1432 bus->flowcontrol = fc; in brcmf_sdio_hdparse()
1435 if ((u8)(tx_seq_max - bus->tx_seq) > 0x40) { in brcmf_sdio_hdparse()
1437 tx_seq_max = bus->tx_seq + 2; in brcmf_sdio_hdparse()
1439 bus->tx_max = tx_seq_max; in brcmf_sdio_hdparse()
1450 static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header, in brcmf_sdio_hdpack() argument
1459 if (bus->txglom) { in brcmf_sdio_hdpack()
1474 trace_brcmf_sdpcm_hdr(SDPCM_TX + !!(bus->txglom), header); in brcmf_sdio_hdpack()
1477 static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq) in brcmf_sdio_rxglom() argument
1493 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_rxglom()
1496 if (bus->glomd) { in brcmf_sdio_rxglom()
1498 dlen = (u16) (bus->glomd->len); in brcmf_sdio_rxglom()
1499 dptr = bus->glomd->data; in brcmf_sdio_rxglom()
1518 if (sublen % bus->sgentry_align) { in brcmf_sdio_rxglom()
1520 sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1528 (roundup(totlen, bus->blocksize) - totlen); in brcmf_sdio_rxglom()
1529 totlen = roundup(totlen, bus->blocksize); in brcmf_sdio_rxglom()
1533 pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align); in brcmf_sdio_rxglom()
1539 skb_queue_tail(&bus->glom, pnext); in brcmf_sdio_rxglom()
1542 pkt_align(pnext, sublen, bus->sgentry_align); in brcmf_sdio_rxglom()
1546 in bus structure */ in brcmf_sdio_rxglom()
1550 if (BRCMF_GLOM_ON() && bus->cur_read.len && in brcmf_sdio_rxglom()
1551 totlen != bus->cur_read.len) { in brcmf_sdio_rxglom()
1553 bus->cur_read.len, totlen, rxseq); in brcmf_sdio_rxglom()
1557 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1562 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_rxglom()
1563 bus->glomd = NULL; in brcmf_sdio_rxglom()
1564 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1569 if (!skb_queue_empty(&bus->glom)) { in brcmf_sdio_rxglom()
1572 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1579 pfirst = skb_peek(&bus->glom); in brcmf_sdio_rxglom()
1580 dlen = (u16) brcmf_sdio_glom_len(bus); in brcmf_sdio_rxglom()
1586 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1587 errcode = brcmf_sdiod_recv_chain(bus->sdiodev, in brcmf_sdio_rxglom()
1588 &bus->glom, dlen); in brcmf_sdio_rxglom()
1589 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1590 bus->sdcnt.f2rxdata++; in brcmf_sdio_rxglom()
1597 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1598 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1599 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1600 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1601 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1611 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1612 errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new, in brcmf_sdio_rxglom()
1614 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1615 bus->cur_read.len = rd_new.len_nxtfrm << 4; in brcmf_sdio_rxglom()
1622 skb_queue_walk(&bus->glom, pnext) { in brcmf_sdio_rxglom()
1629 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1630 errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new, in brcmf_sdio_rxglom()
1632 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1641 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1642 brcmf_sdio_rxfail(bus, true, false); in brcmf_sdio_rxglom()
1643 bus->sdcnt.rxglomfail++; in brcmf_sdio_rxglom()
1644 brcmf_sdio_free_glom(bus); in brcmf_sdio_rxglom()
1645 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_rxglom()
1646 bus->cur_read.len = 0; in brcmf_sdio_rxglom()
1652 skb_queue_walk_safe(&bus->glom, pfirst, pnext) { in brcmf_sdio_rxglom()
1665 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1674 bus->glom.qlen, pfirst, pfirst->data, in brcmf_sdio_rxglom()
1677 skb_unlink(pfirst, &bus->glom); in brcmf_sdio_rxglom()
1679 brcmf_rx_event(bus->sdiodev->dev, pfirst); in brcmf_sdio_rxglom()
1681 brcmf_rx_frame(bus->sdiodev->dev, pfirst, in brcmf_sdio_rxglom()
1683 bus->sdcnt.rxglompkts++; in brcmf_sdio_rxglom()
1686 bus->sdcnt.rxglomframes++; in brcmf_sdio_rxglom()
1691 static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition, in brcmf_sdio_dcmd_resp_wait() argument
1698 add_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1708 remove_wait_queue(&bus->dcmd_resp_wait, &wait); in brcmf_sdio_dcmd_resp_wait()
1713 static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus) in brcmf_sdio_dcmd_resp_wake() argument
1715 wake_up_interruptible(&bus->dcmd_resp_wait); in brcmf_sdio_dcmd_resp_wake()
1720 brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff) in brcmf_sdio_read_control() argument
1727 if (bus->rxblen) in brcmf_sdio_read_control()
1728 buf = vzalloc(bus->rxblen); in brcmf_sdio_read_control()
1732 rbuf = bus->rxbuf; in brcmf_sdio_read_control()
1733 pad = ((unsigned long)rbuf % bus->head_align); in brcmf_sdio_read_control()
1735 rbuf += (bus->head_align - pad); in brcmf_sdio_read_control()
1744 if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { in brcmf_sdio_read_control()
1745 pad = bus->blocksize - (rdlen % bus->blocksize); in brcmf_sdio_read_control()
1746 if ((pad <= bus->roundup) && (pad < bus->blocksize) && in brcmf_sdio_read_control()
1747 ((len + pad) < bus->sdiodev->bus_if->maxctl)) in brcmf_sdio_read_control()
1749 } else if (rdlen % bus->head_align) { in brcmf_sdio_read_control()
1750 rdlen += bus->head_align - (rdlen % bus->head_align); in brcmf_sdio_read_control()
1754 if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1756 rdlen, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1757 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1761 if ((len - doff) > bus->sdiodev->bus_if->maxctl) { in brcmf_sdio_read_control()
1763 len, len - doff, bus->sdiodev->bus_if->maxctl); in brcmf_sdio_read_control()
1764 bus->sdcnt.rx_toolong++; in brcmf_sdio_read_control()
1765 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_read_control()
1770 sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen); in brcmf_sdio_read_control()
1771 bus->sdcnt.f2rxdata++; in brcmf_sdio_read_control()
1777 bus->sdcnt.rxc_errors++; in brcmf_sdio_read_control()
1778 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_read_control()
1789 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1790 if (bus->rxctl) { in brcmf_sdio_read_control()
1792 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1796 bus->rxctl = buf + doff; in brcmf_sdio_read_control()
1797 bus->rxctl_orig = buf; in brcmf_sdio_read_control()
1798 bus->rxlen = len - doff; in brcmf_sdio_read_control()
1799 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_read_control()
1803 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_read_control()
1807 static void brcmf_sdio_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen) in brcmf_sdio_pad() argument
1809 if (bus->roundup && bus->blocksize && *rdlen > bus->blocksize) { in brcmf_sdio_pad()
1810 *pad = bus->blocksize - (*rdlen % bus->blocksize); in brcmf_sdio_pad()
1811 if (*pad <= bus->roundup && *pad < bus->blocksize && in brcmf_sdio_pad()
1814 } else if (*rdlen % bus->head_align) { in brcmf_sdio_pad()
1815 *rdlen += bus->head_align - (*rdlen % bus->head_align); in brcmf_sdio_pad()
1819 static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_readframes() argument
1826 struct brcmf_sdio_hdrinfo *rd = &bus->cur_read, rd_new; in brcmf_sdio_readframes()
1832 bus->rxpending = true; in brcmf_sdio_readframes()
1834 for (rd->seq_num = bus->rx_seq, rxleft = maxframes; in brcmf_sdio_readframes()
1835 !bus->rxskip && rxleft && bus->sdiodev->state == BRCMF_SDIOD_DATA; in brcmf_sdio_readframes()
1839 if (bus->glomd || !skb_queue_empty(&bus->glom)) { in brcmf_sdio_readframes()
1842 bus->glomd, skb_peek(&bus->glom)); in brcmf_sdio_readframes()
1843 cnt = brcmf_sdio_rxglom(bus, rd->seq_num); in brcmf_sdio_readframes()
1852 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1854 ret = brcmf_sdiod_recv_buf(bus->sdiodev, in brcmf_sdio_readframes()
1855 bus->rxhdr, BRCMF_FIRSTREAD); in brcmf_sdio_readframes()
1856 bus->sdcnt.f2rxhdrs++; in brcmf_sdio_readframes()
1860 bus->sdcnt.rx_hdrfail++; in brcmf_sdio_readframes()
1861 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1862 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1867 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1870 if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd, in brcmf_sdio_readframes()
1872 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1873 if (!bus->rxpending) in brcmf_sdio_readframes()
1880 brcmf_sdio_read_control(bus, bus->rxhdr, in brcmf_sdio_readframes()
1888 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1896 brcmf_sdio_pad(bus, &pad, &rd->len_left); in brcmf_sdio_readframes()
1899 bus->head_align); in brcmf_sdio_readframes()
1903 brcmf_sdio_rxfail(bus, false, in brcmf_sdio_readframes()
1905 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1909 pkt_align(pkt, rd->len_left, bus->head_align); in brcmf_sdio_readframes()
1911 ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt); in brcmf_sdio_readframes()
1912 bus->sdcnt.f2rxdata++; in brcmf_sdio_readframes()
1913 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1919 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1920 brcmf_sdio_rxfail(bus, true, in brcmf_sdio_readframes()
1922 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1928 memcpy(pkt->data, bus->rxhdr, head_read); in brcmf_sdio_readframes()
1931 memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN); in brcmf_sdio_readframes()
1933 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1934 if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new, in brcmf_sdio_readframes()
1939 bus->sdcnt.rx_readahead_cnt++; in brcmf_sdio_readframes()
1945 brcmf_sdio_rxfail(bus, true, true); in brcmf_sdio_readframes()
1946 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1950 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1958 bus->rxhdr, SDPCM_HDRLEN, in brcmf_sdio_readframes()
1966 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1967 brcmf_sdio_rxfail(bus, false, true); in brcmf_sdio_readframes()
1968 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1979 if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_HWHDR_LEN])) { in brcmf_sdio_readframes()
1987 bus->glomd = pkt; in brcmf_sdio_readframes()
1991 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
1992 brcmf_sdio_rxfail(bus, false, false); in brcmf_sdio_readframes()
1993 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_readframes()
2010 brcmf_rx_event(bus->sdiodev->dev, pkt); in brcmf_sdio_readframes()
2012 brcmf_rx_frame(bus->sdiodev->dev, pkt, in brcmf_sdio_readframes()
2029 if (bus->rxskip) in brcmf_sdio_readframes()
2031 bus->rx_seq = rd->seq_num; in brcmf_sdio_readframes()
2037 brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus) in brcmf_sdio_wait_event_wakeup() argument
2039 wake_up_interruptible(&bus->ctrl_wait); in brcmf_sdio_wait_event_wakeup()
2043 static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt) in brcmf_sdio_txpkt_hdalign() argument
2052 head_pad = ((unsigned long)dat_buf % bus->head_align); in brcmf_sdio_txpkt_hdalign()
2055 stats = &bus->sdiodev->bus_if->stats; in brcmf_sdio_txpkt_hdalign()
2066 memset(dat_buf, 0, head_pad + bus->tx_hdrlen); in brcmf_sdio_txpkt_hdalign()
2072 * bus layer usage.
2079 static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus, in brcmf_sdio_txpkt_prep_sg() argument
2090 sdiodev = bus->sdiodev; in brcmf_sdio_txpkt_prep_sg()
2093 WARN_ON(blksize % bus->sgentry_align); in brcmf_sdio_txpkt_prep_sg()
2098 tail_chop = pkt->len % bus->sgentry_align; in brcmf_sdio_txpkt_prep_sg()
2100 tail_pad = bus->sgentry_align - tail_chop; in brcmf_sdio_txpkt_prep_sg()
2106 bus->head_align); in brcmf_sdio_txpkt_prep_sg()
2109 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); in brcmf_sdio_txpkt_prep_sg()
2137 * @bus: brcmf_sdio structure pointer
2148 brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt_prep() argument
2157 txseq = bus->tx_seq; in brcmf_sdio_txpkt_prep()
2169 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_next); in brcmf_sdio_txpkt_prep()
2174 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad); in brcmf_sdio_txpkt_prep()
2180 if (bus->txglom && pktq->qlen > 1) { in brcmf_sdio_txpkt_prep()
2181 ret = brcmf_sdio_txpkt_prep_sg(bus, pktq, in brcmf_sdio_txpkt_prep()
2190 hd_info.dat_offset = head_pad + bus->tx_hdrlen; in brcmf_sdio_txpkt_prep()
2194 brcmf_sdio_hdpack(bus, pkt_next->data, &hd_info); in brcmf_sdio_txpkt_prep()
2203 head_pad + bus->tx_hdrlen, in brcmf_sdio_txpkt_prep()
2209 if (bus->txglom) in brcmf_sdio_txpkt_prep()
2216 * @bus: brcmf_sdio structure pointer
2224 brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq) in brcmf_sdio_txpkt_postp() argument
2243 hdr = pkt_next->data + bus->tx_hdrlen - SDPCM_SWHDR_LEN; in brcmf_sdio_txpkt_postp()
2248 if (bus->txglom) { in brcmf_sdio_txpkt_postp()
2258 static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq, in brcmf_sdio_txpkt() argument
2266 ret = brcmf_sdio_txpkt_prep(bus, pktq, chan); in brcmf_sdio_txpkt()
2270 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_txpkt()
2271 ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq); in brcmf_sdio_txpkt()
2272 bus->sdcnt.f2txdata++; in brcmf_sdio_txpkt()
2275 brcmf_sdio_txfail(bus); in brcmf_sdio_txpkt()
2277 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_txpkt()
2280 brcmf_sdio_txpkt_postp(bus, pktq); in brcmf_sdio_txpkt()
2282 bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP; in brcmf_sdio_txpkt()
2285 brcmf_proto_bcdc_txcomplete(bus->sdiodev->dev, pkt_next, in brcmf_sdio_txpkt()
2291 static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes) in brcmf_sdio_sendfromq() argument
2295 u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus); in brcmf_sdio_sendfromq()
2303 tx_prec_map = ~bus->flowcontrol; in brcmf_sdio_sendfromq()
2306 for (cnt = 0; (cnt < maxframes) && data_ok(bus);) { in brcmf_sdio_sendfromq()
2308 if (bus->txglom) in brcmf_sdio_sendfromq()
2309 pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, in brcmf_sdio_sendfromq()
2310 bus->sdiodev->txglomsz); in brcmf_sdio_sendfromq()
2312 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); in brcmf_sdio_sendfromq()
2314 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2316 pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, in brcmf_sdio_sendfromq()
2322 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_sendfromq()
2326 ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); in brcmf_sdio_sendfromq()
2331 if (!bus->intr) { in brcmf_sdio_sendfromq()
2333 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_sendfromq()
2334 intstatus = brcmf_sdiod_readl(bus->sdiodev, in brcmf_sdio_sendfromq()
2336 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_sendfromq()
2338 bus->sdcnt.f2txdata++; in brcmf_sdio_sendfromq()
2341 if (intstatus & bus->hostintmask) in brcmf_sdio_sendfromq()
2342 atomic_set(&bus->ipend, 1); in brcmf_sdio_sendfromq()
2347 if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) && in brcmf_sdio_sendfromq()
2348 bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { in brcmf_sdio_sendfromq()
2349 bus->txoff = false; in brcmf_sdio_sendfromq()
2350 brcmf_proto_bcdc_txflowblock(bus->sdiodev->dev, false); in brcmf_sdio_sendfromq()
2356 static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len) in brcmf_sdio_tx_ctrlframe() argument
2366 /* Back the pointer to make room for bus header */ in brcmf_sdio_tx_ctrlframe()
2367 frame -= bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2368 len += bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2371 doff = ((unsigned long)frame % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2375 memset(frame + bus->tx_hdrlen, 0, doff); in brcmf_sdio_tx_ctrlframe()
2380 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { in brcmf_sdio_tx_ctrlframe()
2381 pad = bus->blocksize - (len % bus->blocksize); in brcmf_sdio_tx_ctrlframe()
2382 if ((pad > bus->roundup) || (pad >= bus->blocksize)) in brcmf_sdio_tx_ctrlframe()
2384 } else if (len % bus->head_align) { in brcmf_sdio_tx_ctrlframe()
2385 pad = bus->head_align - (len % bus->head_align); in brcmf_sdio_tx_ctrlframe()
2391 hd_info.dat_offset = doff + bus->tx_hdrlen; in brcmf_sdio_tx_ctrlframe()
2392 hd_info.seq_num = bus->tx_seq; in brcmf_sdio_tx_ctrlframe()
2395 brcmf_sdio_hdpack(bus, frame, &hd_info); in brcmf_sdio_tx_ctrlframe()
2397 if (bus->txglom) in brcmf_sdio_tx_ctrlframe()
2407 ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); in brcmf_sdio_tx_ctrlframe()
2410 brcmf_sdio_txfail(bus); in brcmf_sdio_tx_ctrlframe()
2412 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; in brcmf_sdio_tx_ctrlframe()
2430 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_stop() local
2431 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_bus_stop()
2438 if (bus->watchdog_tsk) { in brcmf_sdio_bus_stop()
2439 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_bus_stop()
2440 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_bus_stop()
2441 bus->watchdog_tsk = NULL; in brcmf_sdio_bus_stop()
2448 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_stop()
2454 local_hostintmask = bus->hostintmask; in brcmf_sdio_bus_stop()
2455 bus->hostintmask = 0; in brcmf_sdio_bus_stop()
2462 bpreq |= brcmf_chip_is_ulp(bus->ci) ? in brcmf_sdio_bus_stop()
2472 /* Turn off the bus (F2), free any pending packets */ in brcmf_sdio_bus_stop()
2483 brcmu_pktq_flush(&bus->txq, true, NULL, NULL); in brcmf_sdio_bus_stop()
2486 brcmu_pkt_buf_free_skb(bus->glomd); in brcmf_sdio_bus_stop()
2487 brcmf_sdio_free_glom(bus); in brcmf_sdio_bus_stop()
2490 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2491 bus->rxlen = 0; in brcmf_sdio_bus_stop()
2492 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_stop()
2493 brcmf_sdio_dcmd_resp_wake(bus); in brcmf_sdio_bus_stop()
2496 bus->rxskip = false; in brcmf_sdio_bus_stop()
2497 bus->tx_seq = bus->rx_seq = 0; in brcmf_sdio_bus_stop()
2500 static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) in brcmf_sdio_clrintr() argument
2505 sdiodev = bus->sdiodev; in brcmf_sdio_clrintr()
2508 if (!sdiodev->irq_en && !atomic_read(&bus->ipend)) { in brcmf_sdio_clrintr()
2509 enable_irq(sdiodev->settings->bus.sdio.oob_irq_nr); in brcmf_sdio_clrintr()
2516 static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) in brcmf_sdio_intr_rstatus() argument
2518 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_intr_rstatus()
2525 val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret); in brcmf_sdio_intr_rstatus()
2526 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2530 val &= bus->hostintmask; in brcmf_sdio_intr_rstatus()
2531 atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); in brcmf_sdio_intr_rstatus()
2535 brcmf_sdiod_writel(bus->sdiodev, addr, val, &ret); in brcmf_sdio_intr_rstatus()
2536 bus->sdcnt.f1regdata++; in brcmf_sdio_intr_rstatus()
2537 atomic_or(val, &bus->intstatus); in brcmf_sdio_intr_rstatus()
2543 static void brcmf_sdio_dpc(struct brcmf_sdio *bus) in brcmf_sdio_dpc() argument
2545 struct brcmf_sdio_dev *sdiod = bus->sdiodev; in brcmf_sdio_dpc()
2547 u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus); in brcmf_sdio_dpc()
2549 uint txlimit = bus->txbound; /* Tx frames to send before resched */ in brcmf_sdio_dpc()
2555 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2558 if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { in brcmf_sdio_dpc()
2563 devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL, in brcmf_sdio_dpc()
2568 clkctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_dpc()
2575 devctl = brcmf_sdiod_readb(bus->sdiodev, in brcmf_sdio_dpc()
2578 brcmf_sdiod_writeb(bus->sdiodev, in brcmf_sdio_dpc()
2580 bus->clkstate = CLK_AVAIL; in brcmf_sdio_dpc()
2585 brcmf_sdio_bus_sleep(bus, false, true); in brcmf_sdio_dpc()
2588 if (atomic_read(&bus->ipend) > 0) { in brcmf_sdio_dpc()
2589 atomic_set(&bus->ipend, 0); in brcmf_sdio_dpc()
2590 err = brcmf_sdio_intr_rstatus(bus); in brcmf_sdio_dpc()
2594 intstatus = atomic_xchg(&bus->intstatus, 0); in brcmf_sdio_dpc()
2606 bus->sdcnt.f1regdata += 2; in brcmf_sdio_dpc()
2607 atomic_set(&bus->fcstate, in brcmf_sdio_dpc()
2609 intstatus |= (newstatus & bus->hostintmask); in brcmf_sdio_dpc()
2615 intstatus |= brcmf_sdio_hostmail(bus); in brcmf_sdio_dpc()
2618 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2643 if (bus->rxskip) in brcmf_sdio_dpc()
2647 if ((intstatus & I_HMB_FRAME_IND) && (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_dpc()
2648 brcmf_sdio_readframes(bus, bus->rxbound); in brcmf_sdio_dpc()
2649 if (!bus->rxpending) in brcmf_sdio_dpc()
2655 atomic_or(intstatus, &bus->intstatus); in brcmf_sdio_dpc()
2657 brcmf_sdio_clrintr(bus); in brcmf_sdio_dpc()
2659 if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && in brcmf_sdio_dpc()
2660 data_ok(bus)) { in brcmf_sdio_dpc()
2661 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2662 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2663 err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, in brcmf_sdio_dpc()
2664 bus->ctrl_frame_len); in brcmf_sdio_dpc()
2665 bus->ctrl_frame_err = err; in brcmf_sdio_dpc()
2667 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2669 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2670 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2673 if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2674 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit && in brcmf_sdio_dpc()
2675 data_ok(bus)) { in brcmf_sdio_dpc()
2676 framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : in brcmf_sdio_dpc()
2678 brcmf_sdio_sendfromq(bus, framecnt); in brcmf_sdio_dpc()
2681 if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { in brcmf_sdio_dpc()
2683 atomic_set(&bus->intstatus, 0); in brcmf_sdio_dpc()
2684 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2685 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2686 if (bus->ctrl_frame_stat) { in brcmf_sdio_dpc()
2687 bus->ctrl_frame_err = -ENODEV; in brcmf_sdio_dpc()
2689 bus->ctrl_frame_stat = false; in brcmf_sdio_dpc()
2690 brcmf_sdio_wait_event_wakeup(bus); in brcmf_sdio_dpc()
2692 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_dpc()
2694 } else if (atomic_read(&bus->intstatus) || in brcmf_sdio_dpc()
2695 atomic_read(&bus->ipend) > 0 || in brcmf_sdio_dpc()
2696 (!atomic_read(&bus->fcstate) && in brcmf_sdio_dpc()
2697 brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && in brcmf_sdio_dpc()
2698 data_ok(bus))) { in brcmf_sdio_dpc()
2699 bus->dpc_triggered = true; in brcmf_sdio_dpc()
2707 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_gettxq() local
2709 return &bus->txq; in brcmf_sdio_bus_gettxq()
2760 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txdata() local
2767 skb_push(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2774 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); in brcmf_sdio_bus_txdata()
2775 bus->sdcnt.fcqueued++; in brcmf_sdio_bus_txdata()
2778 spin_lock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2781 if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) { in brcmf_sdio_bus_txdata()
2782 skb_pull(pkt, bus->tx_hdrlen); in brcmf_sdio_bus_txdata()
2783 brcmf_err("out of bus->txq !!!\n"); in brcmf_sdio_bus_txdata()
2789 if (pktq_len(&bus->txq) >= TXHI) { in brcmf_sdio_bus_txdata()
2790 bus->txoff = true; in brcmf_sdio_bus_txdata()
2793 spin_unlock_bh(&bus->txq_lock); in brcmf_sdio_bus_txdata()
2796 if (pktq_plen(&bus->txq, prec) > qcount[prec]) in brcmf_sdio_bus_txdata()
2797 qcount[prec] = pktq_plen(&bus->txq, prec); in brcmf_sdio_bus_txdata()
2800 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txdata()
2807 static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) in brcmf_sdio_readconsole() argument
2809 struct brcmf_console *c = &bus->console; in brcmf_sdio_readconsole()
2815 if (bus->console_addr == 0) in brcmf_sdio_readconsole()
2819 addr = bus->console_addr + offsetof(struct rte_console, log_le); in brcmf_sdio_readconsole()
2820 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, in brcmf_sdio_readconsole()
2846 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize); in brcmf_sdio_readconsole()
2889 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_txctl() local
2897 bus->ctrl_frame_buf = msg; in brcmf_sdio_bus_txctl()
2898 bus->ctrl_frame_len = msglen; in brcmf_sdio_bus_txctl()
2900 bus->ctrl_frame_stat = true; in brcmf_sdio_bus_txctl()
2902 brcmf_sdio_trigger_dpc(bus); in brcmf_sdio_bus_txctl()
2903 wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, in brcmf_sdio_bus_txctl()
2906 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2907 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_txctl()
2908 if (bus->ctrl_frame_stat) { in brcmf_sdio_bus_txctl()
2910 bus->ctrl_frame_stat = false; in brcmf_sdio_bus_txctl()
2913 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_txctl()
2917 bus->ctrl_frame_err); in brcmf_sdio_bus_txctl()
2919 ret = bus->ctrl_frame_err; in brcmf_sdio_bus_txctl()
2923 bus->sdcnt.tx_ctlerrs++; in brcmf_sdio_bus_txctl()
2925 bus->sdcnt.tx_ctlpkts++; in brcmf_sdio_bus_txctl()
2931 static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_dump_console() argument
2941 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2948 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2955 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, in brcmf_sdio_dump_console()
2970 rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, in brcmf_sdio_dump_console()
2988 static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_trap_info() argument
2999 error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, in brcmf_sdio_trap_info()
3036 static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus, in brcmf_sdio_assert_info() argument
3051 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_assert_info()
3053 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3059 error = brcmf_sdiod_ramrw(bus->sdiodev, false, in brcmf_sdio_assert_info()
3064 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_assert_info()
3071 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3076 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_checkdied()
3088 brcmf_sdio_trap_info(NULL, bus, &sh); in brcmf_sdio_checkdied()
3094 static int brcmf_sdio_died_dump(struct seq_file *seq, struct brcmf_sdio *bus) in brcmf_sdio_died_dump() argument
3099 error = brcmf_sdio_readshared(bus, &sh); in brcmf_sdio_died_dump()
3103 error = brcmf_sdio_assert_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3107 error = brcmf_sdio_trap_info(seq, bus, &sh); in brcmf_sdio_died_dump()
3111 error = brcmf_sdio_dump_console(seq, bus, &sh); in brcmf_sdio_died_dump()
3120 struct brcmf_sdio *bus = bus_if->bus_priv.sdio->bus; in brcmf_sdio_forensic_read() local
3122 return brcmf_sdio_died_dump(seq, bus); in brcmf_sdio_forensic_read()
3129 struct brcmf_sdio_count *sdcnt = &sdiodev->bus->sdcnt; in brcmf_debugfs_sdio_count_read()
3169 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_debugfs_create() local
3175 bus->console_interval = BRCMF_CONSOLE; in brcmf_sdio_debugfs_create()
3181 &bus->console_interval); in brcmf_sdio_debugfs_create()
3184 static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) in brcmf_sdio_checkdied() argument
3203 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_rxctl() local
3210 timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); in brcmf_sdio_bus_rxctl()
3212 spin_lock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3213 rxlen = bus->rxlen; in brcmf_sdio_bus_rxctl()
3214 memcpy(msg, bus->rxctl, min(msglen, rxlen)); in brcmf_sdio_bus_rxctl()
3215 bus->rxctl = NULL; in brcmf_sdio_bus_rxctl()
3216 buf = bus->rxctl_orig; in brcmf_sdio_bus_rxctl()
3217 bus->rxctl_orig = NULL; in brcmf_sdio_bus_rxctl()
3218 bus->rxlen = 0; in brcmf_sdio_bus_rxctl()
3219 spin_unlock_bh(&bus->rxctl_lock); in brcmf_sdio_bus_rxctl()
3227 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3233 brcmf_sdio_checkdied(bus); in brcmf_sdio_bus_rxctl()
3237 bus->sdcnt.rx_ctlpkts++; in brcmf_sdio_bus_rxctl()
3239 bus->sdcnt.rx_ctlerrs++; in brcmf_sdio_bus_rxctl()
3298 static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, in brcmf_sdio_download_code_file() argument
3305 err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase, in brcmf_sdio_download_code_file()
3309 err, (int)fw->size, bus->ci->rambase); in brcmf_sdio_download_code_file()
3310 else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, in brcmf_sdio_download_code_file()
3317 static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, in brcmf_sdio_download_nvram() argument
3325 address = bus->ci->ramsize - varsz + bus->ci->rambase; in brcmf_sdio_download_nvram()
3326 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); in brcmf_sdio_download_nvram()
3330 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) in brcmf_sdio_download_nvram()
3336 static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus, in brcmf_sdio_download_firmware() argument
3343 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_download_firmware()
3344 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_download_firmware()
3349 bcmerror = brcmf_sdio_download_code_file(bus, fw); in brcmf_sdio_download_firmware()
3357 bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen); in brcmf_sdio_download_firmware()
3365 if (!brcmf_chip_set_active(bus->ci, rstvec)) { in brcmf_sdio_download_firmware()
3371 brcmf_sdio_clkctl(bus, CLK_SDONLY, false); in brcmf_sdio_download_firmware()
3372 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_download_firmware()
3376 static bool brcmf_sdio_aos_no_decode(struct brcmf_sdio *bus) in brcmf_sdio_aos_no_decode() argument
3378 if (bus->ci->chip == CY_CC_43012_CHIP_ID) in brcmf_sdio_aos_no_decode()
3384 static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) in brcmf_sdio_sr_init() argument
3394 if (brcmf_chip_is_ulp(bus->ci)) { in brcmf_sdio_sr_init()
3402 if (brcmf_sdio_aos_no_decode(bus)) { in brcmf_sdio_sr_init()
3409 val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); in brcmf_sdio_sr_init()
3415 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); in brcmf_sdio_sr_init()
3422 brcmf_sdiod_func0_wb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, in brcmf_sdio_sr_init()
3430 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, in brcmf_sdio_sr_init()
3438 bus->sr_enabled = true; in brcmf_sdio_sr_init()
3443 static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) in brcmf_sdio_kso_init() argument
3445 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_kso_init()
3455 val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); in brcmf_sdio_kso_init()
3464 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, in brcmf_sdio_kso_init()
3480 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_preinit() local
3481 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_bus_preinit()
3490 bus_if->maxctl += bus->roundup; in brcmf_sdio_bus_preinit()
3492 value += bus->head_align; in brcmf_sdio_bus_preinit()
3493 bus->rxbuf = kmalloc(value, GFP_ATOMIC); in brcmf_sdio_bus_preinit()
3494 if (bus->rxbuf) in brcmf_sdio_bus_preinit()
3495 bus->rxblen = value; in brcmf_sdio_bus_preinit()
3498 * a device perspective, ie. bus:txglom affects the in brcmf_sdio_bus_preinit()
3499 * bus transfers from device to host. in brcmf_sdio_bus_preinit()
3504 err = brcmf_iovar_data_set(dev, "bus:txglom", &value, in brcmf_sdio_bus_preinit()
3508 value = sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_bus_preinit()
3511 err = brcmf_iovar_data_set(dev, "bus:txglomalign", &value, in brcmf_sdio_bus_preinit()
3518 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_bus_preinit()
3520 bus->txglom = false; in brcmf_sdio_bus_preinit()
3522 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", in brcmf_sdio_bus_preinit()
3525 /* bus:rxglom is allowed to fail */ in brcmf_sdio_bus_preinit()
3528 bus->txglom = true; in brcmf_sdio_bus_preinit()
3529 bus->tx_hdrlen += SDPCM_HWEXT_LEN; in brcmf_sdio_bus_preinit()
3532 brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); in brcmf_sdio_bus_preinit()
3542 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_ramsize() local
3544 return bus->ci->ramsize - bus->ci->srsize; in brcmf_sdio_bus_get_ramsize()
3552 struct brcmf_sdio *bus = sdiodev->bus; in brcmf_sdio_bus_get_memdump() local
3558 brcmf_dbg(INFO, "dump at 0x%08x: size=%zu\n", bus->ci->rambase, in brcmf_sdio_bus_get_memdump()
3561 address = bus->ci->rambase; in brcmf_sdio_bus_get_memdump()
3583 void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) in brcmf_sdio_trigger_dpc() argument
3585 if (!bus->dpc_triggered) { in brcmf_sdio_trigger_dpc()
3586 bus->dpc_triggered = true; in brcmf_sdio_trigger_dpc()
3587 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_trigger_dpc()
3591 void brcmf_sdio_isr(struct brcmf_sdio *bus) in brcmf_sdio_isr() argument
3595 if (!bus) { in brcmf_sdio_isr()
3596 brcmf_err("bus is null pointer, exiting\n"); in brcmf_sdio_isr()
3601 bus->sdcnt.intrcount++; in brcmf_sdio_isr()
3603 atomic_set(&bus->ipend, 1); in brcmf_sdio_isr()
3605 if (brcmf_sdio_intr_rstatus(bus)) { in brcmf_sdio_isr()
3610 if (!bus->intr) in brcmf_sdio_isr()
3613 bus->dpc_triggered = true; in brcmf_sdio_isr()
3614 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_isr()
3617 static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) in brcmf_sdio_bus_watchdog() argument
3622 if (!bus->sr_enabled && in brcmf_sdio_bus_watchdog()
3623 bus->poll && (++bus->polltick >= bus->pollrate)) { in brcmf_sdio_bus_watchdog()
3627 bus->polltick = 0; in brcmf_sdio_bus_watchdog()
3630 if (!bus->intr || in brcmf_sdio_bus_watchdog()
3631 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { in brcmf_sdio_bus_watchdog()
3633 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3636 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3637 devpend = brcmf_sdiod_func0_rb(bus->sdiodev, in brcmf_sdio_bus_watchdog()
3639 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3647 bus->sdcnt.pollcnt++; in brcmf_sdio_bus_watchdog()
3648 atomic_set(&bus->ipend, 1); in brcmf_sdio_bus_watchdog()
3650 bus->dpc_triggered = true; in brcmf_sdio_bus_watchdog()
3651 queue_work(bus->brcmf_wq, &bus->datawork); in brcmf_sdio_bus_watchdog()
3656 bus->sdcnt.lastintrs = bus->sdcnt.intrcount; in brcmf_sdio_bus_watchdog()
3660 if (bus->sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() && in brcmf_sdio_bus_watchdog()
3661 bus->console_interval != 0) { in brcmf_sdio_bus_watchdog()
3662 bus->console.count += jiffies_to_msecs(BRCMF_WD_POLL); in brcmf_sdio_bus_watchdog()
3663 if (bus->console.count >= bus->console_interval) { in brcmf_sdio_bus_watchdog()
3664 bus->console.count -= bus->console_interval; in brcmf_sdio_bus_watchdog()
3665 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3667 brcmf_sdio_bus_sleep(bus, false, false); in brcmf_sdio_bus_watchdog()
3668 if (brcmf_sdio_readconsole(bus) < 0) in brcmf_sdio_bus_watchdog()
3670 bus->console_interval = 0; in brcmf_sdio_bus_watchdog()
3671 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3677 if (!bus->dpc_triggered) { in brcmf_sdio_bus_watchdog()
3679 if ((!bus->dpc_running) && (bus->idletime > 0) && in brcmf_sdio_bus_watchdog()
3680 (bus->clkstate == CLK_AVAIL)) { in brcmf_sdio_bus_watchdog()
3681 bus->idlecount++; in brcmf_sdio_bus_watchdog()
3682 if (bus->idlecount > bus->idletime) { in brcmf_sdio_bus_watchdog()
3684 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3685 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_bus_watchdog()
3686 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3687 brcmf_sdio_bus_sleep(bus, true, false); in brcmf_sdio_bus_watchdog()
3688 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_bus_watchdog()
3691 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3694 bus->idlecount = 0; in brcmf_sdio_bus_watchdog()
3700 struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, in brcmf_sdio_dataworker() local
3703 bus->dpc_running = true; in brcmf_sdio_dataworker()
3705 while (READ_ONCE(bus->dpc_triggered)) { in brcmf_sdio_dataworker()
3706 bus->dpc_triggered = false; in brcmf_sdio_dataworker()
3707 brcmf_sdio_dpc(bus); in brcmf_sdio_dataworker()
3708 bus->idlecount = 0; in brcmf_sdio_dataworker()
3710 bus->dpc_running = false; in brcmf_sdio_dataworker()
3711 if (brcmf_sdiod_freezing(bus->sdiodev)) { in brcmf_sdio_dataworker()
3712 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); in brcmf_sdio_dataworker()
3713 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_dataworker()
3714 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_dataworker()
3837 struct brcmf_core *core = sdiodev->bus->sdio_core; in brcmf_sdio_buscore_activate()
3892 brcmf_sdio_probe_attach(struct brcmf_sdio *bus) in brcmf_sdio_probe_attach() argument
3901 sdiodev = bus->sdiodev; in brcmf_sdio_probe_attach()
3924 bus->ci = brcmf_chip_attach(sdiodev, &brcmf_sdio_buscore_ops); in brcmf_sdio_probe_attach()
3925 if (IS_ERR(bus->ci)) { in brcmf_sdio_probe_attach()
3927 bus->ci = NULL; in brcmf_sdio_probe_attach()
3932 bus->sdio_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); in brcmf_sdio_probe_attach()
3933 if (!bus->sdio_core) in brcmf_sdio_probe_attach()
3937 sdiodev->cc_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_CHIPCOMMON); in brcmf_sdio_probe_attach()
3943 bus->ci->chip, in brcmf_sdio_probe_attach()
3944 bus->ci->chiprev); in brcmf_sdio_probe_attach()
3952 bus->head_align = ALIGNMENT; in brcmf_sdio_probe_attach()
3953 bus->sgentry_align = ALIGNMENT; in brcmf_sdio_probe_attach()
3954 if (sdiodev->settings->bus.sdio.sd_head_align > ALIGNMENT) in brcmf_sdio_probe_attach()
3955 bus->head_align = sdiodev->settings->bus.sdio.sd_head_align; in brcmf_sdio_probe_attach()
3956 if (sdiodev->settings->bus.sdio.sd_sgentry_align > ALIGNMENT) in brcmf_sdio_probe_attach()
3957 bus->sgentry_align = in brcmf_sdio_probe_attach()
3958 sdiodev->settings->bus.sdio.sd_sgentry_align; in brcmf_sdio_probe_attach()
3971 (sdiodev->settings->bus.sdio.oob_irq_supported))) in brcmf_sdio_probe_attach()
3975 if (brcmf_sdio_kso_init(bus)) { in brcmf_sdio_probe_attach()
3980 if (sdiodev->settings->bus.sdio.drive_strength) in brcmf_sdio_probe_attach()
3981 drivestrength = sdiodev->settings->bus.sdio.drive_strength; in brcmf_sdio_probe_attach()
3984 brcmf_sdio_drivestrengthinit(sdiodev, bus->ci, drivestrength); in brcmf_sdio_probe_attach()
3998 reg_addr = CORE_CC_REG(brcmf_chip_get_pmu(bus->ci)->base, pmucontrol); in brcmf_sdio_probe_attach()
4011 brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); in brcmf_sdio_probe_attach()
4014 bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); in brcmf_sdio_probe_attach()
4015 if (!bus->hdrbuf) in brcmf_sdio_probe_attach()
4018 bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], in brcmf_sdio_probe_attach()
4019 bus->head_align); in brcmf_sdio_probe_attach()
4022 bus->intr = true; in brcmf_sdio_probe_attach()
4023 bus->poll = false; in brcmf_sdio_probe_attach()
4024 if (bus->poll) in brcmf_sdio_probe_attach()
4025 bus->pollrate = 1; in brcmf_sdio_probe_attach()
4037 struct brcmf_sdio *bus = (struct brcmf_sdio *)data; in brcmf_sdio_watchdog_thread() local
4042 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4046 brcmf_sdiod_freezer_uncount(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4047 wait = wait_for_completion_interruptible(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
4048 brcmf_sdiod_freezer_count(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4049 brcmf_sdiod_try_freeze(bus->sdiodev); in brcmf_sdio_watchdog_thread()
4051 brcmf_sdio_bus_watchdog(bus); in brcmf_sdio_watchdog_thread()
4053 bus->sdcnt.tickcnt++; in brcmf_sdio_watchdog_thread()
4054 reinit_completion(&bus->watchdog_wait); in brcmf_sdio_watchdog_thread()
4064 struct brcmf_sdio *bus = from_timer(bus, t, timer); in brcmf_sdio_watchdog() local
4066 if (bus->watchdog_tsk) { in brcmf_sdio_watchdog()
4067 complete(&bus->watchdog_wait); in brcmf_sdio_watchdog()
4069 if (bus->wd_active) in brcmf_sdio_watchdog()
4070 mod_timer(&bus->timer, in brcmf_sdio_watchdog()
4117 struct brcmf_sdio *bus = sdiod->bus; in brcmf_sdio_firmware_callback() local
4118 struct brcmf_core *core = bus->sdio_core; in brcmf_sdio_firmware_callback()
4136 bus->alp_only = true; in brcmf_sdio_firmware_callback()
4137 err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len); in brcmf_sdio_firmware_callback()
4140 bus->alp_only = false; in brcmf_sdio_firmware_callback()
4143 bus->sdcnt.tickcnt = 0; in brcmf_sdio_firmware_callback()
4144 brcmf_sdio_wd_timer(bus, true); in brcmf_sdio_firmware_callback()
4149 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_firmware_callback()
4150 if (bus->clkstate != CLK_AVAIL) in brcmf_sdio_firmware_callback()
4157 bpreq |= brcmf_chip_is_ulp(bus->ci) ? in brcmf_sdio_firmware_callback()
4178 bus->hostintmask = HOSTINTMASK; in brcmf_sdio_firmware_callback()
4180 bus->hostintmask, NULL); in brcmf_sdio_firmware_callback()
4219 if (brcmf_chip_sr_capable(bus->ci)) { in brcmf_sdio_firmware_callback()
4220 brcmf_sdio_sr_init(bus); in brcmf_sdio_firmware_callback()
4229 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); in brcmf_sdio_firmware_callback()
4238 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_firmware_callback()
4244 /* Assign bus interface call back */ in brcmf_sdio_firmware_callback()
4247 sdiod->bus_if->chip = bus->ci->chip; in brcmf_sdio_firmware_callback()
4248 sdiod->bus_if->chiprev = bus->ci->chiprev; in brcmf_sdio_firmware_callback()
4271 brcmf_sdio_checkdied(bus); in brcmf_sdio_firmware_callback()
4281 brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus) in brcmf_sdio_prepare_fw_request() argument
4285 { ".bin", bus->sdiodev->fw_name }, in brcmf_sdio_prepare_fw_request()
4286 { ".txt", bus->sdiodev->nvram_name }, in brcmf_sdio_prepare_fw_request()
4289 fwreq = brcmf_fw_alloc_request(bus->ci->chip, bus->ci->chiprev, in brcmf_sdio_prepare_fw_request()
4298 fwreq->board_type = bus->sdiodev->settings->board_type; in brcmf_sdio_prepare_fw_request()
4306 struct brcmf_sdio *bus; in brcmf_sdio_probe() local
4312 /* Allocate private bus interface state */ in brcmf_sdio_probe()
4313 bus = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); in brcmf_sdio_probe()
4314 if (!bus) in brcmf_sdio_probe()
4317 bus->sdiodev = sdiodev; in brcmf_sdio_probe()
4318 sdiodev->bus = bus; in brcmf_sdio_probe()
4319 skb_queue_head_init(&bus->glom); in brcmf_sdio_probe()
4320 bus->txbound = BRCMF_TXBOUND; in brcmf_sdio_probe()
4321 bus->rxbound = BRCMF_RXBOUND; in brcmf_sdio_probe()
4322 bus->txminmax = BRCMF_TXMINMAX; in brcmf_sdio_probe()
4323 bus->tx_seq = SDPCM_SEQ_WRAP - 1; in brcmf_sdio_probe()
4333 INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); in brcmf_sdio_probe()
4334 bus->brcmf_wq = wq; in brcmf_sdio_probe()
4337 if (!(brcmf_sdio_probe_attach(bus))) { in brcmf_sdio_probe()
4342 spin_lock_init(&bus->rxctl_lock); in brcmf_sdio_probe()
4343 spin_lock_init(&bus->txq_lock); in brcmf_sdio_probe()
4344 init_waitqueue_head(&bus->ctrl_wait); in brcmf_sdio_probe()
4345 init_waitqueue_head(&bus->dcmd_resp_wait); in brcmf_sdio_probe()
4348 timer_setup(&bus->timer, brcmf_sdio_watchdog, 0); in brcmf_sdio_probe()
4350 init_completion(&bus->watchdog_wait); in brcmf_sdio_probe()
4351 bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, in brcmf_sdio_probe()
4352 bus, "brcmf_wdog/%s", in brcmf_sdio_probe()
4354 if (IS_ERR(bus->watchdog_tsk)) { in brcmf_sdio_probe()
4356 bus->watchdog_tsk = NULL; in brcmf_sdio_probe()
4359 bus->dpc_triggered = false; in brcmf_sdio_probe()
4360 bus->dpc_running = false; in brcmf_sdio_probe()
4362 /* default sdio bus header length for tx packet */ in brcmf_sdio_probe()
4363 bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; in brcmf_sdio_probe()
4366 bus->blocksize = bus->sdiodev->func2->cur_blksize; in brcmf_sdio_probe()
4367 bus->roundup = min(max_roundup, bus->blocksize); in brcmf_sdio_probe()
4369 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_probe()
4372 sdio_disable_func(bus->sdiodev->func2); in brcmf_sdio_probe()
4374 bus->rxflow = false; in brcmf_sdio_probe()
4377 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); in brcmf_sdio_probe()
4379 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_probe()
4382 bus->clkstate = CLK_SDONLY; in brcmf_sdio_probe()
4383 bus->idletime = BRCMF_IDLE_INTERVAL; in brcmf_sdio_probe()
4384 bus->idleclock = BRCMF_IDLE_ACTIVE; in brcmf_sdio_probe()
4387 bus->sr_enabled = false; in brcmf_sdio_probe()
4391 fwreq = brcmf_sdio_prepare_fw_request(bus); in brcmf_sdio_probe()
4405 return bus; in brcmf_sdio_probe()
4408 brcmf_sdio_remove(bus); in brcmf_sdio_probe()
4413 void brcmf_sdio_remove(struct brcmf_sdio *bus) in brcmf_sdio_remove() argument
4417 if (bus) { in brcmf_sdio_remove()
4419 if (bus->watchdog_tsk) { in brcmf_sdio_remove()
4420 send_sig(SIGTERM, bus->watchdog_tsk, 1); in brcmf_sdio_remove()
4421 kthread_stop(bus->watchdog_tsk); in brcmf_sdio_remove()
4422 bus->watchdog_tsk = NULL; in brcmf_sdio_remove()
4426 brcmf_sdiod_intr_unregister(bus->sdiodev); in brcmf_sdio_remove()
4428 brcmf_detach(bus->sdiodev->dev); in brcmf_sdio_remove()
4430 cancel_work_sync(&bus->datawork); in brcmf_sdio_remove()
4431 if (bus->brcmf_wq) in brcmf_sdio_remove()
4432 destroy_workqueue(bus->brcmf_wq); in brcmf_sdio_remove()
4434 if (bus->ci) { in brcmf_sdio_remove()
4435 if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { in brcmf_sdio_remove()
4436 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_remove()
4437 brcmf_sdio_wd_timer(bus, false); in brcmf_sdio_remove()
4438 brcmf_sdio_clkctl(bus, CLK_AVAIL, false); in brcmf_sdio_remove()
4444 brcmf_chip_set_passive(bus->ci); in brcmf_sdio_remove()
4445 brcmf_sdio_clkctl(bus, CLK_NONE, false); in brcmf_sdio_remove()
4446 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_remove()
4448 brcmf_chip_detach(bus->ci); in brcmf_sdio_remove()
4450 if (bus->sdiodev->settings) in brcmf_sdio_remove()
4451 brcmf_release_module_param(bus->sdiodev->settings); in brcmf_sdio_remove()
4453 kfree(bus->rxbuf); in brcmf_sdio_remove()
4454 kfree(bus->hdrbuf); in brcmf_sdio_remove()
4455 kfree(bus); in brcmf_sdio_remove()
4461 void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, bool active) in brcmf_sdio_wd_timer() argument
4464 if (!active && bus->wd_active) { in brcmf_sdio_wd_timer()
4465 del_timer_sync(&bus->timer); in brcmf_sdio_wd_timer()
4466 bus->wd_active = false; in brcmf_sdio_wd_timer()
4471 if (bus->sdiodev->state != BRCMF_SDIOD_DATA) in brcmf_sdio_wd_timer()
4475 if (!bus->wd_active) { in brcmf_sdio_wd_timer()
4479 bus->timer.expires = jiffies + BRCMF_WD_POLL; in brcmf_sdio_wd_timer()
4480 add_timer(&bus->timer); in brcmf_sdio_wd_timer()
4481 bus->wd_active = true; in brcmf_sdio_wd_timer()
4484 mod_timer(&bus->timer, jiffies + BRCMF_WD_POLL); in brcmf_sdio_wd_timer()
4489 int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep) in brcmf_sdio_sleep() argument
4493 sdio_claim_host(bus->sdiodev->func1); in brcmf_sdio_sleep()
4494 ret = brcmf_sdio_bus_sleep(bus, sleep, false); in brcmf_sdio_sleep()
4495 sdio_release_host(bus->sdiodev->func1); in brcmf_sdio_sleep()