1 From: Thomas Hebb <tommyhebb@gmail.com>
2 Date: Fri, 13 Apr 2018 17:40:26 +0300
3 Subject: [PATCH] ath10k: search all IEs for variant before falling back
5 commit f2593cb1b291 ("ath10k: Search SMBIOS for OEM board file
6 extension") added a feature to ath10k that allows Board Data File
7 (BDF) conflicts between multiple devices that use the same device IDs
8 but have different calibration requirements to be resolved by allowing
9 a "variant" string to be stored in SMBIOS [and later device tree, added
10 by commit d06f26c5c8a4 ("ath10k: search DT for qcom,ath10k-calibration-
11 variant")] that gets appended to the ID stored in board-2.bin.
13 This original patch had a regression, however. Namely that devices with
14 a variant present in SMBIOS that didn't need custom BDFs could no longer
15 find the default BDF, which has no variant appended. The patch was
16 reverted and re-applied with a fix for this issue in commit 1657b8f84ed9
17 ("search SMBIOS for OEM board file extension").
19 But the fix to fall back to a default BDF introduced another issue: the
20 driver currently parses IEs in board-2.bin one by one, and for each one
21 it first checks to see if it matches the ID with the variant appended.
22 If it doesn't, it checks to see if it matches the "fallback" ID with no
23 variant. If a matching BDF is found at any point during this search, the
24 search is terminated and that BDF is used. The issue is that it's very
25 possible (and is currently the case for board-2.bin files present in the
26 ath10k-firmware repository) for the default BDF to occur in an earlier
27 IE than the variant-specific BDF. In this case, the current code will
28 happily choose the default BDF even though a better-matching BDF is
29 present later in the file.
31 This patch fixes the issue by first searching the entire file for the ID
32 with variant, and searching for the fallback ID only if that search
33 fails. It also includes some code cleanup in the area, as
34 ath10k_core_fetch_board_data_api_n() no longer does its own string
35 mangling to remove the variant from an ID, instead leaving that job to a
36 new flag passed to ath10k_core_create_board_name().
38 I've tested this patch on a QCA4019 and verified that the driver behaves
39 correctly for 1) both fallback and variant BDFs present, 2) only fallback
40 BDF present, and 3) no matching BDFs present.
42 Fixes: 1657b8f84ed9 ("ath10k: search SMBIOS for OEM board file extension")
43 Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
44 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
46 Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c8489668065a283d3027e86e877b103a87f99d22
48 ath10k-4.13/core.c | 134 ++++++++++++++++++---------------
49 1 file changed, 72 insertions(+), 62 deletions(-)
51 --- a/ath10k-4.13/core.c
52 +++ b/ath10k-4.13/core.c
53 @@ -1429,14 +1429,61 @@ out:
57 +static int ath10k_core_search_bd(struct ath10k *ar,
58 + const char *boardname,
63 + struct ath10k_fw_ie *hdr;
64 + int ret = -ENOENT, ie_id;
66 + while (len > sizeof(struct ath10k_fw_ie)) {
67 + hdr = (struct ath10k_fw_ie *)data;
68 + ie_id = le32_to_cpu(hdr->id);
69 + ie_len = le32_to_cpu(hdr->len);
71 + len -= sizeof(*hdr);
74 + if (len < ALIGN(ie_len, 4)) {
75 + ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
76 + ie_id, ie_len, len);
81 + case ATH10K_BD_IE_BOARD:
82 + ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
85 + /* no match found, continue */
88 + /* either found or error, so stop searching */
92 + /* jump over the padding */
93 + ie_len = ALIGN(ie_len, 4);
100 + /* return result of parse_bd_ie_board() or -ENOENT */
104 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
105 const char *boardname,
106 + const char *fallback_boardname,
107 const char *filename)
109 - size_t len, magic_len, ie_len;
110 - struct ath10k_fw_ie *hdr;
111 + size_t len, magic_len;
116 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
117 ar->hw_params.fw.dir,
118 @@ -1474,73 +1521,28 @@ static int ath10k_core_fetch_board_data_
122 - while (len > sizeof(struct ath10k_fw_ie)) {
123 - hdr = (struct ath10k_fw_ie *)data;
124 - ie_id = le32_to_cpu(hdr->id);
125 - ie_len = le32_to_cpu(hdr->len);
127 - len -= sizeof(*hdr);
130 - if (len < ALIGN(ie_len, 4)) {
131 - ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
132 - ie_id, ie_len, len);
138 - case ATH10K_BD_IE_BOARD:
139 - ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
141 - if (ret == -ENOENT && ar->id.bdf_ext[0] != '\0') {
142 - /* try default bdf if variant was not found */
143 - char *s, *v = ",variant=";
144 - char boardname2[100];
146 - strlcpy(boardname2, boardname,
147 - sizeof(boardname2));
149 - s = strstr(boardname2, v);
151 - *s = '\0'; /* strip ",variant=%s" */
153 - ret = ath10k_core_parse_bd_ie_board(ar, data,
158 - if (ret == -ENOENT)
159 - /* no match found, continue */
162 - /* there was an error, bail out */
165 - /* board data found */
168 + /* attempt to find boardname in the IE list */
169 + ret = ath10k_core_search_bd(ar, boardname, data, len);
171 - /* jump over the padding */
172 - ie_len = ALIGN(ie_len, 4);
177 + /* if we didn't find it and have a fallback name, try that */
178 + if (ret == -ENOENT && fallback_boardname)
179 + ret = ath10k_core_search_bd(ar, fallback_boardname, data, len);
182 - if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) {
183 + if (ret == -ENOENT) {
185 "failed to fetch board data for %s from %s/%s\n",
186 boardname, ar->hw_params.fw.dir, filename);
191 /* Save firmware board name so we can display it later. */
192 strlcpy(ar->normal_mode_fw.fw_file.fw_board_name, filename,
193 sizeof(ar->normal_mode_fw.fw_file.fw_board_name));
201 @@ -1549,12 +1551,12 @@ err:
204 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
206 + size_t name_len, bool with_variant)
208 /* strlen(',variant=') + strlen(ar->id.bdf_ext) */
209 char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 };
211 - if (ar->id.bdf_ext[0] != '\0')
212 + if (with_variant && ar->id.bdf_ext[0] != '\0')
213 scnprintf(variant, sizeof(variant), ",variant=%s",
216 @@ -1580,21 +1582,31 @@ out:
218 static int ath10k_core_fetch_board_file(struct ath10k *ar)
220 - char boardname[100];
221 + char boardname[100], fallback_boardname[100];
224 - ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
225 + ret = ath10k_core_create_board_name(ar, boardname,
226 + sizeof(boardname), true);
228 ath10k_err(ar, "failed to create board name: %d", ret);
232 + ret = ath10k_core_create_board_name(ar, fallback_boardname,
233 + sizeof(boardname), false);
235 + ath10k_err(ar, "failed to create fallback board name: %d", ret);
240 if (ar->fwcfg.bname[0])
241 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
242 + fallback_boardname,
245 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
246 + fallback_boardname,
247 ATH10K_BOARD_API2_FILE);
250 --- a/ath10k-4.16/core.c
251 +++ b/ath10k-4.16/core.c
252 @@ -1562,14 +1562,61 @@ out:
256 +static int ath10k_core_search_bd(struct ath10k *ar,
257 + const char *boardname,
262 + struct ath10k_fw_ie *hdr;
263 + int ret = -ENOENT, ie_id;
265 + while (len > sizeof(struct ath10k_fw_ie)) {
266 + hdr = (struct ath10k_fw_ie *)data;
267 + ie_id = le32_to_cpu(hdr->id);
268 + ie_len = le32_to_cpu(hdr->len);
270 + len -= sizeof(*hdr);
273 + if (len < ALIGN(ie_len, 4)) {
274 + ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
275 + ie_id, ie_len, len);
280 + case ATH10K_BD_IE_BOARD:
281 + ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
283 + if (ret == -ENOENT)
284 + /* no match found, continue */
287 + /* either found or error, so stop searching */
291 + /* jump over the padding */
292 + ie_len = ALIGN(ie_len, 4);
299 + /* return result of parse_bd_ie_board() or -ENOENT */
303 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
304 const char *boardname,
305 + const char *fallback_boardname,
306 const char *filename)
308 - size_t len, magic_len, ie_len;
309 - struct ath10k_fw_ie *hdr;
310 + size_t len, magic_len;
315 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
316 ar->hw_params.fw.dir,
317 @@ -1607,73 +1654,28 @@ static int ath10k_core_fetch_board_data_
321 - while (len > sizeof(struct ath10k_fw_ie)) {
322 - hdr = (struct ath10k_fw_ie *)data;
323 - ie_id = le32_to_cpu(hdr->id);
324 - ie_len = le32_to_cpu(hdr->len);
326 - len -= sizeof(*hdr);
329 - if (len < ALIGN(ie_len, 4)) {
330 - ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
331 - ie_id, ie_len, len);
337 - case ATH10K_BD_IE_BOARD:
338 - ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
340 - if (ret == -ENOENT && ar->id.bdf_ext[0] != '\0') {
341 - /* try default bdf if variant was not found */
342 - char *s, *v = ",variant=";
343 - char boardname2[100];
345 - strlcpy(boardname2, boardname,
346 - sizeof(boardname2));
348 - s = strstr(boardname2, v);
350 - *s = '\0'; /* strip ",variant=%s" */
352 - ret = ath10k_core_parse_bd_ie_board(ar, data,
357 - if (ret == -ENOENT)
358 - /* no match found, continue */
361 - /* there was an error, bail out */
364 - /* board data found */
367 + /* attempt to find boardname in the IE list */
368 + ret = ath10k_core_search_bd(ar, boardname, data, len);
370 - /* jump over the padding */
371 - ie_len = ALIGN(ie_len, 4);
376 + /* if we didn't find it and have a fallback name, try that */
377 + if (ret == -ENOENT && fallback_boardname)
378 + ret = ath10k_core_search_bd(ar, fallback_boardname, data, len);
381 - if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) {
382 + if (ret == -ENOENT) {
384 "failed to fetch board data for %s from %s/%s\n",
385 boardname, ar->hw_params.fw.dir, filename);
390 /* Save firmware board name so we can display it later. */
391 strlcpy(ar->normal_mode_fw.fw_file.fw_board_name, filename,
392 sizeof(ar->normal_mode_fw.fw_file.fw_board_name));
400 @@ -1682,12 +1684,12 @@ err:
403 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
405 + size_t name_len, bool with_variant)
407 /* strlen(',variant=') + strlen(ar->id.bdf_ext) */
408 char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 };
410 - if (ar->id.bdf_ext[0] != '\0')
411 + if (with_variant && ar->id.bdf_ext[0] != '\0')
412 scnprintf(variant, sizeof(variant), ",variant=%s",
415 @@ -1713,21 +1715,31 @@ out:
417 static int ath10k_core_fetch_board_file(struct ath10k *ar)
419 - char boardname[100];
420 + char boardname[100], fallback_boardname[100];
423 - ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
424 + ret = ath10k_core_create_board_name(ar, boardname,
425 + sizeof(boardname), true);
427 ath10k_err(ar, "failed to create board name: %d", ret);
431 + ret = ath10k_core_create_board_name(ar, fallback_boardname,
432 + sizeof(boardname), false);
434 + ath10k_err(ar, "failed to create fallback board name: %d", ret);
439 if (ar->fwcfg.bname[0])
440 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
441 + fallback_boardname,
444 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
445 + fallback_boardname,
446 ATH10K_BOARD_API2_FILE);