2017-07-19 19:08:36

by Ian Molton

[permalink] [raw]
Subject: PATCH v3 brcmfmac driver cleanup

Hi all,

Please find the 3rd revision of my cleanup patchset for brcmfmac.

I've done some further cleanup and it now handles SDIO the ay the MMC subsystem
was designed to.

I've also taken the liberty of greatly reducing the amount of indirection
used thoughout the SDIO code, which I think has improved readability quite a
lot.

Hope this finds you all well.

-Ian


2017-07-19 19:08:39

by Ian Molton

[permalink] [raw]
Subject: [PATCH 04/34] brcmfmac: Clean up brcmf_sdiod_set_sbaddr_window()

This function sets the address of the IO window used for
SDIO accesses onto the backplane of the chip.

It currently uses 3 separate masks despite the full mask being
defined in the code already. Remove the separate masks and clean up.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 15 ++++-----------
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 3 ---
2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 5b9a21d6b6b2..aee1ecb7260e 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -408,23 +408,16 @@ static int
brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
{
int err = 0, i;
- u8 addr[3];
+ u32 addr;

if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
return -ENOMEDIUM;

- addr[0] = (address >> 8) & SBSDIO_SBADDRLOW_MASK;
- addr[1] = (address >> 16) & SBSDIO_SBADDRMID_MASK;
- addr[2] = (address >> 24) & SBSDIO_SBADDRHIGH_MASK;
+ addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;

- for (i = 0; i < 3; i++) {
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr[i],
+ for ( i = 0 ; i < 3 && !err ; i++, addr >>= 8 )
+ brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr & 0xff,
&err);
- if (err) {
- brcmf_err("failed at addr: 0x%0x\n",
- SBSDIO_FUNC1_SBADDRLOW + i);
- }
- }

return err;
}
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index f3da32fc6360..e3b78db331b5 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -133,9 +133,6 @@

/* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */

-#define SBSDIO_SBADDRLOW_MASK 0x80 /* Valid bits in SBADDRLOW */
-#define SBSDIO_SBADDRMID_MASK 0xff /* Valid bits in SBADDRMID */
-#define SBSDIO_SBADDRHIGH_MASK 0xffU /* Valid bits in SBADDRHIGH */
/* Address bits from SBADDR regs */
#define SBSDIO_SBWINDOW_MASK 0xffff8000

--
2.11.0

2017-07-19 19:13:29

by Ian Molton

[permalink] [raw]
Subject: [PATCH 23/34] brcmfmac: HUGE cleanup of IO access functions.

Most of the core IO functions are called via a long train of pointers.

Introduce brcmf_readl(), brcmf_writel(), brcmf_writelp(),
brcmf_clear_bits(), and brcmf_set_bits_post() in an attempt to deal with
this.

These brcmf_writelp() and brcmf_set_bits_post() issue posted writes.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/chip.c | 474 ++++++++++-----------
1 file changed, 235 insertions(+), 239 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index 1485463794ff..bab1bb3e99ae 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -28,6 +28,9 @@
#include "debug.h"
#include "chip.h"

+#undef brcmf_dbg
+#define brcmf_dbg(a, b, ...) printk(b, ##__VA_ARGS__)
+
/* SOC Interconnect types (aka chip types) */
#define SOCI_SB 0
#define SOCI_AXI 1
@@ -106,9 +109,6 @@

#define CORE_SB(base, field) \
(base + SBCONFIGOFF + offsetof(struct sbconfig, field))
-#define SBCOREREV(sbidh) \
- ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \
- ((sbidh) & SSB_IDHIGH_RCLO))

struct sbconfig {
u32 PAD[2];
@@ -223,40 +223,75 @@ struct sbsocramregs {
#define ARMCR4_BSZ_MASK 0x3f
#define ARMCR4_BSZ_MULT 8192

+static inline int brcmf_readl(struct brcmf_chip *chip, u32 addr)
+{
+ return chip->ops->read32(chip->ctx, addr);
+}
+
+static inline void brcmf_writel(struct brcmf_chip *chip, u32 addr, u32 v)
+{
+ chip->ops->write32(chip->ctx, addr, v);
+}
+
+static inline void brcmf_writelp(struct brcmf_chip *chip, u32 addr, u32 v)
+{
+ chip->ops->write32(chip->ctx, addr, v);
+ chip->ops->read32(chip->ctx, addr);
+}
+
+static void brcmf_clear_bits(struct brcmf_chip *ci, u32 reg, u32 bits)
+{
+ u32 val;
+
+ val = brcmf_readl(ci, reg);
+ val &= ~bits;
+ brcmf_writel(ci, reg, val);
+}
+
+static void brcmf_set_bits_post(struct brcmf_chip *ci, u32 reg, u32 bits)
+{
+ u32 val;
+
+ val = brcmf_readl(ci, reg);
+ val |= bits;
+ brcmf_writelp(ci, reg, val);
+}
+
static bool brcmf_chip_sb_iscoreup(struct brcmf_core *core)
{
struct brcmf_chip *ci = core->chip;
- u32 regdata;
- u32 address;
-
- address = CORE_SB(core->base, sbtmstatelow);
+ u32 val;

- regdata = ci->ops->read32(ci->ctx, address);
+ val = brcmf_readl(ci, CORE_SB(core->base, sbtmstatelow));

- regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT |
- SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK);
+ val &= SSB_TMSLOW_RESET |
+ SSB_TMSLOW_REJECT |
+ SSB_IMSTATE_REJECT |
+ SSB_TMSLOW_CLOCK;

- return SSB_TMSLOW_CLOCK == regdata;
+ return SSB_TMSLOW_CLOCK == val;
}

static bool brcmf_chip_axi_iscoreup(struct brcmf_core *core)
{
struct brcmf_chip *ci = core->chip;
- u32 regdata;
- bool ret;
+ u32 val;

- regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
+ val = brcmf_readl(ci, core->wrapbase + BCMA_IOCTL);

- ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK;
+ if((val & BCMA_IOCTL_FGC) || !(val & BCMA_IOCTL_CLK))
+ return 0;

- regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
+ /* Is core in reset? */
+ val = brcmf_readl(ci, core->wrapbase + BCMA_RESET_CTL);

- ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0);
+ val &= BCMA_RESET_CTL_RESET;

- return ret;
+ return !val;
}

-static void brcmf_chip_sb_coredisable(struct brcmf_core *core,
+/* prereset and reset ignored */
+static void brcmf_chip_sb_core_disable(struct brcmf_core *core,
u32 prereset, u32 reset)
{
struct brcmf_chip *ci = core->chip;
@@ -264,211 +299,176 @@ static void brcmf_chip_sb_coredisable(struct brcmf_core *core,

base = core->base;

- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+ val = brcmf_readl(ci, CORE_SB(base, sbtmstatelow));

+ /* If core is already in reset, skip reset */
if (val & SSB_TMSLOW_RESET)
return;

- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
-
- if ((val & SSB_TMSLOW_CLOCK) != 0) {
- /*
- * set target reject and spin until busy is clear
- * (preserve core-specific bits)
- */
- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+ if (!(val & SSB_TMSLOW_CLOCK))
+ goto out_clock_off;

- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
- val | SSB_TMSLOW_REJECT);
+ /* Clock is running, so do other stuff? */

- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+ /*
+ * Set target reject and spin until busy is clear
+ * (preserve core-specific bits)
+ */
+ brcmf_set_bits_post(ci, CORE_SB(base, sbtmstatelow), SSB_TMSLOW_REJECT);
+ udelay(1);

- udelay(1);
+ SPINWAIT((brcmf_readl(ci, CORE_SB(base, sbtmstatehigh))
+ & SSB_TMSHIGH_BUSY), 100000);

- SPINWAIT((ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh))
- & SSB_TMSHIGH_BUSY), 100000);
+ val = brcmf_readl(ci, CORE_SB(base, sbtmstatehigh));

- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
+ if (val & SSB_TMSHIGH_BUSY)
+ brcmf_err("core state still busy\n");

- if (val & SSB_TMSHIGH_BUSY)
- brcmf_err("core state still busy\n");

- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
-
- if (val & SSB_IDLOW_INITIATOR) {
- val = ci->ops->read32(ci->ctx,
- CORE_SB(base, sbimstate));
- val |= SSB_IMSTATE_REJECT;
- ci->ops->write32(ci->ctx,
- CORE_SB(base, sbimstate), val);
- val = ci->ops->read32(ci->ctx,
- CORE_SB(base, sbimstate));
- udelay(1);
- SPINWAIT((ci->ops->read32(ci->ctx,
- CORE_SB(base, sbimstate)) &
- SSB_IMSTATE_BUSY), 100000);
- }
+ val = brcmf_readl(ci, CORE_SB(base, sbidlow));
+ if (val & SSB_IDLOW_INITIATOR)
+ {
+ /* Do something and spin until core acknowledges */

- /* set reset and reject while enabling the clocks */
- val = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
- SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET;
+ brcmf_set_bits_post(ci, CORE_SB(base, sbimstate),
+ SSB_IMSTATE_REJECT);
+ udelay(1);

- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow), val);
+ SPINWAIT((brcmf_readl(ci, CORE_SB(base, sbimstate)) &
+ SSB_IMSTATE_BUSY), 100000);

- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+ val = brcmf_readl(ci, CORE_SB(base, sbimstate));

- udelay(10);
+ if (val & SSB_IMSTATE_BUSY)
+ brcmf_err("core state still busy\n");
+ }

- /* clear the initiator reject bit */
- val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
+ /* Set reset and reject while enabling the clocks */
+ brcmf_writelp(ci, CORE_SB(base, sbtmstatelow),
+ SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
+ SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET);

- if (val & SSB_IDLOW_INITIATOR) {
- val = ci->ops->read32(ci->ctx,
- CORE_SB(base, sbimstate));
+ udelay(10);

- val &= ~SSB_IMSTATE_REJECT;
+ /* Clear the initiator reject bit */
+ /* FIXME: Has this value actually changed since it was read earlier? */
+ val = brcmf_readl(ci, CORE_SB(base, sbidlow));

- ci->ops->write32(ci->ctx,
- CORE_SB(base, sbimstate), val);
- }
- }
+ if (val & SSB_IDLOW_INITIATOR)
+ brcmf_clear_bits(ci, CORE_SB(base, sbimstate),
+ SSB_IMSTATE_REJECT);

+out_clock_off:
/* leave reset and reject asserted */
- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
- (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET));
+ brcmf_writel(ci, CORE_SB(base, sbtmstatelow),
+ SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET);

udelay(1);
}

-static void brcmf_chip_axi_coredisable(struct brcmf_core *core,
+static void brcmf_chip_axi_core_disable(struct brcmf_core *core,
u32 prereset, u32 reset)
{
struct brcmf_chip *ci = core->chip;
- u32 regdata;
+ u32 val;

- /* if core is already in reset, skip reset */
- regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
+ val = brcmf_readl(ci, core->wrapbase + BCMA_RESET_CTL);

- if ((regdata & BCMA_RESET_CTL_RESET) != 0)
+ /* If core is already in reset, skip reset */
+ if ((val & BCMA_RESET_CTL_RESET))
goto in_reset_configure;

- /* configure reset */
- ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
+ /* Configure reset */
+ brcmf_writelp(ci, core->wrapbase + BCMA_IOCTL,
prereset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);

- ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
-
- /* put in reset */
- ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL,
- BCMA_RESET_CTL_RESET);
+ /* Put the core into reset */
+ brcmf_writel(ci, core->wrapbase + BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);

usleep_range(10, 20);

- /* wait till reset is 1 */
- SPINWAIT(ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) !=
+ /*
+ * Wait till reset is 1
+ * FIXME: should this test the BCMA_RESET_CTL_RESET bit only?
+ */
+ SPINWAIT(brcmf_readl(ci, core->wrapbase + BCMA_RESET_CTL) !=
BCMA_RESET_CTL_RESET, 300);

in_reset_configure:
- /* in-reset configure */
- ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
+ brcmf_writelp(ci, core->wrapbase + BCMA_IOCTL,
reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
-
- ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
}

-static void brcmf_chip_sb_resetcore(struct brcmf_core *core, u32 prereset,
+static void brcmf_chip_sb_reset_core(struct brcmf_core *core, u32 prereset,
u32 reset, u32 postreset)
{
struct brcmf_chip *ci = core->chip;
u32 base = core->base;
- u32 regdata;
+ u32 val;

/*
* Must do the disable sequence first to work for
* arbitrary current core state.
*/
- brcmf_chip_sb_coredisable(core, 0, 0);
+ brcmf_chip_sb_core_disable(core, 0, 0);

/*
* Now do the initialization sequence.
* set reset while enabling the clock and
* forcing them on throughout the core
*/
- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
+ brcmf_writelp(ci, CORE_SB(base, sbtmstatelow),
SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
SSB_TMSLOW_RESET);

- regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
-
udelay(1);

- /* clear any serror */
- regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
+ /* Clear any serror */
+ val = brcmf_readl(ci, CORE_SB(base, sbtmstatehigh));

- if (regdata & SSB_TMSHIGH_SERR)
- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatehigh), 0);
+ if (val & SSB_TMSHIGH_SERR)
+ brcmf_writel(ci, CORE_SB(base, sbtmstatehigh), 0);

- regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbimstate));
+ val = brcmf_readl(ci, CORE_SB(base, sbimstate));

- if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
- regdata &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
- ci->ops->write32(ci->ctx, CORE_SB(base, sbimstate), regdata);
+ if (val & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
+ val &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
+ brcmf_writel(ci, CORE_SB(base, sbimstate), val);
}

- /* clear reset and allow it to propagate throughout the core */
- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
+ /* Clear reset and allow it to propagate throughout the core */
+ brcmf_writelp(ci, CORE_SB(base, sbtmstatelow),
SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK);

- regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
-
udelay(1);

- /* leave clock enabled */
- ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
- SSB_TMSLOW_CLOCK);
-
- regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+ /* Leave clock enabled */
+ brcmf_writelp(ci, CORE_SB(base, sbtmstatelow), SSB_TMSLOW_CLOCK);

udelay(1);
}

-static void brcmf_chip_axi_resetcore(struct brcmf_core *core, u32 prereset,
+static void brcmf_chip_axi_reset_core(struct brcmf_core *core, u32 prereset,
u32 reset, u32 postreset)
{
struct brcmf_chip *ci = core->chip;
- int count;
-
- /* must disable first to work for arbitrary current core state */
- brcmf_chip_axi_coredisable(core, prereset, reset);
-
- count = 0;
+ int count = 0;

- while (ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) &
- BCMA_RESET_CTL_RESET) {
+ /* Must disable first to work for arbitrary current core state */
+ brcmf_chip_axi_core_disable(core, prereset, reset);

- ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL, 0);
+ while ((brcmf_readl(ci, core->wrapbase + BCMA_RESET_CTL) &
+ BCMA_RESET_CTL_RESET) &&
+ count++ <= 50) {

- count++;
-
- if (count > 50)
- break;
+ brcmf_writel(ci, core->wrapbase + BCMA_RESET_CTL, 0);

usleep_range(40, 60);
}

- ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
- postreset | BCMA_IOCTL_CLK);
-
- ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
-}
-
-static char *brcmf_chip_name(uint chipid, char *buf, uint len)
-{
- const char *fmt;
-
- fmt = ((chipid > 0xa000) || (chipid < 0x4000)) ? "%d" : "%x";
- snprintf(buf, len, fmt, chipid);
- return buf;
+ brcmf_writelp(ci, core->wrapbase + BCMA_IOCTL,
+ postreset | BCMA_IOCTL_CLK);
}

static struct brcmf_core *__brcmf_chip_add_core(struct brcmf_chip *ci,
@@ -481,9 +481,9 @@ static struct brcmf_core *__brcmf_chip_add_core(struct brcmf_chip *ci,
if (!core)
return NULL;

+ core->chip = ci;
core->id = coreid;
core->base = base;
- core->chip = ci;
core->wrapbase = wrapbase;

list_add_tail(&core->list, &ci->cores);
@@ -496,16 +496,16 @@ static struct brcmf_core *brcmf_chip_add_sb_core(struct brcmf_chip *ci,
u32 wrapbase)
{
struct brcmf_core *core;
- u32 regdata;
+ u32 val;

core = __brcmf_chip_add_core(ci, coreid, base, wrapbase);

if (!core)
goto out;

- regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
+ val = brcmf_readl(ci, CORE_SB(core->base, sbidhigh));

- core->rev = SBCOREREV(regdata);
+ core->rev = (val & 0xf) | ((val & 0x7000) >> 8);

out:
return core;
@@ -573,34 +573,29 @@ static int brcmf_chip_cores_check(struct brcmf_chip *ci)
return 0;
}

-static u32 brcmf_chip_core_read32(struct brcmf_core *core, u16 reg)
-{
- return core->chip->ops->read32(core->chip->ctx, core->base + reg);
-}
-
-static void brcmf_chip_core_write32(struct brcmf_core *core,
- u16 reg, u32 val)
-{
- core->chip->ops->write32(core->chip->ctx, core->base + reg, val);
-}
-
static bool brcmf_chip_socram_banksize(struct brcmf_core *core, u8 idx,
u32 *banksize)
{
+ struct brcmf_chip *ci = core->chip;
u32 bankinfo;
u32 bankidx = (SOCRAM_MEMTYPE_RAM << SOCRAM_BANKIDX_MEMTYPE_SHIFT);

bankidx |= idx;
- brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankidx), bankidx);
- bankinfo = brcmf_chip_core_read32(core, SOCRAMREGOFFS(bankinfo));
+
+ brcmf_writel(ci, core->base + SOCRAMREGOFFS(bankidx), bankidx);
+
+ bankinfo = brcmf_readl(ci, core->base + SOCRAMREGOFFS(bankinfo));
+
*banksize = (bankinfo & SOCRAM_BANKINFO_SZMASK) + 1;
*banksize *= SOCRAM_BANKINFO_SZBASE;
+
return !!(bankinfo & SOCRAM_BANKINFO_RETNTRAM_MASK);
}

static void brcmf_chip_socram_ramsize(struct brcmf_core *sr, u32 *ramsize,
u32 *srsize)
{
+ struct brcmf_chip *ci = sr->chip;
u32 coreinfo;
uint nb, banksize, lss;
bool retent;
@@ -616,7 +611,8 @@ static void brcmf_chip_socram_ramsize(struct brcmf_core *sr, u32 *ramsize,
brcmf_chip_resetcore(sr, 0, 0, 0);

/* Get info for determining size */
- coreinfo = brcmf_chip_core_read32(sr, SOCRAMREGOFFS(coreinfo));
+ coreinfo = brcmf_readl(ci, sr->base + SOCRAMREGOFFS(coreinfo));
+
nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;

if ((sr->rev <= 7) || (sr->rev == 12)) {
@@ -657,6 +653,7 @@ static void brcmf_chip_socram_ramsize(struct brcmf_core *sr, u32 *ramsize,
/** Return the SYS MEM size */
static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core *sysmem)
{
+ struct brcmf_chip *ci = sysmem->chip;
u32 memsize = 0;
u32 coreinfo;
u32 idx;
@@ -666,7 +663,7 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core *sysmem)
if (!brcmf_chip_iscoreup(sysmem))
brcmf_chip_resetcore(sysmem, 0, 0, 0);

- coreinfo = brcmf_chip_core_read32(sysmem, SYSMEMREGOFFS(coreinfo));
+ coreinfo = brcmf_readl(ci, sysmem->base + SYSMEMREGOFFS(coreinfo));
nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;

for (idx = 0; idx < nb; idx++) {
@@ -680,6 +677,7 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core *sysmem)
/** Return the TCM-RAM size of the ARMCR4 core. */
static u32 brcmf_chip_tcm_ramsize(struct brcmf_core *cr4)
{
+ struct brcmf_chip *ci = cr4->chip;
u32 corecap;
u32 memsize = 0;
u32 nab;
@@ -688,15 +686,18 @@ static u32 brcmf_chip_tcm_ramsize(struct brcmf_core *cr4)
u32 bxinfo;
u32 idx;

- corecap = brcmf_chip_core_read32(cr4, ARMCR4_CAP);
+ corecap = brcmf_readl(ci, cr4->base + ARMCR4_CAP);

nab = (corecap & ARMCR4_TCBANB_MASK) >> ARMCR4_TCBANB_SHIFT;
nbb = (corecap & ARMCR4_TCBBNB_MASK) >> ARMCR4_TCBBNB_SHIFT;
+
totb = nab + nbb;

for (idx = 0; idx < totb; idx++) {
- brcmf_chip_core_write32(cr4, ARMCR4_BANKIDX, idx);
- bxinfo = brcmf_chip_core_read32(cr4, ARMCR4_BANKINFO);
+ brcmf_writel(ci, cr4->base + ARMCR4_BANKIDX, idx);
+
+ bxinfo = brcmf_readl(ci, cr4->base + ARMCR4_BANKINFO);
+
memsize += ((bxinfo & ARMCR4_BSZ_MASK) + 1) * ARMCR4_BSZ_MULT;
}

@@ -786,15 +787,17 @@ static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip *ci, u32 *eromaddr,
{
u32 val;

- /* read next descriptor */
- val = ci->ops->read32(ci->ctx, *eromaddr);
+ /* Read next descriptor */
+ val = brcmf_readl(ci, *eromaddr);
+
*eromaddr += 4;

if (!type)
return val;

- /* determine descriptor type */
+ /* Determine descriptor type */
*type = (val & DMP_DESC_TYPE_MSK);
+
if ((*type & ~DMP_DESC_ADDRSIZE_GT32) == DMP_DESC_ADDRESS)
*type = DMP_DESC_ADDRESS;

@@ -885,7 +888,7 @@ int brcmf_chip_dmp_erom_scan(struct brcmf_chip *ci)
u32 base, wrap;
int err;

- eromaddr = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, eromptr));
+ eromaddr = brcmf_readl(ci, CORE_CC_REG(SI_ENUM_BASE, eromptr));

while (desc_type != DMP_DESC_EOT) {
val = brcmf_chip_dmp_get_desc(ci, &eromaddr, &desc_type);
@@ -960,80 +963,79 @@ static int brcmf_chip_add_static(struct brcmf_chip *ci,

static int brcmf_chip_probe(struct brcmf_chip *ci)
{
- u32 regdata;
- u32 socitype;
+ u32 val, socitype;
int ret;

- /* Get CC core rev
- * Chipid is assume to be at offset 0 from SI_ENUM_BASE
- * For different chiptypes or old sdio hosts w/o chipcommon,
- * other ways of to probe should be added here.
- */
- regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
+ val = brcmf_readl(ci, CORE_CC_REG(SI_ENUM_BASE, chipid));

- ci->chip = regdata & CID_ID_MASK;
- ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;

- socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
+ ci->chip = val & CID_ID_MASK;
+ ci->chiprev = (val & CID_REV_MASK) >> CID_REV_SHIFT;

- brcmf_chip_name(ci->chip, ci->name, sizeof(ci->name));
+ snprintf(ci->name, sizeof(ci->name),
+ (ci->chip > 0xa000 || ci->chip < 0x4000) ? "%d" : "%x",
+ ci->chip);

- printk("found %s chip: BCM%s, rev=%d\n",
- socitype == SOCI_SB ? "SB" : "AXI", ci->name,
- ci->chiprev);
+ socitype = (val & CID_TYPE_MASK) >> CID_TYPE_SHIFT;

switch(socitype) {
case SOCI_SB:

- switch(ci->chip) {
- case BRCM_CC_4329_CHIP_ID:
- ret = brcmf_chip_add_static(ci, brcmf_4329);
- break;
- default:
- brcmf_err("SB chip is not supported\n");
- return -ENODEV;
- }
+ switch(ci->chip) {
+ case BRCM_CC_4329_CHIP_ID:
+ ret = brcmf_chip_add_static(ci, brcmf_4329);
+ break;
+ default:
+ brcmf_err("SB chip is not supported\n");
+ return -ENODEV;
+ }

- if(!ret)
- return -ENODEV;
+ if(!ret)
+ return -ENODEV;

- ci->iscoreup = brcmf_chip_sb_iscoreup;
- ci->coredisable = brcmf_chip_sb_coredisable;
- ci->resetcore = brcmf_chip_sb_resetcore;
+ ci->iscoreup = brcmf_chip_sb_iscoreup;
+ ci->coredisable = brcmf_chip_sb_core_disable;
+ ci->resetcore = brcmf_chip_sb_reset_core;

- break;
- case SOCI_AXI:
+ break;
+ case SOCI_AXI:

- if (brcmf_chip_dmp_erom_scan(ci))
- return -ENODEV;
+ if (brcmf_chip_dmp_erom_scan(ci))
+ return -ENODEV;

- ci->iscoreup = brcmf_chip_axi_iscoreup;
- ci->coredisable = brcmf_chip_axi_coredisable;
- ci->resetcore = brcmf_chip_axi_resetcore;
+ ci->iscoreup = brcmf_chip_axi_iscoreup;
+ ci->coredisable = brcmf_chip_axi_core_disable;
+ ci->resetcore = brcmf_chip_axi_reset_core;

- break;
- default:
- brcmf_err("chip backplane type %u is not supported\n",
- socitype);
- return -ENODEV;
+ break;
+ default:
+ brcmf_err("chip backplane type %u is not supported\n",
+ socitype);
+ return -ENODEV;
}

ret = brcmf_chip_cores_check(ci);
if (ret)
return ret;

- /* assure chip is passive for core access */
+ /* Ensure chip is passive for core access */
brcmf_chip_set_passive(ci);

- /* Call bus specific reset function now. Cores have been determined
- * but further access may require a chip specific reset at this point.
+ /* Cores have been probed, but further access may require a chip
+ * specific reset at this point.
*/
if (ci->ops->reset) {
ci->ops->reset(ci->ctx, ci);
brcmf_chip_set_passive(ci);
}

- return brcmf_chip_get_raminfo(ci);
+ ret = brcmf_chip_get_raminfo(ci);
+
+ printk("Found BCM%s, %s backplane, rev=%d\n", ci->name,
+ socitype == SOCI_SB ? "SB" : "AXI",
+ ci->chiprev);
+
+ return ret;
}

static void brcmf_chip_disable_arm(struct brcmf_chip *chip, u16 id)
@@ -1053,9 +1055,11 @@ static void brcmf_chip_disable_arm(struct brcmf_chip *chip, u16 id)
case BCMA_CORE_ARM_CR4:
case BCMA_CORE_ARM_CA7:

- /* clear all IOCTL bits except HALT bit */
- val = chip->ops->read32(chip->ctx, cpu->wrapbase + BCMA_IOCTL);
+ /* Clear all IOCTL bits except HALT bit */
+ val = brcmf_readl(chip, cpu->wrapbase + BCMA_IOCTL);
+
val &= ARMCR4_BCMA_IOCTL_CPUHALT;
+
brcmf_chip_resetcore(cpu, val, ARMCR4_BCMA_IOCTL_CPUHALT,
ARMCR4_BCMA_IOCTL_CPUHALT);
break;
@@ -1076,17 +1080,14 @@ static int brcmf_chip_setup(struct brcmf_chip *chip)
base = cc->base;

/* get chipcommon capabilites */
- chip->cc_caps = chip->ops->read32(chip->ctx,
- CORE_CC_REG(base, capabilities));
- chip->cc_caps_ext = chip->ops->read32(chip->ctx,
- CORE_CC_REG(base,
+ chip->cc_caps = brcmf_readl(chip, CORE_CC_REG(base, capabilities));
+ chip->cc_caps_ext = brcmf_readl(chip, CORE_CC_REG(base,
capabilities_ext));

/* get pmu caps & rev */
pmu = brcmf_chip_get_pmu(chip); /* after reading cc_caps_ext */
if (chip->cc_caps & CC_CAP_PMU) {
- val = chip->ops->read32(chip->ctx,
- CORE_CC_REG(pmu->base, pmucapabilities));
+ val = brcmf_readl(chip, CORE_CC_REG(pmu->base, pmucapabilities));
chip->pmurev = val & PCAP_REV_MASK;
chip->pmucaps = val;
}
@@ -1232,8 +1233,8 @@ brcmf_chip_cm3_set_passive(struct brcmf_chip *chip)

/* disable bank #3 remap for this device */
if (chip->chip == BRCM_CC_43430_CHIP_ID) {
- brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankidx), 3);
- brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankpda), 0);
+ brcmf_writel(chip, core->base + SOCRAMREGOFFS(bankidx), 3);
+ brcmf_writel(chip, core->base + SOCRAMREGOFFS(bankpda), 0);
}
}

@@ -1356,53 +1357,48 @@ bool brcmf_chip_set_active(struct brcmf_chip *chip, u32 rstvec)
return false;
}

-bool brcmf_chip_sr_capable(struct brcmf_chip *chip)
+bool brcmf_chip_sr_capable(struct brcmf_chip *ci)
{
- struct brcmf_core *pmu = brcmf_chip_get_pmu(chip);
- u32 base, addr, reg, pmu_cc3_mask = ~0;
+ struct brcmf_core *pmu = brcmf_chip_get_pmu(ci);
+ u32 base, reg, pmu_cc3_mask = ~0;

brcmf_dbg(TRACE, "Enter\n");

- /* old chips with PMU version less than 17 don't support save restore */
- if (chip->pmurev < 17)
+ /* Old chips with PMU version less than 17 don't support save restore */
+ if (ci->pmurev < 17)
return false;

- base = brcmf_chip_get_chipcommon(chip)->base;
-
- switch (chip->chip) {
+ switch (ci->chip) {
case BRCM_CC_4354_CHIP_ID:
case BRCM_CC_4356_CHIP_ID:
- /* explicitly check SR engine enable bit */
+ /* Explicitly check SR engine enable bit */
pmu_cc3_mask = BIT(2);
- /* fall-through */
+ /* Fall-through */
case BRCM_CC_43241_CHIP_ID:
case BRCM_CC_4335_CHIP_ID:
case BRCM_CC_4339_CHIP_ID:

- /* read PMU chipcontrol register 3 */
- addr = CORE_CC_REG(pmu->base, chipcontrol_addr);
- chip->ops->write32(chip->ctx, addr, 3);
+ /* Read PMU chipcontrol register 3 */
+ brcmf_writel(ci, CORE_CC_REG(pmu->base, chipcontrol_addr), 3);

- addr = CORE_CC_REG(pmu->base, chipcontrol_data);
- reg = chip->ops->read32(chip->ctx, addr);
+ reg = brcmf_readl(ci, CORE_CC_REG(pmu->base, chipcontrol_data));

return (reg & pmu_cc3_mask) != 0;
case BRCM_CC_43430_CHIP_ID:

- addr = CORE_CC_REG(base, sr_control1);
- reg = chip->ops->read32(chip->ctx, addr);
+ base = brcmf_chip_get_chipcommon(ci)->base;
+
+ reg = brcmf_readl(ci, CORE_CC_REG(base, sr_control1));

return reg != 0;
default:

- addr = CORE_CC_REG(pmu->base, pmucapabilities_ext);
- reg = chip->ops->read32(chip->ctx, addr);
+ reg = brcmf_readl(ci, CORE_CC_REG(pmu->base, pmucapabilities_ext));

if ((reg & PCAPEXT_SR_SUPPORTED_MASK) == 0)
return false;

- addr = CORE_CC_REG(pmu->base, retention_ctl);
- reg = chip->ops->read32(chip->ctx, addr);
+ reg = brcmf_readl(ci, CORE_CC_REG(pmu->base, retention_ctl));

return (reg & (PMU_RCTL_MACPHY_DISABLE_MASK |
PMU_RCTL_LOGIC_DISABLE_MASK)) == 0;
--
2.11.0

2017-07-19 19:15:46

by Ian Molton

[permalink] [raw]
Subject: [PATCH 21/34] brcmfmac: Simplify chip probe routine

* Renamed routine in line with kernel convention.
* Improved handling of chips that cannot autoprobe

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/chip.c | 130 +++++++++++++--------
1 file changed, 84 insertions(+), 46 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index 38794d7c1da8..b3b28e78c49d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -223,17 +223,6 @@ struct sbsocramregs {
#define ARMCR4_BSZ_MASK 0x3f
#define ARMCR4_BSZ_MULT 8192

-
-static void brcmf_chip_sb_corerev(struct brcmf_chip *ci,
- struct brcmf_core *core)
-{
- u32 regdata;
-
- regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
-
- core->rev = SBCOREREV(regdata);
-}
-
static bool brcmf_chip_sb_iscoreup(struct brcmf_core *core)
{
struct brcmf_chip *ci = core->chip;
@@ -482,7 +471,7 @@ static char *brcmf_chip_name(uint chipid, char *buf, uint len)
return buf;
}

-static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip *ci,
+static struct brcmf_core *__brcmf_chip_add_core(struct brcmf_chip *ci,
u16 coreid, u32 base,
u32 wrapbase)
{
@@ -490,7 +479,7 @@ static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip *ci,

core = kzalloc(sizeof(*core), GFP_KERNEL);
if (!core)
- return ERR_PTR(-ENOMEM);
+ return NULL;

core->id = coreid;
core->base = base;
@@ -502,6 +491,41 @@ static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip *ci,
return core;
}

+static struct brcmf_core *brcmf_chip_add_sb_core(struct brcmf_chip *ci,
+ u16 coreid, u32 base,
+ u32 wrapbase)
+{
+ struct brcmf_core *core;
+ u32 regdata;
+
+ core = __brcmf_chip_add_core(ci, coreid, base, wrapbase);
+
+ if (!core)
+ goto out;
+
+ regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
+
+ core->rev = SBCOREREV(regdata);
+
+out:
+ return core;
+}
+
+static struct brcmf_core *brcmf_chip_add_axi_core(struct brcmf_chip *ci,
+ u16 coreid, u32 base,
+ u32 wrapbase, u8 rev)
+{
+ struct brcmf_core *core;
+
+ core = __brcmf_chip_add_core(ci, coreid, base, wrapbase);
+
+ if (core)
+ core->rev = rev;
+
+ return core;
+}
+
+
/* safety check for chipinfo */
static int brcmf_chip_cores_check(struct brcmf_chip *ci)
{
@@ -900,19 +924,42 @@ int brcmf_chip_dmp_erom_scan(struct brcmf_chip *ci)
continue;

/* finally a core to be added */
- core = brcmf_chip_add_core(ci, id, base, wrap);
- if (IS_ERR(core))
- return PTR_ERR(core);
-
- core->rev = rev;
+ core = brcmf_chip_add_axi_core(ci, id, base, wrap, rev);
+ if (!core)
+ return -ENOMEM; //FIXME - and cleanup the allocated cores?
}

return 0;
}

-static int brcmf_chip_recognition(struct brcmf_chip *ci)
+struct brcmf_chip_desc {
+ u16 id;
+ u32 base;
+};
+
+static struct brcmf_chip_desc brcmf_4329[] = {
+ { BCMA_CORE_CHIPCOMMON, SI_ENUM_BASE },
+ { BCMA_CORE_SDIO_DEV, BCM4329_CORE_BUS_BASE },
+ { BCMA_CORE_INTERNAL_MEM, BCM4329_CORE_SOCRAM_BASE },
+ { BCMA_CORE_ARM_CM3, BCM4329_CORE_ARM_BASE },
+ { BCMA_CORE_80211, 0x18001000 },
+ { 0 , 0},
+};
+
+static int brcmf_chip_add_static(struct brcmf_chip *ci,
+ struct brcmf_chip_desc *desc)
+{
+ for ( ; desc->id ; desc++ )
+ brcmf_chip_add_sb_core(ci, desc->id, desc->base, 0);
+
+ //FIXME: cleanup if we fail to add a core?
+
+ return 0;
+}
+
+
+static int brcmf_chip_probe(struct brcmf_chip *ci)
{
- struct brcmf_core *core;
u32 regdata;
u32 socitype;
int ret;
@@ -920,11 +967,13 @@ static int brcmf_chip_recognition(struct brcmf_chip *ci)
/* Get CC core rev
* Chipid is assume to be at offset 0 from SI_ENUM_BASE
* For different chiptypes or old sdio hosts w/o chipcommon,
- * other ways of recognition should be added here.
+ * other ways of to probe should be added here.
*/
regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
+
ci->chip = regdata & CID_ID_MASK;
ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
+
socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;

brcmf_chip_name(ci->chip, ci->name, sizeof(ci->name));
@@ -936,43 +985,32 @@ static int brcmf_chip_recognition(struct brcmf_chip *ci)
switch(socitype) {
case SOCI_SB:

- if (ci->chip != BRCM_CC_4329_CHIP_ID) {
- brcmf_err("SB chip is not supported\n");
- return -ENODEV;
+ switch(ci->chip) {
+ case BRCM_CC_4329_CHIP_ID:
+ ret = brcmf_chip_add_static(ci, brcmf_4329);
+ break;
+ default:
+ brcmf_err("SB chip is not supported\n");
+ return -ENODEV;
}

+ if(!ret)
+ return -ENODEV;
+
ci->iscoreup = brcmf_chip_sb_iscoreup;
ci->coredisable = brcmf_chip_sb_coredisable;
ci->resetcore = brcmf_chip_sb_resetcore;

- core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
- SI_ENUM_BASE, 0);
- brcmf_chip_sb_corerev(ci, core);
-
- core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
- BCM4329_CORE_BUS_BASE, 0);
- brcmf_chip_sb_corerev(ci, core);
-
- core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
- BCM4329_CORE_SOCRAM_BASE, 0);
- brcmf_chip_sb_corerev(ci, core);
-
- core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
- BCM4329_CORE_ARM_BASE, 0);
- brcmf_chip_sb_corerev(ci, core);
-
- core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0);
- brcmf_chip_sb_corerev(ci, core);
-
break;
case SOCI_AXI:

+ if (brcmf_chip_dmp_erom_scan(ci))
+ return -ENODEV;
+
ci->iscoreup = brcmf_chip_ai_iscoreup;
ci->coredisable = brcmf_chip_ai_coredisable;
ci->resetcore = brcmf_chip_ai_resetcore;

- brcmf_chip_dmp_erom_scan(ci);
-
break;
default:
brcmf_err("chip backplane type %u is not supported\n",
@@ -1093,7 +1131,7 @@ struct brcmf_chip *brcmf_chip_attach(void *ctx,
if (err < 0)
goto fail;

- err = brcmf_chip_recognition(chip);
+ err = brcmf_chip_probe(chip);
if (err < 0)
goto fail;

--
2.11.0

2017-07-19 19:08:42

by Ian Molton

[permalink] [raw]
Subject: [PATCH 07/34] brcmfmac: Remove brcmf_sdiod_request_data()

This function is obfuscating how IO works on this chip. Remove it
and push its logic into brcmf_sdiod_reg_{read,write}().

Handling of -ENOMEDIUM is altered, but as that's pretty much broken anyway
we can ignore that.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 241 ++++++++-------------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 2 +-
2 files changed, 90 insertions(+), 153 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 7eb54539a85e..6df12430a43f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -230,6 +230,44 @@ void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
sdiodev->state = state;
}

+static int
+brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
+{
+ int err = 0, i;
+ u32 addr;
+
+ if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
+ return -ENOMEDIUM;
+
+ addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;
+
+ for ( i = 0 ; i < 3 && !err ; i++, addr >>= 8 )
+ brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr & 0xff,
+ &err);
+
+ return err;
+}
+
+static int
+brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, u32 *addr)
+{
+ uint bar0 = *addr & ~SBSDIO_SB_OFT_ADDR_MASK;
+ int err = 0;
+
+ if (bar0 != sdiodev->sbwad) {
+ err = brcmf_sdiod_set_sbaddr_window(sdiodev, bar0);
+ if (err)
+ return err;
+
+ sdiodev->sbwad = bar0;
+ }
+
+ *addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
+
+ return 0;
+}
+
static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func, u8 byte, uint regaddr)
{
int err_ret;
@@ -248,172 +286,85 @@ static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func, u8 byte, uint re
return err_ret;
}

-static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
- u32 addr, u8 regsz, void *data, bool write)
-{
- struct sdio_func *func;
- int ret = -EINVAL;
-
- brcmf_dbg(SDIO, "rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
- write, fn, addr, regsz);
-
- /* only allow byte access on F0 */
- if (WARN_ON(regsz > 1 && !fn))
- return -EINVAL;
- func = sdiodev->func[fn];
-
- switch (regsz) {
- case 1:
- if (write) {
- if (fn)
- sdio_writeb(func, *(u8 *)data, addr, &ret);
- else
- ret = brcmf_sdiod_f0_writeb(func, *(u8 *)data, addr);
- } else {
- if (fn)
- *(u8 *)data = sdio_readb(func, addr, &ret);
- else
- *(u8 *)data = sdio_f0_readb(func, addr, &ret);
- }
- break;
- case 2:
- if (write)
- sdio_writew(func, *(u16 *)data, addr, &ret);
- else
- *(u16 *)data = sdio_readw(func, addr, &ret);
- break;
- case 4:
- if (write)
- sdio_writel(func, *(u32 *)data, addr, &ret);
- else
- *(u32 *)data = sdio_readl(func, addr, &ret);
- break;
- default:
- brcmf_err("invalid size: %d\n", regsz);
- break;
- }
-
- if (ret)
- brcmf_dbg(SDIO, "failed to %s data F%d@0x%05x, err: %d\n",
- write ? "write" : "read", fn, addr, ret);
-
- return ret;
-}
-
static int brcmf_sdiod_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr,
u8 regsz, void *data)
{
- u8 func;
- s32 retry = 0;
int ret;

- if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
- return -ENOMEDIUM;
-
/*
* figure out how to read the register based on address range
* 0x00 ~ 0x7FF: function 0 CCCR and FBR
* 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
* The rest: function 1 silicon backplane core registers
+ * f0 writes must be bytewise
*/
- if ((addr & ~REG_F0_REG_MASK) == 0)
- func = SDIO_FUNC_0;
- else
- func = SDIO_FUNC_1;
-
- do {
- /* for retry wait for 1 ms till bus get settled down */
- if (retry)
- usleep_range(1000, 2000);

- ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
- data, true);
-
- } while (ret != 0 && ret != -ENOMEDIUM &&
- retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);
+ if ((addr & ~REG_F0_REG_MASK) == 0) {
+ if (WARN_ON(regsz > 1))
+ return -EINVAL;
+ ret = brcmf_sdiod_f0_writeb(sdiodev->func[0], *(u8 *)data, addr);
+ }
+ else {
+ switch (regsz) {
+ case 1:
+ sdio_writeb(sdiodev->func[1], *(u8 *)data, addr, &ret);
+ break;
+ case 4:
+ ret = brcmf_sdiod_addrprep(sdiodev, &addr);
+ if (ret)
+ goto done;

- if (ret == -ENOMEDIUM)
- brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
+ sdio_writel(sdiodev->func[1], *(u32 *)data, addr, &ret);
+ break;
+ default:
+ BUG();
+ ret = -EINVAL;
+ break;
+ }
+ }

+done:
return ret;
}

static int brcmf_sdiod_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr,
u8 regsz, void *data)
{
- u8 func;
- s32 retry = 0;
int ret;

- if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
- return -ENOMEDIUM;
-
/*
* figure out how to read the register based on address range
* 0x00 ~ 0x7FF: function 0 CCCR and FBR
* 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
* The rest: function 1 silicon backplane core registers
+ * f0 reads must be bytewise
*/
- if ((addr & ~REG_F0_REG_MASK) == 0)
- func = SDIO_FUNC_0;
- else
- func = SDIO_FUNC_1;
-
- do {
- memset(data, 0, regsz);
-
- /* for retry wait for 1 ms till bus get settled down */
- if (retry)
- usleep_range(1000, 2000);
-
- ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
- data, false);
-
- } while (ret != 0 && ret != -ENOMEDIUM &&
- retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);
-
- if (ret == -ENOMEDIUM)
- brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
-
- return ret;
-}
-
-static int
-brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
-{
- int err = 0, i;
- u32 addr;
-
- if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
- return -ENOMEDIUM;
-
- addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;
-
- for ( i = 0 ; i < 3 && !err ; i++, addr >>= 8 )
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr & 0xff,
- &err);
-
- return err;
-}
-
-static int
-brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, u32 *addr)
-{
- uint bar0 = *addr & ~SBSDIO_SB_OFT_ADDR_MASK;
- int err = 0;
-
- if (bar0 != sdiodev->sbwad) {
- err = brcmf_sdiod_set_sbaddr_window(sdiodev, bar0);
- if (err)
- return err;
-
- sdiodev->sbwad = bar0;
+ if ((addr & ~REG_F0_REG_MASK) == 0) {
+ if (WARN_ON(regsz > 1))
+ return -EINVAL;
+ *(u8 *)data = sdio_f0_readb(sdiodev->func[0], addr, &ret);
}
+ else {
+ switch (regsz) {
+ case 1:
+ *(u8 *)data = sdio_readb(sdiodev->func[1], addr, &ret);
+ break;
+ case 4:
+ ret = brcmf_sdiod_addrprep(sdiodev, &addr);
+ if (ret)
+ goto done;

- *addr &= SBSDIO_SB_OFT_ADDR_MASK;
- *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
+ *(u32 *)data = sdio_readl(sdiodev->func[1], addr, &ret);
+ break;
+ default:
+ BUG();
+ ret = -EINVAL;
+ break;
+ }
+ }

- return 0;
+done:
+ return ret;
}

u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
@@ -437,15 +388,9 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
int retval;

brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
- retval = brcmf_sdiod_addrprep(sdiodev, &addr);
- if (retval)
- goto done;
-
- retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);
-
brcmf_dbg(SDIO, "data:0x%08x\n", data);
+ retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);

-done:
if (ret)
*ret = retval;

@@ -470,13 +415,7 @@ void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
int retval;

brcmf_dbg(SDIO, "addr:0x%08x, data:0x%08x\n", addr, data);
- retval = brcmf_sdiod_addrprep(sdiodev, &addr);
- if (retval)
- goto done;

- retval = brcmf_sdiod_reg_write(sdiodev, addr, 4, &data);
-
-done:
if (ret)
*ret = retval;
}
@@ -884,14 +823,12 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
return bcmerror;
}

-int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, uint fn)
+int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn)
{
- char t_func = (char)fn;
brcmf_dbg(SDIO, "Enter\n");

/* issue abort cmd52 command through F0 */
- brcmf_sdiod_request_data(sdiodev, SDIO_FUNC_0, SDIO_CCCR_ABORT,
- 1, &t_func, true);
+ brcmf_sdiod_reg_write(sdiodev, SDIO_CCCR_ABORT, 1, &fn);

brcmf_dbg(SDIO, "Exit\n");
return 0;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index e3b78db331b5..1e4b4760159f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -339,7 +339,7 @@ int brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
u8 *data, uint size);

/* Issue an abort to the specified function */
-int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, uint fn);
+int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn);
void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev);
void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
enum brcmf_sdiod_state state);
--
2.11.0

2017-07-19 19:11:06

by Ian Molton

[permalink] [raw]
Subject: [PATCH 17/34] brcmfmac: Remove unused macro.

This macro is used exactly nowhere in the code. Delete it.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 6b8583c37b92..a72e9d0eb471 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -159,8 +159,6 @@ struct rte_console {
/* manfid tuple length, include tuple, link bytes */
#define SBSDIO_CIS_MANFID_TUPLE_LEN 6

-#define CORE_BUS_REG(base, field) \
- (base + offsetof(struct sdpcmd_regs, field))
#define __sd_reg(field) \
(offsetof(struct sdpcmd_regs, field))

--
2.11.0

2017-07-19 19:14:33

by Ian Molton

[permalink] [raw]
Subject: [PATCH 20/34] brcmfmac: Whitespace patch

Improve legibility / conform to kernel coding style.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/chip.c | 47 ++++++++++++++++++++++
1 file changed, 47 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index 781f54bb844b..38794d7c1da8 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -276,29 +276,36 @@ static void brcmf_chip_sb_coredisable(struct brcmf_core *core,
base = core->base;

val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
if (val & SSB_TMSLOW_RESET)
return;

val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
if ((val & SSB_TMSLOW_CLOCK) != 0) {
/*
* set target reject and spin until busy is clear
* (preserve core-specific bits)
*/
val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
val | SSB_TMSLOW_REJECT);

val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
udelay(1);
+
SPINWAIT((ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh))
& SSB_TMSHIGH_BUSY), 100000);

val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
+
if (val & SSB_TMSHIGH_BUSY)
brcmf_err("core state still busy\n");

val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
+
if (val & SSB_IDLOW_INITIATOR) {
val = ci->ops->read32(ci->ctx,
CORE_SB(base, sbimstate));
@@ -316,16 +323,22 @@ static void brcmf_chip_sb_coredisable(struct brcmf_core *core,
/* set reset and reject while enabling the clocks */
val = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET;
+
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow), val);
+
val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
udelay(10);

/* clear the initiator reject bit */
val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
+
if (val & SSB_IDLOW_INITIATOR) {
val = ci->ops->read32(ci->ctx,
CORE_SB(base, sbimstate));
+
val &= ~SSB_IMSTATE_REJECT;
+
ci->ops->write32(ci->ctx,
CORE_SB(base, sbimstate), val);
}
@@ -334,6 +347,7 @@ static void brcmf_chip_sb_coredisable(struct brcmf_core *core,
/* leave reset and reject asserted */
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
(SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET));
+
udelay(1);
}

@@ -345,17 +359,20 @@ static void brcmf_chip_ai_coredisable(struct brcmf_core *core,

/* if core is already in reset, skip reset */
regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
+
if ((regdata & BCMA_RESET_CTL_RESET) != 0)
goto in_reset_configure;

/* configure reset */
ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
prereset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
+
ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);

/* put in reset */
ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL,
BCMA_RESET_CTL_RESET);
+
usleep_range(10, 20);

/* wait till reset is 1 */
@@ -366,6 +383,7 @@ static void brcmf_chip_ai_coredisable(struct brcmf_core *core,
/* in-reset configure */
ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
+
ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
}

@@ -390,15 +408,19 @@ static void brcmf_chip_sb_resetcore(struct brcmf_core *core, u32 prereset,
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
SSB_TMSLOW_RESET);
+
regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
udelay(1);

/* clear any serror */
regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
+
if (regdata & SSB_TMSHIGH_SERR)
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatehigh), 0);

regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbimstate));
+
if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
regdata &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
ci->ops->write32(ci->ctx, CORE_SB(base, sbimstate), regdata);
@@ -407,13 +429,17 @@ static void brcmf_chip_sb_resetcore(struct brcmf_core *core, u32 prereset,
/* clear reset and allow it to propagate throughout the core */
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK);
+
regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
udelay(1);

/* leave clock enabled */
ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
SSB_TMSLOW_CLOCK);
+
regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+
udelay(1);
}

@@ -427,17 +453,23 @@ static void brcmf_chip_ai_resetcore(struct brcmf_core *core, u32 prereset,
brcmf_chip_ai_coredisable(core, prereset, reset);

count = 0;
+
while (ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) &
BCMA_RESET_CTL_RESET) {
+
ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL, 0);
+
count++;
+
if (count > 50)
break;
+
usleep_range(40, 60);
}

ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
postreset | BCMA_IOCTL_CLK);
+
ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
}

@@ -908,6 +940,7 @@ static int brcmf_chip_recognition(struct brcmf_chip *ci)
brcmf_err("SB chip is not supported\n");
return -ENODEV;
}
+
ci->iscoreup = brcmf_chip_sb_iscoreup;
ci->coredisable = brcmf_chip_sb_coredisable;
ci->resetcore = brcmf_chip_sb_resetcore;
@@ -915,25 +948,31 @@ static int brcmf_chip_recognition(struct brcmf_chip *ci)
core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
SI_ENUM_BASE, 0);
brcmf_chip_sb_corerev(ci, core);
+
core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
BCM4329_CORE_BUS_BASE, 0);
brcmf_chip_sb_corerev(ci, core);
+
core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
BCM4329_CORE_SOCRAM_BASE, 0);
brcmf_chip_sb_corerev(ci, core);
+
core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
BCM4329_CORE_ARM_BASE, 0);
brcmf_chip_sb_corerev(ci, core);

core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0);
brcmf_chip_sb_corerev(ci, core);
+
break;
case SOCI_AXI:
+
ci->iscoreup = brcmf_chip_ai_iscoreup;
ci->coredisable = brcmf_chip_ai_coredisable;
ci->resetcore = brcmf_chip_ai_resetcore;

brcmf_chip_dmp_erom_scan(ci);
+
break;
default:
brcmf_err("chip backplane type %u is not supported\n",
@@ -1301,24 +1340,32 @@ bool brcmf_chip_sr_capable(struct brcmf_chip *chip)
case BRCM_CC_43241_CHIP_ID:
case BRCM_CC_4335_CHIP_ID:
case BRCM_CC_4339_CHIP_ID:
+
/* read PMU chipcontrol register 3 */
addr = CORE_CC_REG(pmu->base, chipcontrol_addr);
chip->ops->write32(chip->ctx, addr, 3);
+
addr = CORE_CC_REG(pmu->base, chipcontrol_data);
reg = chip->ops->read32(chip->ctx, addr);
+
return (reg & pmu_cc3_mask) != 0;
case BRCM_CC_43430_CHIP_ID:
+
addr = CORE_CC_REG(base, sr_control1);
reg = chip->ops->read32(chip->ctx, addr);
+
return reg != 0;
default:
+
addr = CORE_CC_REG(pmu->base, pmucapabilities_ext);
reg = chip->ops->read32(chip->ctx, addr);
+
if ((reg & PCAPEXT_SR_SUPPORTED_MASK) == 0)
return false;

addr = CORE_CC_REG(pmu->base, retention_ctl);
reg = chip->ops->read32(chip->ctx, addr);
+
return (reg & (PMU_RCTL_MACPHY_DISABLE_MASK |
PMU_RCTL_LOGIC_DISABLE_MASK)) == 0;
}
--
2.11.0

2017-07-19 19:15:39

by Ian Molton

[permalink] [raw]
Subject: [PATCH 16/34] brcmfmac: Cleanup offsetof()

Create a macro to make the code a bit more readable, whilst we're stuck
with using struct element offsets as register offsets.


Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 35 +++++++++-------------
1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 152905e985d2..6b8583c37b92 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -161,6 +161,8 @@ struct rte_console {

#define CORE_BUS_REG(base, field) \
(base + offsetof(struct sdpcmd_regs, field))
+#define __sd_reg(field) \
+ (offsetof(struct sdpcmd_regs, field))

/* SDIO function 1 register CHIPCLKCSR */
/* Force ALP request to backplane */
@@ -1078,12 +1080,10 @@ static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)
brcmf_dbg(SDIO, "Enter\n");

/* Read mailbox data and ack that we did so */
- ret = r_sdreg32(bus, &hmb_data,
- offsetof(struct sdpcmd_regs, tohostmailboxdata));
+ ret = r_sdreg32(bus, &hmb_data, __sd_reg(tohostmailboxdata));

if (ret == 0)
- w_sdreg32(bus, SMB_INT_ACK,
- offsetof(struct sdpcmd_regs, tosbmailbox));
+ w_sdreg32(bus, SMB_INT_ACK, __sd_reg(tosbmailbox));
bus->sdcnt.f1regdata += 2;

/* Dongle recomposed rx frames, accept them again */
@@ -1190,8 +1190,7 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)

if (rtx) {
bus->sdcnt.rxrtx++;
- err = w_sdreg32(bus, SMB_NAK,
- offsetof(struct sdpcmd_regs, tosbmailbox));
+ err = w_sdreg32(bus, SMB_NAK, __sd_reg(tosbmailbox));

bus->sdcnt.f1regdata++;
if (err == 0)
@@ -2315,9 +2314,7 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
if (!bus->intr) {
/* Check device status, signal pending interrupt */
sdio_claim_host(bus->sdiodev->func[1]);
- ret = r_sdreg32(bus, &intstatus,
- offsetof(struct sdpcmd_regs,
- intstatus));
+ ret = r_sdreg32(bus, &intstatus, __sd_reg(intstatus));
sdio_release_host(bus->sdiodev->func[1]);
bus->sdcnt.f2txdata++;
if (ret != 0)
@@ -2423,7 +2420,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
brcmf_sdio_bus_sleep(bus, false, false);

/* Disable and clear interrupts at the chip level also */
- w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask));
+ w_sdreg32(bus, 0, __sd_reg(hostintmask));
local_hostintmask = bus->hostintmask;
bus->hostintmask = 0;

@@ -2442,8 +2439,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);

/* Clear any pending interrupts now that F2 is disabled */
- w_sdreg32(bus, local_hostintmask,
- offsetof(struct sdpcmd_regs, intstatus));
+ w_sdreg32(bus, local_hostintmask, __sd_reg(intstatus));

sdio_release_host(sdiodev->func[1]);
}
@@ -2489,7 +2485,7 @@ static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)
int ret;

buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
- addr = buscore->base + offsetof(struct sdpcmd_regs, intstatus);
+ addr = buscore->base + __sd_reg(intstatus);

val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret);
bus->sdcnt.f1regdata++;
@@ -2564,11 +2560,9 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
*/
if (intstatus & I_HMB_FC_CHANGE) {
intstatus &= ~I_HMB_FC_CHANGE;
- err = w_sdreg32(bus, I_HMB_FC_CHANGE,
- offsetof(struct sdpcmd_regs, intstatus));
+ err = w_sdreg32(bus, I_HMB_FC_CHANGE, __sd_reg(intstatus));

- err = r_sdreg32(bus, &newstatus,
- offsetof(struct sdpcmd_regs, intstatus));
+ err = r_sdreg32(bus, &newstatus, __sd_reg(intstatus));
bus->sdcnt.f1regdata += 2;
atomic_set(&bus->fcstate,
!!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)));
@@ -3748,7 +3742,7 @@ static void brcmf_sdio_buscore_activate(void *ctx, struct brcmf_chip *chip,

/* clear all interrupts */
core = brcmf_chip_get_core(chip, BCMA_CORE_SDIO_DEV);
- reg_addr = core->base + offsetof(struct sdpcmd_regs, intstatus);
+ reg_addr = core->base + __sd_reg(intstatus);
brcmf_sdiod_writel(sdiodev, reg_addr, 0xFFFFFFFF, NULL);

if (rstvec)
@@ -4023,7 +4017,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,

/* Enable function 2 (frame transfers) */
w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
- offsetof(struct sdpcmd_regs, tosbmailboxdata));
+ __sd_reg(tosbmailboxdata));
err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);


@@ -4033,8 +4027,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
if (!err) {
/* Set up the interrupt mask and enable interrupts */
bus->hostintmask = HOSTINTMASK;
- w_sdreg32(bus, bus->hostintmask,
- offsetof(struct sdpcmd_regs, hostintmask));
+ w_sdreg32(bus, bus->hostintmask, __sd_reg(hostintmask));

brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
} else {
--
2.11.0

2017-07-19 19:11:00

by Ian Molton

[permalink] [raw]
Subject: [PATCH 19/34] brcmfmac: Get rid of chip_priv and core_priv structs

There is zero need to keep these structures separate, they are *always*
allocated together. All they do is obfuscate the code, whilst offering
zero real gain.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/chip.c | 384 +++++++++------------
.../wireless/broadcom/brcm80211/brcmfmac/chip.h | 22 ++
2 files changed, 192 insertions(+), 214 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index 7b8ba7192e1a..781f54bb844b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -223,75 +223,58 @@ struct sbsocramregs {
#define ARMCR4_BSZ_MASK 0x3f
#define ARMCR4_BSZ_MULT 8192

-struct brcmf_core_priv {
- struct brcmf_core pub;
- u32 wrapbase;
- struct list_head list;
- struct brcmf_chip_priv *chip;
-};
-
-struct brcmf_chip_priv {
- struct brcmf_chip pub;
- const struct brcmf_buscore_ops *ops;
- void *ctx;
- /* assured first core is chipcommon, second core is buscore */
- struct list_head cores;
- u16 num_cores;
-
- bool (*iscoreup)(struct brcmf_core_priv *core);
- void (*coredisable)(struct brcmf_core_priv *core, u32 prereset,
- u32 reset);
- void (*resetcore)(struct brcmf_core_priv *core, u32 prereset, u32 reset,
- u32 postreset);
-};

-static void brcmf_chip_sb_corerev(struct brcmf_chip_priv *ci,
+static void brcmf_chip_sb_corerev(struct brcmf_chip *ci,
struct brcmf_core *core)
{
u32 regdata;

regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
+
core->rev = SBCOREREV(regdata);
}

-static bool brcmf_chip_sb_iscoreup(struct brcmf_core_priv *core)
+static bool brcmf_chip_sb_iscoreup(struct brcmf_core *core)
{
- struct brcmf_chip_priv *ci;
+ struct brcmf_chip *ci = core->chip;
u32 regdata;
u32 address;

- ci = core->chip;
- address = CORE_SB(core->pub.base, sbtmstatelow);
+ address = CORE_SB(core->base, sbtmstatelow);
+
regdata = ci->ops->read32(ci->ctx, address);
+
regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT |
SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK);
+
return SSB_TMSLOW_CLOCK == regdata;
}

-static bool brcmf_chip_ai_iscoreup(struct brcmf_core_priv *core)
+static bool brcmf_chip_ai_iscoreup(struct brcmf_core *core)
{
- struct brcmf_chip_priv *ci;
+ struct brcmf_chip *ci = core->chip;
u32 regdata;
bool ret;

- ci = core->chip;
regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
+
ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK;

regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
+
ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0);

return ret;
}

-static void brcmf_chip_sb_coredisable(struct brcmf_core_priv *core,
+static void brcmf_chip_sb_coredisable(struct brcmf_core *core,
u32 prereset, u32 reset)
{
- struct brcmf_chip_priv *ci;
+ struct brcmf_chip *ci = core->chip;
u32 val, base;

- ci = core->chip;
- base = core->pub.base;
+ base = core->base;
+
val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
if (val & SSB_TMSLOW_RESET)
return;
@@ -354,14 +337,12 @@ static void brcmf_chip_sb_coredisable(struct brcmf_core_priv *core,
udelay(1);
}

-static void brcmf_chip_ai_coredisable(struct brcmf_core_priv *core,
+static void brcmf_chip_ai_coredisable(struct brcmf_core *core,
u32 prereset, u32 reset)
{
- struct brcmf_chip_priv *ci;
+ struct brcmf_chip *ci = core->chip;
u32 regdata;

- ci = core->chip;
-
/* if core is already in reset, skip reset */
regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
if ((regdata & BCMA_RESET_CTL_RESET) != 0)
@@ -388,15 +369,13 @@ static void brcmf_chip_ai_coredisable(struct brcmf_core_priv *core,
ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
}

-static void brcmf_chip_sb_resetcore(struct brcmf_core_priv *core, u32 prereset,
+static void brcmf_chip_sb_resetcore(struct brcmf_core *core, u32 prereset,
u32 reset, u32 postreset)
{
- struct brcmf_chip_priv *ci;
+ struct brcmf_chip *ci = core->chip;
+ u32 base = core->base;
u32 regdata;
- u32 base;

- ci = core->chip;
- base = core->pub.base;
/*
* Must do the disable sequence first to work for
* arbitrary current core state.
@@ -438,14 +417,12 @@ static void brcmf_chip_sb_resetcore(struct brcmf_core_priv *core, u32 prereset,
udelay(1);
}

-static void brcmf_chip_ai_resetcore(struct brcmf_core_priv *core, u32 prereset,
+static void brcmf_chip_ai_resetcore(struct brcmf_core *core, u32 prereset,
u32 reset, u32 postreset)
{
- struct brcmf_chip_priv *ci;
+ struct brcmf_chip *ci = core->chip;
int count;

- ci = core->chip;
-
/* must disable first to work for arbitrary current core state */
brcmf_chip_ai_coredisable(core, prereset, reset);

@@ -473,29 +450,30 @@ static char *brcmf_chip_name(uint chipid, char *buf, uint len)
return buf;
}

-static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip_priv *ci,
+static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip *ci,
u16 coreid, u32 base,
u32 wrapbase)
{
- struct brcmf_core_priv *core;
+ struct brcmf_core *core;

core = kzalloc(sizeof(*core), GFP_KERNEL);
if (!core)
return ERR_PTR(-ENOMEM);

- core->pub.id = coreid;
- core->pub.base = base;
+ core->id = coreid;
+ core->base = base;
core->chip = ci;
core->wrapbase = wrapbase;

list_add_tail(&core->list, &ci->cores);
- return &core->pub;
+
+ return core;
}

/* safety check for chipinfo */
-static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
+static int brcmf_chip_cores_check(struct brcmf_chip *ci)
{
- struct brcmf_core_priv *core;
+ struct brcmf_core *core;
bool need_socram = false;
bool has_socram = false;
bool cpu_found = false;
@@ -503,10 +481,10 @@ static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)

list_for_each_entry(core, &ci->cores, list) {
brcmf_dbg(INFO, " [%-2d] core 0x%x:%-2d base 0x%08x wrap 0x%08x\n",
- idx++, core->pub.id, core->pub.rev, core->pub.base,
+ idx++, core->id, core->rev, core->base,
core->wrapbase);

- switch (core->pub.id) {
+ switch (core->id) {
case BCMA_CORE_ARM_CM3:
cpu_found = true;
need_socram = true;
@@ -529,26 +507,28 @@ static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
brcmf_err("CPU core not detected\n");
return -ENXIO;
}
+
/* check RAM core presence for ARM CM3 core */
if (need_socram && !has_socram) {
brcmf_err("RAM core not provided with ARM CM3 core\n");
return -ENODEV;
}
+
return 0;
}

-static u32 brcmf_chip_core_read32(struct brcmf_core_priv *core, u16 reg)
+static u32 brcmf_chip_core_read32(struct brcmf_core *core, u16 reg)
{
- return core->chip->ops->read32(core->chip->ctx, core->pub.base + reg);
+ return core->chip->ops->read32(core->chip->ctx, core->base + reg);
}

-static void brcmf_chip_core_write32(struct brcmf_core_priv *core,
+static void brcmf_chip_core_write32(struct brcmf_core *core,
u16 reg, u32 val)
{
- core->chip->ops->write32(core->chip->ctx, core->pub.base + reg, val);
+ core->chip->ops->write32(core->chip->ctx, core->base + reg, val);
}

-static bool brcmf_chip_socram_banksize(struct brcmf_core_priv *core, u8 idx,
+static bool brcmf_chip_socram_banksize(struct brcmf_core *core, u8 idx,
u32 *banksize)
{
u32 bankinfo;
@@ -562,7 +542,7 @@ static bool brcmf_chip_socram_banksize(struct brcmf_core_priv *core, u8 idx,
return !!(bankinfo & SOCRAM_BANKINFO_RETNTRAM_MASK);
}

-static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
+static void brcmf_chip_socram_ramsize(struct brcmf_core *sr, u32 *ramsize,
u32 *srsize)
{
u32 coreinfo;
@@ -573,17 +553,17 @@ static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
*ramsize = 0;
*srsize = 0;

- if (WARN_ON(sr->pub.rev < 4))
+ if (WARN_ON(sr->rev < 4))
return;

- if (!brcmf_chip_iscoreup(&sr->pub))
- brcmf_chip_resetcore(&sr->pub, 0, 0, 0);
+ if (!brcmf_chip_iscoreup(sr))
+ brcmf_chip_resetcore(sr, 0, 0, 0);

/* Get info for determining size */
coreinfo = brcmf_chip_core_read32(sr, SOCRAMREGOFFS(coreinfo));
nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;

- if ((sr->pub.rev <= 7) || (sr->pub.rev == 12)) {
+ if ((sr->rev <= 7) || (sr->rev == 12)) {
banksize = (coreinfo & SRCI_SRBSZ_MASK);
lss = (coreinfo & SRCI_LSS_MASK) >> SRCI_LSS_SHIFT;
if (lss != 0)
@@ -602,9 +582,9 @@ static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
}

/* hardcoded save&restore memory sizes */
- switch (sr->chip->pub.chip) {
+ switch (sr->chip->chip) {
case BRCM_CC_4334_CHIP_ID:
- if (sr->chip->pub.chiprev < 2)
+ if (sr->chip->chiprev < 2)
*srsize = (32 * 1024);
break;
case BRCM_CC_43430_CHIP_ID:
@@ -619,7 +599,7 @@ static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
}

/** Return the SYS MEM size */
-static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem)
+static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core *sysmem)
{
u32 memsize = 0;
u32 coreinfo;
@@ -627,8 +607,8 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem)
u32 nb;
u32 banksize;

- if (!brcmf_chip_iscoreup(&sysmem->pub))
- brcmf_chip_resetcore(&sysmem->pub, 0, 0, 0);
+ if (!brcmf_chip_iscoreup(sysmem))
+ brcmf_chip_resetcore(sysmem, 0, 0, 0);

coreinfo = brcmf_chip_core_read32(sysmem, SYSMEMREGOFFS(coreinfo));
nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
@@ -642,7 +622,7 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem)
}

/** Return the TCM-RAM size of the ARMCR4 core. */
-static u32 brcmf_chip_tcm_ramsize(struct brcmf_core_priv *cr4)
+static u32 brcmf_chip_tcm_ramsize(struct brcmf_core *cr4)
{
u32 corecap;
u32 memsize = 0;
@@ -667,9 +647,9 @@ static u32 brcmf_chip_tcm_ramsize(struct brcmf_core_priv *cr4)
return memsize;
}

-static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci)
+static u32 brcmf_chip_tcm_rambase(struct brcmf_chip *ci)
{
- switch (ci->pub.chip) {
+ switch (ci->chip) {
case BRCM_CC_4345_CHIP_ID:
return 0x198000;
case BRCM_CC_4335_CHIP_ID:
@@ -691,60 +671,53 @@ static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci)
case BRCM_CC_4366_CHIP_ID:
return 0x200000;
default:
- brcmf_err("unknown chip: %s\n", ci->pub.name);
+ brcmf_err("unknown chip: %s\n", ci->name);
break;
}
return 0;
}

-static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
+static int brcmf_chip_get_raminfo(struct brcmf_chip *ci)
{
- struct brcmf_core_priv *mem_core;
struct brcmf_core *mem;

- mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_ARM_CR4);
+ mem = brcmf_chip_get_core(ci, BCMA_CORE_ARM_CR4);
if (mem) {
- mem_core = container_of(mem, struct brcmf_core_priv, pub);
- ci->pub.ramsize = brcmf_chip_tcm_ramsize(mem_core);
- ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
- if (!ci->pub.rambase) {
+ ci->ramsize = brcmf_chip_tcm_ramsize(mem);
+ ci->rambase = brcmf_chip_tcm_rambase(ci);
+ if (!ci->rambase) {
brcmf_err("RAM base not provided with ARM CR4 core\n");
return -EINVAL;
}
} else {
- mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_SYS_MEM);
+ mem = brcmf_chip_get_core(ci, BCMA_CORE_SYS_MEM);
if (mem) {
- mem_core = container_of(mem, struct brcmf_core_priv,
- pub);
- ci->pub.ramsize = brcmf_chip_sysmem_ramsize(mem_core);
- ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
- if (!ci->pub.rambase) {
+ ci->ramsize = brcmf_chip_sysmem_ramsize(mem);
+ ci->rambase = brcmf_chip_tcm_rambase(ci);
+ if (!ci->rambase) {
brcmf_err("RAM base not provided with ARM CA7 core\n");
return -EINVAL;
}
} else {
- mem = brcmf_chip_get_core(&ci->pub,
- BCMA_CORE_INTERNAL_MEM);
+ mem = brcmf_chip_get_core(ci, BCMA_CORE_INTERNAL_MEM);
if (!mem) {
brcmf_err("No memory cores found\n");
return -ENOMEM;
}
- mem_core = container_of(mem, struct brcmf_core_priv,
- pub);
- brcmf_chip_socram_ramsize(mem_core, &ci->pub.ramsize,
- &ci->pub.srsize);
+ brcmf_chip_socram_ramsize(mem, &ci->ramsize,
+ &ci->srsize);
}
}
brcmf_dbg(INFO, "RAM: base=0x%x size=%d (0x%x) sr=%d (0x%x)\n",
- ci->pub.rambase, ci->pub.ramsize, ci->pub.ramsize,
- ci->pub.srsize, ci->pub.srsize);
+ ci->rambase, ci->ramsize, ci->ramsize,
+ ci->srsize, ci->srsize);

- if (!ci->pub.ramsize) {
+ if (!ci->ramsize) {
brcmf_err("RAM size is undetermined\n");
return -ENOMEM;
}

- if (ci->pub.ramsize > BRCMF_CHIP_MAX_MEMSIZE) {
+ if (ci->ramsize > BRCMF_CHIP_MAX_MEMSIZE) {
brcmf_err("RAM size is incorrect\n");
return -ENOMEM;
}
@@ -752,7 +725,7 @@ static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
return 0;
}

-static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip_priv *ci, u32 *eromaddr,
+static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip *ci, u32 *eromaddr,
u8 *type)
{
u32 val;
@@ -772,7 +745,7 @@ static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip_priv *ci, u32 *eromaddr,
return val;
}

-static int brcmf_chip_dmp_get_regaddr(struct brcmf_chip_priv *ci, u32 *eromaddr,
+static int brcmf_chip_dmp_get_regaddr(struct brcmf_chip *ci, u32 *eromaddr,
u32 *regbase, u32 *wrapbase)
{
u8 desc;
@@ -845,7 +818,7 @@ static int brcmf_chip_dmp_get_regaddr(struct brcmf_chip_priv *ci, u32 *eromaddr,
}

static
-int brcmf_chip_dmp_erom_scan(struct brcmf_chip_priv *ci)
+int brcmf_chip_dmp_erom_scan(struct brcmf_chip *ci)
{
struct brcmf_core *core;
u32 eromaddr;
@@ -905,7 +878,7 @@ int brcmf_chip_dmp_erom_scan(struct brcmf_chip_priv *ci)
return 0;
}

-static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
+static int brcmf_chip_recognition(struct brcmf_chip *ci)
{
struct brcmf_core *core;
u32 regdata;
@@ -918,18 +891,20 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
* other ways of recognition should be added here.
*/
regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
- ci->pub.chip = regdata & CID_ID_MASK;
- ci->pub.chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
+ ci->chip = regdata & CID_ID_MASK;
+ ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;

- brcmf_chip_name(ci->pub.chip, ci->pub.name, sizeof(ci->pub.name));
- brcmf_dbg(INFO, "found %s chip: BCM%s, rev=%d\n",
- socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name,
- ci->pub.chiprev);
+ brcmf_chip_name(ci->chip, ci->name, sizeof(ci->name));
+
+ printk("found %s chip: BCM%s, rev=%d\n",
+ socitype == SOCI_SB ? "SB" : "AXI", ci->name,
+ ci->chiprev);

switch(socitype) {
case SOCI_SB:
- if (ci->pub.chip != BRCM_CC_4329_CHIP_ID) {
+
+ if (ci->chip != BRCM_CC_4329_CHIP_ID) {
brcmf_err("SB chip is not supported\n");
return -ENODEV;
}
@@ -971,42 +946,40 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
return ret;

/* assure chip is passive for core access */
- brcmf_chip_set_passive(&ci->pub);
+ brcmf_chip_set_passive(ci);

/* Call bus specific reset function now. Cores have been determined
* but further access may require a chip specific reset at this point.
*/
if (ci->ops->reset) {
- ci->ops->reset(ci->ctx, &ci->pub);
- brcmf_chip_set_passive(&ci->pub);
+ ci->ops->reset(ci->ctx, ci);
+ brcmf_chip_set_passive(ci);
}

return brcmf_chip_get_raminfo(ci);
}

-static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
+static void brcmf_chip_disable_arm(struct brcmf_chip *chip, u16 id)
{
- struct brcmf_core *core;
- struct brcmf_core_priv *cpu;
+ struct brcmf_core *cpu;
u32 val;


- core = brcmf_chip_get_core(&chip->pub, id);
- if (!core)
+ cpu = brcmf_chip_get_core(chip, id);
+ if (!cpu)
return;

switch (id) {
case BCMA_CORE_ARM_CM3:
- brcmf_chip_coredisable(core, 0, 0);
+ brcmf_chip_coredisable(cpu, 0, 0);
break;
case BCMA_CORE_ARM_CR4:
case BCMA_CORE_ARM_CA7:
- cpu = container_of(core, struct brcmf_core_priv, pub);

/* clear all IOCTL bits except HALT bit */
val = chip->ops->read32(chip->ctx, cpu->wrapbase + BCMA_IOCTL);
val &= ARMCR4_BCMA_IOCTL_CPUHALT;
- brcmf_chip_resetcore(core, val, ARMCR4_BCMA_IOCTL_CPUHALT,
+ brcmf_chip_resetcore(cpu, val, ARMCR4_BCMA_IOCTL_CPUHALT,
ARMCR4_BCMA_IOCTL_CPUHALT);
break;
default:
@@ -1015,41 +988,38 @@ static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
}
}

-static int brcmf_chip_setup(struct brcmf_chip_priv *chip)
+static int brcmf_chip_setup(struct brcmf_chip *chip)
{
- struct brcmf_chip *pub;
- struct brcmf_core_priv *cc;
- struct brcmf_core *pmu;
+ struct brcmf_core *cc, *pmu;
u32 base;
u32 val;
int ret = 0;

- pub = &chip->pub;
- cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
- base = cc->pub.base;
+ cc = list_first_entry(&chip->cores, struct brcmf_core, list);
+ base = cc->base;

/* get chipcommon capabilites */
- pub->cc_caps = chip->ops->read32(chip->ctx,
+ chip->cc_caps = chip->ops->read32(chip->ctx,
CORE_CC_REG(base, capabilities));
- pub->cc_caps_ext = chip->ops->read32(chip->ctx,
+ chip->cc_caps_ext = chip->ops->read32(chip->ctx,
CORE_CC_REG(base,
capabilities_ext));

/* get pmu caps & rev */
- pmu = brcmf_chip_get_pmu(pub); /* after reading cc_caps_ext */
- if (pub->cc_caps & CC_CAP_PMU) {
+ pmu = brcmf_chip_get_pmu(chip); /* after reading cc_caps_ext */
+ if (chip->cc_caps & CC_CAP_PMU) {
val = chip->ops->read32(chip->ctx,
CORE_CC_REG(pmu->base, pmucapabilities));
- pub->pmurev = val & PCAP_REV_MASK;
- pub->pmucaps = val;
+ chip->pmurev = val & PCAP_REV_MASK;
+ chip->pmucaps = val;
}

brcmf_dbg(INFO, "ccrev=%d, pmurev=%d, pmucaps=0x%x\n",
- cc->pub.rev, pub->pmurev, pub->pmucaps);
+ cc->rev, chip->pmurev, chip->pmucaps);

/* execute bus core specific setup */
if (chip->ops->setup)
- ret = chip->ops->setup(chip->ctx, pub);
+ ret = chip->ops->setup(chip->ctx, chip);

return ret;
}
@@ -1057,7 +1027,7 @@ static int brcmf_chip_setup(struct brcmf_chip_priv *chip)
struct brcmf_chip *brcmf_chip_attach(void *ctx,
const struct brcmf_buscore_ops *ops)
{
- struct brcmf_chip_priv *chip;
+ struct brcmf_chip *chip;
int err = 0;

if (WARN_ON(!ops->read32))
@@ -1092,20 +1062,18 @@ struct brcmf_chip *brcmf_chip_attach(void *ctx,
if (err < 0)
goto fail;

- return &chip->pub;
+ return chip;

fail:
- brcmf_chip_detach(&chip->pub);
+ brcmf_chip_detach(chip);
return ERR_PTR(err);
}

-void brcmf_chip_detach(struct brcmf_chip *pub)
+void brcmf_chip_detach(struct brcmf_chip *chip)
{
- struct brcmf_chip_priv *chip;
- struct brcmf_core_priv *core;
- struct brcmf_core_priv *tmp;
+ struct brcmf_core *core;
+ struct brcmf_core *tmp;

- chip = container_of(pub, struct brcmf_chip_priv, pub);
list_for_each_entry_safe(core, tmp, &chip->cores, list) {
list_del(&core->list);
kfree(core);
@@ -1113,40 +1081,38 @@ void brcmf_chip_detach(struct brcmf_chip *pub)
kfree(chip);
}

-struct brcmf_core *brcmf_chip_get_core(struct brcmf_chip *pub, u16 coreid)
+struct brcmf_core *brcmf_chip_get_core(struct brcmf_chip *chip, u16 coreid)
{
- struct brcmf_chip_priv *chip;
- struct brcmf_core_priv *core;
+ struct brcmf_core *core;

- chip = container_of(pub, struct brcmf_chip_priv, pub);
list_for_each_entry(core, &chip->cores, list)
- if (core->pub.id == coreid)
- return &core->pub;
+ if (core->id == coreid)
+ return core;

return NULL;
}

-struct brcmf_core *brcmf_chip_get_chipcommon(struct brcmf_chip *pub)
+struct brcmf_core *brcmf_chip_get_chipcommon(struct brcmf_chip *chip)
{
- struct brcmf_chip_priv *chip;
- struct brcmf_core_priv *cc;
-
- chip = container_of(pub, struct brcmf_chip_priv, pub);
- cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
- if (WARN_ON(!cc || cc->pub.id != BCMA_CORE_CHIPCOMMON))
- return brcmf_chip_get_core(pub, BCMA_CORE_CHIPCOMMON);
- return &cc->pub;
+ struct brcmf_core *cc;
+
+ cc = list_first_entry(&chip->cores, struct brcmf_core, list);
+
+ if (WARN_ON(!cc || cc->id != BCMA_CORE_CHIPCOMMON))
+ return brcmf_chip_get_core(chip, BCMA_CORE_CHIPCOMMON);
+
+ return cc;
}

-struct brcmf_core *brcmf_chip_get_pmu(struct brcmf_chip *pub)
+struct brcmf_core *brcmf_chip_get_pmu(struct brcmf_chip *chip)
{
- struct brcmf_core *cc = brcmf_chip_get_chipcommon(pub);
+ struct brcmf_core *cc = brcmf_chip_get_chipcommon(chip);
struct brcmf_core *pmu;

/* See if there is separated PMU core available */
if (cc->rev >= 35 &&
- pub->cc_caps_ext & BCMA_CC_CAP_EXT_AOB_PRESENT) {
- pmu = brcmf_chip_get_core(pub, BCMA_CORE_PMU);
+ chip->cc_caps_ext & BCMA_CC_CAP_EXT_AOB_PRESENT) {
+ pmu = brcmf_chip_get_core(chip, BCMA_CORE_PMU);
if (pmu)
return pmu;
}
@@ -1155,188 +1121,178 @@ struct brcmf_core *brcmf_chip_get_pmu(struct brcmf_chip *pub)
return cc;
}

-bool brcmf_chip_iscoreup(struct brcmf_core *pub)
+bool brcmf_chip_iscoreup(struct brcmf_core *core)
{
- struct brcmf_core_priv *core;
-
- core = container_of(pub, struct brcmf_core_priv, pub);
return core->chip->iscoreup(core);
}

-void brcmf_chip_coredisable(struct brcmf_core *pub, u32 prereset, u32 reset)
+void brcmf_chip_coredisable(struct brcmf_core *core, u32 prereset, u32 reset)
{
- struct brcmf_core_priv *core;
-
- core = container_of(pub, struct brcmf_core_priv, pub);
core->chip->coredisable(core, prereset, reset);
}

-void brcmf_chip_resetcore(struct brcmf_core *pub, u32 prereset, u32 reset,
+void brcmf_chip_resetcore(struct brcmf_core *core, u32 prereset, u32 reset,
u32 postreset)
{
- struct brcmf_core_priv *core;
-
- core = container_of(pub, struct brcmf_core_priv, pub);
core->chip->resetcore(core, prereset, reset, postreset);
}

static void
-brcmf_chip_cm3_set_passive(struct brcmf_chip_priv *chip)
+brcmf_chip_cm3_set_passive(struct brcmf_chip *chip)
{
struct brcmf_core *core;
- struct brcmf_core_priv *sr;

brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
+
+ core = brcmf_chip_get_core(chip, BCMA_CORE_80211);
brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
D11_BCMA_IOCTL_PHYCLOCKEN,
D11_BCMA_IOCTL_PHYCLOCKEN,
D11_BCMA_IOCTL_PHYCLOCKEN);
- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
+
+ core = brcmf_chip_get_core(chip, BCMA_CORE_INTERNAL_MEM);
brcmf_chip_resetcore(core, 0, 0, 0);

/* disable bank #3 remap for this device */
- if (chip->pub.chip == BRCM_CC_43430_CHIP_ID) {
- sr = container_of(core, struct brcmf_core_priv, pub);
- brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankidx), 3);
- brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankpda), 0);
+ if (chip->chip == BRCM_CC_43430_CHIP_ID) {
+ brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankidx), 3);
+ brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankpda), 0);
}
}

-static bool brcmf_chip_cm3_set_active(struct brcmf_chip_priv *chip)
+static bool brcmf_chip_cm3_set_active(struct brcmf_chip *chip)
{
struct brcmf_core *core;

- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
+ core = brcmf_chip_get_core(chip, BCMA_CORE_INTERNAL_MEM);
+
if (!brcmf_chip_iscoreup(core)) {
brcmf_err("SOCRAM core is down after reset?\n");
return false;
}

- chip->ops->activate(chip->ctx, &chip->pub, 0);
+ chip->ops->activate(chip->ctx, chip, 0);

- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CM3);
+ core = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CM3);
brcmf_chip_resetcore(core, 0, 0, 0);

return true;
}

static inline void
-brcmf_chip_cr4_set_passive(struct brcmf_chip_priv *chip)
+brcmf_chip_cr4_set_passive(struct brcmf_chip *chip)
{
struct brcmf_core *core;

brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CR4);

- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
+ core = brcmf_chip_get_core(chip, BCMA_CORE_80211);
brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
D11_BCMA_IOCTL_PHYCLOCKEN,
D11_BCMA_IOCTL_PHYCLOCKEN,
D11_BCMA_IOCTL_PHYCLOCKEN);
}

-static bool brcmf_chip_cr4_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
+static bool brcmf_chip_cr4_set_active(struct brcmf_chip *chip, u32 rstvec)
{
struct brcmf_core *core;

- chip->ops->activate(chip->ctx, &chip->pub, rstvec);
+ chip->ops->activate(chip->ctx, chip, rstvec);

/* restore ARM */
- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CR4);
+ core = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CR4);
brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);

return true;
}

static inline void
-brcmf_chip_ca7_set_passive(struct brcmf_chip_priv *chip)
+brcmf_chip_ca7_set_passive(struct brcmf_chip *chip)
{
struct brcmf_core *core;

brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CA7);

- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
+ core = brcmf_chip_get_core(chip, BCMA_CORE_80211);
brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
D11_BCMA_IOCTL_PHYCLOCKEN,
D11_BCMA_IOCTL_PHYCLOCKEN,
D11_BCMA_IOCTL_PHYCLOCKEN);
}

-static bool brcmf_chip_ca7_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
+static bool brcmf_chip_ca7_set_active(struct brcmf_chip *chip, u32 rstvec)
{
struct brcmf_core *core;

- chip->ops->activate(chip->ctx, &chip->pub, rstvec);
+ chip->ops->activate(chip->ctx, chip, rstvec);

/* restore ARM */
- core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CA7);
+ core = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CA7);
brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);

return true;
}

-void brcmf_chip_set_passive(struct brcmf_chip *pub)
+void brcmf_chip_set_passive(struct brcmf_chip *chip)
{
- struct brcmf_chip_priv *chip;
struct brcmf_core *arm;

brcmf_dbg(TRACE, "Enter\n");

- chip = container_of(pub, struct brcmf_chip_priv, pub);
- arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
+ arm = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CR4);
if (arm) {
brcmf_chip_cr4_set_passive(chip);
return;
}
- arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CA7);
+
+ arm = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CA7);
if (arm) {
brcmf_chip_ca7_set_passive(chip);
return;
}
- arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
+
+ arm = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CM3);
if (arm) {
brcmf_chip_cm3_set_passive(chip);
return;
}
}

-bool brcmf_chip_set_active(struct brcmf_chip *pub, u32 rstvec)
+bool brcmf_chip_set_active(struct brcmf_chip *chip, u32 rstvec)
{
- struct brcmf_chip_priv *chip;
struct brcmf_core *arm;

brcmf_dbg(TRACE, "Enter\n");

- chip = container_of(pub, struct brcmf_chip_priv, pub);
- arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
+ arm = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CR4);
if (arm)
return brcmf_chip_cr4_set_active(chip, rstvec);
- arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CA7);
+
+ arm = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CA7);
if (arm)
return brcmf_chip_ca7_set_active(chip, rstvec);
- arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
+
+ arm = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CM3);
if (arm)
return brcmf_chip_cm3_set_active(chip);

return false;
}

-bool brcmf_chip_sr_capable(struct brcmf_chip *pub)
+bool brcmf_chip_sr_capable(struct brcmf_chip *chip)
{
+ struct brcmf_core *pmu = brcmf_chip_get_pmu(chip);
u32 base, addr, reg, pmu_cc3_mask = ~0;
- struct brcmf_chip_priv *chip;
- struct brcmf_core *pmu = brcmf_chip_get_pmu(pub);

brcmf_dbg(TRACE, "Enter\n");

/* old chips with PMU version less than 17 don't support save restore */
- if (pub->pmurev < 17)
+ if (chip->pmurev < 17)
return false;

- base = brcmf_chip_get_chipcommon(pub)->base;
- chip = container_of(pub, struct brcmf_chip_priv, pub);
+ base = brcmf_chip_get_chipcommon(chip)->base;

- switch (pub->chip) {
+ switch (chip->chip) {
case BRCM_CC_4354_CHIP_ID:
case BRCM_CC_4356_CHIP_ID:
/* explicitly check SR engine enable bit */
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
index dd0ec3eba6a9..0babb328d155 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
@@ -21,6 +21,8 @@
#define CORE_CC_REG(base, field) \
(base + offsetof(struct chipcregs, field))

+struct brcmf_core;
+
/**
* struct brcmf_chip - chip level information.
*
@@ -36,6 +38,20 @@
* @name: string representation of the chip identifier.
*/
struct brcmf_chip {
+ const struct brcmf_buscore_ops *ops;
+
+ /* assured first core is chipcommon, second core is buscore */
+ //FIXME: Really? does not appear to hold true for 43430
+ struct list_head cores; /* List of cores in this chip */
+ u16 num_cores;
+
+ bool (*iscoreup)(struct brcmf_core *core);
+ void (*coredisable)(struct brcmf_core *core, u32 prereset, u32 reset);
+ void (*resetcore)(struct brcmf_core *core, u32 prereset, u32 reset,
+ u32 postreset);
+
+ void *ctx;
+
u32 chip;
u32 chiprev;
u32 cc_caps;
@@ -45,6 +61,7 @@ struct brcmf_chip {
u32 rambase;
u32 ramsize;
u32 srsize;
+
char name[8];
};

@@ -56,9 +73,14 @@ struct brcmf_chip {
* @base: base address of core register space.
*/
struct brcmf_core {
+ struct brcmf_chip *chip; /* Parent chip */
+ struct list_head list;
+
u16 id;
u16 rev;
u32 base;
+ u32 wrapbase;
+
};

/**
--
2.11.0

2017-07-24 19:48:02

by Arend Van Spriel

[permalink] [raw]
Subject: Re: PATCH v3 brcmfmac driver cleanup

On 19-07-17 21:07, Ian Molton wrote:
> Hi all,
>
> Please find the 3rd revision of my cleanup patchset for brcmfmac.
>
> I've done some further cleanup and it now handles SDIO the ay the MMC subsystem
> was designed to.
>
> I've also taken the liberty of greatly reducing the amount of indirection
> used thoughout the SDIO code, which I think has improved readability quite a
> lot.
>
> Hope this finds you all well.

After only one week of vacation there was quite some catching up to do.
So I decided to get an easy start and run 'checkpatch.pl --strict' over
the series. Attached the output of that. Might be stuff that was already
wrong before. I did only a quick check on patch 1/34 and it is really
introduced by that patch. So can you please check the output.

FWIW, I tend to ignore the warning about block comments, ie.:

/*
* bla
*/

is fine by me. At least I prefer it over:

/* bla
*/

Regards,
Arend


Attachments:
cleanup-checkpatch.txt (51.84 kB)

2017-07-19 19:13:22

by Ian Molton

[permalink] [raw]
Subject: [PATCH 14/34] brcmfmac: Remove brcmf_sdiod_addrprep()

This function has become trivial enough that it may as well be pushed into
its callers, which has the side-benefit of clarifying what's going on.

Remove it, and rename brcmf_sdiod_set_sbaddr_window() to
brcmf_sdiod_set_backplane_window() as it's easier to understand.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 78 ++++++++++++----------
1 file changed, 43 insertions(+), 35 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 13f20b58d34e..eb388b69418a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -229,41 +229,23 @@ void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
}

static int
-brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
+brcmf_sdiod_set_backplane_window(struct brcmf_sdio_dev *sdiodev, u32 addr)
{
+ u32 v, bar0 = addr & SBSDIO_SBWINDOW_MASK;
int err = 0, i;
- u32 addr;

- if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
- return -ENOMEDIUM;
-
- addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;
+ if (bar0 == sdiodev->sbwad)
+ return 0;

- for ( i = 0 ; i < 3 && !err ; i++, addr >>= 8 )
- brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr & 0xff,
- &err);
+ v = bar0 >> 8;

- return err;
-}
-
-static int
-brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, u32 *addr)
-{
- uint bar0 = *addr & ~SBSDIO_SB_OFT_ADDR_MASK;
- int err = 0;
-
- if (bar0 != sdiodev->sbwad) {
- err = brcmf_sdiod_set_sbaddr_window(sdiodev, bar0);
- if (err)
- return err;
+ for (i = 0 ; i < 3 && !err ; i++, v>>=8)
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, v & 0xff, &err);

+ if(!err)
sdiodev->sbwad = bar0;
- }
-
- *addr &= SBSDIO_SB_OFT_ADDR_MASK;
- *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

- return 0;
+ return err;
}

u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
@@ -271,11 +253,17 @@ u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
u32 data = 0;
int retval;

- retval = brcmf_sdiod_addrprep(sdiodev, &addr);
+ retval = brcmf_sdiod_set_backplane_window(sdiodev, addr);
+ if (retval)
+ goto out;
+
+ addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!retval)
data = sdio_readl(sdiodev->func[1], addr, &retval);

+out:
if (ret)
*ret = retval;

@@ -287,11 +275,17 @@ void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
{
int retval;

- retval = brcmf_sdiod_addrprep(sdiodev, &addr);
+ retval = brcmf_sdiod_set_backplane_window(sdiodev, addr);
+ if (retval)
+ goto out;
+
+ addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!retval)
sdio_writel(sdiodev->func[1], data, addr, &retval);

+out:
if (ret)
*ret = retval;
}
@@ -539,10 +533,13 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pkt->len);

- err = brcmf_sdiod_addrprep(sdiodev, &addr);
+ err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
if (err)
goto done;

+ addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
+
err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr, pkt);

done:
@@ -560,10 +557,13 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n",
addr, pktq->qlen);

- err = brcmf_sdiod_addrprep(sdiodev, &addr);
+ err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
if (err)
goto done;

+ addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
+
if (pktq->qlen == 1)
err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
pktq->next);
@@ -605,7 +605,12 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)

memcpy(mypkt->data, buf, nbytes);

- err = brcmf_sdiod_addrprep(sdiodev, &addr);
+ err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
+ if (err)
+ return err;
+
+ addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!err)
err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);
@@ -625,10 +630,13 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pktq->qlen);

- err = brcmf_sdiod_addrprep(sdiodev, &addr);
+ err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
if (err)
return err;

+ addr &= SBSDIO_SB_OFT_ADDR_MASK;
+ addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
+
if (pktq->qlen == 1 || !sdiodev->sg_support)
skb_queue_walk(pktq, skb) {
err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2,
@@ -672,7 +680,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
/* Do the transfer(s) */
while (size) {
/* Set the backplane window to include the start address */
- err = brcmf_sdiod_set_sbaddr_window(sdiodev, address);
+ err = brcmf_sdiod_set_backplane_window(sdiodev, address);
if (err)
break;

@@ -716,7 +724,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
dev_kfree_skb(pkt);

/* Return the window to backplane enumeration space for core access */
- if (brcmf_sdiod_set_sbaddr_window(sdiodev, sdiodev->sbwad))
+ if (brcmf_sdiod_set_backplane_window(sdiodev, sdiodev->sbwad))
brcmf_err("FAILED to set window back to 0x%x\n",
sdiodev->sbwad);

--
2.11.0

2017-07-19 19:15:53

by Ian Molton

[permalink] [raw]
Subject: [PATCH 25/34] brcmfmac: Remove repeated calls to brcmf_chip_get_core()

There is no need to repeatdly call brcmf_chip_get_core(), which
traverses a list of cores every time its called (including during
register access code!).

Call it once, and store a pointer to the core structure. The existing
code does nto keep track of users of the cores anyway, and even so, this
will allow for easier refcounting in future.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 25 +++++++++++++---------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index a72e9d0eb471..f984e1342d9d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -435,6 +435,7 @@ struct brcmf_sdio_count {
struct brcmf_sdio {
struct brcmf_sdio_dev *sdiodev; /* sdio device handler */
struct brcmf_chip *ci; /* Chip info struct */
+ struct brcmf_core *sdio_core; /* sdio core info struct */

u32 hostintmask; /* Copy of Host Interrupt Mask */
atomic_t intstatus; /* Intstatus bits (events) pending */
@@ -662,10 +663,9 @@ static bool data_ok(struct brcmf_sdio *bus)
*/
static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset)
{
- struct brcmf_core *core;
+ struct brcmf_core *core = bus->sdio_core;
int ret;

- core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
*regvar = brcmf_sdiod_readl(bus->sdiodev, core->base + offset, &ret);

return ret;
@@ -673,10 +673,9 @@ static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset)

static int w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset)
{
- struct brcmf_core *core;
+ struct brcmf_core *core = bus->sdio_core;
int ret;

- core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
brcmf_sdiod_writel(bus->sdiodev, core->base + reg_offset, regval, &ret);

return ret;
@@ -2477,12 +2476,11 @@ static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus)

static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)
{
- struct brcmf_core *buscore;
+ struct brcmf_core *buscore = bus->sdio_core;
u32 addr;
unsigned long val;
int ret;

- buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
addr = buscore->base + __sd_reg(intstatus);

val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret);
@@ -3357,13 +3355,14 @@ static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)
/* enable KSO bit */
static int brcmf_sdio_kso_init(struct brcmf_sdio *bus)
{
+ struct brcmf_core *core = bus->sdio_core;
u8 val;
int err = 0;

brcmf_dbg(TRACE, "Enter\n");

/* KSO bit added in SDIO core rev 12 */
- if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12)
+ if (core->rev < 12)
return 0;

val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
@@ -3391,6 +3390,7 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
struct brcmf_sdio *bus = sdiodev->bus;
+ struct brcmf_core *core = bus->sdio_core;
uint pad_size;
u32 value;
int err;
@@ -3399,7 +3399,7 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
* a device perspective, ie. bus:txglom affects the
* bus transfers from device to host.
*/
- if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12) {
+ if (core->rev < 12) {
/* for sdio core rev < 12, disable txgloming */
value = 0;
err = brcmf_iovar_data_set(dev, "bus:txglom", &value,
@@ -3735,11 +3735,10 @@ static void brcmf_sdio_buscore_activate(void *ctx, struct brcmf_chip *chip,
u32 rstvec)
{
struct brcmf_sdio_dev *sdiodev = ctx;
- struct brcmf_core *core;
+ struct brcmf_core *core = sdiodev->bus->sdio_core;
u32 reg_addr;

/* clear all interrupts */
- core = brcmf_chip_get_core(chip, BCMA_CORE_SDIO_DEV);
reg_addr = core->base + __sd_reg(intstatus);
brcmf_sdiod_writel(sdiodev, reg_addr, 0xFFFFFFFF, NULL);

@@ -3818,6 +3817,12 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
bus->ci = NULL;
goto fail;
}
+
+ /* Pick up the SDIO core info struct from chip.c */
+ bus->sdio_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
+ if (!bus->sdio_core)
+ goto fail;
+
sdiodev->settings = brcmf_get_module_param(sdiodev->dev,
BRCMF_BUSTYPE_SDIO,
bus->ci->chip,
--
2.11.0

2017-07-19 19:15:41

by Ian Molton

[permalink] [raw]
Subject: [PATCH 26/34] brcmfmac: General cleaning up. whitespace and comments fix.

Tidy code, fix whitespace, remove useless debug code.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 24 ++++++++++++++--------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index f984e1342d9d..7d68b375c71a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -642,11 +642,13 @@ static struct brcmf_firmware_mapping brcmf_sdio_fwnames[] = {

static void pkt_align(struct sk_buff *p, int len, int align)
{
- uint datalign;
- datalign = (unsigned long)(p->data);
+ uint datalign = (unsigned long)(p->data);
+
datalign = roundup(datalign, (align)) - datalign;
+
if (datalign)
skb_pull(p, datalign);
+
__skb_trim(p, len);
}

@@ -2460,10 +2462,9 @@ static void brcmf_sdio_bus_stop(struct device *dev)

static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus)
{
- struct brcmf_sdio_dev *sdiodev;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
unsigned long flags;

- sdiodev = bus->sdiodev;
if (sdiodev->oob_irq_requested) {
spin_lock_irqsave(&sdiodev->irq_en_lock, flags);
if (!sdiodev->irq_en && !atomic_read(&bus->ipend)) {
@@ -3754,15 +3755,23 @@ static u32 brcmf_sdio_buscore_read32(void *ctx, u32 addr)
u32 val, rev;

val = brcmf_sdiod_readl(sdiodev, addr, NULL);
+
+ /* Force 4339 chips over rev2 to use the same ID */
+ /* This is borderline tolerable whilst there is only two exceptions */
+ /* But could be handled better */
if ((sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 ||
- sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
- addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) {
+ sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
+ addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) {
+
rev = (val & CID_REV_MASK) >> CID_REV_SHIFT;
+
if (rev >= 2) {
val &= ~CID_ID_MASK;
val |= BRCM_CC_4339_CHIP_ID;
}
+
}
+
return val;
}

@@ -3793,9 +3802,6 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
sdiodev = bus->sdiodev;
sdio_claim_host(sdiodev->func[1]);

- pr_debug("F1 signature read @0x18000000=0x%4x\n",
- brcmf_sdiod_readl(sdiodev, SI_ENUM_BASE, NULL));
-
/*
* Force PLL off until brcmf_chip_attach()
* programs PLL control regs
--
2.11.0

2017-07-19 19:08:43

by Ian Molton

[permalink] [raw]
Subject: [PATCH 09/34] brcmfmac: Remove noisy debugging.

If you need debugging this low level, you're doing something wrong.
Remove these noisy debug statements so the code is more readable.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 9145dda11e5a..7dd6af689ac8 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -372,9 +372,7 @@ u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
u8 data = 0;
int retval;

- brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
retval = brcmf_sdiod_reg_read(sdiodev, addr, 1, &data);
- brcmf_dbg(SDIO, "data:0x%02x\n", data);

if (ret)
*ret = retval;
@@ -387,8 +385,6 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
u32 data = 0;
int retval;

- brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
- brcmf_dbg(SDIO, "data:0x%08x\n", data);
retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);

if (ret)
@@ -402,7 +398,6 @@ void brcmf_sdiod_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
{
int retval;

- brcmf_dbg(SDIO, "addr:0x%08x, data:0x%02x\n", addr, data);
retval = brcmf_sdiod_reg_write(sdiodev, addr, 1, &data);

if (ret)
@@ -414,7 +409,7 @@ void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
{
int retval;

- brcmf_dbg(SDIO, "addr:0x%08x, data:0x%08x\n", addr, data);
+ retval = brcmf_sdiod_reg_write(sdiodev, addr, 4, &data);

if (ret)
*ret = retval;
--
2.11.0

2017-07-19 19:08:42

by Ian Molton

[permalink] [raw]
Subject: [PATCH 08/34] brcmfmac: Fix uninitialised variable

Unlikely to be a problem, but brcmf_sdiod_regrb() is
not symmetric with brcmf_sdiod_regrl() in this regard.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 6df12430a43f..9145dda11e5a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -369,7 +369,7 @@ static int brcmf_sdiod_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr,

u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
{
- u8 data;
+ u8 data = 0;
int retval;

brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
--
2.11.0

2017-07-19 19:13:18

by Ian Molton

[permalink] [raw]
Subject: [PATCH 27/34] brcmfmac: Remove {r,w}_sdreg32

Remove yet another IO function from the code and replace with one
that already exists.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 88 +++++++++++-----------
1 file changed, 42 insertions(+), 46 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 7d68b375c71a..cc83388b8c72 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -659,30 +659,6 @@ static bool data_ok(struct brcmf_sdio *bus)
((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0;
}

-/*
- * Reads a register in the SDIO hardware block. This block occupies a series of
- * adresses on the 32 bit backplane bus.
- */
-static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset)
-{
- struct brcmf_core *core = bus->sdio_core;
- int ret;
-
- *regvar = brcmf_sdiod_readl(bus->sdiodev, core->base + offset, &ret);
-
- return ret;
-}
-
-static int w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset)
-{
- struct brcmf_core *core = bus->sdio_core;
- int ret;
-
- brcmf_sdiod_writel(bus->sdiodev, core->base + reg_offset, regval, &ret);
-
- return ret;
-}
-
static int
brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
{
@@ -1071,6 +1047,8 @@ static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus)

static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)
{
+ struct brcmf_sdio_dev *sdiod = bus->sdiodev;
+ struct brcmf_core *core = bus->sdio_core;
u32 intstatus = 0;
u32 hmb_data;
u8 fcbits;
@@ -1079,10 +1057,13 @@ static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)
brcmf_dbg(SDIO, "Enter\n");

/* Read mailbox data and ack that we did so */
- ret = r_sdreg32(bus, &hmb_data, __sd_reg(tohostmailboxdata));
+ hmb_data = brcmf_sdiod_readl(sdiod, core->base +
+ __sd_reg(tohostmailboxdata), &ret);
+
+ if (!ret)
+ brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailbox),
+ SMB_INT_ACK, &ret);

- if (ret == 0)
- w_sdreg32(bus, SMB_INT_ACK, __sd_reg(tosbmailbox));
bus->sdcnt.f1regdata += 2;

/* Dongle recomposed rx frames, accept them again */
@@ -1151,6 +1132,8 @@ static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)

static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
{
+ struct brcmf_sdio_dev *sdiod = bus->sdiodev;
+ struct brcmf_core *core = bus->sdio_core;
uint retries = 0;
u16 lastrbc;
u8 hi, lo;
@@ -1189,7 +1172,8 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)

if (rtx) {
bus->sdcnt.rxrtx++;
- err = w_sdreg32(bus, SMB_NAK, __sd_reg(tosbmailbox));
+ brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailbox),
+ SMB_NAK, &err);

bus->sdcnt.f1regdata++;
if (err == 0)
@@ -2273,6 +2257,7 @@ static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq,

static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
{
+ struct brcmf_core *core = bus->sdio_core;
struct sk_buff *pkt;
struct sk_buff_head pktq;
u32 intstatus = 0;
@@ -2313,7 +2298,8 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
if (!bus->intr) {
/* Check device status, signal pending interrupt */
sdio_claim_host(bus->sdiodev->func[1]);
- ret = r_sdreg32(bus, &intstatus, __sd_reg(intstatus));
+ intstatus = brcmf_sdiod_readl(bus->sdiodev, core->base +
+ __sd_reg(intstatus), &ret);
sdio_release_host(bus->sdiodev->func[1]);
bus->sdcnt.f2txdata++;
if (ret != 0)
@@ -2397,12 +2383,13 @@ static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len)

static void brcmf_sdio_bus_stop(struct device *dev)
{
- u32 local_hostintmask;
- u8 saveclk;
- int err;
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
struct brcmf_sdio *bus = sdiodev->bus;
+ struct brcmf_core *core = bus->sdio_core;
+ u32 local_hostintmask;
+ u8 saveclk;
+ int err;

brcmf_dbg(TRACE, "Enter\n");

@@ -2419,7 +2406,8 @@ static void brcmf_sdio_bus_stop(struct device *dev)
brcmf_sdio_bus_sleep(bus, false, false);

/* Disable and clear interrupts at the chip level also */
- w_sdreg32(bus, 0, __sd_reg(hostintmask));
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(hostintmask), 0, NULL);
+
local_hostintmask = bus->hostintmask;
bus->hostintmask = 0;

@@ -2438,7 +2426,8 @@ static void brcmf_sdio_bus_stop(struct device *dev)
sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);

/* Clear any pending interrupts now that F2 is disabled */
- w_sdreg32(bus, local_hostintmask, __sd_reg(intstatus));
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(intstatus),
+ local_hostintmask, NULL);

sdio_release_host(sdiodev->func[1]);
}
@@ -2504,6 +2493,8 @@ static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)

static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
{
+ struct brcmf_core *core = bus->sdio_core;
+ struct brcmf_sdio_dev *sdiod = bus->sdiodev;
u32 newstatus = 0;
unsigned long intstatus;
uint txlimit = bus->txbound; /* Tx frames to send before resched */
@@ -2557,9 +2548,12 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
*/
if (intstatus & I_HMB_FC_CHANGE) {
intstatus &= ~I_HMB_FC_CHANGE;
- err = w_sdreg32(bus, I_HMB_FC_CHANGE, __sd_reg(intstatus));
+ brcmf_sdiod_writel(sdiod, core->base + __sd_reg(intstatus),
+ I_HMB_FC_CHANGE, &err);
+
+ newstatus = brcmf_sdiod_readl(sdiod, core->base + __sd_reg(intstatus),
+ &err);

- err = r_sdreg32(bus, &newstatus, __sd_reg(intstatus));
bus->sdcnt.f1regdata += 2;
atomic_set(&bus->fcstate,
!!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)));
@@ -3979,22 +3973,21 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
const struct firmware *code,
void *nvram, u32 nvram_len)
{
- struct brcmf_bus *bus_if;
- struct brcmf_sdio_dev *sdiodev;
- struct brcmf_sdio *bus;
+ struct brcmf_bus *bus_if = dev_get_drvdata(dev);
+ struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
+ struct brcmf_sdio *bus = sdiodev->bus;
+ struct brcmf_sdio_dev *sdiod = bus->sdiodev;
+ struct brcmf_core *core = bus->sdio_core;
u8 saveclk;

brcmf_dbg(TRACE, "Enter: dev=%s, err=%d\n", dev_name(dev), err);
- bus_if = dev_get_drvdata(dev);
- sdiodev = bus_if->bus_priv.sdio;
+
if (err)
goto fail;

if (!bus_if->drvr)
return;

- bus = sdiodev->bus;
-
/* try to download image and nvram to the dongle */
bus->alp_only = true;
err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len);
@@ -4025,8 +4018,9 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
}

/* Enable function 2 (frame transfers) */
- w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
- __sd_reg(tosbmailboxdata));
+ brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailboxdata),
+ SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, NULL);
+
err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);


@@ -4036,7 +4030,9 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
if (!err) {
/* Set up the interrupt mask and enable interrupts */
bus->hostintmask = HOSTINTMASK;
- w_sdreg32(bus, bus->hostintmask, __sd_reg(hostintmask));
+ brcmf_sdiod_writel(sdiod, core->base + __sd_reg(hostintmask),
+ bus->hostintmask, NULL);
+

brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
} else {
--
2.11.0

2017-07-19 19:13:24

by Ian Molton

[permalink] [raw]
Subject: [PATCH 11/34] brcmfmac: Split brcmf_sdiod_buffrw function up.

This function needs to be split up into separate read / write variants
for clarity.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 64 +++++++++++++++-------
1 file changed, 45 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index f97b2234044f..013b9b852d81 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -415,8 +415,8 @@ void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
*ret = retval;
}

-static int brcmf_sdiod_buffrw(struct brcmf_sdio_dev *sdiodev, uint fn,
- bool write, u32 addr, struct sk_buff *pkt)
+static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev, uint fn,
+ u32 addr, struct sk_buff *pkt)
{
unsigned int req_sz;
int err;
@@ -425,18 +425,36 @@ static int brcmf_sdiod_buffrw(struct brcmf_sdio_dev *sdiodev, uint fn,
req_sz = pkt->len + 3;
req_sz &= (uint)~3;

- if (write)
- err = sdio_memcpy_toio(sdiodev->func[fn], addr,
- ((u8 *)(pkt->data)), req_sz);
- else if (fn == 1)
- err = sdio_memcpy_fromio(sdiodev->func[fn], ((u8 *)(pkt->data)),
- addr, req_sz);
+ if (fn == 1)
+ err = sdio_memcpy_fromio(sdiodev->func[fn],
+ ((u8 *)(pkt->data)), addr, req_sz);
else
/* function 2 read is FIFO operation */
- err = sdio_readsb(sdiodev->func[fn], ((u8 *)(pkt->data)), addr,
- req_sz);
+ err = sdio_readsb(sdiodev->func[fn],
+ ((u8 *)(pkt->data)), addr, req_sz);
+
if (err == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
+
+ return err;
+}
+
+static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
+ u32 addr, struct sk_buff *pkt)
+{
+ unsigned int req_sz;
+ int err;
+
+ /* Single skb use the standard mmc interface */
+ req_sz = pkt->len + 3;
+ req_sz &= (uint)~3;
+
+ err = sdio_memcpy_toio(sdiodev->func[fn], addr,
+ ((u8 *)(pkt->data)), req_sz);
+
+ if (err == -ENOMEDIUM)
+ brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
+
return err;
}

@@ -644,7 +662,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
if (err)
goto done;

- err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr, pkt);

done:
return err;
@@ -666,13 +684,13 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
goto done;

if (pktq->qlen == 1)
- err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr,
+ err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
pktq->next);
else if (!sdiodev->sg_support) {
glom_skb = brcmu_pkt_buf_get_skb(totlen);
if (!glom_skb)
return -ENOMEM;
- err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr,
+ err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
glom_skb);
if (err)
goto done;
@@ -697,6 +715,7 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
int err;

mypkt = brcmu_pkt_buf_get_skb(nbytes);
+
if (!mypkt) {
brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n",
nbytes);
@@ -708,10 +727,10 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
err = brcmf_sdiod_addrprep(sdiodev, &addr);

if (!err)
- err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true, addr,
- mypkt);
+ err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);

brcmu_pkt_buf_free_skb(mypkt);
+
return err;

}
@@ -731,7 +750,7 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,

if (pktq->qlen == 1 || !sdiodev->sg_support)
skb_queue_walk(pktq, skb) {
- err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true,
+ err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2,
addr, skb);
if (err)
break;
@@ -784,10 +803,17 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
sdaddr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

skb_put(pkt, dsize);
- if (write)
+
+ if (write) {
memcpy(pkt->data, data, dsize);
- err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_1, write,
- sdaddr, pkt);
+ err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_1,
+ sdaddr, pkt);
+ }
+ else {
+ err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_1,
+ sdaddr, pkt);
+ }
+
if (err) {
brcmf_err("membytes transfer failed\n");
break;
--
2.11.0

2017-07-19 19:13:27

by Ian Molton

[permalink] [raw]
Subject: [PATCH 12/34] brcmfmac: Replace old IO functions with simpler ones.

Primarily this patch removes:

brcmf_sdiod_f0_writeb()
brcmf_sdiod_reg_write()
brcmf_sdiod_reg_read()

Since we no longer use the quirky method of deciding which function to
address via the address being accessed, take the opportunity to rename
some IO functions more in line with common kernel code.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 165 +++------------------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 157 +++++++++-----------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 27 ++--
3 files changed, 111 insertions(+), 238 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 013b9b852d81..13f20b58d34e 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -137,27 +137,25 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
if (sdiodev->bus_if->chip == BRCM_CC_43362_CHIP_ID) {
/* assign GPIO to SDIO core */
addr = CORE_CC_REG(SI_ENUM_BASE, gpiocontrol);
- gpiocontrol = brcmf_sdiod_regrl(sdiodev, addr, &ret);
+ gpiocontrol = brcmf_sdiod_readl(sdiodev, addr, &ret);
gpiocontrol |= 0x2;
- brcmf_sdiod_regwl(sdiodev, addr, gpiocontrol, &ret);
+ brcmf_sdiod_writel(sdiodev, addr, gpiocontrol, &ret);

- brcmf_sdiod_regwb(sdiodev, SBSDIO_GPIO_SELECT, 0xf,
- &ret);
- brcmf_sdiod_regwb(sdiodev, SBSDIO_GPIO_OUT, 0, &ret);
- brcmf_sdiod_regwb(sdiodev, SBSDIO_GPIO_EN, 0x2, &ret);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_GPIO_SELECT, 0xf, &ret);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_GPIO_OUT, 0, &ret);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_GPIO_EN, 0x2, &ret);
}

/* must configure SDIO_CCCR_IENx to enable irq */
- data = brcmf_sdiod_regrb(sdiodev, SDIO_CCCR_IENx, &ret);
+ data = brcmf_sdiod_func0_rb(sdiodev, SDIO_CCCR_IENx, &ret);
data |= 1 << SDIO_FUNC_1 | 1 << SDIO_FUNC_2 | 1;
- brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_IENx, data, &ret);
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, data, &ret);

/* redirect, configure and enable io for interrupt signal */
data = SDIO_SEPINT_MASK | SDIO_SEPINT_OE;
if (pdata->oob_irq_flags & IRQF_TRIGGER_HIGH)
data |= SDIO_SEPINT_ACT_HI;
- brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_BRCM_SEPINT, data, &ret);
-
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, data, &ret);
sdio_release_host(sdiodev->func[1]);
} else {
brcmf_dbg(SDIO, "Entering\n");
@@ -183,8 +181,8 @@ void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev)

pdata = &sdiodev->settings->bus.sdio;
sdio_claim_host(sdiodev->func[1]);
- brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL);
- brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_IENx, 0, NULL);
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL);
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, 0, NULL);
sdio_release_host(sdiodev->func[1]);

sdiodev->oob_irq_requested = false;
@@ -242,7 +240,7 @@ brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;

for ( i = 0 ; i < 3 && !err ; i++, addr >>= 8 )
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr & 0xff,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr & 0xff,
&err);

return err;
@@ -268,124 +266,15 @@ brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, u32 *addr)
return 0;
}

-static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func, u8 byte, uint regaddr)
-{
- int err_ret;
-
- /*
- * Can only directly write to some F0 registers.
- * Handle CCCR_IENx and CCCR_ABORT command
- * as a special case.
- */
- if ((regaddr == SDIO_CCCR_ABORT) ||
- (regaddr == SDIO_CCCR_IENx))
- sdio_writeb(func, byte, regaddr, &err_ret);
- else
- sdio_f0_writeb(func, byte, regaddr, &err_ret);
-
- return err_ret;
-}
-
-static int brcmf_sdiod_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr,
- u8 regsz, void *data)
-{
- int ret;
-
- /*
- * figure out how to read the register based on address range
- * 0x00 ~ 0x7FF: function 0 CCCR and FBR
- * 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
- * The rest: function 1 silicon backplane core registers
- * f0 writes must be bytewise
- */
-
- if ((addr & ~REG_F0_REG_MASK) == 0) {
- if (WARN_ON(regsz > 1))
- return -EINVAL;
- ret = brcmf_sdiod_f0_writeb(sdiodev->func[0], *(u8 *)data, addr);
- }
- else {
- switch (regsz) {
- case 1:
- sdio_writeb(sdiodev->func[1], *(u8 *)data, addr, &ret);
- break;
- case 4:
- ret = brcmf_sdiod_addrprep(sdiodev, &addr);
- if (ret)
- goto done;
-
- sdio_writel(sdiodev->func[1], *(u32 *)data, addr, &ret);
- break;
- default:
- BUG();
- ret = -EINVAL;
- break;
- }
- }
-
-done:
- return ret;
-}
-
-static int brcmf_sdiod_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr,
- u8 regsz, void *data)
-{
- int ret;
-
- /*
- * figure out how to read the register based on address range
- * 0x00 ~ 0x7FF: function 0 CCCR and FBR
- * 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
- * The rest: function 1 silicon backplane core registers
- * f0 reads must be bytewise
- */
- if ((addr & ~REG_F0_REG_MASK) == 0) {
- if (WARN_ON(regsz > 1))
- return -EINVAL;
- *(u8 *)data = sdio_f0_readb(sdiodev->func[0], addr, &ret);
- }
- else {
- switch (regsz) {
- case 1:
- *(u8 *)data = sdio_readb(sdiodev->func[1], addr, &ret);
- break;
- case 4:
- ret = brcmf_sdiod_addrprep(sdiodev, &addr);
- if (ret)
- goto done;
-
- *(u32 *)data = sdio_readl(sdiodev->func[1], addr, &ret);
- break;
- default:
- BUG();
- ret = -EINVAL;
- break;
- }
- }
-
-done:
- return ret;
-}
-
-u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
-{
- u8 data = 0;
- int retval;
-
- retval = brcmf_sdiod_reg_read(sdiodev, addr, 1, &data);
-
- if (ret)
- *ret = retval;
-
- return data;
-}
-
-u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
+u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
{
u32 data = 0;
int retval;

- retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);
+ retval = brcmf_sdiod_addrprep(sdiodev, &addr);
+
+ if (!retval)
+ data = sdio_readl(sdiodev->func[1], addr, &retval);

if (ret)
*ret = retval;
@@ -393,23 +282,15 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
return data;
}

-void brcmf_sdiod_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
- u8 data, int *ret)
-{
- int retval;
-
- retval = brcmf_sdiod_reg_write(sdiodev, addr, 1, &data);
-
- if (ret)
- *ret = retval;
-}
-
-void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
+void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
u32 data, int *ret)
{
int retval;

- retval = brcmf_sdiod_reg_write(sdiodev, addr, 4, &data);
+ retval = brcmf_sdiod_addrprep(sdiodev, &addr);
+
+ if (!retval)
+ sdio_writel(sdiodev->func[1], data, addr, &retval);

if (ret)
*ret = retval;
@@ -848,8 +729,8 @@ int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn)
{
brcmf_dbg(SDIO, "Enter\n");

- /* issue abort cmd52 command through F0 */
- brcmf_sdiod_reg_write(sdiodev, SDIO_CCCR_ABORT, 1, &fn);
+ /* Issue abort cmd52 command through F0 */
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_ABORT, fn, NULL);

brcmf_dbg(SDIO, "Exit\n");
return 0;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index fbcbb4325936..152905e985d2 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -666,7 +666,7 @@ static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset)
int ret;

core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
- *regvar = brcmf_sdiod_regrl(bus->sdiodev, core->base + offset, &ret);
+ *regvar = brcmf_sdiod_readl(bus->sdiodev, core->base + offset, &ret);

return ret;
}
@@ -677,7 +677,7 @@ static int w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset)
int ret;

core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
- brcmf_sdiod_regwl(bus->sdiodev, core->base + reg_offset, regval, &ret);
+ brcmf_sdiod_writel(bus->sdiodev, core->base + reg_offset, regval, &ret);

return ret;
}
@@ -694,8 +694,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)

wr_val = (on << SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT);
/* 1st KSO write goes to AOS wake up core if device is asleep */
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
- wr_val, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err);

if (on) {
/* device WAKEUP through KSO:
@@ -721,8 +720,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
* just one write attempt may fail,
* read it back until it matches written value
*/
- rd_val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
- &err);
+ rd_val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
if (!err) {
if ((rd_val & bmask) == cmp_val)
break;
@@ -732,8 +730,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
if (err && (err_cnt++ > BRCMF_SDIO_MAX_ACCESS_ERRORS))
break;
udelay(KSO_WAIT_US);
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
- wr_val, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err);
} while (try_cnt++ < MAX_KSO_ATTEMPTS);

if (try_cnt > 2)
@@ -769,16 +766,14 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
clkreq =
bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ;

- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
- clkreq, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
if (err) {
brcmf_err("HT Avail request error: %d\n", err);
return -EBADE;
}

/* Check current status */
- clkctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_FUNC1_CHIPCLKCSR, &err);
+ clkctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
if (err) {
brcmf_err("HT Avail read error: %d\n", err);
return -EBADE;
@@ -787,8 +782,8 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
/* Go to pending and await interrupt if appropriate */
if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) {
/* Allow only clock-available interrupt */
- devctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
if (err) {
brcmf_err("Devctl error setting CA: %d\n",
err);
@@ -796,26 +791,26 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
}

devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ &err);
brcmf_dbg(SDIO, "CLKCTL: set PENDING\n");
bus->clkstate = CLK_PENDING;

return 0;
} else if (bus->clkstate == CLK_PENDING) {
/* Cancel CA-only interrupt filter */
- devctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ &err);
}

/* Otherwise, wait here (polling) for HT Avail */
timeout = jiffies +
msecs_to_jiffies(PMU_MAX_TRANSITION_DLY/1000);
while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) {
- clkctl = brcmf_sdiod_regrb(bus->sdiodev,
+ clkctl = brcmf_sdiod_readb(bus->sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
&err);
if (time_after(jiffies, timeout))
@@ -849,16 +844,15 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)

if (bus->clkstate == CLK_PENDING) {
/* Cancel CA-only interrupt filter */
- devctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ &err);
}

bus->clkstate = CLK_SDONLY;
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
- clkreq, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
brcmf_dbg(SDIO, "CLKCTL: turned OFF\n");
if (err) {
brcmf_err("Failed access turning clock off: %d\n",
@@ -948,12 +942,12 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)

/* Going to sleep */
if (sleep) {
- clkcsr = brcmf_sdiod_regrb(bus->sdiodev,
+ clkcsr = brcmf_sdiod_readb(bus->sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
&err);
if ((clkcsr & SBSDIO_CSR_MASK) == 0) {
brcmf_dbg(SDIO, "no clock, set ALP\n");
- brcmf_sdiod_regwb(bus->sdiodev,
+ brcmf_sdiod_writeb(bus->sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
SBSDIO_ALP_AVAIL_REQ, &err);
}
@@ -1170,16 +1164,13 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
if (abort)
brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2);

- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL,
- SFC_RF_TERM, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, &err);
bus->sdcnt.f1regdata++;

/* Wait until the packet has been flushed (device/FIFO stable) */
for (lastrbc = retries = 0xffff; retries > 0; retries--) {
- hi = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_FUNC1_RFRAMEBCHI, &err);
- lo = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_FUNC1_RFRAMEBCLO, &err);
+ hi = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCHI, &err);
+ lo = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCLO, &err);
bus->sdcnt.f1regdata += 2;

if ((hi == 0) && (lo == 0))
@@ -1221,12 +1212,12 @@ static void brcmf_sdio_txfail(struct brcmf_sdio *bus)
bus->sdcnt.tx_sderrs++;

brcmf_sdiod_abort(sdiodev, SDIO_FUNC_2);
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, NULL);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, NULL);
bus->sdcnt.f1regdata++;

for (i = 0; i < 3; i++) {
- hi = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_WFRAMEBCHI, NULL);
- lo = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_WFRAMEBCLO, NULL);
+ hi = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_WFRAMEBCHI, NULL);
+ lo = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_WFRAMEBCLO, NULL);
bus->sdcnt.f1regdata += 2;
if ((hi == 0) && (lo == 0))
break;
@@ -2437,10 +2428,10 @@ static void brcmf_sdio_bus_stop(struct device *dev)
bus->hostintmask = 0;

/* Force backplane clocks to assure F2 interrupt propagates */
- saveclk = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
+ saveclk = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
&err);
if (!err)
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
(saveclk | SBSDIO_FORCE_HT), &err);
if (err)
brcmf_err("Failed to force clock for F2: err %d\n",
@@ -2500,7 +2491,7 @@ static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)
buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
addr = buscore->base + offsetof(struct sdpcmd_regs, intstatus);

- val = brcmf_sdiod_regrl(bus->sdiodev, addr, &ret);
+ val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret);
bus->sdcnt.f1regdata++;
if (ret != 0)
return ret;
@@ -2510,7 +2501,7 @@ static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)

/* Clear interrupts */
if (val) {
- brcmf_sdiod_regwl(bus->sdiodev, addr, val, &ret);
+ brcmf_sdiod_writel(bus->sdiodev, addr, val, &ret);
bus->sdcnt.f1regdata++;
atomic_or(val, &bus->intstatus);
}
@@ -2536,23 +2527,21 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)

#ifdef DEBUG
/* Check for inconsistent device control */
- devctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL, &err);
#endif /* DEBUG */

/* Read CSR, if clock on switch to AVAIL, else ignore */
- clkctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_FUNC1_CHIPCLKCSR, &err);
+ clkctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);

brcmf_dbg(SDIO, "DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n",
devctl, clkctl);

if (SBSDIO_HTAV(clkctl)) {
- devctl = brcmf_sdiod_regrb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ &err);
bus->clkstate = CLK_AVAIL;
}
}
@@ -3338,21 +3327,21 @@ static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)

brcmf_dbg(TRACE, "Enter\n");

- val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err);
+ val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err);
if (err) {
brcmf_err("error reading SBSDIO_FUNC1_WAKEUPCTRL\n");
return;
}

val |= 1 << SBSDIO_FUNC1_WCTRL_HTWAIT_SHIFT;
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_WAKEUPCTRL\n");
return;
}

/* Add CMD14 Support */
- brcmf_sdiod_regwb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP,
+ brcmf_sdiod_func0_wb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP,
(SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT |
SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT),
&err);
@@ -3361,8 +3350,8 @@ static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)
return;
}

- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
- SBSDIO_FORCE_HT, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, SBSDIO_FORCE_HT,
+ &err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_CHIPCLKCSR\n");
return;
@@ -3385,7 +3374,7 @@ static int brcmf_sdio_kso_init(struct brcmf_sdio *bus)
if (brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV)->rev < 12)
return 0;

- val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
+ val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
if (err) {
brcmf_err("error reading SBSDIO_FUNC1_SLEEPCSR\n");
return err;
@@ -3394,8 +3383,7 @@ static int brcmf_sdio_kso_init(struct brcmf_sdio *bus)
if (!(val & SBSDIO_FUNC1_SLEEPCSR_KSO_MASK)) {
val |= (SBSDIO_FUNC1_SLEEPCSR_KSO_EN <<
SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT);
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
- val, &err);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, val, &err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_SLEEPCSR\n");
return err;
@@ -3556,7 +3544,7 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
u8 devpend;

sdio_claim_host(bus->sdiodev->func[1]);
- devpend = brcmf_sdiod_regrb(bus->sdiodev,
+ devpend = brcmf_sdiod_func0_rb(bus->sdiodev,
SDIO_CCCR_INTx,
NULL);
sdio_release_host(bus->sdiodev->func[1]);
@@ -3696,12 +3684,12 @@ brcmf_sdio_drivestrengthinit(struct brcmf_sdio_dev *sdiodev,
}
}
addr = CORE_CC_REG(pmu->base, chipcontrol_addr);
- brcmf_sdiod_regwl(sdiodev, addr, 1, NULL);
- cc_data_temp = brcmf_sdiod_regrl(sdiodev, addr, NULL);
+ brcmf_sdiod_writel(sdiodev, addr, 1, NULL);
+ cc_data_temp = brcmf_sdiod_readl(sdiodev, addr, NULL);
cc_data_temp &= ~str_mask;
drivestrength_sel <<= str_shift;
cc_data_temp |= drivestrength_sel;
- brcmf_sdiod_regwl(sdiodev, addr, cc_data_temp, NULL);
+ brcmf_sdiod_writel(sdiodev, addr, cc_data_temp, NULL);

brcmf_dbg(INFO, "SDIO: %d mA (req=%d mA) drive strength selected, set to 0x%08x\n",
str_tab[i].strength, drivestrength, cc_data_temp);
@@ -3716,7 +3704,7 @@ static int brcmf_sdio_buscoreprep(void *ctx)

/* Try forcing SDIO core to do ALPAvail request only */
clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ;
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err);
if (err) {
brcmf_err("error writing for HT off\n");
return err;
@@ -3724,8 +3712,7 @@ static int brcmf_sdio_buscoreprep(void *ctx)

/* If register supported, wait for ALPAvail and then force ALP */
/* This may take up to 15 milliseconds */
- clkval = brcmf_sdiod_regrb(sdiodev,
- SBSDIO_FUNC1_CHIPCLKCSR, NULL);
+ clkval = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, NULL);

if ((clkval & ~SBSDIO_AVBITS) != clkset) {
brcmf_err("ChipClkCSR access: wrote 0x%02x read 0x%02x\n",
@@ -3733,8 +3720,7 @@ static int brcmf_sdio_buscoreprep(void *ctx)
return -EACCES;
}

- SPINWAIT(((clkval = brcmf_sdiod_regrb(sdiodev,
- SBSDIO_FUNC1_CHIPCLKCSR, NULL)),
+ SPINWAIT(((clkval = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, NULL)),
!SBSDIO_ALPAV(clkval)),
PMU_MAX_TRANSITION_DLY);
if (!SBSDIO_ALPAV(clkval)) {
@@ -3744,11 +3730,11 @@ static int brcmf_sdio_buscoreprep(void *ctx)
}

clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP;
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err);
udelay(65);

/* Also, disable the extra SDIO pull-ups */
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SDIOPULLUP, 0, NULL);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SDIOPULLUP, 0, NULL);

return 0;
}
@@ -3763,7 +3749,7 @@ static void brcmf_sdio_buscore_activate(void *ctx, struct brcmf_chip *chip,
/* clear all interrupts */
core = brcmf_chip_get_core(chip, BCMA_CORE_SDIO_DEV);
reg_addr = core->base + offsetof(struct sdpcmd_regs, intstatus);
- brcmf_sdiod_regwl(sdiodev, reg_addr, 0xFFFFFFFF, NULL);
+ brcmf_sdiod_writel(sdiodev, reg_addr, 0xFFFFFFFF, NULL);

if (rstvec)
/* Write reset vector to address 0 */
@@ -3776,7 +3762,7 @@ static u32 brcmf_sdio_buscore_read32(void *ctx, u32 addr)
struct brcmf_sdio_dev *sdiodev = ctx;
u32 val, rev;

- val = brcmf_sdiod_regrl(sdiodev, addr, NULL);
+ val = brcmf_sdiod_readl(sdiodev, addr, NULL);
if ((sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 ||
sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) {
@@ -3793,7 +3779,7 @@ static void brcmf_sdio_buscore_write32(void *ctx, u32 addr, u32 val)
{
struct brcmf_sdio_dev *sdiodev = ctx;

- brcmf_sdiod_regwl(sdiodev, addr, val, NULL);
+ brcmf_sdiod_writel(sdiodev, addr, val, NULL);
}

static const struct brcmf_buscore_ops brcmf_sdio_buscore_ops = {
@@ -3817,18 +3803,16 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
sdio_claim_host(sdiodev->func[1]);

pr_debug("F1 signature read @0x18000000=0x%4x\n",
- brcmf_sdiod_regrl(sdiodev, SI_ENUM_BASE, NULL));
+ brcmf_sdiod_readl(sdiodev, SI_ENUM_BASE, NULL));

/*
* Force PLL off until brcmf_chip_attach()
* programs PLL control regs
*/

- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
- BRCMF_INIT_CLKCTL1, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, BRCMF_INIT_CLKCTL1, &err);
if (!err)
- clkctl = brcmf_sdiod_regrb(sdiodev,
- SBSDIO_FUNC1_CHIPCLKCSR, &err);
+ clkctl = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);

if (err || ((clkctl & ~SBSDIO_AVBITS) != BRCMF_INIT_CLKCTL1)) {
brcmf_err("ChipClkCSR access: err %d wrote 0x%02x read 0x%02x\n",
@@ -3888,25 +3872,25 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
brcmf_sdio_drivestrengthinit(sdiodev, bus->ci, drivestrength);

/* Set card control so an SDIO card reset does a WLAN backplane reset */
- reg_val = brcmf_sdiod_regrb(sdiodev, SDIO_CCCR_BRCM_CARDCTRL, &err);
+ reg_val = brcmf_sdiod_func0_rb(sdiodev, SDIO_CCCR_BRCM_CARDCTRL, &err);
if (err)
goto fail;

reg_val |= SDIO_CCCR_BRCM_CARDCTRL_WLANRESET;

- brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_BRCM_CARDCTRL, reg_val, &err);
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_CARDCTRL, reg_val, &err);
if (err)
goto fail;

/* set PMUControl so a backplane reset does PMU state reload */
reg_addr = CORE_CC_REG(brcmf_chip_get_pmu(bus->ci)->base, pmucontrol);
- reg_val = brcmf_sdiod_regrl(sdiodev, reg_addr, &err);
+ reg_val = brcmf_sdiod_readl(sdiodev, reg_addr, &err);
if (err)
goto fail;

reg_val |= (BCMA_CC_PMU_CTL_RES_RELOAD << BCMA_CC_PMU_CTL_RES_SHIFT);

- brcmf_sdiod_regwl(sdiodev, reg_addr, reg_val, &err);
+ brcmf_sdiod_writel(sdiodev, reg_addr, reg_val, &err);
if (err)
goto fail;

@@ -4027,9 +4011,9 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
goto release;

/* Force clocks on backplane to be sure F2 interrupt propagates */
- saveclk = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
+ saveclk = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
if (!err) {
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
(saveclk | SBSDIO_FORCE_HT), &err);
}
if (err) {
@@ -4052,7 +4036,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
w_sdreg32(bus, bus->hostintmask,
offsetof(struct sdpcmd_regs, hostintmask));

- brcmf_sdiod_regwb(sdiodev, SBSDIO_WATERMARK, 8, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
} else {
/* Disable F2 again */
sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
@@ -4063,8 +4047,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
brcmf_sdio_sr_init(bus);
} else {
/* Restore previous clock setting */
- brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
- saveclk, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, saveclk, &err);
}

if (err == 0) {
@@ -4204,7 +4187,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
bus->rxflow = false;

/* Done with backplane-dependent accesses, can drop clock... */
- brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);
+ brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);

sdio_release_host(bus->sdiodev->func[1]);

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index 1e4b4760159f..2f32c9270eaa 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -50,6 +50,7 @@
#define SBSDIO_NUM_FUNCTION 3

/* function 0 vendor specific CCCR registers */
+
#define SDIO_CCCR_BRCM_CARDCAP 0xf0
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT 0x02
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT 0x04
@@ -131,8 +132,6 @@
/* with b15, maps to 32-bit SB access */
#define SBSDIO_SB_ACCESS_2_4B_FLAG 0x08000

-/* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
-
/* Address bits from SBADDR regs */
#define SBSDIO_SBWINDOW_MASK 0xffff8000

@@ -293,13 +292,23 @@ struct sdpcmd_regs {
int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev);
void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev);

-/* sdio device register access interface */
-u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
-u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
-void brcmf_sdiod_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr, u8 data,
- int *ret);
-void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr, u32 data,
- int *ret);
+/* SDIO device register access interface */
+/* Functions for accessing SDIO Function 0 */
+#define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
+ sdio_readb((sdiodev)->func[0], (addr), (r))
+
+#define brcmf_sdiod_func0_wb(sdiodev, addr, v, ret) \
+ sdio_writeb((sdiodev)->func[0], (v), (addr), (ret))
+
+/* Functions for accessing SDIO Function 1 */
+#define brcmf_sdiod_readb(sdiodev, addr, r) \
+ sdio_readb((sdiodev)->func[1], (addr), (r))
+
+#define brcmf_sdiod_writeb(sdiodev, addr, v, ret) \
+ sdio_writeb((sdiodev)->func[1], (v), (addr), (ret))
+
+u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
+void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr, u32 data, int *ret);

/* Buffer transfer to/from device (client) core via cmd53.
* fn: function number
--
2.11.0

2017-07-19 19:15:50

by Ian Molton

[permalink] [raw]
Subject: [PATCH 15/34] brcmfamc: remove unnecessary call to brcmf_sdiod_set_backplane_window()

All functions that might require the window address changing call
brcmf_sdiod_set_backplane_window() prior to access. Thus resetting
the window is not required.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index eb388b69418a..ab015bad02f2 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -723,11 +723,6 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

dev_kfree_skb(pkt);

- /* Return the window to backplane enumeration space for core access */
- if (brcmf_sdiod_set_backplane_window(sdiodev, sdiodev->sbwad))
- brcmf_err("FAILED to set window back to 0x%x\n",
- sdiodev->sbwad);
-
sdio_release_host(sdiodev->func[1]);

return err;
--
2.11.0

2017-07-19 19:15:44

by Ian Molton

[permalink] [raw]
Subject: [PATCH 31/34] brcmfmac: Remove func0 from function array

Linux doesnt pass you func0 as a function when probing - instead
providing specific access functions to read/write it.

This prepares for a patch to remove the actual array entry itself.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 5 +----
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 4 ++--
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 13 ++++++-------
3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 42b09a301f5f..89cf71d98cee 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -1021,8 +1021,7 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
/* store refs to functions used. mmc_card does
* not hold the F0 function pointer.
*/
- sdiodev->func[0] = kmemdup(func, sizeof(*func), GFP_KERNEL);
- sdiodev->func[0]->num = 0;
+ sdiodev->func[0] = NULL;
sdiodev->func[1] = func->card->sdio_func[0];
sdiodev->func[2] = func;

@@ -1048,7 +1047,6 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
fail:
dev_set_drvdata(&func->dev, NULL);
dev_set_drvdata(&sdiodev->func[1]->dev, NULL);
- kfree(sdiodev->func[0]);
kfree(sdiodev);
kfree(bus_if);
return err;
@@ -1081,7 +1079,6 @@ static void brcmf_ops_sdio_remove(struct sdio_func *func)
dev_set_drvdata(&sdiodev->func[2]->dev, NULL);

kfree(bus_if);
- kfree(sdiodev->func[0]);
kfree(sdiodev);
}

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 2a52f48bdddc..9b8bd870c1fc 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -3751,8 +3751,8 @@ static u32 brcmf_sdio_buscore_read32(void *ctx, u32 addr)
/* Force 4339 chips over rev2 to use the same ID */
/* This is borderline tolerable whilst there is only two exceptions */
/* But could be handled better */
- if ((sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 ||
- sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
+ if ((sdiodev->func[1]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 ||
+ sdiodev->func[1]->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) {

rev = (val & CID_REV_MASK) >> CID_REV_SHIFT;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index d0dd69454bbd..cae21d14042d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -21,7 +21,9 @@
#include <linux/firmware.h>
#include "firmware.h"

-#define SDIO_FUNC_0 0
+/* Maximum number of I/O funcs */
+#define NUM_SDIO_FUNCS 3
+
#define SDIO_FUNC_1 1
#define SDIO_FUNC_2 2

@@ -39,9 +41,6 @@
#define INTR_STATUS_FUNC1 0x2
#define INTR_STATUS_FUNC2 0x4

-/* Maximum number of I/O funcs */
-#define SDIOD_MAX_IOFUNCS 7
-
/* mask of register map */
#define REG_F0_REG_MASK 0x7FF
#define REG_F1_MISC_MASK 0x1FFFF
@@ -175,7 +174,7 @@ struct brcmf_sdio;
struct brcmf_sdiod_freezer;

struct brcmf_sdio_dev {
- struct sdio_func *func[SDIO_MAX_FUNCS];
+ struct sdio_func *func[NUM_SDIO_FUNCS];
u8 num_funcs; /* Supported funcs on client */
u32 sbwad; /* Save backplane window address */
struct brcmf_core *cc_core; /* chipcommon core info struct */
@@ -297,10 +296,10 @@ void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev);
/* SDIO device register access interface */
/* Functions for accessing SDIO Function 0 */
#define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
- sdio_f0_readb((sdiodev)->func[0], (addr), (r))
+ sdio_f0_readb((sdiodev)->func[1], (addr), (r))

#define brcmf_sdiod_func0_wb(sdiodev, addr, v, ret) \
- sdio_f0_writeb((sdiodev)->func[0], (v), (addr), (ret))
+ sdio_f0_writeb((sdiodev)->func[1], (v), (addr), (ret))

/* Functions for accessing SDIO Function 1 */
#define brcmf_sdiod_readb(sdiodev, addr, r) \
--
2.11.0

2017-07-19 19:12:10

by Ian Molton

[permalink] [raw]
Subject: [PATCH 24/34] brcmfmac: Rename chip.ctx -> chip.bus_priv

This driver uses the label ctx like its going out of fashion.

Lets rename this usage of it so that its easier to see whats going on.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/chip.c | 24 +++++++++++-----------
.../wireless/broadcom/brcm80211/brcmfmac/chip.h | 16 +++++++--------
2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index bab1bb3e99ae..ae21f16b31de 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -225,18 +225,18 @@ struct sbsocramregs {

static inline int brcmf_readl(struct brcmf_chip *chip, u32 addr)
{
- return chip->ops->read32(chip->ctx, addr);
+ return chip->ops->read32(chip->bus_priv, addr);
}

static inline void brcmf_writel(struct brcmf_chip *chip, u32 addr, u32 v)
{
- chip->ops->write32(chip->ctx, addr, v);
+ chip->ops->write32(chip->bus_priv, addr, v);
}

static inline void brcmf_writelp(struct brcmf_chip *chip, u32 addr, u32 v)
{
- chip->ops->write32(chip->ctx, addr, v);
- chip->ops->read32(chip->ctx, addr);
+ chip->ops->write32(chip->bus_priv, addr, v);
+ chip->ops->read32(chip->bus_priv, addr);
}

static void brcmf_clear_bits(struct brcmf_chip *ci, u32 reg, u32 bits)
@@ -1025,7 +1025,7 @@ static int brcmf_chip_probe(struct brcmf_chip *ci)
* specific reset at this point.
*/
if (ci->ops->reset) {
- ci->ops->reset(ci->ctx, ci);
+ ci->ops->reset(ci->bus_priv, ci);
brcmf_chip_set_passive(ci);
}

@@ -1097,12 +1097,12 @@ static int brcmf_chip_setup(struct brcmf_chip *chip)

/* execute bus core specific setup */
if (chip->ops->setup)
- ret = chip->ops->setup(chip->ctx, chip);
+ ret = chip->ops->setup(chip->bus_priv, chip);

return ret;
}

-struct brcmf_chip *brcmf_chip_attach(void *ctx,
+struct brcmf_chip *brcmf_chip_attach(void *bus_priv,
const struct brcmf_buscore_ops *ops)
{
struct brcmf_chip *chip;
@@ -1126,9 +1126,9 @@ struct brcmf_chip *brcmf_chip_attach(void *ctx,
INIT_LIST_HEAD(&chip->cores);
chip->num_cores = 0;
chip->ops = ops;
- chip->ctx = ctx;
+ chip->bus_priv = bus_priv;

- err = ops->prepare(ctx);
+ err = ops->prepare(bus_priv);
if (err < 0)
goto fail;

@@ -1249,7 +1249,7 @@ static bool brcmf_chip_cm3_set_active(struct brcmf_chip *chip)
return false;
}

- chip->ops->activate(chip->ctx, chip, 0);
+ chip->ops->activate(chip->bus_priv, chip, 0);

core = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CM3);
brcmf_chip_resetcore(core, 0, 0, 0);
@@ -1275,7 +1275,7 @@ static bool brcmf_chip_cr4_set_active(struct brcmf_chip *chip, u32 rstvec)
{
struct brcmf_core *core;

- chip->ops->activate(chip->ctx, chip, rstvec);
+ chip->ops->activate(chip->bus_priv, chip, rstvec);

/* restore ARM */
core = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CR4);
@@ -1302,7 +1302,7 @@ static bool brcmf_chip_ca7_set_active(struct brcmf_chip *chip, u32 rstvec)
{
struct brcmf_core *core;

- chip->ops->activate(chip->ctx, chip, rstvec);
+ chip->ops->activate(chip->bus_priv, chip, rstvec);

/* restore ARM */
core = brcmf_chip_get_core(chip, BCMA_CORE_ARM_CA7);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
index 0babb328d155..8698abfb806e 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
@@ -50,7 +50,7 @@ struct brcmf_chip {
void (*resetcore)(struct brcmf_core *core, u32 prereset, u32 reset,
u32 postreset);

- void *ctx;
+ void *bus_priv;

u32 chip;
u32 chiprev;
@@ -94,15 +94,15 @@ struct brcmf_core {
* The callback should use the provided @rstvec when non-zero.
*/
struct brcmf_buscore_ops {
- u32 (*read32)(void *ctx, u32 addr);
- void (*write32)(void *ctx, u32 addr, u32 value);
- int (*prepare)(void *ctx);
- int (*reset)(void *ctx, struct brcmf_chip *chip);
- int (*setup)(void *ctx, struct brcmf_chip *chip);
- void (*activate)(void *ctx, struct brcmf_chip *chip, u32 rstvec);
+ u32 (*read32)(void *bus_priv, u32 addr);
+ void (*write32)(void *bus_priv, u32 addr, u32 value);
+ int (*prepare)(void *bus_priv);
+ int (*reset)(void *bus_priv, struct brcmf_chip *chip);
+ int (*setup)(void *bus_priv, struct brcmf_chip *chip);
+ void (*activate)(void *bus_priv, struct brcmf_chip *chip, u32 rstvec);
};

-struct brcmf_chip *brcmf_chip_attach(void *ctx,
+struct brcmf_chip *brcmf_chip_attach(void *bus_priv,
const struct brcmf_buscore_ops *ops);
void brcmf_chip_detach(struct brcmf_chip *chip);
struct brcmf_core *brcmf_chip_get_core(struct brcmf_chip *chip, u16 coreid);
--
2.11.0

2017-07-19 19:08:36

by Ian Molton

[permalink] [raw]
Subject: [PATCH 01/34] brcmfmac: Fix parameter order in brcmf_sdiod_f0_writeb()

All the other IO functions are the other way round in this
driver. Make this one match.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 984c1d0560b1..1acbaaf0f5c9 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -230,8 +230,7 @@ void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
sdiodev->state = state;
}

-static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func,
- uint regaddr, u8 byte)
+static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func, u8 byte, uint regaddr)
{
int err_ret;

@@ -269,8 +268,7 @@ static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
if (fn)
sdio_writeb(func, *(u8 *)data, addr, &ret);
else
- ret = brcmf_sdiod_f0_writeb(func, addr,
- *(u8 *)data);
+ ret = brcmf_sdiod_f0_writeb(func, *(u8 *)data, addr);
} else {
if (fn)
*(u8 *)data = sdio_readb(func, addr, &ret);
--
2.11.0

2017-07-19 19:15:48

by Ian Molton

[permalink] [raw]
Subject: [PATCH 34/34] brcmfmac: Reduce the noise from repeatedly dereferencing common pointers

This introduces no functional changes, but makes the code drastically more
readable, reducing the amount of dereferencing performed inside functions
throughout the SDIO core.

For example, reduce:
sdio_release_host(bus->sdiodev->func1);
to:
sdio_release_host(func1);

Fixup a few inconsistently named pointers whilst we are at it ie.

sdiod -> sdiodev

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 139 ++++----
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 380 +++++++++++----------
2 files changed, 285 insertions(+), 234 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index d9fe2faf2b04..3319deb0e889 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -105,6 +105,8 @@ static void brcmf_sdiod_dummy_irqhandler(struct sdio_func *func)
int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
{
struct brcmfmac_sdio_pd *pdata;
+ struct sdio_func *func1 = sdiodev->func1;
+ struct sdio_func *func2 = sdiodev->func2;
int ret = 0;
u8 data;
u32 addr, gpiocontrol;
@@ -118,7 +120,7 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)

ret = request_irq(pdata->oob_irq_nr, brcmf_sdiod_oob_irqhandler,
pdata->oob_irq_flags, "brcmf_oob_intr",
- &sdiodev->func1->dev);
+ &func1->dev);
if (ret != 0) {
brcmf_err("request_irq failed %d\n", ret);
return ret;
@@ -132,7 +134,7 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
}
sdiodev->irq_wake = true;

- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);

if (sdiodev->bus_if->chip == BRCM_CC_43362_CHIP_ID) {
/* assign GPIO to SDIO core */
@@ -156,13 +158,13 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
if (pdata->oob_irq_flags & IRQF_TRIGGER_HIGH)
data |= SDIO_SEPINT_ACT_HI;
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, data, &ret);
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);
} else {
brcmf_dbg(SDIO, "Entering\n");
- sdio_claim_host(sdiodev->func1);
- sdio_claim_irq(sdiodev->func1, brcmf_sdiod_ib_irqhandler);
- sdio_claim_irq(sdiodev->func2, brcmf_sdiod_dummy_irqhandler);
- sdio_release_host(sdiodev->func1);
+ sdio_claim_host(func1);
+ sdio_claim_irq(func1, brcmf_sdiod_ib_irqhandler);
+ sdio_claim_irq(func2, brcmf_sdiod_dummy_irqhandler);
+ sdio_release_host(func1);
sdiodev->sd_irq_requested = true;
}

@@ -171,6 +173,8 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)

void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev)
{
+ struct sdio_func *func1 = sdiodev->func1;
+ struct sdio_func *func2 = sdiodev->func2;

brcmf_dbg(SDIO, "Entering oob=%d sd=%d\n",
sdiodev->oob_irq_requested,
@@ -180,26 +184,26 @@ void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev)
struct brcmfmac_sdio_pd *pdata;

pdata = &sdiodev->settings->bus.sdio;
- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL);
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, 0, NULL);
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);

sdiodev->oob_irq_requested = false;
if (sdiodev->irq_wake) {
disable_irq_wake(pdata->oob_irq_nr);
sdiodev->irq_wake = false;
}
- free_irq(pdata->oob_irq_nr, &sdiodev->func1->dev);
+ free_irq(pdata->oob_irq_nr, &func1->dev);
sdiodev->irq_en = false;
sdiodev->oob_irq_requested = false;
}

if (sdiodev->sd_irq_requested) {
- sdio_claim_host(sdiodev->func1);
- sdio_release_irq(sdiodev->func2);
- sdio_release_irq(sdiodev->func1);
- sdio_release_host(sdiodev->func1);
+ sdio_claim_host(func1);
+ sdio_release_irq(func2);
+ sdio_release_irq(func1);
+ sdio_release_host(func1);
sdiodev->sd_irq_requested = false;
}
}
@@ -250,6 +254,7 @@ brcmf_sdiod_set_backplane_window(struct brcmf_sdio_dev *sdiodev, u32 addr)

u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
{
+ struct sdio_func *func1 = sdiodev->func1;
u32 data = 0;
int retval;

@@ -261,7 +266,7 @@ u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!retval)
- data = sdio_readl(sdiodev->func1, addr, &retval);
+ data = sdio_readl(func1, addr, &retval);

out:
if (ret)
@@ -273,6 +278,7 @@ u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
u32 data, int *ret)
{
+ struct sdio_func *func1 = sdiodev->func1;
int retval;

retval = brcmf_sdiod_set_backplane_window(sdiodev, addr);
@@ -283,7 +289,7 @@ void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!retval)
- sdio_writel(sdiodev->func1, data, addr, &retval);
+ sdio_writel(func1, data, addr, &retval);

out:
if (ret)
@@ -529,6 +535,7 @@ int brcmf_sdiod_recv_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)

int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
{
+ struct sdio_func *func2 = sdiodev->func2;
u32 addr = sdiodev->cc_core->base;
int err = 0;

@@ -541,7 +548,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
addr &= SBSDIO_SB_OFT_ADDR_MASK;
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, func2, addr, pkt);

done:
return err;
@@ -550,6 +557,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
struct sk_buff_head *pktq, uint totlen)
{
+ struct sdio_func *func2 = sdiodev->func2;
struct sk_buff *glom_skb = NULL;
struct sk_buff *skb;
u32 addr = sdiodev->cc_core->base;
@@ -566,14 +574,12 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (pktq->qlen == 1)
- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr,
- pktq->next);
+ err = brcmf_sdiod_buff_read(sdiodev, func2, addr, pktq->next);
else if (!sdiodev->sg_support) {
glom_skb = brcmu_pkt_buf_get_skb(totlen);
if (!glom_skb)
return -ENOMEM;
- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr,
- glom_skb);
+ err = brcmf_sdiod_buff_read(sdiodev, func2, addr, glom_skb);
if (err)
goto done;

@@ -582,8 +588,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
skb_pull(glom_skb, skb->len);
}
} else
- err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, false, addr,
- pktq);
+ err = brcmf_sdiod_sglist_rw(sdiodev, func2, false, addr, pktq);

done:
brcmu_pkt_buf_free_skb(glom_skb);
@@ -593,6 +598,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
{
struct sk_buff *mypkt;
+ struct sdio_func *func2 = sdiodev->func2;
u32 addr = sdiodev->cc_core->base;
int err;

@@ -614,7 +620,7 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!err)
- err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func2, addr, mypkt);
+ err = brcmf_sdiod_buff_write(sdiodev, func2, addr, mypkt);

brcmu_pkt_buf_free_skb(mypkt);

@@ -626,6 +632,7 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,
struct sk_buff_head *pktq)
{
struct sk_buff *skb;
+ struct sdio_func *func2 = sdiodev->func2;
u32 addr = sdiodev->cc_core->base;
int err;

@@ -640,14 +647,12 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,

if (pktq->qlen == 1 || !sdiodev->sg_support)
skb_queue_walk(pktq, skb) {
- err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func2,
- addr, skb);
+ err = brcmf_sdiod_buff_write(sdiodev, func2, addr, skb);
if (err)
break;
}
else
- err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, true, addr,
- pktq);
+ err = brcmf_sdiod_sglist_rw(sdiodev, func2, true, addr, pktq);

return err;
}
@@ -656,6 +661,7 @@ int
brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
u8 *data, uint size)
{
+ struct sdio_func *func1 = sdiodev->func1;
int err = 0;
struct sk_buff *pkt;
u32 sdaddr;
@@ -676,7 +682,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
else
dsize = size;

- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);

/* Do the transfer(s) */
while (size) {
@@ -696,12 +702,10 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

if (write) {
memcpy(pkt->data, data, dsize);
- err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func1,
- sdaddr, pkt);
+ err = brcmf_sdiod_buff_write(sdiodev, func1, sdaddr, pkt);
}
else {
- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func1,
- sdaddr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, func1, sdaddr, pkt);
}

if (err) {
@@ -724,7 +728,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

dev_kfree_skb(pkt);

- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);

return err;
}
@@ -742,18 +746,16 @@ int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func)

void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
{
- struct sdio_func *func;
- struct mmc_host *host;
+ struct sdio_func *func2 = sdiodev->func2;
+ struct mmc_host *host = func2->card->host;
uint max_blocks;
uint nents;
int err;

- func = sdiodev->func2;
- host = func->card->host;
sdiodev->sg_support = host->max_segs > 1;
max_blocks = min_t(uint, host->max_blk_count, 511u);
sdiodev->max_request_size = min_t(uint, host->max_req_size,
- max_blocks * func->cur_blksize);
+ max_blocks * func2->cur_blksize);
sdiodev->max_segment_count = min_t(uint, host->max_segs,
SG_MAX_SINGLE_ALLOC);
sdiodev->max_segment_size = host->max_seg_size;
@@ -800,6 +802,7 @@ static void brcmf_sdiod_freezer_detach(struct brcmf_sdio_dev *sdiodev)

static int brcmf_sdiod_freezer_on(struct brcmf_sdio_dev *sdiodev)
{
+ struct sdio_func *func1 = sdiodev->func1;
atomic_t *expect = &sdiodev->freezer->thread_count;
int res = 0;

@@ -809,17 +812,19 @@ static int brcmf_sdiod_freezer_on(struct brcmf_sdio_dev *sdiodev)
brcmf_sdio_trigger_dpc(sdiodev->bus);
wait_event(sdiodev->freezer->thread_freeze,
atomic_read(expect) == sdiodev->freezer->frozen_count);
- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);
res = brcmf_sdio_sleep(sdiodev->bus, true);
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);
return res;
}

static void brcmf_sdiod_freezer_off(struct brcmf_sdio_dev *sdiodev)
{
- sdio_claim_host(sdiodev->func1);
+ struct sdio_func *func1 = sdiodev->func1;
+
+ sdio_claim_host(func1);
brcmf_sdio_sleep(sdiodev->bus, false);
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);
atomic_set(&sdiodev->freezer->freezing, 0);
complete_all(&sdiodev->freezer->resumed);
}
@@ -860,6 +865,9 @@ static void brcmf_sdiod_freezer_detach(struct brcmf_sdio_dev *sdiodev)

static int brcmf_sdiod_remove(struct brcmf_sdio_dev *sdiodev)
{
+ struct sdio_func *func1 = sdiodev->func1;
+ struct sdio_func *func2 = sdiodev->func2;
+
sdiodev->state = BRCMF_SDIOD_DOWN;
if (sdiodev->bus) {
brcmf_sdio_remove(sdiodev->bus);
@@ -869,19 +877,19 @@ static int brcmf_sdiod_remove(struct brcmf_sdio_dev *sdiodev)
brcmf_sdiod_freezer_detach(sdiodev);

/* Disable Function 2 */
- sdio_claim_host(sdiodev->func2);
- sdio_disable_func(sdiodev->func2);
- sdio_release_host(sdiodev->func2);
+ sdio_claim_host(func2);
+ sdio_disable_func(func2);
+ sdio_release_host(func2);

/* Disable Function 1 */
- sdio_claim_host(sdiodev->func1);
- sdio_disable_func(sdiodev->func1);
- sdio_release_host(sdiodev->func1);
+ sdio_claim_host(func1);
+ sdio_disable_func(func1);
+ sdio_release_host(func1);

sg_free_table(&sdiodev->sgtable);
sdiodev->sbwad = 0;

- pm_runtime_allow(sdiodev->func1->card->host->parent);
+ pm_runtime_allow(func1->card->host->parent);
return 0;
}

@@ -895,29 +903,32 @@ static void brcmf_sdiod_host_fixup(struct mmc_host *host)

static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
{
+ struct sdio_func *func1 = sdiodev->func1;
+ struct sdio_func *func2 = sdiodev->func2;
+
int ret = 0;

- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);

- ret = sdio_set_block_size(sdiodev->func1, SDIO_FUNC1_BLOCKSIZE);
+ ret = sdio_set_block_size(func1, SDIO_FUNC1_BLOCKSIZE);
if (ret) {
brcmf_err("Failed to set F1 blocksize\n");
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);
goto out;
}
- ret = sdio_set_block_size(sdiodev->func2, SDIO_FUNC2_BLOCKSIZE);
+ ret = sdio_set_block_size(func2, SDIO_FUNC2_BLOCKSIZE);
if (ret) {
brcmf_err("Failed to set F2 blocksize\n");
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);
goto out;
}

/* increase F2 timeout */
- sdiodev->func2->enable_timeout = SDIO_WAIT_F2RDY;
+ func2->enable_timeout = SDIO_WAIT_F2RDY;

/* Enable Function 1 */
- ret = sdio_enable_func(sdiodev->func1);
- sdio_release_host(sdiodev->func1);
+ ret = sdio_enable_func(func1);
+ sdio_release_host(func1);
if (ret) {
brcmf_err("Failed to enable F1: err=%d\n", ret);
goto out;
@@ -933,7 +944,8 @@ static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
ret = -ENODEV;
goto out;
}
- brcmf_sdiod_host_fixup(sdiodev->func2->card->host);
+
+ brcmf_sdiod_host_fixup(func2->card->host);
out:
if (ret)
brcmf_sdiod_remove(sdiodev);
@@ -1053,7 +1065,6 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
static void brcmf_ops_sdio_remove(struct sdio_func *func)
{
struct brcmf_bus *bus_if;
- struct brcmf_sdio_dev *sdiodev;

brcmf_dbg(SDIO, "Enter\n");
brcmf_dbg(SDIO, "sdio vendor ID: 0x%04x\n", func->vendor);
@@ -1062,7 +1073,9 @@ static void brcmf_ops_sdio_remove(struct sdio_func *func)

bus_if = dev_get_drvdata(&func->dev);
if (bus_if) {
- sdiodev = bus_if->bus_priv.sdio;
+ struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
+ struct sdio_func *func1 = sdiodev->func1;
+ struct sdio_func *func2 = sdiodev->func2;

/* start by unregistering irqs */
brcmf_sdiod_intr_unregister(sdiodev);
@@ -1073,8 +1086,8 @@ static void brcmf_ops_sdio_remove(struct sdio_func *func)
/* only proceed with rest of cleanup if func 1 */
brcmf_sdiod_remove(sdiodev);

- dev_set_drvdata(&sdiodev->func1->dev, NULL);
- dev_set_drvdata(&sdiodev->func2->dev, NULL);
+ dev_set_drvdata(&func1->dev, NULL);
+ dev_set_drvdata(&func2->dev, NULL);

kfree(bus_if);
kfree(sdiodev);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 5f90f747e76a..69a10a471a94 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -662,6 +662,7 @@ static bool data_ok(struct brcmf_sdio *bus)
static int
brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
u8 wr_val = 0, rd_val, cmp_val, bmask;
int err = 0;
int err_cnt = 0;
@@ -671,7 +672,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)

wr_val = (on << SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT);
/* 1st KSO write goes to AOS wake up core if device is asleep */
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err);

if (on) {
/* device WAKEUP through KSO:
@@ -697,7 +698,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
* just one write attempt may fail,
* read it back until it matches written value
*/
- rd_val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
+ rd_val = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
if (!err) {
if ((rd_val & bmask) == cmp_val)
break;
@@ -707,7 +708,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
if (err && (err_cnt++ > BRCMF_SDIO_MAX_ACCESS_ERRORS))
break;
udelay(KSO_WAIT_US);
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SLEEPCSR, wr_val, &err);
} while (try_cnt++ < MAX_KSO_ATTEMPTS);

if (try_cnt > 2)
@@ -725,6 +726,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
/* Turn backplane clock on or off */
static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
int err;
u8 clkctl, clkreq, devctl;
unsigned long timeout;
@@ -743,14 +745,14 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
clkreq =
bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ;

- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
if (err) {
brcmf_err("HT Avail request error: %d\n", err);
return -EBADE;
}

/* Check current status */
- clkctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
+ clkctl = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
if (err) {
brcmf_err("HT Avail read error: %d\n", err);
return -EBADE;
@@ -759,7 +761,7 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
/* Go to pending and await interrupt if appropriate */
if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) {
/* Allow only clock-available interrupt */
- devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
&err);
if (err) {
brcmf_err("Devctl error setting CA: %d\n",
@@ -768,7 +770,7 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
}

devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_DEVICE_CTL, devctl,
&err);
brcmf_dbg(SDIO, "CLKCTL: set PENDING\n");
bus->clkstate = CLK_PENDING;
@@ -776,10 +778,10 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
return 0;
} else if (bus->clkstate == CLK_PENDING) {
/* Cancel CA-only interrupt filter */
- devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
&err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_DEVICE_CTL, devctl,
&err);
}

@@ -787,7 +789,7 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
timeout = jiffies +
msecs_to_jiffies(PMU_MAX_TRANSITION_DLY/1000);
while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) {
- clkctl = brcmf_sdiod_readb(bus->sdiodev,
+ clkctl = brcmf_sdiod_readb(sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
&err);
if (time_after(jiffies, timeout))
@@ -821,15 +823,15 @@ static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok)

if (bus->clkstate == CLK_PENDING) {
/* Cancel CA-only interrupt filter */
- devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
&err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_DEVICE_CTL, devctl,
&err);
}

bus->clkstate = CLK_SDONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
brcmf_dbg(SDIO, "CLKCTL: turned OFF\n");
if (err) {
brcmf_err("Failed access turning clock off: %d\n",
@@ -904,6 +906,7 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
static int
brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
int err = 0;
u8 clkcsr;

@@ -919,12 +922,12 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)

/* Going to sleep */
if (sleep) {
- clkcsr = brcmf_sdiod_readb(bus->sdiodev,
+ clkcsr = brcmf_sdiod_readb(sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
&err);
if ((clkcsr & SBSDIO_CSR_MASK) == 0) {
brcmf_dbg(SDIO, "no clock, set ALP\n");
- brcmf_sdiod_writeb(bus->sdiodev,
+ brcmf_sdiod_writeb(sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
SBSDIO_ALP_AVAIL_REQ, &err);
}
@@ -966,13 +969,15 @@ static inline bool brcmf_sdio_valid_shared_address(u32 addr)
static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
struct sdpcm_shared *sh)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
u32 addr = 0;
int rv;
u32 shaddr = 0;
struct sdpcm_shared_le sh_le;
__le32 addr_le;

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
brcmf_sdio_bus_sleep(bus, false, false);

/*
@@ -982,7 +987,7 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
shaddr = bus->ci->rambase + bus->ci->ramsize - 4;
if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci))
shaddr -= bus->ci->srsize;
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr,
+ rv = brcmf_sdiod_ramrw(sdiodev, false, shaddr,
(u8 *)&addr_le, 4);
if (rv < 0)
goto fail;
@@ -1001,12 +1006,12 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
brcmf_dbg(INFO, "sdpcm_shared address 0x%08X\n", addr);

/* Read hndrte_shared structure */
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le,
+ rv = brcmf_sdiod_ramrw(sdiodev, false, addr, (u8 *)&sh_le,
sizeof(struct sdpcm_shared_le));
if (rv < 0)
goto fail;

- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);

/* Endianness */
sh->flags = le32_to_cpu(sh_le.flags);
@@ -1028,7 +1033,7 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
fail:
brcmf_err("unable to obtain sdpcm_shared info: rv=%d (addr=0x%x)\n",
rv, addr);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
return rv;
}

@@ -1047,7 +1052,7 @@ static void brcmf_sdio_get_console_addr(struct brcmf_sdio *bus)

static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)
{
- struct brcmf_sdio_dev *sdiod = bus->sdiodev;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
struct brcmf_core *core = bus->sdio_core;
u32 intstatus = 0;
u32 hmb_data;
@@ -1057,11 +1062,11 @@ static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)
brcmf_dbg(SDIO, "Enter\n");

/* Read mailbox data and ack that we did so */
- hmb_data = brcmf_sdiod_readl(sdiod, core->base +
+ hmb_data = brcmf_sdiod_readl(sdiodev, core->base +
__sd_reg(tohostmailboxdata), &ret);

if (!ret)
- brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailbox),
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(tosbmailbox),
SMB_INT_ACK, &ret);

bus->sdcnt.f1regdata += 2;
@@ -1132,7 +1137,8 @@ static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)

static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
{
- struct brcmf_sdio_dev *sdiod = bus->sdiodev;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func2 = sdiodev->func2;
struct brcmf_core *core = bus->sdio_core;
uint retries = 0;
u16 lastrbc;
@@ -1144,15 +1150,15 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
rtx ? ", send NAK" : "");

if (abort)
- brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func2);
+ brcmf_sdiod_abort(sdiodev, func2);

- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, &err);
bus->sdcnt.f1regdata++;

/* Wait until the packet has been flushed (device/FIFO stable) */
for (lastrbc = retries = 0xffff; retries > 0; retries--) {
- hi = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCHI, &err);
- lo = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_RFRAMEBCLO, &err);
+ hi = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_RFRAMEBCHI, &err);
+ lo = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_RFRAMEBCLO, &err);
bus->sdcnt.f1regdata += 2;

if ((hi == 0) && (lo == 0))
@@ -1172,7 +1178,7 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)

if (rtx) {
bus->sdcnt.rxrtx++;
- brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailbox),
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(tosbmailbox),
SMB_NAK, &err);

bus->sdcnt.f1regdata++;
@@ -1187,13 +1193,14 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
static void brcmf_sdio_txfail(struct brcmf_sdio *bus)
{
struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func2 = sdiodev->func2;
u8 i, hi, lo;

/* On failure, abort the command and terminate the frame */
brcmf_err("sdio error, abort command and terminate frame\n");
bus->sdcnt.tx_sderrs++;

- brcmf_sdiod_abort(sdiodev, sdiodev->func2);
+ brcmf_sdiod_abort(sdiodev, func2);
brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, NULL);
bus->sdcnt.f1regdata++;

@@ -1442,6 +1449,8 @@ static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header,

static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
u16 dlen, totlen;
u8 *dptr, num = 0;
u16 sublen;
@@ -1549,10 +1558,9 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
* read directly into the chained packet, or allocate a large
* packet and and copy into the chain.
*/
- sdio_claim_host(bus->sdiodev->func1);
- errcode = brcmf_sdiod_recv_chain(bus->sdiodev,
- &bus->glom, dlen);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
+ errcode = brcmf_sdiod_recv_chain(sdiodev, &bus->glom, dlen);
+ sdio_release_host(func1);
bus->sdcnt.f2rxdata++;

/* On failure, kill the superframe */
@@ -1560,11 +1568,11 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
brcmf_err("glom read of %d bytes failed: %d\n",
dlen, errcode);

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
brcmf_sdio_rxfail(bus, true, false);
bus->sdcnt.rxglomfail++;
brcmf_sdio_free_glom(bus);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
return 0;
}

@@ -1574,10 +1582,10 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)

rd_new.seq_num = rxseq;
rd_new.len = dlen;
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new,
BRCMF_SDIO_FT_SUPER);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
bus->cur_read.len = rd_new.len_nxtfrm << 4;

/* Remove superframe header, remember offset */
@@ -1593,10 +1601,10 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)

rd_new.len = pnext->len;
rd_new.seq_num = rxseq++;
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new,
BRCMF_SDIO_FT_SUB);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
brcmf_dbg_hex_dump(BRCMF_GLOM_ON(),
pnext->data, 32, "subframe:\n");

@@ -1605,11 +1613,11 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)

if (errcode) {
/* Terminate frame on error */
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
brcmf_sdio_rxfail(bus, true, false);
bus->sdcnt.rxglomfail++;
brcmf_sdio_free_glom(bus);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
bus->cur_read.len = 0;
return 0;
}
@@ -1643,9 +1651,9 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
pfirst->prev);
skb_unlink(pfirst, &bus->glom);
if (brcmf_sdio_fromevntchan(&dptr[SDPCM_HWHDR_LEN]))
- brcmf_rx_event(bus->sdiodev->dev, pfirst);
+ brcmf_rx_event(sdiodev->dev, pfirst);
else
- brcmf_rx_frame(bus->sdiodev->dev, pfirst,
+ brcmf_rx_frame(sdiodev->dev, pfirst,
false);
bus->sdcnt.rxglompkts++;
}
@@ -1686,6 +1694,7 @@ static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus)
static void
brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
uint rdlen, pad;
u8 *buf = NULL, *rbuf;
int sdret;
@@ -1712,30 +1721,30 @@ brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff)
if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) {
pad = bus->blocksize - (rdlen % bus->blocksize);
if ((pad <= bus->roundup) && (pad < bus->blocksize) &&
- ((len + pad) < bus->sdiodev->bus_if->maxctl))
+ ((len + pad) < sdiodev->bus_if->maxctl))
rdlen += pad;
} else if (rdlen % bus->head_align) {
rdlen += bus->head_align - (rdlen % bus->head_align);
}

/* Drop if the read is too big or it exceeds our maximum */
- if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) {
+ if ((rdlen + BRCMF_FIRSTREAD) > sdiodev->bus_if->maxctl) {
brcmf_err("%d-byte control read exceeds %d-byte buffer\n",
- rdlen, bus->sdiodev->bus_if->maxctl);
+ rdlen, sdiodev->bus_if->maxctl);
brcmf_sdio_rxfail(bus, false, false);
goto done;
}

- if ((len - doff) > bus->sdiodev->bus_if->maxctl) {
+ if ((len - doff) > sdiodev->bus_if->maxctl) {
brcmf_err("%d-byte ctl frame (%d-byte ctl data) exceeds %d-byte limit\n",
- len, len - doff, bus->sdiodev->bus_if->maxctl);
+ len, len - doff, sdiodev->bus_if->maxctl);
bus->sdcnt.rx_toolong++;
brcmf_sdio_rxfail(bus, false, false);
goto done;
}

/* Read remain of frame body */
- sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen);
+ sdret = brcmf_sdiod_recv_buf(sdiodev, rbuf, rdlen);
bus->sdcnt.f2rxdata++;

/* Control frame failures need retransmission */
@@ -2010,6 +2019,7 @@ brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus)

static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
struct brcmf_bus_stats *stats;
u16 head_pad;
u8 *dat_buf;
@@ -2020,7 +2030,7 @@ static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt)
head_pad = ((unsigned long)dat_buf % bus->head_align);
if (head_pad) {
if (skb_headroom(pkt) < head_pad) {
- stats = &bus->sdiodev->bus_if->stats;
+ stats = &sdiodev->bus_if->stats;
atomic_inc(&stats->pktcowed);
if (skb_cow_head(pkt, head_pad)) {
atomic_inc(&stats->pktcow_failed);
@@ -2047,14 +2057,13 @@ static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus,
struct sk_buff_head *pktq,
struct sk_buff *pkt, u16 total_len)
{
- struct brcmf_sdio_dev *sdiodev;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
struct sk_buff *pkt_pad;
u16 tail_pad, tail_chop, chain_pad;
unsigned int blksize;
bool lastfrm;
int ntail, ret;

- sdiodev = bus->sdiodev;
blksize = sdiodev->func2->cur_blksize;
/* sg entry alignment should be a divisor of block size */
WARN_ON(blksize % bus->sgentry_align);
@@ -2225,6 +2234,9 @@ brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq)
static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
uint chan)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
+
int ret;
struct sk_buff *pkt_next, *tmp;

@@ -2234,14 +2246,14 @@ static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
if (ret)
goto done;

- sdio_claim_host(bus->sdiodev->func1);
- ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq);
+ sdio_claim_host(func1);
+ ret = brcmf_sdiod_send_pkt(sdiodev, pktq);
bus->sdcnt.f2txdata++;

if (ret < 0)
brcmf_sdio_txfail(bus);

- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);

done:
brcmf_sdio_txpkt_postp(bus, pktq);
@@ -2249,7 +2261,7 @@ static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP;
skb_queue_walk_safe(pktq, pkt_next, tmp) {
__skb_unlink(pkt_next, pktq);
- brcmf_proto_bcdc_txcomplete(bus->sdiodev->dev, pkt_next,
+ brcmf_proto_bcdc_txcomplete(sdiodev->dev, pkt_next,
ret == 0);
}
return ret;
@@ -2257,6 +2269,8 @@ static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq,

static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
struct brcmf_core *core = bus->sdio_core;
struct sk_buff *pkt;
struct sk_buff_head pktq;
@@ -2274,7 +2288,7 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
pkt_num = 1;
if (bus->txglom)
pkt_num = min_t(u8, bus->tx_max - bus->tx_seq,
- bus->sdiodev->txglomsz);
+ sdiodev->txglomsz);
pkt_num = min_t(u32, pkt_num,
brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol));
__skb_queue_head_init(&pktq);
@@ -2297,10 +2311,10 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
/* In poll mode, need to check for other events */
if (!bus->intr) {
/* Check device status, signal pending interrupt */
- sdio_claim_host(bus->sdiodev->func1);
- intstatus = brcmf_sdiod_readl(bus->sdiodev, core->base +
+ sdio_claim_host(func1);
+ intstatus = brcmf_sdiod_readl(sdiodev, core->base +
__sd_reg(intstatus), &ret);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
bus->sdcnt.f2txdata++;
if (ret != 0)
break;
@@ -2310,10 +2324,10 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
}

/* Deflow-control stack if needed */
- if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) &&
+ if ((sdiodev->state == BRCMF_SDIOD_DATA) &&
bus->txoff && (pktq_len(&bus->txq) < TXLOW)) {
bus->txoff = false;
- brcmf_proto_bcdc_txflowblock(bus->sdiodev->dev, false);
+ brcmf_proto_bcdc_txflowblock(sdiodev->dev, false);
}

return cnt;
@@ -2321,6 +2335,7 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)

static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
u8 doff;
u16 pad;
uint retries = 0;
@@ -2370,7 +2385,7 @@ static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len)
frame, min_t(u16, len, 16), "TxHdr:\n");

do {
- ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len);
+ ret = brcmf_sdiod_send_buf(sdiodev, frame, len);

if (ret < 0)
brcmf_sdio_txfail(bus);
@@ -2466,33 +2481,36 @@ static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus)

static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
struct brcmf_core *core = bus->sdio_core;
unsigned long val;
int ret;

- val = brcmf_sdiod_readl(bus->sdiodev, core->base + __sd_reg(intstatus), &ret);
+ val = brcmf_sdiod_readl(sdiodev, core->base + __sd_reg(intstatus), &ret);
bus->sdcnt.f1regdata++;
if (ret != 0)
- return ret;
+ goto out;

val &= bus->hostintmask;
atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE));

+ if (!val)
+ goto out;
+
/* Clear interrupts */
- if (val) {
- brcmf_sdiod_writel(bus->sdiodev, core->base + __sd_reg(intstatus),
- val, &ret);
- bus->sdcnt.f1regdata++;
- atomic_or(val, &bus->intstatus);
- }
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(intstatus), val, &ret);
+ bus->sdcnt.f1regdata++;
+ atomic_or(val, &bus->intstatus);

+out:
return ret;
}

static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
{
struct brcmf_core *core = bus->sdio_core;
- struct brcmf_sdio_dev *sdiod = bus->sdiodev;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
u32 newstatus = 0;
unsigned long intstatus;
uint txlimit = bus->txbound; /* Tx frames to send before resched */
@@ -2501,7 +2519,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)

brcmf_dbg(TRACE, "Enter\n");

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);

/* If waiting for HTAVAIL, check status */
if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) {
@@ -2509,20 +2527,20 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)

#ifdef DEBUG
/* Check for inconsistent device control */
- devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL, &err);
#endif /* DEBUG */

/* Read CSR, if clock on switch to AVAIL, else ignore */
- clkctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
+ clkctl = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);

brcmf_dbg(SDIO, "DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n",
devctl, clkctl);

if (SBSDIO_HTAV(clkctl)) {
- devctl = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_DEVICE_CTL,
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
&err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_DEVICE_CTL, devctl,
&err);
bus->clkstate = CLK_AVAIL;
}
@@ -2546,11 +2564,12 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
*/
if (intstatus & I_HMB_FC_CHANGE) {
intstatus &= ~I_HMB_FC_CHANGE;
- brcmf_sdiod_writel(sdiod, core->base + __sd_reg(intstatus),
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(intstatus),
I_HMB_FC_CHANGE, &err);

- newstatus = brcmf_sdiod_readl(sdiod, core->base + __sd_reg(intstatus),
- &err);
+ newstatus = brcmf_sdiod_readl(sdiodev,
+ core->base + __sd_reg(intstatus),
+ &err);

bus->sdcnt.f1regdata += 2;
atomic_set(&bus->fcstate,
@@ -2564,7 +2583,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
intstatus |= brcmf_sdio_hostmail(bus);
}

- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);

/* Generally don't ask for these, can get CRC errors... */
if (intstatus & I_WR_OOSYNC) {
@@ -2607,7 +2626,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)

if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) &&
data_ok(bus)) {
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
if (bus->ctrl_frame_stat) {
err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf,
bus->ctrl_frame_len);
@@ -2615,7 +2634,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
wmb();
bus->ctrl_frame_stat = false;
}
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
brcmf_sdio_wait_event_wakeup(bus);
}
/* Send queued frames (limit 1 if rx may still be pending) */
@@ -2627,18 +2646,18 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
brcmf_sdio_sendfromq(bus, framecnt);
}

- if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) {
+ if ((sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) {
brcmf_err("failed backplane access over SDIO, halting operation\n");
atomic_set(&bus->intstatus, 0);
if (bus->ctrl_frame_stat) {
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
if (bus->ctrl_frame_stat) {
bus->ctrl_frame_err = -ENODEV;
wmb();
bus->ctrl_frame_stat = false;
brcmf_sdio_wait_event_wakeup(bus);
}
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
}
} else if (atomic_read(&bus->intstatus) ||
atomic_read(&bus->ipend) > 0 ||
@@ -2755,6 +2774,7 @@ static int brcmf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt)

static int brcmf_sdio_readconsole(struct brcmf_sdio *bus)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
struct brcmf_console *c = &bus->console;
u8 line[CONSOLE_LINE_MAX], ch;
u32 n, idx, addr;
@@ -2766,7 +2786,7 @@ static int brcmf_sdio_readconsole(struct brcmf_sdio *bus)

/* Read console log struct */
addr = bus->console_addr + offsetof(struct rte_console, log_le);
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le,
+ rv = brcmf_sdiod_ramrw(sdiodev, false, addr, (u8 *)&c->log_le,
sizeof(c->log_le));
if (rv < 0)
return rv;
@@ -2792,7 +2812,7 @@ static int brcmf_sdio_readconsole(struct brcmf_sdio *bus)

/* Read the console buffer */
addr = le32_to_cpu(c->log_le.buf);
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize);
+ rv = brcmf_sdiod_ramrw(sdiodev, false, addr, c->buf, c->bufsize);
if (rv < 0)
return rv;

@@ -2835,6 +2855,7 @@ brcmf_sdio_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
{
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
+ struct sdio_func *func1 = sdiodev->func1;
struct brcmf_sdio *bus = sdiodev->bus;
int ret;

@@ -2853,13 +2874,13 @@ brcmf_sdio_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
CTL_DONE_TIMEOUT);
ret = 0;
if (bus->ctrl_frame_stat) {
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
if (bus->ctrl_frame_stat) {
brcmf_dbg(SDIO, "ctrl_frame timeout\n");
bus->ctrl_frame_stat = false;
ret = -ETIMEDOUT;
}
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
}
if (!ret) {
brcmf_dbg(SDIO, "ctrl_frame complete, err=%d\n",
@@ -2880,6 +2901,7 @@ brcmf_sdio_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus,
struct sdpcm_shared *sh)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
u32 addr, console_ptr, console_size, console_index;
char *conbuf = NULL;
__le32 sh_val;
@@ -2887,22 +2909,19 @@ static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus,

/* obtain console information from device memory */
addr = sh->console_addr + offsetof(struct rte_console, log_le);
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr,
- (u8 *)&sh_val, sizeof(u32));
+ rv = brcmf_sdiod_ramrw(sdiodev, false, addr, (u8 *)&sh_val, sizeof(u32));
if (rv < 0)
return rv;
console_ptr = le32_to_cpu(sh_val);

addr = sh->console_addr + offsetof(struct rte_console, log_le.buf_size);
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr,
- (u8 *)&sh_val, sizeof(u32));
+ rv = brcmf_sdiod_ramrw(sdiodev, false, addr, (u8 *)&sh_val, sizeof(u32));
if (rv < 0)
return rv;
console_size = le32_to_cpu(sh_val);

addr = sh->console_addr + offsetof(struct rte_console, log_le.idx);
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr,
- (u8 *)&sh_val, sizeof(u32));
+ rv = brcmf_sdiod_ramrw(sdiodev, false, addr, (u8 *)&sh_val, sizeof(u32));
if (rv < 0)
return rv;
console_index = le32_to_cpu(sh_val);
@@ -2916,7 +2935,7 @@ static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus,

/* obtain the console data from device */
conbuf[console_size] = '\0';
- rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf,
+ rv = brcmf_sdiod_ramrw(sdiodev, false, console_ptr, (u8 *)conbuf,
console_size);
if (rv < 0)
goto done;
@@ -2971,6 +2990,8 @@ static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus,
static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus,
struct sdpcm_shared *sh)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
int error = 0;
char file[80] = "?";
char expr[80] = "<???>";
@@ -2983,20 +3004,20 @@ static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus,
return 0;
}

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
if (sh->assert_file_addr != 0) {
- error = brcmf_sdiod_ramrw(bus->sdiodev, false,
+ error = brcmf_sdiod_ramrw(sdiodev, false,
sh->assert_file_addr, (u8 *)file, 80);
if (error < 0)
return error;
}
if (sh->assert_exp_addr != 0) {
- error = brcmf_sdiod_ramrw(bus->sdiodev, false,
+ error = brcmf_sdiod_ramrw(sdiodev, false,
sh->assert_exp_addr, (u8 *)expr, 80);
if (error < 0)
return error;
}
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);

seq_printf(seq, "dongle assert: %s:%d: assert(%s)\n",
file, sh->assert_line, expr);
@@ -3228,16 +3249,17 @@ brcmf_sdio_verifymemory(struct brcmf_sdio_dev *sdiodev, u32 ram_addr,
static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus,
const struct firmware *fw)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
int err;

brcmf_dbg(TRACE, "Enter\n");

- err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase,
- (u8 *)fw->data, fw->size);
+ err = brcmf_sdiod_ramrw(sdiodev, true, bus->ci->rambase, (u8 *)fw->data,
+ fw->size);
if (err)
brcmf_err("error %d on writing %d membytes at 0x%08x\n",
err, (int)fw->size, bus->ci->rambase);
- else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase,
+ else if (!brcmf_sdio_verifymemory(sdiodev, bus->ci->rambase,
(u8 *)fw->data, fw->size))
err = -EIO;

@@ -3247,17 +3269,18 @@ static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus,
static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus,
void *vars, u32 varsz)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
int address;
int err;

brcmf_dbg(TRACE, "Enter\n");

address = bus->ci->ramsize - varsz + bus->ci->rambase;
- err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz);
+ err = brcmf_sdiod_ramrw(sdiodev, true, address, vars, varsz);
if (err)
brcmf_err("error %d on writing %d nvram bytes at 0x%08x\n",
err, varsz, address);
- else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz))
+ else if (!brcmf_sdio_verifymemory(sdiodev, address, vars, varsz))
err = -EIO;

return err;
@@ -3267,10 +3290,12 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,
const struct firmware *fw,
void *nvram, u32 nvlen)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
int bcmerror;
u32 rstvec;

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
brcmf_sdio_clkctl(bus, CLK_AVAIL, false);

rstvec = get_unaligned_le32(fw->data);
@@ -3299,32 +3324,33 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,

err:
brcmf_sdio_clkctl(bus, CLK_SDONLY, false);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
return bcmerror;
}

static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
int err = 0;
u8 val;

brcmf_dbg(TRACE, "Enter\n");

- val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err);
+ val = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err);
if (err) {
brcmf_err("error reading SBSDIO_FUNC1_WAKEUPCTRL\n");
return;
}

val |= 1 << SBSDIO_FUNC1_WCTRL_HTWAIT_SHIFT;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_WAKEUPCTRL\n");
return;
}

/* Add CMD14 Support */
- brcmf_sdiod_func0_wb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP,
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_CARDCAP,
(SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT |
SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT),
&err);
@@ -3333,7 +3359,7 @@ static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)
return;
}

- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, SBSDIO_FORCE_HT,
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, SBSDIO_FORCE_HT,
&err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_CHIPCLKCSR\n");
@@ -3348,6 +3374,7 @@ static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)
/* enable KSO bit */
static int brcmf_sdio_kso_init(struct brcmf_sdio *bus)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
struct brcmf_core *core = bus->sdio_core;
u8 val;
int err = 0;
@@ -3358,7 +3385,7 @@ static int brcmf_sdio_kso_init(struct brcmf_sdio *bus)
if (core->rev < 12)
return 0;

- val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
+ val = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err);
if (err) {
brcmf_err("error reading SBSDIO_FUNC1_SLEEPCSR\n");
return err;
@@ -3367,7 +3394,7 @@ static int brcmf_sdio_kso_init(struct brcmf_sdio *bus)
if (!(val & SBSDIO_FUNC1_SLEEPCSR_KSO_MASK)) {
val |= (SBSDIO_FUNC1_SLEEPCSR_KSO_EN <<
SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT);
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, val, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SLEEPCSR, val, &err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_SLEEPCSR\n");
return err;
@@ -3383,6 +3410,7 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
struct brcmf_sdio *bus = sdiodev->bus;
+ struct sdio_func *func2 = sdiodev->func2;
struct brcmf_core *core = bus->sdio_core;
uint pad_size;
u32 value;
@@ -3413,8 +3441,8 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
if (sdiodev->sg_support) {
bus->txglom = false;
value = 1;
- pad_size = bus->sdiodev->func2->cur_blksize << 1;
- err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom",
+ pad_size = func2->cur_blksize << 1;
+ err = brcmf_iovar_data_set(sdiodev->dev, "bus:rxglom",
&value, sizeof(u32));
if (err < 0) {
/* bus:rxglom is allowed to fail */
@@ -3424,7 +3452,7 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
bus->tx_hdrlen += SDPCM_HWEXT_LEN;
}
}
- brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen);
+ brcmf_bus_add_txhdrlen(sdiodev->dev, bus->tx_hdrlen);

done:
return err;
@@ -3511,6 +3539,9 @@ void brcmf_sdio_isr(struct brcmf_sdio *bus)

static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
+
brcmf_dbg(TIMER, "Enter\n");

/* Poll period: check device if appropriate. */
@@ -3528,11 +3559,11 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
if (!bus->dpc_triggered) {
u8 devpend;

- sdio_claim_host(bus->sdiodev->func1);
- devpend = brcmf_sdiod_func0_rb(bus->sdiodev,
+ sdio_claim_host(func1);
+ devpend = brcmf_sdiod_func0_rb(sdiodev,
SDIO_CCCR_INTx,
NULL);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
intstatus = devpend & (INTR_STATUS_FUNC1 |
INTR_STATUS_FUNC2);
}
@@ -3553,18 +3584,18 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
}
#ifdef DEBUG
/* Poll for console output periodically */
- if (bus->sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() &&
+ if (sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() &&
bus->console_interval != 0) {
bus->console.count += jiffies_to_msecs(BRCMF_WD_POLL);
if (bus->console.count >= bus->console_interval) {
bus->console.count -= bus->console_interval;
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
/* Make sure backplane clock is on */
brcmf_sdio_bus_sleep(bus, false, false);
if (brcmf_sdio_readconsole(bus) < 0)
/* stop on error */
bus->console_interval = 0;
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
}
}
#endif /* DEBUG */
@@ -3577,11 +3608,11 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
bus->idlecount++;
if (bus->idlecount > bus->idletime) {
brcmf_dbg(SDIO, "idle\n");
- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
brcmf_sdio_wd_timer(bus, false);
bus->idlecount = 0;
brcmf_sdio_bus_sleep(bus, true, false);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
}
} else {
bus->idlecount = 0;
@@ -3595,6 +3626,7 @@ static void brcmf_sdio_dataworker(struct work_struct *work)
{
struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio,
datawork);
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;

bus->dpc_running = true;
wmb();
@@ -3604,10 +3636,10 @@ static void brcmf_sdio_dataworker(struct work_struct *work)
bus->idlecount = 0;
}
bus->dpc_running = false;
- if (brcmf_sdiod_freezing(bus->sdiodev)) {
- brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN);
- brcmf_sdiod_try_freeze(bus->sdiodev);
- brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA);
+ if (brcmf_sdiod_freezing(sdiodev)) {
+ brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_DOWN);
+ brcmf_sdiod_try_freeze(sdiodev);
+ brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_DATA);
}
}

@@ -3784,15 +3816,15 @@ static const struct brcmf_buscore_ops brcmf_sdio_buscore_ops = {
static bool
brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
{
- struct brcmf_sdio_dev *sdiodev;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
u8 clkctl = 0;
int err = 0;
int reg_addr;
u32 reg_val;
u32 drivestrength;

- sdiodev = bus->sdiodev;
- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);

/*
* Force PLL off until brcmf_chip_attach()
@@ -3923,18 +3955,19 @@ static int
brcmf_sdio_watchdog_thread(void *data)
{
struct brcmf_sdio *bus = (struct brcmf_sdio *)data;
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
int wait;

allow_signal(SIGTERM);
/* Run until signal received */
- brcmf_sdiod_freezer_count(bus->sdiodev);
+ brcmf_sdiod_freezer_count(sdiodev);
while (1) {
if (kthread_should_stop())
break;
- brcmf_sdiod_freezer_uncount(bus->sdiodev);
+ brcmf_sdiod_freezer_uncount(sdiodev);
wait = wait_for_completion_interruptible(&bus->watchdog_wait);
- brcmf_sdiod_freezer_count(bus->sdiodev);
- brcmf_sdiod_try_freeze(bus->sdiodev);
+ brcmf_sdiod_freezer_count(sdiodev);
+ brcmf_sdiod_try_freeze(sdiodev);
if (!wait) {
brcmf_sdio_bus_watchdog(bus);
/* Count the tick for reference */
@@ -3978,8 +4011,9 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
{
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
+ struct sdio_func *func1 = sdiodev->func1;
+ struct sdio_func *func2 = sdiodev->func2;
struct brcmf_sdio *bus = sdiodev->bus;
- struct brcmf_sdio_dev *sdiod = bus->sdiodev;
struct brcmf_core *core = bus->sdio_core;
u8 saveclk;

@@ -4002,7 +4036,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
bus->sdcnt.tickcnt = 0;
brcmf_sdio_wd_timer(bus, true);

- sdio_claim_host(sdiodev->func1);
+ sdio_claim_host(func1);

/* Make sure backplane clock is on, needed to generate F2 interrupt */
brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
@@ -4021,10 +4055,10 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
}

/* Enable function 2 (frame transfers) */
- brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailboxdata),
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(tosbmailboxdata),
SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, NULL);

- err = sdio_enable_func(sdiodev->func2);
+ err = sdio_enable_func(func2);


brcmf_dbg(INFO, "enable F2: err=%d\n", err);
@@ -4033,14 +4067,13 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
if (!err) {
/* Set up the interrupt mask and enable interrupts */
bus->hostintmask = HOSTINTMASK;
- brcmf_sdiod_writel(sdiod, core->base + __sd_reg(hostintmask),
+ brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(hostintmask),
bus->hostintmask, NULL);

-
brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
} else {
/* Disable F2 again */
- sdio_disable_func(sdiodev->func2);
+ sdio_disable_func(func2);
goto release;
}

@@ -4053,7 +4086,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,

if (err == 0) {
/* Allow full data communication using DPC from now on. */
- brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA);
+ brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_DATA);

err = brcmf_sdiod_intr_register(sdiodev);
if (err != 0)
@@ -4064,7 +4097,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
if (err != 0)
brcmf_sdio_clkctl(bus, CLK_NONE, false);

- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);

err = brcmf_bus_started(dev);
if (err != 0) {
@@ -4074,11 +4107,11 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
return;

release:
- sdio_release_host(sdiodev->func1);
+ sdio_release_host(func1);
fail:
brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), err);
device_release_driver(dev);
- device_release_driver(&sdiodev->func2->dev);
+ device_release_driver(&func2->dev);
}

struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
@@ -4143,16 +4176,16 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
bus->dpc_running = false;

/* Assign bus interface call back */
- bus->sdiodev->bus_if->dev = bus->sdiodev->dev;
- bus->sdiodev->bus_if->ops = &brcmf_sdio_bus_ops;
- bus->sdiodev->bus_if->chip = bus->ci->chip;
- bus->sdiodev->bus_if->chiprev = bus->ci->chiprev;
+ sdiodev->bus_if->dev = sdiodev->dev;
+ sdiodev->bus_if->ops = &brcmf_sdio_bus_ops;
+ sdiodev->bus_if->chip = bus->ci->chip;
+ sdiodev->bus_if->chiprev = bus->ci->chiprev;

/* default sdio bus header length for tx packet */
bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN;

/* Attach to the common layer, reserve hdr space */
- ret = brcmf_attach(bus->sdiodev->dev, bus->sdiodev->settings);
+ ret = brcmf_attach(sdiodev->dev, sdiodev->settings);
if (ret != 0) {
brcmf_err("brcmf_attach failed\n");
goto fail;
@@ -4161,17 +4194,17 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
/* allocate scatter-gather table. sg support
* will be disabled upon allocation failure.
*/
- brcmf_sdiod_sgtable_alloc(bus->sdiodev);
+ brcmf_sdiod_sgtable_alloc(sdiodev);

/* Query the F2 block size, set roundup accordingly */
- bus->blocksize = bus->sdiodev->func2->cur_blksize;
+ bus->blocksize = sdiodev->func2->cur_blksize;
bus->roundup = min(max_roundup, bus->blocksize);

/* Allocate buffers */
- if (bus->sdiodev->bus_if->maxctl) {
- bus->sdiodev->bus_if->maxctl += bus->roundup;
+ if (sdiodev->bus_if->maxctl) {
+ sdiodev->bus_if->maxctl += bus->roundup;
bus->rxblen =
- roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN),
+ roundup((sdiodev->bus_if->maxctl + SDPCM_HDRLEN),
ALIGNMENT) + bus->head_align;
bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC);
if (!(bus->rxbuf)) {
@@ -4180,17 +4213,17 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
}
}

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(sdiodev->func1);

/* Disable F2 to clear any intermediate frame state on the dongle */
- sdio_disable_func(bus->sdiodev->func2);
+ sdio_disable_func(sdiodev->func2);

bus->rxflow = false;

/* Done with backplane-dependent accesses, can drop clock... */
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);

- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(sdiodev->func1);

/* ...and initialize clock/power states */
bus->clkstate = CLK_SDONLY;
@@ -4231,18 +4264,21 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
brcmf_dbg(TRACE, "Enter\n");

if (bus) {
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
+
/* De-register interrupt handler */
- brcmf_sdiod_intr_unregister(bus->sdiodev);
+ brcmf_sdiod_intr_unregister(sdiodev);

- brcmf_detach(bus->sdiodev->dev);
+ brcmf_detach(sdiodev->dev);

cancel_work_sync(&bus->datawork);
if (bus->brcmf_wq)
destroy_workqueue(bus->brcmf_wq);

if (bus->ci) {
- if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) {
- sdio_claim_host(bus->sdiodev->func1);
+ if (sdiodev->state != BRCMF_SDIOD_NOMEDIUM) {
+ sdio_claim_host(sdiodev->func1);
brcmf_sdio_wd_timer(bus, false);
brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
/* Leave the device in state where it is
@@ -4252,12 +4288,12 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
msleep(20);
brcmf_chip_set_passive(bus->ci);
brcmf_sdio_clkctl(bus, CLK_NONE, false);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);
}
brcmf_chip_detach(bus->ci);
}
- if (bus->sdiodev->settings)
- brcmf_release_module_param(bus->sdiodev->settings);
+ if (sdiodev->settings)
+ brcmf_release_module_param(sdiodev->settings);

kfree(bus->rxbuf);
kfree(bus->hdrbuf);
@@ -4297,11 +4333,13 @@ void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, bool active)

int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep)
{
+ struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
+ struct sdio_func *func1 = sdiodev->func1;
int ret;

- sdio_claim_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
ret = brcmf_sdio_bus_sleep(bus, sleep, false);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_release_host(func1);

return ret;
}
--
2.11.0

2017-07-19 19:11:03

by Ian Molton

[permalink] [raw]
Subject: [PATCH 22/34] brcmfmac: Rename axi functions for clarity.

These functions are poorly named. for the sake of one character,
correct this.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index b3b28e78c49d..1485463794ff 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -239,7 +239,7 @@ static bool brcmf_chip_sb_iscoreup(struct brcmf_core *core)
return SSB_TMSLOW_CLOCK == regdata;
}

-static bool brcmf_chip_ai_iscoreup(struct brcmf_core *core)
+static bool brcmf_chip_axi_iscoreup(struct brcmf_core *core)
{
struct brcmf_chip *ci = core->chip;
u32 regdata;
@@ -340,7 +340,7 @@ static void brcmf_chip_sb_coredisable(struct brcmf_core *core,
udelay(1);
}

-static void brcmf_chip_ai_coredisable(struct brcmf_core *core,
+static void brcmf_chip_axi_coredisable(struct brcmf_core *core,
u32 prereset, u32 reset)
{
struct brcmf_chip *ci = core->chip;
@@ -432,14 +432,14 @@ static void brcmf_chip_sb_resetcore(struct brcmf_core *core, u32 prereset,
udelay(1);
}

-static void brcmf_chip_ai_resetcore(struct brcmf_core *core, u32 prereset,
+static void brcmf_chip_axi_resetcore(struct brcmf_core *core, u32 prereset,
u32 reset, u32 postreset)
{
struct brcmf_chip *ci = core->chip;
int count;

/* must disable first to work for arbitrary current core state */
- brcmf_chip_ai_coredisable(core, prereset, reset);
+ brcmf_chip_axi_coredisable(core, prereset, reset);

count = 0;

@@ -1007,9 +1007,9 @@ static int brcmf_chip_probe(struct brcmf_chip *ci)
if (brcmf_chip_dmp_erom_scan(ci))
return -ENODEV;

- ci->iscoreup = brcmf_chip_ai_iscoreup;
- ci->coredisable = brcmf_chip_ai_coredisable;
- ci->resetcore = brcmf_chip_ai_resetcore;
+ ci->iscoreup = brcmf_chip_axi_iscoreup;
+ ci->coredisable = brcmf_chip_axi_coredisable;
+ ci->resetcore = brcmf_chip_axi_resetcore;

break;
default:
--
2.11.0

2017-07-19 19:15:52

by Ian Molton

[permalink] [raw]
Subject: [PATCH 28/34] brcmfmac: Rename buscore->core for consistency

Avoid confusion with unrelated _buscore labels.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index cc83388b8c72..19f40a1ee418 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -2466,14 +2466,11 @@ static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus)

static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)
{
- struct brcmf_core *buscore = bus->sdio_core;
- u32 addr;
+ struct brcmf_core *core = bus->sdio_core;
unsigned long val;
int ret;

- addr = buscore->base + __sd_reg(intstatus);
-
- val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret);
+ val = brcmf_sdiod_readl(bus->sdiodev, core->base + __sd_reg(intstatus), &ret);
bus->sdcnt.f1regdata++;
if (ret != 0)
return ret;
@@ -2483,7 +2480,8 @@ static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus)

/* Clear interrupts */
if (val) {
- brcmf_sdiod_writel(bus->sdiodev, addr, val, &ret);
+ brcmf_sdiod_writel(bus->sdiodev, core->base + __sd_reg(intstatus),
+ val, &ret);
bus->sdcnt.f1regdata++;
atomic_or(val, &bus->intstatus);
}
--
2.11.0

2017-07-19 19:08:40

by Ian Molton

[permalink] [raw]
Subject: [PATCH 06/34] brcmfmac: Remove bandaid for SleepCSR

Register access code is not the place for band-aid fixes like this.
If this is a genuine problem, it should be fixed further up in the driver
stack.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 26 ----------------------
1 file changed, 26 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index c3e909526a1d..7eb54539a85e 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -334,19 +334,6 @@ static int brcmf_sdiod_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr,

if (ret == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
- else if (ret != 0) {
- /*
- * SleepCSR register access can fail when
- * waking up the device so reduce this noise
- * in the logs.
- */
- if (addr != SBSDIO_FUNC1_SLEEPCSR)
- brcmf_err("failed to write data F%d@0x%05x, err: %d\n",
- func, addr, ret);
- else
- brcmf_dbg(SDIO, "failed to write data F%d@0x%05x, err: %d\n",
- func, addr, ret);
- }

return ret;
}
@@ -387,19 +374,6 @@ static int brcmf_sdiod_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr,

if (ret == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
- else if (ret != 0) {
- /*
- * SleepCSR register access can fail when
- * waking up the device so reduce this noise
- * in the logs.
- */
- if (addr != SBSDIO_FUNC1_SLEEPCSR)
- brcmf_err("failed to read data F%d@0x%05x, err: %d\n",
- func, addr, ret);
- else
- brcmf_dbg(SDIO, "failed to read data F%d@0x%05x, err: %d\n",
- func, addr, ret);
- }

return ret;
}
--
2.11.0

2017-07-19 19:11:04

by Ian Molton

[permalink] [raw]
Subject: [PATCH 10/34] brcmfmac: Rename bcmerror to err

Trivial cleanup of nasty variable name

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 7dd6af689ac8..f97b2234044f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -747,7 +747,7 @@ int
brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
u8 *data, uint size)
{
- int bcmerror = 0;
+ int err = 0;
struct sk_buff *pkt;
u32 sdaddr;
uint dsize;
@@ -772,8 +772,8 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
/* Do the transfer(s) */
while (size) {
/* Set the backplane window to include the start address */
- bcmerror = brcmf_sdiod_set_sbaddr_window(sdiodev, address);
- if (bcmerror)
+ err = brcmf_sdiod_set_sbaddr_window(sdiodev, address);
+ if (err)
break;

brcmf_dbg(SDIO, "%s %d bytes at offset 0x%08x in window 0x%08x\n",
@@ -786,9 +786,9 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
skb_put(pkt, dsize);
if (write)
memcpy(pkt->data, data, dsize);
- bcmerror = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_1, write,
+ err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_1, write,
sdaddr, pkt);
- if (bcmerror) {
+ if (err) {
brcmf_err("membytes transfer failed\n");
break;
}
@@ -815,7 +815,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

sdio_release_host(sdiodev->func[1]);

- return bcmerror;
+ return err;
}

int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn)
--
2.11.0

2017-07-19 19:08:39

by Ian Molton

[permalink] [raw]
Subject: [PATCH 05/34] brcmfmac: Remove dead IO code

The value passed to brcmf_sdiod_addrprep() is *always* 4
remove this parameter and the unused code to handle it.

Signed-off-by: Ian Molton <[email protected]>
---
.../net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index aee1ecb7260e..c3e909526a1d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -423,7 +423,7 @@ brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
}

static int
-brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, uint width, u32 *addr)
+brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, u32 *addr)
{
uint bar0 = *addr & ~SBSDIO_SB_OFT_ADDR_MASK;
int err = 0;
@@ -437,9 +437,7 @@ brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, uint width, u32 *addr)
}

*addr &= SBSDIO_SB_OFT_ADDR_MASK;
-
- if (width == 4)
- *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
+ *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

return 0;
}
@@ -465,7 +463,7 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
int retval;

brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
- retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
+ retval = brcmf_sdiod_addrprep(sdiodev, &addr);
if (retval)
goto done;

@@ -498,7 +496,7 @@ void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
int retval;

brcmf_dbg(SDIO, "addr:0x%08x, data:0x%08x\n", addr, data);
- retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
+ retval = brcmf_sdiod_addrprep(sdiodev, &addr);
if (retval)
goto done;

@@ -734,7 +732,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pkt->len);

- err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
+ err = brcmf_sdiod_addrprep(sdiodev, &addr);
if (err)
goto done;

@@ -755,7 +753,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n",
addr, pktq->qlen);

- err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
+ err = brcmf_sdiod_addrprep(sdiodev, &addr);
if (err)
goto done;

@@ -799,7 +797,7 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)

memcpy(mypkt->data, buf, nbytes);

- err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
+ err = brcmf_sdiod_addrprep(sdiodev, &addr);

if (!err)
err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true, addr,
@@ -819,7 +817,7 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pktq->qlen);

- err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
+ err = brcmf_sdiod_addrprep(sdiodev, &addr);
if (err)
return err;

--
2.11.0

2017-07-19 19:13:16

by Ian Molton

[permalink] [raw]
Subject: [PATCH 13/34] brcmfmac: Tidy register definitions a little

Trivial tidy of register definitions.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index 2f32c9270eaa..e2324a78249b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -51,17 +51,18 @@

/* function 0 vendor specific CCCR registers */

-#define SDIO_CCCR_BRCM_CARDCAP 0xf0
+#define SDIO_CCCR_BRCM_CARDCAP 0xf0
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT 0x02
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT 0x04
#define SDIO_CCCR_BRCM_CARDCAP_CMD_NODEC 0x08
+
#define SDIO_CCCR_BRCM_CARDCTRL 0xf1
#define SDIO_CCCR_BRCM_CARDCTRL_WLANRESET 0x02
-#define SDIO_CCCR_BRCM_SEPINT 0xf2

-#define SDIO_SEPINT_MASK 0x01
-#define SDIO_SEPINT_OE 0x02
-#define SDIO_SEPINT_ACT_HI 0x04
+#define SDIO_CCCR_BRCM_SEPINT 0xf2
+#define SDIO_SEPINT_MASK 0x01
+#define SDIO_SEPINT_OE 0x02
+#define SDIO_SEPINT_ACT_HI 0x04

/* function 1 miscellaneous registers */

--
2.11.0

2017-07-19 19:13:14

by Ian Molton

[permalink] [raw]
Subject: [PATCH 33/34] brcmfmac: Remove array of functions

Replace the array of functions with a pair of pointers to the
relevant functions.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 115 +++++++--------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 164 ++++++++++-----------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 15 +-
3 files changed, 144 insertions(+), 150 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 43a9c28738b3..d9fe2faf2b04 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -118,7 +118,7 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)

ret = request_irq(pdata->oob_irq_nr, brcmf_sdiod_oob_irqhandler,
pdata->oob_irq_flags, "brcmf_oob_intr",
- &sdiodev->func[1]->dev);
+ &sdiodev->func1->dev);
if (ret != 0) {
brcmf_err("request_irq failed %d\n", ret);
return ret;
@@ -132,7 +132,7 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
}
sdiodev->irq_wake = true;

- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);

if (sdiodev->bus_if->chip == BRCM_CC_43362_CHIP_ID) {
/* assign GPIO to SDIO core */
@@ -156,13 +156,13 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
if (pdata->oob_irq_flags & IRQF_TRIGGER_HIGH)
data |= SDIO_SEPINT_ACT_HI;
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, data, &ret);
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
} else {
brcmf_dbg(SDIO, "Entering\n");
- sdio_claim_host(sdiodev->func[1]);
- sdio_claim_irq(sdiodev->func[1], brcmf_sdiod_ib_irqhandler);
- sdio_claim_irq(sdiodev->func[2], brcmf_sdiod_dummy_irqhandler);
- sdio_release_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
+ sdio_claim_irq(sdiodev->func1, brcmf_sdiod_ib_irqhandler);
+ sdio_claim_irq(sdiodev->func2, brcmf_sdiod_dummy_irqhandler);
+ sdio_release_host(sdiodev->func1);
sdiodev->sd_irq_requested = true;
}

@@ -180,26 +180,26 @@ void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev)
struct brcmfmac_sdio_pd *pdata;

pdata = &sdiodev->settings->bus.sdio;
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL);
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, 0, NULL);
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);

sdiodev->oob_irq_requested = false;
if (sdiodev->irq_wake) {
disable_irq_wake(pdata->oob_irq_nr);
sdiodev->irq_wake = false;
}
- free_irq(pdata->oob_irq_nr, &sdiodev->func[1]->dev);
+ free_irq(pdata->oob_irq_nr, &sdiodev->func1->dev);
sdiodev->irq_en = false;
sdiodev->oob_irq_requested = false;
}

if (sdiodev->sd_irq_requested) {
- sdio_claim_host(sdiodev->func[1]);
- sdio_release_irq(sdiodev->func[2]);
- sdio_release_irq(sdiodev->func[1]);
- sdio_release_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
+ sdio_release_irq(sdiodev->func2);
+ sdio_release_irq(sdiodev->func1);
+ sdio_release_host(sdiodev->func1);
sdiodev->sd_irq_requested = false;
}
}
@@ -261,7 +261,7 @@ u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!retval)
- data = sdio_readl(sdiodev->func[1], addr, &retval);
+ data = sdio_readl(sdiodev->func1, addr, &retval);

out:
if (ret)
@@ -283,7 +283,7 @@ void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!retval)
- sdio_writel(sdiodev->func[1], data, addr, &retval);
+ sdio_writel(sdiodev->func1, data, addr, &retval);

out:
if (ret)
@@ -541,7 +541,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
addr &= SBSDIO_SB_OFT_ADDR_MASK;
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr, pkt);

done:
return err;
@@ -566,13 +566,13 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (pktq->qlen == 1)
- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr,
pktq->next);
else if (!sdiodev->sg_support) {
glom_skb = brcmu_pkt_buf_get_skb(totlen);
if (!glom_skb)
return -ENOMEM;
- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr,
glom_skb);
if (err)
goto done;
@@ -582,7 +582,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
skb_pull(glom_skb, skb->len);
}
} else
- err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], false, addr,
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, false, addr,
pktq);

done:
@@ -614,7 +614,7 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!err)
- err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2], addr, mypkt);
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func2, addr, mypkt);

brcmu_pkt_buf_free_skb(mypkt);

@@ -640,13 +640,13 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,

if (pktq->qlen == 1 || !sdiodev->sg_support)
skb_queue_walk(pktq, skb) {
- err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2],
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func2,
addr, skb);
if (err)
break;
}
else
- err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], true, addr,
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, true, addr,
pktq);

return err;
@@ -676,7 +676,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
else
dsize = size;

- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);

/* Do the transfer(s) */
while (size) {
@@ -696,11 +696,11 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

if (write) {
memcpy(pkt->data, data, dsize);
- err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[1],
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func1,
sdaddr, pkt);
}
else {
- err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[1],
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func1,
sdaddr, pkt);
}

@@ -724,7 +724,7 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

dev_kfree_skb(pkt);

- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);

return err;
}
@@ -748,7 +748,7 @@ void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
uint nents;
int err;

- func = sdiodev->func[2];
+ func = sdiodev->func2;
host = func->card->host;
sdiodev->sg_support = host->max_segs > 1;
max_blocks = min_t(uint, host->max_blk_count, 511u);
@@ -809,17 +809,17 @@ static int brcmf_sdiod_freezer_on(struct brcmf_sdio_dev *sdiodev)
brcmf_sdio_trigger_dpc(sdiodev->bus);
wait_event(sdiodev->freezer->thread_freeze,
atomic_read(expect) == sdiodev->freezer->frozen_count);
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
res = brcmf_sdio_sleep(sdiodev->bus, true);
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
return res;
}

static void brcmf_sdiod_freezer_off(struct brcmf_sdio_dev *sdiodev)
{
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
brcmf_sdio_sleep(sdiodev->bus, false);
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
atomic_set(&sdiodev->freezer->freezing, 0);
complete_all(&sdiodev->freezer->resumed);
}
@@ -869,19 +869,19 @@ static int brcmf_sdiod_remove(struct brcmf_sdio_dev *sdiodev)
brcmf_sdiod_freezer_detach(sdiodev);

/* Disable Function 2 */
- sdio_claim_host(sdiodev->func[2]);
- sdio_disable_func(sdiodev->func[2]);
- sdio_release_host(sdiodev->func[2]);
+ sdio_claim_host(sdiodev->func2);
+ sdio_disable_func(sdiodev->func2);
+ sdio_release_host(sdiodev->func2);

/* Disable Function 1 */
- sdio_claim_host(sdiodev->func[1]);
- sdio_disable_func(sdiodev->func[1]);
- sdio_release_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
+ sdio_disable_func(sdiodev->func1);
+ sdio_release_host(sdiodev->func1);

sg_free_table(&sdiodev->sgtable);
sdiodev->sbwad = 0;

- pm_runtime_allow(sdiodev->func[1]->card->host->parent);
+ pm_runtime_allow(sdiodev->func1->card->host->parent);
return 0;
}

@@ -897,29 +897,27 @@ static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
{
int ret = 0;

- sdiodev->num_funcs = 2;
+ sdio_claim_host(sdiodev->func1);

- sdio_claim_host(sdiodev->func[1]);
-
- ret = sdio_set_block_size(sdiodev->func[1], SDIO_FUNC1_BLOCKSIZE);
+ ret = sdio_set_block_size(sdiodev->func1, SDIO_FUNC1_BLOCKSIZE);
if (ret) {
brcmf_err("Failed to set F1 blocksize\n");
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
goto out;
}
- ret = sdio_set_block_size(sdiodev->func[2], SDIO_FUNC2_BLOCKSIZE);
+ ret = sdio_set_block_size(sdiodev->func2, SDIO_FUNC2_BLOCKSIZE);
if (ret) {
brcmf_err("Failed to set F2 blocksize\n");
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
goto out;
}

/* increase F2 timeout */
- sdiodev->func[2]->enable_timeout = SDIO_WAIT_F2RDY;
+ sdiodev->func2->enable_timeout = SDIO_WAIT_F2RDY;

/* Enable Function 1 */
- ret = sdio_enable_func(sdiodev->func[1]);
- sdio_release_host(sdiodev->func[1]);
+ ret = sdio_enable_func(sdiodev->func1);
+ sdio_release_host(sdiodev->func1);
if (ret) {
brcmf_err("Failed to enable F1: err=%d\n", ret);
goto out;
@@ -935,7 +933,7 @@ static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
ret = -ENODEV;
goto out;
}
- brcmf_sdiod_host_fixup(sdiodev->func[2]->card->host);
+ brcmf_sdiod_host_fixup(sdiodev->func2->card->host);
out:
if (ret)
brcmf_sdiod_remove(sdiodev);
@@ -1022,16 +1020,15 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
/* store refs to functions used. mmc_card does
* not hold the F0 function pointer.
*/
- sdiodev->func[0] = NULL;
- sdiodev->func[1] = func->card->sdio_func[0];
- sdiodev->func[2] = func;
+ sdiodev->func1 = func->card->sdio_func[0];
+ sdiodev->func2 = func;

sdiodev->bus_if = bus_if;
bus_if->bus_priv.sdio = sdiodev;
bus_if->proto_type = BRCMF_PROTO_BCDC;
dev_set_drvdata(&func->dev, bus_if);
- dev_set_drvdata(&sdiodev->func[1]->dev, bus_if);
- sdiodev->dev = &sdiodev->func[1]->dev;
+ dev_set_drvdata(&sdiodev->func1->dev, bus_if);
+ sdiodev->dev = &sdiodev->func1->dev;

brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_DOWN);

@@ -1047,7 +1044,7 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,

fail:
dev_set_drvdata(&func->dev, NULL);
- dev_set_drvdata(&sdiodev->func[1]->dev, NULL);
+ dev_set_drvdata(&sdiodev->func1->dev, NULL);
kfree(sdiodev);
kfree(bus_if);
return err;
@@ -1076,8 +1073,8 @@ static void brcmf_ops_sdio_remove(struct sdio_func *func)
/* only proceed with rest of cleanup if func 1 */
brcmf_sdiod_remove(sdiodev);

- dev_set_drvdata(&sdiodev->func[1]->dev, NULL);
- dev_set_drvdata(&sdiodev->func[2]->dev, NULL);
+ dev_set_drvdata(&sdiodev->func1->dev, NULL);
+ dev_set_drvdata(&sdiodev->func2->dev, NULL);

kfree(bus_if);
kfree(sdiodev);
@@ -1122,7 +1119,7 @@ static int brcmf_ops_sdio_suspend(struct device *dev)
else
sdio_flags |= MMC_PM_WAKE_SDIO_IRQ;
}
- if (sdio_set_host_pm_flags(sdiodev->func[1], sdio_flags))
+ if (sdio_set_host_pm_flags(sdiodev->func1, sdio_flags))
brcmf_err("Failed to set pm_flags %x\n", sdio_flags);
return 0;
}
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index c94625b6549f..5f90f747e76a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -972,7 +972,7 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
struct sdpcm_shared_le sh_le;
__le32 addr_le;

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_bus_sleep(bus, false, false);

/*
@@ -1006,7 +1006,7 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
if (rv < 0)
goto fail;

- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

/* Endianness */
sh->flags = le32_to_cpu(sh_le.flags);
@@ -1028,7 +1028,7 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
fail:
brcmf_err("unable to obtain sdpcm_shared info: rv=%d (addr=0x%x)\n",
rv, addr);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
return rv;
}

@@ -1144,7 +1144,7 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
rtx ? ", send NAK" : "");

if (abort)
- brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func[2]);
+ brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func2);

brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, &err);
bus->sdcnt.f1regdata++;
@@ -1193,7 +1193,7 @@ static void brcmf_sdio_txfail(struct brcmf_sdio *bus)
brcmf_err("sdio error, abort command and terminate frame\n");
bus->sdcnt.tx_sderrs++;

- brcmf_sdiod_abort(sdiodev, sdiodev->func[2]);
+ brcmf_sdiod_abort(sdiodev, sdiodev->func2);
brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, NULL);
bus->sdcnt.f1regdata++;

@@ -1549,10 +1549,10 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
* read directly into the chained packet, or allocate a large
* packet and and copy into the chain.
*/
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
errcode = brcmf_sdiod_recv_chain(bus->sdiodev,
&bus->glom, dlen);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
bus->sdcnt.f2rxdata++;

/* On failure, kill the superframe */
@@ -1560,11 +1560,11 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
brcmf_err("glom read of %d bytes failed: %d\n",
dlen, errcode);

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_rxfail(bus, true, false);
bus->sdcnt.rxglomfail++;
brcmf_sdio_free_glom(bus);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
return 0;
}

@@ -1574,10 +1574,10 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)

rd_new.seq_num = rxseq;
rd_new.len = dlen;
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new,
BRCMF_SDIO_FT_SUPER);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
bus->cur_read.len = rd_new.len_nxtfrm << 4;

/* Remove superframe header, remember offset */
@@ -1593,10 +1593,10 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)

rd_new.len = pnext->len;
rd_new.seq_num = rxseq++;
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new,
BRCMF_SDIO_FT_SUB);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
brcmf_dbg_hex_dump(BRCMF_GLOM_ON(),
pnext->data, 32, "subframe:\n");

@@ -1605,11 +1605,11 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)

if (errcode) {
/* Terminate frame on error */
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_rxfail(bus, true, false);
bus->sdcnt.rxglomfail++;
brcmf_sdio_free_glom(bus);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
bus->cur_read.len = 0;
return 0;
}
@@ -1817,7 +1817,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)

rd->len_left = rd->len;
/* read header first for unknow frame length */
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
if (!rd->len) {
ret = brcmf_sdiod_recv_buf(bus->sdiodev,
bus->rxhdr, BRCMF_FIRSTREAD);
@@ -1827,7 +1827,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
ret);
bus->sdcnt.rx_hdrfail++;
brcmf_sdio_rxfail(bus, true, true);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
continue;
}

@@ -1837,7 +1837,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)

if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd,
BRCMF_SDIO_FT_NORMAL)) {
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
if (!bus->rxpending)
break;
else
@@ -1853,7 +1853,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
rd->len_nxtfrm = 0;
/* treat all packet as event if we don't know */
rd->channel = SDPCM_EVENT_CHANNEL;
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
continue;
}
rd->len_left = rd->len > BRCMF_FIRSTREAD ?
@@ -1870,7 +1870,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
brcmf_err("brcmu_pkt_buf_get_skb failed\n");
brcmf_sdio_rxfail(bus, false,
RETRYCHAN(rd->channel));
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
continue;
}
skb_pull(pkt, head_read);
@@ -1878,16 +1878,16 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)

ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt);
bus->sdcnt.f2rxdata++;
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

if (ret < 0) {
brcmf_err("read %d bytes from channel %d failed: %d\n",
rd->len, rd->channel, ret);
brcmu_pkt_buf_free_skb(pkt);
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_rxfail(bus, true,
RETRYCHAN(rd->channel));
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
continue;
}

@@ -1898,7 +1898,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
} else {
memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN);
rd_new.seq_num = rd->seq_num;
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new,
BRCMF_SDIO_FT_NORMAL)) {
rd->len = 0;
@@ -1911,11 +1911,11 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
roundup(rd_new.len, 16) >> 4);
rd->len = 0;
brcmf_sdio_rxfail(bus, true, true);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
brcmu_pkt_buf_free_skb(pkt);
continue;
}
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
rd->len_nxtfrm = rd_new.len_nxtfrm;
rd->channel = rd_new.channel;
rd->dat_offset = rd_new.dat_offset;
@@ -1931,9 +1931,9 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
rd_new.seq_num);
/* Force retry w/normal header read */
rd->len = 0;
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_rxfail(bus, false, true);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
brcmu_pkt_buf_free_skb(pkt);
continue;
}
@@ -1956,9 +1956,9 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
} else {
brcmf_err("%s: glom superframe w/o "
"descriptor!\n", __func__);
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_rxfail(bus, false, false);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
}
/* prepare the descriptor for the next read */
rd->len = rd->len_nxtfrm << 4;
@@ -2055,7 +2055,7 @@ static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus,
int ntail, ret;

sdiodev = bus->sdiodev;
- blksize = sdiodev->func[2]->cur_blksize;
+ blksize = sdiodev->func2->cur_blksize;
/* sg entry alignment should be a divisor of block size */
WARN_ON(blksize % bus->sgentry_align);

@@ -2234,14 +2234,14 @@ static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
if (ret)
goto done;

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq);
bus->sdcnt.f2txdata++;

if (ret < 0)
brcmf_sdio_txfail(bus);

- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

done:
brcmf_sdio_txpkt_postp(bus, pktq);
@@ -2297,10 +2297,10 @@ static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes)
/* In poll mode, need to check for other events */
if (!bus->intr) {
/* Check device status, signal pending interrupt */
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
intstatus = brcmf_sdiod_readl(bus->sdiodev, core->base +
__sd_reg(intstatus), &ret);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
bus->sdcnt.f2txdata++;
if (ret != 0)
break;
@@ -2400,7 +2400,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
}

if (sdiodev->state != BRCMF_SDIOD_NOMEDIUM) {
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);

/* Enable clock for device interrupts */
brcmf_sdio_bus_sleep(bus, false, false);
@@ -2423,13 +2423,13 @@ static void brcmf_sdio_bus_stop(struct device *dev)

/* Turn off the bus (F2), free any pending packets */
brcmf_dbg(INTR, "disable SDIO interrupts\n");
- sdio_disable_func(sdiodev->func[2]);
+ sdio_disable_func(sdiodev->func2);

/* Clear any pending interrupts now that F2 is disabled */
brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(intstatus),
local_hostintmask, NULL);

- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
}
/* Clear the data packet queues */
brcmu_pktq_flush(&bus->txq, true, NULL, NULL);
@@ -2501,7 +2501,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)

brcmf_dbg(TRACE, "Enter\n");

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);

/* If waiting for HTAVAIL, check status */
if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) {
@@ -2564,7 +2564,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
intstatus |= brcmf_sdio_hostmail(bus);
}

- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

/* Generally don't ask for these, can get CRC errors... */
if (intstatus & I_WR_OOSYNC) {
@@ -2607,7 +2607,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)

if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) &&
data_ok(bus)) {
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
if (bus->ctrl_frame_stat) {
err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf,
bus->ctrl_frame_len);
@@ -2615,7 +2615,7 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
wmb();
bus->ctrl_frame_stat = false;
}
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
brcmf_sdio_wait_event_wakeup(bus);
}
/* Send queued frames (limit 1 if rx may still be pending) */
@@ -2631,14 +2631,14 @@ static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
brcmf_err("failed backplane access over SDIO, halting operation\n");
atomic_set(&bus->intstatus, 0);
if (bus->ctrl_frame_stat) {
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
if (bus->ctrl_frame_stat) {
bus->ctrl_frame_err = -ENODEV;
wmb();
bus->ctrl_frame_stat = false;
brcmf_sdio_wait_event_wakeup(bus);
}
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
}
} else if (atomic_read(&bus->intstatus) ||
atomic_read(&bus->ipend) > 0 ||
@@ -2853,13 +2853,13 @@ brcmf_sdio_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
CTL_DONE_TIMEOUT);
ret = 0;
if (bus->ctrl_frame_stat) {
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
if (bus->ctrl_frame_stat) {
brcmf_dbg(SDIO, "ctrl_frame timeout\n");
bus->ctrl_frame_stat = false;
ret = -ETIMEDOUT;
}
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
}
if (!ret) {
brcmf_dbg(SDIO, "ctrl_frame complete, err=%d\n",
@@ -2983,7 +2983,7 @@ static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus,
return 0;
}

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
if (sh->assert_file_addr != 0) {
error = brcmf_sdiod_ramrw(bus->sdiodev, false,
sh->assert_file_addr, (u8 *)file, 80);
@@ -2996,7 +2996,7 @@ static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus,
if (error < 0)
return error;
}
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

seq_printf(seq, "dongle assert: %s:%d: assert(%s)\n",
file, sh->assert_line, expr);
@@ -3270,7 +3270,7 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,
int bcmerror;
u32 rstvec;

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_clkctl(bus, CLK_AVAIL, false);

rstvec = get_unaligned_le32(fw->data);
@@ -3299,7 +3299,7 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,

err:
brcmf_sdio_clkctl(bus, CLK_SDONLY, false);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
return bcmerror;
}

@@ -3413,7 +3413,7 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
if (sdiodev->sg_support) {
bus->txglom = false;
value = 1;
- pad_size = bus->sdiodev->func[2]->cur_blksize << 1;
+ pad_size = bus->sdiodev->func2->cur_blksize << 1;
err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom",
&value, sizeof(u32));
if (err < 0) {
@@ -3455,7 +3455,7 @@ static int brcmf_sdio_bus_get_memdump(struct device *dev, void *data,

address = bus->ci->rambase;
offset = err = 0;
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);
while (offset < mem_size) {
len = ((offset + MEMBLOCK) < mem_size) ? MEMBLOCK :
mem_size - offset;
@@ -3471,7 +3471,7 @@ static int brcmf_sdio_bus_get_memdump(struct device *dev, void *data,
}

done:
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
return err;
}

@@ -3528,11 +3528,11 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
if (!bus->dpc_triggered) {
u8 devpend;

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
devpend = brcmf_sdiod_func0_rb(bus->sdiodev,
SDIO_CCCR_INTx,
NULL);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
intstatus = devpend & (INTR_STATUS_FUNC1 |
INTR_STATUS_FUNC2);
}
@@ -3558,13 +3558,13 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
bus->console.count += jiffies_to_msecs(BRCMF_WD_POLL);
if (bus->console.count >= bus->console_interval) {
bus->console.count -= bus->console_interval;
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
/* Make sure backplane clock is on */
brcmf_sdio_bus_sleep(bus, false, false);
if (brcmf_sdio_readconsole(bus) < 0)
/* stop on error */
bus->console_interval = 0;
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
}
}
#endif /* DEBUG */
@@ -3577,11 +3577,11 @@ static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
bus->idlecount++;
if (bus->idlecount > bus->idletime) {
brcmf_dbg(SDIO, "idle\n");
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_wd_timer(bus, false);
bus->idlecount = 0;
brcmf_sdio_bus_sleep(bus, true, false);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
}
} else {
bus->idlecount = 0;
@@ -3751,8 +3751,8 @@ static u32 brcmf_sdio_buscore_read32(void *ctx, u32 addr)
/* Force 4339 chips over rev2 to use the same ID */
/* This is borderline tolerable whilst there is only two exceptions */
/* But could be handled better */
- if ((sdiodev->func[1]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 ||
- sdiodev->func[1]->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
+ if ((sdiodev->func1->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 ||
+ sdiodev->func1->device == SDIO_DEVICE_ID_BROADCOM_4339) &&
addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) {

rev = (val & CID_REV_MASK) >> CID_REV_SHIFT;
@@ -3792,7 +3792,7 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
u32 drivestrength;

sdiodev = bus->sdiodev;
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);

/*
* Force PLL off until brcmf_chip_attach()
@@ -3854,8 +3854,8 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
/* wowl can be supported when KEEP_POWER is true and (WAKE_SDIO_IRQ
* is true or when platform data OOB irq is true).
*/
- if ((sdio_get_host_pm_caps(sdiodev->func[1]) & MMC_PM_KEEP_POWER) &&
- ((sdio_get_host_pm_caps(sdiodev->func[1]) & MMC_PM_WAKE_SDIO_IRQ) ||
+ if ((sdio_get_host_pm_caps(sdiodev->func1) & MMC_PM_KEEP_POWER) &&
+ ((sdio_get_host_pm_caps(sdiodev->func1) & MMC_PM_WAKE_SDIO_IRQ) ||
(sdiodev->settings->bus.sdio.oob_irq_supported)))
sdiodev->bus_if->wowl_supported = true;
#endif
@@ -3894,7 +3894,7 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
if (err)
goto fail;

- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);

brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN);

@@ -3915,7 +3915,7 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
return true;

fail:
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
return false;
}

@@ -4002,7 +4002,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
bus->sdcnt.tickcnt = 0;
brcmf_sdio_wd_timer(bus, true);

- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);

/* Make sure backplane clock is on, needed to generate F2 interrupt */
brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
@@ -4024,7 +4024,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailboxdata),
SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, NULL);

- err = sdio_enable_func(sdiodev->func[2]);
+ err = sdio_enable_func(sdiodev->func2);


brcmf_dbg(INFO, "enable F2: err=%d\n", err);
@@ -4040,7 +4040,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
} else {
/* Disable F2 again */
- sdio_disable_func(sdiodev->func[2]);
+ sdio_disable_func(sdiodev->func2);
goto release;
}

@@ -4064,7 +4064,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
if (err != 0)
brcmf_sdio_clkctl(bus, CLK_NONE, false);

- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);

err = brcmf_bus_started(dev);
if (err != 0) {
@@ -4074,11 +4074,11 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
return;

release:
- sdio_release_host(sdiodev->func[1]);
+ sdio_release_host(sdiodev->func1);
fail:
brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), err);
device_release_driver(dev);
- device_release_driver(&sdiodev->func[2]->dev);
+ device_release_driver(&sdiodev->func2->dev);
}

struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
@@ -4104,7 +4104,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)

/* single-threaded workqueue */
wq = alloc_ordered_workqueue("brcmf_wq/%s", WQ_MEM_RECLAIM,
- dev_name(&sdiodev->func[1]->dev));
+ dev_name(&sdiodev->func1->dev));
if (!wq) {
brcmf_err("insufficient memory to create txworkqueue\n");
goto fail;
@@ -4133,7 +4133,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
init_completion(&bus->watchdog_wait);
bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread,
bus, "brcmf_wdog/%s",
- dev_name(&sdiodev->func[1]->dev));
+ dev_name(&sdiodev->func1->dev));
if (IS_ERR(bus->watchdog_tsk)) {
pr_warn("brcmf_watchdog thread failed to start\n");
bus->watchdog_tsk = NULL;
@@ -4164,7 +4164,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
brcmf_sdiod_sgtable_alloc(bus->sdiodev);

/* Query the F2 block size, set roundup accordingly */
- bus->blocksize = bus->sdiodev->func[2]->cur_blksize;
+ bus->blocksize = bus->sdiodev->func2->cur_blksize;
bus->roundup = min(max_roundup, bus->blocksize);

/* Allocate buffers */
@@ -4180,17 +4180,17 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
}
}

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);

/* Disable F2 to clear any intermediate frame state on the dongle */
- sdio_disable_func(bus->sdiodev->func[2]);
+ sdio_disable_func(bus->sdiodev->func2);

bus->rxflow = false;

/* Done with backplane-dependent accesses, can drop clock... */
brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);

- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

/* ...and initialize clock/power states */
bus->clkstate = CLK_SDONLY;
@@ -4242,7 +4242,7 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)

if (bus->ci) {
if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) {
- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
brcmf_sdio_wd_timer(bus, false);
brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
/* Leave the device in state where it is
@@ -4252,7 +4252,7 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
msleep(20);
brcmf_chip_set_passive(bus->ci);
brcmf_sdio_clkctl(bus, CLK_NONE, false);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);
}
brcmf_chip_detach(bus->ci);
}
@@ -4299,9 +4299,9 @@ int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep)
{
int ret;

- sdio_claim_host(bus->sdiodev->func[1]);
+ sdio_claim_host(bus->sdiodev->func1);
ret = brcmf_sdio_bus_sleep(bus, sleep, false);
- sdio_release_host(bus->sdiodev->func[1]);
+ sdio_release_host(bus->sdiodev->func1);

return ret;
}
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index bc9e9bcf40e2..cb93289caf8c 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -21,9 +21,6 @@
#include <linux/firmware.h>
#include "firmware.h"

-/* Maximum number of I/O funcs */
-#define NUM_SDIO_FUNCS 3
-
#define SDIOD_FBR_SIZE 0x100

/* io_en */
@@ -173,8 +170,8 @@ struct brcmf_sdio;
struct brcmf_sdiod_freezer;

struct brcmf_sdio_dev {
- struct sdio_func *func[NUM_SDIO_FUNCS];
- u8 num_funcs; /* Supported funcs on client */
+ struct sdio_func *func1;
+ struct sdio_func *func2;
u32 sbwad; /* Save backplane window address */
struct brcmf_core *cc_core; /* chipcommon core info struct */
struct brcmf_sdio *bus;
@@ -295,17 +292,17 @@ void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev);
/* SDIO device register access interface */
/* Functions for accessing SDIO Function 0 */
#define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
- sdio_f0_readb((sdiodev)->func[1], (addr), (r))
+ sdio_f0_readb((sdiodev)->func1, (addr), (r))

#define brcmf_sdiod_func0_wb(sdiodev, addr, v, ret) \
- sdio_f0_writeb((sdiodev)->func[1], (v), (addr), (ret))
+ sdio_f0_writeb((sdiodev)->func1, (v), (addr), (ret))

/* Functions for accessing SDIO Function 1 */
#define brcmf_sdiod_readb(sdiodev, addr, r) \
- sdio_readb((sdiodev)->func[1], (addr), (r))
+ sdio_readb((sdiodev)->func1, (addr), (r))

#define brcmf_sdiod_writeb(sdiodev, addr, v, ret) \
- sdio_writeb((sdiodev)->func[1], (v), (addr), (ret))
+ sdio_writeb((sdiodev)->func1, (v), (addr), (ret))

u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr, u32 data, int *ret);
--
2.11.0

2017-07-19 19:15:42

by Ian Molton

[permalink] [raw]
Subject: [PATCH 30/34] brcmfmac: Correctly handle accesses to SDIO func0

Rather than workaround the restrictions on func0 addressing in the
driver, set MMC_QUIRK_LENIENT_FN0

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 4 ++++
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index dcdebe8e8ff4..42b09a301f5f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -994,6 +994,10 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
brcmf_dbg(SDIO, "Function#: %d\n", func->num);

dev = &func->dev;
+
+ /* Set MMC_QUIRK_LENIENT_FN0 for this card */
+ func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
+
/* prohibit ACPI power management for this device */
brcmf_sdiod_acpi_set_power_manageable(dev, 0);

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index a5a05d1a34bf..d0dd69454bbd 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -297,10 +297,10 @@ void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev);
/* SDIO device register access interface */
/* Functions for accessing SDIO Function 0 */
#define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
- sdio_readb((sdiodev)->func[0], (addr), (r))
+ sdio_f0_readb((sdiodev)->func[0], (addr), (r))

#define brcmf_sdiod_func0_wb(sdiodev, addr, v, ret) \
- sdio_writeb((sdiodev)->func[0], (v), (addr), (ret))
+ sdio_f0_writeb((sdiodev)->func[0], (v), (addr), (ret))

/* Functions for accessing SDIO Function 1 */
#define brcmf_sdiod_readb(sdiodev, addr, r) \
--
2.11.0

2017-07-19 19:13:25

by Ian Molton

[permalink] [raw]
Subject: [PATCH 18/34] brcmfmac: Rename SOC_AI to SOC_AXI

This #define is poorly named. Correct it.

At the same time, convert the if..elseif...else it is used in to a switch
for clarity.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index 05f22ff81d60..7b8ba7192e1a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -30,7 +30,7 @@

/* SOC Interconnect types (aka chip types) */
#define SOCI_SB 0
-#define SOCI_AI 1
+#define SOCI_AXI 1

/* PL-368 DMP definitions */
#define DMP_DESC_TYPE_MSK 0x0000000F
@@ -927,7 +927,8 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name,
ci->pub.chiprev);

- if (socitype == SOCI_SB) {
+ switch(socitype) {
+ case SOCI_SB:
if (ci->pub.chip != BRCM_CC_4329_CHIP_ID) {
brcmf_err("SB chip is not supported\n");
return -ENODEV;
@@ -951,13 +952,15 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)

core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0);
brcmf_chip_sb_corerev(ci, core);
- } else if (socitype == SOCI_AI) {
+ break;
+ case SOCI_AXI:
ci->iscoreup = brcmf_chip_ai_iscoreup;
ci->coredisable = brcmf_chip_ai_coredisable;
ci->resetcore = brcmf_chip_ai_resetcore;

brcmf_chip_dmp_erom_scan(ci);
- } else {
+ break;
+ default:
brcmf_err("chip backplane type %u is not supported\n",
socitype);
return -ENODEV;
--
2.11.0

2017-07-19 19:13:20

by Ian Molton

[permalink] [raw]
Subject: [PATCH 32/34] brcmfmac: Replace function index with function pointer

In preparation for removing the function array, remove all code that
refers to function by index and replace with pointers to the function
itself.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 69 +++++++++++-----------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 14 ++---
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 14 ++---
3 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 89cf71d98cee..43a9c28738b3 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -148,7 +148,7 @@ int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)

/* must configure SDIO_CCCR_IENx to enable irq */
data = brcmf_sdiod_func0_rb(sdiodev, SDIO_CCCR_IENx, &ret);
- data |= 1 << SDIO_FUNC_1 | 1 << SDIO_FUNC_2 | 1;
+ data |= SDIO_CCCR_IEN_FUNC1 | SDIO_CCCR_IEN_FUNC2 | SDIO_CCCR_IEN_BIT0;
brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, data, &ret);

/* redirect, configure and enable io for interrupt signal */
@@ -290,7 +290,8 @@ void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
*ret = retval;
}

-static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev, uint fn,
+static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev,
+ struct sdio_func *func,
u32 addr, struct sk_buff *pkt)
{
unsigned int req_sz;
@@ -300,13 +301,12 @@ static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev, uint fn,
req_sz = pkt->len + 3;
req_sz &= (uint)~3;

- if (fn == 1)
- err = sdio_memcpy_fromio(sdiodev->func[fn],
- ((u8 *)(pkt->data)), addr, req_sz);
+ if (func->num == 1)
+ err = sdio_memcpy_fromio(func, ((u8 *)(pkt->data)), addr,
+ req_sz);
else
/* function 2 read is FIFO operation */
- err = sdio_readsb(sdiodev->func[fn],
- ((u8 *)(pkt->data)), addr, req_sz);
+ err = sdio_readsb(func, ((u8 *)(pkt->data)), addr, req_sz);

if (err == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
@@ -314,7 +314,8 @@ static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev, uint fn,
return err;
}

-static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
+static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev,
+ struct sdio_func *func,
u32 addr, struct sk_buff *pkt)
{
unsigned int req_sz;
@@ -324,8 +325,7 @@ static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
req_sz = pkt->len + 3;
req_sz &= (uint)~3;

- err = sdio_memcpy_toio(sdiodev->func[fn], addr,
- ((u8 *)(pkt->data)), req_sz);
+ err = sdio_memcpy_toio(func, addr, ((u8 *)(pkt->data)), req_sz);

if (err == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
@@ -336,7 +336,7 @@ static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
/**
* brcmf_sdiod_sglist_rw - SDIO interface function for block data access
* @sdiodev: brcmfmac sdio device
- * @fn: SDIO function number
+ * @func: SDIO function
* @write: direction flag
* @addr: dongle memory address as source/destination
* @pkt: skb pointer
@@ -345,9 +345,10 @@ static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
* stack for block data access. It assumes that the skb passed down by the
* caller has already been padded and aligned.
*/
-static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
- bool write, u32 addr,
- struct sk_buff_head *pktlist)
+static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev,
+ struct sdio_func *func,
+ bool write, u32 addr,
+ struct sk_buff_head *pktlist)
{
unsigned int req_sz, func_blk_sz, sg_cnt, sg_data_sz, pkt_offset;
unsigned int max_req_sz, orig_offset, dst_offset;
@@ -371,7 +372,7 @@ static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
req_sz = 0;
skb_queue_walk(pktlist, pkt_next)
req_sz += pkt_next->len;
- req_sz = ALIGN(req_sz, sdiodev->func[fn]->cur_blksize);
+ req_sz = ALIGN(req_sz, func->cur_blksize);
while (req_sz > PAGE_SIZE) {
pkt_next = brcmu_pkt_buf_get_skb(PAGE_SIZE);
if (pkt_next == NULL) {
@@ -390,7 +391,7 @@ static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
target_list = &local_list;
}

- func_blk_sz = sdiodev->func[fn]->cur_blksize;
+ func_blk_sz = func->cur_blksize;
max_req_sz = sdiodev->max_request_size;
max_seg_cnt = min_t(unsigned short, sdiodev->max_segment_count,
target_list->qlen);
@@ -407,10 +408,10 @@ static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
mmc_dat.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
mmc_cmd.opcode = SD_IO_RW_EXTENDED;
mmc_cmd.arg = write ? 1<<31 : 0; /* write flag */
- mmc_cmd.arg |= (fn & 0x7) << 28; /* SDIO func num */
+ mmc_cmd.arg |= (func->num & 0x7) << 28; /* SDIO func num */
mmc_cmd.arg |= 1<<27; /* block mode */
/* for function 1 the addr will be incremented */
- mmc_cmd.arg |= (fn == 1) ? 1<<26 : 0;
+ mmc_cmd.arg |= (func->num == 1) ? 1<<26 : 0;
mmc_cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
mmc_req.cmd = &mmc_cmd;
mmc_req.data = &mmc_dat;
@@ -456,11 +457,11 @@ static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
mmc_cmd.arg |= (addr & 0x1FFFF) << 9; /* address */
mmc_cmd.arg |= mmc_dat.blocks & 0x1FF; /* block count */
/* incrementing addr for function 1 */
- if (fn == 1)
+ if (func->num == 1)
addr += req_sz;

- mmc_set_data_timeout(&mmc_dat, sdiodev->func[fn]->card);
- mmc_wait_for_req(sdiodev->func[fn]->card->host, &mmc_req);
+ mmc_set_data_timeout(&mmc_dat, func->card);
+ mmc_wait_for_req(func->card->host, &mmc_req);

ret = mmc_cmd.error ? mmc_cmd.error : mmc_dat.error;
if (ret == -ENOMEDIUM) {
@@ -540,7 +541,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
addr &= SBSDIO_SB_OFT_ADDR_MASK;
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

- err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr, pkt);

done:
return err;
@@ -565,13 +566,13 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (pktq->qlen == 1)
- err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
pktq->next);
else if (!sdiodev->sg_support) {
glom_skb = brcmu_pkt_buf_get_skb(totlen);
if (!glom_skb)
return -ENOMEM;
- err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
glom_skb);
if (err)
goto done;
@@ -581,7 +582,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
skb_pull(glom_skb, skb->len);
}
} else
- err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, false, addr,
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], false, addr,
pktq);

done:
@@ -613,7 +614,7 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;

if (!err)
- err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2], addr, mypkt);

brcmu_pkt_buf_free_skb(mypkt);

@@ -639,13 +640,13 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,

if (pktq->qlen == 1 || !sdiodev->sg_support)
skb_queue_walk(pktq, skb) {
- err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2,
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2],
addr, skb);
if (err)
break;
}
else
- err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, true, addr,
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], true, addr,
pktq);

return err;
@@ -695,11 +696,11 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,

if (write) {
memcpy(pkt->data, data, dsize);
- err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_1,
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[1],
sdaddr, pkt);
}
else {
- err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_1,
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[1],
sdaddr, pkt);
}

@@ -728,12 +729,12 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
return err;
}

-int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn)
+int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func)
{
brcmf_dbg(SDIO, "Enter\n");

/* Issue abort cmd52 command through F0 */
- brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_ABORT, fn, NULL);
+ brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_ABORT, func->num, NULL);

brcmf_dbg(SDIO, "Exit\n");
return 0;
@@ -1104,7 +1105,7 @@ static int brcmf_ops_sdio_suspend(struct device *dev)

func = container_of(dev, struct sdio_func, dev);
brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
- if (func->num != SDIO_FUNC_1)
+ if (func->num != 1)
return 0;


@@ -1133,7 +1134,7 @@ static int brcmf_ops_sdio_resume(struct device *dev)
struct sdio_func *func = container_of(dev, struct sdio_func, dev);

brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
- if (func->num != SDIO_FUNC_2)
+ if (func->num != 2)
return 0;

brcmf_sdiod_freezer_off(sdiodev);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 9b8bd870c1fc..c94625b6549f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -1144,7 +1144,7 @@ static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
rtx ? ", send NAK" : "");

if (abort)
- brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2);
+ brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func[2]);

brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, &err);
bus->sdcnt.f1regdata++;
@@ -1193,7 +1193,7 @@ static void brcmf_sdio_txfail(struct brcmf_sdio *bus)
brcmf_err("sdio error, abort command and terminate frame\n");
bus->sdcnt.tx_sderrs++;

- brcmf_sdiod_abort(sdiodev, SDIO_FUNC_2);
+ brcmf_sdiod_abort(sdiodev, sdiodev->func[2]);
brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, NULL);
bus->sdcnt.f1regdata++;

@@ -2055,7 +2055,7 @@ static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus,
int ntail, ret;

sdiodev = bus->sdiodev;
- blksize = sdiodev->func[SDIO_FUNC_2]->cur_blksize;
+ blksize = sdiodev->func[2]->cur_blksize;
/* sg entry alignment should be a divisor of block size */
WARN_ON(blksize % bus->sgentry_align);

@@ -2423,7 +2423,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)

/* Turn off the bus (F2), free any pending packets */
brcmf_dbg(INTR, "disable SDIO interrupts\n");
- sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
+ sdio_disable_func(sdiodev->func[2]);

/* Clear any pending interrupts now that F2 is disabled */
brcmf_sdiod_writel(sdiodev, core->base + __sd_reg(intstatus),
@@ -4024,7 +4024,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
brcmf_sdiod_writel(sdiod, core->base + __sd_reg(tosbmailboxdata),
SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, NULL);

- err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);
+ err = sdio_enable_func(sdiodev->func[2]);


brcmf_dbg(INFO, "enable F2: err=%d\n", err);
@@ -4040,7 +4040,7 @@ static void brcmf_sdio_firmware_callback(struct device *dev, int err,
brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
} else {
/* Disable F2 again */
- sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
+ sdio_disable_func(sdiodev->func[2]);
goto release;
}

@@ -4183,7 +4183,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
sdio_claim_host(bus->sdiodev->func[1]);

/* Disable F2 to clear any intermediate frame state on the dongle */
- sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]);
+ sdio_disable_func(bus->sdiodev->func[2]);

bus->rxflow = false;

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index cae21d14042d..bc9e9bcf40e2 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -24,9 +24,6 @@
/* Maximum number of I/O funcs */
#define NUM_SDIO_FUNCS 3

-#define SDIO_FUNC_1 1
-#define SDIO_FUNC_2 2
-
#define SDIOD_FBR_SIZE 0x100

/* io_en */
@@ -45,11 +42,13 @@
#define REG_F0_REG_MASK 0x7FF
#define REG_F1_MISC_MASK 0x1FFFF

-/* as of sdiod rev 0, supports 3 functions */
-#define SBSDIO_NUM_FUNCTION 3
-
/* function 0 vendor specific CCCR registers */

+/* Interrupt enable bits for func 1 and 2 */
+#define SDIO_CCCR_IEN_BIT0 (1 << 0)
+#define SDIO_CCCR_IEN_FUNC1 (1 << 1)
+#define SDIO_CCCR_IEN_FUNC2 (1 << 2)
+
#define SDIO_CCCR_BRCM_CARDCAP 0xf0
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT 0x02
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT 0x04
@@ -349,7 +348,8 @@ int brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
u8 *data, uint size);

/* Issue an abort to the specified function */
-int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn);
+int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func);
+
void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev);
void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
enum brcmf_sdiod_state state);
--
2.11.0

2017-07-26 10:24:02

by Ian Molton

[permalink] [raw]
Subject: Re: PATCH v3 brcmfmac driver cleanup

On 24/07/17 20:47, Arend van Spriel wrote:
> On 19-07-17 21:07, Ian Molton wrote:
>> Hi all,
>>
>> Please find the 3rd revision of my cleanup patchset for brcmfmac.
>>
>> I've done some further cleanup and it now handles SDIO the ay the MMC subsystem
>> was designed to.
>>
>> I've also taken the liberty of greatly reducing the amount of indirection
>> used thoughout the SDIO code, which I think has improved readability quite a
>> lot.
>>
>> Hope this finds you all well.
> After only one week of vacation there was quite some catching up to do.
> So I decided to get an easy start and run 'checkpatch.pl --strict' over
> the series. Attached the output of that. Might be stuff that was already
> wrong before.

Some of it will be. I can see a couple of lines have crept over 80 chars.

Some lines are ~81-83 chars - I tend to leave those as its usually quite
apparent what is missing off the end. Longer ones I agree should be split.

The original source has some inconsistent whitespace too, which
complicates matters.

> I did only a quick check on patch 1/34 and it is really
> introduced by that patch. So can you please check the output.

Will have a run through and resubmit.

> FWIW, I tend to ignore the warning about block comments, ie.:

Yeah, I tend to agree. /* Blah as the first line of a multiline comment
just looks unbalanced to me.

-Ian

2017-07-19 19:08:38

by Ian Molton

[permalink] [raw]
Subject: [PATCH 03/34] brcmfmac: Split brcmf_sdiod_regrw_helper() up.

This large function is concealing a LOT of obscure logic about
how the hardware functions. Time to split it up.

This first patch splits the function into two pieces - read and write,
doing away with the rw flag in the process.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 94 +++++++++++++++++-----
1 file changed, 73 insertions(+), 21 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index db983168ceba..5b9a21d6b6b2 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -300,8 +300,8 @@ static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
return ret;
}

-static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
- u8 regsz, void *data, bool write)
+static int brcmf_sdiod_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr,
+ u8 regsz, void *data)
{
u8 func;
s32 retry = 0;
@@ -322,13 +322,66 @@ static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
func = SDIO_FUNC_1;

do {
- if (!write)
- memset(data, 0, regsz);
/* for retry wait for 1 ms till bus get settled down */
if (retry)
usleep_range(1000, 2000);
+
+ ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
+ data, true);
+
+ } while (ret != 0 && ret != -ENOMEDIUM &&
+ retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);
+
+ if (ret == -ENOMEDIUM)
+ brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
+ else if (ret != 0) {
+ /*
+ * SleepCSR register access can fail when
+ * waking up the device so reduce this noise
+ * in the logs.
+ */
+ if (addr != SBSDIO_FUNC1_SLEEPCSR)
+ brcmf_err("failed to write data F%d@0x%05x, err: %d\n",
+ func, addr, ret);
+ else
+ brcmf_dbg(SDIO, "failed to write data F%d@0x%05x, err: %d\n",
+ func, addr, ret);
+ }
+
+ return ret;
+}
+
+static int brcmf_sdiod_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr,
+ u8 regsz, void *data)
+{
+ u8 func;
+ s32 retry = 0;
+ int ret;
+
+ if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
+ return -ENOMEDIUM;
+
+ /*
+ * figure out how to read the register based on address range
+ * 0x00 ~ 0x7FF: function 0 CCCR and FBR
+ * 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
+ * The rest: function 1 silicon backplane core registers
+ */
+ if ((addr & ~REG_F0_REG_MASK) == 0)
+ func = SDIO_FUNC_0;
+ else
+ func = SDIO_FUNC_1;
+
+ do {
+ memset(data, 0, regsz);
+
+ /* for retry wait for 1 ms till bus get settled down */
+ if (retry)
+ usleep_range(1000, 2000);
+
ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
- data, write);
+ data, false);
+
} while (ret != 0 && ret != -ENOMEDIUM &&
retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);

@@ -341,12 +394,13 @@ static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
* in the logs.
*/
if (addr != SBSDIO_FUNC1_SLEEPCSR)
- brcmf_err("failed to %s data F%d@0x%05x, err: %d\n",
- write ? "write" : "read", func, addr, ret);
+ brcmf_err("failed to read data F%d@0x%05x, err: %d\n",
+ func, addr, ret);
else
- brcmf_dbg(SDIO, "failed to %s data F%d@0x%05x, err: %d\n",
- write ? "write" : "read", func, addr, ret);
+ brcmf_dbg(SDIO, "failed to read data F%d@0x%05x, err: %d\n",
+ func, addr, ret);
}
+
return ret;
}

@@ -364,13 +418,11 @@ brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
addr[2] = (address >> 24) & SBSDIO_SBADDRHIGH_MASK;

for (i = 0; i < 3; i++) {
- err = brcmf_sdiod_regrw_helper(sdiodev,
- SBSDIO_FUNC1_SBADDRLOW + i,
- 1, &addr[i], true);
+ brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr[i],
+ &err);
if (err) {
brcmf_err("failed at addr: 0x%0x\n",
SBSDIO_FUNC1_SBADDRLOW + i);
- break;
}
}

@@ -405,8 +457,7 @@ u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
int retval;

brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 1, &data,
- false);
+ retval = brcmf_sdiod_reg_read(sdiodev, addr, 1, &data);
brcmf_dbg(SDIO, "data:0x%02x\n", data);

if (ret)
@@ -424,8 +475,9 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
if (retval)
goto done;
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 4, &data,
- false);
+
+ retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);
+
brcmf_dbg(SDIO, "data:0x%08x\n", data);

done:
@@ -441,8 +493,8 @@ void brcmf_sdiod_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
int retval;

brcmf_dbg(SDIO, "addr:0x%08x, data:0x%02x\n", addr, data);
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 1, &data,
- true);
+ retval = brcmf_sdiod_reg_write(sdiodev, addr, 1, &data);
+
if (ret)
*ret = retval;
}
@@ -456,8 +508,8 @@ void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
if (retval)
goto done;
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 4, &data,
- true);
+
+ retval = brcmf_sdiod_reg_write(sdiodev, addr, 4, &data);

done:
if (ret)
--
2.11.0

2017-07-19 19:08:37

by Ian Molton

[permalink] [raw]
Subject: [PATCH 02/34] brcmfmac: Register sizes on hardware are not dependent on compiler types

The 4 IO functions in this patch are incorrect as they use compiler types
to determine how many bytes to send to the hardware.

Signed-off-by: Ian Molton <[email protected]>
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 1acbaaf0f5c9..db983168ceba 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -263,7 +263,7 @@ static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
func = sdiodev->func[fn];

switch (regsz) {
- case sizeof(u8):
+ case 1:
if (write) {
if (fn)
sdio_writeb(func, *(u8 *)data, addr, &ret);
@@ -276,13 +276,13 @@ static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
*(u8 *)data = sdio_f0_readb(func, addr, &ret);
}
break;
- case sizeof(u16):
+ case 2:
if (write)
sdio_writew(func, *(u16 *)data, addr, &ret);
else
*(u16 *)data = sdio_readw(func, addr, &ret);
break;
- case sizeof(u32):
+ case 4:
if (write)
sdio_writel(func, *(u32 *)data, addr, &ret);
else
@@ -366,7 +366,7 @@ brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
for (i = 0; i < 3; i++) {
err = brcmf_sdiod_regrw_helper(sdiodev,
SBSDIO_FUNC1_SBADDRLOW + i,
- sizeof(u8), &addr[i], true);
+ 1, &addr[i], true);
if (err) {
brcmf_err("failed at addr: 0x%0x\n",
SBSDIO_FUNC1_SBADDRLOW + i);
@@ -405,7 +405,7 @@ u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
int retval;

brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
+ retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 1, &data,
false);
brcmf_dbg(SDIO, "data:0x%02x\n", data);

@@ -421,10 +421,10 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
int retval;

brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
- retval = brcmf_sdiod_addrprep(sdiodev, sizeof(data), &addr);
+ retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
if (retval)
goto done;
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
+ retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 4, &data,
false);
brcmf_dbg(SDIO, "data:0x%08x\n", data);

@@ -441,7 +441,7 @@ void brcmf_sdiod_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
int retval;

brcmf_dbg(SDIO, "addr:0x%08x, data:0x%02x\n", addr, data);
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
+ retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 1, &data,
true);
if (ret)
*ret = retval;
@@ -453,10 +453,10 @@ void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
int retval;

brcmf_dbg(SDIO, "addr:0x%08x, data:0x%08x\n", addr, data);
- retval = brcmf_sdiod_addrprep(sdiodev, sizeof(data), &addr);
+ retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
if (retval)
goto done;
- retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
+ retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 4, &data,
true);

done:
@@ -874,7 +874,7 @@ int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, uint fn)

/* issue abort cmd52 command through F0 */
brcmf_sdiod_request_data(sdiodev, SDIO_FUNC_0, SDIO_CCCR_ABORT,
- sizeof(t_func), &t_func, true);
+ 1, &t_func, true);

brcmf_dbg(SDIO, "Exit\n");
return 0;
--
2.11.0

2017-07-19 19:15:37

by Ian Molton

[permalink] [raw]
Subject: [PATCH 29/34] brcmfmac: stabilise the value of ->sbwad in use for some xfer routines.

The IO functions operate within the Chipcommon IO window. Explicitly
set this, rather than relying on the last initialisation IO access to
leave it set to the right value by chance.

Signed-off-by: Ian Molton <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 8 ++++----
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 5 +++++
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 1 +
3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index ab015bad02f2..dcdebe8e8ff4 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -528,7 +528,7 @@ int brcmf_sdiod_recv_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)

int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
{
- u32 addr = sdiodev->sbwad;
+ u32 addr = sdiodev->cc_core->base;
int err = 0;

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pkt->len);
@@ -551,7 +551,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
{
struct sk_buff *glom_skb = NULL;
struct sk_buff *skb;
- u32 addr = sdiodev->sbwad;
+ u32 addr = sdiodev->cc_core->base;
int err = 0;

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n",
@@ -592,7 +592,7 @@ int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
{
struct sk_buff *mypkt;
- u32 addr = sdiodev->sbwad;
+ u32 addr = sdiodev->cc_core->base;
int err;

mypkt = brcmu_pkt_buf_get_skb(nbytes);
@@ -625,7 +625,7 @@ int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,
struct sk_buff_head *pktq)
{
struct sk_buff *skb;
- u32 addr = sdiodev->sbwad;
+ u32 addr = sdiodev->cc_core->base;
int err;

brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pktq->qlen);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 19f40a1ee418..2a52f48bdddc 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -3821,6 +3821,11 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
if (!bus->sdio_core)
goto fail;

+ /* Pick up the CHIPCOMMON core info struct, used for bulk IO in bcmsdh.c */
+ sdiodev->cc_core = brcmf_chip_get_core(bus->ci, BCMA_CORE_CHIPCOMMON);
+ if (!sdiodev->cc_core)
+ goto fail;
+
sdiodev->settings = brcmf_get_module_param(sdiodev->dev,
BRCMF_BUSTYPE_SDIO,
bus->ci->chip,
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
index e2324a78249b..a5a05d1a34bf 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
@@ -178,6 +178,7 @@ struct brcmf_sdio_dev {
struct sdio_func *func[SDIO_MAX_FUNCS];
u8 num_funcs; /* Supported funcs on client */
u32 sbwad; /* Save backplane window address */
+ struct brcmf_core *cc_core; /* chipcommon core info struct */
struct brcmf_sdio *bus;
struct device *dev;
struct brcmf_bus *bus_if;
--
2.11.0