Forest Bond | 92b9679 | 2009-06-13 07:38:31 -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 | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 31 | * CARDqGetTSFOffset - Calculate TSFOffset |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 32 | * CARDbGetCurrentTSF - Read Current NIC TSF counter |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 33 | * CARDqGetNextTBTT - Calculate Next Beacon TSF counter |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -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. |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 43 | * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 44 | * 09-01-2003 Bryan YC Fan: Add vUpdateIFS(). |
| 45 | * |
| 46 | */ |
| 47 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 48 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 49 | #include "tmacro.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 50 | #include "card.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 51 | #include "baseband.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 52 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 53 | #include "desc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 54 | #include "rf.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 55 | #include "power.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 56 | #include "key.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | #include "rc4.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 58 | #include "country.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 59 | #include "datarate.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 60 | #include "rndis.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 61 | #include "control.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 62 | |
| 63 | /*--------------------- Static Definitions -------------------------*/ |
| 64 | |
| 65 | //static int msglevel =MSG_LEVEL_DEBUG; |
| 66 | static int msglevel =MSG_LEVEL_INFO; |
| 67 | |
| 68 | |
| 69 | /*--------------------- Static Definitions -------------------------*/ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 70 | |
| 71 | /*--------------------- Static Classes ----------------------------*/ |
| 72 | |
| 73 | /*--------------------- Static Variables --------------------------*/ |
| 74 | //const WORD cwRXBCNTSFOff[MAX_RATE] = |
| 75 | //{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3}; |
| 76 | |
| 77 | const WORD cwRXBCNTSFOff[MAX_RATE] = |
| 78 | {192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3}; |
| 79 | |
| 80 | /*--------------------- Static Functions --------------------------*/ |
| 81 | |
| 82 | /*--------------------- Export Variables --------------------------*/ |
| 83 | |
| 84 | /*--------------------- Export Functions --------------------------*/ |
| 85 | /* |
| 86 | * Description: Set NIC media channel |
| 87 | * |
| 88 | * Parameters: |
| 89 | * In: |
| 90 | * pDevice - The adapter to be set |
| 91 | * uConnectionChannel - Channel to be set |
| 92 | * Out: |
| 93 | * none |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 94 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 95 | void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 96 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 97 | |
| 98 | if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38 |
| 99 | if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL)) |
| 100 | uConnectionChannel = (CB_MAX_CHANNEL_24G+1); |
| 101 | } else { |
| 102 | if ((uConnectionChannel > CB_MAX_CHANNEL_24G) || (uConnectionChannel == 0)) // 1 ~ 14 |
| 103 | uConnectionChannel = 1; |
| 104 | } |
| 105 | |
| 106 | // clear NAV |
| 107 | MACvRegBitsOn(pDevice, MAC_REG_MACCR, MACCR_CLRNAV); |
| 108 | |
| 109 | // Set Channel[7] = 0 to tell H/W channel is changing now. |
| 110 | MACvRegBitsOff(pDevice, MAC_REG_CHANNEL, 0x80); |
| 111 | |
| 112 | //if (pMgmt->uCurrChannel == uConnectionChannel) |
| 113 | // return bResult; |
| 114 | |
| 115 | CONTROLnsRequestOut(pDevice, |
| 116 | MESSAGE_TYPE_SELECT_CHANNLE, |
| 117 | (WORD) uConnectionChannel, |
| 118 | 0, |
| 119 | 0, |
| 120 | NULL |
| 121 | ); |
| 122 | |
| 123 | //{{ RobertYu: 20041202 |
| 124 | //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput |
| 125 | |
| 126 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 127 | pDevice->byCurPwr = 0xFF; |
| 128 | RFbRawSetPower(pDevice, pDevice->abyOFDMAPwrTbl[uConnectionChannel-15], RATE_54M); |
| 129 | } else if (pDevice->byBBType == BB_TYPE_11G) { |
| 130 | pDevice->byCurPwr = 0xFF; |
| 131 | RFbRawSetPower(pDevice, pDevice->abyOFDMPwrTbl[uConnectionChannel-1], RATE_54M); |
| 132 | } else { |
| 133 | pDevice->byCurPwr = 0xFF; |
| 134 | RFbRawSetPower(pDevice, pDevice->abyCCKPwrTbl[uConnectionChannel-1], RATE_1M); |
| 135 | } |
| 136 | ControlvWriteByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_CHANNEL,(BYTE)(uConnectionChannel|0x80)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Description: Get CCK mode basic rate |
| 141 | * |
| 142 | * Parameters: |
| 143 | * In: |
| 144 | * pDevice - The adapter to be set |
| 145 | * wRateIdx - Receiving data rate |
| 146 | * Out: |
| 147 | * none |
| 148 | * |
| 149 | * Return Value: response Control frame rate |
| 150 | * |
| 151 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 152 | static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 153 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 154 | u16 ui = wRateIdx; |
| 155 | |
| 156 | while (ui > RATE_1M) { |
| 157 | if (pDevice->wBasicRate & (1 << ui)) |
| 158 | return ui; |
| 159 | ui--; |
| 160 | } |
| 161 | |
| 162 | return RATE_1M; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Description: Get OFDM mode basic rate |
| 167 | * |
| 168 | * Parameters: |
| 169 | * In: |
| 170 | * pDevice - The adapter to be set |
| 171 | * wRateIdx - Receiving data rate |
| 172 | * Out: |
| 173 | * none |
| 174 | * |
| 175 | * Return Value: response Control frame rate |
| 176 | * |
| 177 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 178 | static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 179 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 180 | u16 ui = wRateIdx; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 181 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 182 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", |
| 183 | pDevice->wBasicRate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 184 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 185 | if (!CARDbIsOFDMinBasicRate(pDevice)) { |
| 186 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 187 | "swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx); |
| 188 | if (wRateIdx > RATE_24M) |
| 189 | wRateIdx = RATE_24M; |
| 190 | return wRateIdx; |
| 191 | } |
| 192 | |
| 193 | while (ui > RATE_11M) { |
| 194 | if (pDevice->wBasicRate & (1 << ui)) { |
| 195 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 196 | "swGetOFDMControlRate: %d\n", ui); |
| 197 | return ui; |
| 198 | } |
| 199 | ui--; |
| 200 | } |
| 201 | |
| 202 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n"); |
| 203 | |
| 204 | return RATE_24M; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /* |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 208 | * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 209 | * |
| 210 | * Parameters: |
| 211 | * In: |
| 212 | * wRate - Tx Rate |
| 213 | * byPktType - Tx Packet type |
| 214 | * Out: |
| 215 | * pbyTxRate - pointer to RSPINF TxRate field |
| 216 | * pbyRsvTime - pointer to RSPINF RsvTime field |
| 217 | * |
| 218 | * Return Value: none |
| 219 | * |
| 220 | */ |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 221 | void |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 222 | CARDvCalculateOFDMRParameter ( |
Andres More | 592ccfe | 2010-04-17 12:07:42 -0300 | [diff] [blame] | 223 | WORD wRate, |
| 224 | BYTE byBBType, |
Andres More | 6f8c13c | 2010-05-04 20:40:10 -0300 | [diff] [blame] | 225 | PBYTE pbyTxRate, |
| 226 | PBYTE pbyRsvTime |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 227 | ) |
| 228 | { |
| 229 | switch (wRate) { |
| 230 | case RATE_6M : |
| 231 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 232 | *pbyTxRate = 0x9B; |
| 233 | *pbyRsvTime = 24; |
| 234 | } |
| 235 | else { |
| 236 | *pbyTxRate = 0x8B; |
| 237 | *pbyRsvTime = 30; |
| 238 | } |
| 239 | break; |
| 240 | |
| 241 | case RATE_9M : |
| 242 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 243 | *pbyTxRate = 0x9F; |
| 244 | *pbyRsvTime = 16; |
| 245 | } |
| 246 | else { |
| 247 | *pbyTxRate = 0x8F; |
| 248 | *pbyRsvTime = 22; |
| 249 | } |
| 250 | break; |
| 251 | |
| 252 | case RATE_12M : |
| 253 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 254 | *pbyTxRate = 0x9A; |
| 255 | *pbyRsvTime = 12; |
| 256 | } |
| 257 | else { |
| 258 | *pbyTxRate = 0x8A; |
| 259 | *pbyRsvTime = 18; |
| 260 | } |
| 261 | break; |
| 262 | |
| 263 | case RATE_18M : |
| 264 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 265 | *pbyTxRate = 0x9E; |
| 266 | *pbyRsvTime = 8; |
| 267 | } |
| 268 | else { |
| 269 | *pbyTxRate = 0x8E; |
| 270 | *pbyRsvTime = 14; |
| 271 | } |
| 272 | break; |
| 273 | |
| 274 | case RATE_36M : |
| 275 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 276 | *pbyTxRate = 0x9D; |
| 277 | *pbyRsvTime = 4; |
| 278 | } |
| 279 | else { |
| 280 | *pbyTxRate = 0x8D; |
| 281 | *pbyRsvTime = 10; |
| 282 | } |
| 283 | break; |
| 284 | |
| 285 | case RATE_48M : |
| 286 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 287 | *pbyTxRate = 0x98; |
| 288 | *pbyRsvTime = 4; |
| 289 | } |
| 290 | else { |
| 291 | *pbyTxRate = 0x88; |
| 292 | *pbyRsvTime = 10; |
| 293 | } |
| 294 | break; |
| 295 | |
| 296 | case RATE_54M : |
| 297 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 298 | *pbyTxRate = 0x9C; |
| 299 | *pbyRsvTime = 4; |
| 300 | } |
| 301 | else { |
| 302 | *pbyTxRate = 0x8C; |
| 303 | *pbyRsvTime = 10; |
| 304 | } |
| 305 | break; |
| 306 | |
| 307 | case RATE_24M : |
| 308 | default : |
| 309 | if (byBBType == BB_TYPE_11A) {//5GHZ |
| 310 | *pbyTxRate = 0x99; |
| 311 | *pbyRsvTime = 8; |
| 312 | } |
| 313 | else { |
| 314 | *pbyTxRate = 0x89; |
| 315 | *pbyRsvTime = 14; |
| 316 | } |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * Description: Set RSPINF |
| 323 | * |
| 324 | * Parameters: |
| 325 | * In: |
| 326 | * pDevice - The adapter to be set |
| 327 | * Out: |
| 328 | * none |
| 329 | * |
| 330 | * Return Value: None. |
| 331 | * |
| 332 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 333 | void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 334 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 335 | u8 abyServ[4] = {0, 0, 0, 0}; /* For CCK */ |
| 336 | u8 abySignal[4] = {0, 0, 0, 0}; |
| 337 | u16 awLen[4] = {0, 0, 0, 0}; |
| 338 | u8 abyTxRate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */ |
| 339 | u8 abyRsvTime[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 340 | u8 abyData[34]; |
| 341 | int i; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 342 | |
| 343 | //RSPINF_b_1 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 344 | BBvCalculateParameter(pDevice, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 345 | 14, |
| 346 | swGetCCKControlRate(pDevice, RATE_1M), |
| 347 | PK_TYPE_11B, |
| 348 | &awLen[0], |
| 349 | &abyServ[0], |
| 350 | &abySignal[0] |
| 351 | ); |
| 352 | |
| 353 | ///RSPINF_b_2 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 354 | BBvCalculateParameter(pDevice, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 355 | 14, |
| 356 | swGetCCKControlRate(pDevice, RATE_2M), |
| 357 | PK_TYPE_11B, |
| 358 | &awLen[1], |
| 359 | &abyServ[1], |
| 360 | &abySignal[1] |
| 361 | ); |
| 362 | |
| 363 | //RSPINF_b_5 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 364 | BBvCalculateParameter(pDevice, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 365 | 14, |
| 366 | swGetCCKControlRate(pDevice, RATE_5M), |
| 367 | PK_TYPE_11B, |
| 368 | &awLen[2], |
| 369 | &abyServ[2], |
| 370 | &abySignal[2] |
| 371 | ); |
| 372 | |
| 373 | //RSPINF_b_11 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 374 | BBvCalculateParameter(pDevice, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 375 | 14, |
| 376 | swGetCCKControlRate(pDevice, RATE_11M), |
| 377 | PK_TYPE_11B, |
| 378 | &awLen[3], |
| 379 | &abyServ[3], |
| 380 | &abySignal[3] |
| 381 | ); |
| 382 | |
| 383 | //RSPINF_a_6 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 384 | CARDvCalculateOFDMRParameter (RATE_6M, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 385 | byBBType, |
| 386 | &abyTxRate[0], |
| 387 | &abyRsvTime[0]); |
| 388 | |
| 389 | //RSPINF_a_9 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 390 | CARDvCalculateOFDMRParameter (RATE_9M, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 391 | byBBType, |
| 392 | &abyTxRate[1], |
| 393 | &abyRsvTime[1]); |
| 394 | |
| 395 | //RSPINF_a_12 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 396 | CARDvCalculateOFDMRParameter (RATE_12M, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 397 | byBBType, |
| 398 | &abyTxRate[2], |
| 399 | &abyRsvTime[2]); |
| 400 | |
| 401 | //RSPINF_a_18 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 402 | CARDvCalculateOFDMRParameter (RATE_18M, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 403 | byBBType, |
| 404 | &abyTxRate[3], |
| 405 | &abyRsvTime[3]); |
| 406 | |
| 407 | //RSPINF_a_24 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 408 | CARDvCalculateOFDMRParameter (RATE_24M, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 409 | byBBType, |
| 410 | &abyTxRate[4], |
| 411 | &abyRsvTime[4]); |
| 412 | |
| 413 | //RSPINF_a_36 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 414 | CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 415 | byBBType, |
| 416 | &abyTxRate[5], |
| 417 | &abyRsvTime[5]); |
| 418 | |
| 419 | //RSPINF_a_48 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 420 | CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 421 | byBBType, |
| 422 | &abyTxRate[6], |
| 423 | &abyRsvTime[6]); |
| 424 | |
| 425 | //RSPINF_a_54 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 426 | CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 427 | byBBType, |
| 428 | &abyTxRate[7], |
| 429 | &abyRsvTime[7]); |
| 430 | |
| 431 | //RSPINF_a_72 |
Justin P. Mattock | bda7978 | 2012-08-26 08:16:44 -0700 | [diff] [blame] | 432 | CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 433 | byBBType, |
| 434 | &abyTxRate[8], |
| 435 | &abyRsvTime[8]); |
| 436 | |
| 437 | abyData[0] = (BYTE)(awLen[0]&0xFF); |
| 438 | abyData[1] = (BYTE)(awLen[0]>>8); |
| 439 | abyData[2] = abySignal[0]; |
| 440 | abyData[3] = abyServ[0]; |
| 441 | |
| 442 | abyData[4] = (BYTE)(awLen[1]&0xFF); |
| 443 | abyData[5] = (BYTE)(awLen[1]>>8); |
| 444 | abyData[6] = abySignal[1]; |
| 445 | abyData[7] = abyServ[1]; |
| 446 | |
| 447 | abyData[8] = (BYTE)(awLen[2]&0xFF); |
| 448 | abyData[9] = (BYTE)(awLen[2]>>8); |
| 449 | abyData[10] = abySignal[2]; |
| 450 | abyData[11] = abyServ[2]; |
| 451 | |
| 452 | abyData[12] = (BYTE)(awLen[3]&0xFF); |
| 453 | abyData[13] = (BYTE)(awLen[3]>>8); |
| 454 | abyData[14] = abySignal[3]; |
| 455 | abyData[15] = abyServ[3]; |
| 456 | |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 457 | for (i = 0; i < 9; i++) { |
| 458 | abyData[16+i*2] = abyTxRate[i]; |
| 459 | abyData[16+i*2+1] = abyRsvTime[i]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 460 | } |
| 461 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 462 | CONTROLnsRequestOut(pDevice, |
| 463 | MESSAGE_TYPE_WRITE, |
| 464 | MAC_REG_RSPINF_B_1, |
| 465 | MESSAGE_REQUEST_MACREG, |
| 466 | 34, |
| 467 | &abyData[0]); |
| 468 | |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Description: Update IFS |
| 473 | * |
| 474 | * Parameters: |
| 475 | * In: |
| 476 | * pDevice - The adapter to be set |
| 477 | * Out: |
| 478 | * none |
| 479 | * |
| 480 | * Return Value: None. |
| 481 | * |
| 482 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 483 | void vUpdateIFS(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 484 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 485 | u8 byMaxMin = 0; |
| 486 | u8 byData[4]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 487 | |
| 488 | if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a |
| 489 | pDevice->uSlot = C_SLOT_SHORT; |
| 490 | pDevice->uSIFS = C_SIFS_A; |
| 491 | pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT; |
| 492 | pDevice->uCwMin = C_CWMIN_A; |
| 493 | byMaxMin = 4; |
| 494 | } |
| 495 | else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b |
| 496 | pDevice->uSlot = C_SLOT_LONG; |
| 497 | pDevice->uSIFS = C_SIFS_BG; |
| 498 | pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG; |
| 499 | pDevice->uCwMin = C_CWMIN_B; |
| 500 | byMaxMin = 5; |
| 501 | } |
| 502 | else {// PK_TYPE_11GA & PK_TYPE_11GB |
| 503 | BYTE byRate = 0; |
| 504 | BOOL bOFDMRate = FALSE; |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 505 | unsigned int ii = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 506 | PWLAN_IE_SUPP_RATES pItemRates = NULL; |
| 507 | |
| 508 | pDevice->uSIFS = C_SIFS_BG; |
| 509 | if (pDevice->bShortSlotTime) { |
| 510 | pDevice->uSlot = C_SLOT_SHORT; |
| 511 | } else { |
| 512 | pDevice->uSlot = C_SLOT_LONG; |
| 513 | } |
| 514 | pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot; |
| 515 | |
| 516 | pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrSuppRates; |
| 517 | for (ii = 0; ii < pItemRates->len; ii++) { |
| 518 | byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); |
| 519 | if (RATEwGetRateIdx(byRate) > RATE_11M) { |
| 520 | bOFDMRate = TRUE; |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | if (bOFDMRate == FALSE) { |
| 525 | pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrExtSuppRates; |
| 526 | for (ii = 0; ii < pItemRates->len; ii++) { |
| 527 | byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); |
| 528 | if (RATEwGetRateIdx(byRate) > RATE_11M) { |
| 529 | bOFDMRate = TRUE; |
| 530 | break; |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | if (bOFDMRate == TRUE) { |
| 535 | pDevice->uCwMin = C_CWMIN_A; |
| 536 | byMaxMin = 4; |
| 537 | } else { |
| 538 | pDevice->uCwMin = C_CWMIN_B; |
| 539 | byMaxMin = 5; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | pDevice->uCwMax = C_CWMAX; |
| 544 | pDevice->uEIFS = C_EIFS; |
| 545 | |
| 546 | byData[0] = (BYTE)pDevice->uSIFS; |
| 547 | byData[1] = (BYTE)pDevice->uDIFS; |
| 548 | byData[2] = (BYTE)pDevice->uEIFS; |
| 549 | byData[3] = (BYTE)pDevice->uSlot; |
| 550 | CONTROLnsRequestOut(pDevice, |
| 551 | MESSAGE_TYPE_WRITE, |
| 552 | MAC_REG_SIFS, |
| 553 | MESSAGE_REQUEST_MACREG, |
| 554 | 4, |
| 555 | &byData[0]); |
| 556 | |
| 557 | byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023 |
| 558 | CONTROLnsRequestOut(pDevice, |
| 559 | MESSAGE_TYPE_WRITE, |
| 560 | MAC_REG_CWMAXMIN0, |
| 561 | MESSAGE_REQUEST_MACREG, |
| 562 | 1, |
| 563 | &byMaxMin); |
| 564 | } |
| 565 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 566 | void CARDvUpdateBasicTopRate(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 567 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 568 | u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M; |
| 569 | u8 ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 570 | |
| 571 | //Determines the highest basic rate. |
| 572 | for (ii = RATE_54M; ii >= RATE_6M; ii --) { |
| 573 | if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) { |
| 574 | byTopOFDM = ii; |
| 575 | break; |
| 576 | } |
| 577 | } |
| 578 | pDevice->byTopOFDMBasicRate = byTopOFDM; |
| 579 | |
| 580 | for (ii = RATE_11M;; ii --) { |
| 581 | if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) { |
| 582 | byTopCCK = ii; |
| 583 | break; |
| 584 | } |
| 585 | if (ii == RATE_1M) |
| 586 | break; |
| 587 | } |
| 588 | pDevice->byTopCCKBasicRate = byTopCCK; |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * Description: Set NIC Tx Basic Rate |
| 593 | * |
| 594 | * Parameters: |
| 595 | * In: |
| 596 | * pDevice - The adapter to be set |
| 597 | * wBasicRate - Basic Rate to be set |
| 598 | * Out: |
| 599 | * none |
| 600 | * |
| 601 | * Return Value: TRUE if succeeded; FALSE if failed. |
| 602 | * |
| 603 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 604 | void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 605 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 606 | u16 wRate = (1 << wRateIdx); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 607 | |
| 608 | pDevice->wBasicRate |= wRate; |
| 609 | |
| 610 | //Determines the highest basic rate. |
| 611 | CARDvUpdateBasicTopRate(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 612 | } |
| 613 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 614 | int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 615 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 616 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 617 | |
| 618 | for (ii = RATE_54M; ii >= RATE_6M; ii --) { |
| 619 | if ((pDevice->wBasicRate) & ((WORD)(1<<ii))) |
| 620 | return TRUE; |
| 621 | } |
| 622 | return FALSE; |
| 623 | } |
| 624 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 625 | u8 CARDbyGetPktType(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 626 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 627 | |
| 628 | if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) { |
| 629 | return (BYTE)pDevice->byBBType; |
| 630 | } |
| 631 | else if (CARDbIsOFDMinBasicRate(pDevice)) { |
| 632 | return PK_TYPE_11GA; |
| 633 | } |
| 634 | else { |
| 635 | return PK_TYPE_11GB; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /* |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 641 | * Description: Calculate TSF offset of two TSF input |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 642 | * Get TSF Offset from RxBCN's TSF and local TSF |
| 643 | * |
| 644 | * Parameters: |
| 645 | * In: |
| 646 | * pDevice - The adapter to be sync. |
| 647 | * qwTSF1 - Rx BCN's TSF |
| 648 | * qwTSF2 - Local TSF |
| 649 | * Out: |
| 650 | * none |
| 651 | * |
| 652 | * Return Value: TSF Offset value |
| 653 | * |
| 654 | */ |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 655 | u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 656 | { |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 657 | u64 qwTSFOffset = 0; |
| 658 | WORD wRxBcnTSFOffst = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 659 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 660 | wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 661 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 662 | qwTSF2 += (u64)wRxBcnTSFOffst; |
| 663 | |
| 664 | qwTSFOffset = qwTSF1 - qwTSF2; |
| 665 | |
| 666 | return qwTSFOffset; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
| 670 | |
| 671 | /* |
| 672 | * Description: Sync. TSF counter to BSS |
| 673 | * Get TSF offset and write to HW |
| 674 | * |
| 675 | * Parameters: |
| 676 | * In: |
| 677 | * pDevice - The adapter to be sync. |
| 678 | * qwBSSTimestamp - Rx BCN's TSF |
| 679 | * qwLocalTSF - Local TSF |
| 680 | * Out: |
| 681 | * none |
| 682 | * |
| 683 | * Return Value: none |
| 684 | * |
| 685 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 686 | void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate, |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 687 | u64 qwBSSTimestamp, u64 qwLocalTSF) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 688 | { |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 689 | u64 qwTSFOffset = 0; |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 690 | u8 pbyData[8]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 691 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 692 | |
| 693 | qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); |
| 694 | // adjust TSF |
| 695 | // HW's TSF add TSF Offset reg |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 696 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 697 | pbyData[0] = (u8)qwTSFOffset; |
| 698 | pbyData[1] = (u8)(qwTSFOffset >> 8); |
| 699 | pbyData[2] = (u8)(qwTSFOffset >> 16); |
| 700 | pbyData[3] = (u8)(qwTSFOffset >> 24); |
| 701 | pbyData[4] = (u8)(qwTSFOffset >> 32); |
| 702 | pbyData[5] = (u8)(qwTSFOffset >> 40); |
| 703 | pbyData[6] = (u8)(qwTSFOffset >> 48); |
| 704 | pbyData[7] = (u8)(qwTSFOffset >> 56); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 705 | |
| 706 | CONTROLnsRequestOut(pDevice, |
| 707 | MESSAGE_TYPE_SET_TSFTBTT, |
| 708 | MESSAGE_REQUEST_TSF, |
| 709 | 0, |
| 710 | 8, |
| 711 | pbyData |
| 712 | ); |
| 713 | |
| 714 | } |
| 715 | /* |
| 716 | * Description: Read NIC TSF counter |
| 717 | * Get local TSF counter |
| 718 | * |
| 719 | * Parameters: |
| 720 | * In: |
| 721 | * pDevice - The adapter to be read |
| 722 | * Out: |
| 723 | * qwCurrTSF - Current TSF counter |
| 724 | * |
| 725 | * Return Value: TRUE if success; otherwise FALSE |
| 726 | * |
| 727 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 728 | int CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 729 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 730 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 731 | *pqwCurrTSF = pDevice->qwCurrTSF; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 732 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 733 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | |
| 737 | /* |
| 738 | * Description: Clear NIC TSF counter |
| 739 | * Clear local TSF counter |
| 740 | * |
| 741 | * Parameters: |
| 742 | * In: |
| 743 | * pDevice - The adapter to be read |
| 744 | * |
| 745 | * Return Value: TRUE if success; otherwise FALSE |
| 746 | * |
| 747 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 748 | int CARDbClearCurrentTSF(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 749 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 750 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 751 | MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 752 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 753 | pDevice->qwCurrTSF = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 754 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 755 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* |
| 759 | * Description: Read NIC TSF counter |
| 760 | * Get NEXTTBTT from adjusted TSF and Beacon Interval |
| 761 | * |
| 762 | * Parameters: |
| 763 | * In: |
| 764 | * qwTSF - Current TSF counter |
| 765 | * wbeaconInterval - Beacon Interval |
| 766 | * Out: |
| 767 | * qwCurrTSF - Current TSF counter |
| 768 | * |
| 769 | * Return Value: TSF value of next Beacon |
| 770 | * |
| 771 | */ |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 772 | u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 773 | { |
| 774 | |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 775 | unsigned int uLowNextTBTT; |
| 776 | unsigned int uHighRemain, uLowRemain; |
| 777 | unsigned int uBeaconInterval; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 778 | |
| 779 | uBeaconInterval = wBeaconInterval * 1024; |
| 780 | // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 781 | uLowNextTBTT = ((qwTSF & 0xffffffffU) >> 10) << 10; |
| 782 | uLowRemain = (uLowNextTBTT) % uBeaconInterval; |
| 783 | uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32)) |
| 784 | % uBeaconInterval; |
| 785 | uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; |
| 786 | uLowRemain = uBeaconInterval - uLowRemain; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 787 | |
| 788 | // check if carry when add one beacon interval |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 789 | if ((~uLowNextTBTT) < uLowRemain) |
| 790 | qwTSF = ((qwTSF >> 32) + 1) << 32; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 791 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 792 | qwTSF = (qwTSF & 0xffffffff00000000U) | |
| 793 | (u64)(uLowNextTBTT + uLowRemain); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 794 | |
| 795 | return (qwTSF); |
| 796 | } |
| 797 | |
| 798 | |
| 799 | /* |
| 800 | * Description: Set NIC TSF counter for first Beacon time |
| 801 | * Get NEXTTBTT from adjusted TSF and Beacon Interval |
| 802 | * |
| 803 | * Parameters: |
| 804 | * In: |
| 805 | * dwIoBase - IO Base |
| 806 | * wBeaconInterval - Beacon Interval |
| 807 | * Out: |
| 808 | * none |
| 809 | * |
| 810 | * Return Value: none |
| 811 | * |
| 812 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 813 | void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 814 | { |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 815 | u64 qwNextTBTT = 0; |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 816 | u8 pbyData[8]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 817 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 818 | CARDbClearCurrentTSF(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 819 | //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 820 | qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 821 | // Set NextTBTT |
| 822 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 823 | pbyData[0] = (u8)qwNextTBTT; |
| 824 | pbyData[1] = (u8)(qwNextTBTT >> 8); |
| 825 | pbyData[2] = (u8)(qwNextTBTT >> 16); |
| 826 | pbyData[3] = (u8)(qwNextTBTT >> 24); |
| 827 | pbyData[4] = (u8)(qwNextTBTT >> 32); |
| 828 | pbyData[5] = (u8)(qwNextTBTT >> 40); |
| 829 | pbyData[6] = (u8)(qwNextTBTT >> 48); |
| 830 | pbyData[7] = (u8)(qwNextTBTT >> 56); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 831 | |
| 832 | CONTROLnsRequestOut(pDevice, |
| 833 | MESSAGE_TYPE_SET_TSFTBTT, |
| 834 | MESSAGE_REQUEST_TBTT, |
| 835 | 0, |
| 836 | 8, |
| 837 | pbyData |
| 838 | ); |
| 839 | |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | |
| 844 | /* |
| 845 | * Description: Sync NIC TSF counter for Beacon time |
| 846 | * Get NEXTTBTT and write to HW |
| 847 | * |
| 848 | * Parameters: |
| 849 | * In: |
| 850 | * pDevice - The adapter to be set |
| 851 | * qwTSF - Current TSF counter |
| 852 | * wBeaconInterval - Beacon Interval |
| 853 | * Out: |
| 854 | * none |
| 855 | * |
| 856 | * Return Value: none |
| 857 | * |
| 858 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 859 | void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF, |
| 860 | u16 wBeaconInterval) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 861 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 862 | u8 pbyData[8]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 863 | |
| 864 | qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); |
| 865 | |
| 866 | // Set NextTBTT |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 867 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 868 | pbyData[0] = (u8)qwTSF; |
| 869 | pbyData[1] = (u8)(qwTSF >> 8); |
| 870 | pbyData[2] = (u8)(qwTSF >> 16); |
| 871 | pbyData[3] = (u8)(qwTSF >> 24); |
| 872 | pbyData[4] = (u8)(qwTSF >> 32); |
| 873 | pbyData[5] = (u8)(qwTSF >> 40); |
| 874 | pbyData[6] = (u8)(qwTSF >> 48); |
| 875 | pbyData[7] = (u8)(qwTSF >> 56); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 876 | |
| 877 | CONTROLnsRequestOut(pDevice, |
| 878 | MESSAGE_TYPE_SET_TSFTBTT, |
| 879 | MESSAGE_REQUEST_TBTT, |
| 880 | 0, |
| 881 | 8, |
| 882 | pbyData |
| 883 | ); |
| 884 | |
| 885 | |
Malcolm Priestley | 7c65fa2 | 2012-11-28 21:11:02 +0000 | [diff] [blame] | 886 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 887 | "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 888 | |
| 889 | return; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * Description: Turn off Radio power |
| 894 | * |
| 895 | * Parameters: |
| 896 | * In: |
| 897 | * pDevice - The adapter to be turned off |
| 898 | * Out: |
| 899 | * none |
| 900 | * |
| 901 | * Return Value: TRUE if success; otherwise FALSE |
| 902 | * |
| 903 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 904 | int CARDbRadioPowerOff(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 905 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 906 | int bResult = TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 907 | |
| 908 | //if (pDevice->bRadioOff == TRUE) |
| 909 | // return TRUE; |
| 910 | |
| 911 | pDevice->bRadioOff = TRUE; |
| 912 | |
| 913 | switch (pDevice->byRFType) { |
| 914 | case RF_AL2230: |
| 915 | case RF_AL2230S: |
| 916 | case RF_AIROHA7230: |
| 917 | case RF_VT3226: //RobertYu:20051111 |
| 918 | case RF_VT3226D0: |
| 919 | case RF_VT3342A0: //RobertYu:20060609 |
| 920 | MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); |
| 921 | break; |
| 922 | } |
| 923 | |
| 924 | MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON); |
| 925 | |
| 926 | BBvSetDeepSleep(pDevice); |
| 927 | |
| 928 | return bResult; |
| 929 | } |
| 930 | |
| 931 | |
| 932 | /* |
| 933 | * Description: Turn on Radio power |
| 934 | * |
| 935 | * Parameters: |
| 936 | * In: |
| 937 | * pDevice - The adapter to be turned on |
| 938 | * Out: |
| 939 | * none |
| 940 | * |
| 941 | * Return Value: TRUE if success; otherwise FALSE |
| 942 | * |
| 943 | */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 944 | int CARDbRadioPowerOn(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 945 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 946 | int bResult = TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 947 | |
| 948 | if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { |
| 949 | return FALSE; |
| 950 | } |
| 951 | |
| 952 | //if (pDevice->bRadioOff == FALSE) |
| 953 | // return TRUE; |
| 954 | |
| 955 | pDevice->bRadioOff = FALSE; |
| 956 | |
| 957 | BBvExitDeepSleep(pDevice); |
| 958 | |
| 959 | MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON); |
| 960 | |
| 961 | switch (pDevice->byRFType) { |
| 962 | case RF_AL2230: |
| 963 | case RF_AL2230S: |
| 964 | case RF_AIROHA7230: |
| 965 | case RF_VT3226: //RobertYu:20051111 |
| 966 | case RF_VT3226D0: |
| 967 | case RF_VT3342A0: //RobertYu:20060609 |
| 968 | MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); |
| 969 | break; |
| 970 | } |
| 971 | |
| 972 | return bResult; |
| 973 | } |
| 974 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 975 | void CARDvSetBSSMode(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 976 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 977 | // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now |
| 978 | // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA |
| 979 | if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) ) |
| 980 | { |
| 981 | MACvSetBBType(pDevice, BB_TYPE_11G); |
| 982 | } |
| 983 | else |
| 984 | { |
| 985 | MACvSetBBType(pDevice, pDevice->byBBType); |
| 986 | } |
| 987 | pDevice->byPacketType = CARDbyGetPktType(pDevice); |
| 988 | |
| 989 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 990 | ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03); |
| 991 | } else if (pDevice->byBBType == BB_TYPE_11B) { |
| 992 | ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02); |
| 993 | } else if (pDevice->byBBType == BB_TYPE_11G) { |
| 994 | ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08); |
| 995 | } |
| 996 | |
| 997 | vUpdateIFS(pDevice); |
| 998 | CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType); |
| 999 | |
| 1000 | if ( pDevice->byBBType == BB_TYPE_11A ) { |
| 1001 | //request by Jack 2005-04-26 |
| 1002 | if (pDevice->byRFType == RF_AIROHA7230) { |
| 1003 | pDevice->abyBBVGA[0] = 0x20; |
| 1004 | ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]); |
| 1005 | } |
| 1006 | pDevice->abyBBVGA[2] = 0x10; |
| 1007 | pDevice->abyBBVGA[3] = 0x10; |
| 1008 | } else { |
| 1009 | //request by Jack 2005-04-26 |
| 1010 | if (pDevice->byRFType == RF_AIROHA7230) { |
| 1011 | pDevice->abyBBVGA[0] = 0x1C; |
| 1012 | ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]); |
| 1013 | } |
| 1014 | pDevice->abyBBVGA[2] = 0x0; |
| 1015 | pDevice->abyBBVGA[3] = 0x0; |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | /* |
| 1020 | * |
| 1021 | * Description: |
| 1022 | * Do Channel Switch defined in 802.11h |
| 1023 | * |
| 1024 | * Parameters: |
| 1025 | * In: |
| 1026 | * hDeviceContext - device structure point |
| 1027 | * Out: |
| 1028 | * none |
| 1029 | * |
| 1030 | * Return Value: none. |
| 1031 | * |
| 1032 | -*/ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1033 | int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode, |
| 1034 | u8 byNewChannel, u8 byCount) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1035 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1036 | int bResult = TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1037 | |
| 1038 | if (byCount == 0) { |
| 1039 | pDevice->sMgmtObj.uCurrChannel = byNewChannel; |
Marcos Paulo de Souza | 0ae3a91 | 2011-12-18 21:12:15 +0000 | [diff] [blame] | 1040 | CARDbSetMediaChannel(pDevice, byNewChannel); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1041 | |
Matias De la Puente | fc4f558 | 2010-10-29 19:07:45 -0300 | [diff] [blame] | 1042 | return bResult; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1043 | } |
| 1044 | pDevice->byChannelSwitchCount = byCount; |
| 1045 | pDevice->byNewChannel = byNewChannel; |
| 1046 | pDevice->bChannelSwitch = TRUE; |
| 1047 | |
| 1048 | if (byMode == 1) { |
| 1049 | //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL); |
| 1050 | pDevice->bStopDataPkt = TRUE; |
| 1051 | } |
matias | cd74ea3 | 2010-09-16 15:11:28 -0300 | [diff] [blame] | 1052 | return bResult; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |