~ubuntu-branches/ubuntu/precise/linux-ti-omap/precise

« back to all changes in this revision

Viewing changes to ubuntu/rtl8192se/rtl_ps.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader, Amit Kucheria
  • Date: 2010-03-23 18:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20100323180512-iavj906ocnphdubp
Tags: 2.6.33-500.3
[ Amit Kucheria ]

* [Config] Fix the debug package name to end in -dbgsym
* SAUCE: Add the ubuntu/ drivers to omap
* SAUCE: Re-export the symbols for aufs
* [Config] Enable AUFS and COMPCACHE

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
 
3
 *
 
4
 * Based on the r8180 driver, which is:
 
5
 * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
 
6
 * This program is free software; you can redistribute it and/or modify it
 
7
 * under the terms of version 2 of the GNU General Public License as
 
8
 * published by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
 * more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along with
 
16
 * this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 
18
 *
 
19
 * The full GNU General Public License is included in this distribution in the
 
20
 * file called LICENSE.
 
21
 *
 
22
 * Contact Information:
 
23
 * wlanfae <wlanfae@realtek.com>
 
24
 *****************************************************************************/
 
25
#include "rtl_ps.h"
 
26
#include "rtl_core.h"
 
27
#ifdef RTL8192CE
 
28
#include "rtl8192c/r8192C_phy.h"
 
29
#include "rtl8192c/r8192C_phyreg.h"
 
30
#include "rtl8192c/r8192C_rtl6052.h"
 
31
#include "rtl8192c/r8192C_Efuse.h"
 
32
#elif defined RTL8192SE
 
33
#include "rtl8192s/r8192S_phy.h"
 
34
#include "rtl8192s/r8192S_phyreg.h"
 
35
#include "rtl8192s/r8192S_rtl6052.h"
 
36
#include "rtl8192s/r8192S_Efuse.h"
 
37
#else
 
38
#include "rtl8192e/r8192E_phy.h"
 
39
#include "rtl8192e/r8192E_phyreg.h"
 
40
#include "rtl8192e/r8190P_rtl8256.h" /* RTL8225 Radio frontend */
 
41
#include "rtl8192e/r8192E_cmdpkt.h"
 
42
#endif
 
43
 
 
44
#if defined(RTL8192E) || defined(RTL8192SE) || defined RTL8192CE
 
45
void rtl8192_hw_sleep_down(struct net_device *dev)
 
46
{
 
47
        struct r8192_priv *priv = rtllib_priv(dev);
 
48
        unsigned long flags = 0;
 
49
#ifdef CONFIG_ASPM_OR_D3
 
50
        PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
51
#endif  
 
52
        spin_lock_irqsave(&priv->rf_ps_lock,flags);
 
53
        if (priv->RFChangeInProgress) {
 
54
                spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
 
55
                RT_TRACE(COMP_RF, "rtl8192_hw_sleep_down(): RF Change in progress! \n");
 
56
                printk("rtl8192_hw_sleep_down(): RF Change in progress!\n");
 
57
                return;
 
58
        }
 
59
        spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
 
60
        RT_TRACE(COMP_PS, "%s()============>come to sleep down\n", __FUNCTION__);
 
61
 
 
62
#ifdef CONFIG_RTLWIFI_DEBUGFS   
 
63
        if(priv->debug->hw_holding) {
 
64
                return;
 
65
        }
 
66
#endif  
 
67
        MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
 
68
#ifdef CONFIG_ASPM_OR_D3
 
69
        if(pPSC->RegRfPsLevel & RT_RF_LPS_LEVEL_ASPM)
 
70
        {
 
71
                RT_ENABLE_ASPM(dev);
 
72
                RT_SET_PS_LEVEL(pPSC, RT_RF_LPS_LEVEL_ASPM);
 
73
        }
 
74
#endif
 
75
}
 
76
 
 
77
void rtl8192_hw_sleep_wq(void *data)
 
78
{
 
79
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
 
80
        struct rtllib_device *ieee = container_of_dwork_rsl(data,struct rtllib_device,hw_sleep_wq);
 
81
        struct net_device *dev = ieee->dev;
 
82
#else
 
83
        struct net_device *dev = (struct net_device *)data;
 
84
#endif
 
85
        rtl8192_hw_sleep_down(dev);
 
86
}
 
87
 
 
88
void rtl8192_hw_wakeup(struct net_device* dev)
 
89
{
 
90
        struct r8192_priv *priv = rtllib_priv(dev);
 
91
        unsigned long flags = 0;
 
92
#ifdef CONFIG_ASPM_OR_D3
 
93
        PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
94
#endif  
 
95
        spin_lock_irqsave(&priv->rf_ps_lock,flags);
 
96
        if (priv->RFChangeInProgress) {
 
97
                spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
 
98
                RT_TRACE(COMP_RF, "rtl8192_hw_wakeup(): RF Change in progress! \n");
 
99
                printk("rtl8192_hw_wakeup(): RF Change in progress! schedule wake up task again\n");
 
100
                queue_delayed_work_rsl(priv->rtllib->wq,&priv->rtllib->hw_wakeup_wq,MSECS(10));
 
101
                return;
 
102
        }
 
103
        spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
 
104
#ifdef CONFIG_ASPM_OR_D3
 
105
        if (pPSC->RegRfPsLevel & RT_RF_LPS_LEVEL_ASPM) {
 
106
                RT_DISABLE_ASPM(dev);
 
107
                RT_CLEAR_PS_LEVEL(pPSC, RT_RF_LPS_LEVEL_ASPM);
 
108
        }
 
109
#endif
 
110
        RT_TRACE(COMP_PS, "%s()============>come to wake up\n", __FUNCTION__);
 
111
        MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS);
 
112
}
 
113
 
 
114
void rtl8192_hw_wakeup_wq(void *data)
 
115
{
 
116
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
 
117
        struct rtllib_device *ieee = container_of_dwork_rsl(data,struct rtllib_device,hw_wakeup_wq);  
 
118
        struct net_device *dev = ieee->dev;
 
119
#else
 
120
        struct net_device *dev = (struct net_device *)data;
 
121
#endif
 
122
        rtl8192_hw_wakeup(dev);
 
123
 
 
124
}
 
125
 
 
126
#define MIN_SLEEP_TIME 50
 
127
#define MAX_SLEEP_TIME 10000
 
128
void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
 
129
{
 
130
#ifdef _RTL8192_EXT_PATCH_
 
131
        struct r8192_priv *priv = rtllib_priv(dev);
 
132
        u32 rb = jiffies, sleep_cost = MSECS(8+16+7), delta = 0;
 
133
        unsigned long flags;
 
134
 
 
135
        if((tl > rb) && (th > 0))
 
136
                return;
 
137
 
 
138
        spin_lock_irqsave(&priv->ps_lock,flags);
 
139
 
 
140
        if (tl >= sleep_cost)
 
141
                tl -= sleep_cost;
 
142
        else if (th > 0) {
 
143
                tl = 0xffffffff - sleep_cost + tl;  
 
144
                th--;
 
145
        } else {
 
146
                spin_unlock_irqrestore(&priv->ps_lock,flags);
 
147
                return;
 
148
        }
 
149
 
 
150
        if (tl > rb) {
 
151
                delta = tl - rb;
 
152
        } else if (th > 0) {
 
153
                delta = 0xffffffff - rb + tl;
 
154
                th --;
 
155
        } else {
 
156
                spin_unlock_irqrestore(&priv->ps_lock,flags);
 
157
                return;
 
158
        }
 
159
 
 
160
        if (delta <= MSECS(MIN_SLEEP_TIME)) {
 
161
                spin_unlock_irqrestore(&priv->ps_lock,flags);
 
162
                printk("too short to sleep::%x, %x, %lx\n",tl, rb,  MSECS(MIN_SLEEP_TIME));
 
163
                return;
 
164
        }       
 
165
 
 
166
        if(delta > MSECS(MAX_SLEEP_TIME)) {
 
167
                spin_unlock_irqrestore(&priv->ps_lock,flags);
 
168
                printk("========>too long to sleep:%x, %x, %lx\n", tl, rb,  MSECS(MAX_SLEEP_TIME));
 
169
                return;
 
170
        }
 
171
 
 
172
        RT_TRACE(COMP_LPS, "==============>%s(): wake up time is %d,%d\n",__FUNCTION__,delta,jiffies_to_msecs(delta));
 
173
        queue_delayed_work_rsl(priv->rtllib->wq,&priv->rtllib->hw_wakeup_wq,delta); 
 
174
        queue_delayed_work_rsl(priv->rtllib->wq, (void *)&priv->rtllib->hw_sleep_wq,0);
 
175
 
 
176
        spin_unlock_irqrestore(&priv->ps_lock,flags);
 
177
#else
 
178
        struct r8192_priv *priv = rtllib_priv(dev);
 
179
 
 
180
        u32 rb = jiffies;
 
181
        unsigned long flags;
 
182
 
 
183
        spin_lock_irqsave(&priv->ps_lock,flags);
 
184
 
 
185
        tl -= MSECS(8+16+7);
 
186
 
 
187
        if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
 
188
                        ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
 
189
                spin_unlock_irqrestore(&priv->ps_lock,flags);
 
190
                printk("too short to sleep::%x, %x, %lx\n",tl, rb,  MSECS(MIN_SLEEP_TIME));
 
191
                return;
 
192
        }       
 
193
 
 
194
        if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
 
195
                        ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))||
 
196
                        ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) {
 
197
                printk("========>too long to sleep:%x, %x, %lx\n", tl, rb,  MSECS(MAX_SLEEP_TIME));
 
198
                spin_unlock_irqrestore(&priv->ps_lock,flags);
 
199
                return;
 
200
        }
 
201
        {
 
202
                u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
 
203
                queue_delayed_work_rsl(priv->rtllib->wq,
 
204
                                &priv->rtllib->hw_wakeup_wq,tmp); 
 
205
        }
 
206
        queue_delayed_work_rsl(priv->rtllib->wq, 
 
207
                        (void *)&priv->rtllib->hw_sleep_wq,0);
 
208
        spin_unlock_irqrestore(&priv->ps_lock,flags);
 
209
#endif
 
210
}
 
211
#endif
 
212
 
 
213
#ifdef ENABLE_IPS
 
214
void InactivePsWorkItemCallback(struct net_device *dev)
 
215
{
 
216
        struct r8192_priv *priv = rtllib_priv(dev);
 
217
        PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
218
 
 
219
        RT_TRACE(COMP_PS, "InactivePsWorkItemCallback() ---------> \n");                        
 
220
        pPSC->bSwRfProcessing = true;
 
221
 
 
222
        RT_TRACE(COMP_PS, "InactivePsWorkItemCallback(): Set RF to %s.\n", \
 
223
                        pPSC->eInactivePowerState == eRfOff?"OFF":"ON");
 
224
#ifdef CONFIG_ASPM_OR_D3
 
225
        if(pPSC->eInactivePowerState == eRfOn)
 
226
        {
 
227
 
 
228
                if((pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_ASPM) && RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_ASPM))
 
229
                {
 
230
                        RT_DISABLE_ASPM(dev);
 
231
                        RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_ASPM);
 
232
                }
 
233
#ifdef TODO             
 
234
                else if((pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_PCI_D3) && RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_PCI_D3))
 
235
                {
 
236
                        RT_LEAVE_D3(dev, false);
 
237
                        RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_PCI_D3);
 
238
                }
 
239
#endif          
 
240
        }
 
241
#endif
 
242
        MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
 
243
 
 
244
#ifdef CONFIG_ASPM_OR_D3
 
245
        if(pPSC->eInactivePowerState == eRfOff)
 
246
        {
 
247
                if(pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_ASPM)
 
248
                {
 
249
                        RT_ENABLE_ASPM(dev);
 
250
                        RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_ASPM);
 
251
                }
 
252
#ifdef TODO             
 
253
                else if(pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_PCI_D3)
 
254
                {
 
255
                        RT_ENTER_D3(dev, false);
 
256
                        RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_PCI_D3);
 
257
                }
 
258
#endif          
 
259
        }
 
260
#endif
 
261
        
 
262
#if 0
 
263
        if(pPSC->eInactivePowerState == eRfOn)
 
264
        {
 
265
                while( index < 4 )
 
266
                {
 
267
                        if( ( pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP104_Encryption ) ||
 
268
                                (pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP40_Encryption) )
 
269
                        {
 
270
                                if( pMgntInfo->SecurityInfo.KeyLen[index] != 0)
 
271
                                pAdapter->HalFunc.SetKeyHandler(pAdapter, index, 0, false, pMgntInfo->SecurityInfo.PairwiseEncAlgorithm, true, false);
 
272
 
 
273
                        }
 
274
                        index++;
 
275
                }
 
276
        }
 
277
#endif
 
278
        pPSC->bSwRfProcessing = false;  
 
279
        RT_TRACE(COMP_PS, "InactivePsWorkItemCallback() <--------- \n");                        
 
280
}
 
281
 
 
282
void
 
283
IPSEnter(struct net_device *dev)
 
284
{
 
285
        struct r8192_priv *priv = rtllib_priv(dev);
 
286
        PRT_POWER_SAVE_CONTROL          pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
287
        RT_RF_POWER_STATE                       rtState;
 
288
 
 
289
        if (pPSC->bInactivePs)
 
290
        {
 
291
                rtState = priv->rtllib->eRFPowerState;
 
292
                if (rtState == eRfOn && !pPSC->bSwRfProcessing &&\
 
293
                        (priv->rtllib->state != RTLLIB_LINKED)&&\
 
294
                        (priv->rtllib->iw_mode != IW_MODE_MASTER))
 
295
                {
 
296
                        RT_TRACE(COMP_PS,"IPSEnter(): Turn off RF.\n");
 
297
                        pPSC->eInactivePowerState = eRfOff;
 
298
                        priv->isRFOff = true;
 
299
                        priv->bInPowerSaveMode = true;
 
300
                        InactivePsWorkItemCallback(dev);
 
301
                }
 
302
        }       
 
303
}
 
304
 
 
305
void
 
306
IPSLeave(struct net_device *dev)
 
307
{
 
308
        struct r8192_priv *priv = rtllib_priv(dev);
 
309
        PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
310
        RT_RF_POWER_STATE       rtState;
 
311
 
 
312
        if (pPSC->bInactivePs)
 
313
        {       
 
314
                rtState = priv->rtllib->eRFPowerState;  
 
315
                if (rtState != eRfOn  && !pPSC->bSwRfProcessing && priv->rtllib->RfOffReason <= RF_CHANGE_BY_IPS)
 
316
                {
 
317
                        RT_TRACE(COMP_PS, "IPSLeave(): Turn on RF.\n");
 
318
                        pPSC->eInactivePowerState = eRfOn;
 
319
                        priv->bInPowerSaveMode = false;
 
320
                        InactivePsWorkItemCallback(dev);
 
321
                }
 
322
        }
 
323
}
 
324
void IPSLeave_wq(void *data)
 
325
{
 
326
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
 
327
        struct rtllib_device *ieee = container_of_work_rsl(data,struct rtllib_device,ips_leave_wq);
 
328
        struct net_device *dev = ieee->dev;
 
329
#else
 
330
        struct net_device *dev = (struct net_device *)data;
 
331
#endif
 
332
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
333
        down(&priv->rtllib->ips_sem);
 
334
        IPSLeave(dev);  
 
335
        up(&priv->rtllib->ips_sem);     
 
336
}
 
337
void rtllib_ips_leave_wq(struct net_device *dev)
 
338
{
 
339
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
340
        RT_RF_POWER_STATE       rtState;
 
341
        rtState = priv->rtllib->eRFPowerState;
 
342
 
 
343
        if(priv->rtllib->PowerSaveControl.bInactivePs){ 
 
344
                if(rtState == eRfOff){
 
345
                        if(priv->rtllib->RfOffReason > RF_CHANGE_BY_IPS)
 
346
                        {
 
347
                                RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
 
348
                                return;
 
349
                        }
 
350
                        else{
 
351
                                printk("=========>%s(): IPSLeave\n",__FUNCTION__);
 
352
                                queue_work_rsl(priv->rtllib->wq,&priv->rtllib->ips_leave_wq);                           
 
353
                        }
 
354
                }
 
355
        }
 
356
}
 
357
void rtllib_ips_leave(struct net_device *dev)
 
358
{
 
359
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
360
        down(&priv->rtllib->ips_sem);
 
361
        IPSLeave(dev);  
 
362
        up(&priv->rtllib->ips_sem);     
 
363
}
 
364
#endif
 
365
 
 
366
#ifdef ENABLE_LPS
 
367
bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,    u8 rtPsMode)
 
368
{
 
369
        struct r8192_priv *priv = rtllib_priv(dev);
 
370
 
 
371
#ifdef _RTL8192_EXT_PATCH_
 
372
        if((priv->rtllib->iw_mode == IW_MODE_ADHOC) || (priv->rtllib->iw_mode == IW_MODE_MASTER)
 
373
                || (priv->rtllib->iw_mode == IW_MODE_MESH))     
 
374
#else
 
375
        if(priv->rtllib->iw_mode == IW_MODE_ADHOC)      
 
376
#endif
 
377
        {
 
378
                return false;
 
379
        }
 
380
 
 
381
        
 
382
        RT_TRACE(COMP_LPS,"%s(): set ieee->ps = %x\n",__FUNCTION__,rtPsMode);
 
383
        if(!priv->ps_force) {
 
384
                priv->rtllib->ps = rtPsMode;
 
385
        }
 
386
#if 0
 
387
        priv->rtllib->dot11PowerSaveMode = rtPsMode;
 
388
 
 
389
        if(priv->rtllib->dot11PowerSaveMode == eMaxPs)
 
390
        {
 
391
        }
 
392
        else
 
393
        {
 
394
        }
 
395
#endif
 
396
        if(priv->rtllib->sta_sleep != 0 && rtPsMode == RTLLIB_PS_DISABLED)
 
397
        {
 
398
                unsigned long flags;
 
399
 
 
400
                rtl8192_hw_wakeup(dev);
 
401
                priv->rtllib->sta_sleep = 0;
 
402
 
 
403
                spin_lock_irqsave(&(priv->rtllib->mgmt_tx_lock), flags);
 
404
                printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n");
 
405
                rtllib_sta_ps_send_null_frame(priv->rtllib, 0);
 
406
                spin_unlock_irqrestore(&(priv->rtllib->mgmt_tx_lock), flags);
 
407
        }
 
408
 
 
409
#if 0
 
410
        if((pPSC->bFwCtrlLPS) && (pPSC->bLeisurePs))
 
411
        {       
 
412
                if(priv->rtllib->dot11PowerSaveMode == eActive)
 
413
                {
 
414
                        RpwmVal = 0x0C; 
 
415
                        FwPwrMode = FW_PS_ACTIVE_MODE;
 
416
                        Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_SET_RPWM, (pu1Byte)(&RpwmVal));
 
417
                        Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_H2C_FW_PWRMODE, (pu1Byte)(&FwPwrMode));
 
418
                }
 
419
                else
 
420
                {
 
421
                        if(GetFwLPS_Doze(Adapter))
 
422
                        {
 
423
                                RpwmVal = 0x02; 
 
424
                                Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_H2C_FW_PWRMODE, (pu1Byte)(&pPSC->FWCtrlPSMode));
 
425
                                Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_SET_RPWM, (pu1Byte)(&RpwmVal));
 
426
                        }
 
427
                        else
 
428
                        {
 
429
                                pMgntInfo->dot11PowerSaveMode = eActive;
 
430
                                Adapter->bInPowerSaveMode = false;      
 
431
                        }
 
432
                }
 
433
        }
 
434
#endif
 
435
        return true;
 
436
}
 
437
 
 
438
 
 
439
void LeisurePSEnter(struct net_device *dev)
 
440
{
 
441
        struct r8192_priv *priv = rtllib_priv(dev);
 
442
        PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
443
 
 
444
        RT_TRACE(COMP_PS, "LeisurePSEnter()...\n");
 
445
        RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n", 
 
446
                pPSC->bLeisurePs, priv->rtllib->ps,pPSC->LpsIdleCount,RT_CHECK_FOR_HANG_PERIOD);
 
447
 
 
448
#ifdef _RTL8192_EXT_PATCH_
 
449
        if(!((priv->rtllib->iw_mode == IW_MODE_INFRA) && (priv->rtllib->state == RTLLIB_LINKED))
 
450
                || (priv->rtllib->iw_mode == IW_MODE_ADHOC) || (priv->rtllib->iw_mode == IW_MODE_MASTER)
 
451
                || (priv->rtllib->iw_mode == IW_MODE_MESH))
 
452
#else
 
453
        if(!((priv->rtllib->iw_mode == IW_MODE_INFRA) && (priv->rtllib->state == RTLLIB_LINKED))
 
454
                || (priv->rtllib->iw_mode == IW_MODE_ADHOC) || (priv->rtllib->iw_mode == IW_MODE_MASTER))
 
455
#endif
 
456
                return;
 
457
 
 
458
        if (pPSC->bLeisurePs)
 
459
        {
 
460
                if(pPSC->LpsIdleCount >= RT_CHECK_FOR_HANG_PERIOD) 
 
461
                {
 
462
        
 
463
                        if(priv->rtllib->ps == RTLLIB_PS_DISABLED)
 
464
                        {
 
465
 
 
466
                                RT_TRACE(COMP_LPS, "LeisurePSEnter(): Enter 802.11 power save mode...\n");
 
467
 
 
468
                                if(!pPSC->bFwCtrlLPS)
 
469
                                {
 
470
                                        if (priv->rtllib->SetFwCmdHandler)
 
471
                                        {
 
472
                                                priv->rtllib->SetFwCmdHandler(dev, FW_CMD_LPS_ENTER);
 
473
                                        } 
 
474
                                }       
 
475
                                MgntActSet_802_11_PowerSaveMode(dev, RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST);
 
476
 
 
477
                                /*if(pPSC->RegRfPsLevel & RT_RF_LPS_LEVEL_ASPM)
 
478
                                {
 
479
                                        RT_ENABLE_ASPM(pAdapter);
 
480
                                        RT_SET_PS_LEVEL(pAdapter, RT_RF_LPS_LEVEL_ASPM);
 
481
                                }*/
 
482
 
 
483
                        }       
 
484
                }
 
485
                else
 
486
                        pPSC->LpsIdleCount++;
 
487
        }       
 
488
}
 
489
 
 
490
 
 
491
void LeisurePSLeave(struct net_device *dev)
 
492
{
 
493
        struct r8192_priv *priv = rtllib_priv(dev);
 
494
        PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
495
 
 
496
 
 
497
        RT_TRACE(COMP_PS, "LeisurePSLeave()...\n");
 
498
        RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d\n", 
 
499
                pPSC->bLeisurePs, priv->rtllib->ps);
 
500
 
 
501
        if (pPSC->bLeisurePs)
 
502
        {       
 
503
                if(priv->rtllib->ps != RTLLIB_PS_DISABLED)
 
504
                {
 
505
#ifdef CONFIG_ASPM_OR_D3
 
506
                        if(pPSC->RegRfPsLevel & RT_RF_LPS_LEVEL_ASPM && RT_IN_PS_LEVEL(pPSC, RT_RF_LPS_LEVEL_ASPM))
 
507
                        {
 
508
                                RT_DISABLE_ASPM(dev);
 
509
                                RT_CLEAR_PS_LEVEL(pPSC, RT_RF_LPS_LEVEL_ASPM);
 
510
                        } 
 
511
#endif
 
512
                        RT_TRACE(COMP_LPS, "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n");
 
513
                        MgntActSet_802_11_PowerSaveMode(dev, RTLLIB_PS_DISABLED);
 
514
 
 
515
                        if(!pPSC->bFwCtrlLPS) 
 
516
                        {
 
517
                                if (priv->rtllib->SetFwCmdHandler)
 
518
                                {
 
519
                                        priv->rtllib->SetFwCmdHandler(dev, FW_CMD_LPS_LEAVE);
 
520
                                } 
 
521
                    }
 
522
                }
 
523
        }
 
524
}
 
525
#endif
 
526
 
 
527
#ifdef CONFIG_ASPM_OR_D3
 
528
bool PlatformSwitchDevicePciASPM(struct net_device *dev, u8 value)
 
529
{
 
530
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
531
        bool bResult = false;
 
532
 
 
533
        pci_write_config_byte(priv->pdev, priv->ASPMRegOffset, value);
 
534
        udelay(100);
 
535
 
 
536
        return bResult;
 
537
}
 
538
 
 
539
bool PlatformSwitchClkReq(struct net_device *dev, u8 value)
 
540
{
 
541
        bool bResult = false;
 
542
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
543
        u8      Buffer;
 
544
 
 
545
        Buffer= value;  
 
546
        
 
547
        pci_write_config_byte(priv->pdev,priv->ClkReqOffset,value);
 
548
        bResult = true;
 
549
#ifdef TODO
 
550
        if(Buffer) {
 
551
                priv->ClkReqState = true;
 
552
        } else {
 
553
                priv->ClkReqState = false;
 
554
        }
 
555
#endif
 
556
        udelay(100);
 
557
        return bResult;
 
558
}
 
559
 
 
560
void
 
561
PlatformDisableASPM(struct net_device *dev)
 
562
{
 
563
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
564
        PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
565
 
 
566
        u8      LinkCtrlReg;
 
567
        u16     PciBridgeLinkCtrlReg, ASPMLevel=0;
 
568
 
 
569
        LinkCtrlReg = priv->LinkCtrlReg;
 
570
        ASPMLevel |= BIT0|BIT1;
 
571
        LinkCtrlReg &=~ASPMLevel;
 
572
 
 
573
        PciBridgeLinkCtrlReg = priv->PciBridgeLinkCtrlReg;
 
574
        PciBridgeLinkCtrlReg &=~(BIT0|BIT1);
 
575
 
 
576
        if (priv->aspm_clkreq_enable) {
 
577
 
 
578
                pci_write_config_byte(priv->bridge_pdev,priv->PciBridgeASPMRegOffset,PciBridgeLinkCtrlReg);
 
579
                RT_TRACE(COMP_POWER, "Write reg[%x]=%x\n", (priv->PciBridgeASPMRegOffset), PciBridgeLinkCtrlReg);
 
580
                udelay(100);
 
581
        }
 
582
 
 
583
        PlatformSwitchDevicePciASPM(dev, priv->LinkCtrlReg);
 
584
 
 
585
        PlatformSwitchClkReq(dev, 0x0);
 
586
        if (pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_CLK_REQ)
 
587
                RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_CLK_REQ);
 
588
        udelay(100);
 
589
}
 
590
 
 
591
void PlatformEnableASPM(struct net_device *dev)
 
592
{
 
593
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
594
        PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
 
595
        u16     ASPMLevel = 0;
 
596
 
 
597
        if (!priv->aspm_clkreq_enable) {
 
598
                RT_TRACE(COMP_INIT, "%s: Fail to enable ASPM. Cannot find the Bus of PCI(Bridge).\n",\
 
599
                                __FUNCTION__);
 
600
                return;
 
601
        }
 
602
 
 
603
        ASPMLevel |= priv->RegDevicePciASPMSetting;
 
604
        PlatformSwitchDevicePciASPM(dev, (priv->LinkCtrlReg | ASPMLevel));
 
605
 
 
606
        if (pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_CLK_REQ) {
 
607
                PlatformSwitchClkReq(dev,(pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0);
 
608
                RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_CLK_REQ);
 
609
        }
 
610
        udelay(100);
 
611
 
 
612
        pci_write_config_byte(priv->bridge_pdev,priv->PciBridgeASPMRegOffset,\
 
613
                        ((priv->PciBridgeLinkCtrlReg | priv->RegHostPciASPMSetting)&~BIT0)&0xff);
 
614
        RT_TRACE(COMP_INIT, "Write reg[%x] = %x\n",
 
615
                priv->PciBridgeASPMRegOffset, 
 
616
                (priv->PciBridgeLinkCtrlReg|priv->RegHostPciASPMSetting));
 
617
        udelay(100);
 
618
}
 
619
 
 
620
u32 PlatformResetPciSpace(struct net_device *dev,u8 Value)
 
621
{
 
622
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
623
 
 
624
        pci_write_config_byte(priv->pdev,0x04,Value);   
 
625
 
 
626
        return 1;
 
627
        
 
628
}
 
629
bool PlatformSetPMCSR(struct net_device *dev,u8 value,bool bTempSetting)
 
630
{
 
631
        bool bResult = false;
 
632
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
633
        u8  Buffer;
 
634
        bool bActuallySet=false, bSetFunc=false;
 
635
        unsigned long flag;
 
636
 
 
637
        Buffer= value;
 
638
        spin_lock_irqsave(&priv->D3_lock,flag);
 
639
#ifdef TODO     
 
640
        if(bTempSetting) 
 
641
        {
 
642
                if(Buffer==0x00) 
 
643
                {
 
644
                        priv->LeaveD3Cnt++;
 
645
 
 
646
                        {
 
647
                                bActuallySet =true;
 
648
                        }
 
649
                }
 
650
                else 
 
651
                {
 
652
                        priv->LeaveD3Cnt--;
 
653
 
 
654
                        if(priv->LeaveD3Cnt == 0) 
 
655
                        {
 
656
                                bActuallySet=true;
 
657
                        }
 
658
                }
 
659
        }
 
660
        else
 
661
        {
 
662
                priv->LeaveD3Cnt=0;
 
663
                bActuallySet=true;
 
664
                bSetFunc=true;
 
665
        }
 
666
#endif
 
667
        if (bActuallySet) {
 
668
                if (Buffer) {
 
669
                        PlatformSwitchClkReq(dev, 0x01);
 
670
                } else {
 
671
                        PlatformSwitchClkReq(dev, 0x00);
 
672
                }
 
673
                
 
674
                pci_write_config_byte(priv->pdev,0x44,Buffer);
 
675
                RT_TRACE(COMP_POWER, "PlatformSetPMCSR(): D3(value: %d)\n", Buffer);
 
676
 
 
677
                bResult = true;
 
678
                if (!Buffer) {
 
679
                        PlatformResetPciSpace(dev, 0x06);
 
680
                        PlatformResetPciSpace(dev, 0x07);
 
681
                }
 
682
 
 
683
                if (bSetFunc) {
 
684
                        if(Buffer) 
 
685
                        {
 
686
#ifdef TO_DO_LIST
 
687
                                RT_DISABLE_FUNC(Adapter, DF_IO_D3_BIT);
 
688
#endif
 
689
                        } else {
 
690
#ifdef TO_DO_LIST
 
691
                                RT_ENABLE_FUNC(Adapter, DF_IO_D3_BIT);
 
692
#endif
 
693
                        }
 
694
                }
 
695
                
 
696
        }
 
697
        spin_unlock_irqrestore(&priv->D3_lock,flag);
 
698
        return bResult;
 
699
}
 
700
#endif