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.
21 * Purpose: Handles 802.11 power managment functions
28 * PSvEnablePowerSaving - Enable Power Saving Mode
29 * PSvDiasblePowerSaving - Disable Power Saving Mode
30 * PSbConsiderPowerDown - Decide if we can Power Down
31 * PSvSendPSPOLL - Send PS-POLL packet
32 * PSbSendNullPacket - Send Null packet
33 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
41 #if !defined(__TTYPE_H__)
44 #if !defined(__TBIT_H__)
47 #if !defined(__MAC_H__)
50 #if !defined(__DEVICE_H__)
53 #if !defined(__WMGR_H__)
56 #if !defined(__POWER_H__)
59 #if !defined(__WCMD_H__)
62 #if !defined(__TBIT_H__)
65 #if !defined(__UMEM_H__)
68 #if !defined(__RXTX_H__)
71 #if !defined(__CARD_H__)
78 /*--------------------- Static Definitions -------------------------*/
83 /*--------------------- Static Classes ----------------------------*/
85 /*--------------------- Static Variables --------------------------*/
86 static int msglevel =MSG_LEVEL_INFO;
87 /*--------------------- Static Functions --------------------------*/
90 /*--------------------- Export Variables --------------------------*/
93 /*--------------------- Export Functions --------------------------*/
97 * Routine Description:
98 * Enable hw power saving functions
107 PSvEnablePowerSaving(
108 IN HANDLE hDeviceContext,
109 IN WORD wListenInterval
112 PSDevice pDevice = (PSDevice)hDeviceContext;
113 PSMgmtObject pMgmt = pDevice->pMgmt;
114 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
116 // set period of power up before TBTT
117 VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
118 if (pDevice->eOPMode != OP_MODE_ADHOC) {
120 VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
123 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
126 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
128 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
130 if (wListenInterval >= 2) {
131 // clear always listen beacon
132 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
133 //pDevice->wCFG &= ~CFG_ALB;
134 // first time set listen next beacon
135 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
136 pMgmt->wCountToWakeUp = wListenInterval;
139 // always listen beacon
140 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
141 //pDevice->wCFG |= CFG_ALB;
142 pMgmt->wCountToWakeUp = 0;
145 // enable power saving hw function
146 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
147 pDevice->bEnablePSMode = TRUE;
149 if (pDevice->eOPMode == OP_MODE_ADHOC) {
150 // bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt);
152 // We don't send null pkt in ad hoc mode since beacon will handle this.
153 else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
154 PSbSendNullPacket(pDevice);
156 pDevice->bPWBitOn = TRUE;
157 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
168 * Routine Description:
169 * Disable hw power saving functions
177 PSvDisablePowerSaving(
178 IN HANDLE hDeviceContext
181 PSDevice pDevice = (PSDevice)hDeviceContext;
182 // PSMgmtObject pMgmt = pDevice->pMgmt;
184 // disable power saving hw function
185 MACbPSWakeup(pDevice->PortOffset);
187 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
189 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
190 // set always listen beacon
191 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
193 pDevice->bEnablePSMode = FALSE;
195 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
196 PSbSendNullPacket(pDevice);
198 pDevice->bPWBitOn = FALSE;
205 * Routine Description:
206 * Consider to power down when no more packets to tx or rx.
209 * TRUE, if power down success
215 PSbConsiderPowerDown(
216 IN HANDLE hDeviceContext,
218 IN BOOL bCheckCountToWakeUp
221 PSDevice pDevice = (PSDevice)hDeviceContext;
222 PSMgmtObject pMgmt = pDevice->pMgmt;
225 // check if already in Doze mode
226 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
229 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
230 // check if in TIM wake period
231 if (pMgmt->bInTIMWake)
236 if (pDevice->bCmdRunning)
240 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
242 // check if all TD are empty,
243 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
244 if (pDevice->iTDUsed[uIdx] != 0)
248 // check if rx isr is clear
250 ((pDevice->dwIsr& ISR_RXDMA0) != 0) &&
251 ((pDevice->dwIsr & ISR_RXDMA1) != 0)){
255 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
256 if (bCheckCountToWakeUp &&
257 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
262 // no Tx, no Rx isr, now go to Doze
263 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
264 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
272 * Routine Description:
273 * Send PS-POLL packet
284 IN HANDLE hDeviceContext
287 PSDevice pDevice = (PSDevice)hDeviceContext;
288 PSMgmtObject pMgmt = pDevice->pMgmt;
289 PSTxMgmtPacket pTxPacket = NULL;
292 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
293 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
294 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
295 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
297 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
298 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
299 WLAN_SET_FC_PWRMGT(0)
301 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
302 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
303 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
304 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
305 pTxPacket->cbPayloadLen = 0;
307 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
308 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
311 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
321 * Routine Description:
322 * Send NULL packet to AP for notification power state of STA
330 IN HANDLE hDeviceContext
333 PSDevice pDevice = (PSDevice)hDeviceContext;
334 PSTxMgmtPacket pTxPacket = NULL;
335 PSMgmtObject pMgmt = pDevice->pMgmt;
339 if (pDevice->bLinkPass == FALSE) {
343 if ((pDevice->bEnablePSMode == FALSE) &&
344 (pDevice->fTxDataInSleep == FALSE)){
348 if (pDevice->bEnablePSMode == FALSE) {
352 if (pDevice->bEnablePSMode) {
353 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
354 if (pDevice->iTDUsed[uIdx] != 0)
359 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
360 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
361 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
363 if (pDevice->bEnablePSMode) {
365 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
367 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
368 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
369 WLAN_SET_FC_PWRMGT(1)
373 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
375 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
376 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
377 WLAN_SET_FC_PWRMGT(0)
381 if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
382 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
385 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
386 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
387 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
388 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
389 pTxPacket->cbPayloadLen = 0;
391 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
392 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
397 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
406 * Routine Description:
407 * Check if Next TBTT must wake up
416 IN HANDLE hDeviceContext
420 PSDevice pDevice = (PSDevice)hDeviceContext;
421 PSMgmtObject pMgmt = pDevice->pMgmt;
422 BOOL bWakeUp = FALSE;
424 if (pMgmt->wListenInterval >= 2) {
425 if (pMgmt->wCountToWakeUp == 0) {
426 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
429 pMgmt->wCountToWakeUp --;
431 if (pMgmt->wCountToWakeUp == 1) {
432 // Turn on wake up to listen next beacon
433 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);