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
50 static int msglevel
= MSG_LEVEL_INFO
;
54 * Routine Description:
55 * Enable hw power saving functions
62 void PSvEnablePowerSaving(struct vnt_private
*pDevice
, u16 wListenInterval
)
64 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
65 u16 wAID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
67 /* set period of power up before TBTT */
68 MACvWriteWord(pDevice
, MAC_REG_PWBT
, C_PWBT
);
70 if (pDevice
->eOPMode
!= OP_MODE_ADHOC
) {
72 MACvWriteWord(pDevice
, MAC_REG_AIDATIM
, wAID
);
75 /* MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); */
78 /* Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE */
79 /* enable power saving hw function */
80 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_PSEN
);
83 MACvRegBitsOn(pDevice
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
85 /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work */
86 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
88 if (wListenInterval
>= 2) {
90 /* clear always listen beacon */
91 MACvRegBitsOff(pDevice
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
93 /* first time set listen next beacon */
94 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
96 pMgmt
->wCountToWakeUp
= wListenInterval
;
100 /* always listen beacon */
101 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
103 pMgmt
->wCountToWakeUp
= 0;
106 pDevice
->bEnablePSMode
= true;
108 /* We don't send null pkt in ad hoc mode since beacon will handle this. */
109 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
)
110 PSbSendNullPacket(pDevice
);
112 pDevice
->bPWBitOn
= true;
113 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PS:Power Saving Mode Enable...\n");
118 * Routine Description:
119 * Disable hw power saving functions
126 void PSvDisablePowerSaving(struct vnt_private
*pDevice
)
129 /* disable power saving hw function */
130 CONTROLnsRequestOut(pDevice
, MESSAGE_TYPE_DISABLE_PS
, 0,
133 /* clear AutoSleep */
134 MACvRegBitsOff(pDevice
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
136 /* set always listen beacon */
137 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
138 pDevice
->bEnablePSMode
= false;
140 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
)
141 PSbSendNullPacket(pDevice
);
143 pDevice
->bPWBitOn
= false;
148 * Routine Description:
149 * Consider to power down when no more packets to tx or rx.
152 * true, if power down success
156 int PSbConsiderPowerDown(struct vnt_private
*pDevice
, int bCheckRxDMA
,
157 int bCheckCountToWakeUp
)
159 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
162 /* check if already in Doze mode */
163 ControlvReadByte(pDevice
, MESSAGE_REQUEST_MACREG
,
164 MAC_REG_PSCTL
, &byData
);
166 if ((byData
& PSCTL_PS
) != 0)
169 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
170 /* check if in TIM wake period */
171 if (pMgmt
->bInTIMWake
)
175 /* check scan state */
176 if (pDevice
->bCmdRunning
)
180 if (pDevice
->bPSModeTxBurst
)
184 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_PSEN
);
186 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
187 if (bCheckCountToWakeUp
&& (pMgmt
->wCountToWakeUp
== 0
188 || pMgmt
->wCountToWakeUp
== 1)) {
193 pDevice
->bPSRxBeacon
= true;
195 /* no Tx, no Rx isr, now go to Doze */
196 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
197 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
203 * Routine Description:
204 * Send PS-POLL packet
211 void PSvSendPSPOLL(struct vnt_private
*pDevice
)
213 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
214 struct vnt_tx_mgmt
*pTxPacket
= NULL
;
216 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(struct vnt_tx_mgmt
)
217 + WLAN_HDR_ADDR2_LEN
);
218 pTxPacket
= (struct vnt_tx_mgmt
*)pMgmt
->pbyPSPacketPool
;
219 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((u8
*)pTxPacket
220 + sizeof(struct vnt_tx_mgmt
));
222 pTxPacket
->p80211Header
->sA2
.wFrameCtl
= cpu_to_le16(
224 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL
) |
225 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL
) |
226 WLAN_SET_FC_PWRMGT(0)
229 pTxPacket
->p80211Header
->sA2
.wDurationID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
230 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
231 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
232 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR2_LEN
;
233 pTxPacket
->cbPayloadLen
= 0;
235 /* log failure if sending failed */
236 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
237 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send PS-Poll packet failed..\n");
243 * Routine Description:
244 * Send NULL packet to AP for notification power state of STA
251 int PSbSendNullPacket(struct vnt_private
*pDevice
)
253 struct vnt_tx_mgmt
*pTxPacket
= NULL
;
254 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
257 if (pDevice
->bLinkPass
== false)
260 if ((pDevice
->bEnablePSMode
== false) &&
261 (pDevice
->fTxDataInSleep
== false)) {
265 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(struct vnt_tx_mgmt
)
266 + WLAN_NULLDATA_FR_MAXLEN
);
267 pTxPacket
= (struct vnt_tx_mgmt
*)pMgmt
->pbyPSPacketPool
;
268 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((u8
*)pTxPacket
269 + sizeof(struct vnt_tx_mgmt
));
271 flags
= WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
272 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
);
274 if (pDevice
->bEnablePSMode
)
275 flags
|= WLAN_SET_FC_PWRMGT(1);
277 flags
|= WLAN_SET_FC_PWRMGT(0);
279 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(flags
);
281 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
)
282 pTxPacket
->p80211Header
->sA3
.wFrameCtl
|= cpu_to_le16((u16
)WLAN_SET_FC_TODS(1));
284 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
285 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
286 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr3
, pMgmt
->abyCurrBSSID
, WLAN_BSSID_LEN
);
287 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR3_LEN
;
288 pTxPacket
->cbPayloadLen
= 0;
289 /* log error if sending failed */
290 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
291 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send Null Packet failed !\n");
299 * Routine Description:
300 * Check if Next TBTT must wake up
307 int PSbIsNextTBTTWakeUp(struct vnt_private
*pDevice
)
309 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
312 if (pMgmt
->wListenInterval
>= 2) {
313 if (pMgmt
->wCountToWakeUp
== 0)
314 pMgmt
->wCountToWakeUp
= pMgmt
->wListenInterval
;
316 pMgmt
->wCountToWakeUp
--;
318 if (pMgmt
->wCountToWakeUp
== 1) {
319 /* Turn on wake up to listen next beacon */
320 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
321 pDevice
->bPSRxBeacon
= false;
323 } else if (!pDevice
->bPSRxBeacon
) {
324 /* Listen until RxBeacon */
325 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_LNBCN
);