hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/******************************************************************************
 *
 * Copyright(c) 2007 - 2021 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#define _RTW_PWRCTRL_C_
 
#include <drv_types.h>
#ifdef CONFIG_RTW_IPS
bool rtw_core_set_ips_state(void *drv_priv, enum rtw_rf_state state)
{
        struct dvobj_priv *dvobj = (struct dvobj_priv *)drv_priv;
        enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
 
        if (state == RTW_RF_ON) {
                pstatus = rtw_phl_rf_on(dvobj->phl);
        } else if (state == RTW_RF_OFF) {
                pstatus = rtw_phl_rf_off(dvobj->phl);
        }
 
        if (RTW_PHL_STATUS_SUCCESS == pstatus)
                return true;
        else
                return false;
}
#endif
 
#ifdef CONFIG_RESUME_IN_WORKQUEUE
   static void resume_workitem_callback(struct work_struct *work);
#endif /* CONFIG_RESUME_IN_WORKQUEUE */
 
void rtw_init_pwrctrl_priv(_adapter *padapter)
{
   struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
 
#if defined(CONFIG_CONCURRENT_MODE)
   if (!is_primary_adapter(padapter))
       return;
#endif
   pwrctrlpriv->bInSuspend = _FALSE;
   pwrctrlpriv->bkeepfwalive = _FALSE;
#ifdef CONFIG_RESUME_IN_WORKQUEUE
   _init_workitem(&pwrctrlpriv->resume_work, resume_workitem_callback, NULL);
   pwrctrlpriv->rtw_workqueue = create_singlethread_workqueue("rtw_workqueue");
#endif /* CONFIG_RESUME_IN_WORKQUEUE */
}
 
 
void rtw_free_pwrctrl_priv(_adapter *adapter)
{
   struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(adapter);
 
#if defined(CONFIG_CONCURRENT_MODE)
   if (!is_primary_adapter(adapter))
       return;
#endif
 
 
   /* _rtw_memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv)); */
 
 
#ifdef CONFIG_RESUME_IN_WORKQUEUE
   if (pwrctrlpriv->rtw_workqueue) {
       flush_workqueue(pwrctrlpriv->rtw_workqueue);
       destroy_workqueue(pwrctrlpriv->rtw_workqueue);
   }
#endif
}
 
#ifdef CONFIG_RESUME_IN_WORKQUEUE
extern int rtw_resume_process(_adapter *padapter);
 
static void resume_workitem_callback(struct work_struct *work)
{
   struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, resume_work);
   struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
   _adapter *adapter = dvobj_get_primary_adapter(dvobj);
 
   RTW_INFO("%s\n", __FUNCTION__);
 
   rtw_resume_process(adapter);
 
   rtw_resume_unlock_suspend();
}
 
void rtw_resume_in_workqueue(struct pwrctrl_priv *pwrpriv)
{
   /* accquire system's suspend lock preventing from falliing asleep while resume in workqueue */
   /* rtw_lock_suspend(); */
 
   rtw_resume_lock_suspend();
 
#if 1
   queue_work(pwrpriv->rtw_workqueue, &pwrpriv->resume_work);
#else
   _set_workitem(&pwrpriv->resume_work);
#endif
}
#endif /* CONFIG_RESUME_IN_WORKQUEUE */
 
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
inline bool rtw_is_earlysuspend_registered(struct pwrctrl_priv *pwrpriv)
{
   return (pwrpriv->early_suspend.suspend) ? _TRUE : _FALSE;
}
 
inline bool rtw_is_do_late_resume(struct pwrctrl_priv *pwrpriv)
{
   return (pwrpriv->do_late_resume) ? _TRUE : _FALSE;
}
 
inline void rtw_set_do_late_resume(struct pwrctrl_priv *pwrpriv, bool enable)
{
   pwrpriv->do_late_resume = enable;
}
#endif
 
#ifdef CONFIG_HAS_EARLYSUSPEND
extern int rtw_resume_process(_adapter *padapter);
static void rtw_early_suspend(struct early_suspend *h)
{
   struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
   RTW_INFO("%s\n", __FUNCTION__);
 
   rtw_set_do_late_resume(pwrpriv, _FALSE);
}
 
static void rtw_late_resume(struct early_suspend *h)
{
   struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
   struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
   _adapter *adapter = dvobj_get_primary_adapter(dvobj);
 
   RTW_INFO("%s\n", __FUNCTION__);
 
   if (pwrpriv->do_late_resume) {
       rtw_set_do_late_resume(pwrpriv, _FALSE);
       rtw_resume_process(adapter);
   }
}
 
void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
{
   RTW_INFO("%s\n", __FUNCTION__);
 
   /* jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit */
   pwrpriv->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
   pwrpriv->early_suspend.suspend = rtw_early_suspend;
   pwrpriv->early_suspend.resume = rtw_late_resume;
   register_early_suspend(&pwrpriv->early_suspend);
 
 
}
 
void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
{
   RTW_INFO("%s\n", __FUNCTION__);
 
   rtw_set_do_late_resume(pwrpriv, _FALSE);
 
   if (pwrpriv->early_suspend.suspend)
       unregister_early_suspend(&pwrpriv->early_suspend);
 
   pwrpriv->early_suspend.suspend = NULL;
   pwrpriv->early_suspend.resume = NULL;
}
#endif /* CONFIG_HAS_EARLYSUSPEND */
 
#ifdef CONFIG_ANDROID_POWER
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
   extern int rtw_resume_process(_adapter *padapter);
#endif
static void rtw_early_suspend(android_early_suspend_t *h)
{
   struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
   RTW_INFO("%s\n", __FUNCTION__);
 
   rtw_set_do_late_resume(pwrpriv, _FALSE);
}
 
static void rtw_late_resume(android_early_suspend_t *h)
{
   struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
   struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
   _adapter *adapter = dvobj_get_primary_adapter(dvobj);
 
   RTW_INFO("%s\n", __FUNCTION__);
   if (pwrpriv->do_late_resume) {
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
       rtw_set_do_late_resume(pwrpriv, _FALSE);
       rtw_resume_process(adapter);
#endif
   }
}
 
void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
{
   RTW_INFO("%s\n", __FUNCTION__);
 
   /* jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit */
   pwrpriv->early_suspend.level = ANDROID_EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
   pwrpriv->early_suspend.suspend = rtw_early_suspend;
   pwrpriv->early_suspend.resume = rtw_late_resume;
   android_register_early_suspend(&pwrpriv->early_suspend);
}
 
void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
{
   RTW_INFO("%s\n", __FUNCTION__);
 
   rtw_set_do_late_resume(pwrpriv, _FALSE);
 
   if (pwrpriv->early_suspend.suspend)
       android_unregister_early_suspend(&pwrpriv->early_suspend);
 
   pwrpriv->early_suspend.suspend = NULL;
   pwrpriv->early_suspend.resume = NULL;
}
#endif /* CONFIG_ANDROID_POWER */
 
static void _rtw_ssmps(_adapter *adapter, struct sta_info *sta)
{
   struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
   struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
 
   issue_action_SM_PS_wait_ack(adapter , sta->phl_sta->mac_addr,
           sta->phl_sta->asoc_cap.sm_ps, 3, 1);
 
   if (sta->phl_sta->asoc_cap.sm_ps == SM_PS_STATIC) {
       pmlmeext->txss_bk = sta->phl_sta->asoc_cap.nss_rx;
       rtw_phl_sta_assoc_cap_process(sta->phl_sta, _TRUE);
       sta->phl_sta->asoc_cap.nss_rx = 1;
       sta->phl_sta->asoc_cap.stbc_ht_rx = 0;
       sta->phl_sta->asoc_cap.stbc_vht_rx = 0;
       sta->phl_sta->asoc_cap.stbc_he_rx = 0;
   } else {
       sta->phl_sta->asoc_cap.nss_rx = pmlmeext->txss_bk;
       rtw_phl_sta_assoc_cap_process(sta->phl_sta, _FALSE);
   }
 
   rtw_phl_cmd_change_stainfo(adapter_to_dvobj(adapter)->phl,
                  sta->phl_sta,
                  STA_CHG_RAMASK,
                  NULL,
                  0,
                  PHL_CMD_DIRECTLY,
                  0);
}
 
void rtw_ssmps_enter(_adapter *adapter, struct sta_info *sta)
{
   /* P2P spec v1.9 3.3.1 */
   if (MLME_IS_AP(adapter) && !MLME_IS_GO(adapter))
       return;
 
   if (sta->phl_sta->asoc_cap.sm_ps == SM_PS_STATIC)
       return;
 
   RTW_INFO(ADPT_FMT" STA [" MAC_FMT "]\n", ADPT_ARG(adapter), MAC_ARG(sta->phl_sta->mac_addr));
 
   sta->phl_sta->asoc_cap.sm_ps = SM_PS_STATIC;
   _rtw_ssmps(adapter, sta);
}
void rtw_ssmps_leave(_adapter *adapter, struct sta_info *sta)
{
   /* P2P spec v1.9 3.3.1 */
   if (MLME_IS_AP(adapter) && !MLME_IS_GO(adapter))
       return;
 
   if (sta->phl_sta->asoc_cap.sm_ps == SM_PS_DISABLE)
       return;
 
   RTW_INFO(ADPT_FMT" STA [" MAC_FMT "] \n", ADPT_ARG(adapter), MAC_ARG(sta->phl_sta->mac_addr));
   sta->phl_sta->asoc_cap.sm_ps = SM_PS_DISABLE;
   _rtw_ssmps(adapter, sta);
}