160-ath10k-search-all-IEs-for-variant-before-falling-back.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. From: Thomas Hebb <[email protected]>
  2. Subject: [PATCH] ath10k: search all IEs for variant before falling back
  3. Date: Wed, 21 Feb 2018 11:43:39 -0500
  4. commit f2593cb1b291 ("ath10k: Search SMBIOS for OEM board file
  5. extension") added a feature to ath10k that allows Board Data File
  6. (BDF) conflicts between multiple devices that use the same device IDs
  7. but have different calibration requirements to be resolved by allowing
  8. a "variant" string to be stored in SMBIOS [and later device tree, added
  9. by commit d06f26c5c8a4 ("ath10k: search DT for qcom,ath10k-calibration-
  10. variant")] that gets appended to the ID stored in board-2.bin.
  11. This original patch had a regression, however. Namely that devices with
  12. a variant present in SMBIOS that didn't need custom BDFs could no longer
  13. find the default BDF, which has no variant appended. The patch was
  14. reverted and re-applied with a fix for this issue in commit 1657b8f84ed9
  15. ("search SMBIOS for OEM board file extension").
  16. But the fix to fall back to a default BDF introduced another issue: the
  17. driver currently parses IEs in board-2.bin one by one, and for each one
  18. it first checks to see if it matches the ID with the variant appended.
  19. If it doesn't, it checks to see if it matches the "fallback" ID with no
  20. variant. If a matching BDF is found at any point during this search, the
  21. search is terminated and that BDF is used. The issue is that it's very
  22. possible (and is currently the case for board-2.bin files present in the
  23. ath10k-firmware repository) for the default BDF to occur in an earlier
  24. IE than the variant-specific BDF. In this case, the current code will
  25. happily choose the default BDF even though a better-matching BDF is
  26. present later in the file.
  27. This patch fixes the issue by first searching the entire file for the ID
  28. with variant, and searching for the fallback ID only if that search
  29. fails. It also includes some code cleanup in the area, as
  30. ath10k_core_fetch_board_data_api_n() no longer does its own string
  31. mangling to remove the variant from an ID, instead leaving that job to a
  32. new flag passed to ath10k_core_create_board_name().
  33. I've tested this patch on a QCA4019 and verified that the driver behaves
  34. correctly for 1) both fallback and variant BDFs present, 2) only fallback
  35. BDF present, and 3) no matching BDFs present.
  36. Fixes: 1657b8f84ed9 ("ath10k: search SMBIOS for OEM board file extension")
  37. Signed-off-by: Thomas Hebb <[email protected]>
  38. ---
  39. drivers/net/wireless/ath/ath10k/core.c | 134 ++++++++++++++++++---------------
  40. 1 file changed, 72 insertions(+), 62 deletions(-)
  41. --- a/drivers/net/wireless/ath/ath10k/core.c
  42. +++ b/drivers/net/wireless/ath/ath10k/core.c
  43. @@ -1132,14 +1132,61 @@ out:
  44. return ret;
  45. }
  46. +static int ath10k_core_search_bd(struct ath10k *ar,
  47. + const char *boardname,
  48. + const u8 *data,
  49. + size_t len)
  50. +{
  51. + size_t ie_len;
  52. + struct ath10k_fw_ie *hdr;
  53. + int ret = -ENOENT, ie_id;
  54. +
  55. + while (len > sizeof(struct ath10k_fw_ie)) {
  56. + hdr = (struct ath10k_fw_ie *)data;
  57. + ie_id = le32_to_cpu(hdr->id);
  58. + ie_len = le32_to_cpu(hdr->len);
  59. +
  60. + len -= sizeof(*hdr);
  61. + data = hdr->data;
  62. +
  63. + if (len < ALIGN(ie_len, 4)) {
  64. + ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
  65. + ie_id, ie_len, len);
  66. + return -EINVAL;
  67. + }
  68. +
  69. + switch (ie_id) {
  70. + case ATH10K_BD_IE_BOARD:
  71. + ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
  72. + boardname);
  73. + if (ret == -ENOENT)
  74. + /* no match found, continue */
  75. + break;
  76. +
  77. + /* either found or error, so stop searching */
  78. + goto out;
  79. + }
  80. +
  81. + /* jump over the padding */
  82. + ie_len = ALIGN(ie_len, 4);
  83. +
  84. + len -= ie_len;
  85. + data += ie_len;
  86. + }
  87. +
  88. +out:
  89. + /* return result of parse_bd_ie_board() or -ENOENT */
  90. + return ret;
  91. +}
  92. +
  93. static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
  94. const char *boardname,
  95. + const char *fallback_boardname,
  96. const char *filename)
  97. {
  98. - size_t len, magic_len, ie_len;
  99. - struct ath10k_fw_ie *hdr;
  100. + size_t len, magic_len;
  101. const u8 *data;
  102. - int ret, ie_id;
  103. + int ret;
  104. ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
  105. ar->hw_params.fw.dir,
  106. @@ -1177,69 +1224,23 @@ static int ath10k_core_fetch_board_data_
  107. data += magic_len;
  108. len -= magic_len;
  109. - while (len > sizeof(struct ath10k_fw_ie)) {
  110. - hdr = (struct ath10k_fw_ie *)data;
  111. - ie_id = le32_to_cpu(hdr->id);
  112. - ie_len = le32_to_cpu(hdr->len);
  113. -
  114. - len -= sizeof(*hdr);
  115. - data = hdr->data;
  116. -
  117. - if (len < ALIGN(ie_len, 4)) {
  118. - ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
  119. - ie_id, ie_len, len);
  120. - ret = -EINVAL;
  121. - goto err;
  122. - }
  123. + /* attempt to find boardname in the IE list */
  124. + ret = ath10k_core_search_bd(ar, boardname, data, len);
  125. - switch (ie_id) {
  126. - case ATH10K_BD_IE_BOARD:
  127. - ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
  128. - boardname);
  129. - if (ret == -ENOENT && ar->id.bdf_ext[0] != '\0') {
  130. - /* try default bdf if variant was not found */
  131. - char *s, *v = ",variant=";
  132. - char boardname2[100];
  133. -
  134. - strlcpy(boardname2, boardname,
  135. - sizeof(boardname2));
  136. -
  137. - s = strstr(boardname2, v);
  138. - if (s)
  139. - *s = '\0'; /* strip ",variant=%s" */
  140. -
  141. - ret = ath10k_core_parse_bd_ie_board(ar, data,
  142. - ie_len,
  143. - boardname2);
  144. - }
  145. + /* if we didn't find it and have a fallback name, try that */
  146. + if (ret == -ENOENT && fallback_boardname)
  147. + ret = ath10k_core_search_bd(ar, fallback_boardname, data, len);
  148. - if (ret == -ENOENT)
  149. - /* no match found, continue */
  150. - break;
  151. - else if (ret)
  152. - /* there was an error, bail out */
  153. - goto err;
  154. -
  155. - /* board data found */
  156. - goto out;
  157. - }
  158. -
  159. - /* jump over the padding */
  160. - ie_len = ALIGN(ie_len, 4);
  161. -
  162. - len -= ie_len;
  163. - data += ie_len;
  164. - }
  165. -
  166. -out:
  167. - if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) {
  168. + if (ret == -ENOENT) {
  169. ath10k_err(ar,
  170. "failed to fetch board data for %s from %s/%s\n",
  171. boardname, ar->hw_params.fw.dir, filename);
  172. ret = -ENODATA;
  173. - goto err;
  174. }
  175. + if (ret)
  176. + goto err;
  177. +
  178. return 0;
  179. err:
  180. @@ -1248,12 +1249,12 @@ err:
  181. }
  182. static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
  183. - size_t name_len)
  184. + size_t name_len, bool with_variant)
  185. {
  186. /* strlen(',variant=') + strlen(ar->id.bdf_ext) */
  187. char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 };
  188. - if (ar->id.bdf_ext[0] != '\0')
  189. + if (with_variant && ar->id.bdf_ext[0] != '\0')
  190. scnprintf(variant, sizeof(variant), ",variant=%s",
  191. ar->id.bdf_ext);
  192. @@ -1279,17 +1280,26 @@ out:
  193. static int ath10k_core_fetch_board_file(struct ath10k *ar)
  194. {
  195. - char boardname[100];
  196. + char boardname[100], fallback_boardname[100];
  197. int ret;
  198. - ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
  199. + ret = ath10k_core_create_board_name(ar, boardname,
  200. + sizeof(boardname), true);
  201. if (ret) {
  202. ath10k_err(ar, "failed to create board name: %d", ret);
  203. return ret;
  204. }
  205. + ret = ath10k_core_create_board_name(ar, fallback_boardname,
  206. + sizeof(boardname), false);
  207. + if (ret) {
  208. + ath10k_err(ar, "failed to create fallback board name: %d", ret);
  209. + return ret;
  210. + }
  211. +
  212. ar->bd_api = 2;
  213. ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
  214. + fallback_boardname,
  215. ATH10K_BOARD_API2_FILE);
  216. if (!ret)
  217. goto success;