Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wifi: wfx: implement wfx_remain_on_channel()

With some conditions, the device is able to send/receive frames during
scan operation. So, it is possible to use it implement the "remain on
channel" feature. We just ask for a passive scan (without sending any
probe request) on one channel.

This architecture allows to leverage some interesting features:
- if the device is AP, the device switches channel just after the next
beacon and the beacons are stopped during the off-channel interval.
- if the device is connected, it advertises it is asleep before to
switch channel (so the AP should stop to try to send data)

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20231004172843.195332-9-jerome.pouiller@silabs.com

authored by

Jérôme Pouiller and committed by
Kalle Valo
fc627dad f7385a20

+76 -1
+3
drivers/net/wireless/silabs/wfx/main.c
··· 151 151 .change_chanctx = wfx_change_chanctx, 152 152 .assign_vif_chanctx = wfx_assign_vif_chanctx, 153 153 .unassign_vif_chanctx = wfx_unassign_vif_chanctx, 154 + .remain_on_channel = wfx_remain_on_channel, 155 + .cancel_remain_on_channel = wfx_cancel_remain_on_channel, 154 156 }; 155 157 156 158 bool wfx_api_older_than(struct wfx_dev *wdev, int major, int minor) ··· 291 289 hw->wiphy->features |= NL80211_FEATURE_AP_SCAN; 292 290 hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; 293 291 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 292 + hw->wiphy->max_remain_on_channel_duration = 5000; 294 293 hw->wiphy->max_ap_assoc_sta = HIF_LINK_ID_MAX; 295 294 hw->wiphy->max_scan_ssids = 2; 296 295 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
+62
drivers/net/wireless/silabs/wfx/scan.c
··· 145 145 wvif->scan_nb_chan_done = nb_chan_done; 146 146 complete(&wvif->scan_complete); 147 147 } 148 + 149 + void wfx_remain_on_channel_work(struct work_struct *work) 150 + { 151 + struct wfx_vif *wvif = container_of(work, struct wfx_vif, remain_on_channel_work); 152 + struct ieee80211_channel *chan = wvif->remain_on_channel_chan; 153 + int duration = wvif->remain_on_channel_duration; 154 + int ret; 155 + 156 + /* Hijack scan request to implement Remain-On-Channel */ 157 + mutex_lock(&wvif->wdev->conf_mutex); 158 + mutex_lock(&wvif->wdev->scan_lock); 159 + if (wvif->join_in_progress) { 160 + dev_info(wvif->wdev->dev, "abort in-progress REQ_JOIN"); 161 + wfx_reset(wvif); 162 + } 163 + wfx_tx_flush(wvif->wdev); 164 + 165 + reinit_completion(&wvif->scan_complete); 166 + ret = wfx_hif_scan_uniq(wvif, chan, duration); 167 + if (ret) 168 + goto end; 169 + ieee80211_ready_on_channel(wvif->wdev->hw); 170 + ret = wait_for_completion_timeout(&wvif->scan_complete, 171 + msecs_to_jiffies(duration * 120 / 100)); 172 + if (!ret) { 173 + wfx_hif_stop_scan(wvif); 174 + ret = wait_for_completion_timeout(&wvif->scan_complete, 1 * HZ); 175 + dev_dbg(wvif->wdev->dev, "roc timeout\n"); 176 + } 177 + if (!ret) 178 + dev_err(wvif->wdev->dev, "roc didn't stop\n"); 179 + ieee80211_remain_on_channel_expired(wvif->wdev->hw); 180 + end: 181 + mutex_unlock(&wvif->wdev->scan_lock); 182 + mutex_unlock(&wvif->wdev->conf_mutex); 183 + wfx_bh_request_tx(wvif->wdev); 184 + } 185 + 186 + int wfx_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 187 + struct ieee80211_channel *chan, int duration, 188 + enum ieee80211_roc_type type) 189 + { 190 + struct wfx_dev *wdev = hw->priv; 191 + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; 192 + 193 + if (wfx_api_older_than(wdev, 3, 10)) 194 + return -EOPNOTSUPP; 195 + 196 + wvif->remain_on_channel_duration = duration; 197 + wvif->remain_on_channel_chan = chan; 198 + schedule_work(&wvif->remain_on_channel_work); 199 + return 0; 200 + } 201 + 202 + int wfx_cancel_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 203 + { 204 + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; 205 + 206 + wfx_hif_stop_scan(wvif); 207 + flush_work(&wvif->remain_on_channel_work); 208 + return 0; 209 + }
+6
drivers/net/wireless/silabs/wfx/scan.h
··· 19 19 void wfx_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 20 20 void wfx_scan_complete(struct wfx_vif *wvif, int nb_chan_done); 21 21 22 + void wfx_remain_on_channel_work(struct work_struct *work); 23 + int wfx_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 24 + struct ieee80211_channel *chan, int duration, 25 + enum ieee80211_roc_type type); 26 + int wfx_cancel_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 27 + 22 28 #endif
+1
drivers/net/wireless/silabs/wfx/sta.c
··· 728 728 729 729 init_completion(&wvif->scan_complete); 730 730 INIT_WORK(&wvif->scan_work, wfx_hw_scan_work); 731 + INIT_WORK(&wvif->remain_on_channel_work, wfx_remain_on_channel_work); 731 732 732 733 wfx_tx_queues_init(wvif); 733 734 wfx_tx_policy_init(wvif);
+4 -1
drivers/net/wireless/silabs/wfx/wfx.h
··· 70 70 71 71 bool after_dtim_tx_allowed; 72 72 bool join_in_progress; 73 + struct completion set_pm_mode_complete; 73 74 74 75 struct delayed_work beacon_loss_work; 75 76 ··· 88 87 bool scan_abort; 89 88 struct ieee80211_scan_request *scan_req; 90 89 91 - struct completion set_pm_mode_complete; 90 + struct ieee80211_channel *remain_on_channel_chan; 91 + int remain_on_channel_duration; 92 + struct work_struct remain_on_channel_work; 92 93 }; 93 94 94 95 static inline struct ieee80211_vif *wvif_to_vif(struct wfx_vif *wvif)