Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB
@ 2025-07-15 19:44 Bitterblue Smith
  2025-07-15 19:46 ` [PATCH rtw-next v2 2/2] wifi: rtw89: Lower the timeout in rtw89_fwdl_check_path_ready_ax() " Bitterblue Smith
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bitterblue Smith @ 2025-07-15 19:44 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org; +Cc: Ping-Ke Shih

This read_poll_timeout_atomic() with a delay of 1 µs and a timeout of
1000000 µs can take ~250 seconds in the worst case because sending a
USB control message takes ~250 µs.

Lower the timeout to 4000 for USB in order to reduce the maximum polling
time to ~1 second.

This problem was observed with RTL8851BU while suspending to RAM with
WOWLAN enabled. The computer sat for 4 minutes with a black screen
before suspending.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
 - Lower the timeout for USB instead of increasing the delay.
---
 drivers/net/wireless/realtek/rtw89/fw.c | 9 +++++++--
 drivers/net/wireless/realtek/rtw89/fw.h | 2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 73a4ec988d16..b774a329e7c7 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -6755,13 +6755,18 @@ static int rtw89_fw_read_c2h_reg(struct rtw89_dev *rtwdev,
 	const struct rtw89_chip_info *chip = rtwdev->chip;
 	struct rtw89_fw_info *fw_info = &rtwdev->fw;
 	const u32 *c2h_reg = chip->c2h_regs;
-	u32 ret;
+	u32 ret, timeout;
 	u8 i, val;
 
 	info->id = RTW89_FWCMD_C2HREG_FUNC_NULL;
 
+	if (rtwdev->hci.type == RTW89_HCI_TYPE_USB)
+		timeout = RTW89_C2H_TIMEOUT_USB;
+	else
+		timeout = RTW89_C2H_TIMEOUT;
+
 	ret = read_poll_timeout_atomic(rtw89_read8, val, val, 1,
-				       RTW89_C2H_TIMEOUT, false, rtwdev,
+				       timeout, false, rtwdev,
 				       chip->c2h_ctrl_reg);
 	if (ret) {
 		rtw89_warn(rtwdev, "c2h reg timeout\n");
diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h
index 98be7e72c685..a731c242f389 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.h
+++ b/drivers/net/wireless/realtek/rtw89/fw.h
@@ -115,6 +115,8 @@ struct rtw89_h2creg_sch_tx_en {
 #define RTW89_C2HREG_HDR_LEN 2
 #define RTW89_H2CREG_HDR_LEN 2
 #define RTW89_C2H_TIMEOUT 1000000
+#define RTW89_C2H_TIMEOUT_USB 4000
+
 struct rtw89_mac_c2h_info {
 	u8 id;
 	u8 content_len;
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH rtw-next v2 2/2] wifi: rtw89: Lower the timeout in rtw89_fwdl_check_path_ready_ax() for USB
  2025-07-15 19:44 [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB Bitterblue Smith
@ 2025-07-15 19:46 ` Bitterblue Smith
  2025-07-16  0:17 ` [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() " Ping-Ke Shih
  2025-07-18  6:35 ` Ping-Ke Shih
  2 siblings, 0 replies; 6+ messages in thread
From: Bitterblue Smith @ 2025-07-15 19:46 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org; +Cc: Ping-Ke Shih

When the chip is not powered on correctly (like during driver
development) rtw89_fwdl_check_path_ready_ax() can fail.
read_poll_timeout_atomic() with a delay of 1 µs and a timeout of
400000 µs can take 50 seconds with USB because of the time it takes to
send a USB control message. The firmware upload is tried 5 times, so
in total it takes 250 seconds.

Lower the timeout to 3200 for USB in order to reduce the time
rtw89_fwdl_check_path_ready_ax() takes from 50 seconds to less than 1
second.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
 - Lower the timeout for USB instead of increasing the delay.
 - Don't change rtw89_fwdl_check_path_ready_be().  It uses a larger
   timeout than rtw89_fwdl_check_path_ready_ax(). Leave it for later
   when I can test it.
---
 drivers/net/wireless/realtek/rtw89/fw.h  | 1 +
 drivers/net/wireless/realtek/rtw89/mac.c | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h
index a731c242f389..7e07df4beba7 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.h
+++ b/drivers/net/wireless/realtek/rtw89/fw.h
@@ -4697,6 +4697,7 @@ struct rtw89_c2h_rf_tas_info {
 #define RTW89_FW_BACKTRACE_KEY 0xBACEBACE
 
 #define FWDL_WAIT_CNT 400000
+#define FWDL_WAIT_CNT_USB 3200
 
 int rtw89_fw_check_rdy(struct rtw89_dev *rtwdev, enum rtw89_fwdl_check_type type);
 int rtw89_fw_recognize(struct rtw89_dev *rtwdev);
diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c
index f6bbc796329c..dfaf33173611 100644
--- a/drivers/net/wireless/realtek/rtw89/mac.c
+++ b/drivers/net/wireless/realtek/rtw89/mac.c
@@ -6932,10 +6932,16 @@ int rtw89_fwdl_check_path_ready_ax(struct rtw89_dev *rtwdev,
 				   bool h2c_or_fwdl)
 {
 	u8 check = h2c_or_fwdl ? B_AX_H2C_PATH_RDY : B_AX_FWDL_PATH_RDY;
+	u32 timeout;
 	u8 val;
 
+	if (rtwdev->hci.type == RTW89_HCI_TYPE_USB)
+		timeout = FWDL_WAIT_CNT_USB;
+	else
+		timeout = FWDL_WAIT_CNT;
+
 	return read_poll_timeout_atomic(rtw89_read8, val, val & check,
-					1, FWDL_WAIT_CNT, false,
+					1, timeout, false,
 					rtwdev, R_AX_WCPU_FW_CTRL);
 }
 
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB
  2025-07-15 19:44 [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB Bitterblue Smith
  2025-07-15 19:46 ` [PATCH rtw-next v2 2/2] wifi: rtw89: Lower the timeout in rtw89_fwdl_check_path_ready_ax() " Bitterblue Smith
@ 2025-07-16  0:17 ` Ping-Ke Shih
  2025-07-16 21:31   ` Bitterblue Smith
  2025-07-18  6:35 ` Ping-Ke Shih
  2 siblings, 1 reply; 6+ messages in thread
From: Ping-Ke Shih @ 2025-07-16  0:17 UTC (permalink / raw)
  To: Bitterblue Smith, linux-wireless@vger.kernel.org

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> This read_poll_timeout_atomic() with a delay of 1 µs and a timeout of
> 1000000 µs can take ~250 seconds in the worst case because sending a
> USB control message takes ~250 µs.
> 
> Lower the timeout to 4000 for USB in order to reduce the maximum polling
> time to ~1 second.
> 
> This problem was observed with RTL8851BU while suspending to RAM with
> WOWLAN enabled. The computer sat for 4 minutes with a black screen
> before suspending.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> ---
> v2:
>  - Lower the timeout for USB instead of increasing the delay.
> ---
>  drivers/net/wireless/realtek/rtw89/fw.c | 9 +++++++--
>  drivers/net/wireless/realtek/rtw89/fw.h | 2 ++
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
> index 73a4ec988d16..b774a329e7c7 100644
> --- a/drivers/net/wireless/realtek/rtw89/fw.c
> +++ b/drivers/net/wireless/realtek/rtw89/fw.c
> @@ -6755,13 +6755,18 @@ static int rtw89_fw_read_c2h_reg(struct rtw89_dev *rtwdev,
>         const struct rtw89_chip_info *chip = rtwdev->chip;
>         struct rtw89_fw_info *fw_info = &rtwdev->fw;
>         const u32 *c2h_reg = chip->c2h_regs;
> -       u32 ret;
> +       u32 ret, timeout;
>         u8 i, val;
> 
>         info->id = RTW89_FWCMD_C2HREG_FUNC_NULL;
> 
> +       if (rtwdev->hci.type == RTW89_HCI_TYPE_USB)
> +               timeout = RTW89_C2H_TIMEOUT_USB;

Should we have different timeout times for USB2 and USB3? 
The same question for patch 2/2.

Otherwise, looks good to me.


> +       else
> +               timeout = RTW89_C2H_TIMEOUT;
> +
>         ret = read_poll_timeout_atomic(rtw89_read8, val, val, 1,
> -                                      RTW89_C2H_TIMEOUT, false, rtwdev,
> +                                      timeout, false, rtwdev,
>                                        chip->c2h_ctrl_reg);
>         if (ret) {
>                 rtw89_warn(rtwdev, "c2h reg timeout\n");
> diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h
> index 98be7e72c685..a731c242f389 100644
> --- a/drivers/net/wireless/realtek/rtw89/fw.h
> +++ b/drivers/net/wireless/realtek/rtw89/fw.h
> @@ -115,6 +115,8 @@ struct rtw89_h2creg_sch_tx_en {
>  #define RTW89_C2HREG_HDR_LEN 2
>  #define RTW89_H2CREG_HDR_LEN 2
>  #define RTW89_C2H_TIMEOUT 1000000
> +#define RTW89_C2H_TIMEOUT_USB 4000
> +
>  struct rtw89_mac_c2h_info {
>         u8 id;
>         u8 content_len;
> --
> 2.50.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB
  2025-07-16  0:17 ` [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() " Ping-Ke Shih
@ 2025-07-16 21:31   ` Bitterblue Smith
  2025-07-17  0:20     ` Ping-Ke Shih
  0 siblings, 1 reply; 6+ messages in thread
From: Bitterblue Smith @ 2025-07-16 21:31 UTC (permalink / raw)
  To: Ping-Ke Shih, linux-wireless@vger.kernel.org

On 16/07/2025 03:17, Ping-Ke Shih wrote:
> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>> This read_poll_timeout_atomic() with a delay of 1 µs and a timeout of
>> 1000000 µs can take ~250 seconds in the worst case because sending a
>> USB control message takes ~250 µs.
>>
>> Lower the timeout to 4000 for USB in order to reduce the maximum polling
>> time to ~1 second.
>>
>> This problem was observed with RTL8851BU while suspending to RAM with
>> WOWLAN enabled. The computer sat for 4 minutes with a black screen
>> before suspending.
>>
>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>> ---
>> v2:
>>  - Lower the timeout for USB instead of increasing the delay.
>> ---
>>  drivers/net/wireless/realtek/rtw89/fw.c | 9 +++++++--
>>  drivers/net/wireless/realtek/rtw89/fw.h | 2 ++
>>  2 files changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
>> index 73a4ec988d16..b774a329e7c7 100644
>> --- a/drivers/net/wireless/realtek/rtw89/fw.c
>> +++ b/drivers/net/wireless/realtek/rtw89/fw.c
>> @@ -6755,13 +6755,18 @@ static int rtw89_fw_read_c2h_reg(struct rtw89_dev *rtwdev,
>>         const struct rtw89_chip_info *chip = rtwdev->chip;
>>         struct rtw89_fw_info *fw_info = &rtwdev->fw;
>>         const u32 *c2h_reg = chip->c2h_regs;
>> -       u32 ret;
>> +       u32 ret, timeout;
>>         u8 i, val;
>>
>>         info->id = RTW89_FWCMD_C2HREG_FUNC_NULL;
>>
>> +       if (rtwdev->hci.type == RTW89_HCI_TYPE_USB)
>> +               timeout = RTW89_C2H_TIMEOUT_USB;
> 
> Should we have different timeout times for USB2 and USB3? 
> The same question for patch 2/2.
> 

I measured the time it takes to read R_AX_WCPU_FW_CTRL (patch 2/2):

		USB 2		USB 3
RTL8851BU	125 µs		not supported
RTL8852BU	250 µs		40 µs
RTL8852CU	375 µs		40 µs

In my setup the same timeout works for both. Even with the faster reads
it still waits long enough.

> Otherwise, looks good to me.
> 
> 
>> +       else
>> +               timeout = RTW89_C2H_TIMEOUT;
>> +
>>         ret = read_poll_timeout_atomic(rtw89_read8, val, val, 1,
>> -                                      RTW89_C2H_TIMEOUT, false, rtwdev,
>> +                                      timeout, false, rtwdev,
>>                                        chip->c2h_ctrl_reg);
>>         if (ret) {
>>                 rtw89_warn(rtwdev, "c2h reg timeout\n");
>> diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h
>> index 98be7e72c685..a731c242f389 100644
>> --- a/drivers/net/wireless/realtek/rtw89/fw.h
>> +++ b/drivers/net/wireless/realtek/rtw89/fw.h
>> @@ -115,6 +115,8 @@ struct rtw89_h2creg_sch_tx_en {
>>  #define RTW89_C2HREG_HDR_LEN 2
>>  #define RTW89_H2CREG_HDR_LEN 2
>>  #define RTW89_C2H_TIMEOUT 1000000
>> +#define RTW89_C2H_TIMEOUT_USB 4000
>> +
>>  struct rtw89_mac_c2h_info {
>>         u8 id;
>>         u8 content_len;
>> --
>> 2.50.0
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB
  2025-07-16 21:31   ` Bitterblue Smith
@ 2025-07-17  0:20     ` Ping-Ke Shih
  0 siblings, 0 replies; 6+ messages in thread
From: Ping-Ke Shih @ 2025-07-17  0:20 UTC (permalink / raw)
  To: Bitterblue Smith, linux-wireless@vger.kernel.org

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> On 16/07/2025 03:17, Ping-Ke Shih wrote:
> > Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> >> This read_poll_timeout_atomic() with a delay of 1 µs and a timeout of
> >> 1000000 µs can take ~250 seconds in the worst case because sending a
> >> USB control message takes ~250 µs.
> >>
> >> Lower the timeout to 4000 for USB in order to reduce the maximum polling
> >> time to ~1 second.
> >>
> >> This problem was observed with RTL8851BU while suspending to RAM with
> >> WOWLAN enabled. The computer sat for 4 minutes with a black screen
> >> before suspending.
> >>
> >> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> >> ---
> >> v2:
> >>  - Lower the timeout for USB instead of increasing the delay.
> >> ---
> >>  drivers/net/wireless/realtek/rtw89/fw.c | 9 +++++++--
> >>  drivers/net/wireless/realtek/rtw89/fw.h | 2 ++
> >>  2 files changed, 9 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
> >> index 73a4ec988d16..b774a329e7c7 100644
> >> --- a/drivers/net/wireless/realtek/rtw89/fw.c
> >> +++ b/drivers/net/wireless/realtek/rtw89/fw.c
> >> @@ -6755,13 +6755,18 @@ static int rtw89_fw_read_c2h_reg(struct rtw89_dev *rtwdev,
> >>         const struct rtw89_chip_info *chip = rtwdev->chip;
> >>         struct rtw89_fw_info *fw_info = &rtwdev->fw;
> >>         const u32 *c2h_reg = chip->c2h_regs;
> >> -       u32 ret;
> >> +       u32 ret, timeout;
> >>         u8 i, val;
> >>
> >>         info->id = RTW89_FWCMD_C2HREG_FUNC_NULL;
> >>
> >> +       if (rtwdev->hci.type == RTW89_HCI_TYPE_USB)
> >> +               timeout = RTW89_C2H_TIMEOUT_USB;
> >
> > Should we have different timeout times for USB2 and USB3?
> > The same question for patch 2/2.
> >
> 
> I measured the time it takes to read R_AX_WCPU_FW_CTRL (patch 2/2):
> 
>                 USB 2           USB 3
> RTL8851BU       125 µs          not supported
> RTL8852BU       250 µs          40 µs
> RTL8852CU       375 µs          40 µs
> 
> In my setup the same timeout works for both. Even with the faster reads
> it still waits long enough.

Thanks for the info. 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB
  2025-07-15 19:44 [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB Bitterblue Smith
  2025-07-15 19:46 ` [PATCH rtw-next v2 2/2] wifi: rtw89: Lower the timeout in rtw89_fwdl_check_path_ready_ax() " Bitterblue Smith
  2025-07-16  0:17 ` [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() " Ping-Ke Shih
@ 2025-07-18  6:35 ` Ping-Ke Shih
  2 siblings, 0 replies; 6+ messages in thread
From: Ping-Ke Shih @ 2025-07-18  6:35 UTC (permalink / raw)
  To: Bitterblue Smith, linux-wireless@vger.kernel.org; +Cc: Ping-Ke Shih

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:

> This read_poll_timeout_atomic() with a delay of 1 µs and a timeout of
> 1000000 µs can take ~250 seconds in the worst case because sending a
> USB control message takes ~250 µs.
> 
> Lower the timeout to 4000 for USB in order to reduce the maximum polling
> time to ~1 second.
> 
> This problem was observed with RTL8851BU while suspending to RAM with
> WOWLAN enabled. The computer sat for 4 minutes with a black screen
> before suspending.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>

2 patch(es) applied to rtw-next branch of rtw.git, thanks.

671be46afd1f wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB
12322a026030 wifi: rtw89: Lower the timeout in rtw89_fwdl_check_path_ready_ax() for USB

---
https://github.com/pkshih/rtw.git


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-18  6:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15 19:44 [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() for USB Bitterblue Smith
2025-07-15 19:46 ` [PATCH rtw-next v2 2/2] wifi: rtw89: Lower the timeout in rtw89_fwdl_check_path_ready_ax() " Bitterblue Smith
2025-07-16  0:17 ` [PATCH rtw-next v2 1/2] wifi: rtw89: Lower the timeout in rtw89_fw_read_c2h_reg() " Ping-Ke Shih
2025-07-16 21:31   ` Bitterblue Smith
2025-07-17  0:20     ` Ping-Ke Shih
2025-07-18  6:35 ` Ping-Ke Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox