Commit | Line | Data |
---|---|---|
92b96797 FB |
1 | /* |
2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. | |
3 | * All rights reserved. | |
4 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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. | |
18 | * | |
19 | * | |
20 | * File: power.c | |
21 | * | |
a0a1f61a | 22 | * Purpose: Handles 802.11 power management functions |
92b96797 FB |
23 | * |
24 | * Author: Lyndon Chen | |
25 | * | |
26 | * Date: July 17, 2002 | |
27 | * | |
28 | * 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 | |
35 | * | |
36 | * Revision History: | |
37 | * | |
38 | */ | |
39 | ||
92b96797 | 40 | #include "mac.h" |
92b96797 | 41 | #include "device.h" |
92b96797 | 42 | #include "wmgr.h" |
92b96797 | 43 | #include "power.h" |
92b96797 | 44 | #include "wcmd.h" |
92b96797 | 45 | #include "rxtx.h" |
92b96797 | 46 | #include "card.h" |
62c8526d | 47 | #include "usbpipe.h" |
92b96797 | 48 | |
f9cfbe94 | 49 | static int msglevel = MSG_LEVEL_INFO; |
92b96797 | 50 | |
7404eab2 | 51 | /* |
92b96797 FB |
52 | * |
53 | * Routine Description: | |
54 | * Enable hw power saving functions | |
55 | * | |
56 | * Return Value: | |
57 | * None. | |
58 | * | |
7404eab2 | 59 | */ |
92b96797 | 60 | |
45c73bb1 | 61 | void PSvEnablePowerSaving(struct vnt_private *pDevice, u16 wListenInterval) |
92b96797 | 62 | { |
45c73bb1 MP |
63 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
64 | u16 wAID = pMgmt->wCurrAID | BIT14 | BIT15; | |
92b96797 | 65 | |
f9cfbe94 PW |
66 | /* set period of power up before TBTT */ |
67 | MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT); | |
92b96797 | 68 | |
a0ad2776 | 69 | if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) { |
f9cfbe94 PW |
70 | /* set AID */ |
71 | MACvWriteWord(pDevice, MAC_REG_AIDATIM, wAID); | |
f9cfbe94 | 72 | } |
92b96797 | 73 | |
64052b78 AO |
74 | /* Warren:06-18-2004,the sequence must follow |
75 | * PSEN->AUTOSLEEP->GO2DOZE | |
76 | */ | |
7404eab2 | 77 | /* enable power saving hw function */ |
f9cfbe94 | 78 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); |
92b96797 | 79 | |
7404eab2 | 80 | /* Set AutoSleep */ |
f9cfbe94 | 81 | MACvRegBitsOn(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
92b96797 | 82 | |
64052b78 AO |
83 | /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the |
84 | * AUTOSLEEP doesn't work | |
85 | */ | |
f9cfbe94 | 86 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
92b96797 | 87 | |
f9cfbe94 | 88 | if (wListenInterval >= 2) { |
92b96797 | 89 | |
7404eab2 | 90 | /* clear always listen beacon */ |
f9cfbe94 | 91 | MACvRegBitsOff(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
92b96797 | 92 | |
7404eab2 | 93 | /* first time set listen next beacon */ |
f9cfbe94 | 94 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
92b96797 | 95 | |
f9cfbe94 | 96 | pMgmt->wCountToWakeUp = wListenInterval; |
92b96797 | 97 | |
f9cfbe94 | 98 | } else { |
92b96797 | 99 | |
7404eab2 | 100 | /* always listen beacon */ |
f9cfbe94 | 101 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
92b96797 | 102 | |
f9cfbe94 PW |
103 | pMgmt->wCountToWakeUp = 0; |
104 | } | |
105 | ||
4e9b5e2b | 106 | pDevice->bEnablePSMode = true; |
f9cfbe94 | 107 | |
64052b78 AO |
108 | /* We don't send null pkt in ad hoc mode |
109 | * since beacon will handle this. | |
110 | */ | |
a0ad2776 | 111 | if (pDevice->op_mode == NL80211_IFTYPE_STATION) |
f9cfbe94 | 112 | PSbSendNullPacket(pDevice); |
f9cfbe94 | 113 | |
4e9b5e2b | 114 | pDevice->bPWBitOn = true; |
c5b0b5fc | 115 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable...\n"); |
92b96797 FB |
116 | } |
117 | ||
7404eab2 | 118 | /* |
92b96797 FB |
119 | * |
120 | * Routine Description: | |
121 | * Disable hw power saving functions | |
122 | * | |
123 | * Return Value: | |
124 | * None. | |
125 | * | |
7404eab2 | 126 | */ |
92b96797 | 127 | |
45c73bb1 | 128 | void PSvDisablePowerSaving(struct vnt_private *pDevice) |
92b96797 | 129 | { |
92b96797 | 130 | |
7404eab2 | 131 | /* disable power saving hw function */ |
1390b02a | 132 | vnt_control_out(pDevice, MESSAGE_TYPE_DISABLE_PS, 0, |
f9cfbe94 | 133 | 0, 0, NULL); |
92b96797 | 134 | |
7404eab2 | 135 | /* clear AutoSleep */ |
f9cfbe94 | 136 | MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
92b96797 | 137 | |
7404eab2 | 138 | /* set always listen beacon */ |
f9cfbe94 | 139 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
e269fc2d | 140 | pDevice->bEnablePSMode = false; |
92b96797 | 141 | |
a0ad2776 | 142 | if (pDevice->op_mode == NL80211_IFTYPE_STATION) |
f9cfbe94 | 143 | PSbSendNullPacket(pDevice); |
92b96797 | 144 | |
e269fc2d | 145 | pDevice->bPWBitOn = false; |
92b96797 FB |
146 | } |
147 | ||
7404eab2 | 148 | /* |
92b96797 FB |
149 | * |
150 | * Routine Description: | |
151 | * Consider to power down when no more packets to tx or rx. | |
152 | * | |
153 | * Return Value: | |
4e9b5e2b | 154 | * true, if power down success |
e269fc2d | 155 | * false, if fail |
7404eab2 | 156 | */ |
92b96797 | 157 | |
45c73bb1 MP |
158 | int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, |
159 | int bCheckCountToWakeUp) | |
92b96797 | 160 | { |
45c73bb1 MP |
161 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
162 | u8 byData; | |
f9cfbe94 | 163 | |
7404eab2 | 164 | /* check if already in Doze mode */ |
53742906 | 165 | vnt_control_in_u8(pDevice, MESSAGE_REQUEST_MACREG, |
f9cfbe94 PW |
166 | MAC_REG_PSCTL, &byData); |
167 | ||
c5b0b5fc | 168 | if ((byData & PSCTL_PS) != 0) |
4e9b5e2b | 169 | return true; |
f9cfbe94 PW |
170 | |
171 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { | |
7404eab2 | 172 | /* check if in TIM wake period */ |
f9cfbe94 | 173 | if (pMgmt->bInTIMWake) |
e269fc2d | 174 | return false; |
f9cfbe94 PW |
175 | } |
176 | ||
7404eab2 | 177 | /* check scan state */ |
f9cfbe94 | 178 | if (pDevice->bCmdRunning) |
e269fc2d | 179 | return false; |
f9cfbe94 | 180 | |
7404eab2 | 181 | /* Tx Burst */ |
c5b0b5fc | 182 | if (pDevice->bPSModeTxBurst) |
e269fc2d | 183 | return false; |
f9cfbe94 | 184 | |
7404eab2 | 185 | /* Froce PSEN on */ |
f9cfbe94 PW |
186 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); |
187 | ||
188 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { | |
189 | if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0 | |
190 | || pMgmt->wCountToWakeUp == 1)) { | |
e269fc2d | 191 | return false; |
f9cfbe94 PW |
192 | } |
193 | } | |
194 | ||
4e9b5e2b | 195 | pDevice->bPSRxBeacon = true; |
f9cfbe94 | 196 | |
7404eab2 | 197 | /* no Tx, no Rx isr, now go to Doze */ |
f9cfbe94 PW |
198 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
199 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); | |
4e9b5e2b | 200 | return true; |
92b96797 FB |
201 | } |
202 | ||
7404eab2 | 203 | /* |
92b96797 FB |
204 | * |
205 | * Routine Description: | |
206 | * Send PS-POLL packet | |
207 | * | |
208 | * Return Value: | |
209 | * None. | |
210 | * | |
7404eab2 | 211 | */ |
92b96797 | 212 | |
45c73bb1 | 213 | void PSvSendPSPOLL(struct vnt_private *pDevice) |
92b96797 | 214 | { |
45c73bb1 MP |
215 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
216 | struct vnt_tx_mgmt *pTxPacket = NULL; | |
217 | ||
218 | memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt) | |
219 | + WLAN_HDR_ADDR2_LEN); | |
220 | pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyPSPacketPool; | |
221 | pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket | |
222 | + sizeof(struct vnt_tx_mgmt)); | |
f9cfbe94 | 223 | |
f9cfbe94 PW |
224 | pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16( |
225 | ( | |
226 | WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) | | |
227 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) | | |
228 | WLAN_SET_FC_PWRMGT(0) | |
229 | )); | |
230 | ||
64052b78 AO |
231 | pTxPacket->p80211Header->sA2.wDurationID = |
232 | pMgmt->wCurrAID | BIT14 | BIT15; | |
233 | memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, | |
234 | WLAN_ADDR_LEN); | |
235 | memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, | |
236 | WLAN_ADDR_LEN); | |
f9cfbe94 PW |
237 | pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN; |
238 | pTxPacket->cbPayloadLen = 0; | |
239 | ||
e25b75ec | 240 | /* log failure if sending failed */ |
0f783c9d | 241 | if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) |
64052b78 AO |
242 | DBG_PRT(MSG_LEVEL_DEBUG, |
243 | KERN_INFO "Send PS-Poll packet failed..\n"); | |
92b96797 FB |
244 | } |
245 | ||
7404eab2 | 246 | /* |
92b96797 FB |
247 | * |
248 | * Routine Description: | |
249 | * Send NULL packet to AP for notification power state of STA | |
250 | * | |
251 | * Return Value: | |
252 | * None. | |
253 | * | |
7404eab2 | 254 | */ |
0cbd8d98 | 255 | |
45c73bb1 | 256 | int PSbSendNullPacket(struct vnt_private *pDevice) |
92b96797 | 257 | { |
45c73bb1 MP |
258 | struct vnt_tx_mgmt *pTxPacket = NULL; |
259 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; | |
b898cf21 | 260 | u16 flags = 0; |
f9cfbe94 | 261 | |
e269fc2d AM |
262 | if (pDevice->bLinkPass == false) |
263 | return false; | |
f9cfbe94 | 264 | |
60cc2747 MP |
265 | if (pDevice->bEnablePSMode == false && pDevice->tx_trigger == false) |
266 | return false; | |
f9cfbe94 | 267 | |
45c73bb1 MP |
268 | memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt) |
269 | + WLAN_NULLDATA_FR_MAXLEN); | |
270 | pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyPSPacketPool; | |
271 | pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket | |
272 | + sizeof(struct vnt_tx_mgmt)); | |
f9cfbe94 | 273 | |
b898cf21 | 274 | flags = WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | |
f27d2be4 | 275 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL); |
b898cf21 PW |
276 | |
277 | if (pDevice->bEnablePSMode) | |
278 | flags |= WLAN_SET_FC_PWRMGT(1); | |
279 | else | |
280 | flags |= WLAN_SET_FC_PWRMGT(0); | |
281 | ||
282 | pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(flags); | |
f9cfbe94 | 283 | |
c5b0b5fc | 284 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) |
64052b78 AO |
285 | pTxPacket->p80211Header->sA3.wFrameCtl |= |
286 | cpu_to_le16((u16)WLAN_SET_FC_TODS(1)); | |
287 | ||
288 | memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, | |
289 | WLAN_ADDR_LEN); | |
290 | memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, | |
291 | WLAN_ADDR_LEN); | |
292 | memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, | |
293 | WLAN_BSSID_LEN); | |
f9cfbe94 PW |
294 | pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN; |
295 | pTxPacket->cbPayloadLen = 0; | |
e25b75ec | 296 | /* log error if sending failed */ |
f9cfbe94 | 297 | if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { |
64052b78 AO |
298 | DBG_PRT(MSG_LEVEL_DEBUG, |
299 | KERN_INFO "Send Null Packet failed !\n"); | |
e269fc2d | 300 | return false; |
f9cfbe94 | 301 | } |
4e9b5e2b | 302 | return true; |
92b96797 FB |
303 | } |
304 | ||
7404eab2 | 305 | /* |
92b96797 FB |
306 | * |
307 | * Routine Description: | |
308 | * Check if Next TBTT must wake up | |
309 | * | |
310 | * Return Value: | |
311 | * None. | |
312 | * | |
7404eab2 | 313 | */ |
92b96797 | 314 | |
45c73bb1 | 315 | int PSbIsNextTBTTWakeUp(struct vnt_private *pDevice) |
92b96797 | 316 | { |
45c73bb1 | 317 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
e269fc2d | 318 | int bWakeUp = false; |
f9cfbe94 PW |
319 | |
320 | if (pMgmt->wListenInterval >= 2) { | |
036dba14 | 321 | if (pMgmt->wCountToWakeUp == 0) |
f9cfbe94 | 322 | pMgmt->wCountToWakeUp = pMgmt->wListenInterval; |
f9cfbe94 | 323 | |
c5b0b5fc | 324 | pMgmt->wCountToWakeUp--; |
f9cfbe94 PW |
325 | |
326 | if (pMgmt->wCountToWakeUp == 1) { | |
7404eab2 | 327 | /* Turn on wake up to listen next beacon */ |
f9cfbe94 | 328 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
e269fc2d | 329 | pDevice->bPSRxBeacon = false; |
4e9b5e2b | 330 | bWakeUp = true; |
c5b0b5fc | 331 | } else if (!pDevice->bPSRxBeacon) { |
7404eab2 | 332 | /* Listen until RxBeacon */ |
f9cfbe94 PW |
333 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
334 | } | |
335 | } | |
336 | return bWakeUp; | |
92b96797 FB |
337 | } |
338 |