All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: "Marcin Ślusarz" <marcin.slusarz@gmail.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"Marcin Ślusarz" <mslusarz@renau.com>
Subject: RE: wifi: rtw88: 8821CU hangs after some number of power-off/on cycles
Date: Wed, 29 May 2024 01:52:03 +0000	[thread overview]
Message-ID: <3cc9cc75468d487c988dbacd8dfc5f57@realtek.com> (raw)
In-Reply-To: <CA+GA0_sQ_Bnp8CUq1Pmxf7zut1Kocaxbw4iXT4hYC5_ceXb7WQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 995 bytes --]

Marcin Ślusarz <marcin.slusarz@gmail.com> wrote:
> wt., 28 maj 2024 o 05:52 Ping-Ke Shih <pkshih@realtek.com> napisał(a):
> >
> > Marcin Ślusarz <marcin.slusarz@gmail.com> wrote:
> > >
> > > 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.
> 
> 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. 



[-- Attachment #2: v2-0001-wifi-rtw88-8821cu-keep-power-on-always-for-8821CU.patch --]
[-- Type: application/octet-stream, Size: 4183 bytes --]

From 715a7e758949595646e9134869667dc5a0437c3e Mon Sep 17 00:00:00 2001
From: Ping-Ke Shih <pkshih@realtek.com>
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.

Change-Id: I295de3c71fe91af37e8cc39b70728a8ba7e94b2f
Reported-by: Marcin Ślusarz <marcin.slusarz@gmail.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
---
 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(-)

diff --git a/mac80211.c b/mac80211.c
index 78078d65c88f..5202ba74c20a 100644
--- a/mac80211.c
+++ b/mac80211.c
@@ -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);
diff --git a/main.c b/main.c
index 567f9d4373c4..90d18b338a12 100644
--- a/main.c
+++ b/main.c
@@ -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);
diff --git a/main.h b/main.h
index d9afb585d423..e1c316bd7018 100644
--- a/main.h
+++ b/main.h
@@ -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;
diff --git a/ps.c b/ps.c
index b171e62d2d57..65223751fe2c 100644
--- a/ps.c
+++ b/ps.c
@@ -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;
 
diff --git a/ps.h b/ps.h
index 5ae83d2526cf..92057d01cbec 100644
--- a/ps.h
+++ b/ps.h
@@ -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);
diff --git a/usb.c b/usb.c
index a0188511099a..22742fe81b9a 100644
--- a/usb.c
+++ b/usb.c
@@ -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;
 
diff --git a/wow.c b/wow.c
index c86cfc47361a..2163e1dab630 100644
--- a/wow.c
+++ b/wow.c
@@ -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;
 }
-- 
2.25.1


  reply	other threads:[~2024-05-29  1:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 17:34 wifi: rtw88: 8821CU hangs after some number of power-off/on cycles Marcin Ślusarz
2024-05-27 17:34 ` [PATCH 1/2] wifi: rtw88: use RTW_FLAG_RUNNING for deciding whether to enter/leave IPS Marcin Ślusarz
2024-05-28  3:56   ` Ping-Ke Shih
2024-05-28 10:53     ` Marcin Ślusarz
2024-05-27 17:34 ` [PATCH 2/2] wifi: rtw88: disable power offs for 8821C Marcin Ślusarz
2024-05-27 18:43 ` wifi: rtw88: 8821CU hangs after some number of power-off/on cycles Bitterblue Smith
2024-05-28 10:42   ` Marcin Ślusarz
2024-05-28 12:25     ` Bitterblue Smith
2024-05-28 12:38       ` Marcin Ślusarz
2024-05-28  3:52 ` Ping-Ke Shih
2024-05-28 10:52   ` Marcin Ślusarz
2024-05-29  1:52     ` Ping-Ke Shih [this message]
2024-05-29 15:53       ` Marcin Ślusarz
2024-05-30  3:13         ` Ping-Ke Shih
2024-06-03 14:52           ` Marcin Ślusarz
2024-06-03 14:55             ` [PATCH] wifi: rtw88/usb: stop rx work before potential power off Marcin Ślusarz
2024-06-04  0:57               ` Ping-Ke Shih
2024-06-14 11:35                 ` Marcin Ślusarz
2024-06-14 12:13                   ` [PATCH v2 1/2] wifi: rtw88: 8821cu: keep power on always for 8821CU Marcin Ślusarz
2024-06-14 12:13                     ` [PATCH v2 2/2] wifi: rtw88/usb: stop rx work before potential power off Marcin Ślusarz
2024-06-17  1:56                       ` Ping-Ke Shih
2024-06-17  1:40                     ` [PATCH v2 1/2] wifi: rtw88: 8821cu: keep power on always for 8821CU Ping-Ke Shih
2024-06-17  1:47                   ` [PATCH] wifi: rtw88/usb: stop rx work before potential power off Ping-Ke Shih
2024-06-03 14:56             ` [PATCH] wifi: rtw88: usb: drop rx skbs when device is not running Marcin Ślusarz
2024-06-04  0:50             ` wifi: rtw88: 8821CU hangs after some number of power-off/on cycles Ping-Ke Shih
2024-06-14 11:42               ` Marcin Ślusarz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3cc9cc75468d487c988dbacd8dfc5f57@realtek.com \
    --to=pkshih@realtek.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=marcin.slusarz@gmail.com \
    --cc=mslusarz@renau.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.