349-0003-brcmfmac-insert-default-boardrev-in-nvram-data-if-mi.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From: Hante Meuleman <hante.meuleman@broadcom.com>
  2. Date: Mon, 11 Apr 2016 11:35:23 +0200
  3. Subject: [PATCH] brcmfmac: insert default boardrev in nvram data if
  4. missing
  5. Some nvram files/stores come without the boardrev information,
  6. but firmware requires this to be set. When not found in nvram then
  7. add a default boardrev string to the nvram data.
  8. Reported-by: Rafal Milecki <zajec5@gmail.com>
  9. Reviewed-by: Arend Van Spriel <arend@broadcom.com>
  10. Reviewed-by: Franky (Zhenhui) Lin <franky.lin@broadcom.com>
  11. Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
  12. Signed-off-by: Hante Meuleman <hante.meuleman@broadcom.com>
  13. Signed-off-by: Arend van Spriel <arend@broadcom.com>
  14. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  15. ---
  16. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
  17. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
  18. @@ -29,6 +29,7 @@
  19. #define BRCMF_FW_MAX_NVRAM_SIZE 64000
  20. #define BRCMF_FW_NVRAM_DEVPATH_LEN 19 /* devpath0=pcie/1/4/ */
  21. #define BRCMF_FW_NVRAM_PCIEDEV_LEN 10 /* pcie/1/4/ + \0 */
  22. +#define BRCMF_FW_DEFAULT_BOARDREV "boardrev=0xff"
  23. enum nvram_parser_state {
  24. IDLE,
  25. @@ -51,6 +52,7 @@ enum nvram_parser_state {
  26. * @entry: start position of key,value entry.
  27. * @multi_dev_v1: detect pcie multi device v1 (compressed).
  28. * @multi_dev_v2: detect pcie multi device v2.
  29. + * @boardrev_found: nvram contains boardrev information.
  30. */
  31. struct nvram_parser {
  32. enum nvram_parser_state state;
  33. @@ -63,6 +65,7 @@ struct nvram_parser {
  34. u32 entry;
  35. bool multi_dev_v1;
  36. bool multi_dev_v2;
  37. + bool boardrev_found;
  38. };
  39. /**
  40. @@ -125,6 +128,8 @@ static enum nvram_parser_state brcmf_nvr
  41. nvp->multi_dev_v1 = true;
  42. if (strncmp(&nvp->data[nvp->entry], "pcie/", 5) == 0)
  43. nvp->multi_dev_v2 = true;
  44. + if (strncmp(&nvp->data[nvp->entry], "boardrev", 8) == 0)
  45. + nvp->boardrev_found = true;
  46. } else if (!is_nvram_char(c) || c == ' ') {
  47. brcmf_dbg(INFO, "warning: ln=%d:col=%d: '=' expected, skip invalid key entry\n",
  48. nvp->line, nvp->column);
  49. @@ -284,6 +289,8 @@ static void brcmf_fw_strip_multi_v1(stru
  50. while (i < nvp->nvram_len) {
  51. if ((nvp->nvram[i] - '0' == id) && (nvp->nvram[i + 1] == ':')) {
  52. i += 2;
  53. + if (strncmp(&nvp->nvram[i], "boardrev", 8) == 0)
  54. + nvp->boardrev_found = true;
  55. while (nvp->nvram[i] != 0) {
  56. nvram[j] = nvp->nvram[i];
  57. i++;
  58. @@ -335,6 +342,8 @@ static void brcmf_fw_strip_multi_v2(stru
  59. while (i < nvp->nvram_len - len) {
  60. if (strncmp(&nvp->nvram[i], prefix, len) == 0) {
  61. i += len;
  62. + if (strncmp(&nvp->nvram[i], "boardrev", 8) == 0)
  63. + nvp->boardrev_found = true;
  64. while (nvp->nvram[i] != 0) {
  65. nvram[j] = nvp->nvram[i];
  66. i++;
  67. @@ -356,6 +365,18 @@ fail:
  68. nvp->nvram_len = 0;
  69. }
  70. +static void brcmf_fw_add_defaults(struct nvram_parser *nvp)
  71. +{
  72. + if (nvp->boardrev_found)
  73. + return;
  74. +
  75. + memcpy(&nvp->nvram[nvp->nvram_len], &BRCMF_FW_DEFAULT_BOARDREV,
  76. + strlen(BRCMF_FW_DEFAULT_BOARDREV));
  77. + nvp->nvram_len += strlen(BRCMF_FW_DEFAULT_BOARDREV);
  78. + nvp->nvram[nvp->nvram_len] = '\0';
  79. + nvp->nvram_len++;
  80. +}
  81. +
  82. /* brcmf_nvram_strip :Takes a buffer of "<var>=<value>\n" lines read from a fil
  83. * and ending in a NUL. Removes carriage returns, empty lines, comment lines,
  84. * and converts newlines to NULs. Shortens buffer as needed and pads with NULs.
  85. @@ -377,16 +398,21 @@ static void *brcmf_fw_nvram_strip(const
  86. if (nvp.state == END)
  87. break;
  88. }
  89. - if (nvp.multi_dev_v1)
  90. + if (nvp.multi_dev_v1) {
  91. + nvp.boardrev_found = false;
  92. brcmf_fw_strip_multi_v1(&nvp, domain_nr, bus_nr);
  93. - else if (nvp.multi_dev_v2)
  94. + } else if (nvp.multi_dev_v2) {
  95. + nvp.boardrev_found = false;
  96. brcmf_fw_strip_multi_v2(&nvp, domain_nr, bus_nr);
  97. + }
  98. if (nvp.nvram_len == 0) {
  99. kfree(nvp.nvram);
  100. return NULL;
  101. }
  102. + brcmf_fw_add_defaults(&nvp);
  103. +
  104. pad = nvp.nvram_len;
  105. *new_length = roundup(nvp.nvram_len + 1, 4);
  106. while (pad != *new_length) {