2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: Handles 802.11 power management functions
29 * PSvEnablePowerSaving - Enable Power Saving Mode
30 * PSvDiasblePowerSaving - Disable Power Saving Mode
31 * PSbConsiderPowerDown - Decide if we can Power Down
32 * PSvSendPSPOLL - Send PS-POLL packet
33 * PSbSendNullPacket - Send Null packet
34 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
42 #if !defined(__TTYPE_H__)
45 #if !defined(__TBIT_H__)
48 #if !defined(__MAC_H__)
51 #if !defined(__DEVICE_H__)
54 #if !defined(__WMGR_H__)
57 #if !defined(__POWER_H__)
60 #if !defined(__WCMD_H__)
63 #if !defined(__TBIT_H__)
66 #if !defined(__UMEM_H__)
69 #if !defined(__RXTX_H__)
72 #if !defined(__CARD_H__)
79 /*--------------------- Static Definitions -------------------------*/
84 /*--------------------- Static Classes ----------------------------*/
86 /*--------------------- Static Variables --------------------------*/
87 static int msglevel
=MSG_LEVEL_INFO
;
88 /*--------------------- Static Functions --------------------------*/
91 /*--------------------- Export Variables --------------------------*/
94 /*--------------------- Export Functions --------------------------*/
98 * Routine Description:
99 * Enable hw power saving functions
108 PSvEnablePowerSaving(
109 IN HANDLE hDeviceContext
,
110 IN WORD wListenInterval
113 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
114 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
115 WORD wAID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
117 // set period of power up before TBTT
118 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_PWBT
, C_PWBT
);
119 if (pDevice
->eOPMode
!= OP_MODE_ADHOC
) {
121 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_AIDATIM
, wAID
);
124 MACvWriteATIMW(pDevice
->PortOffset
, pMgmt
->wCurrATIMWindow
);
127 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
129 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_HWUTSF
);
131 if (wListenInterval
>= 2) {
132 // clear always listen beacon
133 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
134 //pDevice->wCFG &= ~CFG_ALB;
135 // first time set listen next beacon
136 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
137 pMgmt
->wCountToWakeUp
= wListenInterval
;
140 // always listen beacon
141 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
142 //pDevice->wCFG |= CFG_ALB;
143 pMgmt
->wCountToWakeUp
= 0;
146 // enable power saving hw function
147 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
148 pDevice
->bEnablePSMode
= TRUE
;
150 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
151 // bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt);
153 // We don't send null pkt in ad hoc mode since beacon will handle this.
154 else if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
155 PSbSendNullPacket(pDevice
);
157 pDevice
->bPWBitOn
= TRUE
;
158 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PS:Power Saving Mode Enable... \n");
169 * Routine Description:
170 * Disable hw power saving functions
178 PSvDisablePowerSaving(
179 IN HANDLE hDeviceContext
182 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
183 // PSMgmtObject pMgmt = pDevice->pMgmt;
185 // disable power saving hw function
186 MACbPSWakeup(pDevice
->PortOffset
);
188 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
190 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_HWUTSF
);
191 // set always listen beacon
192 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
194 pDevice
->bEnablePSMode
= FALSE
;
196 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
197 PSbSendNullPacket(pDevice
);
199 pDevice
->bPWBitOn
= FALSE
;
206 * Routine Description:
207 * Consider to power down when no more packets to tx or rx.
210 * TRUE, if power down success
216 PSbConsiderPowerDown(
217 IN HANDLE hDeviceContext
,
219 IN BOOL bCheckCountToWakeUp
222 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
223 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
226 // check if already in Doze mode
227 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
))
230 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
231 // check if in TIM wake period
232 if (pMgmt
->bInTIMWake
)
237 if (pDevice
->bCmdRunning
)
241 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
243 // check if all TD are empty,
244 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
245 if (pDevice
->iTDUsed
[uIdx
] != 0)
249 // check if rx isr is clear
251 ((pDevice
->dwIsr
& ISR_RXDMA0
) != 0) &&
252 ((pDevice
->dwIsr
& ISR_RXDMA1
) != 0)){
256 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
257 if (bCheckCountToWakeUp
&&
258 (pMgmt
->wCountToWakeUp
== 0 || pMgmt
->wCountToWakeUp
== 1)) {
263 // no Tx, no Rx isr, now go to Doze
264 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
265 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
273 * Routine Description:
274 * Send PS-POLL packet
285 IN HANDLE hDeviceContext
288 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
289 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
290 PSTxMgmtPacket pTxPacket
= NULL
;
293 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(STxMgmtPacket
) + WLAN_HDR_ADDR2_LEN
);
294 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyPSPacketPool
;
295 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((PBYTE
)pTxPacket
+ sizeof(STxMgmtPacket
));
296 pTxPacket
->p80211Header
->sA2
.wFrameCtl
= cpu_to_le16(
298 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL
) |
299 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL
) |
300 WLAN_SET_FC_PWRMGT(0)
302 pTxPacket
->p80211Header
->sA2
.wDurationID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
303 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
304 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
305 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR2_LEN
;
306 pTxPacket
->cbPayloadLen
= 0;
308 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
309 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send PS-Poll packet failed..\n");
312 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
322 * Routine Description:
323 * Send NULL packet to AP for notification power state of STA
331 IN HANDLE hDeviceContext
334 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
335 PSTxMgmtPacket pTxPacket
= NULL
;
336 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
340 if (pDevice
->bLinkPass
== FALSE
) {
344 if ((pDevice
->bEnablePSMode
== FALSE
) &&
345 (pDevice
->fTxDataInSleep
== FALSE
)){
349 if (pDevice
->bEnablePSMode
== FALSE
) {
353 if (pDevice
->bEnablePSMode
) {
354 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
355 if (pDevice
->iTDUsed
[uIdx
] != 0)
360 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(STxMgmtPacket
) + WLAN_NULLDATA_FR_MAXLEN
);
361 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyPSPacketPool
;
362 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((PBYTE
)pTxPacket
+ sizeof(STxMgmtPacket
));
364 if (pDevice
->bEnablePSMode
) {
366 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(
368 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
369 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
) |
370 WLAN_SET_FC_PWRMGT(1)
374 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(
376 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
377 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
) |
378 WLAN_SET_FC_PWRMGT(0)
382 if(pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
383 pTxPacket
->p80211Header
->sA3
.wFrameCtl
|= cpu_to_le16((WORD
)WLAN_SET_FC_TODS(1));
386 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
387 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
388 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr3
, pMgmt
->abyCurrBSSID
, WLAN_BSSID_LEN
);
389 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR3_LEN
;
390 pTxPacket
->cbPayloadLen
= 0;
392 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
393 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send Null Packet failed !\n");
398 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
407 * Routine Description:
408 * Check if Next TBTT must wake up
417 IN HANDLE hDeviceContext
421 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
422 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
423 BOOL bWakeUp
= FALSE
;
425 if (pMgmt
->wListenInterval
>= 2) {
426 if (pMgmt
->wCountToWakeUp
== 0) {
427 pMgmt
->wCountToWakeUp
= pMgmt
->wListenInterval
;
430 pMgmt
->wCountToWakeUp
--;
432 if (pMgmt
->wCountToWakeUp
== 1) {
433 // Turn on wake up to listen next beacon
434 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_LNBCN
);