Re: [PATCH 18/19] wifi: rtw88: match the RTL8723BS firmware connect and power save behaviour

From: Bitterblue Smith

Date: Fri Jul 24 2026 - 18:11:14 EST


On 24/07/2026 21:33, luka.gejak@xxxxxxxxx wrote:
> From: Luka Gejak <luka.gejak@xxxxxxxxx>
>
> The vendor firmware expects the connect media status report at
> association completion rather than when the station is added, so defer
> it until the station is actually associated and track whether it was
> sent, so the disconnect report is only sent to undo one that was.

Does the firmware really care? What happens if you don't do all that?

>
> Leaving LPS also costs enough per-packet latency on this chip to
> throttle bursty traffic badly, and the stock check enters LPS after a
> single quiet two second window that an ordinary session hits
> constantly. Gate LPS on the smoothed throughput for this chip so it
> only sleeps after sustained idle. Other chips keep the existing
> behaviour.
>
> Signed-off-by: Luka Gejak <luka.gejak@xxxxxxxxx>
> ---
> drivers/net/wireless/realtek/rtw88/main.c | 47 ++++++++++++++++++++++-
> 1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
> index a2ef4479f408..63d1fb4bc87e 100644
> --- a/drivers/net/wireless/realtek/rtw88/main.c
> +++ b/drivers/net/wireless/realtek/rtw88/main.c
> @@ -304,6 +304,25 @@ static void rtw_sw_beacon_loss_check(struct rtw_dev *rtwdev,
> /* process TX/RX statistics periodically for hardware,
> * the information helps hardware to enhance performance
> */
> +static bool rtw8723bs_station_media_status(struct rtw_dev *rtwdev,
> + struct ieee80211_sta *sta,
> + struct ieee80211_vif *vif)
> +{
> + return rtw_is_8723bs(rtwdev) &&
> + vif->type == NL80211_IFTYPE_STATION && !sta->tdls;
> +}
> +
> +/* 8723BS SDIO: defer the connect MEDIA_STATUS_RPT until the STA is actually
> + * associated (the vendor firmware sends it at assoc completion, not sta-add).
> + */
> +static bool rtw8723bs_defer_sta_media_status(struct rtw_dev *rtwdev,
> + struct ieee80211_sta *sta,
> + struct ieee80211_vif *vif)
> +{
> + return rtw8723bs_station_media_status(rtwdev, sta, vif) &&
> + !vif->cfg.assoc;
> +}
> +
> static void rtw_watch_dog_work(struct work_struct *work)
> {
> struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
> @@ -382,6 +401,17 @@ static void rtw_watch_dog_work(struct work_struct *work)
> * get that vif and check if device is having traffic more than the
> * threshold.
> */
> + /* On 8723BS SDIO the firmware's per-packet wake latency out of LPS
> + * throttles bursty traffic hard. The stock check enters LPS after a
> + * single quiet 2s window, which a normal bursty session hits
> + * constantly. Gate LPS on the smoothed throughput instead so the chip
> + * only sleeps after sustained idle and stays awake through an active
> + * session. Other chips keep the normal behaviour.
> + */
> + if (rtw_is_8723bs(rtwdev) &&
> + (stats->tx_throughput || stats->rx_throughput))
> + ps_active = true;
> +
> if (rtwdev->ps_enabled && data.rtwvif && !ps_active &&
> !rtwdev->beacon_loss && !rtwdev->ap_active)
> rtw_enter_lps(rtwdev, data.rtwvif->port);
> @@ -450,7 +480,13 @@ int rtw_sta_add(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
> INIT_WORK(&si->rc_work, rtw_sta_rc_work);
>
> rtw_update_sta_info(rtwdev, si, true);
> - rtw_fw_media_status_report(rtwdev, si->mac_id, true);
> + if (rtw8723bs_defer_sta_media_status(rtwdev, sta, vif)) {
> + rtwvif->fw_media_connected = false;
> + } else {
> + rtw_fw_media_status_report(rtwdev, si->mac_id, true);
> + if (rtw8723bs_station_media_status(rtwdev, sta, vif))
> + rtwvif->fw_media_connected = true;
> + }
>
> rtwdev->sta_cnt++;
> rtwdev->beacon_loss = false;
> @@ -465,14 +501,21 @@ void rtw_sta_remove(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
> {
> struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv;
> struct ieee80211_vif *vif = si->vif;
> + struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv;
> int i;
>
> cancel_work_sync(&si->rc_work);
>
> if (vif->type != NL80211_IFTYPE_STATION || sta->tdls)
> rtw_release_macid(rtwdev, si->mac_id);
> - if (fw_exist)
> + if (fw_exist && rtw8723bs_station_media_status(rtwdev, sta, vif) &&
> + !rtwvif->fw_media_connected) {
> + /* connect status was deferred and never sent; nothing to undo */
> + } else if (fw_exist) {
> rtw_fw_media_status_report(rtwdev, si->mac_id, false);
> + if (rtw8723bs_station_media_status(rtwdev, sta, vif))
> + rtwvif->fw_media_connected = false;
> + }
>
> for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
> rtw_txq_cleanup(rtwdev, sta->txq[i]);