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 -------------------------*/
51 /*--------------------- Static Classes ----------------------------*/
53 /*--------------------- Static Variables --------------------------*/
54 static int msglevel
= MSG_LEVEL_INFO
;
55 /*--------------------- Static Functions --------------------------*/
57 /*--------------------- Export Variables --------------------------*/
59 /*--------------------- Export Functions --------------------------*/
63 * Routine Description:
64 * Enable hw power saving functions
74 unsigned short wListenInterval
77 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
78 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
79 unsigned short wAID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
81 // set period of power up before TBTT
82 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_PWBT
, C_PWBT
);
83 if (pDevice
->eOPMode
!= OP_MODE_ADHOC
) {
85 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_AIDATIM
, wAID
);
88 MACvWriteATIMW(pDevice
->PortOffset
, pMgmt
->wCurrATIMWindow
);
91 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
93 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_HWUTSF
);
95 if (wListenInterval
>= 2) {
96 // clear always listen beacon
97 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
98 //pDevice->wCFG &= ~CFG_ALB;
99 // first time set listen next beacon
100 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
101 pMgmt
->wCountToWakeUp
= wListenInterval
;
103 // always listen beacon
104 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
105 //pDevice->wCFG |= CFG_ALB;
106 pMgmt
->wCountToWakeUp
= 0;
109 // enable power saving hw function
110 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
111 pDevice
->bEnablePSMode
= true;
113 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
114 // bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
116 // We don't send null pkt in ad hoc mode since beacon will handle this.
117 else if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
118 PSbSendNullPacket(pDevice
);
120 pDevice
->bPWBitOn
= true;
121 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PS:Power Saving Mode Enable... \n");
127 * Routine Description:
128 * Disable hw power saving functions
136 PSvDisablePowerSaving(
140 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
141 // PSMgmtObject pMgmt = pDevice->pMgmt;
143 // disable power saving hw function
144 MACbPSWakeup(pDevice
->PortOffset
);
146 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
148 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_HWUTSF
);
149 // set always listen beacon
150 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
152 pDevice
->bEnablePSMode
= false;
154 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
155 PSbSendNullPacket(pDevice
);
157 pDevice
->bPWBitOn
= false;
163 * Routine Description:
164 * Consider to power down when no more packets to tx or rx.
167 * true, if power down success
172 PSbConsiderPowerDown(
173 void *hDeviceContext
,
175 bool bCheckCountToWakeUp
178 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
179 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
182 // check if already in Doze mode
183 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
))
186 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
187 // check if in TIM wake period
188 if (pMgmt
->bInTIMWake
)
193 if (pDevice
->bCmdRunning
)
197 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
199 // check if all TD are empty,
200 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
201 if (pDevice
->iTDUsed
[uIdx
] != 0)
205 // check if rx isr is clear
207 ((pDevice
->dwIsr
& ISR_RXDMA0
) != 0) &&
208 ((pDevice
->dwIsr
& ISR_RXDMA1
) != 0)) {
212 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
213 if (bCheckCountToWakeUp
&&
214 (pMgmt
->wCountToWakeUp
== 0 || pMgmt
->wCountToWakeUp
== 1)) {
219 // no Tx, no Rx isr, now go to Doze
220 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
221 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
227 * Routine Description:
228 * Send PS-POLL packet
240 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
241 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
242 PSTxMgmtPacket pTxPacket
= NULL
;
244 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(STxMgmtPacket
) + WLAN_HDR_ADDR2_LEN
);
245 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyPSPacketPool
;
246 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((unsigned char *)pTxPacket
+ sizeof(STxMgmtPacket
));
247 pTxPacket
->p80211Header
->sA2
.wFrameCtl
= cpu_to_le16(
249 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL
) |
250 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL
) |
251 WLAN_SET_FC_PWRMGT(0)
253 pTxPacket
->p80211Header
->sA2
.wDurationID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
254 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
255 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
256 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR2_LEN
;
257 pTxPacket
->cbPayloadLen
= 0;
259 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
260 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send PS-Poll packet failed..\n");
262 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
270 * Routine Description:
271 * Send NULL packet to AP for notification power state of STA
282 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
283 PSTxMgmtPacket pTxPacket
= NULL
;
284 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
287 if (pDevice
->bLinkPass
== false) {
291 if ((pDevice
->bEnablePSMode
== false) &&
292 (pDevice
->fTxDataInSleep
== false)) {
296 if (pDevice
->bEnablePSMode
== false) {
300 if (pDevice
->bEnablePSMode
) {
301 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
302 if (pDevice
->iTDUsed
[uIdx
] != 0)
307 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(STxMgmtPacket
) + WLAN_NULLDATA_FR_MAXLEN
);
308 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyPSPacketPool
;
309 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((unsigned char *)pTxPacket
+ sizeof(STxMgmtPacket
));
311 if (pDevice
->bEnablePSMode
) {
312 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(
314 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
315 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
) |
316 WLAN_SET_FC_PWRMGT(1)
319 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(
321 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
322 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
) |
323 WLAN_SET_FC_PWRMGT(0)
327 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
328 pTxPacket
->p80211Header
->sA3
.wFrameCtl
|= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1));
331 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
332 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
333 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr3
, pMgmt
->abyCurrBSSID
, WLAN_BSSID_LEN
);
334 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR3_LEN
;
335 pTxPacket
->cbPayloadLen
= 0;
337 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
338 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send Null Packet failed !\n");
341 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
349 * Routine Description:
350 * Check if Next TBTT must wake up
362 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
363 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
364 bool bWakeUp
= false;
366 if (pMgmt
->wListenInterval
>= 2) {
367 if (pMgmt
->wCountToWakeUp
== 0) {
368 pMgmt
->wCountToWakeUp
= pMgmt
->wListenInterval
;
371 pMgmt
->wCountToWakeUp
--;
373 if (pMgmt
->wCountToWakeUp
== 1) {
374 // Turn on wake up to listen next beacon
375 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_LNBCN
);