1e3037485SYan-Hsuan Chuang // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2e3037485SYan-Hsuan Chuang /* Copyright(c) 2018-2019 Realtek Corporation
3e3037485SYan-Hsuan Chuang */
4e3037485SYan-Hsuan Chuang
5e3037485SYan-Hsuan Chuang #include "main.h"
627e117e4SYan-Hsuan Chuang #include "reg.h"
7e3037485SYan-Hsuan Chuang #include "fw.h"
8e3037485SYan-Hsuan Chuang #include "ps.h"
9e3037485SYan-Hsuan Chuang #include "mac.h"
104136214fSYan-Hsuan Chuang #include "coex.h"
11e3037485SYan-Hsuan Chuang #include "debug.h"
12e3037485SYan-Hsuan Chuang
rtw_ips_pwr_up(struct rtw_dev * rtwdev)13e3037485SYan-Hsuan Chuang static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)
14e3037485SYan-Hsuan Chuang {
15e3037485SYan-Hsuan Chuang int ret;
16e3037485SYan-Hsuan Chuang
17e3037485SYan-Hsuan Chuang ret = rtw_core_start(rtwdev);
18e3037485SYan-Hsuan Chuang if (ret)
19e3037485SYan-Hsuan Chuang rtw_err(rtwdev, "leave idle state failed\n");
20e3037485SYan-Hsuan Chuang
212ce9a91fSPo-Hao Huang rtw_coex_ips_notify(rtwdev, COEX_IPS_LEAVE);
22e3037485SYan-Hsuan Chuang rtw_set_channel(rtwdev);
23e3037485SYan-Hsuan Chuang
24e3037485SYan-Hsuan Chuang return ret;
25e3037485SYan-Hsuan Chuang }
26e3037485SYan-Hsuan Chuang
rtw_enter_ips(struct rtw_dev * rtwdev)27e3037485SYan-Hsuan Chuang int rtw_enter_ips(struct rtw_dev *rtwdev)
28e3037485SYan-Hsuan Chuang {
294a267bc5SPing-Ke Shih if (!test_bit(RTW_FLAG_POWERON, rtwdev->flags))
306bf3a083SChih-Kang Chang return 0;
31e3037485SYan-Hsuan Chuang
324136214fSYan-Hsuan Chuang rtw_coex_ips_notify(rtwdev, COEX_IPS_ENTER);
334136214fSYan-Hsuan Chuang
34e3037485SYan-Hsuan Chuang rtw_core_stop(rtwdev);
353dff7c6eSYan-Hsuan Chuang rtw_hci_link_ps(rtwdev, true);
36e3037485SYan-Hsuan Chuang
37e3037485SYan-Hsuan Chuang return 0;
38e3037485SYan-Hsuan Chuang }
39e3037485SYan-Hsuan Chuang
rtw_restore_port_cfg_iter(void * data,struct ieee80211_vif * vif)40*8986f0a9SDmitry Antipov static void rtw_restore_port_cfg_iter(void *data, struct ieee80211_vif *vif)
41e3037485SYan-Hsuan Chuang {
42e3037485SYan-Hsuan Chuang struct rtw_dev *rtwdev = data;
43e3037485SYan-Hsuan Chuang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv;
44e3037485SYan-Hsuan Chuang u32 config = ~0;
45e3037485SYan-Hsuan Chuang
46e3037485SYan-Hsuan Chuang rtw_vif_port_config(rtwdev, rtwvif, config);
47e3037485SYan-Hsuan Chuang }
48e3037485SYan-Hsuan Chuang
rtw_leave_ips(struct rtw_dev * rtwdev)49e3037485SYan-Hsuan Chuang int rtw_leave_ips(struct rtw_dev *rtwdev)
50e3037485SYan-Hsuan Chuang {
51e3037485SYan-Hsuan Chuang int ret;
52e3037485SYan-Hsuan Chuang
534a267bc5SPing-Ke Shih if (test_bit(RTW_FLAG_POWERON, rtwdev->flags))
546bf3a083SChih-Kang Chang return 0;
556bf3a083SChih-Kang Chang
563dff7c6eSYan-Hsuan Chuang rtw_hci_link_ps(rtwdev, false);
573dff7c6eSYan-Hsuan Chuang
58e3037485SYan-Hsuan Chuang ret = rtw_ips_pwr_up(rtwdev);
59e3037485SYan-Hsuan Chuang if (ret) {
60e3037485SYan-Hsuan Chuang rtw_err(rtwdev, "failed to leave ips state\n");
61e3037485SYan-Hsuan Chuang return ret;
62e3037485SYan-Hsuan Chuang }
63e3037485SYan-Hsuan Chuang
6478d5bf92SSascha Hauer rtw_iterate_vifs(rtwdev, rtw_restore_port_cfg_iter, rtwdev);
65e3037485SYan-Hsuan Chuang
66e3037485SYan-Hsuan Chuang return 0;
67e3037485SYan-Hsuan Chuang }
68e3037485SYan-Hsuan Chuang
rtw_power_mode_change(struct rtw_dev * rtwdev,bool enter)6927e117e4SYan-Hsuan Chuang void rtw_power_mode_change(struct rtw_dev *rtwdev, bool enter)
7027e117e4SYan-Hsuan Chuang {
7127e117e4SYan-Hsuan Chuang u8 request, confirm, polling;
72690390d8SChin-Yen Lee int ret;
7327e117e4SYan-Hsuan Chuang
7427e117e4SYan-Hsuan Chuang request = rtw_read8(rtwdev, rtwdev->hci.rpwm_addr);
7527e117e4SYan-Hsuan Chuang confirm = rtw_read8(rtwdev, rtwdev->hci.cpwm_addr);
7627e117e4SYan-Hsuan Chuang
7727e117e4SYan-Hsuan Chuang /* toggle to request power mode, others remain 0 */
7827e117e4SYan-Hsuan Chuang request ^= request | BIT_RPWM_TOGGLE;
79690390d8SChin-Yen Lee if (enter) {
8027e117e4SYan-Hsuan Chuang request |= POWER_MODE_LCLK;
81fc3ac64aSChin-Yen Lee if (rtw_get_lps_deep_mode(rtwdev) == LPS_DEEP_MODE_PG)
8204b786e0SYan-Hsuan Chuang request |= POWER_MODE_PG;
8304b786e0SYan-Hsuan Chuang }
84690390d8SChin-Yen Lee /* Each request require an ack from firmware */
85690390d8SChin-Yen Lee request |= POWER_MODE_ACK;
8627e117e4SYan-Hsuan Chuang
875d5d68bcSChin-Yen Lee if (rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_TX_WAKE))
885d5d68bcSChin-Yen Lee request |= POWER_TX_WAKE;
895d5d68bcSChin-Yen Lee
9027e117e4SYan-Hsuan Chuang rtw_write8(rtwdev, rtwdev->hci.rpwm_addr, request);
9127e117e4SYan-Hsuan Chuang
92690390d8SChin-Yen Lee /* Check firmware get the power requset and ack via cpwm register */
93690390d8SChin-Yen Lee ret = read_poll_timeout_atomic(rtw_read8, polling,
94690390d8SChin-Yen Lee (polling ^ confirm) & BIT_RPWM_TOGGLE,
95690390d8SChin-Yen Lee 100, 15000, true, rtwdev,
96690390d8SChin-Yen Lee rtwdev->hci.cpwm_addr);
97690390d8SChin-Yen Lee if (ret) {
98690390d8SChin-Yen Lee /* Hit here means that driver failed to get an ack from firmware.
99690390d8SChin-Yen Lee * The reason could be that hardware is locked at Deep sleep,
100690390d8SChin-Yen Lee * so most of the hardware circuits are not working, even
101690390d8SChin-Yen Lee * register read/write; or firmware is locked in some state and
102690390d8SChin-Yen Lee * cannot get the request. It should be treated as fatal error
103690390d8SChin-Yen Lee * and requires an entire analysis about the firmware/hardware.
10427e117e4SYan-Hsuan Chuang */
105690390d8SChin-Yen Lee WARN(1, "firmware failed to ack driver for %s Deep Power mode\n",
106690390d8SChin-Yen Lee enter ? "entering" : "leaving");
107690390d8SChin-Yen Lee }
10827e117e4SYan-Hsuan Chuang }
10927e117e4SYan-Hsuan Chuang EXPORT_SYMBOL(rtw_power_mode_change);
11027e117e4SYan-Hsuan Chuang
__rtw_leave_lps_deep(struct rtw_dev * rtwdev)11127e117e4SYan-Hsuan Chuang static void __rtw_leave_lps_deep(struct rtw_dev *rtwdev)
11227e117e4SYan-Hsuan Chuang {
11327e117e4SYan-Hsuan Chuang rtw_hci_deep_ps(rtwdev, false);
11427e117e4SYan-Hsuan Chuang }
11527e117e4SYan-Hsuan Chuang
__rtw_fw_leave_lps_check_reg(struct rtw_dev * rtwdev)116f31e039fSChin-Yen Lee static int __rtw_fw_leave_lps_check_reg(struct rtw_dev *rtwdev)
1173a2dd6b7SChin-Yen Lee {
1183a2dd6b7SChin-Yen Lee int i;
1193a2dd6b7SChin-Yen Lee
1203a2dd6b7SChin-Yen Lee /* Driver needs to wait for firmware to leave LPS state
1213a2dd6b7SChin-Yen Lee * successfully. Firmware will send null packet to inform AP,
1223a2dd6b7SChin-Yen Lee * and see if AP sends an ACK back, then firmware will restore
1233a2dd6b7SChin-Yen Lee * the REG_TCR register.
1243a2dd6b7SChin-Yen Lee *
1253a2dd6b7SChin-Yen Lee * If driver does not wait for firmware, null packet with
1263a2dd6b7SChin-Yen Lee * PS bit could be sent due to incorrect REG_TCR setting.
1273a2dd6b7SChin-Yen Lee *
1283a2dd6b7SChin-Yen Lee * In our test, 100ms should be enough for firmware to finish
1293a2dd6b7SChin-Yen Lee * the flow. If REG_TCR Register is still incorrect after 100ms,
1303a2dd6b7SChin-Yen Lee * just modify it directly, and throw a warn message.
1313a2dd6b7SChin-Yen Lee */
1323a2dd6b7SChin-Yen Lee for (i = 0 ; i < LEAVE_LPS_TRY_CNT; i++) {
1333a2dd6b7SChin-Yen Lee if (rtw_read32_mask(rtwdev, REG_TCR, BIT_PWRMGT_HWDATA_EN) == 0)
134f31e039fSChin-Yen Lee return 0;
1353a2dd6b7SChin-Yen Lee msleep(20);
1363a2dd6b7SChin-Yen Lee }
1373a2dd6b7SChin-Yen Lee
138f31e039fSChin-Yen Lee return -EBUSY;
139f31e039fSChin-Yen Lee }
140f31e039fSChin-Yen Lee
__rtw_fw_leave_lps_check_c2h(struct rtw_dev * rtwdev)141f31e039fSChin-Yen Lee static int __rtw_fw_leave_lps_check_c2h(struct rtw_dev *rtwdev)
142f31e039fSChin-Yen Lee {
143f31e039fSChin-Yen Lee if (wait_for_completion_timeout(&rtwdev->lps_leave_check,
144f31e039fSChin-Yen Lee LEAVE_LPS_TIMEOUT))
145f31e039fSChin-Yen Lee return 0;
146f31e039fSChin-Yen Lee return -EBUSY;
147f31e039fSChin-Yen Lee }
148f31e039fSChin-Yen Lee
rtw_fw_leave_lps_check(struct rtw_dev * rtwdev)149f31e039fSChin-Yen Lee static void rtw_fw_leave_lps_check(struct rtw_dev *rtwdev)
150f31e039fSChin-Yen Lee {
151f31e039fSChin-Yen Lee bool ret = false;
152f31e039fSChin-Yen Lee struct rtw_fw_state *fw;
153f31e039fSChin-Yen Lee
154f31e039fSChin-Yen Lee if (test_bit(RTW_FLAG_WOWLAN, rtwdev->flags))
155f31e039fSChin-Yen Lee fw = &rtwdev->wow_fw;
156f31e039fSChin-Yen Lee else
157f31e039fSChin-Yen Lee fw = &rtwdev->fw;
158f31e039fSChin-Yen Lee
1599a711831SChin-Yen Lee if (rtw_fw_feature_check(fw, FW_FEATURE_LPS_C2H))
160f31e039fSChin-Yen Lee ret = __rtw_fw_leave_lps_check_c2h(rtwdev);
161f31e039fSChin-Yen Lee else
162f31e039fSChin-Yen Lee ret = __rtw_fw_leave_lps_check_reg(rtwdev);
163f31e039fSChin-Yen Lee
164f31e039fSChin-Yen Lee if (ret) {
165f31e039fSChin-Yen Lee rtw_write32_clr(rtwdev, REG_TCR, BIT_PWRMGT_HWDATA_EN);
166f31e039fSChin-Yen Lee rtw_warn(rtwdev, "firmware failed to leave lps state\n");
167f31e039fSChin-Yen Lee }
168f31e039fSChin-Yen Lee }
169f31e039fSChin-Yen Lee
rtw_fw_leave_lps_check_prepare(struct rtw_dev * rtwdev)170f31e039fSChin-Yen Lee static void rtw_fw_leave_lps_check_prepare(struct rtw_dev *rtwdev)
171f31e039fSChin-Yen Lee {
172f31e039fSChin-Yen Lee struct rtw_fw_state *fw;
173f31e039fSChin-Yen Lee
174f31e039fSChin-Yen Lee if (test_bit(RTW_FLAG_WOWLAN, rtwdev->flags))
175f31e039fSChin-Yen Lee fw = &rtwdev->wow_fw;
176f31e039fSChin-Yen Lee else
177f31e039fSChin-Yen Lee fw = &rtwdev->fw;
178f31e039fSChin-Yen Lee
1799a711831SChin-Yen Lee if (rtw_fw_feature_check(fw, FW_FEATURE_LPS_C2H))
180f31e039fSChin-Yen Lee reinit_completion(&rtwdev->lps_leave_check);
1813a2dd6b7SChin-Yen Lee }
1823a2dd6b7SChin-Yen Lee
rtw_leave_lps_core(struct rtw_dev * rtwdev)183e3037485SYan-Hsuan Chuang static void rtw_leave_lps_core(struct rtw_dev *rtwdev)
184e3037485SYan-Hsuan Chuang {
185e3037485SYan-Hsuan Chuang struct rtw_lps_conf *conf = &rtwdev->lps_conf;
186e3037485SYan-Hsuan Chuang
187e3037485SYan-Hsuan Chuang conf->state = RTW_ALL_ON;
188e3037485SYan-Hsuan Chuang conf->awake_interval = 1;
189e3037485SYan-Hsuan Chuang conf->rlbm = 0;
190e3037485SYan-Hsuan Chuang conf->smart_ps = 0;
191e3037485SYan-Hsuan Chuang
1923dff7c6eSYan-Hsuan Chuang rtw_hci_link_ps(rtwdev, false);
193f31e039fSChin-Yen Lee rtw_fw_leave_lps_check_prepare(rtwdev);
194e3037485SYan-Hsuan Chuang rtw_fw_set_pwr_mode(rtwdev);
195f31e039fSChin-Yen Lee rtw_fw_leave_lps_check(rtwdev);
1963a2dd6b7SChin-Yen Lee
1973c519605SYan-Hsuan Chuang clear_bit(RTW_FLAG_LEISURE_PS, rtwdev->flags);
1984136214fSYan-Hsuan Chuang
1994136214fSYan-Hsuan Chuang rtw_coex_lps_notify(rtwdev, COEX_LPS_DISABLE);
200e3037485SYan-Hsuan Chuang }
201e3037485SYan-Hsuan Chuang
rtw_get_lps_deep_mode(struct rtw_dev * rtwdev)202fc3ac64aSChin-Yen Lee enum rtw_lps_deep_mode rtw_get_lps_deep_mode(struct rtw_dev *rtwdev)
203fc3ac64aSChin-Yen Lee {
204fc3ac64aSChin-Yen Lee if (test_bit(RTW_FLAG_WOWLAN, rtwdev->flags))
205fc3ac64aSChin-Yen Lee return rtwdev->lps_conf.wow_deep_mode;
206fc3ac64aSChin-Yen Lee else
207fc3ac64aSChin-Yen Lee return rtwdev->lps_conf.deep_mode;
208fc3ac64aSChin-Yen Lee }
209fc3ac64aSChin-Yen Lee
__rtw_enter_lps_deep(struct rtw_dev * rtwdev)21027e117e4SYan-Hsuan Chuang static void __rtw_enter_lps_deep(struct rtw_dev *rtwdev)
21127e117e4SYan-Hsuan Chuang {
212fc3ac64aSChin-Yen Lee if (rtw_get_lps_deep_mode(rtwdev) == LPS_DEEP_MODE_NONE)
213d3be4d11SYan-Hsuan Chuang return;
214d3be4d11SYan-Hsuan Chuang
21527e117e4SYan-Hsuan Chuang if (!test_bit(RTW_FLAG_LEISURE_PS, rtwdev->flags)) {
21627e117e4SYan-Hsuan Chuang rtw_dbg(rtwdev, RTW_DBG_PS,
21727e117e4SYan-Hsuan Chuang "Should enter LPS before entering deep PS\n");
21827e117e4SYan-Hsuan Chuang return;
21927e117e4SYan-Hsuan Chuang }
22027e117e4SYan-Hsuan Chuang
221fc3ac64aSChin-Yen Lee if (rtw_get_lps_deep_mode(rtwdev) == LPS_DEEP_MODE_PG)
22204b786e0SYan-Hsuan Chuang rtw_fw_set_pg_info(rtwdev);
22304b786e0SYan-Hsuan Chuang
22427e117e4SYan-Hsuan Chuang rtw_hci_deep_ps(rtwdev, true);
22527e117e4SYan-Hsuan Chuang }
22627e117e4SYan-Hsuan Chuang
rtw_enter_lps_core(struct rtw_dev * rtwdev)227e3037485SYan-Hsuan Chuang static void rtw_enter_lps_core(struct rtw_dev *rtwdev)
228e3037485SYan-Hsuan Chuang {
229e3037485SYan-Hsuan Chuang struct rtw_lps_conf *conf = &rtwdev->lps_conf;
230e3037485SYan-Hsuan Chuang
231e3037485SYan-Hsuan Chuang conf->state = RTW_RF_OFF;
232e3037485SYan-Hsuan Chuang conf->awake_interval = 1;
233e3037485SYan-Hsuan Chuang conf->rlbm = 1;
234e3037485SYan-Hsuan Chuang conf->smart_ps = 2;
235e3037485SYan-Hsuan Chuang
2364136214fSYan-Hsuan Chuang rtw_coex_lps_notify(rtwdev, COEX_LPS_ENABLE);
2374136214fSYan-Hsuan Chuang
238e3037485SYan-Hsuan Chuang rtw_fw_set_pwr_mode(rtwdev);
2393dff7c6eSYan-Hsuan Chuang rtw_hci_link_ps(rtwdev, true);
2403dff7c6eSYan-Hsuan Chuang
2413c519605SYan-Hsuan Chuang set_bit(RTW_FLAG_LEISURE_PS, rtwdev->flags);
242e3037485SYan-Hsuan Chuang }
243e3037485SYan-Hsuan Chuang
__rtw_enter_lps(struct rtw_dev * rtwdev,u8 port_id)24427e117e4SYan-Hsuan Chuang static void __rtw_enter_lps(struct rtw_dev *rtwdev, u8 port_id)
245e3037485SYan-Hsuan Chuang {
246e3037485SYan-Hsuan Chuang struct rtw_lps_conf *conf = &rtwdev->lps_conf;
247e3037485SYan-Hsuan Chuang
2483d391c06SYan-Hsuan Chuang if (test_bit(RTW_FLAG_LEISURE_PS, rtwdev->flags))
249e3037485SYan-Hsuan Chuang return;
250e3037485SYan-Hsuan Chuang
251e3037485SYan-Hsuan Chuang conf->mode = RTW_MODE_LPS;
2523d391c06SYan-Hsuan Chuang conf->port_id = port_id;
253e3037485SYan-Hsuan Chuang
254e3037485SYan-Hsuan Chuang rtw_enter_lps_core(rtwdev);
255e3037485SYan-Hsuan Chuang }
256e3037485SYan-Hsuan Chuang
__rtw_leave_lps(struct rtw_dev * rtwdev)25727e117e4SYan-Hsuan Chuang static void __rtw_leave_lps(struct rtw_dev *rtwdev)
258e3037485SYan-Hsuan Chuang {
259e3037485SYan-Hsuan Chuang struct rtw_lps_conf *conf = &rtwdev->lps_conf;
260e3037485SYan-Hsuan Chuang
26127e117e4SYan-Hsuan Chuang if (test_and_clear_bit(RTW_FLAG_LEISURE_PS_DEEP, rtwdev->flags)) {
26227e117e4SYan-Hsuan Chuang rtw_dbg(rtwdev, RTW_DBG_PS,
26327e117e4SYan-Hsuan Chuang "Should leave deep PS before leaving LPS\n");
26427e117e4SYan-Hsuan Chuang __rtw_leave_lps_deep(rtwdev);
26527e117e4SYan-Hsuan Chuang }
266d3e20fd1SYan-Hsuan Chuang
2673d391c06SYan-Hsuan Chuang if (!test_bit(RTW_FLAG_LEISURE_PS, rtwdev->flags))
268e3037485SYan-Hsuan Chuang return;
269e3037485SYan-Hsuan Chuang
270e3037485SYan-Hsuan Chuang conf->mode = RTW_MODE_ACTIVE;
271e3037485SYan-Hsuan Chuang
272e3037485SYan-Hsuan Chuang rtw_leave_lps_core(rtwdev);
273e3037485SYan-Hsuan Chuang }
27427e117e4SYan-Hsuan Chuang
rtw_enter_lps(struct rtw_dev * rtwdev,u8 port_id)27527e117e4SYan-Hsuan Chuang void rtw_enter_lps(struct rtw_dev *rtwdev, u8 port_id)
27627e117e4SYan-Hsuan Chuang {
27727e117e4SYan-Hsuan Chuang lockdep_assert_held(&rtwdev->mutex);
27827e117e4SYan-Hsuan Chuang
2793a068a2aSYan-Hsuan Chuang if (rtwdev->coex.stat.wl_force_lps_ctrl)
2803a068a2aSYan-Hsuan Chuang return;
2813a068a2aSYan-Hsuan Chuang
28227e117e4SYan-Hsuan Chuang __rtw_enter_lps(rtwdev, port_id);
28327e117e4SYan-Hsuan Chuang __rtw_enter_lps_deep(rtwdev);
28427e117e4SYan-Hsuan Chuang }
28527e117e4SYan-Hsuan Chuang
rtw_leave_lps(struct rtw_dev * rtwdev)28627e117e4SYan-Hsuan Chuang void rtw_leave_lps(struct rtw_dev *rtwdev)
28727e117e4SYan-Hsuan Chuang {
28827e117e4SYan-Hsuan Chuang lockdep_assert_held(&rtwdev->mutex);
28927e117e4SYan-Hsuan Chuang
29027e117e4SYan-Hsuan Chuang __rtw_leave_lps_deep(rtwdev);
29127e117e4SYan-Hsuan Chuang __rtw_leave_lps(rtwdev);
29227e117e4SYan-Hsuan Chuang }
29327e117e4SYan-Hsuan Chuang
rtw_leave_lps_deep(struct rtw_dev * rtwdev)29427e117e4SYan-Hsuan Chuang void rtw_leave_lps_deep(struct rtw_dev *rtwdev)
29527e117e4SYan-Hsuan Chuang {
29627e117e4SYan-Hsuan Chuang lockdep_assert_held(&rtwdev->mutex);
29727e117e4SYan-Hsuan Chuang
29827e117e4SYan-Hsuan Chuang __rtw_leave_lps_deep(rtwdev);
29927e117e4SYan-Hsuan Chuang }
3003918dd01SPing-Ke Shih
3013918dd01SPing-Ke Shih struct rtw_vif_recalc_lps_iter_data {
3023918dd01SPing-Ke Shih struct rtw_dev *rtwdev;
3033918dd01SPing-Ke Shih struct ieee80211_vif *found_vif;
3043918dd01SPing-Ke Shih int count;
3053918dd01SPing-Ke Shih };
3063918dd01SPing-Ke Shih
__rtw_vif_recalc_lps(struct rtw_vif_recalc_lps_iter_data * data,struct ieee80211_vif * vif)3073918dd01SPing-Ke Shih static void __rtw_vif_recalc_lps(struct rtw_vif_recalc_lps_iter_data *data,
3083918dd01SPing-Ke Shih struct ieee80211_vif *vif)
3093918dd01SPing-Ke Shih {
3103918dd01SPing-Ke Shih if (data->count < 0)
3113918dd01SPing-Ke Shih return;
3123918dd01SPing-Ke Shih
3133918dd01SPing-Ke Shih if (vif->type != NL80211_IFTYPE_STATION) {
3143918dd01SPing-Ke Shih data->count = -1;
3153918dd01SPing-Ke Shih return;
3163918dd01SPing-Ke Shih }
3173918dd01SPing-Ke Shih
3183918dd01SPing-Ke Shih data->count++;
3193918dd01SPing-Ke Shih data->found_vif = vif;
3203918dd01SPing-Ke Shih }
3213918dd01SPing-Ke Shih
rtw_vif_recalc_lps_iter(void * data,struct ieee80211_vif * vif)322*8986f0a9SDmitry Antipov static void rtw_vif_recalc_lps_iter(void *data, struct ieee80211_vif *vif)
3233918dd01SPing-Ke Shih {
3243918dd01SPing-Ke Shih __rtw_vif_recalc_lps(data, vif);
3253918dd01SPing-Ke Shih }
3263918dd01SPing-Ke Shih
rtw_recalc_lps(struct rtw_dev * rtwdev,struct ieee80211_vif * new_vif)3273918dd01SPing-Ke Shih void rtw_recalc_lps(struct rtw_dev *rtwdev, struct ieee80211_vif *new_vif)
3283918dd01SPing-Ke Shih {
3293918dd01SPing-Ke Shih struct rtw_vif_recalc_lps_iter_data data = { .rtwdev = rtwdev };
3303918dd01SPing-Ke Shih
3313918dd01SPing-Ke Shih if (new_vif)
3323918dd01SPing-Ke Shih __rtw_vif_recalc_lps(&data, new_vif);
3333918dd01SPing-Ke Shih rtw_iterate_vifs(rtwdev, rtw_vif_recalc_lps_iter, &data);
3343918dd01SPing-Ke Shih
3353918dd01SPing-Ke Shih if (data.count == 1 && data.found_vif->cfg.ps) {
3363918dd01SPing-Ke Shih rtwdev->ps_enabled = true;
3373918dd01SPing-Ke Shih } else {
3383918dd01SPing-Ke Shih rtwdev->ps_enabled = false;
3393918dd01SPing-Ke Shih rtw_leave_lps(rtwdev);
3403918dd01SPing-Ke Shih }
3413918dd01SPing-Ke Shih }
342