linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
To: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Cc: Ping-Ke Shih <pkshih@realtek.com>
Subject: [PATCH v2 12/22] wifi: rtw88: Detect beacon loss with chips other than 8822c
Date: Fri, 11 Oct 2024 23:52:13 +0300	[thread overview]
Message-ID: <a60666a1-88e6-4e84-ae9b-ac2eb903dd01@gmail.com> (raw)
In-Reply-To: <d2870a44-9b91-4090-9a25-873eb62997f5@gmail.com>

The driver is supposed to avoid entering LPS (power saving) when there
is beacon loss, but only RTL8822C detects the beacon loss (because it
has beacon filtering in the firmware).

Detect beacon loss with the other chips by checking if we received less
than half the expected number of beacons in the last 2-second interval.

This gets rid of the occasional "failed to get tx report from firmware"
warnings with RTL8821AU. It may also avoid some disconnections.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
 - Move beacon loss checking to separate function.
 - Move variable declaration to the top.
---
 drivers/net/wireless/realtek/rtw88/main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index e6f985a92019..65d20ad02667 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -202,6 +202,21 @@ static void rtw_vif_watch_dog_iter(void *data, struct ieee80211_vif *vif)
 	rtwvif->stats.rx_cnt = 0;
 }
 
+static void rtw_sw_beacon_loss_check(struct rtw_dev *rtwdev,
+				     struct rtw_vif *rtwvif, int received_beacons)
+{
+	int watchdog_delay = 2000000 / 1024; /* TU */
+	int beacon_int, expected_beacons;
+
+	if (rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_BCN_FILTER) || !rtwvif)
+		return;
+
+	beacon_int = rtwvif_to_vif(rtwvif)->bss_conf.beacon_int;
+	expected_beacons = DIV_ROUND_UP(watchdog_delay, beacon_int);
+
+	rtwdev->beacon_loss = received_beacons < expected_beacons / 2;
+}
+
 /* process TX/RX statistics periodically for hardware,
  * the information helps hardware to enhance performance
  */
@@ -212,6 +227,7 @@ static void rtw_watch_dog_work(struct work_struct *work)
 	struct rtw_traffic_stats *stats = &rtwdev->stats;
 	struct rtw_watch_dog_iter_data data = {};
 	bool busy_traffic = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
+	int received_beacons = rtwdev->dm_info.cur_pkt_count.num_bcn_pkt;
 	u32 tx_unicast_mbps, rx_unicast_mbps;
 	bool ps_active;
 
@@ -270,6 +286,8 @@ static void rtw_watch_dog_work(struct work_struct *work)
 	 */
 	rtw_iterate_vifs(rtwdev, rtw_vif_watch_dog_iter, &data);
 
+	rtw_sw_beacon_loss_check(rtwdev, data.rtwvif, received_beacons);
+
 	/* fw supports only one station associated to enter lps, if there are
 	 * more than two stations associated to the AP, then we can not enter
 	 * lps, because fw does not handle the overlapped beacon interval
-- 
2.46.0


  parent reply	other threads:[~2024-10-11 20:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 20:31 [PATCH v2 00/22] wifi: rtw88: Add support for RTL8821AU and RTL8812AU Bitterblue Smith
2024-10-11 20:44 ` [PATCH v2 01/22] wifi: rtw88: Add some definitions for RTL8821AU/RTL8812AU Bitterblue Smith
2024-10-11 20:45 ` [PATCH v2 02/22] wifi: rtw88: Dump the HW features only for some chips Bitterblue Smith
2024-10-11 20:47 ` [PATCH v2 03/22] wifi: rtw88: Allow different C2H RA report sizes Bitterblue Smith
2024-10-18  6:11   ` Ping-Ke Shih
2024-10-18 16:41     ` Bitterblue Smith
2024-10-11 20:47 ` [PATCH v2 04/22] wifi: rtw88: Extend the init table parsing for RTL8812AU Bitterblue Smith
2024-10-18  6:16   ` Ping-Ke Shih
2024-10-11 20:48 ` [PATCH v2 05/22] wifi: rtw88: Allow rtw_chip_info.ltecoex_addr to be NULL Bitterblue Smith
2024-10-11 20:49 ` [PATCH v2 06/22] wifi: rtw88: Let each driver control the power on/off process Bitterblue Smith
2024-10-11 20:49 ` [PATCH v2 07/22] wifi: rtw88: Enable data rate fallback for older chips Bitterblue Smith
2024-10-18  6:26   ` Ping-Ke Shih
2024-10-18 16:41     ` Bitterblue Smith
2024-10-11 20:50 ` [PATCH v2 08/22] wifi: rtw88: Make txagc_remnant_ofdm an array Bitterblue Smith
2024-10-11 20:50 ` [PATCH v2 09/22] wifi: rtw88: Support TX page sizes bigger than 128 Bitterblue Smith
2024-10-18  6:33   ` Ping-Ke Shih
2024-10-11 20:51 ` [PATCH v2 10/22] wifi: rtw88: Move pwr_track_tbl to struct rtw_rfe_def Bitterblue Smith
2024-10-18  6:41   ` Ping-Ke Shih
2024-10-18 16:41     ` Bitterblue Smith
2024-10-11 20:51 ` [PATCH v2 11/22] wifi: rtw88: usb: Set pkt_info.ls for the reserved page Bitterblue Smith
2024-10-18  6:42   ` Ping-Ke Shih
2024-10-11 20:52 ` Bitterblue Smith [this message]
2024-10-11 20:52 ` [PATCH v2 13/22] wifi: rtw88: coex: Support chips without a scoreboard Bitterblue Smith
2024-10-11 20:53 ` [PATCH v2 14/22] wifi: rtw88: 8821a: Regularly ask for BT info updates Bitterblue Smith
2024-10-11 20:54 ` [PATCH v2 15/22] wifi: rtw88: 8812a: Mitigate beacon loss Bitterblue Smith
2024-10-11 20:54 ` [PATCH v2 16/22] wifi: rtw88: Add rtw8812a_table.{c,h} Bitterblue Smith
2024-10-11 20:55 ` [PATCH v2 17/22] wifi: rtw88: Add rtw8821a_table.{c,h} Bitterblue Smith
2024-10-11 20:56 ` [PATCH v2 18/22] wifi: rtw88: Add rtw88xxa.{c,h} Bitterblue Smith
2024-10-11 20:56 ` [PATCH v2 19/22] wifi: rtw88: Add rtw8821a.{c,h} Bitterblue Smith
2024-10-11 20:57 ` [PATCH v2 20/22] wifi: rtw88: Add rtw8812a.{c,h} Bitterblue Smith
2024-10-11 20:57 ` [PATCH v2 21/22] wifi: rtw88: Add rtw8821au.c and rtw8812au.c Bitterblue Smith
2024-10-18  7:36   ` Ping-Ke Shih
2024-10-18 16:42     ` Bitterblue Smith
2024-10-11 20:59 ` [PATCH v2 22/22] wifi: rtw88: Enable the new RTL8821AU/RTL8812AU drivers Bitterblue Smith
2024-10-18  7:37   ` Ping-Ke Shih

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=a60666a1-88e6-4e84-ae9b-ac2eb903dd01@gmail.com \
    --to=rtl8821cerfe2@gmail.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).