wifi: rtw88: 8821CU hangs after some number of power-off/on cycles
From: Marcin Ślusarz <[email protected]>
If I don't connect to any Wifi network, after around 10 minutes, the device hangs with endless spamming of:rtw_8821cu 1-1:1.2: rtw_usb_reg_sec: reg 0x4e0, usb write 1 fail, status: -71 killing both Wifi and Bluetooth part of the device.
On arm, just leaving the wifi device unconnected kills it in up to 20 minutes. If I keep restarting wpa_supplicant I can trigger it within a minute. Looping "ifconfig wlan0 down; ifconfig wlan0 up" also triggers it within a minute.
On x86_64 system the only way I could trigger this was via ifconfig loop, but it took 3 hours and 20 minutes to do it.
The only thing that can "fix" the device is replugging it.
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
Disabling power-off for that chip "fixes" the issue. The patches below implement that, but I'm not seriously proposing them for merging.
Marcin Ślusarz (2):
wifi: rtw88: use RTW_FLAG_RUNNING for deciding whether to enter/leave
IPS
wifi: rtw88: disable power offs for 8821C
drivers/net/wireless/realtek/rtw88/main.c | 14 ++++++++------ drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 wifi: rtw88: use RTW_FLAG_RUNNING for deciding whether to enter/leave IPS
From: Marcin Ślusarz <[email protected]>
Needed by the next patch that disables power off operation for one chip.
--- drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/ps.c +2 -2
@@ -26,7 +26,7 @@ static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)int rtw_enter_ips (struct rtw_dev *rtwdev) { -if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags)) +if (!test_bit (RTW_FLAG_RUNNING , rtwdev->flags))return 0 ;rtw_coex_ips_notify (rtwdev,COEX_IPS_ENTER );
@@ -50,7 +50,7 @@ int rtw_leave_ips(struct rtw_dev *rtwdev) {int ret; -if (test_bit (RTW_FLAG_POWERON , rtwdev->flags)) +if (test_bit (RTW_FLAG_RUNNING , rtwdev->flags))return 0 ;rtw_hci_link_ps (rtwdev, false);
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerRE: [PATCH 1/2] wifi: rtw88: use RTW_FLAG_RUNNING for deciding whether to enter/leave IPS
Quoted 18 lines · Marcin Ślusarz
From: Marcin Ślusarz <[email protected]>
Needed by the next patch that disables power off operation for one chip.
Signed-off-by Marcin Ślusarz <[email protected]>Cc Ping-Ke Shih <[email protected]>Cc Larry Finger <[email protected]>Cc Kalle Valo <[email protected]>--- drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/realtek/rtw88/ps.c +0
-0
drivers/net/wireless/realtek/rtw88/ps.c static int rtw_ips_pwr_up(struct rtw_dev *rtwdev) · line 29
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/ps.c +1
-1@@ -26,7 +26,7 @@ static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)int rtw_enter_ips (struct rtw_dev *rtwdev) { -if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags)) +if (!test_bit (RTW_FLAG_RUNNING , rtwdev->flags))
RTW_FLAG_POWERON is to maintain power state (i.e. ips) of WiFi card, and prevent entering/leaving IPS twice suddenly. Changing this is confused to me.
Re: [PATCH 1/2] wifi: rtw88: use RTW_FLAG_RUNNING for deciding whether to enter/leave IPS
wt., 28 maj 2024 o 05:56 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 21 lines
Quoted 19 lines · Marcin Ślusarz
From: Marcin Ślusarz <[email protected]>
Needed by the next patch that disables power off operation for one chip.
Signed-off-by Marcin Ślusarz <[email protected]>Cc Ping-Ke Shih <[email protected]>Cc Larry Finger <[email protected]>Cc Kalle Valo <[email protected]>--- drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/realtek/rtw88/ps.c +0
-0@@ -26,7 +26,7 @@ static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)
Quoted 7 lines
drivers/net/wireless/realtek/rtw88/ps.c static int rtw_ips_pwr_up(struct rtw_dev *rtwdev) · line 29
Quoted 4 lines
drivers/net/wireless/realtek/rtw88/ps.c +1
-1int rtw_enter_ips (struct rtw_dev *rtwdev) { -if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags)) +if (!test_bit (RTW_FLAG_RUNNING , rtwdev->flags))
RTW_FLAG_POWERONis to maintain power state (i.e. ips) of WiFi card, and prevent entering/leaving IPS twice suddenly. Changing this is confused to me.
I explained it in the other thread as a reply to Bitterblue.
PATCH 2/2 wifi: rtw88: disable power offs for 8821C
In reply to Marcin ŚlusarzFrom: Marcin Ślusarz <[email protected]>
This chip fails to reliably wake up from power off.
After some number of power off+on cycles, it stops with endless spamming of:rtw_8821cu 1-1:1.2: rtw_usb_reg_sec: reg 0x4e0, usb write 1 fail, status: -71 killing both Wifi and Bluetooth part of the device.
On arm, just leaving the wifi device unconfigured kills it in up to 20 minutes. If I keep restarting wpa_supplicant I can trigger it within a minute. Looping "ifconfig wlan0 down; ifconfig wlan0 up" also triggers it within a minute.
On x86_64 system the only way I could trigger this was via ifconfig loop, but it took 3 hours and 20 minutes to do it.
The only thing that "fixes" the device is replugging it.
--- drivers/net/wireless/realtek/rtw88/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +8 -6
@@ -1482,11 +1482,11 @@ void rtw_core_scan_complete(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,int rtw_core_start (struct rtw_dev *rtwdev) { -int ret; - - ret =rtw_power_on (rtwdev); -if (ret) -return ret; +if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags)) { +int ret =rtw_power_on (rtwdev); +if (ret) +return ret; + }rtw_sec_enable_sec_engine (rtwdev);
@@ -1534,7 +1534,9 @@ void rtw_core_stop(struct rtw_dev *rtwdev)mutex_lock (&rtwdev->mutex); -rtw_power_off (rtwdev); +/* FIXME: 8821C doesn't wake up from this state from time to time */ +if (rtwdev->chip->id !=RTW_CHIP_TYPE_8821C ) +rtw_power_off (rtwdev); } static void rtw_init_ht_cap(struct rtw_dev *rtwdev,
Signature · 1 line
2.25.1
Quoted 22 lines · Marcin Ślusarz
From: Marcin Ślusarz <[email protected]>
If I don't connect to any Wifi network, after around 10 minutes, the device hangs with endless spamming of:
rtw_8821cu1-1:1.2:rtw_usb_reg_sec: reg0x4e0, usb write 1 fail, status: -71 killing both Wifi and Bluetooth part of the device.On arm, just leaving the wifi device unconnected kills it in up to 20 minutes. If I keep restarting
wpa_supplicantI can trigger it within a minute. Looping "ifconfig wlan0 down; ifconfig wlan0 up" also triggers it within a minute.On
x86_64system the only way I could trigger this was via ifconfig loop, but it took 3 hours and 20 minutes to do it.The only thing that can "fix" the device is replugging it.
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
Disabling power-off for that chip "fixes" the issue. The patches below implement that, but I'm not seriously proposing them for merging.
Quoted 9 lines
Marcin Ślusarz (2):
wifi: rtw88: useRTW_FLAG_RUNNINGfor deciding whether to enter/leave
IPS
wifi: rtw88: disable power offs for 8821Cdrivers/net/wireless/realtek/rtw88/main.c | 14 ++++++++------ drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-)
The first patch alone doesn't fix it?
pon., 27 maj 2024 o 20:43 Bitterblue Smith <[email protected]> napisał(a):
Quoted 29 lines · Marcin Ślusarz
Quoted 27 lines
From: Marcin Ślusarz <[email protected]>
If I don't connect to any Wifi network, after around 10 minutes, the device hangs with endless spamming of:
rtw_8821cu1-1:1.2:rtw_usb_reg_sec: reg0x4e0, usb write 1 fail, status: -71 killing both Wifi and Bluetooth part of the device.On arm, just leaving the wifi device unconnected kills it in up to 20 minutes. If I keep restarting
wpa_supplicantI can trigger it within a minute. Looping "ifconfig wlan0 down; ifconfig wlan0 up" also triggers it within a minute.On
x86_64system the only way I could trigger this was via ifconfig loop, but it took 3 hours and 20 minutes to do it.The only thing that can "fix" the device is replugging it.
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
Disabling power-off for that chip "fixes" the issue. The patches below implement that, but I'm not seriously proposing them for merging.
Marcin Ślusarz (2):
wifi: rtw88: useRTW_FLAG_RUNNINGfor deciding whether to enter/leave
IPS
wifi: rtw88: disable power offs for 8821C
Quoted 6 lines
Quoted 4 lines
drivers/net/wireless/realtek/rtw88/main.c | 14 ++++++++------ drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-)The first patch alone doesn't fix it?
The first patch exists only to make the second patch work. Without the first one, rtw_enter_ips will perform all actions except actually doing the power off, which clears the POWERON flag.
After that, rtw_leave_ips will happily return early success without actually undoing the stuff that rtw_enter_ips did (like canceling all work_structs).
Quoted 35 lines · Marcin Ślusarz
pon., 27 maj 2024 o 20:43 Bitterblue Smith <[email protected]> napisał(a):
Quoted 34 lines · Marcin Ślusarz
Quoted 31 lines
From: Marcin Ślusarz <[email protected]>
If I don't connect to any Wifi network, after around 10 minutes, the device hangs with endless spamming of:
rtw_8821cu1-1:1.2:rtw_usb_reg_sec: reg0x4e0, usb write 1 fail, status: -71 killing both Wifi and Bluetooth part of the device.On arm, just leaving the wifi device unconnected kills it in up to 20 minutes. If I keep restarting
wpa_supplicantI can trigger it within a minute. Looping "ifconfig wlan0 down; ifconfig wlan0 up" also triggers it within a minute.On
x86_64system the only way I could trigger this was via ifconfig loop, but it took 3 hours and 20 minutes to do it.The only thing that can "fix" the device is replugging it.
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
Disabling power-off for that chip "fixes" the issue. The patches below implement that, but I'm not seriously proposing them for merging.
Marcin Ślusarz (2):
wifi: rtw88: useRTW_FLAG_RUNNINGfor deciding whether to enter/leave
IPS
wifi: rtw88: disable power offs for 8821Cdrivers/net/wireless/realtek/rtw88/main.c | 14 ++++++++------ drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-)
Quoted 7 lines
Quoted 1 line
The first patch alone doesn't fix it?
The first patch exists only to make the second patch work. Without the first one,
rtw_enter_ipswill perform all actions except actually doing the power off, which clears the POWERON flag.
After that,rtw_leave_ipswill happily return early success without actually undoing the stuff thatrtw_enter_ipsdid (like canceling allwork_structs).
I see.
I wonder if it's really the chip that has a problem, or rtw88? Can you try your ifconfig loop with the other driver?
https://github.com/morrownr/8821cu-20210916/
wt., 28 maj 2024 o 14:25 Bitterblue Smith <[email protected]> napisał(a):
Quoted 45 lines · Marcin Ślusarz
Quoted 35 lines
pon., 27 maj 2024 o 20:43 Bitterblue Smith <[email protected]> napisał(a):
Quoted 34 lines · Marcin Ślusarz
Quoted 31 lines
From: Marcin Ślusarz <[email protected]>
If I don't connect to any Wifi network, after around 10 minutes, the device hangs with endless spamming of:
rtw_8821cu1-1:1.2:rtw_usb_reg_sec: reg0x4e0, usb write 1 fail, status: -71 killing both Wifi and Bluetooth part of the device.On arm, just leaving the wifi device unconnected kills it in up to 20 minutes. If I keep restarting
wpa_supplicantI can trigger it within a minute. Looping "ifconfig wlan0 down; ifconfig wlan0 up" also triggers it within a minute.On
x86_64system the only way I could trigger this was via ifconfig loop, but it took 3 hours and 20 minutes to do it.The only thing that can "fix" the device is replugging it.
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
Disabling power-off for that chip "fixes" the issue. The patches below implement that, but I'm not seriously proposing them for merging.
Marcin Ślusarz (2):
wifi: rtw88: useRTW_FLAG_RUNNINGfor deciding whether to enter/leave
IPS
wifi: rtw88: disable power offs for 8821Cdrivers/net/wireless/realtek/rtw88/main.c | 14 ++++++++------ drivers/net/wireless/realtek/rtw88/ps.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-)Quoted 7 lines
Quoted 1 line
The first patch alone doesn't fix it?
The first patch exists only to make the second patch work. Without the first one,
rtw_enter_ipswill perform all actions except actually doing the power off, which clears the POWERON flag.
After that,rtw_leave_ipswill happily return early success without actually undoing the stuff thatrtw_enter_ipsdid (like canceling allwork_structs).
Quoted 5 lines
I see.
I wonder if it's really the chip that has a problem, or rtw88? Can you try your ifconfig loop with the other driver?
https://github.com/morrownr/8821cu-20210916/
Actually, the issue was found on this driver. I started looking at the issue more closely (and discovered the exact reproduction steps) after I switched to rtw88 and discovered it has exactly the same problem.
So yeah, it's either a chip issue or the same bug in both drivers.
Ping-Ke Shih
maintainerQuoted 3 lines · Marcin Ślusarz
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
To avoid power-off/on sequence once device becomes idle, I would like to add a ips_disabled helper. Please revert your changes and apply my attached patch.
From e12845f1f6aab639375c5fa5e156d41474572b92 Mon Sep 17 00:00:00 2001
From: Ping-Ke Shih <[email protected]>
Date: Tue, 28 May 2024 11:48:13 +0800
Subject: [PATCH] wifi: rtw88: 8821cu: disable idle power save for 8821CU
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This chip fails to reliably wake up from power off.
--- mac80211.c | 2 +- main.c | 4 ++-- main.h | 2 ++ ps.c | 5 ++++- ps.h | 2 +- usb.c | 3 +++ wow.c | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-)
mac80211.c +1 -1
@@ -99,7 +99,7 @@ static int rtw_ops_config(struct ieee80211_hw *hw, u32 changed)if ((changed &IEEE80211_CONF_CHANGE_IDLE ) && (hw->conf.flags &IEEE80211_CONF_IDLE ) && !test_bit (RTW_FLAG_SCANNING , rtwdev->flags)) -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, false); out:mutex_unlock (&rtwdev->mutex);
main.c +2 -2
@@ -306,7 +306,7 @@ static void rtw_ips_work(struct work_struct *work)mutex_lock (&rtwdev->mutex);if (rtwdev->hw->conf.flags &IEEE80211_CONF_IDLE ) -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, false);mutex_unlock (&rtwdev->mutex); }
@@ -660,7 +660,7 @@ free:rtw_iterate_stas_atomic (rtwdev, rtw_reset_sta_iter, rtwdev);rtw_iterate_vifs_atomic (rtwdev, rtw_reset_vif_iter, rtwdev);bitmap_zero (rtwdev->hw_port,RTW_PORT_NUM ); -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, true); }static void rtw_fw_recovery_work (struct work_struct *work)
main.h +2 -0
@@ -2283,6 +2283,8 @@ struct rtw_dev {bool beacon_loss;struct completion lps_leave_check; +bool ips_disabled; +struct dentry *debugfs;u8 sta_cnt;
ps.c +4 -1
@@ -24,8 +24,11 @@ static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)return ret; } -int rtw_enter_ips (struct rtw_dev *rtwdev) +int rtw_enter_ips (struct rtw_dev *rtwdev,bool force) { +if (!force && rtwdev->ips_disabled) +return 0 ; +if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags))return 0 ;
ps.h +1 -1
@@ -15,7 +15,7 @@#define LEAVE_LPS_TRY_CNT 5#define LEAVE_LPS_TIMEOUT msecs_to_jiffies(100) -int rtw_enter_ips (struct rtw_dev *rtwdev); +int rtw_enter_ips (struct rtw_dev *rtwdev,bool force);int rtw_leave_ips (struct rtw_dev *rtwdev);void rtw_power_mode_change (struct rtw_dev *rtwdev,bool enter);
usb.c +3 -0
@@ -854,6 +854,9 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) rtwdev->hci.ops = &rtw_usb_ops; rtwdev->hci.type =RTW_HCI_TYPE_USB ; +if (rtwdev->chip->id ==RTW_CHIP_TYPE_8821C ) + rtwdev->ips_disabled = true; + rtwusb =rtw_get_usb_priv (rtwdev); rtwusb->rtwdev = rtwdev;
wow.c +1 -1
@@ -677,7 +677,7 @@ static int rtw_wow_restore_ps(struct rtw_dev *rtwdev)int ret =0 ;if (rtw_wow_no_link (rtwdev) && rtwdev->wow.ips_enabled) - ret =rtw_enter_ips (rtwdev); + ret =rtw_enter_ips (rtwdev, false);return ret; }
Signature · 1 line
2.25.1
wt., 28 maj 2024 o 05:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 8 lines
Quoted 3 lines · Marcin Ślusarz
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
To avoid power-off/on sequence once device becomes idle, I would like to add a
ips_disabledhelper. Please revert your changes and apply my attached patch.
My first attempt was very similar, and it fixed some cases but not all of them.
This is due to the existence of a second source of power-offs - rtw_ops_stop, which is called, e.g., on downing the interface (ifconfig wlan0 down).
Ping-Ke Shih
maintainerQuoted 7 lines · Marcin Ślusarz
wt., 28 maj 2024 o 05:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 6 lines
Quoted 3 lines · Marcin Ślusarz
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
Quoted 7 lines
Quoted 2 lines
To avoid power-off/on sequence once device becomes idle, I would like to add a
ips_disabledhelper. Please revert your changes and apply my attached patch.My first attempt was very similar, and it fixed some cases but not all of them.
This is due to the existence of a second source of power-offs -
rtw_ops_stop, which is called, e.g., on downing the interface (ifconfig wlan0 down).
Please try attached v2 patch. I would like to have an explicit helper (i.e. always_power_on in v2) to have this fix, so days later people can be easy to understand how it works. Not prefer adjusting existing flags to implicitly have behavior you want.
From 715a7e758949595646e9134869667dc5a0437c3e Mon Sep 17 00:00:00 2001
From: Ping-Ke Shih <[email protected]>
Date: Tue, 28 May 2024 11:48:13 +0800
Subject: [PATCH v2] wifi: rtw88: 8821cu: keep power on always for 8821CU
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This chip fails to reliably wake up from power off.
--- mac80211.c | 2 +- main.c | 10 ++++++++-- main.h | 2 ++ ps.c | 5 ++++- ps.h | 2 +- usb.c | 3 +++ wow.c | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-)
mac80211.c +1 -1
@@ -99,7 +99,7 @@ static int rtw_ops_config(struct ieee80211_hw *hw, u32 changed)if ((changed &IEEE80211_CONF_CHANGE_IDLE ) && (hw->conf.flags &IEEE80211_CONF_IDLE ) && !test_bit (RTW_FLAG_SCANNING , rtwdev->flags)) -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, false); out:mutex_unlock (&rtwdev->mutex);
main.c +8 -2
@@ -306,7 +306,7 @@ static void rtw_ips_work(struct work_struct *work)mutex_lock (&rtwdev->mutex);if (rtwdev->hw->conf.flags &IEEE80211_CONF_IDLE ) -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, false);mutex_unlock (&rtwdev->mutex); }
@@ -660,7 +660,7 @@ free:rtw_iterate_stas_atomic (rtwdev, rtw_reset_sta_iter, rtwdev);rtw_iterate_vifs_atomic (rtwdev, rtw_reset_vif_iter, rtwdev);bitmap_zero (rtwdev->hw_port,RTW_PORT_NUM ); -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, true); }static void rtw_fw_recovery_work (struct work_struct *work)
@@ -1375,6 +1375,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)bool wifi_only;int ret; +if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) +return 0 ; + ret =rtw_hci_setup (rtwdev);if (ret) {rtw_err (rtwdev,"failed to setup hci\n" );
@@ -1525,6 +1528,9 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +if (rtwdev->always_power_on) +return ; +rtw_hci_stop (rtwdev);rtw_coex_power_off_setting (rtwdev);rtw_mac_power_off (rtwdev);
main.h +2 -0
@@ -2283,6 +2283,8 @@ struct rtw_dev {bool beacon_loss;struct completion lps_leave_check; +bool always_power_on; +struct dentry *debugfs;u8 sta_cnt;
ps.c +4 -1
@@ -24,8 +24,11 @@ static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)return ret; } -int rtw_enter_ips (struct rtw_dev *rtwdev) +int rtw_enter_ips (struct rtw_dev *rtwdev,bool force) { +if (!force && rtwdev->always_power_on) +return 0 ; +if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags))return 0 ;
ps.h +1 -1
@@ -15,7 +15,7 @@#define LEAVE_LPS_TRY_CNT 5#define LEAVE_LPS_TIMEOUT msecs_to_jiffies(100) -int rtw_enter_ips (struct rtw_dev *rtwdev); +int rtw_enter_ips (struct rtw_dev *rtwdev,bool force);int rtw_leave_ips (struct rtw_dev *rtwdev);void rtw_power_mode_change (struct rtw_dev *rtwdev,bool enter);
usb.c +3 -0
@@ -854,6 +854,9 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) rtwdev->hci.ops = &rtw_usb_ops; rtwdev->hci.type =RTW_HCI_TYPE_USB ; +if (rtwdev->chip->id ==RTW_CHIP_TYPE_8821C ) + rtwdev->always_power_on = true; + rtwusb =rtw_get_usb_priv (rtwdev); rtwusb->rtwdev = rtwdev;
wow.c +1 -1
@@ -677,7 +677,7 @@ static int rtw_wow_restore_ps(struct rtw_dev *rtwdev)int ret =0 ;if (rtw_wow_no_link (rtwdev) && rtwdev->wow.ips_enabled) - ret =rtw_enter_ips (rtwdev); + ret =rtw_enter_ips (rtwdev, false);return ret; }
Signature · 1 line
2.25.1
śr., 29 maj 2024 o 03:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 14 lines
Quoted 12 lines · Marcin Ślusarz
wt., 28 maj 2024 o 05:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 8 lines
Quoted 3 lines · Marcin Ślusarz
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
To avoid power-off/on sequence once device becomes idle, I would like to add a
ips_disabledhelper. Please revert your changes and apply my attached patch.My first attempt was very similar, and it fixed some cases but not all of them.
Quoted 7 lines
Quoted 2 lines
This is due to the existence of a second source of power-offs -
rtw_ops_stop, which is called, e.g., on downing the interface (ifconfig wlan0 down).Please try attached v2 patch. I would like to have an explicit helper (i.e.
always_power_onin v2) to have this fix, so days later people can be easy to understand how it works. Not prefer adjusting existing flags to implicitly have behavior you want.
So, do you think this is a chip issue, not just some driver misconfiguration?
I'm asking because if we are going in this direction, there's something more to fix... With your v2, very frequently, I hit WARN_ON(!local->started) in ieee80211_rx_napi (in wireless-next, the code was moved to ieee80211_rx_list).
With my patch, I checked and hit that WARN_ON, too, but very occasionally.
I think the difference is in what happens in rtw_ips_enter - I disabled only the power_off, but you also disabled everything else, including the cancelation of work_structs.
The warning itself sounds harmless, but I think users should never see such warnings, so this needs to be fixed somehow. Probably some additional work_struct(s) need to be canceled?
Marcin
Ping-Ke Shih
maintainerQuoted 18 lines · Marcin Ślusarz
śr., 29 maj 2024 o 03:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 17 lines
Quoted 14 lines · Marcin Ślusarz
wt., 28 maj 2024 o 05:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 8 lines
Quoted 3 lines · Marcin Ślusarz
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
To avoid power-off/on sequence once device becomes idle, I would like to add a
ips_disabledhelper. Please revert your changes and apply my attached patch.My first attempt was very similar, and it fixed some cases but not all of them.
This is due to the existence of a second source of power-offs -
rtw_ops_stop, which is called, e.g., on downing the interface (ifconfig wlan0 down).
Quoted 6 lines
Quoted 4 lines
Please try attached v2 patch. I would like to have an explicit helper (i.e.
always_power_onin v2) to have this fix, so days later people can be easy to understand how it works. Not prefer adjusting existing flags to implicitly have behavior you want.So, do you think this is a chip issue, not just some driver misconfiguration?
I asked internal USB WiFi people who say vendor drivers of USB/SDIO can't power-on/-off frequently but not very sure if hardware issue or driver issue.
Quoted 7 lines
I'm asking because if we are going in this direction, there's something more to fix... With your v2, very frequently, I hit
WARN_ON(!local->started)inieee80211_rx_napi(in wireless-next, the code was moved toieee80211_rx_list).With my patch, I checked and hit that
WARN_ON, too, but very occasionally.
Quoted 8 lines
I think the difference is in what happens in
rtw_ips_enter- I disabled only thepower_off, but you also disabled everything else, including the cancelation ofwork_structs.The warning itself sounds harmless, but I think users should never see such warnings, so this needs to be fixed somehow. Probably some additional
work_struct(s)need to be canceled?
I forgot to say my patch is compiled test only, and I didn't consider flow too much, just to close the behavior of your patches. You can improve my patch to be more reliable to avoid WARN_ON().
Ping-Ke
czw., 30 maj 2024 o 05:13 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 41 lines
Quoted 18 lines · Marcin Ślusarz
śr., 29 maj 2024 o 03:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 17 lines
Quoted 14 lines · Marcin Ślusarz
wt., 28 maj 2024 o 05:52 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 8 lines
Quoted 3 lines · Marcin Ślusarz
I found out that the reason for those hangs is a power-off+on sequence that's triggered by the above steps.
To avoid power-off/on sequence once device becomes idle, I would like to add a
ips_disabledhelper. Please revert your changes and apply my attached patch.My first attempt was very similar, and it fixed some cases but not all of them.
This is due to the existence of a second source of power-offs -
rtw_ops_stop, which is called, e.g., on downing the interface (ifconfig wlan0 down).Quoted 6 lines
Quoted 4 lines
Please try attached v2 patch. I would like to have an explicit helper (i.e.
always_power_onin v2) to have this fix, so days later people can be easy to understand how it works. Not prefer adjusting existing flags to implicitly have behavior you want.So, do you think this is a chip issue, not just some driver misconfiguration?
I asked internal USB WiFi people who say vendor drivers of USB/SDIO can't power-on/-off frequently but not very sure if hardware issue or driver issue.
Quoted 11 lines
I'm asking because if we are going in this direction, there's something more to fix... With your v2, very frequently, I hit
WARN_ON(!local->started)inieee80211_rx_napi(in wireless-next, the code was moved toieee80211_rx_list).With my patch, I checked and hit that
WARN_ON, too, but very occasionally.I think the difference is in what happens in
rtw_ips_enter- I disabled only thepower_off, but you also disabled everything else, including the cancelation ofwork_structs.
Quoted 8 lines
Quoted 4 lines
The warning itself sounds harmless, but I think users should never see such warnings, so this needs to be fixed somehow. Probably some additional
work_struct(s)need to be canceled?I forgot to say my patch is compiled test only, and I didn't consider flow too much, just to close the behavior of your patches. You can improve my patch to be more reliable to avoid
WARN_ON().
Two variants of the patch that fix this issue will follow. They are built on top of yours
v2 and my "wifi: rtw88: schedule rx work after everything is set up" from the other thread.
Please choose the one you like more :).
PATCH 1/1 wifi: rtw88/usb: stop rx work before potential power off
From: Marcin Ślusarz <[email protected]>
Avoids WARN_ON(!local->started) in ieee80211_rx_list, after the patch that disables power management of 8821CU.
--- drivers/net/wireless/realtek/rtw88/hci.h | 12 +++++++ drivers/net/wireless/realtek/rtw88/main.c | 7 +++- drivers/net/wireless/realtek/rtw88/pci.c | 6 ++++ drivers/net/wireless/realtek/rtw88/sdio.c | 6 ++++ drivers/net/wireless/realtek/rtw88/usb.c | 40 +++++++++++++++-------- drivers/net/wireless/realtek/rtw88/usb.h | 1 + 6 files changed, 58 insertions(+), 14 deletions(-)
drivers/net/wireless/realtek/rtw88/hci.h +12 -0
@@ -18,6 +18,8 @@ struct rtw_hci_ops {void (*deep_ps)(struct rtw_dev *rtwdev,bool enter);void (*link_ps)(struct rtw_dev *rtwdev,bool enter);void (*interface_cfg)(struct rtw_dev *rtwdev); +void (*stop_rx)(struct rtw_dev *rtwdev); +void (*start_rx)(struct rtw_dev *rtwdev);int (*write_data_rsvd_page)(struct rtw_dev *rtwdev,u8 *buf,u32 size);int (*write_data_h2c)(struct rtw_dev *rtwdev,u8 *buf,u32 size);
@@ -57,6 +59,16 @@ static inline void rtw_hci_stop(struct rtw_dev *rtwdev) rtwdev->hci.ops->stop (rtwdev); } +static inline void rtw_hci_start_rx (struct rtw_dev *rtwdev) +{ + rtwdev->hci.ops->start_rx (rtwdev); +} + +static inline void rtw_hci_stop_rx (struct rtw_dev *rtwdev) +{ + rtwdev->hci.ops->stop_rx (rtwdev); +} +static inline void rtw_hci_deep_ps (struct rtw_dev *rtwdev,bool enter) { rtwdev->hci.ops->deep_ps (rtwdev, enter);
drivers/net/wireless/realtek/rtw88/main.c +6 -1
@@ -1357,7 +1357,7 @@ static int rtw_power_on(struct rtw_dev *rtwdev)int ret;if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) -return 0 ; + goto success; ret =rtw_hci_setup (rtwdev);if (ret) {
@@ -1407,6 +1407,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)rtw_coex_power_on_setting (rtwdev);rtw_coex_init_hw_config (rtwdev, wifi_only); +success: +rtw_hci_start_rx (rtwdev); +return 0 ; err_off:
@@ -1509,6 +1512,8 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +rtw_hci_stop_rx (rtwdev); +if (rtwdev->always_power_on)return ;
drivers/net/wireless/realtek/rtw88/pci.c +6 -0
@@ -1590,6 +1590,10 @@ static void rtw_pci_destroy(struct rtw_dev *rtwdev, struct pci_dev *pdev)rtw_pci_io_unmapping (rtwdev, pdev); } +static void rtw_pci_nop (struct rtw_dev *rtwdev) +{ +} +static struct rtw_hci_ops rtw_pci_ops = { .tx_write = rtw_pci_tx_write, .tx_kick_off = rtw_pci_tx_kick_off,
@@ -1600,6 +1604,8 @@ static struct rtw_hci_ops rtw_pci_ops = { .deep_ps = rtw_pci_deep_ps, .link_ps = rtw_pci_link_ps, .interface_cfg = rtw_pci_interface_cfg, + .stop_rx = rtw_pci_nop, + .start_rx = rtw_pci_nop, .read8 = rtw_pci_read8, .read16 = rtw_pci_read16,
drivers/net/wireless/realtek/rtw88/sdio.c +6 -0
@@ -1147,6 +1147,10 @@ static void rtw_sdio_declaim(struct rtw_dev *rtwdev,sdio_release_host (sdio_func); } +static void rtw_sdio_nop (struct rtw_dev *rtwdev) +{ +} +static struct rtw_hci_ops rtw_sdio_ops = { .tx_write = rtw_sdio_tx_write, .tx_kick_off = rtw_sdio_tx_kick_off,
@@ -1156,6 +1160,8 @@ static struct rtw_hci_ops rtw_sdio_ops = { .deep_ps = rtw_sdio_deep_ps, .link_ps = rtw_sdio_link_ps, .interface_cfg = rtw_sdio_interface_cfg, + .stop_rx = rtw_sdio_nop, + .start_rx = rtw_sdio_nop, .read8 = rtw_sdio_read8, .read16 = rtw_sdio_read16,
drivers/net/wireless/realtek/rtw88/usb.c +27 -13
@@ -716,6 +716,30 @@ static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev)/* empty function for rtw_hci_ops */ } +static void rtw_usb_stop_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); +rtw_usb_cancel_rx_bufs (rtwusb); + rtwusb->rx_enabled = false; +} + +static void rtw_usb_start_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); +int i; + +if (rtwusb->rx_enabled) +return ; + +for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { +struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; + +rtw_usb_rx_resubmit (rtwusb, rxcb); + } + + rtwusb->rx_enabled = true; +} +static struct rtw_hci_ops rtw_usb_ops = { .tx_write = rtw_usb_tx_write, .tx_kick_off = rtw_usb_tx_kick_off,
@@ -725,6 +749,8 @@ static struct rtw_hci_ops rtw_usb_ops = { .deep_ps = rtw_usb_deep_ps, .link_ps = rtw_usb_link_ps, .interface_cfg = rtw_usb_interface_cfg, + .stop_rx = rtw_usb_stop_rx, + .start_rx = rtw_usb_start_rx, .write8 = rtw_usb_write8, .write16 = rtw_usb_write16,
@@ -754,18 +780,6 @@ static int rtw_usb_init_rx(struct rtw_dev *rtwdev)return 0 ; } -static void rtw_usb_setup_rx (struct rtw_dev *rtwdev) -{ -struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); -int i; - -for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { -struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; - -rtw_usb_rx_resubmit (rtwusb, rxcb); - } -} -static void rtw_usb_deinit_rx (struct rtw_dev *rtwdev) {struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);
@@ -903,7 +917,7 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) goto err_destroy_rxwq; } -rtw_usb_setup_rx (rtwdev); +rtw_usb_start_rx (rtwdev);return 0 ;
drivers/net/wireless/realtek/rtw88/usb.h +1 -0
@@ -82,6 +82,7 @@ struct rtw_usb {struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM ];struct sk_buff_head rx_queue;struct work_struct rx_work; +bool rx_enabled; };static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data (struct sk_buff *skb)
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerRE: [PATCH] wifi: rtw88/usb: stop rx work before potential power off
Quoted 4 lines · Marcin Ślusarz
From: Marcin Ślusarz <[email protected]>
Avoids
WARN_ON(!local->started)inieee80211_rx_list, after the patch that disables power management of 8821CU.
Please describe how/what you do in this patch.
Quoted 25 lines
Signed-off-by Marcin Ślusarz <[email protected]>--- drivers/net/wireless/realtek/rtw88/hci.h | 12 +++++++ drivers/net/wireless/realtek/rtw88/main.c | 7 +++- drivers/net/wireless/realtek/rtw88/pci.c | 6 ++++ drivers/net/wireless/realtek/rtw88/sdio.c | 6 ++++ drivers/net/wireless/realtek/rtw88/usb.c | 40 +++++++++++++++-------- drivers/net/wireless/realtek/rtw88/usb.h | 1 + 6 files changed, 58 insertions(+), 14 deletions(-)drivers/net/wireless/realtek/rtw88/hci.h +2
-0@@ -18,6 +18,8 @@ struct rtw_hci_ops {void (*deep_ps)(struct rtw_dev *rtwdev,bool enter);void (*link_ps)(struct rtw_dev *rtwdev,bool enter);void (*interface_cfg)(struct rtw_dev *rtwdev); +void (*stop_rx)(struct rtw_dev *rtwdev); +void (*start_rx)(struct rtw_dev *rtwdev);int (*write_data_rsvd_page)(struct rtw_dev *rtwdev,u8 *buf,u32 size);int (*write_data_h2c)(struct rtw_dev *rtwdev,u8 *buf,u32 size);
drivers/net/wireless/realtek/rtw88/hci.h static inline void rtw_hci_stop(struct rtw_dev *rtwdev) · line 63
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/hci.h +2
-0@@ -57,6 +59,16 @@ static inline void rtw_hci_stop(struct rtw_dev *rtwdev) rtwdev->hci.ops->stop (rtwdev); } +static inline void rtw_hci_start_rx (struct rtw_dev *rtwdev) +{
For PCI/SDIO nop, I would like to give them NULL, so here can be
if (rtwdev->hci.ops->start_rx)
rtwdev->hci.ops->start_rx(rtwdev);
Quoted 16 lines
drivers/net/wireless/realtek/rtw88/hci.h +8
-0+ rtwdev->hci.ops->start_rx (rtwdev); +} + +static inline void rtw_hci_stop_rx (struct rtw_dev *rtwdev) +{ + rtwdev->hci.ops->stop_rx (rtwdev); +} +static inline void rtw_hci_deep_ps (struct rtw_dev *rtwdev,bool enter) { rtwdev->hci.ops->deep_ps (rtwdev, enter);drivers/net/wireless/realtek/rtw88/main.c +0
-0
drivers/net/wireless/realtek/rtw88/main.c static int rtw_power_on(struct rtw_dev *rtwdev) · line 1360
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/main.c +1
-1@@ -1357,7 +1357,7 @@ static int rtw_power_on(struct rtw_dev *rtwdev)int ret;if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) -return 0 ; + goto success;
rtw_hci_start_rx(rtwdev) is only needed by this case, so
if (rtwdev->always_power_on && test_bit(RTW_FLAG_POWERON, rtwdev->flags)) {
rtw_hci_start_rx(rtwdev);
return 0;
}Quoted 14 lines
drivers/net/wireless/realtek/rtw88/main.c +3
-0ret =rtw_hci_setup (rtwdev);if (ret) {@@ -1407,6 +1407,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)rtw_coex_power_on_setting (rtwdev);rtw_coex_init_hw_config (rtwdev, wifi_only); +success: +rtw_hci_start_rx (rtwdev); +return 0 ; err_off:
drivers/net/wireless/realtek/rtw88/main.c int rtw_core_start(struct rtw_dev *rtwdev) · line 1516
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/main.c +2
-0@@ -1509,6 +1512,8 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +rtw_hci_stop_rx (rtwdev); +
Similarly here can be
if (rtwdev->always_power_on) {
rtw_hci_stop_rx(rtwdev);
return;
}Quoted 56 lines
drivers/net/wireless/realtek/rtw88/main.c +0
-0if (rtwdev->always_power_on)return ;drivers/net/wireless/realtek/rtw88/pci.c +6
-0@@ -1590,6 +1590,10 @@ static void rtw_pci_destroy(struct rtw_dev *rtwdev, struct pci_dev *pdev)rtw_pci_io_unmapping (rtwdev, pdev); } +static void rtw_pci_nop (struct rtw_dev *rtwdev) +{ +} +static struct rtw_hci_ops rtw_pci_ops = { .tx_write = rtw_pci_tx_write, .tx_kick_off = rtw_pci_tx_kick_off,@@ -1600,6 +1604,8 @@ static struct rtw_hci_ops rtw_pci_ops = { .deep_ps = rtw_pci_deep_ps, .link_ps = rtw_pci_link_ps, .interface_cfg = rtw_pci_interface_cfg, + .stop_rx = rtw_pci_nop, + .start_rx = rtw_pci_nop, .read8 = rtw_pci_read8, .read16 = rtw_pci_read16,drivers/net/wireless/realtek/rtw88/sdio.c +6
-0@@ -1147,6 +1147,10 @@ static void rtw_sdio_declaim(struct rtw_dev *rtwdev,sdio_release_host (sdio_func); } +static void rtw_sdio_nop (struct rtw_dev *rtwdev) +{ +} +static struct rtw_hci_ops rtw_sdio_ops = { .tx_write = rtw_sdio_tx_write, .tx_kick_off = rtw_sdio_tx_kick_off,@@ -1156,6 +1160,8 @@ static struct rtw_hci_ops rtw_sdio_ops = { .deep_ps = rtw_sdio_deep_ps, .link_ps = rtw_sdio_link_ps, .interface_cfg = rtw_sdio_interface_cfg, + .stop_rx = rtw_sdio_nop, + .start_rx = rtw_sdio_nop, .read8 = rtw_sdio_read8, .read16 = rtw_sdio_read16,drivers/net/wireless/realtek/rtw88/usb.c +0
-0
drivers/net/wireless/realtek/rtw88/usb.c static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev) · line 721
Quoted 6 lines
drivers/net/wireless/realtek/rtw88/usb.c +3
-0@@ -716,6 +716,30 @@ static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev)/* empty function for rtw_hci_ops */ } +static void rtw_usb_stop_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);
Do we really need a ' rtwusb->rx_enabled' to maintain symmetric calling of start/stop_rx? If yes, here should add
if (!rtwusb->rx_enabled) return;
But, I don't like that flag if it isn't strongly required.
Quoted 76 lines
drivers/net/wireless/realtek/rtw88/usb.c +24
-13+rtw_usb_cancel_rx_bufs (rtwusb); + rtwusb->rx_enabled = false; +} + +static void rtw_usb_start_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); +int i; + +if (rtwusb->rx_enabled) +return ; + +for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { +struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; + +rtw_usb_rx_resubmit (rtwusb, rxcb); + } + + rtwusb->rx_enabled = true; +} +static struct rtw_hci_ops rtw_usb_ops = { .tx_write = rtw_usb_tx_write, .tx_kick_off = rtw_usb_tx_kick_off,@@ -725,6 +749,8 @@ static struct rtw_hci_ops rtw_usb_ops = { .deep_ps = rtw_usb_deep_ps, .link_ps = rtw_usb_link_ps, .interface_cfg = rtw_usb_interface_cfg, + .stop_rx = rtw_usb_stop_rx, + .start_rx = rtw_usb_start_rx, .write8 = rtw_usb_write8, .write16 = rtw_usb_write16,@@ -754,18 +780,6 @@ static int rtw_usb_init_rx(struct rtw_dev *rtwdev)return 0 ; } -static void rtw_usb_setup_rx (struct rtw_dev *rtwdev) -{ -struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); -int i; - -for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { -struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; - -rtw_usb_rx_resubmit (rtwusb, rxcb); - } -} -static void rtw_usb_deinit_rx (struct rtw_dev *rtwdev) {struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);@@ -903,7 +917,7 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) goto err_destroy_rxwq; } -rtw_usb_setup_rx (rtwdev); +rtw_usb_start_rx (rtwdev);return 0 ;drivers/net/wireless/realtek/rtw88/usb.h +1
-1@@ -82,6 +82,7 @@ struct rtw_usb {struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM ];struct sk_buff_head rx_queue;struct work_struct rx_work; +bool rx_enabled; };static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data (struct sk_buff *skb) --2.25.1
Re: [PATCH] wifi: rtw88/usb: stop rx work before potential power off
wt., 4 cze 2024 o 02:57 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 37 lines
Quoted 4 lines · Marcin Ślusarz
From: Marcin Ślusarz <[email protected]>
Avoids
WARN_ON(!local->started)inieee80211_rx_list, after the patch that disables power management of 8821CU.Please describe how/what you do in this patch.
Quoted 28 lines
Signed-off-by Marcin Ślusarz <[email protected]>--- drivers/net/wireless/realtek/rtw88/hci.h | 12 +++++++ drivers/net/wireless/realtek/rtw88/main.c | 7 +++- drivers/net/wireless/realtek/rtw88/pci.c | 6 ++++ drivers/net/wireless/realtek/rtw88/sdio.c | 6 ++++ drivers/net/wireless/realtek/rtw88/usb.c | 40 +++++++++++++++-------- drivers/net/wireless/realtek/rtw88/usb.h | 1 + 6 files changed, 58 insertions(+), 14 deletions(-)drivers/net/wireless/realtek/rtw88/hci.h +2
-0@@ -18,6 +18,8 @@ struct rtw_hci_ops {void (*deep_ps)(struct rtw_dev *rtwdev,bool enter);void (*link_ps)(struct rtw_dev *rtwdev,bool enter);void (*interface_cfg)(struct rtw_dev *rtwdev); +void (*stop_rx)(struct rtw_dev *rtwdev); +void (*start_rx)(struct rtw_dev *rtwdev);int (*write_data_rsvd_page)(struct rtw_dev *rtwdev,u8 *buf,u32 size);int (*write_data_h2c)(struct rtw_dev *rtwdev,u8 *buf,u32 size);@@ -57,6 +59,16 @@ static inline void rtw_hci_stop(struct rtw_dev *rtwdev) rtwdev->hci.ops->stop (rtwdev); }
Quoted 7 lines
drivers/net/wireless/realtek/rtw88/hci.h static inline void rtw_hci_stop(struct rtw_dev *rtwdev) · line 63
Quoted 2 lines
drivers/net/wireless/realtek/rtw88/hci.h +2
-0+static inline void rtw_hci_start_rx (struct rtw_dev *rtwdev) +{For PCI/SDIO nop, I would like to give them NULL, so here can be
if (
rtwdev->hci.ops->start_rx)rtwdev->hci.ops->start_rx(rtwdev);
Sure
Quoted 25 lines
Quoted 17 lines
drivers/net/wireless/realtek/rtw88/hci.h +8
-0+ rtwdev->hci.ops->start_rx (rtwdev); +} + +static inline void rtw_hci_stop_rx (struct rtw_dev *rtwdev) +{ + rtwdev->hci.ops->stop_rx (rtwdev); +} +static inline void rtw_hci_deep_ps (struct rtw_dev *rtwdev,bool enter) { rtwdev->hci.ops->deep_ps (rtwdev, enter);drivers/net/wireless/realtek/rtw88/main.c +0
-0drivers/net/wireless/realtek/rtw88/main.c static int rtw_power_on(struct rtw_dev *rtwdev) · line 1360
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/main.c +1
-1@@ -1357,7 +1357,7 @@ static int rtw_power_on(struct rtw_dev *rtwdev)int ret;if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) -return 0 ; + goto success;
rtw_hci_start_rx(rtwdev)is only needed by this case, so
Quoted 4 lines
if (rtwdev->always_power_on && test_bit(RTW_FLAG_POWERON, rtwdev->flags)) {
rtw_hci_start_rx(rtwdev);
return 0;
}Yes, strictly speaking, it's needed only in the always_power_on case, but doing that in the common code path ensures that it's tested and still works.
Quoted 23 lines
Quoted 15 lines
drivers/net/wireless/realtek/rtw88/main.c +3
-0ret =rtw_hci_setup (rtwdev);if (ret) {@@ -1407,6 +1407,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)rtw_coex_power_on_setting (rtwdev);rtw_coex_init_hw_config (rtwdev, wifi_only); +success: +rtw_hci_start_rx (rtwdev); +return 0 ; err_off:drivers/net/wireless/realtek/rtw88/main.c int rtw_core_start(struct rtw_dev *rtwdev) · line 1516
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/main.c +2
-0@@ -1509,6 +1512,8 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +rtw_hci_stop_rx (rtwdev); +Similarly here can be
Quoted 4 lines
if (rtwdev->always_power_on) {
rtw_hci_stop_rx(rtwdev);
return;
}Ditto
Quoted 68 lines
Quoted 58 lines
drivers/net/wireless/realtek/rtw88/main.c +0
-0if (rtwdev->always_power_on)return ;drivers/net/wireless/realtek/rtw88/pci.c +6
-0@@ -1590,6 +1590,10 @@ static void rtw_pci_destroy(struct rtw_dev *rtwdev, struct pci_dev *pdev)rtw_pci_io_unmapping (rtwdev, pdev); } +static void rtw_pci_nop (struct rtw_dev *rtwdev) +{ +} +static struct rtw_hci_ops rtw_pci_ops = { .tx_write = rtw_pci_tx_write, .tx_kick_off = rtw_pci_tx_kick_off,@@ -1600,6 +1604,8 @@ static struct rtw_hci_ops rtw_pci_ops = { .deep_ps = rtw_pci_deep_ps, .link_ps = rtw_pci_link_ps, .interface_cfg = rtw_pci_interface_cfg, + .stop_rx = rtw_pci_nop, + .start_rx = rtw_pci_nop, .read8 = rtw_pci_read8, .read16 = rtw_pci_read16,drivers/net/wireless/realtek/rtw88/sdio.c +6
-0@@ -1147,6 +1147,10 @@ static void rtw_sdio_declaim(struct rtw_dev *rtwdev,sdio_release_host (sdio_func); } +static void rtw_sdio_nop (struct rtw_dev *rtwdev) +{ +} +static struct rtw_hci_ops rtw_sdio_ops = { .tx_write = rtw_sdio_tx_write, .tx_kick_off = rtw_sdio_tx_kick_off,@@ -1156,6 +1160,8 @@ static struct rtw_hci_ops rtw_sdio_ops = { .deep_ps = rtw_sdio_deep_ps, .link_ps = rtw_sdio_link_ps, .interface_cfg = rtw_sdio_interface_cfg, + .stop_rx = rtw_sdio_nop, + .start_rx = rtw_sdio_nop, .read8 = rtw_sdio_read8, .read16 = rtw_sdio_read16,drivers/net/wireless/realtek/rtw88/usb.c +0
-0drivers/net/wireless/realtek/rtw88/usb.c static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev) · line 721
Quoted 6 lines
drivers/net/wireless/realtek/rtw88/usb.c +3
-0@@ -716,6 +716,30 @@ static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev)/* empty function for rtw_hci_ops */ } +static void rtw_usb_stop_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);Do we really need a '
rtwusb->rx_enabled' to maintain symmetric calling of start/stop_rx? If yes, here should add
Quoted 2 lines
if (!rtwusb->rx_enabled)
return;Sure
Quoted 1 line
But, I don't like that flag if it isn't strongly required.
It's required because start_rx is called twice initially - from rtw_usb_probe and rtw_core_start (via rtw_power_on).
Quoted 78 lines
Quoted 77 lines
drivers/net/wireless/realtek/rtw88/usb.c +24
-13+rtw_usb_cancel_rx_bufs (rtwusb); + rtwusb->rx_enabled = false; +} + +static void rtw_usb_start_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); +int i; + +if (rtwusb->rx_enabled) +return ; + +for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { +struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; + +rtw_usb_rx_resubmit (rtwusb, rxcb); + } + + rtwusb->rx_enabled = true; +} +static struct rtw_hci_ops rtw_usb_ops = { .tx_write = rtw_usb_tx_write, .tx_kick_off = rtw_usb_tx_kick_off,@@ -725,6 +749,8 @@ static struct rtw_hci_ops rtw_usb_ops = { .deep_ps = rtw_usb_deep_ps, .link_ps = rtw_usb_link_ps, .interface_cfg = rtw_usb_interface_cfg, + .stop_rx = rtw_usb_stop_rx, + .start_rx = rtw_usb_start_rx, .write8 = rtw_usb_write8, .write16 = rtw_usb_write16,@@ -754,18 +780,6 @@ static int rtw_usb_init_rx(struct rtw_dev *rtwdev)return 0 ; } -static void rtw_usb_setup_rx (struct rtw_dev *rtwdev) -{ -struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); -int i; - -for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { -struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; - -rtw_usb_rx_resubmit (rtwusb, rxcb); - } -} -static void rtw_usb_deinit_rx (struct rtw_dev *rtwdev) {struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);@@ -903,7 +917,7 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) goto err_destroy_rxwq; } -rtw_usb_setup_rx (rtwdev); +rtw_usb_start_rx (rtwdev);return 0 ;drivers/net/wireless/realtek/rtw88/usb.h +1
-1@@ -82,6 +82,7 @@ struct rtw_usb {struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM ];struct sk_buff_head rx_queue;struct work_struct rx_work; +bool rx_enabled; };static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data (struct sk_buff *skb) --2.25.1
PATCH v2 1/2 wifi: rtw88: 8821cu: keep power on always for 8821CU
From: Ping-Ke Shih <[email protected]>
This chip fails to reliably wake up from power off.
---
v2: no changes since v1
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 2 +- drivers/net/wireless/realtek/rtw88/main.c | 10 ++++++++-- drivers/net/wireless/realtek/rtw88/main.h | 2 ++ drivers/net/wireless/realtek/rtw88/ps.c | 5 ++++- drivers/net/wireless/realtek/rtw88/ps.h | 2 +- drivers/net/wireless/realtek/rtw88/usb.c | 3 +++ drivers/net/wireless/realtek/rtw88/wow.c | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-)
drivers/net/wireless/realtek/rtw88/mac80211.c +1 -1
@@ -98,7 +98,7 @@ static int rtw_ops_config(struct ieee80211_hw *hw, u32 changed)if ((changed &IEEE80211_CONF_CHANGE_IDLE ) && (hw->conf.flags &IEEE80211_CONF_IDLE ) && !test_bit (RTW_FLAG_SCANNING , rtwdev->flags)) -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, false); out:mutex_unlock (&rtwdev->mutex);
drivers/net/wireless/realtek/rtw88/main.c +8 -2
@@ -302,7 +302,7 @@ static void rtw_ips_work(struct work_struct *work)mutex_lock (&rtwdev->mutex);if (rtwdev->hw->conf.flags &IEEE80211_CONF_IDLE ) -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, false);mutex_unlock (&rtwdev->mutex); }
@@ -647,7 +647,7 @@ static void __fw_recovery_work(struct rtw_dev *rtwdev)rtw_iterate_stas_atomic (rtwdev, rtw_reset_sta_iter, rtwdev);rtw_iterate_vifs_atomic (rtwdev, rtw_reset_vif_iter, rtwdev);bitmap_zero (rtwdev->hw_port,RTW_PORT_NUM ); -rtw_enter_ips (rtwdev); +rtw_enter_ips (rtwdev, true); }static void rtw_fw_recovery_work (struct work_struct *work)
@@ -1356,6 +1356,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)bool wifi_only;int ret; +if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) +return 0 ; + ret =rtw_hci_setup (rtwdev);if (ret) {rtw_err (rtwdev,"failed to setup hci\n" );
@@ -1506,6 +1509,9 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +if (rtwdev->always_power_on) +return ; +rtw_hci_stop (rtwdev);rtw_coex_power_off_setting (rtwdev);rtw_mac_power_off (rtwdev);
drivers/net/wireless/realtek/rtw88/main.h +2 -0
@@ -2049,6 +2049,8 @@ struct rtw_dev {bool beacon_loss;struct completion lps_leave_check; +bool always_power_on; +struct dentry *debugfs;u8 sta_cnt;
drivers/net/wireless/realtek/rtw88/ps.c +4 -1
@@ -24,8 +24,11 @@ static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)return ret; } -int rtw_enter_ips (struct rtw_dev *rtwdev) +int rtw_enter_ips (struct rtw_dev *rtwdev,bool force) { +if (!force && rtwdev->always_power_on) +return 0 ; +if (!test_bit (RTW_FLAG_POWERON , rtwdev->flags))return 0 ;
drivers/net/wireless/realtek/rtw88/ps.h +1 -1
@@ -15,7 +15,7 @@#define LEAVE_LPS_TRY_CNT 5#define LEAVE_LPS_TIMEOUT msecs_to_jiffies(100) -int rtw_enter_ips (struct rtw_dev *rtwdev); +int rtw_enter_ips (struct rtw_dev *rtwdev,bool force);int rtw_leave_ips (struct rtw_dev *rtwdev);void rtw_power_mode_change (struct rtw_dev *rtwdev,bool enter);
drivers/net/wireless/realtek/rtw88/usb.c +3 -0
@@ -859,6 +859,9 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) rtwdev->hci.ops = &rtw_usb_ops; rtwdev->hci.type =RTW_HCI_TYPE_USB ; +if (rtwdev->chip->id ==RTW_CHIP_TYPE_8821C ) + rtwdev->always_power_on = true; + rtwusb =rtw_get_usb_priv (rtwdev); rtwusb->rtwdev = rtwdev;
drivers/net/wireless/realtek/rtw88/wow.c +1 -1
@@ -620,7 +620,7 @@ static int rtw_wow_restore_ps(struct rtw_dev *rtwdev)int ret =0 ;if (rtw_wow_no_link (rtwdev) && rtwdev->wow.ips_enabled) - ret =rtw_enter_ips (rtwdev); + ret =rtw_enter_ips (rtwdev, false);return ret; }
Signature · 1 line
2.25.1
PATCH v2 2/2 wifi: rtw88/usb: stop rx work before potential power off
If power off is disabled (like on 8821CU after previous patch), the hardware can still fire and deliver data. This may have undersired impact on the networking stack (e.g. WARN_ON(!local->started) in ieee80211_rx_list), because hw is not supposed to do that after power off.
So to prevent that, cancel any pending RX URBs to stop the completion handlers from being called.
---
v2: start_rx/stop_rx cbs can be NULL; rx_enabled check added to stop_rx
--- drivers/net/wireless/realtek/rtw88/hci.h | 14 ++++++++ drivers/net/wireless/realtek/rtw88/main.c | 7 +++- drivers/net/wireless/realtek/rtw88/usb.c | 44 ++++++++++++++++------- drivers/net/wireless/realtek/rtw88/usb.h | 1 + 4 files changed, 52 insertions(+), 14 deletions(-)
drivers/net/wireless/realtek/rtw88/hci.h +14 -0
@@ -18,6 +18,8 @@ struct rtw_hci_ops {void (*deep_ps)(struct rtw_dev *rtwdev,bool enter);void (*link_ps)(struct rtw_dev *rtwdev,bool enter);void (*interface_cfg)(struct rtw_dev *rtwdev); +void (*stop_rx)(struct rtw_dev *rtwdev); +void (*start_rx)(struct rtw_dev *rtwdev);int (*write_data_rsvd_page)(struct rtw_dev *rtwdev,u8 *buf,u32 size);int (*write_data_h2c)(struct rtw_dev *rtwdev,u8 *buf,u32 size);
@@ -57,6 +59,18 @@ static inline void rtw_hci_stop(struct rtw_dev *rtwdev) rtwdev->hci.ops->stop (rtwdev); } +static inline void rtw_hci_start_rx (struct rtw_dev *rtwdev) +{ +if (rtwdev->hci.ops->start_rx) + rtwdev->hci.ops->start_rx (rtwdev); +} + +static inline void rtw_hci_stop_rx (struct rtw_dev *rtwdev) +{ +if (rtwdev->hci.ops->stop_rx) + rtwdev->hci.ops->stop_rx (rtwdev); +} +static inline void rtw_hci_deep_ps (struct rtw_dev *rtwdev,bool enter) { rtwdev->hci.ops->deep_ps (rtwdev, enter);
drivers/net/wireless/realtek/rtw88/main.c +6 -1
@@ -1357,7 +1357,7 @@ static int rtw_power_on(struct rtw_dev *rtwdev)int ret;if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) -return 0 ; + goto success; ret =rtw_hci_setup (rtwdev);if (ret) {
@@ -1407,6 +1407,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)rtw_coex_power_on_setting (rtwdev);rtw_coex_init_hw_config (rtwdev, wifi_only); +success: +rtw_hci_start_rx (rtwdev); +return 0 ; err_off:
@@ -1509,6 +1512,8 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +rtw_hci_stop_rx (rtwdev); +if (rtwdev->always_power_on)return ;
drivers/net/wireless/realtek/rtw88/usb.c +31 -13
68 lines not on this page · raw message
drivers/net/wireless/realtek/rtw88/usb.h +1 -0
@@ -82,6 +82,7 @@ struct rtw_usb {struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM ];struct sk_buff_head rx_queue;struct work_struct rx_work; +bool rx_enabled; };static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data (struct sk_buff *skb)
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerRE: [PATCH v2 2/2] wifi: rtw88/usb: stop rx work before potential power off
Quoted 65 lines · Marcin Ślusarz
If power off is disabled (like on 8821CU after previous patch), the hardware can still fire and deliver data. This may have undersired impact on the networking stack (e.g.
WARN_ON(!local->started)inieee80211_rx_list), because hw is not supposed to do that after power off.So to prevent that, cancel any pending RX URBs to stop the completion handlers from being called.
Signed-off-by Marcin Ślusarz <[email protected]>---
v2: start_rx/stop_rx cbs can be NULL;rx_enabledcheck added tostop_rx--- drivers/net/wireless/realtek/rtw88/hci.h | 14 ++++++++ drivers/net/wireless/realtek/rtw88/main.c | 7 +++- drivers/net/wireless/realtek/rtw88/usb.c | 44 ++++++++++++++++------- drivers/net/wireless/realtek/rtw88/usb.h | 1 + 4 files changed, 52 insertions(+), 14 deletions(-)drivers/net/wireless/realtek/rtw88/hci.h +14
-0@@ -18,6 +18,8 @@ struct rtw_hci_ops {void (*deep_ps)(struct rtw_dev *rtwdev,bool enter);void (*link_ps)(struct rtw_dev *rtwdev,bool enter);void (*interface_cfg)(struct rtw_dev *rtwdev); +void (*stop_rx)(struct rtw_dev *rtwdev); +void (*start_rx)(struct rtw_dev *rtwdev);int (*write_data_rsvd_page)(struct rtw_dev *rtwdev,u8 *buf,u32 size);int (*write_data_h2c)(struct rtw_dev *rtwdev,u8 *buf,u32 size);@@ -57,6 +59,18 @@ static inline void rtw_hci_stop(struct rtw_dev *rtwdev) rtwdev->hci.ops->stop (rtwdev); } +static inline void rtw_hci_start_rx (struct rtw_dev *rtwdev) +{ +if (rtwdev->hci.ops->start_rx) + rtwdev->hci.ops->start_rx (rtwdev); +} + +static inline void rtw_hci_stop_rx (struct rtw_dev *rtwdev) +{ +if (rtwdev->hci.ops->stop_rx) + rtwdev->hci.ops->stop_rx (rtwdev); +} +static inline void rtw_hci_deep_ps (struct rtw_dev *rtwdev,bool enter) { rtwdev->hci.ops->deep_ps (rtwdev, enter);drivers/net/wireless/realtek/rtw88/main.c +1
-1@@ -1357,7 +1357,7 @@ static int rtw_power_on(struct rtw_dev *rtwdev)int ret;if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) -return 0 ; + goto success; ret =rtw_hci_setup (rtwdev);if (ret) {
drivers/net/wireless/realtek/rtw88/main.c static int rtw_power_on(struct rtw_dev *rtwdev) · line 1412
Quoted 6 lines
drivers/net/wireless/realtek/rtw88/main.c +3
-0@@ -1407,6 +1407,9 @@ static int rtw_power_on(struct rtw_dev *rtwdev)rtw_coex_power_on_setting (rtwdev);rtw_coex_init_hw_config (rtwdev, wifi_only); +success: +rtw_hci_start_rx (rtwdev); +
As mentioned, this is not a common routine, but only special for always_power_on case. For normal case, running both rtw_hci_start() and rtw_hci_start_rx() are confusing. Even I'm thinking the names of these two ops are confusing people.
drivers/net/wireless/realtek/rtw88/main.c int rtw_core_start(struct rtw_dev *rtwdev) · line 1516
Quoted 9 lines
drivers/net/wireless/realtek/rtw88/main.c +2
-0return 0 ; err_off:@@ -1509,6 +1512,8 @@ int rtw_core_start(struct rtw_dev *rtwdev)static void rtw_power_off (struct rtw_dev *rtwdev) { +rtw_hci_stop_rx (rtwdev); +
Ditto.
Quoted 43 lines
drivers/net/wireless/realtek/rtw88/main.c +0
-0if (rtwdev->always_power_on)return ;drivers/net/wireless/realtek/rtw88/usb.c +28
-0@@ -713,6 +713,34 @@ static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev)/* empty function for rtw_hci_ops */ } +static void rtw_usb_stop_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); + +if (!rtwusb->rx_enabled) +return ; + +rtw_usb_cancel_rx_bufs (rtwusb); + rtwusb->rx_enabled = false; +} + +static void rtw_usb_start_rx (struct rtw_dev *rtwdev) +{ +struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); +int i; + +if (rtwusb->rx_enabled) +return ; + +for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { +struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; + +rtw_usb_rx_resubmit (rtwusb, rxcb); + } + + rtwusb->rx_enabled = true; +} +static struct rtw_hci_ops rtw_usb_ops = { .tx_write = rtw_usb_tx_write, .tx_kick_off = rtw_usb_tx_kick_off,
drivers/net/wireless/realtek/rtw88/usb.c static struct rtw_hci_ops rtw_usb_ops = { · line 754
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/usb.c +2
-0@@ -722,6 +750,8 @@ static struct rtw_hci_ops rtw_usb_ops = { .deep_ps = rtw_usb_deep_ps, .link_ps = rtw_usb_link_ps, .interface_cfg = rtw_usb_interface_cfg, + .stop_rx = rtw_usb_stop_rx, + .start_rx = rtw_usb_start_rx,
Please set .stop_rx/.start_rx to NULL for PCI and SDIO explicitly.
Quoted 46 lines
drivers/net/wireless/realtek/rtw88/usb.c +1
-13.write8 = rtw_usb_write8, .write16 = rtw_usb_write16,@@ -751,18 +781,6 @@ static int rtw_usb_init_rx(struct rtw_dev *rtwdev)return 0 ; } -static void rtw_usb_setup_rx (struct rtw_dev *rtwdev) -{ -struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev); -int i; - -for (i =0 ; i <RTW_USB_RXCB_NUM ; i++) { -struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i]; - -rtw_usb_rx_resubmit (rtwusb, rxcb); - } -} -static void rtw_usb_deinit_rx (struct rtw_dev *rtwdev) {struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);@@ -900,7 +918,7 @@ int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) goto err_destroy_rxwq; } -rtw_usb_setup_rx (rtwdev); +rtw_usb_start_rx (rtwdev);return 0 ;drivers/net/wireless/realtek/rtw88/usb.h +1
-1@@ -82,6 +82,7 @@ struct rtw_usb {struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM ];struct sk_buff_head rx_queue;struct work_struct rx_work; +bool rx_enabled; };static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data (struct sk_buff *skb) --2.25.1
Ping-Ke Shih
maintainerRE: [PATCH v2 1/2] wifi: rtw88: 8821cu: keep power on always for 8821CU
In reply to Marcin ŚlusarzQuoted 3 lines · Marcin Ślusarz
From: Ping-Ke Shih <[email protected]>
This chip fails to reliably wake up from power off.
"so keep power on ...." (more description)
Quoted 2 lines
Change-Id: I295de3c71fe91af37e8cc39b70728a8ba7e94b2f
No change-ID. Please run checkpatch.pl before sending.
Quoted 2 lines
Reported-by Marcin Ślusarz <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>
I think you can edit this patch as what you want. Then I can become the Co-developer (use Co-developed-by).
Ping-Ke Shih
maintainerRE: [PATCH] wifi: rtw88/usb: stop rx work before potential power off
In reply to Marcin ŚlusarzQuoted 14 lines · Marcin Ślusarz
wt., 4 cze 2024 o 02:57 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 13 lines
drivers/net/wireless/realtek/rtw88/main.c static int rtw_power_on(struct rtw_dev *rtwdev) · line 1360
Quoted 8 lines · Marcin Ślusarz
drivers/net/wireless/realtek/rtw88/main.c +1
-1@@ -1357,7 +1357,7 @@ static int rtw_power_on(struct rtw_dev *rtwdev)int ret;if (rtwdev->always_power_on &&test_bit (RTW_FLAG_POWERON , rtwdev->flags)) -return 0 ; + goto success;
rtw_hci_start_rx(rtwdev)is only needed by this case, so
Quoted 8 lines
Quoted 4 lines
if (rtwdev->always_power_on && test_bit(RTW_FLAG_POWERON, rtwdev->flags)) { rtw_hci_start_rx(rtwdev); return 0; }Yes, strictly speaking, it's needed only in the
always_power_oncase, but doing that in the common code path ensures that it's tested and still works.
For the non- always_power_on case, it calls rtw_hci_start()/rtw_hci_stop() already so I don't think we should call these duplicates.
PATCH 1/1 wifi: rtw88: usb: drop rx skbs when device is not running
In reply to Marcin ŚlusarzFrom: Marcin Ślusarz <[email protected]>
Avoids WARN_ON(!local->started) in ieee80211_rx_list, after the patch that disables power management of 8821CU.
--- drivers/net/wireless/realtek/rtw88/usb.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/usb.c +5 -0
@@ -570,6 +570,11 @@ static void rtw_usb_rx_handler(struct work_struct *work)continue ; } +if (!test_bit (RTW_FLAG_RUNNING , rtwdev->flags)) { +dev_kfree_skb_any (skb); +continue ; + } +skb_put (skb, pkt_stat.pkt_len);skb_reserve (skb, pkt_offset);memcpy (skb->cb, &rx_status,sizeof (rx_status));
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerQuoted 20 lines · Marcin Ślusarz
Quoted 11 lines
Quoted 11 lines
I'm asking because if we are going in this direction, there's something more to fix... With your v2, very frequently, I hit
WARN_ON(!local->started)inieee80211_rx_napi(in wireless-next, the code was moved toieee80211_rx_list).With my patch, I checked and hit that
WARN_ON, too, but very occasionally.I think the difference is in what happens in
rtw_ips_enter- I disabled only thepower_off, but you also disabled everything else, including the cancelation ofwork_structs.Quoted 8 lines
Quoted 4 lines
The warning itself sounds harmless, but I think users should never see such warnings, so this needs to be fixed somehow. Probably some additional
work_struct(s)need to be canceled?I forgot to say my patch is compiled test only, and I didn't consider flow too much, just to close the behavior of your patches. You can improve my patch to be more reliable to avoid
WARN_ON().
Quoted 5 lines
Two variants of the patch that fix this issue will follow. They are built on top of yours
v2 and my "wifi: rtw88: schedule rx work after everything is set up" from the other thread.
Please choose the one you like more :).
The patch "wifi: rtw88: usb: drop rx skbs when device is not running" is to drop all skb it receives. USB is still working, so I don't prefer this.
"wifi: rtw88/usb: stop rx work before potential power off" seems to stop RX. But how rtw_usb_cancel_rx_bufs() can stop RX? Remove RX urb to stop it? Not sure if this is regular method for USB devices?
By the way, please take and refine my v2 patch into your patchset. That will be easier to me to merge patches finally.
Ping-Ke
wt., 4 cze 2024 o 02:50 Ping-Ke Shih <[email protected]> napisał(a):
Quoted 28 lines
Quoted 20 lines · Marcin Ślusarz
Quoted 11 lines
Quoted 11 lines
I'm asking because if we are going in this direction, there's something more to fix... With your v2, very frequently, I hit
WARN_ON(!local->started)inieee80211_rx_napi(in wireless-next, the code was moved toieee80211_rx_list).With my patch, I checked and hit that
WARN_ON, too, but very occasionally.I think the difference is in what happens in
rtw_ips_enter- I disabled only thepower_off, but you also disabled everything else, including the cancelation ofwork_structs.Quoted 8 lines
Quoted 4 lines
The warning itself sounds harmless, but I think users should never see such warnings, so this needs to be fixed somehow. Probably some additional
work_struct(s)need to be canceled?I forgot to say my patch is compiled test only, and I didn't consider flow too much, just to close the behavior of your patches. You can improve my patch to be more reliable to avoid
WARN_ON().Quoted 5 lines
Two variants of the patch that fix this issue will follow. They are built on top of yours
v2 and my "wifi: rtw88: schedule rx work after everything is set up" from the other thread.
Please choose the one you like more :).
Quoted 5 lines
The patch "wifi: rtw88: usb: drop rx skbs when device is not running" is to drop all skb it receives. USB is still working, so I don't prefer this.
"wifi: rtw88/usb: stop rx work before potential power off" seems to stop RX. But how
rtw_usb_cancel_rx_bufs()can stop RX? Remove RX urb to stop it?
Yes, URBs are removed, so the buffers will not be filled in, and completion callbacks will not be called.
Quoted 1 line
Not sure if this is regular method for USB devices?
I'm not sure, either. Ideally, it should be disabled in hardware, but AFAIK there's no public documentation for this chip, so no way for me to figure out how to do it, and we are dealing with a case of power management failure here.
Quoted 5 lines
By the way, please take and refine my v2 patch into your patchset. That will be easier to me to merge patches finally.
Ping-Ke