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
49 /*--------------------- Static Definitions -------------------------*/
54 /*--------------------- Static Classes ----------------------------*/
56 /*--------------------- Static Variables --------------------------*/
57 static int msglevel
=MSG_LEVEL_INFO
;
58 /*--------------------- Static Functions --------------------------*/
61 /*--------------------- Export Variables --------------------------*/
64 /*--------------------- Export Functions --------------------------*/
68 * Routine Description:
69 * Enable hw power saving functions
80 unsigned short wListenInterval
83 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
84 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
85 unsigned short wAID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
87 // set period of power up before TBTT
88 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_PWBT
, C_PWBT
);
89 if (pDevice
->eOPMode
!= OP_MODE_ADHOC
) {
91 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_AIDATIM
, wAID
);
94 MACvWriteATIMW(pDevice
->PortOffset
, pMgmt
->wCurrATIMWindow
);
97 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
99 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_HWUTSF
);
101 if (wListenInterval
>= 2) {
102 // clear always listen beacon
103 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
104 //pDevice->wCFG &= ~CFG_ALB;
105 // first time set listen next beacon
106 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
107 pMgmt
->wCountToWakeUp
= wListenInterval
;
110 // always listen beacon
111 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
112 //pDevice->wCFG |= CFG_ALB;
113 pMgmt
->wCountToWakeUp
= 0;
116 // enable power saving hw function
117 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
118 pDevice
->bEnablePSMode
= true;
120 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
121 // bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
123 // We don't send null pkt in ad hoc mode since beacon will handle this.
124 else if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
125 PSbSendNullPacket(pDevice
);
127 pDevice
->bPWBitOn
= true;
128 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PS:Power Saving Mode Enable... \n");
139 * Routine Description:
140 * Disable hw power saving functions
148 PSvDisablePowerSaving(
152 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
153 // PSMgmtObject pMgmt = pDevice->pMgmt;
155 // disable power saving hw function
156 MACbPSWakeup(pDevice
->PortOffset
);
158 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
160 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_HWUTSF
);
161 // set always listen beacon
162 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
164 pDevice
->bEnablePSMode
= false;
166 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
167 PSbSendNullPacket(pDevice
);
169 pDevice
->bPWBitOn
= false;
176 * Routine Description:
177 * Consider to power down when no more packets to tx or rx.
180 * true, if power down success
186 PSbConsiderPowerDown(
187 void *hDeviceContext
,
189 bool bCheckCountToWakeUp
192 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
193 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
196 // check if already in Doze mode
197 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
))
200 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
201 // check if in TIM wake period
202 if (pMgmt
->bInTIMWake
)
207 if (pDevice
->bCmdRunning
)
211 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
213 // check if all TD are empty,
214 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
215 if (pDevice
->iTDUsed
[uIdx
] != 0)
219 // check if rx isr is clear
221 ((pDevice
->dwIsr
& ISR_RXDMA0
) != 0) &&
222 ((pDevice
->dwIsr
& ISR_RXDMA1
) != 0)){
226 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
227 if (bCheckCountToWakeUp
&&
228 (pMgmt
->wCountToWakeUp
== 0 || pMgmt
->wCountToWakeUp
== 1)) {
233 // no Tx, no Rx isr, now go to Doze
234 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
235 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
243 * Routine Description:
244 * Send PS-POLL packet
258 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
259 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
260 PSTxMgmtPacket pTxPacket
= NULL
;
263 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(STxMgmtPacket
) + WLAN_HDR_ADDR2_LEN
);
264 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyPSPacketPool
;
265 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((unsigned char *)pTxPacket
+ sizeof(STxMgmtPacket
));
266 pTxPacket
->p80211Header
->sA2
.wFrameCtl
= cpu_to_le16(
268 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL
) |
269 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL
) |
270 WLAN_SET_FC_PWRMGT(0)
272 pTxPacket
->p80211Header
->sA2
.wDurationID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
273 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
274 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
275 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR2_LEN
;
276 pTxPacket
->cbPayloadLen
= 0;
278 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
279 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send PS-Poll packet failed..\n");
282 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
292 * Routine Description:
293 * Send NULL packet to AP for notification power state of STA
304 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
305 PSTxMgmtPacket pTxPacket
= NULL
;
306 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
310 if (pDevice
->bLinkPass
== false) {
314 if ((pDevice
->bEnablePSMode
== false) &&
315 (pDevice
->fTxDataInSleep
== false)){
319 if (pDevice
->bEnablePSMode
== false) {
323 if (pDevice
->bEnablePSMode
) {
324 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
325 if (pDevice
->iTDUsed
[uIdx
] != 0)
330 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(STxMgmtPacket
) + WLAN_NULLDATA_FR_MAXLEN
);
331 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyPSPacketPool
;
332 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((unsigned char *)pTxPacket
+ sizeof(STxMgmtPacket
));
334 if (pDevice
->bEnablePSMode
) {
336 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(
338 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
339 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
) |
340 WLAN_SET_FC_PWRMGT(1)
344 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(
346 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
347 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
) |
348 WLAN_SET_FC_PWRMGT(0)
352 if(pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
353 pTxPacket
->p80211Header
->sA3
.wFrameCtl
|= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1));
356 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
357 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
358 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr3
, pMgmt
->abyCurrBSSID
, WLAN_BSSID_LEN
);
359 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR3_LEN
;
360 pTxPacket
->cbPayloadLen
= 0;
362 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
363 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send Null Packet failed !\n");
368 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
377 * Routine Description:
378 * Check if Next TBTT must wake up
391 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
392 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
393 bool bWakeUp
= false;
395 if (pMgmt
->wListenInterval
>= 2) {
396 if (pMgmt
->wCountToWakeUp
== 0) {
397 pMgmt
->wCountToWakeUp
= pMgmt
->wListenInterval
;
400 pMgmt
->wCountToWakeUp
--;
402 if (pMgmt
->wCountToWakeUp
== 1) {
403 // Turn on wake up to listen next beacon
404 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_LNBCN
);