Commit | Line | Data |
---|---|---|
5449c685 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 | * | |
612822f5 | 19 | * |
5449c685 FB |
20 | * File: power.c |
21 | * | |
658ce9d6 | 22 | * Purpose: Handles 802.11 power management functions |
5449c685 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 | ||
5449c685 | 40 | #include "mac.h" |
5449c685 | 41 | #include "device.h" |
5449c685 | 42 | #include "power.h" |
5449c685 | 43 | #include "card.h" |
5449c685 FB |
44 | |
45 | /*--------------------- Static Definitions -------------------------*/ | |
46 | ||
5449c685 FB |
47 | /*--------------------- Static Classes ----------------------------*/ |
48 | ||
5449c685 FB |
49 | /*--------------------- Static Functions --------------------------*/ |
50 | ||
5449c685 FB |
51 | /*--------------------- Export Variables --------------------------*/ |
52 | ||
5449c685 FB |
53 | /*--------------------- Export Functions --------------------------*/ |
54 | ||
55 | /*+ | |
56 | * | |
57 | * Routine Description: | |
58 | * Enable hw power saving functions | |
59 | * | |
60 | * Return Value: | |
61 | * None. | |
62 | * | |
474f0f89 | 63 | -*/ |
5449c685 | 64 | |
6b35b7b3 | 65 | void |
5449c685 | 66 | PSvEnablePowerSaving( |
474f0f89 JP |
67 | void *hDeviceContext, |
68 | unsigned short wListenInterval | |
69 | ) | |
5449c685 | 70 | { |
cf76dc4b | 71 | struct vnt_private *pDevice = hDeviceContext; |
e99d357c | 72 | u16 wAID = pDevice->current_aid | BIT(14) | BIT(15); |
474f0f89 | 73 | |
c3dd5a08 | 74 | /* set period of power up before TBTT */ |
474f0f89 | 75 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT); |
a9873673 | 76 | if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) { |
c3dd5a08 | 77 | /* set AID */ |
474f0f89 JP |
78 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID); |
79 | } else { | |
c3dd5a08 | 80 | /* set ATIM Window */ |
e99d357c | 81 | #if 0 /* TODO atim window */ |
474f0f89 | 82 | MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); |
e99d357c | 83 | #endif |
474f0f89 | 84 | } |
c3dd5a08 | 85 | /* Set AutoSleep */ |
474f0f89 | 86 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
c3dd5a08 | 87 | /* Set HWUTSF */ |
474f0f89 JP |
88 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); |
89 | ||
90 | if (wListenInterval >= 2) { | |
c3dd5a08 | 91 | /* clear always listen beacon */ |
474f0f89 | 92 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
c3dd5a08 | 93 | /* first time set listen next beacon */ |
474f0f89 | 94 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); |
5e0cc8a2 | 95 | } else { |
c3dd5a08 | 96 | /* always listen beacon */ |
474f0f89 | 97 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
474f0f89 JP |
98 | } |
99 | ||
c3dd5a08 | 100 | /* enable power saving hw function */ |
474f0f89 JP |
101 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); |
102 | pDevice->bEnablePSMode = true; | |
103 | ||
474f0f89 | 104 | pDevice->bPWBitOn = true; |
48caf5a0 | 105 | pr_debug("PS:Power Saving Mode Enable...\n"); |
5449c685 FB |
106 | } |
107 | ||
5449c685 FB |
108 | /*+ |
109 | * | |
110 | * Routine Description: | |
111 | * Disable hw power saving functions | |
112 | * | |
113 | * Return Value: | |
114 | * None. | |
115 | * | |
474f0f89 | 116 | -*/ |
5449c685 | 117 | |
6b35b7b3 | 118 | void |
5449c685 | 119 | PSvDisablePowerSaving( |
474f0f89 JP |
120 | void *hDeviceContext |
121 | ) | |
5449c685 | 122 | { |
cf76dc4b | 123 | struct vnt_private *pDevice = hDeviceContext; |
5449c685 | 124 | |
c3dd5a08 | 125 | /* disable power saving hw function */ |
474f0f89 | 126 | MACbPSWakeup(pDevice->PortOffset); |
c3dd5a08 | 127 | /* clear AutoSleep */ |
474f0f89 | 128 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
c3dd5a08 | 129 | /* clear HWUTSF */ |
474f0f89 | 130 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); |
c3dd5a08 | 131 | /* set always listen beacon */ |
474f0f89 JP |
132 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
133 | ||
134 | pDevice->bEnablePSMode = false; | |
135 | ||
474f0f89 | 136 | pDevice->bPWBitOn = false; |
5449c685 FB |
137 | } |
138 | ||
5449c685 FB |
139 | |
140 | /*+ | |
141 | * | |
142 | * Routine Description: | |
143 | * Check if Next TBTT must wake up | |
144 | * | |
145 | * Return Value: | |
146 | * None. | |
147 | * | |
474f0f89 | 148 | -*/ |
5449c685 | 149 | |
7b6a0013 | 150 | bool |
5449c685 | 151 | PSbIsNextTBTTWakeUp( |
474f0f89 JP |
152 | void *hDeviceContext |
153 | ) | |
5449c685 | 154 | { |
cf76dc4b | 155 | struct vnt_private *pDevice = hDeviceContext; |
e24c235b MP |
156 | struct ieee80211_hw *hw = pDevice->hw; |
157 | struct ieee80211_conf *conf = &hw->conf; | |
474f0f89 | 158 | bool bWakeUp = false; |
5449c685 | 159 | |
3e7921a0 MP |
160 | if (conf->listen_interval > 1) { |
161 | if (!pDevice->wake_up_count) | |
162 | pDevice->wake_up_count = conf->listen_interval; | |
163 | ||
164 | --pDevice->wake_up_count; | |
165 | ||
166 | if (pDevice->wake_up_count == 1) { | |
167 | /* Turn on wake up to listen next beacon */ | |
168 | MACvRegBitsOn(pDevice->PortOffset, | |
169 | MAC_REG_PSCTL, PSCTL_LNBCN); | |
170 | bWakeUp = true; | |
171 | } | |
474f0f89 | 172 | } |
5449c685 | 173 | |
474f0f89 | 174 | return bWakeUp; |
5449c685 | 175 | } |