Message ID | 20220104072658.69756-34-marcan@marcan.st (mailing list archive) |
---|---|
State | Handled Elsewhere, archived |
Headers | show |
Series | brcmfmac: Support Apple T2 and M1 platforms | expand |
On 1/4/2022 8:26 AM, Hector Martin wrote: > The TxCap blobs are additional data blobs used on Apple devices, and > are uploaded analogously to CLM blobs. Add core support for doing this. Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com> > Acked-by: Linus Walleij <linus.walleij@linaro.org> > Signed-off-by: Hector Martin <marcan@marcan.st> > --- > .../broadcom/brcm80211/brcmfmac/bus.h | 1 + > .../broadcom/brcm80211/brcmfmac/common.c | 97 +++++++++++++------ > 2 files changed, 71 insertions(+), 27 deletions(-) > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h > index b13af8f631f3..f4bd98da9761 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h > @@ -39,6 +39,7 @@ enum brcmf_bus_protocol_type { > /* Firmware blobs that may be available */ > enum brcmf_blob_type { > BRCMF_BLOB_CLM, > + BRCMF_BLOB_TXCAP, > }; > > struct brcmf_mp_device; > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c > index c84c48e49fde..d65308c3f070 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c [...] > @@ -165,20 +157,64 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) > } while ((datalen > 0) && (err == 0)); > [...] > +static int brcmf_c_process_txcap_blob(struct brcmf_if *ifp) > +{ > + struct brcmf_pub *drvr = ifp->drvr; > + struct brcmf_bus *bus = drvr->bus_if; > + const struct firmware *fw = NULL; > + s32 err; > + > + brcmf_dbg(TRACE, "Enter\n"); > + > + err = brcmf_bus_get_blob(bus, &fw, BRCMF_BLOB_TXCAP); > + if (err || !fw) { > + brcmf_info("no txcap_blob available (err=%d)\n", err); > + return 0; > + } > + > + brcmf_info("TxCap blob found, loading\n"); > + err = brcmf_c_download_blob(ifp, fw->data, fw->size, > + "txcapload", "txcapload_status"); Although unlikely that we end up here with a firmware that does not support this command it is not impossible. Should we handle that here or introduce a feature flag for txcap loading? > + release_firmware(fw); > return err; > }
On 21/01/2022 16.36, Arend van Spriel wrote: > On 1/4/2022 8:26 AM, Hector Martin wrote: >> The TxCap blobs are additional data blobs used on Apple devices, and >> are uploaded analogously to CLM blobs. Add core support for doing this. > > Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com> >> Acked-by: Linus Walleij <linus.walleij@linaro.org> >> Signed-off-by: Hector Martin <marcan@marcan.st> >> --- >> .../broadcom/brcm80211/brcmfmac/bus.h | 1 + >> .../broadcom/brcm80211/brcmfmac/common.c | 97 +++++++++++++------ >> 2 files changed, 71 insertions(+), 27 deletions(-) >> >> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h >> index b13af8f631f3..f4bd98da9761 100644 >> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h >> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h >> @@ -39,6 +39,7 @@ enum brcmf_bus_protocol_type { >> /* Firmware blobs that may be available */ >> enum brcmf_blob_type { >> BRCMF_BLOB_CLM, >> + BRCMF_BLOB_TXCAP, >> }; >> >> struct brcmf_mp_device; >> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c >> index c84c48e49fde..d65308c3f070 100644 >> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c >> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c > > [...] > >> @@ -165,20 +157,64 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) >> } while ((datalen > 0) && (err == 0)); >> > > [...] > >> +static int brcmf_c_process_txcap_blob(struct brcmf_if *ifp) >> +{ >> + struct brcmf_pub *drvr = ifp->drvr; >> + struct brcmf_bus *bus = drvr->bus_if; >> + const struct firmware *fw = NULL; >> + s32 err; >> + >> + brcmf_dbg(TRACE, "Enter\n"); >> + >> + err = brcmf_bus_get_blob(bus, &fw, BRCMF_BLOB_TXCAP); >> + if (err || !fw) { >> + brcmf_info("no txcap_blob available (err=%d)\n", err); >> + return 0; >> + } >> + >> + brcmf_info("TxCap blob found, loading\n"); >> + err = brcmf_c_download_blob(ifp, fw->data, fw->size, >> + "txcapload", "txcapload_status"); > > Although unlikely that we end up here with a firmware that does not > support this command it is not impossible. Should we handle that here or > introduce a feature flag for txcap loading? Hmm, like trying to read txcapload_status to set the feature flag? Honestly though, if we end up here on an unsupported firmware that sounds like a firmware loading error, since if we have a TxCap blob for a given board we better have a firmware that supports it. So it doesn't feel too wrong to just error out entirely so the user knows something is horribly wrong, instead of trying to use what is probably the wrong firmware.
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index b13af8f631f3..f4bd98da9761 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -39,6 +39,7 @@ enum brcmf_bus_protocol_type { /* Firmware blobs that may be available */ enum brcmf_blob_type { BRCMF_BLOB_CLM, + BRCMF_BLOB_TXCAP, }; struct brcmf_mp_device; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c index c84c48e49fde..d65308c3f070 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c @@ -101,7 +101,7 @@ void brcmf_c_set_joinpref_default(struct brcmf_if *ifp) static int brcmf_c_download(struct brcmf_if *ifp, u16 flag, struct brcmf_dload_data_le *dload_buf, - u32 len) + u32 len, const char *var) { s32 err; @@ -112,17 +112,17 @@ static int brcmf_c_download(struct brcmf_if *ifp, u16 flag, dload_buf->crc = cpu_to_le32(0); len = sizeof(*dload_buf) + len - 1; - err = brcmf_fil_iovar_data_set(ifp, "clmload", dload_buf, len); + err = brcmf_fil_iovar_data_set(ifp, var, dload_buf, len); return err; } -static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) +static int brcmf_c_download_blob(struct brcmf_if *ifp, + const void *data, size_t size, + const char *loadvar, const char *statvar) { struct brcmf_pub *drvr = ifp->drvr; - struct brcmf_bus *bus = drvr->bus_if; struct brcmf_dload_data_le *chunk_buf; - const struct firmware *clm = NULL; u32 chunk_len; u32 datalen; u32 cumulative_len; @@ -132,20 +132,11 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) brcmf_dbg(TRACE, "Enter\n"); - err = brcmf_bus_get_blob(bus, &clm, BRCMF_BLOB_CLM); - if (err || !clm) { - brcmf_info("no clm_blob available (err=%d), device may have limited channels available\n", - err); - return 0; - } - chunk_buf = kzalloc(sizeof(*chunk_buf) + MAX_CHUNK_LEN - 1, GFP_KERNEL); - if (!chunk_buf) { - err = -ENOMEM; - goto done; - } + if (!chunk_buf) + return -ENOMEM; - datalen = clm->size; + datalen = size; cumulative_len = 0; do { if (datalen > MAX_CHUNK_LEN) { @@ -154,9 +145,10 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) chunk_len = datalen; dl_flag |= DL_END; } - memcpy(chunk_buf->data, clm->data + cumulative_len, chunk_len); + memcpy(chunk_buf->data, data + cumulative_len, chunk_len); - err = brcmf_c_download(ifp, dl_flag, chunk_buf, chunk_len); + err = brcmf_c_download(ifp, dl_flag, chunk_buf, chunk_len, + loadvar); dl_flag &= ~DL_BEGIN; @@ -165,20 +157,64 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) } while ((datalen > 0) && (err == 0)); if (err) { - bphy_err(drvr, "clmload (%zu byte file) failed (%d)\n", - clm->size, err); - /* Retrieve clmload_status and print */ - err = brcmf_fil_iovar_int_get(ifp, "clmload_status", &status); + bphy_err(drvr, "%s (%zu byte file) failed (%d)\n", + loadvar, size, err); + /* Retrieve status and print */ + err = brcmf_fil_iovar_int_get(ifp, statvar, &status); if (err) - bphy_err(drvr, "get clmload_status failed (%d)\n", err); + bphy_err(drvr, "get %s failed (%d)\n", statvar, err); else - brcmf_dbg(INFO, "clmload_status=%d\n", status); + brcmf_dbg(INFO, "%s=%d\n", statvar, status); err = -EIO; } kfree(chunk_buf); -done: - release_firmware(clm); + return err; +} + +static int brcmf_c_process_clm_blob(struct brcmf_if *ifp) +{ + struct brcmf_pub *drvr = ifp->drvr; + struct brcmf_bus *bus = drvr->bus_if; + const struct firmware *fw = NULL; + s32 err; + + brcmf_dbg(TRACE, "Enter\n"); + + err = brcmf_bus_get_blob(bus, &fw, BRCMF_BLOB_CLM); + if (err || !fw) { + brcmf_info("no clm_blob available (err=%d), device may have limited channels available\n", + err); + return 0; + } + + err = brcmf_c_download_blob(ifp, fw->data, fw->size, + "clmload", "clmload_status"); + + release_firmware(fw); + return err; +} + +static int brcmf_c_process_txcap_blob(struct brcmf_if *ifp) +{ + struct brcmf_pub *drvr = ifp->drvr; + struct brcmf_bus *bus = drvr->bus_if; + const struct firmware *fw = NULL; + s32 err; + + brcmf_dbg(TRACE, "Enter\n"); + + err = brcmf_bus_get_blob(bus, &fw, BRCMF_BLOB_TXCAP); + if (err || !fw) { + brcmf_info("no txcap_blob available (err=%d)\n", err); + return 0; + } + + brcmf_info("TxCap blob found, loading\n"); + err = brcmf_c_download_blob(ifp, fw->data, fw->size, + "txcapload", "txcapload_status"); + + release_firmware(fw); return err; } @@ -248,6 +284,13 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) goto done; } + /* Do TxCap downloading, if needed */ + err = brcmf_c_process_txcap_blob(ifp); + if (err < 0) { + bphy_err(drvr, "download TxCap blob file failed, %d\n", err); + goto done; + } + /* query for 'ver' to get version info from firmware */ memset(buf, 0, sizeof(buf)); err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));