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 Functions --------------------------*/
55 /*--------------------- Export Variables --------------------------*/
57 /*--------------------- Export Functions --------------------------*/
61 * Routine Description:
62 * Enable hw power saving functions
72 unsigned short wListenInterval
75 struct vnt_private *pDevice = hDeviceContext;
76 PSMgmtObject pMgmt = pDevice->pMgmt;
77 unsigned short wAID = pMgmt->wCurrAID | BIT14 | BIT15;
79 // set period of power up before TBTT
80 VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
81 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
83 VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
86 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
89 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
91 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
93 if (wListenInterval >= 2) {
94 // clear always listen beacon
95 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
96 // first time set listen next beacon
97 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
98 pMgmt->wCountToWakeUp = wListenInterval;
100 // always listen beacon
101 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
102 pMgmt->wCountToWakeUp = 0;
105 // enable power saving hw function
106 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
107 pDevice->bEnablePSMode = true;
109 /* We don't send null pkt in ad hoc mode since beacon will handle this. */
110 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC &&
111 pDevice->op_mode == NL80211_IFTYPE_STATION)
112 PSbSendNullPacket(pDevice);
114 pDevice->bPWBitOn = true;
115 pr_debug("PS:Power Saving Mode Enable...\n");
120 * Routine Description:
121 * Disable hw power saving functions
129 PSvDisablePowerSaving(
133 struct vnt_private *pDevice = hDeviceContext;
135 // disable power saving hw function
136 MACbPSWakeup(pDevice->PortOffset);
138 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
140 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
141 // set always listen beacon
142 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
144 pDevice->bEnablePSMode = false;
146 if (pDevice->op_mode == NL80211_IFTYPE_STATION)
147 PSbSendNullPacket(pDevice);
149 pDevice->bPWBitOn = false;
154 * Routine Description:
155 * Consider to power down when no more packets to tx or rx.
158 * true, if power down success
163 PSbConsiderPowerDown(
164 void *hDeviceContext,
166 bool bCheckCountToWakeUp
169 struct vnt_private *pDevice = hDeviceContext;
170 PSMgmtObject pMgmt = pDevice->pMgmt;
173 // check if already in Doze mode
174 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
177 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
178 // check if in TIM wake period
179 if (pMgmt->bInTIMWake)
184 if (pDevice->bCmdRunning)
188 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
190 // check if all TD are empty,
191 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
192 if (pDevice->iTDUsed[uIdx] != 0)
196 // check if rx isr is clear
198 ((pDevice->dwIsr & ISR_RXDMA0) != 0) &&
199 ((pDevice->dwIsr & ISR_RXDMA1) != 0)) {
203 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
204 if (bCheckCountToWakeUp &&
205 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
210 // no Tx, no Rx isr, now go to Doze
211 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
212 pr_debug("Go to Doze ZZZZZZZZZZZZZZZ\n");
218 * Routine Description:
219 * Send PS-POLL packet
231 struct vnt_private *pDevice = hDeviceContext;
232 PSMgmtObject pMgmt = pDevice->pMgmt;
233 PSTxMgmtPacket pTxPacket = NULL;
235 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
236 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
237 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
238 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
240 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
241 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
242 WLAN_SET_FC_PWRMGT(0)
244 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
245 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
246 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
247 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
248 pTxPacket->cbPayloadLen = 0;
250 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
251 pr_debug("Send PS-Poll packet failed..\n");
256 * Routine Description:
257 * Send NULL packet to AP for notification power state of STA
268 struct vnt_private *pDevice = hDeviceContext;
269 PSTxMgmtPacket pTxPacket = NULL;
270 PSMgmtObject pMgmt = pDevice->pMgmt;
273 if (!pDevice->bLinkPass)
276 if (!pDevice->bEnablePSMode && !pDevice->fTxDataInSleep)
279 if (pDevice->bEnablePSMode) {
280 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
281 if (pDevice->iTDUsed[uIdx] != 0)
286 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
287 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
288 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
290 if (pDevice->bEnablePSMode) {
291 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
293 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
294 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
295 WLAN_SET_FC_PWRMGT(1)
298 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
300 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
301 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
302 WLAN_SET_FC_PWRMGT(0)
306 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA)
307 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1));
309 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
310 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
311 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
312 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
313 pTxPacket->cbPayloadLen = 0;
315 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
316 pr_debug("Send Null Packet failed !\n");
325 * Routine Description:
326 * Check if Next TBTT must wake up
338 struct vnt_private *pDevice = hDeviceContext;
339 PSMgmtObject pMgmt = pDevice->pMgmt;
340 bool bWakeUp = false;
342 if (pMgmt->wListenInterval >= 2) {
343 if (pMgmt->wCountToWakeUp == 0)
344 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
346 pMgmt->wCountToWakeUp--;
348 if (pMgmt->wCountToWakeUp == 1) {
349 // Turn on wake up to listen next beacon
350 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);