0014-ath10k-firmware-override.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. From df9ba74e96a8e1818028ea6f4a066a2388075377 Mon Sep 17 00:00:00 2001
  2. From: Maximilian Luz <luzmaximilian@gmail.com>
  3. Date: Sat, 27 Feb 2021 00:45:52 +0100
  4. Subject: [PATCH] ath10k: Add module parameters to override board files
  5. Some Surface devices, specifically the Surface Go and AMD version of the
  6. Surface Laptop 3 (wich both come with QCA6174 WiFi chips), work better
  7. with a different board file, as it seems that the firmeware included
  8. upstream is buggy.
  9. As it is generally not a good idea to randomly overwrite files, let
  10. alone doing so via packages, we add module parameters to override those
  11. file names in the driver. This allows us to package/deploy the override
  12. via a modprobe.d config.
  13. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  14. Patchset: ath10k-firmware-override
  15. ---
  16. drivers/net/wireless/ath/ath10k/core.c | 58 ++++++++++++++++++++++++++
  17. 1 file changed, 58 insertions(+)
  18. diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
  19. index 436eac342b62..c9028d59bfe2 100644
  20. --- a/drivers/net/wireless/ath/ath10k/core.c
  21. +++ b/drivers/net/wireless/ath/ath10k/core.c
  22. @@ -41,6 +41,9 @@ static bool uart_print;
  23. static bool skip_otp;
  24. static bool rawmode;
  25. +static char *override_board = "";
  26. +static char *override_board2 = "";
  27. +
  28. unsigned long ath10k_coredump_mask = BIT(ATH10K_FW_CRASH_DUMP_REGISTERS) |
  29. BIT(ATH10K_FW_CRASH_DUMP_CE_DATA);
  30. @@ -52,6 +55,9 @@ module_param(skip_otp, bool, 0644);
  31. module_param(rawmode, bool, 0644);
  32. module_param_named(coredump_mask, ath10k_coredump_mask, ulong, 0444);
  33. +module_param(override_board, charp, 0644);
  34. +module_param(override_board2, charp, 0644);
  35. +
  36. MODULE_PARM_DESC(debug_mask, "Debugging mask");
  37. MODULE_PARM_DESC(uart_print, "Uart target debugging");
  38. MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
  39. @@ -59,6 +65,9 @@ MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
  40. MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
  41. MODULE_PARM_DESC(coredump_mask, "Bitfield of what to include in firmware crash file");
  42. +MODULE_PARM_DESC(override_board, "Override for board.bin file");
  43. +MODULE_PARM_DESC(override_board2, "Override for board-2.bin file");
  44. +
  45. static const struct ath10k_hw_params ath10k_hw_params_list[] = {
  46. {
  47. .id = QCA988X_HW_2_0_VERSION,
  48. @@ -705,6 +714,42 @@ static int ath10k_init_configure_target(struct ath10k *ar)
  49. return 0;
  50. }
  51. +static const char *ath10k_override_board_fw_file(struct ath10k *ar,
  52. + const char *file)
  53. +{
  54. + if (strcmp(file, "board.bin") == 0) {
  55. + if (strcmp(override_board, "") == 0)
  56. + return file;
  57. +
  58. + if (strcmp(override_board, "none") == 0) {
  59. + dev_info(ar->dev, "firmware override: pretending 'board.bin' does not exist\n");
  60. + return NULL;
  61. + }
  62. +
  63. + dev_info(ar->dev, "firmware override: replacing 'board.bin' with '%s'\n",
  64. + override_board);
  65. +
  66. + return override_board;
  67. + }
  68. +
  69. + if (strcmp(file, "board-2.bin") == 0) {
  70. + if (strcmp(override_board2, "") == 0)
  71. + return file;
  72. +
  73. + if (strcmp(override_board2, "none") == 0) {
  74. + dev_info(ar->dev, "firmware override: pretending 'board-2.bin' does not exist\n");
  75. + return NULL;
  76. + }
  77. +
  78. + dev_info(ar->dev, "firmware override: replacing 'board-2.bin' with '%s'\n",
  79. + override_board2);
  80. +
  81. + return override_board2;
  82. + }
  83. +
  84. + return file;
  85. +}
  86. +
  87. static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
  88. const char *dir,
  89. const char *file)
  90. @@ -719,6 +764,19 @@ static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
  91. if (dir == NULL)
  92. dir = ".";
  93. + /* HACK: Override board.bin and board-2.bin files if specified.
  94. + *
  95. + * Some Surface devices perform better with a different board
  96. + * configuration. To this end, one would need to replace the board.bin
  97. + * file with the modified config and remove the board-2.bin file.
  98. + * Unfortunately, that's not a solution that we can easily package. So
  99. + * we add module options to perform these overrides here.
  100. + */
  101. +
  102. + file = ath10k_override_board_fw_file(ar, file);
  103. + if (!file)
  104. + return ERR_PTR(-ENOENT);
  105. +
  106. snprintf(filename, sizeof(filename), "%s/%s", dir, file);
  107. ret = firmware_request_nowarn(&fw, filename, ar->dev);
  108. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot fw request '%s': %d\n",
  109. --
  110. 2.33.0