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