Skip to content

Commit ffde7f3

Browse files
Ping-Ke ShihKalle Valo
authored andcommitted
wifi: rtw89: add firmware format version to backward compatible with older drivers
In the discuss threads [1] [2], new firmware format break user space because older drivers can't recognize new firmware format. To avoid this, the new format will be named rtw89/rtw8852b_fw-1.bin and only new driver try to load it. Old drivers only load original and understandable firmware rtw89/rtw8852b_fw.bin. More, new driver will be still backward compatible with old firmware, so original firmware can be used by new driver. If there is newer firmware format is introduced, rtw89/rtw8852b_fw-2.bin will be given. The same rules will be applied like above. So, we will have firmware like below in linux-firmware in the future. rtw89/rtw8852b_fw-2.bin rtw89/rtw8852b_fw-1.bin rtw89/rtw8852b_fw.bin After this patch, MODULE_FIRMWARE() of 8852A/B/C become rtw89/rtw8852a_fw.bin rtw89/rtw8852b_fw-1.bin rtw89/rtw8852c_fw.bin [1] https://lore.kernel.org/linux-wireless/df1ce994-3368-a57e-7078-8bdcccf4a1fd@gmail.com/T/#m24cb43be31a762d0ea70bf07f27ae96c59f6931b [2] https://bugzilla.kernel.org/show_bug.cgi?id=217207 Signed-off-by: Ping-Ke Shih <pkshih@realtek.com> Signed-off-by: Kalle Valo <kvalo@kernel.org> Link: https://lore.kernel.org/r/20230320130606.20777-4-pkshih@realtek.com
1 parent b80ad23 commit ffde7f3

File tree

7 files changed

+66
-17
lines changed

7 files changed

+66
-17
lines changed

drivers/net/wireless/realtek/rtw89/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3759,9 +3759,10 @@ struct rtw89_dev *rtw89_alloc_ieee80211_hw(struct device *device,
37593759
struct rtw89_dev *rtwdev;
37603760
struct ieee80211_ops *ops;
37613761
u32 driver_data_size;
3762+
int fw_format = -1;
37623763
bool no_chanctx;
37633764

3764-
firmware = rtw89_early_fw_feature_recognize(device, chip, &early_fw);
3765+
firmware = rtw89_early_fw_feature_recognize(device, chip, &early_fw, &fw_format);
37653766

37663767
ops = kmemdup(&rtw89_ops, sizeof(rtw89_ops), GFP_KERNEL);
37673768
if (!ops)
@@ -3792,6 +3793,7 @@ struct rtw89_dev *rtw89_alloc_ieee80211_hw(struct device *device,
37923793
rtwdev->ops = ops;
37933794
rtwdev->chip = chip;
37943795
rtwdev->fw.req.firmware = firmware;
3796+
rtwdev->fw.fw_format = fw_format;
37953797

37963798
rtw89_debug(rtwdev, RTW89_DBG_FW, "probe driver %s chanctx\n",
37973799
no_chanctx ? "without" : "with");

drivers/net/wireless/realtek/rtw89/core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3080,7 +3080,8 @@ struct rtw89_phy_ul_tb_info {
30803080
struct rtw89_chip_info {
30813081
enum rtw89_core_chip_id chip_id;
30823082
const struct rtw89_chip_ops *ops;
3083-
const char *fw_name;
3083+
const char *fw_basename;
3084+
u8 fw_format_max;
30843085
bool try_ce_fw;
30853086
u32 fifo_size;
30863087
u32 dle_scc_rsvd_size;
@@ -3304,6 +3305,7 @@ struct rtw89_fw_req_info {
33043305

33053306
struct rtw89_fw_info {
33063307
struct rtw89_fw_req_info req;
3308+
int fw_format;
33073309
u8 h2c_seq;
33083310
u8 rec_seq;
33093311
u8 h2c_counter;

drivers/net/wireless/realtek/rtw89/fw.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,14 @@ static void rtw89_fw_recognize_features(struct rtw89_dev *rtwdev)
302302
const struct firmware *
303303
rtw89_early_fw_feature_recognize(struct device *device,
304304
const struct rtw89_chip_info *chip,
305-
struct rtw89_fw_info *early_fw)
305+
struct rtw89_fw_info *early_fw,
306+
int *used_fw_format)
306307
{
307308
union rtw89_compat_fw_hdr buf = {};
308309
const struct firmware *firmware;
309310
bool full_req = false;
311+
char fw_name[64];
312+
int fw_format;
310313
u32 ver_code;
311314
int ret;
312315

@@ -317,12 +320,22 @@ rtw89_early_fw_feature_recognize(struct device *device,
317320
if (IS_ENABLED(CONFIG_SECURITY_LOADPIN_ENFORCE))
318321
full_req = true;
319322

320-
if (full_req)
321-
ret = request_firmware(&firmware, chip->fw_name, device);
322-
else
323-
ret = request_partial_firmware_into_buf(&firmware, chip->fw_name,
324-
device, &buf, sizeof(buf),
325-
0);
323+
for (fw_format = chip->fw_format_max; fw_format >= 0; fw_format--) {
324+
rtw89_fw_get_filename(fw_name, sizeof(fw_name),
325+
chip->fw_basename, fw_format);
326+
327+
if (full_req)
328+
ret = request_firmware(&firmware, fw_name, device);
329+
else
330+
ret = request_partial_firmware_into_buf(&firmware, fw_name,
331+
device, &buf, sizeof(buf),
332+
0);
333+
if (!ret) {
334+
dev_info(device, "loaded firmware %s\n", fw_name);
335+
*used_fw_format = fw_format;
336+
break;
337+
}
338+
}
326339

327340
if (ret) {
328341
dev_err(device, "failed to early request firmware: %d\n", ret);
@@ -666,7 +679,11 @@ void rtw89_load_firmware_work(struct work_struct *work)
666679
{
667680
struct rtw89_dev *rtwdev =
668681
container_of(work, struct rtw89_dev, load_firmware_work);
669-
const char *fw_name = rtwdev->chip->fw_name;
682+
const struct rtw89_chip_info *chip = rtwdev->chip;
683+
char fw_name[64];
684+
685+
rtw89_fw_get_filename(fw_name, sizeof(fw_name),
686+
chip->fw_basename, rtwdev->fw.fw_format);
670687

671688
rtw89_load_firmware_req(rtwdev, &rtwdev->fw.req, fw_name, false);
672689
}

drivers/net/wireless/realtek/rtw89/fw.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3515,6 +3515,15 @@ static inline u32 rtw89_compat_fw_hdr_ver_code(const void *fw_buf)
35153515
return RTW89_FW_HDR_VER_CODE(&compat->fw_hdr);
35163516
}
35173517

3518+
static inline void rtw89_fw_get_filename(char *buf, size_t size,
3519+
const char *fw_basename, int fw_format)
3520+
{
3521+
if (fw_format <= 0)
3522+
snprintf(buf, size, "%s.bin", fw_basename);
3523+
else
3524+
snprintf(buf, size, "%s-%d.bin", fw_basename, fw_format);
3525+
}
3526+
35183527
#define RTW89_H2C_RF_PAGE_SIZE 500
35193528
#define RTW89_H2C_RF_PAGE_NUM 3
35203529
struct rtw89_fw_h2c_rf_reg_info {
@@ -3658,7 +3667,8 @@ int rtw89_fw_recognize(struct rtw89_dev *rtwdev);
36583667
const struct firmware *
36593668
rtw89_early_fw_feature_recognize(struct device *device,
36603669
const struct rtw89_chip_info *chip,
3661-
struct rtw89_fw_info *early_fw);
3670+
struct rtw89_fw_info *early_fw,
3671+
int *used_fw_format);
36623672
int rtw89_fw_download(struct rtw89_dev *rtwdev, enum rtw89_fw_type type);
36633673
void rtw89_load_firmware_work(struct work_struct *work);
36643674
void rtw89_unload_firmware(struct rtw89_dev *rtwdev);

drivers/net/wireless/realtek/rtw89/rtw8852a.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include "rtw8852a_table.h"
1313
#include "txrx.h"
1414

15+
#define RTW8852A_FW_FORMAT_MAX 0
16+
#define RTW8852A_FW_BASENAME "rtw89/rtw8852a_fw"
17+
#define RTW8852A_MODULE_FIRMWARE \
18+
RTW8852A_FW_BASENAME ".bin"
19+
1520
static const struct rtw89_hfc_ch_cfg rtw8852a_hfc_chcfg_pcie[] = {
1621
{128, 1896, grp_0}, /* ACH 0 */
1722
{128, 1896, grp_0}, /* ACH 1 */
@@ -2059,7 +2064,8 @@ static const struct rtw89_chip_ops rtw8852a_chip_ops = {
20592064
const struct rtw89_chip_info rtw8852a_chip_info = {
20602065
.chip_id = RTL8852A,
20612066
.ops = &rtw8852a_chip_ops,
2062-
.fw_name = "rtw89/rtw8852a_fw.bin",
2067+
.fw_basename = RTW8852A_FW_BASENAME,
2068+
.fw_format_max = RTW8852A_FW_FORMAT_MAX,
20632069
.try_ce_fw = false,
20642070
.fifo_size = 458752,
20652071
.dle_scc_rsvd_size = 0,
@@ -2156,7 +2162,7 @@ const struct rtw89_chip_info rtw8852a_chip_info = {
21562162
};
21572163
EXPORT_SYMBOL(rtw8852a_chip_info);
21582164

2159-
MODULE_FIRMWARE("rtw89/rtw8852a_fw.bin");
2165+
MODULE_FIRMWARE(RTW8852A_MODULE_FIRMWARE);
21602166
MODULE_AUTHOR("Realtek Corporation");
21612167
MODULE_DESCRIPTION("Realtek 802.11ax wireless 8852A driver");
21622168
MODULE_LICENSE("Dual BSD/GPL");

drivers/net/wireless/realtek/rtw89/rtw8852b.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include "rtw8852b_table.h"
1313
#include "txrx.h"
1414

15+
#define RTW8852B_FW_FORMAT_MAX 1
16+
#define RTW8852B_FW_BASENAME "rtw89/rtw8852b_fw"
17+
#define RTW8852B_MODULE_FIRMWARE \
18+
RTW8852B_FW_BASENAME "-" __stringify(RTW8852B_FW_FORMAT_MAX) ".bin"
19+
1520
static const struct rtw89_hfc_ch_cfg rtw8852b_hfc_chcfg_pcie[] = {
1621
{5, 343, grp_0}, /* ACH 0 */
1722
{5, 343, grp_0}, /* ACH 1 */
@@ -2480,7 +2485,8 @@ static const struct rtw89_chip_ops rtw8852b_chip_ops = {
24802485
const struct rtw89_chip_info rtw8852b_chip_info = {
24812486
.chip_id = RTL8852B,
24822487
.ops = &rtw8852b_chip_ops,
2483-
.fw_name = "rtw89/rtw8852b_fw.bin",
2488+
.fw_basename = RTW8852B_FW_BASENAME,
2489+
.fw_format_max = RTW8852B_FW_FORMAT_MAX,
24842490
.try_ce_fw = true,
24852491
.fifo_size = 196608,
24862492
.dle_scc_rsvd_size = 98304,
@@ -2576,7 +2582,7 @@ const struct rtw89_chip_info rtw8852b_chip_info = {
25762582
};
25772583
EXPORT_SYMBOL(rtw8852b_chip_info);
25782584

2579-
MODULE_FIRMWARE("rtw89/rtw8852b_fw.bin");
2585+
MODULE_FIRMWARE(RTW8852B_MODULE_FIRMWARE);
25802586
MODULE_AUTHOR("Realtek Corporation");
25812587
MODULE_DESCRIPTION("Realtek 802.11ax wireless 8852B driver");
25822588
MODULE_LICENSE("Dual BSD/GPL");

drivers/net/wireless/realtek/rtw89/rtw8852c.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include "rtw8852c_table.h"
1414
#include "util.h"
1515

16+
#define RTW8852C_FW_FORMAT_MAX 0
17+
#define RTW8852C_FW_BASENAME "rtw89/rtw8852c_fw"
18+
#define RTW8852C_MODULE_FIRMWARE \
19+
RTW8852C_FW_BASENAME ".bin"
20+
1621
static const struct rtw89_hfc_ch_cfg rtw8852c_hfc_chcfg_pcie[] = {
1722
{13, 1614, grp_0}, /* ACH 0 */
1823
{13, 1614, grp_0}, /* ACH 1 */
@@ -2791,7 +2796,8 @@ static const struct rtw89_chip_ops rtw8852c_chip_ops = {
27912796
const struct rtw89_chip_info rtw8852c_chip_info = {
27922797
.chip_id = RTL8852C,
27932798
.ops = &rtw8852c_chip_ops,
2794-
.fw_name = "rtw89/rtw8852c_fw.bin",
2799+
.fw_basename = RTW8852C_FW_BASENAME,
2800+
.fw_format_max = RTW8852C_FW_FORMAT_MAX,
27952801
.try_ce_fw = false,
27962802
.fifo_size = 458752,
27972803
.dle_scc_rsvd_size = 0,
@@ -2892,7 +2898,7 @@ const struct rtw89_chip_info rtw8852c_chip_info = {
28922898
};
28932899
EXPORT_SYMBOL(rtw8852c_chip_info);
28942900

2895-
MODULE_FIRMWARE("rtw89/rtw8852c_fw.bin");
2901+
MODULE_FIRMWARE(RTW8852C_MODULE_FIRMWARE);
28962902
MODULE_AUTHOR("Realtek Corporation");
28972903
MODULE_DESCRIPTION("Realtek 802.11ax wireless 8852C driver");
28982904
MODULE_LICENSE("Dual BSD/GPL");

0 commit comments

Comments
 (0)