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