320-v5.0-0003-brcmfmac-Add-support-for-first-trying-to-get-a-board.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From eae8e50669e15002b195177212a6e25afbe7cf4d Mon Sep 17 00:00:00 2001
  2. From: Hans de Goede <[email protected]>
  3. Date: Wed, 10 Oct 2018 13:01:00 +0200
  4. Subject: [PATCH] brcmfmac: Add support for first trying to get a board
  5. specific nvram file
  6. The nvram files which some brcmfmac chips need are board-specific. To be
  7. able to distribute these as part of linux-firmware, so that devices with
  8. such a wifi chip will work OOTB, multiple (one per board) versions must
  9. co-exist under /lib/firmware.
  10. This commit adds support for callers of the brcmfmac/firmware.c code to
  11. pass in a board_type parameter through the request structure.
  12. If that parameter is set then the code will first try to load
  13. chipmodel.board_type.txt before falling back to the old chipmodel.txt name.
  14. Signed-off-by: Hans de Goede <[email protected]>
  15. Signed-off-by: Kalle Valo <[email protected]>
  16. ---
  17. .../broadcom/brcm80211/brcmfmac/firmware.c | 27 +++++++++++++++++++++-
  18. .../broadcom/brcm80211/brcmfmac/firmware.h | 1 +
  19. 2 files changed, 27 insertions(+), 1 deletion(-)
  20. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
  21. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
  22. @@ -532,6 +532,31 @@ static int brcmf_fw_complete_request(con
  23. return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
  24. }
  25. +static int brcmf_fw_request_firmware(const struct firmware **fw,
  26. + struct brcmf_fw *fwctx)
  27. +{
  28. + struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos];
  29. + int ret;
  30. +
  31. + /* nvram files are board-specific, first try a board-specific path */
  32. + if (cur->type == BRCMF_FW_TYPE_NVRAM && fwctx->req->board_type) {
  33. + char alt_path[BRCMF_FW_NAME_LEN];
  34. +
  35. + strlcpy(alt_path, cur->path, BRCMF_FW_NAME_LEN);
  36. + /* strip .txt at the end */
  37. + alt_path[strlen(alt_path) - 4] = 0;
  38. + strlcat(alt_path, ".", BRCMF_FW_NAME_LEN);
  39. + strlcat(alt_path, fwctx->req->board_type, BRCMF_FW_NAME_LEN);
  40. + strlcat(alt_path, ".txt", BRCMF_FW_NAME_LEN);
  41. +
  42. + ret = request_firmware(fw, alt_path, fwctx->dev);
  43. + if (ret == 0)
  44. + return ret;
  45. + }
  46. +
  47. + return request_firmware(fw, cur->path, fwctx->dev);
  48. +}
  49. +
  50. static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
  51. {
  52. struct brcmf_fw *fwctx = ctx;
  53. @@ -544,7 +569,7 @@ static void brcmf_fw_request_done(const
  54. while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
  55. cur = &fwctx->req->items[fwctx->curpos];
  56. - request_firmware(&fw, cur->path, fwctx->dev);
  57. + brcmf_fw_request_firmware(&fw, fwctx);
  58. ret = brcmf_fw_complete_request(fw, ctx);
  59. }
  60. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
  61. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
  62. @@ -70,6 +70,7 @@ struct brcmf_fw_request {
  63. u16 domain_nr;
  64. u16 bus_nr;
  65. u32 n_items;
  66. + const char *board_type;
  67. struct brcmf_fw_item items[0];
  68. };