2023-06-03 06:01:51

by Neal Sidhwaney

[permalink] [raw]
Subject: [PATCH v3] wifi: brcmfmac: Detect corner error case earlier with log

In brcmf_chip_recognition, the return value from an MMIO read is
interpreted as various fields without checking if it failed, which is
harmless today, as the interpreted fields are checked for validity a
few lines below. However, in corner cases (on my MacbookPro 14,1,
sometimes after waking from sleep or soft reboot), when this happens,
it causes the logging to be misleading, because the message indicates
an unsupported chip type ("brcmfmac: brcmf_chip_recognition: chip
backplane type 15 is not supported"). This patch detects this case
slightly earlier and logs an appropriate message, with the same return
result as is the case today.

Signed-off-by: Neal Sidhwaney <[email protected]>
---
v3: Fix indentation and add context to commit message
v2: Add const to variable holding error code & fix patch submission

drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
index 9f9bf08a70bb..2ef92ef25517 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
@@ -972,6 +972,7 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
u32 regdata;
u32 socitype;
int ret;
+ const u32 READ_FAILED = 0xFFFFFFFF;

/* Get CC core rev
* Chipid is assume to be at offset 0 from SI_ENUM_BASE
@@ -980,6 +981,11 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
*/
regdata = ci->ops->read32(ci->ctx,
CORE_CC_REG(ci->pub.enum_base, chipid));
+ if (regdata == READ_FAILED) {
+ brcmf_err("MMIO read failed: 0x%08x\n", regdata);
+ return -ENODEV;
+ }
+
ci->pub.chip = regdata & CID_ID_MASK;
ci->pub.chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
--
2.40.1


2023-06-08 16:10:45

by Kalle Valo

[permalink] [raw]
Subject: Re: [v3] wifi: brcmfmac: Detect corner error case earlier with log

Neal Sidhwaney <[email protected]> wrote:

> In brcmf_chip_recognition(), the return value from an MMIO read is
> interpreted as various fields without checking if it failed, which is
> harmless today, as the interpreted fields are checked for validity a
> few lines below. However, in corner cases (on my MacbookPro 14,1,
> sometimes after waking from sleep or soft reboot), when this happens,
> it causes the logging to be misleading, because the message indicates
> an unsupported chip type ("brcmfmac: brcmf_chip_recognition: chip
> backplane type 15 is not supported"). This patch detects this case
> slightly earlier and logs an appropriate message, with the same return
> result as is the case today.
>
> Signed-off-by: Neal Sidhwaney <[email protected]>

Patch applied to wireless-next.git, thanks.

f8f912bf69a0 wifi: brcmfmac: Detect corner error case earlier with log

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches