blob: e826f07e91c03bb8b43735658bda881eab64de99 [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
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 *
Jim Lieb612822f2009-08-12 14:54:03 -070019 *
Forest Bond5449c682009-04-25 10:30:44 -040020 * File: power.c
21 *
Uwe Kleine-König658ce9d2009-07-23 08:33:56 +020022 * Purpose: Handles 802.11 power management functions
Forest Bond5449c682009-04-25 10:30:44 -040023 *
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
Forest Bond5449c682009-04-25 10:30:44 -040040#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040041#include "device.h"
Forest Bond5449c682009-04-25 10:30:44 -040042#include "power.h"
Forest Bond5449c682009-04-25 10:30:44 -040043#include "card.h"
Forest Bond5449c682009-04-25 10:30:44 -040044
45/*--------------------- Static Definitions -------------------------*/
46
Forest Bond5449c682009-04-25 10:30:44 -040047/*--------------------- Static Classes ----------------------------*/
48
Forest Bond5449c682009-04-25 10:30:44 -040049/*--------------------- Static Functions --------------------------*/
50
Forest Bond5449c682009-04-25 10:30:44 -040051/*--------------------- Export Variables --------------------------*/
52
Forest Bond5449c682009-04-25 10:30:44 -040053/*--------------------- Export Functions --------------------------*/
54
55/*+
56 *
57 * Routine Description:
58 * Enable hw power saving functions
59 *
60 * Return Value:
61 * None.
62 *
Joe Perches474f0f82013-03-18 10:44:58 -070063 -*/
Forest Bond5449c682009-04-25 10:30:44 -040064
Charles Clément6b35b7b2010-05-07 12:30:19 -070065void
Forest Bond5449c682009-04-25 10:30:44 -040066PSvEnablePowerSaving(
Joe Perches474f0f82013-03-18 10:44:58 -070067 void *hDeviceContext,
68 unsigned short wListenInterval
69)
Forest Bond5449c682009-04-25 10:30:44 -040070{
Malcolm Priestleycf76dc42014-08-10 15:46:59 +010071 struct vnt_private *pDevice = hDeviceContext;
Malcolm Priestleye99d3572014-10-29 17:43:50 +000072 u16 wAID = pDevice->current_aid | BIT(14) | BIT(15);
Forest Bond5449c682009-04-25 10:30:44 -040073
Joe Perches474f0f82013-03-18 10:44:58 -070074 // set period of power up before TBTT
75 VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
Malcolm Priestleya9873672014-08-30 22:25:49 +010076 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
Joe Perches474f0f82013-03-18 10:44:58 -070077 // set AID
78 VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
79 } else {
80 // set ATIM Window
Malcolm Priestleye99d3572014-10-29 17:43:50 +000081#if 0 /* TODO atim window */
Joe Perches474f0f82013-03-18 10:44:58 -070082 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
Malcolm Priestleye99d3572014-10-29 17:43:50 +000083#endif
Joe Perches474f0f82013-03-18 10:44:58 -070084 }
85 // Set AutoSleep
86 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
87 // Set HWUTSF
88 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
Forest Bond5449c682009-04-25 10:30:44 -040089
Joe Perches474f0f82013-03-18 10:44:58 -070090 if (wListenInterval >= 2) {
91 // clear always listen beacon
92 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
Joe Perches474f0f82013-03-18 10:44:58 -070093 // first time set listen next beacon
94 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
Joe Perches5e0cc8a2013-03-18 20:55:37 -070095 } else {
Joe Perches474f0f82013-03-18 10:44:58 -070096 // always listen beacon
97 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
Joe Perches474f0f82013-03-18 10:44:58 -070098 }
Forest Bond5449c682009-04-25 10:30:44 -040099
Joe Perches474f0f82013-03-18 10:44:58 -0700100 // enable power saving hw function
101 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
102 pDevice->bEnablePSMode = true;
Forest Bond5449c682009-04-25 10:30:44 -0400103
Joe Perches474f0f82013-03-18 10:44:58 -0700104 pDevice->bPWBitOn = true;
Joe Perches48caf5a2014-08-17 09:17:04 -0700105 pr_debug("PS:Power Saving Mode Enable...\n");
Forest Bond5449c682009-04-25 10:30:44 -0400106}
107
Forest Bond5449c682009-04-25 10:30:44 -0400108/*+
109 *
110 * Routine Description:
111 * Disable hw power saving functions
112 *
113 * Return Value:
114 * None.
115 *
Joe Perches474f0f82013-03-18 10:44:58 -0700116 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400117
Charles Clément6b35b7b2010-05-07 12:30:19 -0700118void
Forest Bond5449c682009-04-25 10:30:44 -0400119PSvDisablePowerSaving(
Joe Perches474f0f82013-03-18 10:44:58 -0700120 void *hDeviceContext
121)
Forest Bond5449c682009-04-25 10:30:44 -0400122{
Malcolm Priestleycf76dc42014-08-10 15:46:59 +0100123 struct vnt_private *pDevice = hDeviceContext;
Forest Bond5449c682009-04-25 10:30:44 -0400124
Joe Perches474f0f82013-03-18 10:44:58 -0700125 // disable power saving hw function
126 MACbPSWakeup(pDevice->PortOffset);
127 //clear AutoSleep
128 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
129 //clear HWUTSF
130 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
131 // set always listen beacon
132 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
Forest Bond5449c682009-04-25 10:30:44 -0400133
Joe Perches474f0f82013-03-18 10:44:58 -0700134 pDevice->bEnablePSMode = false;
Forest Bond5449c682009-04-25 10:30:44 -0400135
Joe Perches474f0f82013-03-18 10:44:58 -0700136 pDevice->bPWBitOn = false;
Forest Bond5449c682009-04-25 10:30:44 -0400137}
138
Forest Bond5449c682009-04-25 10:30:44 -0400139
140/*+
141 *
142 * Routine Description:
143 * Check if Next TBTT must wake up
144 *
145 * Return Value:
146 * None.
147 *
Joe Perches474f0f82013-03-18 10:44:58 -0700148 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400149
Charles Clément7b6a0012010-08-01 17:15:50 +0200150bool
Forest Bond5449c682009-04-25 10:30:44 -0400151PSbIsNextTBTTWakeUp(
Joe Perches474f0f82013-03-18 10:44:58 -0700152 void *hDeviceContext
153)
Forest Bond5449c682009-04-25 10:30:44 -0400154{
Malcolm Priestleycf76dc42014-08-10 15:46:59 +0100155 struct vnt_private *pDevice = hDeviceContext;
Malcolm Priestleye24c2352014-10-29 17:44:00 +0000156 struct ieee80211_hw *hw = pDevice->hw;
157 struct ieee80211_conf *conf = &hw->conf;
Joe Perches474f0f82013-03-18 10:44:58 -0700158 bool bWakeUp = false;
Forest Bond5449c682009-04-25 10:30:44 -0400159
Malcolm Priestleye24c2352014-10-29 17:44:00 +0000160 if (conf->listen_interval == 1) {
161 /* Turn on wake up to listen next beacon */
162 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
163 bWakeUp = true;
Joe Perches474f0f82013-03-18 10:44:58 -0700164 }
Forest Bond5449c682009-04-25 10:30:44 -0400165
Joe Perches474f0f82013-03-18 10:44:58 -0700166 return bWakeUp;
Forest Bond5449c682009-04-25 10:30:44 -0400167}