wifi: brcmfmac: Detect corner error case earlier with log
authorNeal Sidhwaney <nealsid@gmail.com>
Sat, 3 Jun 2023 06:00:23 +0000 (02:00 -0400)
committerKalle Valo <kvalo@kernel.org>
Thu, 8 Jun 2023 16:00:00 +0000 (19:00 +0300)
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 <nealsid@gmail.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20230603060021.57225-1-nealsid@gmail.com
drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c

index 9f9bf08..2ef92ef 100644 (file)
@@ -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;