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 | * |
| 19 | * File: card.c |
| 20 | * Purpose: Provide functions to setup NIC operation mode |
| 21 | * Functions: |
| 22 | * s_vSafeResetTx - Rest Tx |
| 23 | * CARDvSetRSPINF - Set RSPINF |
| 24 | * vUpdateIFS - Update slotTime,SIFS,DIFS, and EIFS |
| 25 | * CARDvUpdateBasicTopRate - Update BasicTopRate |
| 26 | * CARDbAddBasicRate - Add to BasicRateSet |
| 27 | * CARDbSetBasicRate - Set Basic Tx Rate |
| 28 | * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet |
| 29 | * CARDvSetLoopbackMode - Set Loopback mode |
| 30 | * CARDbSoftwareReset - Sortware reset NIC |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 31 | * CARDqGetTSFOffset - Calculate TSFOffset |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 32 | * CARDbGetCurrentTSF - Read Current NIC TSF counter |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 33 | * CARDqGetNextTBTT - Calculate Next Beacon TSF counter |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 34 | * CARDvSetFirstNextTBTT - Set NIC Beacon time |
| 35 | * CARDvUpdateNextTBTT - Sync. NIC Beacon time |
| 36 | * CARDbRadioPowerOff - Turn Off NIC Radio Power |
| 37 | * CARDbRadioPowerOn - Turn On NIC Radio Power |
| 38 | * CARDbSetWEPMode - Set NIC Wep mode |
| 39 | * CARDbSetTxPower - Set NIC tx power |
| 40 | * |
| 41 | * Revision History: |
| 42 | * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. |
| 43 | * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase. |
| 44 | * 09-01-2003 Bryan YC Fan: Add vUpdateIFS(). |
| 45 | * |
| 46 | */ |
| 47 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 48 | #include "tmacro.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 49 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 50 | #include "baseband.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 51 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 52 | #include "desc.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 53 | #include "rf.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 54 | #include "vntwifi.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 55 | #include "power.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 56 | #include "key.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 57 | #include "rc4.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 58 | #include "country.h" |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 59 | #include "channel.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 60 | |
| 61 | /*--------------------- Static Definitions -------------------------*/ |
| 62 | |
| 63 | //static int msglevel =MSG_LEVEL_DEBUG; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 64 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 65 | |
| 66 | #define C_SIFS_A 16 // micro sec. |
| 67 | #define C_SIFS_BG 10 |
| 68 | |
| 69 | #define C_EIFS 80 // micro sec. |
| 70 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 71 | #define C_SLOT_SHORT 9 // micro sec. |
| 72 | #define C_SLOT_LONG 20 |
| 73 | |
| 74 | #define C_CWMIN_A 15 // slot time |
| 75 | #define C_CWMIN_B 31 |
| 76 | |
| 77 | #define C_CWMAX 1023 // slot time |
| 78 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 79 | #define WAIT_BEACON_TX_DOWN_TMO 3 // Times |
| 80 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 81 | //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 82 | static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 83 | //6M, 9M, 12M, 48M |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 84 | static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60}; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 85 | //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 86 | static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 87 | //1M, 2M, 5M, 11M, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 88 | static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16}; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 89 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 90 | /*--------------------- Static Variables --------------------------*/ |
| 91 | |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 92 | const unsigned short cwRXBCNTSFOff[MAX_RATE] = |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 93 | {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3}; |
| 94 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 95 | /*--------------------- Static Functions --------------------------*/ |
| 96 | |
| 97 | static |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 98 | void |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 99 | s_vCalculateOFDMRParameter( |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 100 | unsigned char byRate, |
| 101 | CARD_PHY_TYPE ePHYType, |
| 102 | unsigned char *pbyTxRate, |
| 103 | unsigned char *pbyRsvTime |
| 104 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 105 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 106 | /*--------------------- Export Functions --------------------------*/ |
| 107 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 108 | /* |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 109 | * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 110 | * |
| 111 | * Parameters: |
| 112 | * In: |
| 113 | * wRate - Tx Rate |
| 114 | * byPktType - Tx Packet type |
| 115 | * Out: |
| 116 | * pbyTxRate - pointer to RSPINF TxRate field |
| 117 | * pbyRsvTime - pointer to RSPINF RsvTime field |
| 118 | * |
| 119 | * Return Value: none |
| 120 | * |
| 121 | */ |
| 122 | static |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 123 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 124 | s_vCalculateOFDMRParameter( |
| 125 | unsigned char byRate, |
| 126 | CARD_PHY_TYPE ePHYType, |
| 127 | unsigned char *pbyTxRate, |
| 128 | unsigned char *pbyRsvTime |
| 129 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 130 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 131 | switch (byRate) { |
| 132 | case RATE_6M: |
| 133 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 134 | *pbyTxRate = 0x9B; |
| 135 | *pbyRsvTime = 44; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 136 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 137 | *pbyTxRate = 0x8B; |
| 138 | *pbyRsvTime = 50; |
| 139 | } |
| 140 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 141 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 142 | case RATE_9M: |
| 143 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 144 | *pbyTxRate = 0x9F; |
| 145 | *pbyRsvTime = 36; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 146 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 147 | *pbyTxRate = 0x8F; |
| 148 | *pbyRsvTime = 42; |
| 149 | } |
| 150 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 151 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 152 | case RATE_12M: |
| 153 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 154 | *pbyTxRate = 0x9A; |
| 155 | *pbyRsvTime = 32; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 156 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 157 | *pbyTxRate = 0x8A; |
| 158 | *pbyRsvTime = 38; |
| 159 | } |
| 160 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 161 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 162 | case RATE_18M: |
| 163 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 164 | *pbyTxRate = 0x9E; |
| 165 | *pbyRsvTime = 28; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 166 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 167 | *pbyTxRate = 0x8E; |
| 168 | *pbyRsvTime = 34; |
| 169 | } |
| 170 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 171 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 172 | case RATE_36M: |
| 173 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 174 | *pbyTxRate = 0x9D; |
| 175 | *pbyRsvTime = 24; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 176 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 177 | *pbyTxRate = 0x8D; |
| 178 | *pbyRsvTime = 30; |
| 179 | } |
| 180 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 181 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 182 | case RATE_48M: |
| 183 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 184 | *pbyTxRate = 0x98; |
| 185 | *pbyRsvTime = 24; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 186 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 187 | *pbyTxRate = 0x88; |
| 188 | *pbyRsvTime = 30; |
| 189 | } |
| 190 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 191 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 192 | case RATE_54M: |
| 193 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 194 | *pbyTxRate = 0x9C; |
| 195 | *pbyRsvTime = 24; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 196 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 197 | *pbyTxRate = 0x8C; |
| 198 | *pbyRsvTime = 30; |
| 199 | } |
| 200 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 201 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 202 | case RATE_24M: |
| 203 | default: |
| 204 | if (ePHYType == PHY_TYPE_11A) {//5GHZ |
| 205 | *pbyTxRate = 0x99; |
| 206 | *pbyRsvTime = 28; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 207 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 208 | *pbyTxRate = 0x89; |
| 209 | *pbyRsvTime = 34; |
| 210 | } |
| 211 | break; |
| 212 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 215 | /* |
| 216 | * Description: Set RSPINF |
| 217 | * |
| 218 | * Parameters: |
| 219 | * In: |
| 220 | * pDevice - The adapter to be set |
| 221 | * Out: |
| 222 | * none |
| 223 | * |
| 224 | * Return Value: None. |
| 225 | * |
| 226 | */ |
| 227 | static |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 228 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 229 | s_vSetRSPINF(PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 230 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 231 | unsigned char byServ = 0, bySignal = 0; // For CCK |
| 232 | unsigned short wLen = 0; |
| 233 | unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 234 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 235 | //Set to Page1 |
| 236 | MACvSelectPage1(pDevice->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 237 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 238 | //RSPINF_b_1 |
| 239 | BBvCalculateParameter(pDevice, |
| 240 | 14, |
| 241 | VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 242 | PK_TYPE_11B, |
| 243 | &wLen, |
| 244 | &byServ, |
| 245 | &bySignal |
| 246 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 247 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 248 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 249 | ///RSPINF_b_2 |
| 250 | BBvCalculateParameter(pDevice, |
| 251 | 14, |
| 252 | VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 253 | PK_TYPE_11B, |
| 254 | &wLen, |
| 255 | &byServ, |
| 256 | &bySignal |
| 257 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 258 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 259 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 260 | //RSPINF_b_5 |
| 261 | BBvCalculateParameter(pDevice, |
| 262 | 14, |
| 263 | VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 264 | PK_TYPE_11B, |
| 265 | &wLen, |
| 266 | &byServ, |
| 267 | &bySignal |
| 268 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 269 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 270 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 271 | //RSPINF_b_11 |
| 272 | BBvCalculateParameter(pDevice, |
| 273 | 14, |
| 274 | VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 275 | PK_TYPE_11B, |
| 276 | &wLen, |
| 277 | &byServ, |
| 278 | &bySignal |
| 279 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 280 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 281 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 282 | //RSPINF_a_6 |
| 283 | s_vCalculateOFDMRParameter(RATE_6M, |
| 284 | ePHYType, |
| 285 | &byTxRate, |
| 286 | &byRsvTime); |
| 287 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime)); |
| 288 | //RSPINF_a_9 |
| 289 | s_vCalculateOFDMRParameter(RATE_9M, |
| 290 | ePHYType, |
| 291 | &byTxRate, |
| 292 | &byRsvTime); |
| 293 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime)); |
| 294 | //RSPINF_a_12 |
| 295 | s_vCalculateOFDMRParameter(RATE_12M, |
| 296 | ePHYType, |
| 297 | &byTxRate, |
| 298 | &byRsvTime); |
| 299 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime)); |
| 300 | //RSPINF_a_18 |
| 301 | s_vCalculateOFDMRParameter(RATE_18M, |
| 302 | ePHYType, |
| 303 | &byTxRate, |
| 304 | &byRsvTime); |
| 305 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime)); |
| 306 | //RSPINF_a_24 |
| 307 | s_vCalculateOFDMRParameter(RATE_24M, |
| 308 | ePHYType, |
| 309 | &byTxRate, |
| 310 | &byRsvTime); |
| 311 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime)); |
| 312 | //RSPINF_a_36 |
| 313 | s_vCalculateOFDMRParameter( |
| 314 | VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 315 | ePHYType, |
| 316 | &byTxRate, |
| 317 | &byRsvTime); |
| 318 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime)); |
| 319 | //RSPINF_a_48 |
| 320 | s_vCalculateOFDMRParameter( |
| 321 | VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 322 | ePHYType, |
| 323 | &byTxRate, |
| 324 | &byRsvTime); |
| 325 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime)); |
| 326 | //RSPINF_a_54 |
| 327 | s_vCalculateOFDMRParameter( |
| 328 | VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs), |
| 329 | ePHYType, |
| 330 | &byTxRate, |
| 331 | &byRsvTime); |
| 332 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime)); |
| 333 | //RSPINF_a_72 |
| 334 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime)); |
| 335 | //Set to Page0 |
| 336 | MACvSelectPage0(pDevice->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 337 | } |
| 338 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 339 | /*--------------------- Export Functions --------------------------*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * Description: Card Send packet function |
| 343 | * |
| 344 | * Parameters: |
| 345 | * In: |
| 346 | * pDeviceHandler - The adapter to be set |
| 347 | * pPacket - Packet buffer pointer |
| 348 | * ePktType - Packet type |
| 349 | * uLength - Packet length |
| 350 | * Out: |
| 351 | * none |
| 352 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 353 | * Return Value: true if succeeded; false if failed. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 354 | * |
| 355 | */ |
| 356 | /* |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 357 | bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 358 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 359 | if (ePktType == PKT_TYPE_802_11_MNG) { |
| 360 | return TXbTD0Send(pDevice, pPacket, uLength); |
| 361 | } else if (ePktType == PKT_TYPE_802_11_BCN) { |
| 362 | return TXbBeaconSend(pDevice, pPacket, uLength); |
| 363 | } if (ePktType == PKT_TYPE_802_11_DATA) { |
| 364 | return TXbTD1Send(pDevice, pPacket, uLength); |
| 365 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 366 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 367 | return true; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 368 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 369 | */ |
| 370 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 371 | /* |
| 372 | * Description: Get Card short preamble option value |
| 373 | * |
| 374 | * Parameters: |
| 375 | * In: |
| 376 | * pDevice - The adapter to be set |
| 377 | * Out: |
| 378 | * none |
| 379 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 380 | * Return Value: true if short preamble; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 381 | * |
| 382 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 383 | bool CARDbIsShortPreamble(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 384 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 385 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 386 | if (pDevice->byPreambleType == 0) { |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 387 | return false; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 388 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 389 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Description: Get Card short slot time option value |
| 394 | * |
| 395 | * Parameters: |
| 396 | * In: |
| 397 | * pDevice - The adapter to be set |
| 398 | * Out: |
| 399 | * none |
| 400 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 401 | * Return Value: true if short slot time; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 402 | * |
| 403 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 404 | bool CARDbIsShorSlotTime(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 405 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 406 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 407 | return pDevice->bShortSlotTime; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 408 | } |
| 409 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 410 | /* |
| 411 | * Description: Update IFS |
| 412 | * |
| 413 | * Parameters: |
| 414 | * In: |
| 415 | * pDevice - The adapter to be set |
| 416 | * Out: |
| 417 | * none |
| 418 | * |
| 419 | * Return Value: None. |
| 420 | * |
| 421 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 422 | bool CARDbSetPhyParameter(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 423 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 424 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 425 | unsigned char byCWMaxMin = 0; |
| 426 | unsigned char bySlot = 0; |
| 427 | unsigned char bySIFS = 0; |
| 428 | unsigned char byDIFS = 0; |
| 429 | unsigned char byData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 430 | // PWLAN_IE_SUPP_RATES pRates = NULL; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 431 | PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs; |
| 432 | PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 433 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 434 | //Set SIFS, DIFS, EIFS, SlotTime, CwMin |
| 435 | if (ePHYType == PHY_TYPE_11A) { |
| 436 | if (pSupportRates == NULL) { |
| 437 | pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA; |
| 438 | } |
| 439 | if (pDevice->byRFType == RF_AIROHA7230) { |
| 440 | // AL7230 use single PAPE and connect to PAPE_2.4G |
| 441 | MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G); |
| 442 | pDevice->abyBBVGA[0] = 0x20; |
| 443 | pDevice->abyBBVGA[2] = 0x10; |
| 444 | pDevice->abyBBVGA[3] = 0x10; |
| 445 | BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); |
| 446 | if (byData == 0x1C) { |
| 447 | BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); |
| 448 | } |
| 449 | } else if (pDevice->byRFType == RF_UW2452) { |
| 450 | MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A); |
| 451 | pDevice->abyBBVGA[0] = 0x18; |
| 452 | BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); |
| 453 | if (byData == 0x14) { |
| 454 | BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); |
| 455 | BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57); |
| 456 | } |
| 457 | } else { |
| 458 | MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A); |
| 459 | } |
| 460 | BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03); |
| 461 | bySlot = C_SLOT_SHORT; |
| 462 | bySIFS = C_SIFS_A; |
| 463 | byDIFS = C_SIFS_A + 2*C_SLOT_SHORT; |
| 464 | byCWMaxMin = 0xA4; |
| 465 | } else if (ePHYType == PHY_TYPE_11B) { |
| 466 | if (pSupportRates == NULL) { |
| 467 | pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB; |
| 468 | } |
| 469 | MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B); |
| 470 | if (pDevice->byRFType == RF_AIROHA7230) { |
| 471 | pDevice->abyBBVGA[0] = 0x1C; |
| 472 | pDevice->abyBBVGA[2] = 0x00; |
| 473 | pDevice->abyBBVGA[3] = 0x00; |
| 474 | BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); |
| 475 | if (byData == 0x20) { |
| 476 | BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); |
| 477 | } |
| 478 | } else if (pDevice->byRFType == RF_UW2452) { |
| 479 | pDevice->abyBBVGA[0] = 0x14; |
| 480 | BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); |
| 481 | if (byData == 0x18) { |
| 482 | BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); |
| 483 | BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3); |
| 484 | } |
| 485 | } |
| 486 | BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02); |
| 487 | bySlot = C_SLOT_LONG; |
| 488 | bySIFS = C_SIFS_BG; |
| 489 | byDIFS = C_SIFS_BG + 2*C_SLOT_LONG; |
| 490 | byCWMaxMin = 0xA5; |
| 491 | } else {// PK_TYPE_11GA & PK_TYPE_11GB |
| 492 | if (pSupportRates == NULL) { |
| 493 | pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG; |
| 494 | pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG; |
| 495 | } |
| 496 | MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G); |
| 497 | if (pDevice->byRFType == RF_AIROHA7230) { |
| 498 | pDevice->abyBBVGA[0] = 0x1C; |
| 499 | pDevice->abyBBVGA[2] = 0x00; |
| 500 | pDevice->abyBBVGA[3] = 0x00; |
| 501 | BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); |
| 502 | if (byData == 0x20) { |
| 503 | BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); |
| 504 | } |
| 505 | } else if (pDevice->byRFType == RF_UW2452) { |
| 506 | pDevice->abyBBVGA[0] = 0x14; |
| 507 | BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); |
| 508 | if (byData == 0x18) { |
| 509 | BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); |
| 510 | BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3); |
| 511 | } |
| 512 | } |
| 513 | BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08); |
| 514 | bySIFS = C_SIFS_BG; |
| 515 | if (VNTWIFIbIsShortSlotTime(wCapInfo)) { |
| 516 | bySlot = C_SLOT_SHORT; |
| 517 | byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT; |
| 518 | } else { |
| 519 | bySlot = C_SLOT_LONG; |
| 520 | byDIFS = C_SIFS_BG + 2*C_SLOT_LONG; |
| 521 | } |
| 522 | if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) { |
| 523 | byCWMaxMin = 0xA4; |
| 524 | } else { |
| 525 | byCWMaxMin = 0xA5; |
| 526 | } |
| 527 | if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) { |
| 528 | pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField); |
| 529 | if (pDevice->bProtectMode) { |
| 530 | MACvEnableProtectMD(pDevice->PortOffset); |
| 531 | } else { |
| 532 | MACvDisableProtectMD(pDevice->PortOffset); |
| 533 | } |
| 534 | } |
| 535 | if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) { |
| 536 | pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField); |
| 537 | if (pDevice->bBarkerPreambleMd) { |
| 538 | MACvEnableBarkerPreambleMd(pDevice->PortOffset); |
| 539 | } else { |
| 540 | MACvDisableBarkerPreambleMd(pDevice->PortOffset); |
| 541 | } |
| 542 | } |
| 543 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 544 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 545 | if (pDevice->byRFType == RF_RFMD2959) { |
| 546 | // bcs TX_PE will reserve 3 us |
| 547 | // hardware's processing time here is 2 us. |
| 548 | bySIFS -= 3; |
| 549 | byDIFS -= 3; |
| 550 | //{{ RobertYu: 20041202 |
| 551 | //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput |
| 552 | //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us. |
| 553 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 554 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 555 | if (pDevice->bySIFS != bySIFS) { |
| 556 | pDevice->bySIFS = bySIFS; |
| 557 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS); |
| 558 | } |
| 559 | if (pDevice->byDIFS != byDIFS) { |
| 560 | pDevice->byDIFS = byDIFS; |
| 561 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS); |
| 562 | } |
| 563 | if (pDevice->byEIFS != C_EIFS) { |
| 564 | pDevice->byEIFS = C_EIFS; |
| 565 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS); |
| 566 | } |
| 567 | if (pDevice->bySlot != bySlot) { |
| 568 | pDevice->bySlot = bySlot; |
| 569 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot); |
| 570 | if (pDevice->bySlot == C_SLOT_SHORT) { |
| 571 | pDevice->bShortSlotTime = true; |
| 572 | } else { |
| 573 | pDevice->bShortSlotTime = false; |
| 574 | } |
| 575 | BBvSetShortSlotTime(pDevice); |
| 576 | } |
| 577 | if (pDevice->byCWMaxMin != byCWMaxMin) { |
| 578 | pDevice->byCWMaxMin = byCWMaxMin; |
| 579 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin); |
| 580 | } |
| 581 | if (VNTWIFIbIsShortPreamble(wCapInfo)) { |
| 582 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 583 | } else { |
| 584 | pDevice->byPreambleType = 0; |
| 585 | } |
| 586 | s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates); |
| 587 | pDevice->eCurrentPHYType = ePHYType; |
| 588 | // set for NDIS OID_802_11SUPPORTED_RATES |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 589 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /* |
| 593 | * Description: Sync. TSF counter to BSS |
| 594 | * Get TSF offset and write to HW |
| 595 | * |
| 596 | * Parameters: |
| 597 | * In: |
| 598 | * pDevice - The adapter to be sync. |
| 599 | * byRxRate - data rate of receive beacon |
| 600 | * qwBSSTimestamp - Rx BCN's TSF |
| 601 | * qwLocalTSF - Local TSF |
| 602 | * Out: |
| 603 | * none |
| 604 | * |
| 605 | * Return Value: none |
| 606 | * |
| 607 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 608 | bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 609 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 610 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 611 | QWORD qwTSFOffset; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 612 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 613 | HIDWORD(qwTSFOffset) = 0; |
| 614 | LODWORD(qwTSFOffset) = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 615 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 616 | if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) || |
| 617 | (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) { |
| 618 | qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); |
| 619 | // adjust TSF |
| 620 | // HW's TSF add TSF Offset reg |
| 621 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset)); |
| 622 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset)); |
| 623 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN); |
| 624 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 625 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 626 | } |
| 627 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 628 | /* |
| 629 | * Description: Set NIC TSF counter for first Beacon time |
| 630 | * Get NEXTTBTT from adjusted TSF and Beacon Interval |
| 631 | * |
| 632 | * Parameters: |
| 633 | * In: |
| 634 | * pDevice - The adapter to be set. |
| 635 | * wBeaconInterval - Beacon Interval |
| 636 | * Out: |
| 637 | * none |
| 638 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 639 | * Return Value: true if succeed; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 640 | * |
| 641 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 642 | bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 643 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 644 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 645 | unsigned int uBeaconInterval = 0; |
| 646 | unsigned int uLowNextTBTT = 0; |
| 647 | unsigned int uHighRemain = 0; |
| 648 | unsigned int uLowRemain = 0; |
| 649 | QWORD qwNextTBTT; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 650 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 651 | HIDWORD(qwNextTBTT) = 0; |
| 652 | LODWORD(qwNextTBTT) = 0; |
| 653 | CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter |
| 654 | uBeaconInterval = wBeaconInterval * 1024; |
| 655 | // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval |
| 656 | uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10; |
| 657 | uLowRemain = (uLowNextTBTT) % uBeaconInterval; |
| 658 | // high dword (mod) bcn |
| 659 | uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT)) |
| 660 | % uBeaconInterval; |
| 661 | uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; |
| 662 | uLowRemain = uBeaconInterval - uLowRemain; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 663 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 664 | // check if carry when add one beacon interval |
| 665 | if ((~uLowNextTBTT) < uLowRemain) { |
| 666 | HIDWORD(qwNextTBTT)++; |
| 667 | } |
| 668 | LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 669 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 670 | // set HW beacon interval |
| 671 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval); |
| 672 | pDevice->wBeaconInterval = wBeaconInterval; |
| 673 | // Set NextTBTT |
| 674 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT)); |
| 675 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT)); |
| 676 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 677 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 678 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 679 | } |
| 680 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 681 | /* |
| 682 | * Description: Card Stop Hardware Tx |
| 683 | * |
| 684 | * Parameters: |
| 685 | * In: |
| 686 | * pDeviceHandler - The adapter to be set |
| 687 | * ePktType - Packet type to stop |
| 688 | * Out: |
| 689 | * none |
| 690 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 691 | * Return Value: true if all data packet complete; otherwise false. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 692 | * |
| 693 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 694 | bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 695 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 696 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 697 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 698 | if (ePktType == PKT_TYPE_802_11_ALL) { |
| 699 | pDevice->bStopBeacon = true; |
| 700 | pDevice->bStopTx0Pkt = true; |
| 701 | pDevice->bStopDataPkt = true; |
| 702 | } else if (ePktType == PKT_TYPE_802_11_BCN) { |
| 703 | pDevice->bStopBeacon = true; |
| 704 | } else if (ePktType == PKT_TYPE_802_11_MNG) { |
| 705 | pDevice->bStopTx0Pkt = true; |
| 706 | } else if (ePktType == PKT_TYPE_802_11_DATA) { |
| 707 | pDevice->bStopDataPkt = true; |
| 708 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 709 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 710 | if (pDevice->bStopBeacon == true) { |
| 711 | if (pDevice->bIsBeaconBufReadySet == true) { |
| 712 | if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) { |
| 713 | pDevice->cbBeaconBufReadySetCnt++; |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 714 | return false; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | pDevice->bIsBeaconBufReadySet = false; |
| 718 | pDevice->cbBeaconBufReadySetCnt = 0; |
| 719 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX); |
| 720 | } |
| 721 | // wait all TD0 complete |
| 722 | if (pDevice->bStopTx0Pkt == true) { |
| 723 | if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) { |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 724 | return false; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | // wait all Data TD complete |
| 728 | if (pDevice->bStopDataPkt == true) { |
| 729 | if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) { |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 730 | return false; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 731 | } |
| 732 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 733 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 734 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 737 | /* |
| 738 | * Description: Card Start Hardware Tx |
| 739 | * |
| 740 | * Parameters: |
| 741 | * In: |
| 742 | * pDeviceHandler - The adapter to be set |
| 743 | * ePktType - Packet type to start |
| 744 | * Out: |
| 745 | * none |
| 746 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 747 | * Return Value: true if success; false if failed. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 748 | * |
| 749 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 750 | bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 751 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 752 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 753 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 754 | if (ePktType == PKT_TYPE_802_11_ALL) { |
| 755 | pDevice->bStopBeacon = false; |
| 756 | pDevice->bStopTx0Pkt = false; |
| 757 | pDevice->bStopDataPkt = false; |
| 758 | } else if (ePktType == PKT_TYPE_802_11_BCN) { |
| 759 | pDevice->bStopBeacon = false; |
| 760 | } else if (ePktType == PKT_TYPE_802_11_MNG) { |
| 761 | pDevice->bStopTx0Pkt = false; |
| 762 | } else if (ePktType == PKT_TYPE_802_11_DATA) { |
| 763 | pDevice->bStopDataPkt = false; |
| 764 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 765 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 766 | if ((pDevice->bStopBeacon == false) && |
| 767 | (pDevice->bBeaconBufReady == true) && |
| 768 | (pDevice->eOPMode == OP_MODE_ADHOC)) { |
| 769 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX); |
| 770 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 771 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 772 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 773 | } |
| 774 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 775 | /* |
| 776 | * Description: Card Set BSSID value |
| 777 | * |
| 778 | * Parameters: |
| 779 | * In: |
| 780 | * pDeviceHandler - The adapter to be set |
| 781 | * pbyBSSID - pointer to BSSID field |
| 782 | * bAdhoc - flag to indicate IBSS |
| 783 | * Out: |
| 784 | * none |
| 785 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 786 | * Return Value: true if success; false if failed. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 787 | * |
| 788 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 789 | bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 790 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 791 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 792 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 793 | MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID); |
| 794 | memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN); |
| 795 | if (eOPMode == OP_MODE_ADHOC) { |
| 796 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC); |
| 797 | } else { |
| 798 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC); |
| 799 | } |
| 800 | if (eOPMode == OP_MODE_AP) { |
| 801 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP); |
| 802 | } else { |
| 803 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP); |
| 804 | } |
| 805 | if (eOPMode == OP_MODE_UNKNOWN) { |
| 806 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID); |
| 807 | pDevice->bBSSIDFilter = false; |
| 808 | pDevice->byRxMode &= ~RCR_BSSID; |
| 809 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode); |
| 810 | } else { |
| 811 | if (is_zero_ether_addr(pDevice->abyBSSID) == false) { |
| 812 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID); |
| 813 | pDevice->bBSSIDFilter = true; |
| 814 | pDevice->byRxMode |= RCR_BSSID; |
| 815 | } |
| 816 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode); |
| 817 | } |
| 818 | // Adopt BSS state in Adapter Device Object |
| 819 | pDevice->eOPMode = eOPMode; |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 820 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 823 | /* |
| 824 | * Description: Card indicate status |
| 825 | * |
| 826 | * Parameters: |
| 827 | * In: |
| 828 | * pDeviceHandler - The adapter to be set |
| 829 | * eStatus - Status |
| 830 | * Out: |
| 831 | * none |
| 832 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 833 | * Return Value: true if success; false if failed. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 834 | * |
| 835 | */ |
| 836 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 837 | /* |
| 838 | * Description: Save Assoc info. contain in assoc. response frame |
| 839 | * |
| 840 | * Parameters: |
| 841 | * In: |
| 842 | * pDevice - The adapter to be set |
| 843 | * wCapabilityInfo - Capability information |
| 844 | * wStatus - Status code |
| 845 | * wAID - Assoc. ID |
| 846 | * uLen - Length of IEs |
| 847 | * pbyIEs - pointer to IEs |
| 848 | * Out: |
| 849 | * none |
| 850 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 851 | * Return Value: true if succeed; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 852 | * |
| 853 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 854 | bool CARDbSetTxDataRate( |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 855 | void *pDeviceHandler, |
| 856 | unsigned short wDataRate |
| 857 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 858 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 859 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 860 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 861 | pDevice->wCurrentRate = wDataRate; |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 862 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /*+ |
| 866 | * |
| 867 | * Routine Description: |
| 868 | * Consider to power down when no more packets to tx or rx. |
| 869 | * |
| 870 | * Parameters: |
| 871 | * In: |
| 872 | * pDevice - The adapter to be set |
| 873 | * Out: |
| 874 | * none |
| 875 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 876 | * Return Value: true if power down success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 877 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 878 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 879 | bool |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 880 | CARDbPowerDown( |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 881 | void *pDeviceHandler |
| 882 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 883 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 884 | PSDevice pDevice = (PSDevice)pDeviceHandler; |
| 885 | unsigned int uIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 886 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 887 | // check if already in Doze mode |
| 888 | if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) |
| 889 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 890 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 891 | // Froce PSEN on |
| 892 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 893 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 894 | // check if all TD are empty, |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 895 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 896 | for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) { |
| 897 | if (pDevice->iTDUsed[uIdx] != 0) |
| 898 | return false; |
| 899 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 900 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 901 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
| 902 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); |
| 903 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /* |
| 907 | * Description: Turn off Radio power |
| 908 | * |
| 909 | * Parameters: |
| 910 | * In: |
| 911 | * pDevice - The adapter to be turned off |
| 912 | * Out: |
| 913 | * none |
| 914 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 915 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 916 | * |
| 917 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 918 | bool CARDbRadioPowerOff(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 919 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 920 | PSDevice pDevice = (PSDevice)pDeviceHandler; |
| 921 | bool bResult = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 922 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 923 | if (pDevice->bRadioOff == true) |
| 924 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 925 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 926 | switch (pDevice->byRFType) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 927 | case RF_RFMD2959: |
| 928 | MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV); |
| 929 | MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1); |
| 930 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 931 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 932 | case RF_AIROHA: |
| 933 | case RF_AL2230S: |
| 934 | case RF_AIROHA7230: //RobertYu:20050104 |
| 935 | MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2); |
| 936 | MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); |
| 937 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 938 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 939 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 940 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 941 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 942 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 943 | BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 944 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 945 | pDevice->bRadioOff = true; |
| 946 | //2007-0409-03,<Add> by chester |
| 947 | printk("chester power off\n"); |
| 948 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue |
| 949 | return bResult; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 950 | } |
| 951 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 952 | /* |
| 953 | * Description: Turn on Radio power |
| 954 | * |
| 955 | * Parameters: |
| 956 | * In: |
| 957 | * pDevice - The adapter to be turned on |
| 958 | * Out: |
| 959 | * none |
| 960 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 961 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 962 | * |
| 963 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 964 | bool CARDbRadioPowerOn(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 965 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 966 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 967 | bool bResult = true; |
| 968 | printk("chester power on\n"); |
| 969 | if (pDevice->bRadioControlOff == true) { |
| 970 | if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n"); |
| 971 | if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n"); |
| 972 | return false; } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 973 | |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 974 | if (pDevice->bRadioOff == false) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 975 | printk("chester pbRadioOff\n"); |
| 976 | return true; } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 977 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 978 | BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 979 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 980 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 981 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 982 | switch (pDevice->byRFType) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 983 | case RF_RFMD2959: |
| 984 | MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV); |
| 985 | MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1); |
| 986 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 987 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 988 | case RF_AIROHA: |
| 989 | case RF_AL2230S: |
| 990 | case RF_AIROHA7230: //RobertYu:20050104 |
| 991 | MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | |
| 992 | SOFTPWRCTL_SWPE3)); |
| 993 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 994 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 995 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 996 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 997 | pDevice->bRadioOff = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 998 | // 2007-0409-03,<Add> by chester |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 999 | printk("chester power on\n"); |
| 1000 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue |
| 1001 | return bResult; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1004 | bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1005 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1006 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1007 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1008 | KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset); |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1009 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1012 | /* |
| 1013 | * |
| 1014 | * Description: |
| 1015 | * Add BSSID in PMKID Candidate list. |
| 1016 | * |
| 1017 | * Parameters: |
| 1018 | * In: |
| 1019 | * hDeviceContext - device structure point |
| 1020 | * pbyBSSID - BSSID address for adding |
| 1021 | * wRSNCap - BSS's RSN capability |
| 1022 | * Out: |
| 1023 | * none |
| 1024 | * |
| 1025 | * Return Value: none. |
| 1026 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1027 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 1028 | bool |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1029 | CARDbAdd_PMKID_Candidate( |
| 1030 | void *pDeviceHandler, |
| 1031 | unsigned char *pbyBSSID, |
| 1032 | bool bRSNCapExist, |
| 1033 | unsigned short wRSNCap |
| 1034 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1035 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1036 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1037 | PPMKID_CANDIDATE pCandidateList; |
| 1038 | unsigned int ii = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1039 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1040 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1041 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1042 | if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) { |
| 1043 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n"); |
| 1044 | memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent)); |
| 1045 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1046 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1047 | for (ii = 0; ii < 6; ii++) { |
| 1048 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii)); |
| 1049 | } |
| 1050 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1051 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1052 | // Update Old Candidate |
| 1053 | for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) { |
| 1054 | pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii]; |
| 1055 | if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) { |
| 1056 | if ((bRSNCapExist == true) && (wRSNCap & BIT0)) { |
| 1057 | pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED; |
| 1058 | } else { |
| 1059 | pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED); |
| 1060 | } |
| 1061 | return true; |
| 1062 | } |
| 1063 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1064 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1065 | // New Candidate |
| 1066 | pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates]; |
| 1067 | if ((bRSNCapExist == true) && (wRSNCap & BIT0)) { |
| 1068 | pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED; |
| 1069 | } else { |
| 1070 | pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED); |
| 1071 | } |
| 1072 | memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN); |
| 1073 | pDevice->gsPMKIDCandidate.NumCandidates++; |
| 1074 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); |
| 1075 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 1078 | void * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1079 | CARDpGetCurrentAddress( |
| 1080 | void *pDeviceHandler |
| 1081 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1082 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1083 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1084 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1085 | return pDevice->abyCurrentNetAddr; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1088 | /* |
| 1089 | * |
| 1090 | * Description: |
| 1091 | * Start Spectrum Measure defined in 802.11h |
| 1092 | * |
| 1093 | * Parameters: |
| 1094 | * In: |
| 1095 | * hDeviceContext - device structure point |
| 1096 | * Out: |
| 1097 | * none |
| 1098 | * |
| 1099 | * Return Value: none. |
| 1100 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1101 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 1102 | bool |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1103 | CARDbStartMeasure( |
| 1104 | void *pDeviceHandler, |
| 1105 | void *pvMeasureEIDs, |
| 1106 | unsigned int uNumOfMeasureEIDs |
| 1107 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1108 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1109 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1110 | PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs; |
| 1111 | QWORD qwCurrTSF; |
| 1112 | QWORD qwStartTSF; |
| 1113 | bool bExpired = true; |
| 1114 | unsigned short wDuration = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1115 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1116 | if ((pEID == NULL) || |
| 1117 | (uNumOfMeasureEIDs == 0)) { |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1118 | return true; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1119 | } |
| 1120 | CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF); |
| 1121 | if (pDevice->bMeasureInProgress == true) { |
| 1122 | pDevice->bMeasureInProgress = false; |
| 1123 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR); |
| 1124 | MACvSelectPage1(pDevice->PortOffset); |
| 1125 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0); |
| 1126 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4); |
| 1127 | // clear measure control |
| 1128 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN); |
| 1129 | MACvSelectPage0(pDevice->PortOffset); |
| 1130 | set_channel(pDevice, pDevice->byOrgChannel); |
| 1131 | MACvSelectPage1(pDevice->PortOffset); |
| 1132 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE); |
| 1133 | MACvSelectPage0(pDevice->PortOffset); |
| 1134 | } |
| 1135 | pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1136 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1137 | do { |
| 1138 | pDevice->pCurrMeasureEID = pEID; |
| 1139 | pEID++; |
| 1140 | pDevice->uNumOfMeasureEIDs--; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1141 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1142 | if (pDevice->byLocalID > REV_ID_VT3253_B1) { |
| 1143 | HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime))); |
| 1144 | LODWORD(qwStartTSF) = LODWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime))); |
| 1145 | wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration)); |
| 1146 | wDuration += 1; // 1 TU for channel switching |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1147 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1148 | if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) { |
| 1149 | // start immediately by setting start TSF == current TSF + 2 TU |
| 1150 | LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048; |
| 1151 | HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF); |
| 1152 | if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) { |
| 1153 | HIDWORD(qwStartTSF)++; |
| 1154 | } |
| 1155 | bExpired = false; |
| 1156 | break; |
| 1157 | } else { |
| 1158 | // start at setting start TSF - 1TU(for channel switching) |
| 1159 | if (LODWORD(qwStartTSF) < 1024) { |
| 1160 | HIDWORD(qwStartTSF)--; |
| 1161 | } |
| 1162 | LODWORD(qwStartTSF) -= 1024; |
| 1163 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1164 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1165 | if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) || |
| 1166 | ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) && |
| 1167 | (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF))) |
| 1168 | ) { |
| 1169 | bExpired = false; |
| 1170 | break; |
| 1171 | } |
| 1172 | VNTWIFIbMeasureReport(pDevice->pMgmt, |
| 1173 | false, |
| 1174 | pDevice->pCurrMeasureEID, |
| 1175 | MEASURE_MODE_LATE, |
| 1176 | pDevice->byBasicMap, |
| 1177 | pDevice->byCCAFraction, |
| 1178 | pDevice->abyRPIs |
| 1179 | ); |
| 1180 | } else { |
| 1181 | // hardware do not support measure |
| 1182 | VNTWIFIbMeasureReport(pDevice->pMgmt, |
| 1183 | false, |
| 1184 | pDevice->pCurrMeasureEID, |
| 1185 | MEASURE_MODE_INCAPABLE, |
| 1186 | pDevice->byBasicMap, |
| 1187 | pDevice->byCCAFraction, |
| 1188 | pDevice->abyRPIs |
| 1189 | ); |
| 1190 | } |
| 1191 | } while (pDevice->uNumOfMeasureEIDs != 0); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1192 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1193 | if (bExpired == false) { |
| 1194 | MACvSelectPage1(pDevice->PortOffset); |
| 1195 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF)); |
| 1196 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF)); |
| 1197 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration); |
| 1198 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN); |
| 1199 | MACvSelectPage0(pDevice->PortOffset); |
| 1200 | } else { |
| 1201 | // all measure start time expired we should complete action |
| 1202 | VNTWIFIbMeasureReport(pDevice->pMgmt, |
| 1203 | true, |
| 1204 | NULL, |
| 1205 | 0, |
| 1206 | pDevice->byBasicMap, |
| 1207 | pDevice->byCCAFraction, |
| 1208 | pDevice->abyRPIs |
| 1209 | ); |
| 1210 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1211 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1214 | /* |
| 1215 | * |
| 1216 | * Description: |
| 1217 | * Do Channel Switch defined in 802.11h |
| 1218 | * |
| 1219 | * Parameters: |
| 1220 | * In: |
| 1221 | * hDeviceContext - device structure point |
| 1222 | * Out: |
| 1223 | * none |
| 1224 | * |
| 1225 | * Return Value: none. |
| 1226 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1227 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 1228 | bool |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1229 | CARDbChannelSwitch( |
| 1230 | void *pDeviceHandler, |
| 1231 | unsigned char byMode, |
| 1232 | unsigned char byNewChannel, |
| 1233 | unsigned char byCount |
| 1234 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1235 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1236 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1237 | bool bResult = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1238 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1239 | if (byCount == 0) { |
| 1240 | bResult = set_channel(pDevice, byNewChannel); |
| 1241 | VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel); |
| 1242 | MACvSelectPage1(pDevice->PortOffset); |
| 1243 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE); |
| 1244 | MACvSelectPage0(pDevice->PortOffset); |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1245 | return bResult; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1246 | } |
| 1247 | pDevice->byChannelSwitchCount = byCount; |
| 1248 | pDevice->byNewChannel = byNewChannel; |
| 1249 | pDevice->bChannelSwitch = true; |
| 1250 | if (byMode == 1) { |
| 1251 | bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL); |
| 1252 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1253 | return bResult; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1256 | /* |
| 1257 | * |
| 1258 | * Description: |
| 1259 | * Handle Quiet EID defined in 802.11h |
| 1260 | * |
| 1261 | * Parameters: |
| 1262 | * In: |
| 1263 | * hDeviceContext - device structure point |
| 1264 | * Out: |
| 1265 | * none |
| 1266 | * |
| 1267 | * Return Value: none. |
| 1268 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1269 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 1270 | bool |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1271 | CARDbSetQuiet( |
| 1272 | void *pDeviceHandler, |
| 1273 | bool bResetQuiet, |
| 1274 | unsigned char byQuietCount, |
| 1275 | unsigned char byQuietPeriod, |
| 1276 | unsigned short wQuietDuration, |
| 1277 | unsigned short wQuietOffset |
| 1278 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1279 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1280 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1281 | unsigned int ii = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1282 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1283 | if (bResetQuiet == true) { |
| 1284 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN)); |
| 1285 | for (ii = 0; ii < MAX_QUIET_COUNT; ii++) { |
| 1286 | pDevice->sQuiet[ii].bEnable = false; |
| 1287 | } |
| 1288 | pDevice->uQuietEnqueue = 0; |
| 1289 | pDevice->bEnableFirstQuiet = false; |
| 1290 | pDevice->bQuietEnable = false; |
| 1291 | pDevice->byQuietStartCount = byQuietCount; |
| 1292 | } |
| 1293 | if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) { |
| 1294 | pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true; |
| 1295 | pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod; |
| 1296 | pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration; |
| 1297 | pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount; |
| 1298 | pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval; |
| 1299 | pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset; |
| 1300 | pDevice->uQuietEnqueue++; |
| 1301 | pDevice->uQuietEnqueue %= MAX_QUIET_COUNT; |
| 1302 | if (pDevice->byQuietStartCount < byQuietCount) { |
| 1303 | pDevice->byQuietStartCount = byQuietCount; |
| 1304 | } |
| 1305 | } else { |
| 1306 | // we can not handle Quiet EID more |
| 1307 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1308 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1311 | /* |
| 1312 | * |
| 1313 | * Description: |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1314 | * Do Quiet, It will be called by either ISR(after start) |
Justin P. Mattock | 789d1ae | 2012-08-20 08:43:13 -0700 | [diff] [blame] | 1315 | * or VNTWIFI(before start) so we do not need a SPINLOCK |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1316 | * |
| 1317 | * Parameters: |
| 1318 | * In: |
| 1319 | * hDeviceContext - device structure point |
| 1320 | * Out: |
| 1321 | * none |
| 1322 | * |
| 1323 | * Return Value: none. |
| 1324 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1325 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 1326 | bool |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1327 | CARDbStartQuiet( |
| 1328 | void *pDeviceHandler |
| 1329 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1330 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1331 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1332 | unsigned int ii = 0; |
| 1333 | unsigned long dwStartTime = 0xFFFFFFFF; |
| 1334 | unsigned int uCurrentQuietIndex = 0; |
| 1335 | unsigned long dwNextTime = 0; |
| 1336 | unsigned long dwGap = 0; |
| 1337 | unsigned long dwDuration = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1338 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1339 | for (ii = 0; ii < MAX_QUIET_COUNT; ii++) { |
| 1340 | if ((pDevice->sQuiet[ii].bEnable == true) && |
| 1341 | (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) { |
| 1342 | dwStartTime = pDevice->sQuiet[ii].dwStartTime; |
| 1343 | uCurrentQuietIndex = ii; |
| 1344 | } |
| 1345 | } |
| 1346 | if (dwStartTime == 0xFFFFFFFF) { |
| 1347 | // no more quiet |
| 1348 | pDevice->bQuietEnable = false; |
| 1349 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN)); |
| 1350 | } else { |
| 1351 | if (pDevice->bQuietEnable == false) { |
| 1352 | // first quiet |
| 1353 | pDevice->byQuietStartCount--; |
| 1354 | dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime; |
| 1355 | dwNextTime %= pDevice->wBeaconInterval; |
| 1356 | MACvSelectPage1(pDevice->PortOffset); |
| 1357 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime); |
| 1358 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration); |
| 1359 | if (pDevice->byQuietStartCount == 0) { |
| 1360 | pDevice->bEnableFirstQuiet = false; |
| 1361 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN)); |
| 1362 | } else { |
| 1363 | pDevice->bEnableFirstQuiet = true; |
| 1364 | } |
| 1365 | MACvSelectPage0(pDevice->PortOffset); |
| 1366 | } else { |
| 1367 | if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) { |
| 1368 | // overlap with previous Quiet |
| 1369 | dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime; |
| 1370 | if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) { |
| 1371 | // return false to indicate next quiet expired, should call this function again |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1372 | return false; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1373 | } |
| 1374 | dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap; |
| 1375 | dwGap = 0; |
| 1376 | } else { |
| 1377 | dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime; |
| 1378 | dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration; |
| 1379 | } |
| 1380 | // set GAP and Next duration |
| 1381 | MACvSelectPage1(pDevice->PortOffset); |
| 1382 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap); |
| 1383 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration); |
| 1384 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT); |
| 1385 | MACvSelectPage0(pDevice->PortOffset); |
| 1386 | } |
| 1387 | pDevice->bQuietEnable = true; |
| 1388 | pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime; |
| 1389 | pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration; |
| 1390 | if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) { |
| 1391 | // not period disable current quiet element |
| 1392 | pDevice->sQuiet[uCurrentQuietIndex].bEnable = false; |
| 1393 | } else { |
| 1394 | // set next period start time |
| 1395 | dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod; |
| 1396 | dwNextTime *= pDevice->wBeaconInterval; |
| 1397 | pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime; |
| 1398 | } |
| 1399 | if (pDevice->dwCurrentQuietEndTime > 0x80010000) { |
| 1400 | // decreament all time to avoid wrap around |
| 1401 | for (ii = 0; ii < MAX_QUIET_COUNT; ii++) { |
| 1402 | if (pDevice->sQuiet[ii].bEnable == true) { |
| 1403 | pDevice->sQuiet[ii].dwStartTime -= 0x80000000; |
| 1404 | } |
| 1405 | } |
| 1406 | pDevice->dwCurrentQuietEndTime -= 0x80000000; |
| 1407 | } |
| 1408 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1409 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1412 | /* |
| 1413 | * |
| 1414 | * Description: |
| 1415 | * Set Local Power Constraint |
| 1416 | * |
| 1417 | * Parameters: |
| 1418 | * In: |
| 1419 | * hDeviceContext - device structure point |
| 1420 | * Out: |
| 1421 | * none |
| 1422 | * |
| 1423 | * Return Value: none. |
| 1424 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1425 | -*/ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 1426 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1427 | CARDvSetPowerConstraint( |
| 1428 | void *pDeviceHandler, |
| 1429 | unsigned char byChannel, |
| 1430 | char byPower |
| 1431 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1432 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1433 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1434 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1435 | if (byChannel > CB_MAX_CHANNEL_24G) { |
| 1436 | if (pDevice->bCountryInfo5G == true) { |
| 1437 | pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower; |
| 1438 | } |
| 1439 | } else { |
| 1440 | if (pDevice->bCountryInfo24G == true) { |
| 1441 | pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower; |
| 1442 | } |
| 1443 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1444 | } |
| 1445 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1446 | /* |
| 1447 | * |
| 1448 | * Description: |
| 1449 | * Set Local Power Constraint |
| 1450 | * |
| 1451 | * Parameters: |
| 1452 | * In: |
| 1453 | * hDeviceContext - device structure point |
| 1454 | * Out: |
| 1455 | * none |
| 1456 | * |
| 1457 | * Return Value: none. |
| 1458 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1459 | -*/ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 1460 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1461 | CARDvGetPowerCapability( |
| 1462 | void *pDeviceHandler, |
| 1463 | unsigned char *pbyMinPower, |
| 1464 | unsigned char *pbyMaxPower |
| 1465 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1466 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1467 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1468 | unsigned char byDec = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1469 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1470 | *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh]; |
| 1471 | byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh]; |
| 1472 | if (pDevice->byRFType == RF_UW2452) { |
| 1473 | byDec *= 3; |
| 1474 | byDec >>= 1; |
| 1475 | } else { |
| 1476 | byDec <<= 1; |
| 1477 | } |
| 1478 | *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1481 | /* |
| 1482 | * |
| 1483 | * Description: |
| 1484 | * Get Current Tx Power |
| 1485 | * |
| 1486 | * Parameters: |
| 1487 | * In: |
| 1488 | * hDeviceContext - device structure point |
| 1489 | * Out: |
| 1490 | * none |
| 1491 | * |
| 1492 | * Return Value: none. |
| 1493 | * |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 1494 | */ |
Charles Clément | ec28c7f | 2010-05-28 12:34:18 -0700 | [diff] [blame] | 1495 | char |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1496 | CARDbyGetTransmitPower( |
| 1497 | void *pDeviceHandler |
| 1498 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1499 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1500 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1501 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1502 | return pDevice->byCurPwrdBm; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1503 | } |
| 1504 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1505 | //xxx |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 1506 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1507 | CARDvSafeResetTx( |
| 1508 | void *pDeviceHandler |
| 1509 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1510 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1511 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1512 | unsigned int uu; |
| 1513 | PSTxDesc pCurrTD; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1514 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1515 | // initialize TD index |
| 1516 | pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]); |
| 1517 | pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1518 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1519 | for (uu = 0; uu < TYPE_MAXTD; uu++) |
| 1520 | pDevice->iTDUsed[uu] = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1521 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1522 | for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) { |
| 1523 | pCurrTD = &(pDevice->apTD0Rings[uu]); |
| 1524 | pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST; |
| 1525 | // init all Tx Packet pointer to NULL |
| 1526 | } |
| 1527 | for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) { |
| 1528 | pCurrTD = &(pDevice->apTD1Rings[uu]); |
| 1529 | pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST; |
| 1530 | // init all Tx Packet pointer to NULL |
| 1531 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1532 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1533 | // set MAC TD pointer |
| 1534 | MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset, |
| 1535 | (pDevice->td0_pool_dma)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1536 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1537 | MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset, |
| 1538 | (pDevice->td1_pool_dma)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1539 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1540 | // set MAC Beacon TX pointer |
| 1541 | MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, |
| 1542 | (pDevice->tx_beacon_dma)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1545 | /*+ |
| 1546 | * |
| 1547 | * Description: |
| 1548 | * Reset Rx |
| 1549 | * |
| 1550 | * Parameters: |
| 1551 | * In: |
| 1552 | * pDevice - Pointer to the adapter |
| 1553 | * Out: |
| 1554 | * none |
| 1555 | * |
| 1556 | * Return Value: none |
| 1557 | * |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1558 | -*/ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 1559 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1560 | CARDvSafeResetRx( |
| 1561 | void *pDeviceHandler |
| 1562 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1563 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1564 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1565 | unsigned int uu; |
| 1566 | PSRxDesc pDesc; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1567 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1568 | // initialize RD index |
| 1569 | pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]); |
| 1570 | pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1571 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1572 | // init state, all RD is chip's |
| 1573 | for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) { |
| 1574 | pDesc = &(pDevice->aRD0Ring[uu]); |
| 1575 | pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz); |
| 1576 | pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC; |
| 1577 | pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz); |
| 1578 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1579 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1580 | // init state, all RD is chip's |
| 1581 | for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) { |
| 1582 | pDesc = &(pDevice->aRD1Ring[uu]); |
| 1583 | pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz); |
| 1584 | pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC; |
| 1585 | pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz); |
| 1586 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1587 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1588 | pDevice->cbDFCB = CB_MAX_RX_FRAG; |
| 1589 | pDevice->cbFreeDFCB = pDevice->cbDFCB; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1590 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1591 | // set perPkt mode |
| 1592 | MACvRx0PerPktMode(pDevice->PortOffset); |
| 1593 | MACvRx1PerPktMode(pDevice->PortOffset); |
| 1594 | // set MAC RD pointer |
| 1595 | MACvSetCurrRx0DescAddr(pDevice->PortOffset, |
| 1596 | pDevice->rd0_pool_dma); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1597 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1598 | MACvSetCurrRx1DescAddr(pDevice->PortOffset, |
| 1599 | pDevice->rd1_pool_dma); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1602 | /* |
| 1603 | * Description: Get response Control frame rate in CCK mode |
| 1604 | * |
| 1605 | * Parameters: |
| 1606 | * In: |
| 1607 | * pDevice - The adapter to be set |
| 1608 | * wRateIdx - Receiving data rate |
| 1609 | * Out: |
| 1610 | * none |
| 1611 | * |
| 1612 | * Return Value: response Control frame rate |
| 1613 | * |
| 1614 | */ |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 1615 | unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1616 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1617 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1618 | unsigned int ui = (unsigned int) wRateIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1619 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1620 | while (ui > RATE_1M) { |
| 1621 | if (pDevice->wBasicRate & ((unsigned short)1 << ui)) { |
| 1622 | return (unsigned short)ui; |
| 1623 | } |
| 1624 | ui--; |
| 1625 | } |
| 1626 | return (unsigned short)RATE_1M; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | /* |
| 1630 | * Description: Get response Control frame rate in OFDM mode |
| 1631 | * |
| 1632 | * Parameters: |
| 1633 | * In: |
| 1634 | * pDevice - The adapter to be set |
| 1635 | * wRateIdx - Receiving data rate |
| 1636 | * Out: |
| 1637 | * none |
| 1638 | * |
| 1639 | * Return Value: response Control frame rate |
| 1640 | * |
| 1641 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1642 | unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1643 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1644 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1645 | unsigned int ui = (unsigned int) wRateIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1646 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1647 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1648 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1649 | if (!CARDbIsOFDMinBasicRate((void *)pDevice)) { |
| 1650 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx); |
| 1651 | if (wRateIdx > RATE_24M) |
| 1652 | wRateIdx = RATE_24M; |
| 1653 | return wRateIdx; |
| 1654 | } |
| 1655 | while (ui > RATE_11M) { |
| 1656 | if (pDevice->wBasicRate & ((unsigned short)1 << ui)) { |
| 1657 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui); |
| 1658 | return (unsigned short)ui; |
| 1659 | } |
| 1660 | ui--; |
| 1661 | } |
| 1662 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n"); |
| 1663 | return (unsigned short)RATE_24M; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1666 | /* |
| 1667 | * Description: Set RSPINF |
| 1668 | * |
| 1669 | * Parameters: |
| 1670 | * In: |
| 1671 | * pDevice - The adapter to be set |
| 1672 | * Out: |
| 1673 | * none |
| 1674 | * |
| 1675 | * Return Value: None. |
| 1676 | * |
| 1677 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1678 | void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1679 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1680 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1681 | unsigned char byServ = 0x00, bySignal = 0x00; //For CCK |
| 1682 | unsigned short wLen = 0x0000; |
| 1683 | unsigned char byTxRate, byRsvTime; //For OFDM |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1684 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1685 | //Set to Page1 |
| 1686 | MACvSelectPage1(pDevice->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1687 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1688 | //RSPINF_b_1 |
| 1689 | BBvCalculateParameter(pDevice, |
| 1690 | 14, |
| 1691 | CARDwGetCCKControlRate((void *)pDevice, RATE_1M), |
| 1692 | PK_TYPE_11B, |
| 1693 | &wLen, |
| 1694 | &byServ, |
| 1695 | &bySignal |
| 1696 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1697 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1698 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 1699 | ///RSPINF_b_2 |
| 1700 | BBvCalculateParameter(pDevice, |
| 1701 | 14, |
| 1702 | CARDwGetCCKControlRate((void *)pDevice, RATE_2M), |
| 1703 | PK_TYPE_11B, |
| 1704 | &wLen, |
| 1705 | &byServ, |
| 1706 | &bySignal |
| 1707 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1708 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1709 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 1710 | //RSPINF_b_5 |
| 1711 | BBvCalculateParameter(pDevice, |
| 1712 | 14, |
| 1713 | CARDwGetCCKControlRate((void *)pDevice, RATE_5M), |
| 1714 | PK_TYPE_11B, |
| 1715 | &wLen, |
| 1716 | &byServ, |
| 1717 | &bySignal |
| 1718 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1719 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1720 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 1721 | //RSPINF_b_11 |
| 1722 | BBvCalculateParameter(pDevice, |
| 1723 | 14, |
| 1724 | CARDwGetCCKControlRate((void *)pDevice, RATE_11M), |
| 1725 | PK_TYPE_11B, |
| 1726 | &wLen, |
| 1727 | &byServ, |
| 1728 | &bySignal |
| 1729 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1730 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1731 | VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ))); |
| 1732 | //RSPINF_a_6 |
| 1733 | s_vCalculateOFDMRParameter(RATE_6M, |
| 1734 | ePHYType, |
| 1735 | &byTxRate, |
| 1736 | &byRsvTime); |
| 1737 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime)); |
| 1738 | //RSPINF_a_9 |
| 1739 | s_vCalculateOFDMRParameter(RATE_9M, |
| 1740 | ePHYType, |
| 1741 | &byTxRate, |
| 1742 | &byRsvTime); |
| 1743 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime)); |
| 1744 | //RSPINF_a_12 |
| 1745 | s_vCalculateOFDMRParameter(RATE_12M, |
| 1746 | ePHYType, |
| 1747 | &byTxRate, |
| 1748 | &byRsvTime); |
| 1749 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime)); |
| 1750 | //RSPINF_a_18 |
| 1751 | s_vCalculateOFDMRParameter(RATE_18M, |
| 1752 | ePHYType, |
| 1753 | &byTxRate, |
| 1754 | &byRsvTime); |
| 1755 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime)); |
| 1756 | //RSPINF_a_24 |
| 1757 | s_vCalculateOFDMRParameter(RATE_24M, |
| 1758 | ePHYType, |
| 1759 | &byTxRate, |
| 1760 | &byRsvTime); |
| 1761 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime)); |
| 1762 | //RSPINF_a_36 |
| 1763 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M), |
| 1764 | ePHYType, |
| 1765 | &byTxRate, |
| 1766 | &byRsvTime); |
| 1767 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime)); |
| 1768 | //RSPINF_a_48 |
| 1769 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M), |
| 1770 | ePHYType, |
| 1771 | &byTxRate, |
| 1772 | &byRsvTime); |
| 1773 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime)); |
| 1774 | //RSPINF_a_54 |
| 1775 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M), |
| 1776 | ePHYType, |
| 1777 | &byTxRate, |
| 1778 | &byRsvTime); |
| 1779 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1780 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1781 | //RSPINF_a_72 |
| 1782 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M), |
| 1783 | ePHYType, |
| 1784 | &byTxRate, |
| 1785 | &byRsvTime); |
| 1786 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime)); |
| 1787 | //Set to Page0 |
| 1788 | MACvSelectPage0(pDevice->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | /* |
| 1792 | * Description: Update IFS |
| 1793 | * |
| 1794 | * Parameters: |
| 1795 | * In: |
| 1796 | * pDevice - The adapter to be set |
| 1797 | * Out: |
| 1798 | * none |
| 1799 | * |
| 1800 | * Return Value: None. |
| 1801 | * |
| 1802 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1803 | void vUpdateIFS(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1804 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1805 | //Set SIFS, DIFS, EIFS, SlotTime, CwMin |
| 1806 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1807 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1808 | unsigned char byMaxMin = 0; |
| 1809 | if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a |
| 1810 | pDevice->uSlot = C_SLOT_SHORT; |
| 1811 | pDevice->uSIFS = C_SIFS_A; |
| 1812 | pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT; |
| 1813 | pDevice->uCwMin = C_CWMIN_A; |
| 1814 | byMaxMin = 4; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 1815 | } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1816 | pDevice->uSlot = C_SLOT_LONG; |
| 1817 | pDevice->uSIFS = C_SIFS_BG; |
| 1818 | pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG; |
| 1819 | pDevice->uCwMin = C_CWMIN_B; |
| 1820 | byMaxMin = 5; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 1821 | } else { // PK_TYPE_11GA & PK_TYPE_11GB |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1822 | pDevice->uSIFS = C_SIFS_BG; |
| 1823 | if (pDevice->bShortSlotTime) { |
| 1824 | pDevice->uSlot = C_SLOT_SHORT; |
| 1825 | } else { |
| 1826 | pDevice->uSlot = C_SLOT_LONG; |
| 1827 | } |
| 1828 | pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot; |
| 1829 | if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M |
| 1830 | pDevice->uCwMin = C_CWMIN_A; |
| 1831 | byMaxMin = 4; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 1832 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1833 | pDevice->uCwMin = C_CWMIN_B; |
| 1834 | byMaxMin = 5; |
| 1835 | } |
| 1836 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1837 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1838 | pDevice->uCwMax = C_CWMAX; |
| 1839 | pDevice->uEIFS = C_EIFS; |
| 1840 | if (pDevice->byRFType == RF_RFMD2959) { |
| 1841 | // bcs TX_PE will reserve 3 us |
| 1842 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3)); |
| 1843 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3)); |
| 1844 | } else { |
| 1845 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS); |
| 1846 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS); |
| 1847 | } |
| 1848 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS); |
| 1849 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot); |
| 1850 | byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023 |
| 1851 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1852 | } |
| 1853 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1854 | void CARDvUpdateBasicTopRate(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1855 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1856 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1857 | unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M; |
| 1858 | unsigned char ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1859 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1860 | //Determines the highest basic rate. |
| 1861 | for (ii = RATE_54M; ii >= RATE_6M; ii--) { |
| 1862 | if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) { |
| 1863 | byTopOFDM = ii; |
| 1864 | break; |
| 1865 | } |
| 1866 | } |
| 1867 | pDevice->byTopOFDMBasicRate = byTopOFDM; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1868 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1869 | for (ii = RATE_11M;; ii--) { |
| 1870 | if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) { |
| 1871 | byTopCCK = ii; |
| 1872 | break; |
| 1873 | } |
| 1874 | if (ii == RATE_1M) |
| 1875 | break; |
| 1876 | } |
| 1877 | pDevice->byTopCCKBasicRate = byTopCCK; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1878 | } |
| 1879 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1880 | /* |
| 1881 | * Description: Set NIC Tx Basic Rate |
| 1882 | * |
| 1883 | * Parameters: |
| 1884 | * In: |
| 1885 | * pDevice - The adapter to be set |
| 1886 | * wBasicRate - Basic Rate to be set |
| 1887 | * Out: |
| 1888 | * none |
| 1889 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 1890 | * Return Value: true if succeeded; false if failed. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1891 | * |
| 1892 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1893 | bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1894 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1895 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
| 1896 | unsigned short wRate = (unsigned short)(1<<wRateIdx); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1897 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1898 | pDevice->wBasicRate |= wRate; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1899 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1900 | //Determines the highest basic rate. |
| 1901 | CARDvUpdateBasicTopRate((void *)pDevice); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1902 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 1903 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1904 | } |
| 1905 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1906 | bool CARDbIsOFDMinBasicRate(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1907 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1908 | PSDevice pDevice = (PSDevice)pDeviceHandler; |
| 1909 | int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1910 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1911 | for (ii = RATE_54M; ii >= RATE_6M; ii--) { |
| 1912 | if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii))) |
| 1913 | return true; |
| 1914 | } |
| 1915 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1916 | } |
| 1917 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1918 | unsigned char CARDbyGetPktType(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1919 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1920 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1921 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1922 | if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) { |
| 1923 | return (unsigned char)pDevice->byBBType; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 1924 | } else if (CARDbIsOFDMinBasicRate((void *)pDevice)) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1925 | return PK_TYPE_11GA; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 1926 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1927 | return PK_TYPE_11GB; |
| 1928 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | /* |
| 1932 | * Description: Set NIC Loopback mode |
| 1933 | * |
| 1934 | * Parameters: |
| 1935 | * In: |
| 1936 | * pDevice - The adapter to be set |
| 1937 | * wLoopbackMode - Loopback mode to be set |
| 1938 | * Out: |
| 1939 | * none |
| 1940 | * |
| 1941 | * Return Value: none |
| 1942 | * |
| 1943 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1944 | void CARDvSetLoopbackMode(unsigned long dwIoBase, unsigned short wLoopbackMode) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1945 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1946 | switch (wLoopbackMode) { |
| 1947 | case CARD_LB_NONE: |
| 1948 | case CARD_LB_MAC: |
| 1949 | case CARD_LB_PHY: |
| 1950 | break; |
| 1951 | default: |
| 1952 | ASSERT(false); |
| 1953 | break; |
| 1954 | } |
| 1955 | // set MAC loopback |
| 1956 | MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode)); |
| 1957 | // set Baseband loopback |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1958 | } |
| 1959 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1960 | /* |
| 1961 | * Description: Software Reset NIC |
| 1962 | * |
| 1963 | * Parameters: |
| 1964 | * In: |
| 1965 | * pDevice - The adapter to be reset |
| 1966 | * Out: |
| 1967 | * none |
| 1968 | * |
| 1969 | * Return Value: none |
| 1970 | * |
| 1971 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1972 | bool CARDbSoftwareReset(void *pDeviceHandler) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1973 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1974 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1975 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1976 | // reset MAC |
| 1977 | if (!MACbSafeSoftwareReset(pDevice->PortOffset)) |
| 1978 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1979 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1980 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1983 | /* |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 1984 | * Description: Calculate TSF offset of two TSF input |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1985 | * Get TSF Offset from RxBCN's TSF and local TSF |
| 1986 | * |
| 1987 | * Parameters: |
| 1988 | * In: |
| 1989 | * pDevice - The adapter to be sync. |
| 1990 | * qwTSF1 - Rx BCN's TSF |
| 1991 | * qwTSF2 - Local TSF |
| 1992 | * Out: |
| 1993 | * none |
| 1994 | * |
| 1995 | * Return Value: TSF Offset value |
| 1996 | * |
| 1997 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1998 | QWORD CARDqGetTSFOffset(unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1999 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2000 | QWORD qwTSFOffset; |
| 2001 | unsigned short wRxBcnTSFOffst = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2002 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2003 | HIDWORD(qwTSFOffset) = 0; |
| 2004 | LODWORD(qwTSFOffset) = 0; |
| 2005 | wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE]; |
| 2006 | (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst); |
| 2007 | if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) { |
| 2008 | (qwTSF2).u.dwHighDword++; |
| 2009 | } |
| 2010 | LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2); |
| 2011 | if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) { |
| 2012 | // if borrow needed |
| 2013 | HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 2014 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2015 | HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2); |
| 2016 | }; |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 2017 | return qwTSFOffset; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2018 | } |
| 2019 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2020 | /* |
| 2021 | * Description: Read NIC TSF counter |
| 2022 | * Get local TSF counter |
| 2023 | * |
| 2024 | * Parameters: |
| 2025 | * In: |
| 2026 | * pDevice - The adapter to be read |
| 2027 | * Out: |
| 2028 | * qwCurrTSF - Current TSF counter |
| 2029 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 2030 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2031 | * |
| 2032 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2033 | bool CARDbGetCurrentTSF(unsigned long dwIoBase, PQWORD pqwCurrTSF) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2034 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2035 | unsigned short ww; |
| 2036 | unsigned char byData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2037 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2038 | MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD); |
| 2039 | for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { |
| 2040 | VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData); |
| 2041 | if (!(byData & TFTCTL_TSFCNTRRD)) |
| 2042 | break; |
| 2043 | } |
| 2044 | if (ww == W_MAX_TIMEOUT) |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 2045 | return false; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2046 | VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF)); |
| 2047 | VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2048 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 2049 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2050 | } |
| 2051 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2052 | /* |
| 2053 | * Description: Read NIC TSF counter |
| 2054 | * Get NEXTTBTT from adjusted TSF and Beacon Interval |
| 2055 | * |
| 2056 | * Parameters: |
| 2057 | * In: |
| 2058 | * qwTSF - Current TSF counter |
| 2059 | * wbeaconInterval - Beacon Interval |
| 2060 | * Out: |
| 2061 | * qwCurrTSF - Current TSF counter |
| 2062 | * |
| 2063 | * Return Value: TSF value of next Beacon |
| 2064 | * |
| 2065 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2066 | QWORD CARDqGetNextTBTT(QWORD qwTSF, unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2067 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2068 | unsigned int uLowNextTBTT; |
| 2069 | unsigned int uHighRemain, uLowRemain; |
| 2070 | unsigned int uBeaconInterval; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2071 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2072 | uBeaconInterval = wBeaconInterval * 1024; |
| 2073 | // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval |
| 2074 | uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10; |
| 2075 | // low dword (mod) bcn |
| 2076 | uLowRemain = (uLowNextTBTT) % uBeaconInterval; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2077 | // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF)) |
| 2078 | // % uBeaconInterval; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2079 | // high dword (mod) bcn |
| 2080 | uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF)) |
| 2081 | % uBeaconInterval; |
| 2082 | uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; |
| 2083 | uLowRemain = uBeaconInterval - uLowRemain; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2084 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2085 | // check if carry when add one beacon interval |
| 2086 | if ((~uLowNextTBTT) < uLowRemain) |
| 2087 | HIDWORD(qwTSF)++; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2088 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2089 | LODWORD(qwTSF) = uLowNextTBTT + uLowRemain; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2090 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 2091 | return qwTSF; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2092 | } |
| 2093 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2094 | /* |
| 2095 | * Description: Set NIC TSF counter for first Beacon time |
| 2096 | * Get NEXTTBTT from adjusted TSF and Beacon Interval |
| 2097 | * |
| 2098 | * Parameters: |
| 2099 | * In: |
| 2100 | * dwIoBase - IO Base |
| 2101 | * wBeaconInterval - Beacon Interval |
| 2102 | * Out: |
| 2103 | * none |
| 2104 | * |
| 2105 | * Return Value: none |
| 2106 | * |
| 2107 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2108 | void CARDvSetFirstNextTBTT(unsigned long dwIoBase, unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2109 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2110 | QWORD qwNextTBTT; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2111 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2112 | HIDWORD(qwNextTBTT) = 0; |
| 2113 | LODWORD(qwNextTBTT) = 0; |
| 2114 | CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter |
| 2115 | qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); |
| 2116 | // Set NextTBTT |
| 2117 | VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT)); |
| 2118 | VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT)); |
| 2119 | MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); |
| 2120 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT)); |
| 2121 | return; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2122 | } |
| 2123 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2124 | /* |
| 2125 | * Description: Sync NIC TSF counter for Beacon time |
| 2126 | * Get NEXTTBTT and write to HW |
| 2127 | * |
| 2128 | * Parameters: |
| 2129 | * In: |
| 2130 | * pDevice - The adapter to be set |
| 2131 | * qwTSF - Current TSF counter |
| 2132 | * wBeaconInterval - Beacon Interval |
| 2133 | * Out: |
| 2134 | * none |
| 2135 | * |
| 2136 | * Return Value: none |
| 2137 | * |
| 2138 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2139 | void CARDvUpdateNextTBTT(unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2140 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2141 | qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); |
| 2142 | // Set NextTBTT |
| 2143 | VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF)); |
| 2144 | VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF)); |
| 2145 | MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); |
| 2146 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8xh:%8xh] \n", |
| 2147 | (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2148 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 2149 | return; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 2150 | } |