Skip to content

Commit 823092a

Browse files
Ji-Pin JouKalle Valo
authored andcommitted
wifi: rtw88: fix race condition when doing H2C command
For SDIO/USB interface, since the tranferring speed is slower than that in PCIE, it may have race condition when the driver sets down H2C command to the FW. In the function rtw_fw_send_h2c_command, before the patch, box_reg is written first, then box_ex_reg is written. FW starts to work and fetch the value of box_ex_reg, when the most significant byte of box_reg(4 bytes) is written. Meanwhile, for SDIO/USB interface, since the transferring speed is slow, the driver is still in writing the new value of box_ex_reg through the bus, and FW may get the wrong value of box_ex_reg at the moment. To prevent the above driver/FW racing situation, box_ex_reg is written first then box_reg. Furthermore, it is written in 4 bytes at a time, instead of written in one byte one by one. It can increase the speed for SDIO/USB interface. Signed-off-by: Ji-Pin Jou <[email protected]> Signed-off-by: Ping-Ke Shih <[email protected]> Tested-by: Sascha Hauer <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3ca7f0b commit 823092a

File tree

2 files changed

+8
-5
lines changed
  • drivers/net/wireless/realtek/rtw88

2 files changed

+8
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ EXPORT_SYMBOL(rtw_fw_c2h_cmd_isr);
311311
static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev,
312312
u8 *h2c)
313313
{
314+
struct rtw_h2c_cmd *h2c_cmd = (struct rtw_h2c_cmd *)h2c;
314315
u8 box;
315316
u8 box_state;
316317
u32 box_reg, box_ex_reg;
317-
int idx;
318318
int ret;
319319

320320
rtw_dbg(rtwdev, RTW_DBG_FW,
@@ -356,10 +356,8 @@ static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev,
356356
goto out;
357357
}
358358

359-
for (idx = 0; idx < 4; idx++)
360-
rtw_write8(rtwdev, box_reg + idx, h2c[idx]);
361-
for (idx = 0; idx < 4; idx++)
362-
rtw_write8(rtwdev, box_ex_reg + idx, h2c[idx + 4]);
359+
rtw_write32(rtwdev, box_ex_reg, le32_to_cpu(h2c_cmd->msg_ext));
360+
rtw_write32(rtwdev, box_reg, le32_to_cpu(h2c_cmd->msg));
363361

364362
if (++rtwdev->h2c.last_box_num >= 4)
365363
rtwdev->h2c.last_box_num = 0;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ struct rtw_c2h_adaptivity {
8181
u8 option;
8282
} __packed;
8383

84+
struct rtw_h2c_cmd {
85+
__le32 msg;
86+
__le32 msg_ext;
87+
} __packed;
88+
8489
enum rtw_rsvd_packet_type {
8590
RSVD_BEACON,
8691
RSVD_DUMMY,

0 commit comments

Comments
 (0)