Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 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 | * |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 19 | * |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 20 | * File: power.c |
| 21 | * |
Uwe Kleine-König | 658ce9d | 2009-07-23 08:33:56 +0200 | [diff] [blame] | 22 | * Purpose: Handles 802.11 power management functions |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 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 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 41 | #include "device.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 42 | #include "power.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 43 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 44 | |
| 45 | /*--------------------- Static Definitions -------------------------*/ |
| 46 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 47 | /*--------------------- Static Classes ----------------------------*/ |
| 48 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 49 | /*--------------------- Static Functions --------------------------*/ |
| 50 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 51 | /*--------------------- Export Variables --------------------------*/ |
| 52 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 53 | /*--------------------- Export Functions --------------------------*/ |
| 54 | |
| 55 | /*+ |
| 56 | * |
| 57 | * Routine Description: |
| 58 | * Enable hw power saving functions |
| 59 | * |
| 60 | * Return Value: |
| 61 | * None. |
| 62 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 63 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 64 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 65 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 66 | PSvEnablePowerSaving( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 67 | void *hDeviceContext, |
| 68 | unsigned short wListenInterval |
| 69 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 70 | { |
Malcolm Priestley | cf76dc4 | 2014-08-10 15:46:59 +0100 | [diff] [blame] | 71 | struct vnt_private *pDevice = hDeviceContext; |
Malcolm Priestley | e99d357 | 2014-10-29 17:43:50 +0000 | [diff] [blame] | 72 | u16 wAID = pDevice->current_aid | BIT(14) | BIT(15); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 73 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 74 | // set period of power up before TBTT |
| 75 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT); |
Malcolm Priestley | a987367 | 2014-08-30 22:25:49 +0100 | [diff] [blame] | 76 | if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 77 | // set AID |
| 78 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID); |
| 79 | } else { |
| 80 | // set ATIM Window |
Malcolm Priestley | e99d357 | 2014-10-29 17:43:50 +0000 | [diff] [blame] | 81 | #if 0 /* TODO atim window */ |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 82 | MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); |
Malcolm Priestley | e99d357 | 2014-10-29 17:43:50 +0000 | [diff] [blame] | 83 | #endif |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 84 | } |
| 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 89 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 90 | if (wListenInterval >= 2) { |
| 91 | // clear always listen beacon |
| 92 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 93 | // first time set listen next beacon |
| 94 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 95 | } else { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 96 | // always listen beacon |
| 97 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 98 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 99 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 100 | // enable power saving hw function |
| 101 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); |
| 102 | pDevice->bEnablePSMode = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 103 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 104 | pDevice->bPWBitOn = true; |
Joe Perches | 48caf5a | 2014-08-17 09:17:04 -0700 | [diff] [blame] | 105 | pr_debug("PS:Power Saving Mode Enable...\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 108 | /*+ |
| 109 | * |
| 110 | * Routine Description: |
| 111 | * Disable hw power saving functions |
| 112 | * |
| 113 | * Return Value: |
| 114 | * None. |
| 115 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 116 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 117 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 118 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 119 | PSvDisablePowerSaving( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 120 | void *hDeviceContext |
| 121 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 122 | { |
Malcolm Priestley | cf76dc4 | 2014-08-10 15:46:59 +0100 | [diff] [blame] | 123 | struct vnt_private *pDevice = hDeviceContext; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 124 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 125 | // 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 133 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 134 | pDevice->bEnablePSMode = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 135 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 136 | pDevice->bPWBitOn = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 139 | |
| 140 | /*+ |
| 141 | * |
| 142 | * Routine Description: |
| 143 | * Check if Next TBTT must wake up |
| 144 | * |
| 145 | * Return Value: |
| 146 | * None. |
| 147 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 148 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 149 | |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 150 | bool |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 151 | PSbIsNextTBTTWakeUp( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 152 | void *hDeviceContext |
| 153 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 154 | { |
Malcolm Priestley | cf76dc4 | 2014-08-10 15:46:59 +0100 | [diff] [blame] | 155 | struct vnt_private *pDevice = hDeviceContext; |
Malcolm Priestley | e24c235 | 2014-10-29 17:44:00 +0000 | [diff] [blame] | 156 | struct ieee80211_hw *hw = pDevice->hw; |
| 157 | struct ieee80211_conf *conf = &hw->conf; |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 158 | bool bWakeUp = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 159 | |
Malcolm Priestley | e24c235 | 2014-10-29 17:44:00 +0000 | [diff] [blame] | 160 | 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 Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 164 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 165 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 166 | return bWakeUp; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 167 | } |