blob: 93983d941f929e62ad4728df3e878542c106014f [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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. Mattocka0a1f612012-08-26 08:16:43 -070031 * CARDqGetTSFOffset - Calculate TSFOffset
Forest Bond92b96792009-06-13 07:38:31 -040032 * CARDbGetCurrentTSF - Read Current NIC TSF counter
Justin P. Mattocka0a1f612012-08-26 08:16:43 -070033 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
Forest Bond92b96792009-06-13 07:38:31 -040034 * 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. Mattocka0a1f612012-08-26 08:16:43 -070043 * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase.
Forest Bond92b96792009-06-13 07:38:31 -040044 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
45 *
46 */
47
Malcolm Priestleydd0a7742012-12-10 21:59:10 +000048#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040049#include "tmacro.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "desc.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "power.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "key.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "rc4.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "country.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rndis.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "control.h"
Forest Bond92b96792009-06-13 07:38:31 -040062
63/*--------------------- Static Definitions -------------------------*/
64
65//static int msglevel =MSG_LEVEL_DEBUG;
66static int msglevel =MSG_LEVEL_INFO;
67
68
69/*--------------------- Static Definitions -------------------------*/
Forest Bond92b96792009-06-13 07:38:31 -040070
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
77const 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 Bond92b96792009-06-13 07:38:31 -040094 */
Malcolm Priestleydd0a7742012-12-10 21:59:10 +000095void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel)
Forest Bond92b96792009-06-13 07:38:31 -040096{
Forest Bond92b96792009-06-13 07:38:31 -040097
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 Bond92b96792009-06-13 07:38:31 -0400137}
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 Priestleydd0a7742012-12-10 21:59:10 +0000152static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx)
Forest Bond92b96792009-06-13 07:38:31 -0400153{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000154 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 Bond92b96792009-06-13 07:38:31 -0400163}
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 Priestleydd0a7742012-12-10 21:59:10 +0000178static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx)
Forest Bond92b96792009-06-13 07:38:31 -0400179{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000180 u16 ui = wRateIdx;
Forest Bond92b96792009-06-13 07:38:31 -0400181
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n",
183 pDevice->wBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400184
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000185 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 Bond92b96792009-06-13 07:38:31 -0400205}
206
207/*
Justin P. Mattocka0a1f612012-08-26 08:16:43 -0700208 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond92b96792009-06-13 07:38:31 -0400209 *
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 More8611a292010-05-01 14:25:00 -0300221void
Justin P. Mattockbda79782012-08-26 08:16:44 -0700222CARDvCalculateOFDMRParameter (
Andres More592ccfe2010-04-17 12:07:42 -0300223 WORD wRate,
224 BYTE byBBType,
Andres More6f8c13c2010-05-04 20:40:10 -0300225 PBYTE pbyTxRate,
226 PBYTE pbyRsvTime
Forest Bond92b96792009-06-13 07:38:31 -0400227 )
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 Priestleydd0a7742012-12-10 21:59:10 +0000333void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType)
Forest Bond92b96792009-06-13 07:38:31 -0400334{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000335 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 Bond92b96792009-06-13 07:38:31 -0400342
343 //RSPINF_b_1
Justin P. Mattockbda79782012-08-26 08:16:44 -0700344 BBvCalculateParameter(pDevice,
Forest Bond92b96792009-06-13 07:38:31 -0400345 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. Mattockbda79782012-08-26 08:16:44 -0700354 BBvCalculateParameter(pDevice,
Forest Bond92b96792009-06-13 07:38:31 -0400355 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. Mattockbda79782012-08-26 08:16:44 -0700364 BBvCalculateParameter(pDevice,
Forest Bond92b96792009-06-13 07:38:31 -0400365 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. Mattockbda79782012-08-26 08:16:44 -0700374 BBvCalculateParameter(pDevice,
Forest Bond92b96792009-06-13 07:38:31 -0400375 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. Mattockbda79782012-08-26 08:16:44 -0700384 CARDvCalculateOFDMRParameter (RATE_6M,
Forest Bond92b96792009-06-13 07:38:31 -0400385 byBBType,
386 &abyTxRate[0],
387 &abyRsvTime[0]);
388
389 //RSPINF_a_9
Justin P. Mattockbda79782012-08-26 08:16:44 -0700390 CARDvCalculateOFDMRParameter (RATE_9M,
Forest Bond92b96792009-06-13 07:38:31 -0400391 byBBType,
392 &abyTxRate[1],
393 &abyRsvTime[1]);
394
395 //RSPINF_a_12
Justin P. Mattockbda79782012-08-26 08:16:44 -0700396 CARDvCalculateOFDMRParameter (RATE_12M,
Forest Bond92b96792009-06-13 07:38:31 -0400397 byBBType,
398 &abyTxRate[2],
399 &abyRsvTime[2]);
400
401 //RSPINF_a_18
Justin P. Mattockbda79782012-08-26 08:16:44 -0700402 CARDvCalculateOFDMRParameter (RATE_18M,
Forest Bond92b96792009-06-13 07:38:31 -0400403 byBBType,
404 &abyTxRate[3],
405 &abyRsvTime[3]);
406
407 //RSPINF_a_24
Justin P. Mattockbda79782012-08-26 08:16:44 -0700408 CARDvCalculateOFDMRParameter (RATE_24M,
Forest Bond92b96792009-06-13 07:38:31 -0400409 byBBType,
410 &abyTxRate[4],
411 &abyRsvTime[4]);
412
413 //RSPINF_a_36
Justin P. Mattockbda79782012-08-26 08:16:44 -0700414 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
Forest Bond92b96792009-06-13 07:38:31 -0400415 byBBType,
416 &abyTxRate[5],
417 &abyRsvTime[5]);
418
419 //RSPINF_a_48
Justin P. Mattockbda79782012-08-26 08:16:44 -0700420 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
Forest Bond92b96792009-06-13 07:38:31 -0400421 byBBType,
422 &abyTxRate[6],
423 &abyRsvTime[6]);
424
425 //RSPINF_a_54
Justin P. Mattockbda79782012-08-26 08:16:44 -0700426 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
Forest Bond92b96792009-06-13 07:38:31 -0400427 byBBType,
428 &abyTxRate[7],
429 &abyRsvTime[7]);
430
431 //RSPINF_a_72
Justin P. Mattockbda79782012-08-26 08:16:44 -0700432 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
Forest Bond92b96792009-06-13 07:38:31 -0400433 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 More33d33e422010-05-19 23:50:00 -0300457 for (i = 0; i < 9; i++) {
458 abyData[16+i*2] = abyTxRate[i];
459 abyData[16+i*2+1] = abyRsvTime[i];
Forest Bond92b96792009-06-13 07:38:31 -0400460 }
461
Forest Bond92b96792009-06-13 07:38:31 -0400462 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 Priestleydd0a7742012-12-10 21:59:10 +0000483void vUpdateIFS(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400484{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000485 u8 byMaxMin = 0;
486 u8 byData[4];
Forest Bond92b96792009-06-13 07:38:31 -0400487
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 Morecc856e62010-05-17 21:34:01 -0300505 unsigned int ii = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400506 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 Priestleydd0a7742012-12-10 21:59:10 +0000566void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400567{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000568 u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
569 u8 ii;
Forest Bond92b96792009-06-13 07:38:31 -0400570
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 Priestleydd0a7742012-12-10 21:59:10 +0000604void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx)
Forest Bond92b96792009-06-13 07:38:31 -0400605{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000606 u16 wRate = (1 << wRateIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400607
608 pDevice->wBasicRate |= wRate;
609
610 //Determines the highest basic rate.
611 CARDvUpdateBasicTopRate(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -0400612}
613
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000614int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400615{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000616 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400617
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 Priestleydd0a7742012-12-10 21:59:10 +0000625u8 CARDbyGetPktType(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400626{
Forest Bond92b96792009-06-13 07:38:31 -0400627
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. Mattocka0a1f612012-08-26 08:16:43 -0700641 * Description: Calculate TSF offset of two TSF input
Forest Bond92b96792009-06-13 07:38:31 -0400642 * 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 Priestley7c65fa22012-11-28 21:11:02 +0000655u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2)
Forest Bond92b96792009-06-13 07:38:31 -0400656{
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000657 u64 qwTSFOffset = 0;
658 WORD wRxBcnTSFOffst = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400659
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000660 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400661
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000662 qwTSF2 += (u64)wRxBcnTSFOffst;
663
664 qwTSFOffset = qwTSF1 - qwTSF2;
665
666 return qwTSFOffset;
Forest Bond92b96792009-06-13 07:38:31 -0400667}
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 Priestleydd0a7742012-12-10 21:59:10 +0000686void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000687 u64 qwBSSTimestamp, u64 qwLocalTSF)
Forest Bond92b96792009-06-13 07:38:31 -0400688{
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000689 u64 qwTSFOffset = 0;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000690 u8 pbyData[8];
Forest Bond92b96792009-06-13 07:38:31 -0400691
Forest Bond92b96792009-06-13 07:38:31 -0400692
693 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
694 // adjust TSF
695 // HW's TSF add TSF Offset reg
Forest Bond92b96792009-06-13 07:38:31 -0400696
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000697 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 Bond92b96792009-06-13 07:38:31 -0400705
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 Priestleydd0a7742012-12-10 21:59:10 +0000728int CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
Forest Bond92b96792009-06-13 07:38:31 -0400729{
Forest Bond92b96792009-06-13 07:38:31 -0400730
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000731 *pqwCurrTSF = pDevice->qwCurrTSF;
Forest Bond92b96792009-06-13 07:38:31 -0400732
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000733 return TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400734}
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 Priestleydd0a7742012-12-10 21:59:10 +0000748int CARDbClearCurrentTSF(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400749{
Forest Bond92b96792009-06-13 07:38:31 -0400750
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000751 MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
Forest Bond92b96792009-06-13 07:38:31 -0400752
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000753 pDevice->qwCurrTSF = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400754
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000755 return TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400756}
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 Priestley7c65fa22012-11-28 21:11:02 +0000772u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval)
Forest Bond92b96792009-06-13 07:38:31 -0400773{
774
Andres Morecc856e62010-05-17 21:34:01 -0300775 unsigned int uLowNextTBTT;
776 unsigned int uHighRemain, uLowRemain;
777 unsigned int uBeaconInterval;
Forest Bond92b96792009-06-13 07:38:31 -0400778
779 uBeaconInterval = wBeaconInterval * 1024;
780 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000781 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 Bond92b96792009-06-13 07:38:31 -0400787
788 // check if carry when add one beacon interval
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000789 if ((~uLowNextTBTT) < uLowRemain)
790 qwTSF = ((qwTSF >> 32) + 1) << 32;
Forest Bond92b96792009-06-13 07:38:31 -0400791
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000792 qwTSF = (qwTSF & 0xffffffff00000000U) |
793 (u64)(uLowNextTBTT + uLowRemain);
Forest Bond92b96792009-06-13 07:38:31 -0400794
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 Priestleydd0a7742012-12-10 21:59:10 +0000813void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval)
Forest Bond92b96792009-06-13 07:38:31 -0400814{
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000815 u64 qwNextTBTT = 0;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000816 u8 pbyData[8];
Forest Bond92b96792009-06-13 07:38:31 -0400817
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000818 CARDbClearCurrentTSF(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -0400819 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000820 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
Forest Bond92b96792009-06-13 07:38:31 -0400821 // Set NextTBTT
822
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000823 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 Bond92b96792009-06-13 07:38:31 -0400831
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 Priestleydd0a7742012-12-10 21:59:10 +0000859void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
860 u16 wBeaconInterval)
Forest Bond92b96792009-06-13 07:38:31 -0400861{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000862 u8 pbyData[8];
Forest Bond92b96792009-06-13 07:38:31 -0400863
864 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
865
866 // Set NextTBTT
Forest Bond92b96792009-06-13 07:38:31 -0400867
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000868 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 Bond92b96792009-06-13 07:38:31 -0400876
877 CONTROLnsRequestOut(pDevice,
878 MESSAGE_TYPE_SET_TSFTBTT,
879 MESSAGE_REQUEST_TBTT,
880 0,
881 8,
882 pbyData
883 );
884
885
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
887 "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
Forest Bond92b96792009-06-13 07:38:31 -0400888
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 Priestleydd0a7742012-12-10 21:59:10 +0000904int CARDbRadioPowerOff(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400905{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000906 int bResult = TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400907
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 Priestleydd0a7742012-12-10 21:59:10 +0000944int CARDbRadioPowerOn(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400945{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000946 int bResult = TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400947
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 Priestleydd0a7742012-12-10 21:59:10 +0000975void CARDvSetBSSMode(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400976{
Forest Bond92b96792009-06-13 07:38:31 -0400977 // 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 Priestleydd0a7742012-12-10 21:59:10 +00001033int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode,
1034 u8 byNewChannel, u8 byCount)
Forest Bond92b96792009-06-13 07:38:31 -04001035{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +00001036 int bResult = TRUE;
Forest Bond92b96792009-06-13 07:38:31 -04001037
1038 if (byCount == 0) {
1039 pDevice->sMgmtObj.uCurrChannel = byNewChannel;
Marcos Paulo de Souza0ae3a912011-12-18 21:12:15 +00001040 CARDbSetMediaChannel(pDevice, byNewChannel);
Forest Bond92b96792009-06-13 07:38:31 -04001041
Matias De la Puentefc4f5582010-10-29 19:07:45 -03001042 return bResult;
Forest Bond92b96792009-06-13 07:38:31 -04001043 }
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 }
matiascd74ea32010-09-16 15:11:28 -03001052 return bResult;
Forest Bond92b96792009-06-13 07:38:31 -04001053}
1054
1055
1056
1057
1058
1059