2017-07-26 20:26:09

by Ian Molton

[permalink] [raw]
Subject: Patch v4: Clean up brcmfmac driver

Hi folks,

Here's a v4 of the cleanup patchset - checkpatch clean(er - I have purposely
left some warnings unaddressed).

I also dropped an accidental adjustment of a debug macro from v3.

-Ian


2017-07-29 10:02:57

by kernel test robot

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

Hi Ian,

[auto build test ERROR on wireless-drivers-next/master]
[also build test ERROR on v4.13-rc2 next-20170728]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Ian-Molton/brcmfmac-Fix-parameter-order-in-brcmf_sdiod_f0_writeb/20170728-215756
base: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master
config: parisc-allyesconfig (attached as .config)
compiler: hppa-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc

Note: the linux-review/Ian-Molton/brcmfmac-Fix-parameter-order-in-brcmf_sdiod_f0_writeb/20170728-215756 HEAD 279d46b037ee04966f44b25a0ed07c467540c68c builds fine.
It only hurts bisectibility.

All errors (new ones prefixed by >>):

drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c: In function 'brcmf_chip_recognition':
>> drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c:900:9: error: 'KERN_LOG' undeclared (first use in this function)
printk(KERN_LOG "found %s chip: BCM%s, rev=%d\n",
^~~~~~~~
drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c:900:9: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c:900:18: error: expected ')' before string constant
printk(KERN_LOG "found %s chip: BCM%s, rev=%d\n",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/KERN_LOG +900 drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c

880
881 static int brcmf_chip_recognition(struct brcmf_chip *ci)
882 {
883 struct brcmf_core *core;
884 u32 regdata;
885 u32 socitype;
886 int ret;
887
888 /* Get CC core rev
889 * Chipid is assume to be at offset 0 from SI_ENUM_BASE
890 * For different chiptypes or old sdio hosts w/o chipcommon,
891 * other ways of recognition should be added here.
892 */
893 regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
894 ci->chip = regdata & CID_ID_MASK;
895 ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
896 socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
897
898 brcmf_chip_name(ci->chip, ci->name, sizeof(ci->name));
899
> 900 printk(KERN_LOG "found %s chip: BCM%s, rev=%d\n",
901 socitype == SOCI_SB ? "SB" : "AXI", ci->name, ci->chiprev);
902
903 switch(socitype) {
904 case SOCI_SB:
905
906 if (ci->chip != BRCM_CC_4329_CHIP_ID) {
907 brcmf_err("SB chip is not supported\n");
908 return -ENODEV;
909 }
910 ci->iscoreup = brcmf_chip_sb_iscoreup;
911 ci->coredisable = brcmf_chip_sb_coredisable;
912 ci->resetcore = brcmf_chip_sb_resetcore;
913
914 core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
915 SI_ENUM_BASE, 0);
916 brcmf_chip_sb_corerev(ci, core);
917 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
918 BCM4329_CORE_BUS_BASE, 0);
919 brcmf_chip_sb_corerev(ci, core);
920 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
921 BCM4329_CORE_SOCRAM_BASE, 0);
922 brcmf_chip_sb_corerev(ci, core);
923 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
924 BCM4329_CORE_ARM_BASE, 0);
925 brcmf_chip_sb_corerev(ci, core);
926
927 core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0);
928 brcmf_chip_sb_corerev(ci, core);
929 break;
930 case SOCI_AXI:
931 ci->iscoreup = brcmf_chip_ai_iscoreup;
932 ci->coredisable = brcmf_chip_ai_coredisable;
933 ci->resetcore = brcmf_chip_ai_resetcore;
934
935 brcmf_chip_dmp_erom_scan(ci);
936 break;
937 default:
938 brcmf_err("chip backplane type %u is not supported\n",
939 socitype);
940 return -ENODEV;
941 }
942
943 ret = brcmf_chip_cores_check(ci);
944 if (ret)
945 return ret;
946
947 /* assure chip is passive for core access */
948 brcmf_chip_set_passive(ci);
949
950 /* Call bus specific reset function now. Cores have been determined
951 * but further access may require a chip specific reset at this point.
952 */
953 if (ci->ops->reset) {
954 ci->ops->reset(ci->ctx, ci);
955 brcmf_chip_set_passive(ci);
956 }
957
958 return brcmf_chip_get_raminfo(ci);
959 }
960

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (4.70 kB)
.config.gz (49.13 kB)
Download all attachments

2017-07-27 10:00:20

by Ian Molton

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

On 27/07/17 10:52, Arend van Spriel wrote:
>>
>> How many patches would you like at once?
>
> Hi Ian,
>
> ~10-15 patches should be fine although I am simply ploughing through the
> lot right now.

Hi Arend,

Noted for future series. I take it I shouldn't re-spin if you're going
through them already?

Thanks,

-Ian

2017-07-26 20:46:52

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 9cfabf4a7f62..0b70d61cc912 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -222,18 +222,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)
@@ -1018,7 +1018,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);
}

@@ -1089,12 +1089,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;
@@ -1118,9 +1118,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;

@@ -1241,7 +1241,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);
@@ -1267,7 +1267,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);
@@ -1294,7 +1294,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 060bfa896bf1..680875423f91 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-28 15:56:45

by kernel test robot

[permalink] [raw]
Subject: [PATCH] brcmfmac: fix semicolon.cocci warnings

drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c:316:2-3: Unneeded semicolon


Remove unneeded semicolon.

Generated by: scripts/coccinelle/misc/semicolon.cocci

Fixes: 4451d20a99c4 ("brcmfmac: Replace function index with function pointer")
CC: Ian Molton <[email protected]>
Signed-off-by: Fengguang Wu <[email protected]>
---

bcmsdh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -313,7 +313,7 @@ static int brcmf_sdiod_buff_read(struct
break;
default:
BUG();
- };
+ }

if (err == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);

2017-07-26 20:45:21

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 6884d1f0b935..26b39f0ffdd4 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -529,7 +529,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);
@@ -552,7 +552,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",
@@ -593,7 +593,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);
@@ -626,7 +626,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 b06018e589bb..91a17ef63a6b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -3838,6 +3838,11 @@ brcmf_sdio_probe_attach(struct brcmf_sdio *bus)
if (!bus->sdio_core)
goto fail;

+ /* Pick up the CHIPCOMMON core info struct, 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 fb4f24dfc99d..1ab95011adb0 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

2017-07-26 20:44:13

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 140 +++----
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 409 +++++++++++----------
2 files changed, 294 insertions(+), 255 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 8cfd2cbb1dfa..c2f821b28fee 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 */
@@ -157,13 +159,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;
}

@@ -172,6 +174,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,
@@ -181,26 +185,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;
}
}
@@ -252,6 +256,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;

@@ -263,7 +268,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)
@@ -275,6 +280,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);
@@ -285,7 +291,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)
@@ -536,6 +542,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;

@@ -548,7 +555,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;
@@ -557,6 +564,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;
@@ -573,14 +581,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;

@@ -589,8 +595,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);
@@ -600,6 +605,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;

@@ -621,8 +627,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);

@@ -634,6 +639,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;

@@ -648,14 +654,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;
}
@@ -664,6 +668,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;
@@ -684,7 +689,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) {
@@ -704,11 +709,9 @@ 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) {
@@ -731,7 +734,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;
}
@@ -749,18 +752,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;
@@ -807,6 +808,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;

@@ -816,17 +818,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);
}
@@ -867,6 +871,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);
@@ -876,19 +883,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;
}

@@ -902,29 +909,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;
@@ -940,7 +950,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);
@@ -1060,7 +1071,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);
@@ -1069,7 +1079,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);
@@ -1080,8 +1092,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 618d9ea4fc05..a38b7985f0a1 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,8 +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;
@@ -709,9 +709,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
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)
@@ -729,6 +727,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;
@@ -747,16 +746,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;
@@ -765,34 +762,34 @@ 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, &err);
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
if (err) {
brcmf_err("Devctl error setting CA: %d\n", err);
return -EBADE;
}

devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ brcmf_sdiod_writeb(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_readb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, &err);
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ brcmf_sdiod_writeb(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_readb(bus->sdiodev,
+ clkctl = brcmf_sdiod_readb(sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR,
&err);
if (time_after(jiffies, timeout))
@@ -826,16 +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, &err);
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_DEVICE_CTL,
- devctl, &err);
+ 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",
@@ -910,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;

@@ -925,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);
}
@@ -972,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);

/*
@@ -988,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;
@@ -1007,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);
@@ -1034,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;
}

@@ -1053,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;
@@ -1063,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;
@@ -1138,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;
@@ -1150,16 +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))
@@ -1179,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++;
@@ -1194,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++;

@@ -1449,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;
@@ -1556,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 */
@@ -1567,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;
}

@@ -1581,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 */
@@ -1600,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");

@@ -1612,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;
}
@@ -1650,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++;
}
@@ -1693,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;
@@ -1719,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 */
@@ -2017,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;
@@ -2027,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);
@@ -2054,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);
@@ -2232,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;

@@ -2241,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);
@@ -2256,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;
@@ -2264,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;
@@ -2281,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);
@@ -2304,11 +2311,11 @@ 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;
@@ -2318,10 +2325,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;
@@ -2329,6 +2336,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;
@@ -2378,7 +2386,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);
@@ -2475,34 +2483,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 */
@@ -2511,7 +2521,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) {
@@ -2519,23 +2529,21 @@ 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, &err);
+ devctl = brcmf_sdiod_readb(sdiodev, SBSDIO_DEVICE_CTL,
+ &err);
devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
- brcmf_sdiod_writeb(bus->sdiodev,
- SBSDIO_DEVICE_CTL, devctl, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_DEVICE_CTL, devctl,
+ &err);
bus->clkstate = CLK_AVAIL;
}
}
@@ -2558,10 +2566,10 @@ 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,
+ newstatus = brcmf_sdiod_readl(sdiodev,
core->base + __sd_reg(intstatus),
&err);

@@ -2577,7 +2585,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) {
@@ -2620,7 +2628,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);
@@ -2628,7 +2636,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) */
@@ -2640,18 +2648,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 ||
@@ -2768,6 +2776,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;
@@ -2779,7 +2788,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;
@@ -2805,7 +2814,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;

@@ -2848,6 +2857,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;

@@ -2866,13 +2876,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",
@@ -2893,6 +2903,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;
@@ -2900,22 +2911,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);
@@ -2929,7 +2937,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;
@@ -2984,6 +2992,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] = "<???>";
@@ -2996,20 +3006,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);
@@ -3241,16 +3251,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;

@@ -3260,17 +3271,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;
@@ -3280,10 +3292,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);
@@ -3312,32 +3326,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);
@@ -3346,8 +3361,8 @@ static void brcmf_sdio_sr_init(struct brcmf_sdio *bus)
return;
}

- brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
- SBSDIO_FORCE_HT, &err);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, SBSDIO_FORCE_HT,
+ &err);
if (err) {
brcmf_err("error writing SBSDIO_FUNC1_CHIPCLKCSR\n");
return;
@@ -3361,6 +3376,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;
@@ -3371,7 +3387,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;
@@ -3380,7 +3396,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;
@@ -3396,6 +3412,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;
@@ -3426,8 +3443,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 */
@@ -3437,7 +3454,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;
@@ -3524,6 +3541,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. */
@@ -3541,11 +3561,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_release_host(bus->sdiodev->func[1]);
- SDIO_CCCR_INTx, NULL);
- sdio_release_host(bus->sdiodev->func1);
+ sdio_claim_host(func1);
+ devpend = brcmf_sdiod_func0_rb(sdiodev,
+ SDIO_CCCR_INTx,
+ NULL);
+ sdio_release_host(func1);
intstatus = devpend & (INTR_STATUS_FUNC1 |
INTR_STATUS_FUNC2);
}
@@ -3566,18 +3586,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 */
@@ -3590,11 +3610,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;
@@ -3608,6 +3628,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();
@@ -3617,10 +3638,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);
}
}

@@ -3799,15 +3820,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()
@@ -3940,18 +3961,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 */
@@ -3995,8 +4017,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;

@@ -4019,7 +4042,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);
@@ -4038,10 +4061,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);
@@ -4050,14 +4073,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;
}

@@ -4070,7 +4092,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)
@@ -4081,7 +4103,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) {
@@ -4091,11 +4113,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)
@@ -4160,16 +4182,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;
@@ -4178,17 +4200,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)) {
@@ -4197,17 +4219,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;
@@ -4248,18 +4270,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
@@ -4269,12 +4294,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);
@@ -4314,11 +4339,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-27 06:17:48

by Kalle Valo

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

Ian Molton <[email protected]> writes:

> Here's a v4 of the cleanup patchset - checkpatch clean(er - I have purposely
> left some warnings unaddressed).
>
> I also dropped an accidental adjustment of a debug macro from v3.

Like I said already last time, please split the patchset into reasonable
sizes (and submit one patchset at a time). I will automatically drop
patchbombs like this.

--
Kalle Valo

2017-07-26 20:26:11

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 f585dfd89453..2b441ce91d5f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -264,7 +264,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);
@@ -278,13 +278,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
@@ -368,7 +368,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);
@@ -407,7 +407,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);

@@ -423,10 +423,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);

@@ -443,7 +443,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;
@@ -455,10 +455,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:
@@ -876,7 +876,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-27 10:09:49

by Arend Van Spriel

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

On 7/27/2017 12:00 PM, Ian Molton wrote:
> On 27/07/17 10:52, Arend van Spriel wrote:
>>>
>>> How many patches would you like at once?
>>
>> Hi Ian,
>>
>> ~10-15 patches should be fine although I am simply ploughing through the
>> lot right now.
>
> Hi Arend,
>
> Noted for future series. I take it I shouldn't re-spin if you're going
> through them already?

My "guess" is a v5 is likely ;-)

Regards,
Arend

2017-07-26 20:26:17

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 73f2194a854f..049086f6db97 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -370,9 +370,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;
@@ -385,8 +383,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)
@@ -400,7 +396,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)
@@ -412,7 +407,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-26 20:45:24

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 | 132 +++++++++++++--------
1 file changed, 84 insertions(+), 48 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index daa3c335804b..3fe75aa30d9b 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,15 +471,15 @@ 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,
- u16 coreid, u32 base,
- u32 wrapbase)
+static struct brcmf_core *__brcmf_chip_add_core(struct brcmf_chip *ci,
+ u16 coreid, u32 base,
+ u32 wrapbase)
{
struct brcmf_core *core;

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

core->id = coreid;
core->base = base;
@@ -502,6 +491,40 @@ 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 +923,41 @@ 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 - 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 +965,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));
@@ -932,46 +979,35 @@ static int brcmf_chip_recognition(struct brcmf_chip *ci)
printk(KERN_LOG "found %s chip: BCM%s, rev=%d\n",
socitype == SOCI_SB ? "SB" : "AXI", ci->name, ci->chiprev);

- switch(socitype) {
- case SOCI_SB:
+ switch (socitype) {
+ case SOCI_SB:

- if (ci->chip != BRCM_CC_4329_CHIP_ID) {
+ 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",
@@ -1092,7 +1128,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-26 20:26:13

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
---
.../net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 17 +++++------------
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 3 ---
2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 1ee0f91b6c50..7b2184d1e365 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -410,23 +410,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],
- &err);
- if (err) {
- brcmf_err("failed at addr: 0x%0x\n",
- SBSDIO_FUNC1_SBADDRLOW + i);
- }
- }
+ for (i = 0 ; i < 3 && !err ; i++, addr >>= 8)
+ brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i,
+ addr & 0xff, &err);

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-26 20:42:05

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 | 447 ++++++++++-----------
1 file changed, 219 insertions(+), 228 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index ec47924b0f76..9cfabf4a7f62 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -106,9 +106,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,252 +220,251 @@ 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 val == SSB_TMSLOW_CLOCK;
}

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,
- u32 prereset, u32 reset)
+/* 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;
u32 val, base;

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,
- u32 prereset, u32 reset)
+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,
- prereset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
+ /* 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,
- reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
-
- ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
+ brcmf_writelp(ci, core->wrapbase + BCMA_IOCTL,
+ reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
}

-static void brcmf_chip_sb_resetcore(struct brcmf_core *core, u32 prereset,
- u32 reset, u32 postreset)
+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),
- SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
- SSB_TMSLOW_RESET);
-
- regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
+ brcmf_writelp(ci, CORE_SB(base, sbtmstatelow),
+ SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
+ SSB_TMSLOW_RESET);

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),
- SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK);
-
- regdata = ci->ops->read32(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);

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,
- u32 reset, u32 postreset)
+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;
+ int count = 0;

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

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

- 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;
+ 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 +477,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 +492,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;
@@ -572,34 +568,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;
@@ -615,7 +606,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)) {
@@ -656,6 +648,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;
@@ -665,7 +658,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++) {
@@ -679,6 +672,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;
@@ -687,15 +681,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;
}

@@ -785,15 +782,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;

@@ -884,7 +883,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);
@@ -958,30 +957,23 @@ 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(KERN_LOG "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);
@@ -995,8 +987,8 @@ static int brcmf_chip_probe(struct brcmf_chip *ci)
return -ENODEV;

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

break;
case SOCI_AXI:
@@ -1005,8 +997,8 @@ static int brcmf_chip_probe(struct brcmf_chip *ci)
return -ENODEV;

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

break;
default:
@@ -1019,18 +1011,23 @@ static int brcmf_chip_probe(struct brcmf_chip *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)
@@ -1050,9 +1047,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;
@@ -1073,17 +1072,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,
- capabilities_ext));
+ 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;
}
@@ -1229,8 +1225,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);
}
}

@@ -1353,53 +1349,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-26 20:26:17

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 f703d7be6a85..73f2194a854f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -367,7 +367,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-27 10:12:07

by Ian Molton

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

On 27/07/17 11:09, Arend van Spriel wrote:
>>
>> Hi Arend,
>>
>> Noted for future series. I take it I shouldn't re-spin if you're going
>> through them already?
>
> My "guess" is a v5 is likely ;-)

No prob. I've spotted a gem in it myself (FIXME comment that crept
through). I'll split it into two series at v5 then.

-Ian

2017-07-26 20:46:33

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 26b39f0ffdd4..95149c686c5f 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 1ab95011adb0..8a976c89cf63 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-26 20:46:30

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 | 383 +++++++++------------
.../wireless/broadcom/brcm80211/brcmfmac/chip.h | 22 ++
2 files changed, 191 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..ecd242b33691 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,19 @@ 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(KERN_LOG "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 +945,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 +987,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 +1026,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 +1061,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 +1080,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 +1120,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..060bfa896bf1 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-26 20:46:35

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 | 166 +++----------------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 182 ++++++++++-----------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 28 +++-
3 files changed, 132 insertions(+), 244 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 858ad2d8706b..b2945b463fd3 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,8 +240,8 @@ static int brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev,
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);
+ brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i,
+ addr & 0xff, &err);

return err;
}
@@ -267,123 +265,15 @@ static int 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;
@@ -391,23 +281,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)
+void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
+ u32 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,
- u32 data, int *ret)
-{
- int retval;
+ retval = brcmf_sdiod_addrprep(sdiodev, &addr);

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

if (ret)
*ret = retval;
@@ -845,8 +727,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..a622df81c501 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,7 +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,
+ rd_val = brcmf_sdiod_readb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
&err);
if (!err) {
if ((rd_val & bmask) == cmp_val)
@@ -731,9 +730,11 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
/* bail out upon subsequent access errors */
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,15 +770,15 @@ 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,
+ clkctl = brcmf_sdiod_readb(bus->sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR, &err);
if (err) {
brcmf_err("HT Avail read error: %d\n", err);
@@ -787,35 +788,34 @@ 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,
+ devctl = brcmf_sdiod_readb(bus->sdiodev,
SBSDIO_DEVICE_CTL, &err);
if (err) {
- brcmf_err("Devctl error setting CA: %d\n",
- err);
+ brcmf_err("Devctl error setting CA: %d\n", err);
return -EBADE;
}

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,
+ 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 +849,16 @@ 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,
+ 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,14 +948,14 @@ 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,
- SBSDIO_FUNC1_CHIPCLKCSR,
- SBSDIO_ALP_AVAIL_REQ, &err);
+ brcmf_sdiod_writeb(bus->sdiodev,
+ SBSDIO_FUNC1_CHIPCLKCSR,
+ SBSDIO_ALP_AVAIL_REQ, &err);
}
err = brcmf_sdio_kso_control(bus, false);
} else {
@@ -1170,16 +1170,14 @@ 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 +1219,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,11 +2435,11 @@ 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,
- (saveclk | SBSDIO_FORCE_HT), &err);
+ 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",
err);
@@ -2500,7 +2498,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 +2508,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 +2534,23 @@ 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,
+ 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,
+ 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,31 +3336,31 @@ 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,
- (SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT |
- SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT),
- &err);
+ brcmf_sdiod_func0_wb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP,
+ (SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT |
+ SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT),
+ &err);
if (err) {
brcmf_err("error writing SDIO_CCCR_BRCM_CARDCAP\n");
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 +3383,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 +3392,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,9 +3553,9 @@ 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,
- SDIO_CCCR_INTx,
- NULL);
+ devpend = brcmf_sdiod_func0_rb(bus->sdiodev,
+ SDIO_CCCR_INTx,
+ NULL);
sdio_release_host(bus->sdiodev->func[1]);
intstatus = devpend & (INTR_STATUS_FUNC1 |
INTR_STATUS_FUNC2);
@@ -3696,12 +3693,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 +3713,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 +3721,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,10 +3729,11 @@ static int brcmf_sdio_buscoreprep(void *ctx)
return -EACCES;
}

- SPINWAIT(((clkval = brcmf_sdiod_regrb(sdiodev,
- SBSDIO_FUNC1_CHIPCLKCSR, NULL)),
- !SBSDIO_ALPAV(clkval)),
- PMU_MAX_TRANSITION_DLY);
+ SPINWAIT(((clkval = brcmf_sdiod_readb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
+ NULL)),
+ !SBSDIO_ALPAV(clkval)),
+ PMU_MAX_TRANSITION_DLY);
+
if (!SBSDIO_ALPAV(clkval)) {
brcmf_err("timeout on ALPAV wait, clkval 0x%02x\n",
clkval);
@@ -3744,11 +3741,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 +3760,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 +3773,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 +3790,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 +3814,18 @@ 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 +3885,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,10 +4024,10 @@ 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,
- (saveclk | SBSDIO_FORCE_HT), &err);
+ 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", err);
@@ -4052,7 +4049,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 +4060,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 +4200,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..4c81ea24d19c 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,24 @@ 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-26 20:46:40

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 | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index bee377fcc48f..b06018e589bb 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -2475,14 +2475,12 @@ 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;
@@ -2492,7 +2490,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-26 20:42:03

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 3feaf9125b25..9ef137d6eb3f 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);
}

@@ -2467,10 +2469,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)) {
@@ -3765,15 +3766,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;
}

@@ -3804,9 +3813,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-26 20:46:37

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 3fe75aa30d9b..ec47924b0f76 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;

@@ -1004,9 +1004,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-28 15:55:45

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 32/34] brcmfmac: Replace function index with function pointer

Hi Ian,

[auto build test WARNING on wireless-drivers-next/master]
[also build test WARNING on v4.13-rc2 next-20170728]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Ian-Molton/brcmfmac-Fix-parameter-order-in-brcmf_sdiod_f0_writeb/20170728-215756
base: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master


coccinelle warnings: (new ones prefixed by >>)

>> drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c:316:2-3: Unneeded semicolon

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

2017-07-26 20:26:13

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 7b2184d1e365..609a934c1658 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -425,7 +425,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;
@@ -439,9 +439,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;
}
@@ -467,7 +465,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;

@@ -500,7 +498,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;

@@ -736,7 +734,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;

@@ -757,7 +755,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;

@@ -801,7 +799,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,
@@ -821,7 +819,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-26 20:45:16

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 a622df81c501..82769276654d 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 */
@@ -1084,12 +1086,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 */
@@ -1197,8 +1197,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)
@@ -2322,9 +2321,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)
@@ -2430,7 +2427,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;

@@ -2449,8 +2446,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]);
}
@@ -2496,7 +2492,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++;
@@ -2573,11 +2569,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)));
@@ -3759,7 +3753,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)
@@ -4036,7 +4030,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]);


@@ -4046,8 +4040,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-26 20:26:16

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 239 ++++++++-------------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 2 +-
2 files changed, 87 insertions(+), 154 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index d217b1281e0d..f703d7be6a85 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -230,6 +230,43 @@ 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)
{
@@ -249,173 +286,83 @@ static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func, u8 byte,
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;
+ 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;

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

- *addr &= SBSDIO_SB_OFT_ADDR_MASK;
- *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
-
- return 0;
+done:
+ return ret;
}

u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
@@ -439,15 +386,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;

@@ -472,13 +413,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;
}
@@ -886,14 +821,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-26 20:46: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 | 6 +++---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 13 ++++++-------
3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 95149c686c5f..da0654c50db9 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 91a17ef63a6b..230a24cb6c0a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -3766,9 +3766,9 @@ 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) &&
- addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) {
+ 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 8a976c89cf63..227c90198a8e 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-26 20:26:12

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 2b441ce91d5f..1ee0f91b6c50 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -302,8 +302,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;
@@ -324,13 +324,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);

@@ -343,12 +396,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;
}

@@ -366,13 +420,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;
}
}

@@ -407,8 +459,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)
@@ -426,8 +477,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:
@@ -443,8 +495,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;
}
@@ -458,8 +510,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-26 20:46:47

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 69 +++++++++++++++-------
1 file changed, 47 insertions(+), 22 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 9d5716d0ad73..858ad2d8706b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -413,8 +413,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;
@@ -423,18 +423,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;
}

@@ -642,7 +660,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;
@@ -664,14 +682,14 @@ 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,
- pktq->next);
+ 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,
- glom_skb);
+ err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
+ glom_skb);
if (err)
goto done;

@@ -695,6 +713,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);
@@ -706,10 +725,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;

}
@@ -729,8 +748,8 @@ 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,
- addr, skb);
+ err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2,
+ addr, skb);
if (err)
break;
}
@@ -782,10 +801,16 @@ 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-26 20:46:50

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 | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 049086f6db97..9d5716d0ad73 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -745,7 +745,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;
@@ -770,8 +770,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",
@@ -784,9 +784,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,
- sdaddr, pkt);
- if (bcmerror) {
+ err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_1, write, sdaddr,
+ pkt);
+ if (err) {
brcmf_err("membytes transfer failed\n");
break;
}
@@ -813,7 +813,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-27 09:52:32

by Arend Van Spriel

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

On 7/27/2017 11:47 AM, Ian Molton wrote:
> On 27/07/17 07:17, Kalle Valo wrote:
>>> Here's a v4 of the cleanup patchset - checkpatch clean(er - I have purposely
>>> left some warnings unaddressed).
>>>
>>> I also dropped an accidental adjustment of a debug macro from v3.
>> Like I said already last time, please split the patchset into reasonable
>> sizes (and submit one patchset at a time). I will automatically drop
>> patchbombs like this.
>
> How many patches would you like at once?

Hi Ian,

~10-15 patches should be fine although I am simply ploughing through the
lot right now.

Regards,
Arend

2017-07-27 10:32:07

by Kalle Valo

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

Ian Molton <[email protected]> writes:

> On 27/07/17 07:17, Kalle Valo wrote:
>>> Here's a v4 of the cleanup patchset - checkpatch clean(er - I have purposely
>>> left some warnings unaddressed).
>>>
>>> I also dropped an accidental adjustment of a debug macro from v3.
>> Like I said already last time, please split the patchset into reasonable
>> sizes (and submit one patchset at a time). I will automatically drop
>> patchbombs like this.
>
> How many patches would you like at once?

Check my previous email:

https://lkml.kernel.org/r/[email protected]

--
Kalle Valo

2017-07-26 20:45:19

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-26 20:46:28

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 86 ++++++++++++----------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 14 ++--
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 14 ++--
3 files changed, 61 insertions(+), 53 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index da0654c50db9..5787348003d9 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -148,7 +148,8 @@ 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 */
@@ -291,8 +292,9 @@ 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,
- u32 addr, struct sk_buff *pkt)
+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;
int err;
@@ -301,13 +303,17 @@ 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);
- else
- /* function 2 read is FIFO operation */
- err = sdio_readsb(sdiodev->func[fn],
- ((u8 *)(pkt->data)), addr, req_sz);
+ switch (func->num) {
+ case 1:
+ err = sdio_memcpy_fromio(func, ((u8 *)(pkt->data)), addr,
+ req_sz);
+ break;
+ case 2:
+ err = sdio_readsb(func, ((u8 *)(pkt->data)), addr, req_sz);
+ break;
+ default:
+ BUG();
+ };

if (err == -ENOMEDIUM)
brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
@@ -315,8 +321,9 @@ 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,
- u32 addr, struct sk_buff *pkt)
+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;
int err;
@@ -325,8 +332,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);
@@ -337,7 +343,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
@@ -346,7 +352,8 @@ 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,
+static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev,
+ struct sdio_func *func,
bool write, u32 addr,
struct sk_buff_head *pktlist)
{
@@ -372,7 +379,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) {
@@ -391,7 +398,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);
@@ -408,10 +415,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 |= 1<<27; /* block mode */
+ 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;
@@ -457,11 +464,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) {
@@ -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, SDIO_FUNC_2, addr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr, pkt);

done:
return err;
@@ -566,13 +573,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;
@@ -582,8 +589,8 @@ 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,
- pktq);
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], false,
+ addr, pktq);

done:
brcmu_pkt_buf_free_skb(glom_skb);
@@ -614,7 +621,8 @@ 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);

@@ -640,14 +648,14 @@ 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,
- pktq);
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], true,
+ addr, pktq);

return err;
}
@@ -696,10 +704,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, 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 +736,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 +1112,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 +1141,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 230a24cb6c0a..e90271e14255 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -1150,7 +1150,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);
@@ -1200,7 +1200,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++;

@@ -2062,7 +2062,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);

@@ -2432,7 +2432,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),
@@ -4041,7 +4041,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);
@@ -4057,7 +4057,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;
}

@@ -4200,7 +4200,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 227c90198a8e..3d41bd94f97c 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 BIT(0)
+#define SDIO_CCCR_IEN_FUNC1 BIT(1)
+#define SDIO_CCCR_IEN_FUNC2 BIT(2)
+
#define SDIO_CCCR_BRCM_CARDCAP 0xf0
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT 0x02
#define SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT 0x04
@@ -350,7 +349,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 20:26:15

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 28 +---------------------
1 file changed, 1 insertion(+), 27 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 609a934c1658..d217b1281e0d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -334,21 +334,8 @@ static int brcmf_sdiod_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr,
} while (ret != 0 && ret != -ENOMEDIUM &&
retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);

- if (ret == -ENOMEDIUM) {
+ 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;
}
@@ -389,19 +376,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-26 20:46:49

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 b4fd832cdabe..3feaf9125b25 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;
@@ -2484,12 +2483,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);
@@ -3366,13 +3364,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);
@@ -3400,6 +3399,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;
@@ -3408,7 +3408,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,
@@ -3746,11 +3746,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);

@@ -3831,6 +3830,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-26 20:43:09

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 117 +++++++--------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 166 ++++++++++-----------
.../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 15 +-
3 files changed, 146 insertions(+), 152 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 5787348003d9..8cfd2cbb1dfa 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 */
@@ -157,13 +157,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;
}

@@ -181,26 +181,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;
}
}
@@ -263,7 +263,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)
@@ -285,7 +285,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)
@@ -548,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->func[2], addr, pkt);
+ err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func2, addr, pkt);

done:
return err;
@@ -573,13 +573,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;
@@ -589,7 +589,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,
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, false,
addr, pktq);

done:
@@ -621,7 +621,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,
+ err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func2, addr,
mypkt);

brcmu_pkt_buf_free_skb(mypkt);
@@ -648,14 +648,14 @@ 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, pktq);
+ err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, true, addr,
+ pktq);

return err;
}
@@ -684,7 +684,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) {
@@ -704,10 +704,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->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);
}

@@ -731,7 +731,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;
}
@@ -755,7 +755,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);
@@ -816,17 +816,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);
}
@@ -876,19 +876,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;
}

@@ -904,29 +904,27 @@ static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
{
int ret = 0;

- sdiodev->num_funcs = 2;
-
- sdio_claim_host(sdiodev->func[1]);
+ sdio_claim_host(sdiodev->func1);

- 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;
@@ -942,7 +940,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);
@@ -1029,16 +1027,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);

@@ -1054,7 +1051,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;
@@ -1083,8 +1080,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);
@@ -1129,7 +1126,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 e90271e14255..618d9ea4fc05 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -978,7 +978,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);

/*
@@ -1012,7 +1012,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);
@@ -1034,7 +1034,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;
}

@@ -1150,7 +1150,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);
@@ -1200,7 +1200,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++;

@@ -1556,10 +1556,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 */
@@ -1567,11 +1567,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;
}

@@ -1581,10 +1581,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 */
@@ -1600,10 +1600,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");

@@ -1612,11 +1612,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;
}
@@ -1824,7 +1824,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);
@@ -1834,7 +1834,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;
}

@@ -1844,7 +1844,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
@@ -1860,7 +1860,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 ?
@@ -1877,7 +1877,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);
@@ -1885,16 +1885,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;
}

@@ -1905,7 +1905,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;
@@ -1918,11 +1918,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;
@@ -1938,9 +1938,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;
}
@@ -1963,9 +1963,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;
@@ -2062,7 +2062,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);

@@ -2241,14 +2241,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);
@@ -2304,11 +2304,11 @@ 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;
@@ -2408,7 +2408,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);
@@ -2432,13 +2432,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);
@@ -2511,7 +2511,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) {
@@ -2577,7 +2577,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) {
@@ -2620,7 +2620,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);
@@ -2628,7 +2628,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) */
@@ -2644,14 +2644,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 ||
@@ -2866,13 +2866,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",
@@ -2996,7 +2996,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);
@@ -3009,7 +3009,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);
@@ -3283,7 +3283,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);
@@ -3312,7 +3312,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;
}

@@ -3426,7 +3426,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) {
@@ -3468,7 +3468,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;
@@ -3484,7 +3484,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;
}

@@ -3541,11 +3541,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_CCCR_INTx, NULL);
+ sdio_release_host(bus->sdiodev->func1);
intstatus = devpend & (INTR_STATUS_FUNC1 |
INTR_STATUS_FUNC2);
}
@@ -3571,13 +3571,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 */
@@ -3590,11 +3590,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;
@@ -3766,8 +3766,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;
@@ -3807,7 +3807,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()
@@ -3871,8 +3871,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
@@ -3911,7 +3911,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);

@@ -3932,7 +3932,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;
}

@@ -4019,7 +4019,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);
@@ -4041,7 +4041,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);
@@ -4057,7 +4057,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;
}

@@ -4081,7 +4081,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) {
@@ -4091,11 +4091,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)
@@ -4121,7 +4121,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;
@@ -4150,7 +4150,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;
@@ -4181,7 +4181,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 */
@@ -4197,17 +4197,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;
@@ -4259,7 +4259,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
@@ -4269,7 +4269,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);
}
@@ -4316,9 +4316,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 3d41bd94f97c..94d25201540f 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,
--
2.11.0

2017-07-26 20:46:39

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 | 91 +++++++++++-----------
1 file changed, 45 insertions(+), 46 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 9ef137d6eb3f..bee377fcc48f 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)
{
@@ -1077,6 +1053,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;
@@ -1085,10 +1063,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 */
@@ -1157,6 +1138,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;
@@ -1196,7 +1179,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)
@@ -2280,6 +2264,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;
@@ -2320,7 +2305,9 @@ 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)
@@ -2404,12 +2391,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");

@@ -2426,7 +2414,9 @@ 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;

@@ -2445,7 +2435,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]);
}
@@ -2511,6 +2502,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 */
@@ -2566,9 +2559,13 @@ 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)));
@@ -3992,22 +3989,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);
@@ -4038,8 +4034,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]);


@@ -4049,7 +4046,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-26 20:46:32

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 24775869aee4..6884d1f0b935 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-26 20:46:42

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 82769276654d..b4fd832cdabe 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-26 20:41:00

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 ecd242b33691..daa3c335804b 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);
}

@@ -907,6 +939,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;
@@ -914,25 +947,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",
@@ -1300,24 +1339,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-26 20:26:09

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 | 8 ++++----
1 file changed, 4 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..f585dfd89453 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -230,8 +230,8 @@ 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 +269,8 @@ 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-27 09:47:39

by Ian Molton

[permalink] [raw]
Subject: Re: Patch v4: Clean up brcmfmac driver

On 27/07/17 07:17, Kalle Valo wrote:
>> Here's a v4 of the cleanup patchset - checkpatch clean(er - I have purposely
>> left some warnings unaddressed).
>>
>> I also dropped an accidental adjustment of a debug macro from v3.
> Like I said already last time, please split the patchset into reasonable
> sizes (and submit one patchset at a time). I will automatically drop
> patchbombs like this.

How many patches would you like at once?

-Ian

2017-07-26 20:47:55

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 4c81ea24d19c..fb4f24dfc99d 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-26 20:46:46

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]>

# Conflicts:
# drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
---
.../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 78 ++++++++++++----------
1 file changed, 44 insertions(+), 34 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index b2945b463fd3..24775869aee4 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -228,41 +228,25 @@ 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)
+static int
+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;
+ if (bar0 == sdiodev->sbwad)
+ return 0;

- addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;
+ v = bar0 >> 8;

- for (i = 0 ; i < 3 && !err ; i++, addr >>= 8)
+ for (i = 0 ; i < 3 && !err ; i++, v >>= 8)
brcmf_sdiod_writeb(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;
+ 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)
@@ -270,11 +254,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;

@@ -286,11 +276,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;
}
@@ -538,10 +534,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:
@@ -559,10 +558,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);
@@ -604,7 +606,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);
@@ -624,10 +631,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,
@@ -671,7 +681,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;

@@ -714,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-08-07 11:25:39

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 03/34] brcmfmac: Split brcmf_sdiod_regrw_helper() up.

On 26-07-17 22:25, Ian Molton wrote:
> 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.

I really don't this it is all that obscure, but alas. Everything is in
the eye of the beholder. The reason for having the helper was to not
duplicate code for read and write and different access sizes. So now you
are duplicating it. In subsequent patches you throw away pieces of this
helper so duplication is not as bad in the net result. It would have
been easier if those patches were done before this one.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

some minor comment below

> ---
> .../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 2b441ce91d5f..1ee0f91b6c50 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> @@ -302,8 +302,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)

Fix the indent and column align to opening bracket.

Regards,
Arend

2017-08-07 11:25:22

by Arend Van Spriel

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

Hi Ian,

So it took me a while to get to this patch series. It is indeed way to
big and not well structured making it difficult to review the patches on
a per-patch basis.

I decided to limit myself to looking at the patches involving bcmsdh.c
doing a 'git log bcmsdh.c' on the applied patches. Still twenty patches
to review. I reviewed the first 15 patches of the series and skipped
patch [13/34] as it did not touch bcmsdh.c. A few response already
slipped to the mailing list so I will post the rest shortly. Here is the
first one.

On 26-07-17 22:25, Ian Molton wrote:
> All the other IO functions are the other way round in this
> driver. Make this one match.

Core SDIO functions are indeed the other way around, but the IO
functions in this file use (addr, data) pattern. So should we aim to get
it all consistent with core SDIO or just consistent on its own.

> Signed-off-by: Ian Molton <[email protected]>
> ---
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 8 ++++----
> 1 file changed, 4 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..f585dfd89453 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> @@ -230,8 +230,8 @@ 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)

The second line needs to be aligned on same column as the opening bracket.

Regards,
Arend

2017-08-19 20:27:03

by Ian Molton

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

On 07/08/17 12:27, Arend van Spriel wrote:
> On 7/26/2017 10:25 PM, Ian Molton wrote:
>> 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.
>
> Reviewed-by: Arend van Spriel <[email protected]>
>> Signed-off-by: Ian Molton <[email protected]>
>
> comments below...
>

>> - if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
>> - return -ENOMEDIUM;
>
> So now you are dropping the state check here, which seems significant
> enough to mention in the commit log. We need to discuss that. The idea
> of it was to refrain from using IO function of the MMC stack when we no
> there is no longer a device, ie. when stack has previously returned a
> -ENOMEDIUM.

Yeah, that code is broken (see earlier email) AFAICT anyway, and we
should probably handle losing our card a lot more gracefully in general.

>> + if (bar0 == sdiodev->sbwad)
>> + return 0;
>>
>> - addr = (address & SBSDIO_SBWINDOW_MASK) >> 8;
>> + v = bar0 >> 8;
>
> why introducing a new variable on the stack. You actually don't need any
> and just mask and shift the addr variable passed to the function.

Linux code *generally* doesn't do this. Its stylistic anyway, since the
compiler certainly won't be dumb enough to allocate another register (or
stack space) in this instance.

>> if (!retval)
>> data = sdio_readl(sdiodev->func[1], addr, &retval);
>
> The if-statement is now redundant here...

Good catch! :)

-Ian

2017-08-07 11:26:22

by Arend Van Spriel

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

On 7/26/2017 10:25 PM, Ian Molton wrote:
> If you need debugging this low level, you're doing something wrong.
> Remove these noisy debug statements so the code is more readable.

Needing this debugging does not necessarily means you are doing
something wrong. You may be dealing with hardware that is doing
something wrong and when that happens this debug can be useful. I
frankly hardly ever enable SDIO debug level unless I am in that
scenario. Maybe adding a debug level for low-level access would be
useful to reduce the noise for SDIO debug level.

Regards,
Arend

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

2017-08-08 12:29:30

by Arend Van Spriel

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

On 26-07-17 22:25, Ian Molton wrote:
> 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

Last but not least so to speak. I think "drastically" is a bit
overstated. In terms of readability it can go either way at far as I am
concerned. At least the above example does. In terms of instructions it
depends. Both dereferencing and helper variables on stack have their
price. So I (try to) use some soft limits when it comes to
dereferencing. The depth should not be more than 2, ie.:

bus->sdiodev->func1 is ok, bus->sdiodev->func1->card is not.

The number of dereferences within a particular code path in the function
should not be more than 3.

Also there are some places where you add both func1 and func2 to the
stack, but if you look at it you could do with just one of them.

>From this series I reviewed patches 1 upto and including patch 15, and
patches 29 through 34. Please rework those as requested and resubmit
them. Please also resubmit the remaining patch after that and consider
splitting it up file based. For example below could be a patch series
for chip.c related changes:

$ git log gerrit/brcm-wl-master..HEAD --reverse --oneline --
drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
4c75cf9 brcmfmac: Rename SOC_AI to SOC_AXI
acf9f33 brcmfmac: Get rid of chip_priv and core_priv structs
57cef44 brcmfmac: Whitespace patch
fe23a50 brcmfmac: Simplify chip probe routine
89e5bb5 brcmfmac: Rename axi functions for clarity.
a6352d7 brcmfmac: HUGE cleanup of IO access functions.
ee7ea4f brcmfmac: Rename chip.ctx -> chip.bus_priv

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

comments below...

> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 140 +++----
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 409 +++++++++++----------
> 2 files changed, 294 insertions(+), 255 deletions(-)

[...]

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

Actually only wanted to explicitly mention this one. Probably the
compiler is smart enough to keep sdiodev from the stack, but I would say
it is a variable you do not really need and also in terms of readability
it seems clear enough to do it in one assignment.

> 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;
> }
>

2017-08-08 12:36:38

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 30/34] brcmfmac: Correctly handle accesses to SDIO func0

On 26-07-17 22:25, Ian Molton wrote:
> Rather than workaround the restrictions on func0 addressing in the
> driver, set MMC_QUIRK_LENIENT_FN0

A quirk sounds like a workaround to me, but as it is provided by the mmc
stack it trumps a driver solution.

Acked-by: Arend van Spriel <[email protected]>
> 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(-)

2017-08-07 17:49:08

by Ian Molton

[permalink] [raw]
Subject: Re: [PATCH 03/34] brcmfmac: Split brcmf_sdiod_regrw_helper() up.

On 07/08/17 12:25, Arend van Spriel wrote:
> On 26-07-17 22:25, Ian Molton wrote:
>> 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.
>
> I really don't this it is all that obscure, but alas. Everything is in
> the eye of the beholder. The reason for having the helper was to not
> duplicate code for read and write and different access sizes. So now you
> are duplicating it. In subsequent patches you throw away pieces of this
> helper so duplication is not as bad in the net result. It would have
> been easier if those patches were done before this one.

I agree, this is a big and unwieldy patchset - I've attempted to break
the thing down in such a way that all the steps leading to the end
result are at least sane. I initially did it all in one hit and it was
utterly illegible :-(


> Fix the indent and column align to opening bracket.

I guess a few of these got through. I blame git rebase :)

-Ian

2017-08-19 20:39:24

by Ian Molton

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

On 08/08/17 13:29, Arend van Spriel wrote:
>> int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep)
>> {
>> + struct brcmf_sdio_dev *sdiodev = bus->sdiodev;
>> + struct sdio_func *func1 = sdiodev->func1;
>
> Actually only wanted to explicitly mention this one. Probably the
> compiler is smart enough to keep sdiodev from the stack, but I would say
> it is a variable you do not really need and also in terms of readability
> it seems clear enough to do it in one assignment.

Yeah, it could be - but as you say, the compiler *will* be smart enough,
and doing it in this manner makes it consistent with all the other code :-)

I'm looking at your other comments atm. :)

-Ian

>> 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);
>>

2017-08-07 11:11:58

by Arend Van Spriel

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

On 7/26/2017 10:25 PM, Ian Molton wrote:
> 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.

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

2017-08-07 17:55:27

by Ian Molton

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

On 07/08/17 12:26, Arend van Spriel wrote:
> On 7/26/2017 10:25 PM, Ian Molton wrote:
>> Primarily this patch removes:
>>
>> brcmf_sdiod_f0_writeb()
>> brcmf_sdiod_reg_write()
>> brcmf_sdiod_reg_read()
>
> Having [patch 30/34] "brcmfmac: Correctly handle accesses to SDIO func0"
> before this patch could make this look cleaner.

This is an artifact of how I came to the realisation the code was using
the obsoleted functions - it could be reordered, but it'd probably get
messy...

>> 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.
>
> As mentioned here this is more a rename than a replace so please use
> that in the subject as well.

Noted.

> Reviewed-by: Arend van Spriel <[email protected]>
>> Signed-off-by: Ian Molton <[email protected]>
>> ---
>> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 166
>> +++----------------
>> .../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 182
>> ++++++++++-----------
>> .../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 28 +++-
>> 3 files changed, 132 insertions(+), 244 deletions(-)
>

-Ian

2017-08-07 11:26:13

by Arend Van Spriel

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

On 7/26/2017 10:25 PM, Ian Molton wrote:
> Unlikely to be a problem, but brcmf_sdiod_regrb() is
> not symmetric with brcmf_sdiod_regrl() in this regard.

You are pretty keen on symmetry, but you could also remove the
initialization in brcmf_sdiod_regrl(). As long as no -Wunitialized pops
up that would have my preference.

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

2017-08-07 11:27:04

by Arend Van Spriel

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

On 7/26/2017 10:25 PM, Ian Molton wrote:
> 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.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

comments below...

> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 78 ++++++++++++----------
> 1 file changed, 44 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> index b2945b463fd3..24775869aee4 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> @@ -228,41 +228,25 @@ 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)
> +static int
> +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;

So now you are dropping the state check here, which seems significant
enough to mention in the commit log. We need to discuss that. The idea
of it was to refrain from using IO function of the MMC stack when we no
there is no longer a device, ie. when stack has previously returned a
-ENOMEDIUM.

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

why introducing a new variable on the stack. You actually don't need any
and just mask and shift the addr variable passed to the function.

> - for (i = 0 ; i < 3 && !err ; i++, addr >>= 8)
> + for (i = 0 ; i < 3 && !err ; i++, v >>= 8)
> brcmf_sdiod_writeb(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;
> + 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)
> @@ -270,11 +254,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);

The if-statement is now redundant here...

>
> +out:
> if (ret)
> *ret = retval;
>
> @@ -286,11 +276,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);

...and here.

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

2017-08-07 12:32:05

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 29/34] brcmfmac: stabilise the value of ->sbwad in use for some xfer routines.

So now I jump to this patch
On 7/26/2017 10:25 PM, Ian Molton wrote:
> 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/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
> index fb4f24dfc99d..1ab95011adb0 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 */

We actually just need the chipcommon base address so why not have that
here, ie.:
+ u32 cc_base;

Another option is to simple use SI_ENUM_BASE as the chipcommon base
address will always be 0x18000000 for the SDIO chips.

> struct brcmf_sdio *bus;
> struct device *dev;
> struct brcmf_bus *bus_if;
>

2017-08-19 20:33:14

by Ian Molton

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

On 08/08/17 12:19, Arend van Spriel wrote:
>> - sdio_f0_readb((sdiodev)->func[0], (addr), (r))
>> + sdio_f0_readb((sdiodev)->func[1], (addr), (r))
>
> There is no reason to keep these any longer as these do not provide any
> functionality over the core sdio function unless you consider the
> sdiodev dereference.

I'm happy to submit an incremental patch to these that gets us right
down to the linux mmc core functions. Just seemed like too big a change
to do in one hit.

-Ian

2017-08-07 17:51:30

by Ian Molton

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

On 07/08/17 12:25, Arend van Spriel wrote:
>> Handling of -ENOMEDIUM is altered, but as that's pretty much broken
>> anyway
>> we can ignore that.
>
> Please explain why you think it is broken.

Not got the code to hand right now, but from memory, theres a trapdoor
case where the state can wind up set to something that prevents it ever
being changed again. I'll dig it up when I get back from holiday (this
next few days).

-Ian

2017-08-30 19:32:46

by Arend Van Spriel

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

On 19-08-17 22:02, Ian Molton wrote:
> On 07/08/17 18:51, Ian Molton wrote:
>> On 07/08/17 12:25, Arend van Spriel wrote:
>>>> Handling of -ENOMEDIUM is altered, but as that's pretty much broken
>>>> anyway
>>>> we can ignore that.
>>>
>>> Please explain why you think it is broken.
>>
>> Not got the code to hand right now, but from memory, theres a trapdoor
>> case where the state can wind up set to something that prevents it ever
>> being changed again. I'll dig it up when I get back from holiday (this
>> next few days).
>
> Hi,
>
> Here is the function I had in mind:
>
>
> void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
> enum brcmf_sdiod_state state)
> {
> if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM ||
> state == sdiodev->state)
> return;
>
> brcmf_dbg(TRACE, "%d -> %d\n", sdiodev->state, state);
> switch (sdiodev->state) {
> case BRCMF_SDIOD_DATA:
> /* any other state means bus interface is down */
> brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_DOWN);
> break;
> case BRCMF_SDIOD_DOWN:
> /* transition from DOWN to DATA means bus interface is up */
> if (state == BRCMF_SDIOD_DATA)
> brcmf_bus_change_state(sdiodev->bus_if,
> BRCMF_BUS_UP);
> break;
> default:
> break;
> }
> sdiodev->state = state;
> }
>
>
> If it's *ever* called with state = BRCMF_SDIOD_NOMEDIUM it will
> eventually (last line) set sdiodev->state to the same value.
>
> If its ever called again, the first if() statement will make it return
> before ever changing sdiodev->state again, no matter what value is
> passed for state.
>
> This has to be a bug, surely?

I thought I already responded this email. So it is not a bug. It really
was made like this intentional. It is the end state of this little FSM.
The thing is that there was no way to recover. Maybe nowadays with the
MMC stack being able to power sequence the device (provided it is
properly configured in device tree) we may get lucky using
mmc_hw_reset(). But now you need to consider how many times to call that
before giving up and what driver components/states need to be reset as
well. So I would prefer to keep the current behavior until a more
graceful approach has been designed and implemented to replace it.

Regards,
Arend

2017-08-08 12:29:21

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 33/34] brcmfmac: Remove array of functions

On 26-07-17 22:25, Ian Molton wrote:
> Replace the array of functions with a pair of pointers to the
> relevant functions.

Acked-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>
>
> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 117 +++++++--------
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 166 ++++++++++-----------
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 15 +-
> 3 files changed, 146 insertions(+), 152 deletions(-)

2017-08-19 20:57:57

by Ian Molton

[permalink] [raw]
Subject: Re: [PATCH 06/34] brcmfmac: Remove bandaid for SleepCSR

On 07/08/17 12:25, Arend van Spriel wrote:
> On 26-07-17 22:25, Ian Molton wrote:
>> 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.
>
> So lets make it a SDIO debug message for all register accesses getting
> rid of the error message.

Not quite sure I follow here - but as the code is completely gone in
later patches in the series, does it matter?

Perhaps address this if it in future, if it crops up as a problem, since
it wont be fatal even if it does...

-Ian

2017-08-19 19:52:13

by Ian Molton

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

On 07/08/17 12:25, Arend van Spriel wrote:
>> All the other IO functions are the other way round in this
>> driver. Make this one match.
>
> Core SDIO functions are indeed the other way around, but the IO
> functions in this file use (addr, data) pattern. So should we aim to get
> it all consistent with core SDIO or just consistent on its own.

This is preparatory for a later patch that removes this abstraction
altogether, so yes, it should match the SDIO order.

-Ian

2017-08-19 21:41:46

by Ian Molton

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

On 07/08/17 12:26, Arend van Spriel wrote:

>> + err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);
>>
>> brcmu_pkt_buf_free_skb(mypkt);
>> +
>
> You are keen on sprinkling whitespace here and there. Could you please
> use separate patches for that as much as possible. Not sure why you
> added this one...
>
>> return err;
>>
>
> ...and kept this one.
>
>> }
>

Good catch. There's a couple of others - I'll break them out. That
latter one is clearly an error on my part.

-Ian

2017-08-08 12:29:12

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 32/34] brcmfmac: Replace function index with function pointer

On 26-07-17 22:25, Ian Molton wrote:
> In preparation for removing the function array, remove all code that
> refers to function by index and replace with pointers to the function
> itself.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

comments below...

> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 86 ++++++++++++----------
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 14 ++--
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 14 ++--
> 3 files changed, 61 insertions(+), 53 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> index da0654c50db9..5787348003d9 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> @@ -148,7 +148,8 @@ 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;

This is not really related except that you are doing away with the
SDIO_FUNC_{1,2} defintions. Please use separate patch for this. The BIT0
should basically be FUNC0.

> brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, data, &ret);
>
> /* redirect, configure and enable io for interrupt signal */

[...]

> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
> index 227c90198a8e..3d41bd94f97c 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 BIT(0)

Better change BIT0 to FUNC0 in separate patch as mentioned above.

> +#define SDIO_CCCR_IEN_FUNC1 BIT(1)
> +#define SDIO_CCCR_IEN_FUNC2 BIT(2)
> +

2017-08-07 11:25:49

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 05/34] brcmfmac: Remove dead IO code

On 26-07-17 22:25, Ian Molton wrote:
> The value passed to brcmf_sdiod_addrprep() is *always* 4
> remove this parameter and the unused code to handle it.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>
> ---
> .../net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)

2017-08-07 11:25:55

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 06/34] brcmfmac: Remove bandaid for SleepCSR

On 26-07-17 22:25, Ian Molton wrote:
> 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.

So lets make it a SDIO debug message for all register accesses getting
rid of the error message.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>
>
> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 28 +---------------------
> 1 file changed, 1 insertion(+), 27 deletions(-)

2017-08-07 11:26:57

by Arend Van Spriel

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

On 7/26/2017 10:25 PM, Ian Molton wrote:
> Primarily this patch removes:
>
> brcmf_sdiod_f0_writeb()
> brcmf_sdiod_reg_write()
> brcmf_sdiod_reg_read()

Having [patch 30/34] "brcmfmac: Correctly handle accesses to SDIO func0"
before this patch could make this look cleaner.

> 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.

As mentioned here this is more a rename than a replace so please use
that in the subject as well.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 166 +++----------------
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 182 ++++++++++-----------
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 28 +++-
> 3 files changed, 132 insertions(+), 244 deletions(-)

2017-08-07 11:26:37

by Arend Van Spriel

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

On 7/26/2017 10:25 PM, Ian Molton wrote:
> This function needs to be split up into separate read / write variants
> for clarity.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

more comments below...

> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 69 +++++++++++++++-------
> 1 file changed, 47 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> index 9d5716d0ad73..858ad2d8706b 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c

[...]

> @@ -706,10 +725,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);
> +

You are keen on sprinkling whitespace here and there. Could you please
use separate patches for that as much as possible. Not sure why you
added this one...

> return err;
>

...and kept this one.

> }

2017-08-19 20:02:17

by Ian Molton

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

On 07/08/17 18:51, Ian Molton wrote:
> On 07/08/17 12:25, Arend van Spriel wrote:
>>> Handling of -ENOMEDIUM is altered, but as that's pretty much broken
>>> anyway
>>> we can ignore that.
>>
>> Please explain why you think it is broken.
>
> Not got the code to hand right now, but from memory, theres a trapdoor
> case where the state can wind up set to something that prevents it ever
> being changed again. I'll dig it up when I get back from holiday (this
> next few days).

Hi,

Here is the function I had in mind:


void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
enum brcmf_sdiod_state state)
{
if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM ||
state == sdiodev->state)
return;

brcmf_dbg(TRACE, "%d -> %d\n", sdiodev->state, state);
switch (sdiodev->state) {
case BRCMF_SDIOD_DATA:
/* any other state means bus interface is down */
brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_DOWN);
break;
case BRCMF_SDIOD_DOWN:
/* transition from DOWN to DATA means bus interface is up */
if (state == BRCMF_SDIOD_DATA)
brcmf_bus_change_state(sdiodev->bus_if,
BRCMF_BUS_UP);
break;
default:
break;
}
sdiodev->state = state;
}


If it's *ever* called with state = BRCMF_SDIOD_NOMEDIUM it will
eventually (last line) set sdiodev->state to the same value.

If its ever called again, the first if() statement will make it return
before ever changing sdiodev->state again, no matter what value is
passed for state.

This has to be a bug, surely?

-Ian

2017-08-19 21:50:17

by Ian Molton

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

On 07/08/17 18:55, Ian Molton wrote:
> On 07/08/17 12:26, Arend van Spriel wrote:
>> On 7/26/2017 10:25 PM, Ian Molton wrote:
>>> Primarily this patch removes:
>>>
>>> brcmf_sdiod_f0_writeb()
>>> brcmf_sdiod_reg_write()
>>> brcmf_sdiod_reg_read()
>>
>> Having [patch 30/34] "brcmfmac: Correctly handle accesses to SDIO func0"
>> before this patch could make this look cleaner.
>
> This is an artifact of how I came to the realisation the code was using
> the obsoleted functions - it could be reordered, but it'd probably get
> messy...

I gave it a try, and it got messy - I'd prefer to leave these patches in
their current ordering if thats OK.

-Ian

2017-08-07 11:26:29

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 10/34] brcmfmac: Rename bcmerror to err

On 7/26/2017 10:25 PM, Ian Molton wrote:
> Trivial cleanup of nasty variable name

Did not look, but here is...

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

2017-08-07 11:54:50

by Arend Van Spriel

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

On 8/7/2017 1:11 PM, Arend van Spriel wrote:
> On 7/26/2017 10:25 PM, Ian Molton wrote:
>> 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.

Actually noticed a minor nit. The subject says "brcmfamc".

Regards,
Arend

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

2017-08-08 12:33:44

by Arend Van Spriel

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



On 08-08-17 13:27, Ian Molton wrote:
> On 08/08/17 12:19, Arend van Spriel wrote:
>
>>> #define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
>>> - sdio_f0_readb((sdiodev)->func[0], (addr), (r))
>>> + sdio_f0_readb((sdiodev)->func[1], (addr), (r))
>>
>> There is no reason to keep these any longer as these do not provide any
>> functionality over the core sdio function unless you consider the
>> sdiodev dereference.
>>
>
> I tend to agree, although they're fairly readable anyway. I was trying
> to keep the changes small and incremental.
>
> I'll knock up a patch and see how it looks with them converted to the
> actual functions when I get back from hoiliday.

Enjoy the holiday. Glad to see I am not the only one checking email when
he is not supposed to work ;-)

Regards,
Arend

2017-08-07 11:26:01

by Arend Van Spriel

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

On 26-07-17 22:25, Ian Molton wrote:
> 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.

Please explain why you think it is broken.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

more comments below.

> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 239 ++++++++-------------
> .../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 2 +-
> 2 files changed, 87 insertions(+), 154 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> index d217b1281e0d..f703d7be6a85 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c

[...]

> 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();

Please do not use BUG() as it simply crashes the system. You may argue
that we never reach this unless a coding mistake is made, but still we
prefer WARN() over BUG() in such cases.

> + 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;
> + 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;
>
> - sdiodev->sbwad = bar0;
> + *(u32 *)data = sdio_readl(sdiodev->func[1], addr, &ret);
> + break;
> + default:
> + BUG();

same here as with reg_write() function.

> + ret = -EINVAL;
> + break;
> + }
> }
>
> - *addr &= SBSDIO_SB_OFT_ADDR_MASK;
> - *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
> -
> - return 0;
> +done:
> + return ret;
> }
>
> u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
> @@ -439,15 +386,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);

Now this debug statement move before the actual read, which makes it
useless. You are going to remove it in a subsequent patch, but still.

> + retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);
>
> -done:
> if (ret)
> *ret = retval;
>

2017-08-08 11:19:48

by Arend Van Spriel

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

On 26-07-17 22:25, Ian Molton wrote:
> 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.

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

[...]

> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
> index 8a976c89cf63..227c90198a8e 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
> -

Good riddance, because ...

> /* 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];

... it was not used anyway as this definition is in <linux/mmc/card.h>.

> + 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))

There is no reason to keep these any longer as these do not provide any
functionality over the core sdio function unless you consider the
sdiodev dereference.

2017-08-19 20:31:31

by Ian Molton

[permalink] [raw]
Subject: Re: [PATCH 29/34] brcmfmac: stabilise the value of ->sbwad in use for some xfer routines.

On 07/08/17 13:32, Arend van Spriel wrote:
>
> We actually just need the chipcommon base address so why not have that
> here, ie.:
> + u32 cc_base;

I see no advantage to that - the u32 is the same size as (or not much
bigger than the pointer to the struct brcmf_core, and my approach makes
it clear where the value came from rather than making another copy of it.

> Another option is to simple use SI_ENUM_BASE as the chipcommon base
> address will always be 0x18000000 for the SDIO chips.

I don't like this approach. Why bother probing the core if we then dont
use the values returned? May as well hard code everything... Also not
futureproof.

-Ian

2017-08-19 21:06:43

by Ian Molton

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

On 07/08/17 12:26, Arend van Spriel wrote:
> On 7/26/2017 10:25 PM, Ian Molton wrote:
>> Unlikely to be a problem, but brcmf_sdiod_regrb() is
>> not symmetric with brcmf_sdiod_regrl() in this regard.
>
> You are pretty keen on symmetry, but you could also remove the
> initialization in brcmf_sdiod_regrl(). As long as no -Wunitialized pops
> up that would have my preference.

Whilst the compiler does not complain, there are paths through
brcmf_sdiod_reg_read() that do not set *data, so I think it best to
initialise the value, but its not really very important. Code that isn't
checking the return value is asking for it anyway :)

In the later patches we could remove the initialisation, as IIRC the
Linux MMC IO functions do it for us and we don't avoid calling them in
that version of the code.

-Ian

2017-08-19 20:18:13

by Ian Molton

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

On 07/08/17 12:26, Arend van Spriel wrote:
>
> Needing this debugging does not necessarily means you are doing
> something wrong. You may be dealing with hardware that is doing
> something wrong and when that happens this debug can be useful. I
> frankly hardly ever enable SDIO debug level unless I am in that
> scenario. Maybe adding a debug level for low-level access would be
> useful to reduce the noise for SDIO debug level.

Perhaps, but its only actually called from a half dozen or so places in
the code + the buscore_*32 entrypoints.

All it actually does now is ensure the address window is right and call
the Linux SDIO core readl method. if we can't trust that, we're kinda
screwed anyway. If we later bring the SDIO code in line with the PCIe
code, it wont even do the address window checking (it'll just assume its
already correct).

We can always enable the SDIO core lowlevel debug if we really want to
see register level acceses.

-Ian

2017-08-07 11:25:34

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 02/34] brcmfmac: Register sizes on hardware are not dependent on compiler types

On 26-07-17 22:25, Ian Molton wrote:
> The 4 IO functions in this patch are incorrect as they use compiler types
> to determine how many bytes to send to the hardware.

I see no incorrectness here. It is validating the regsz value and those
compiler types are pretty well defined I would say. Anyway, I find the
use of sizeof() here pretty useless so thanks for the change.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>
> ---
> .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)

2017-08-05 20:08:46

by Arend Van Spriel

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

On 26-07-17 22:25, Ian Molton wrote:
> 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.

No beef here ;-)

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>
>
> # Conflicts:
> # drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> ---
> .../net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 17 +++++------------
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 3 ---
> 2 files changed, 5 insertions(+), 15 deletions(-)

2017-08-07 19:30:31

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH 13/34] brcmfmac: Tidy register definitions a little

On 26-07-17 22:25, Ian Molton wrote:
> Trivial tidy of register definitions.

Initially skipped this one, but it is indeed trivial.

Reviewed-by: Arend van Spriel <[email protected]>
> Signed-off-by: Ian Molton <[email protected]>

comment below...

> ---
> 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 4c81ea24d19c..fb4f24dfc99d 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

So the SEPINT definitions are not consistent with the other ones. Maybe
drop the SDIO_CCCR from the other value definitions and for the SEPINT
replace 'SDIO_' with 'SEPINT_'.

2017-08-08 11:27:20

by Ian Molton

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

On 08/08/17 12:19, Arend van Spriel wrote:

>> #define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
>> - sdio_f0_readb((sdiodev)->func[0], (addr), (r))
>> + sdio_f0_readb((sdiodev)->func[1], (addr), (r))
>
> There is no reason to keep these any longer as these do not provide any
> functionality over the core sdio function unless you consider the
> sdiodev dereference.
>

I tend to agree, although they're fairly readable anyway. I was trying
to keep the changes small and incremental.

I'll knock up a patch and see how it looks with them converted to the
actual functions when I get back from hoiliday.

-Ian