--- a/ath10k-4.13/core.c
+++ b/ath10k-4.13/core.c
-@@ -1419,14 +1419,61 @@ out:
+@@ -1427,14 +1427,61 @@ out:
return ret;
}
ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
ar->hw_params.fw.dir,
-@@ -1464,73 +1511,28 @@ static int ath10k_core_fetch_board_data_
+@@ -1472,73 +1519,28 @@ static int ath10k_core_fetch_board_data_
data += magic_len;
len -= magic_len;
return 0;
err:
-@@ -1539,12 +1541,12 @@ err:
+@@ -1547,12 +1549,12 @@ err:
}
static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
scnprintf(variant, sizeof(variant), ",variant=%s",
ar->id.bdf_ext);
-@@ -1570,21 +1572,31 @@ out:
+@@ -1578,21 +1580,31 @@ out:
+
+ static int ath10k_core_fetch_board_file(struct ath10k *ar)
+ {
+- char boardname[100];
++ char boardname[100], fallback_boardname[100];
+ int ret;
+
+- ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
++ ret = ath10k_core_create_board_name(ar, boardname,
++ sizeof(boardname), true);
+ if (ret) {
+ ath10k_err(ar, "failed to create board name: %d", ret);
+ return ret;
+ }
+
++ ret = ath10k_core_create_board_name(ar, fallback_boardname,
++ sizeof(boardname), false);
++ if (ret) {
++ ath10k_err(ar, "failed to create fallback board name: %d", ret);
++ return ret;
++ }
++
+ ar->bd_api = 2;
+ if (ar->fwcfg.bname[0])
+ ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
++ fallback_boardname,
+ ar->fwcfg.bname);
+ else
+ ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
++ fallback_boardname,
+ ATH10K_BOARD_API2_FILE);
+ if (!ret)
+ goto success;
+--- a/ath10k-4.16/core.c
++++ b/ath10k-4.16/core.c
+@@ -1559,14 +1559,61 @@ out:
+ return ret;
+ }
+
++static int ath10k_core_search_bd(struct ath10k *ar,
++ const char *boardname,
++ const u8 *data,
++ size_t len)
++{
++ size_t ie_len;
++ struct ath10k_fw_ie *hdr;
++ int ret = -ENOENT, ie_id;
++
++ while (len > sizeof(struct ath10k_fw_ie)) {
++ hdr = (struct ath10k_fw_ie *)data;
++ ie_id = le32_to_cpu(hdr->id);
++ ie_len = le32_to_cpu(hdr->len);
++
++ len -= sizeof(*hdr);
++ data = hdr->data;
++
++ if (len < ALIGN(ie_len, 4)) {
++ ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
++ ie_id, ie_len, len);
++ return -EINVAL;
++ }
++
++ switch (ie_id) {
++ case ATH10K_BD_IE_BOARD:
++ ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
++ boardname);
++ if (ret == -ENOENT)
++ /* no match found, continue */
++ break;
++
++ /* either found or error, so stop searching */
++ goto out;
++ }
++
++ /* jump over the padding */
++ ie_len = ALIGN(ie_len, 4);
++
++ len -= ie_len;
++ data += ie_len;
++ }
++
++out:
++ /* return result of parse_bd_ie_board() or -ENOENT */
++ return ret;
++}
++
+ static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
+ const char *boardname,
++ const char *fallback_boardname,
+ const char *filename)
+ {
+- size_t len, magic_len, ie_len;
+- struct ath10k_fw_ie *hdr;
++ size_t len, magic_len;
+ const u8 *data;
+- int ret, ie_id;
++ int ret;
+
+ ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
+ ar->hw_params.fw.dir,
+@@ -1604,73 +1651,28 @@ static int ath10k_core_fetch_board_data_
+ data += magic_len;
+ len -= magic_len;
+
+- while (len > sizeof(struct ath10k_fw_ie)) {
+- hdr = (struct ath10k_fw_ie *)data;
+- ie_id = le32_to_cpu(hdr->id);
+- ie_len = le32_to_cpu(hdr->len);
+-
+- len -= sizeof(*hdr);
+- data = hdr->data;
+-
+- if (len < ALIGN(ie_len, 4)) {
+- ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
+- ie_id, ie_len, len);
+- ret = -EINVAL;
+- goto err;
+- }
+-
+- switch (ie_id) {
+- case ATH10K_BD_IE_BOARD:
+- ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
+- boardname);
+- if (ret == -ENOENT && ar->id.bdf_ext[0] != '\0') {
+- /* try default bdf if variant was not found */
+- char *s, *v = ",variant=";
+- char boardname2[100];
+-
+- strlcpy(boardname2, boardname,
+- sizeof(boardname2));
+-
+- s = strstr(boardname2, v);
+- if (s)
+- *s = '\0'; /* strip ",variant=%s" */
+-
+- ret = ath10k_core_parse_bd_ie_board(ar, data,
+- ie_len,
+- boardname2);
+- }
+-
+- if (ret == -ENOENT)
+- /* no match found, continue */
+- break;
+- else if (ret)
+- /* there was an error, bail out */
+- goto err;
+-
+- /* board data found */
+- goto out;
+- }
++ /* attempt to find boardname in the IE list */
++ ret = ath10k_core_search_bd(ar, boardname, data, len);
+
+- /* jump over the padding */
+- ie_len = ALIGN(ie_len, 4);
+-
+- len -= ie_len;
+- data += ie_len;
+- }
++ /* if we didn't find it and have a fallback name, try that */
++ if (ret == -ENOENT && fallback_boardname)
++ ret = ath10k_core_search_bd(ar, fallback_boardname, data, len);
+
+ out:
+- if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) {
++ if (ret == -ENOENT) {
+ ath10k_err(ar,
+ "failed to fetch board data for %s from %s/%s\n",
+ boardname, ar->hw_params.fw.dir, filename);
+ ret = -ENODATA;
+- goto err;
+ }
+
+ /* Save firmware board name so we can display it later. */
+ strlcpy(ar->normal_mode_fw.fw_file.fw_board_name, filename,
+ sizeof(ar->normal_mode_fw.fw_file.fw_board_name));
+
++ if (ret)
++ goto err;
++
+ return 0;
+
+ err:
+@@ -1679,12 +1681,12 @@ err:
+ }
+
+ static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
+- size_t name_len)
++ size_t name_len, bool with_variant)
+ {
+ /* strlen(',variant=') + strlen(ar->id.bdf_ext) */
+ char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 };
+
+- if (ar->id.bdf_ext[0] != '\0')
++ if (with_variant && ar->id.bdf_ext[0] != '\0')
+ scnprintf(variant, sizeof(variant), ",variant=%s",
+ ar->id.bdf_ext);
+
+@@ -1710,21 +1712,31 @@ out:
static int ath10k_core_fetch_board_file(struct ath10k *ar)
{