staging: vt6656: replace custom BOOL definition with bool
[deliverable/linux.git] / drivers / staging / vt6656 / card.c
CommitLineData
92b96797
FB
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
a0a1f61a 31 * CARDqGetTSFOffset - Calculate TSFOffset
92b96797 32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
a0a1f61a 33 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
92b96797
FB
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.
a0a1f61a 43 * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase.
92b96797
FB
44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
45 *
46 */
47
dd0a774f 48#include "device.h"
92b96797 49#include "tmacro.h"
92b96797 50#include "card.h"
92b96797 51#include "baseband.h"
92b96797 52#include "mac.h"
92b96797 53#include "desc.h"
92b96797 54#include "rf.h"
92b96797 55#include "power.h"
92b96797 56#include "key.h"
92b96797 57#include "rc4.h"
92b96797 58#include "country.h"
92b96797 59#include "datarate.h"
92b96797 60#include "rndis.h"
92b96797 61#include "control.h"
92b96797
FB
62
63/*--------------------- Static Definitions -------------------------*/
64
65//static int msglevel =MSG_LEVEL_DEBUG;
66static int msglevel =MSG_LEVEL_INFO;
67
68
69/*--------------------- Static Definitions -------------------------*/
92b96797
FB
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
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
92b96797 94 */
dd0a774f 95void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel)
92b96797 96{
92b96797
FB
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));
92b96797
FB
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 */
dd0a774f 152static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx)
92b96797 153{
dd0a774f
MP
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;
92b96797
FB
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 */
dd0a774f 178static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx)
92b96797 179{
dd0a774f
MP
180 u16 ui = wRateIdx;
181
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n",
183 pDevice->wBasicRate);
184
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;
92b96797
FB
205}
206
207/*
a0a1f61a 208 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
92b96797
FB
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 */
8611a29a 221void
bda79783 222CARDvCalculateOFDMRParameter (
592ccfeb
AM
223 WORD wRate,
224 BYTE byBBType,
6f8c13c7
AM
225 PBYTE pbyTxRate,
226 PBYTE pbyRsvTime
92b96797
FB
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 */
dd0a774f 333void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType)
92b96797 334{
dd0a774f
MP
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;
92b96797
FB
342
343 //RSPINF_b_1
bda79783 344 BBvCalculateParameter(pDevice,
92b96797
FB
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
bda79783 354 BBvCalculateParameter(pDevice,
92b96797
FB
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
bda79783 364 BBvCalculateParameter(pDevice,
92b96797
FB
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
bda79783 374 BBvCalculateParameter(pDevice,
92b96797
FB
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
bda79783 384 CARDvCalculateOFDMRParameter (RATE_6M,
92b96797
FB
385 byBBType,
386 &abyTxRate[0],
387 &abyRsvTime[0]);
388
389 //RSPINF_a_9
bda79783 390 CARDvCalculateOFDMRParameter (RATE_9M,
92b96797
FB
391 byBBType,
392 &abyTxRate[1],
393 &abyRsvTime[1]);
394
395 //RSPINF_a_12
bda79783 396 CARDvCalculateOFDMRParameter (RATE_12M,
92b96797
FB
397 byBBType,
398 &abyTxRate[2],
399 &abyRsvTime[2]);
400
401 //RSPINF_a_18
bda79783 402 CARDvCalculateOFDMRParameter (RATE_18M,
92b96797
FB
403 byBBType,
404 &abyTxRate[3],
405 &abyRsvTime[3]);
406
407 //RSPINF_a_24
bda79783 408 CARDvCalculateOFDMRParameter (RATE_24M,
92b96797
FB
409 byBBType,
410 &abyTxRate[4],
411 &abyRsvTime[4]);
412
413 //RSPINF_a_36
bda79783 414 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
92b96797
FB
415 byBBType,
416 &abyTxRate[5],
417 &abyRsvTime[5]);
418
419 //RSPINF_a_48
bda79783 420 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
92b96797
FB
421 byBBType,
422 &abyTxRate[6],
423 &abyRsvTime[6]);
424
425 //RSPINF_a_54
bda79783 426 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
92b96797
FB
427 byBBType,
428 &abyTxRate[7],
429 &abyRsvTime[7]);
430
431 //RSPINF_a_72
bda79783 432 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
92b96797
FB
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
33d33e42
AM
457 for (i = 0; i < 9; i++) {
458 abyData[16+i*2] = abyTxRate[i];
459 abyData[16+i*2+1] = abyRsvTime[i];
92b96797
FB
460 }
461
92b96797
FB
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 */
dd0a774f 483void vUpdateIFS(struct vnt_private *pDevice)
92b96797 484{
dd0a774f
MP
485 u8 byMaxMin = 0;
486 u8 byData[4];
92b96797
FB
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;
dfdcc425 504 bool bOFDMRate = FALSE;
cc856e61 505 unsigned int ii = 0;
92b96797
FB
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
14c5ef57 516 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt.abyCurrSuppRates;
92b96797
FB
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) {
14c5ef57
MP
525 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt
526 .abyCurrExtSuppRates;
92b96797
FB
527 for (ii = 0; ii < pItemRates->len; ii++) {
528 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
529 if (RATEwGetRateIdx(byRate) > RATE_11M) {
530 bOFDMRate = TRUE;
531 break;
532 }
533 }
534 }
535 if (bOFDMRate == TRUE) {
536 pDevice->uCwMin = C_CWMIN_A;
537 byMaxMin = 4;
538 } else {
539 pDevice->uCwMin = C_CWMIN_B;
540 byMaxMin = 5;
541 }
542 }
543
544 pDevice->uCwMax = C_CWMAX;
545 pDevice->uEIFS = C_EIFS;
546
547 byData[0] = (BYTE)pDevice->uSIFS;
548 byData[1] = (BYTE)pDevice->uDIFS;
549 byData[2] = (BYTE)pDevice->uEIFS;
550 byData[3] = (BYTE)pDevice->uSlot;
551 CONTROLnsRequestOut(pDevice,
552 MESSAGE_TYPE_WRITE,
553 MAC_REG_SIFS,
554 MESSAGE_REQUEST_MACREG,
555 4,
556 &byData[0]);
557
558 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
559 CONTROLnsRequestOut(pDevice,
560 MESSAGE_TYPE_WRITE,
561 MAC_REG_CWMAXMIN0,
562 MESSAGE_REQUEST_MACREG,
563 1,
564 &byMaxMin);
565}
566
dd0a774f 567void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
92b96797 568{
dd0a774f
MP
569 u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
570 u8 ii;
92b96797
FB
571
572 //Determines the highest basic rate.
573 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
574 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
575 byTopOFDM = ii;
576 break;
577 }
578 }
579 pDevice->byTopOFDMBasicRate = byTopOFDM;
580
581 for (ii = RATE_11M;; ii --) {
582 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
583 byTopCCK = ii;
584 break;
585 }
586 if (ii == RATE_1M)
587 break;
588 }
589 pDevice->byTopCCKBasicRate = byTopCCK;
590 }
591
592/*
593 * Description: Set NIC Tx Basic Rate
594 *
595 * Parameters:
596 * In:
597 * pDevice - The adapter to be set
598 * wBasicRate - Basic Rate to be set
599 * Out:
600 * none
601 *
602 * Return Value: TRUE if succeeded; FALSE if failed.
603 *
604 */
dd0a774f 605void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx)
92b96797 606{
dd0a774f 607 u16 wRate = (1 << wRateIdx);
92b96797
FB
608
609 pDevice->wBasicRate |= wRate;
610
611 //Determines the highest basic rate.
612 CARDvUpdateBasicTopRate(pDevice);
92b96797
FB
613}
614
dd0a774f 615int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
92b96797 616{
dd0a774f 617 int ii;
92b96797
FB
618
619 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
620 if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
621 return TRUE;
622 }
623 return FALSE;
624}
625
dd0a774f 626u8 CARDbyGetPktType(struct vnt_private *pDevice)
92b96797 627{
92b96797
FB
628
629 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
630 return (BYTE)pDevice->byBBType;
631 }
632 else if (CARDbIsOFDMinBasicRate(pDevice)) {
633 return PK_TYPE_11GA;
634 }
635 else {
636 return PK_TYPE_11GB;
637 }
638}
639
640
641/*
a0a1f61a 642 * Description: Calculate TSF offset of two TSF input
92b96797
FB
643 * Get TSF Offset from RxBCN's TSF and local TSF
644 *
645 * Parameters:
646 * In:
647 * pDevice - The adapter to be sync.
648 * qwTSF1 - Rx BCN's TSF
649 * qwTSF2 - Local TSF
650 * Out:
651 * none
652 *
653 * Return Value: TSF Offset value
654 *
655 */
7c65fa2a 656u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2)
92b96797 657{
7c65fa2a
MP
658 u64 qwTSFOffset = 0;
659 WORD wRxBcnTSFOffst = 0;
92b96797 660
7c65fa2a 661 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
92b96797 662
7c65fa2a
MP
663 qwTSF2 += (u64)wRxBcnTSFOffst;
664
665 qwTSFOffset = qwTSF1 - qwTSF2;
666
667 return qwTSFOffset;
92b96797
FB
668}
669
670
671
672/*
673 * Description: Sync. TSF counter to BSS
674 * Get TSF offset and write to HW
675 *
676 * Parameters:
677 * In:
678 * pDevice - The adapter to be sync.
679 * qwBSSTimestamp - Rx BCN's TSF
680 * qwLocalTSF - Local TSF
681 * Out:
682 * none
683 *
684 * Return Value: none
685 *
686 */
dd0a774f 687void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
7c65fa2a 688 u64 qwBSSTimestamp, u64 qwLocalTSF)
92b96797 689{
7c65fa2a 690 u64 qwTSFOffset = 0;
dd0a774f 691 u8 pbyData[8];
92b96797 692
92b96797
FB
693
694 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
695 // adjust TSF
696 // HW's TSF add TSF Offset reg
92b96797 697
7c65fa2a
MP
698 pbyData[0] = (u8)qwTSFOffset;
699 pbyData[1] = (u8)(qwTSFOffset >> 8);
700 pbyData[2] = (u8)(qwTSFOffset >> 16);
701 pbyData[3] = (u8)(qwTSFOffset >> 24);
702 pbyData[4] = (u8)(qwTSFOffset >> 32);
703 pbyData[5] = (u8)(qwTSFOffset >> 40);
704 pbyData[6] = (u8)(qwTSFOffset >> 48);
705 pbyData[7] = (u8)(qwTSFOffset >> 56);
92b96797
FB
706
707 CONTROLnsRequestOut(pDevice,
708 MESSAGE_TYPE_SET_TSFTBTT,
709 MESSAGE_REQUEST_TSF,
710 0,
711 8,
712 pbyData
713 );
714
715}
716/*
717 * Description: Read NIC TSF counter
718 * Get local TSF counter
719 *
720 * Parameters:
721 * In:
722 * pDevice - The adapter to be read
723 * Out:
724 * qwCurrTSF - Current TSF counter
725 *
726 * Return Value: TRUE if success; otherwise FALSE
727 *
728 */
dfdcc425 729bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
92b96797 730{
92b96797 731
7c65fa2a 732 *pqwCurrTSF = pDevice->qwCurrTSF;
92b96797 733
dd0a774f 734 return TRUE;
92b96797
FB
735}
736
737
738/*
739 * Description: Clear NIC TSF counter
740 * Clear local TSF counter
741 *
742 * Parameters:
743 * In:
744 * pDevice - The adapter to be read
745 *
746 * Return Value: TRUE if success; otherwise FALSE
747 *
748 */
dfdcc425 749bool CARDbClearCurrentTSF(struct vnt_private *pDevice)
92b96797 750{
92b96797 751
dd0a774f 752 MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
92b96797 753
7c65fa2a 754 pDevice->qwCurrTSF = 0;
92b96797 755
dd0a774f 756 return TRUE;
92b96797
FB
757}
758
759/*
760 * Description: Read NIC TSF counter
761 * Get NEXTTBTT from adjusted TSF and Beacon Interval
762 *
763 * Parameters:
764 * In:
765 * qwTSF - Current TSF counter
766 * wbeaconInterval - Beacon Interval
767 * Out:
768 * qwCurrTSF - Current TSF counter
769 *
770 * Return Value: TSF value of next Beacon
771 *
772 */
7c65fa2a 773u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval)
92b96797
FB
774{
775
cc856e61
AM
776 unsigned int uLowNextTBTT;
777 unsigned int uHighRemain, uLowRemain;
778 unsigned int uBeaconInterval;
92b96797
FB
779
780 uBeaconInterval = wBeaconInterval * 1024;
781 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
7c65fa2a
MP
782 uLowNextTBTT = ((qwTSF & 0xffffffffU) >> 10) << 10;
783 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
784 uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32))
785 % uBeaconInterval;
786 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
787 uLowRemain = uBeaconInterval - uLowRemain;
92b96797
FB
788
789 // check if carry when add one beacon interval
7c65fa2a
MP
790 if ((~uLowNextTBTT) < uLowRemain)
791 qwTSF = ((qwTSF >> 32) + 1) << 32;
92b96797 792
c7b7cad0 793 qwTSF = (qwTSF & 0xffffffff00000000UL) |
7c65fa2a 794 (u64)(uLowNextTBTT + uLowRemain);
92b96797
FB
795
796 return (qwTSF);
797}
798
799
800/*
801 * Description: Set NIC TSF counter for first Beacon time
802 * Get NEXTTBTT from adjusted TSF and Beacon Interval
803 *
804 * Parameters:
805 * In:
806 * dwIoBase - IO Base
807 * wBeaconInterval - Beacon Interval
808 * Out:
809 * none
810 *
811 * Return Value: none
812 *
813 */
dd0a774f 814void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval)
92b96797 815{
7c65fa2a 816 u64 qwNextTBTT = 0;
dd0a774f 817 u8 pbyData[8];
92b96797 818
7c65fa2a 819 CARDbClearCurrentTSF(pDevice);
92b96797 820 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
7c65fa2a 821 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
92b96797
FB
822 // Set NextTBTT
823
7c65fa2a
MP
824 pbyData[0] = (u8)qwNextTBTT;
825 pbyData[1] = (u8)(qwNextTBTT >> 8);
826 pbyData[2] = (u8)(qwNextTBTT >> 16);
827 pbyData[3] = (u8)(qwNextTBTT >> 24);
828 pbyData[4] = (u8)(qwNextTBTT >> 32);
829 pbyData[5] = (u8)(qwNextTBTT >> 40);
830 pbyData[6] = (u8)(qwNextTBTT >> 48);
831 pbyData[7] = (u8)(qwNextTBTT >> 56);
92b96797
FB
832
833 CONTROLnsRequestOut(pDevice,
834 MESSAGE_TYPE_SET_TSFTBTT,
835 MESSAGE_REQUEST_TBTT,
836 0,
837 8,
838 pbyData
839 );
840
841 return;
842}
843
844
845/*
846 * Description: Sync NIC TSF counter for Beacon time
847 * Get NEXTTBTT and write to HW
848 *
849 * Parameters:
850 * In:
851 * pDevice - The adapter to be set
852 * qwTSF - Current TSF counter
853 * wBeaconInterval - Beacon Interval
854 * Out:
855 * none
856 *
857 * Return Value: none
858 *
859 */
dd0a774f
MP
860void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
861 u16 wBeaconInterval)
92b96797 862{
dd0a774f 863 u8 pbyData[8];
92b96797
FB
864
865 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
866
867 // Set NextTBTT
7c65fa2a
MP
868
869 pbyData[0] = (u8)qwTSF;
870 pbyData[1] = (u8)(qwTSF >> 8);
871 pbyData[2] = (u8)(qwTSF >> 16);
872 pbyData[3] = (u8)(qwTSF >> 24);
873 pbyData[4] = (u8)(qwTSF >> 32);
874 pbyData[5] = (u8)(qwTSF >> 40);
875 pbyData[6] = (u8)(qwTSF >> 48);
876 pbyData[7] = (u8)(qwTSF >> 56);
92b96797
FB
877
878 CONTROLnsRequestOut(pDevice,
879 MESSAGE_TYPE_SET_TSFTBTT,
880 MESSAGE_REQUEST_TBTT,
881 0,
882 8,
883 pbyData
884 );
885
886
7c65fa2a
MP
887 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
888 "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
92b96797
FB
889
890 return;
891}
892
893/*
894 * Description: Turn off Radio power
895 *
896 * Parameters:
897 * In:
898 * pDevice - The adapter to be turned off
899 * Out:
900 * none
901 *
902 * Return Value: TRUE if success; otherwise FALSE
903 *
904 */
dd0a774f 905int CARDbRadioPowerOff(struct vnt_private *pDevice)
92b96797 906{
dd0a774f 907 int bResult = TRUE;
92b96797
FB
908
909 //if (pDevice->bRadioOff == TRUE)
910 // return TRUE;
911
912 pDevice->bRadioOff = TRUE;
913
914 switch (pDevice->byRFType) {
915 case RF_AL2230:
916 case RF_AL2230S:
917 case RF_AIROHA7230:
918 case RF_VT3226: //RobertYu:20051111
919 case RF_VT3226D0:
920 case RF_VT3342A0: //RobertYu:20060609
921 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
922 break;
923 }
924
925 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
926
927 BBvSetDeepSleep(pDevice);
928
929 return bResult;
930}
931
932
933/*
934 * Description: Turn on Radio power
935 *
936 * Parameters:
937 * In:
938 * pDevice - The adapter to be turned on
939 * Out:
940 * none
941 *
942 * Return Value: TRUE if success; otherwise FALSE
943 *
944 */
dd0a774f 945int CARDbRadioPowerOn(struct vnt_private *pDevice)
92b96797 946{
dd0a774f 947 int bResult = TRUE;
92b96797
FB
948
949 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
950 return FALSE;
951 }
952
953 //if (pDevice->bRadioOff == FALSE)
954 // return TRUE;
955
956 pDevice->bRadioOff = FALSE;
957
958 BBvExitDeepSleep(pDevice);
959
960 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
961
962 switch (pDevice->byRFType) {
963 case RF_AL2230:
964 case RF_AL2230S:
965 case RF_AIROHA7230:
966 case RF_VT3226: //RobertYu:20051111
967 case RF_VT3226D0:
968 case RF_VT3342A0: //RobertYu:20060609
969 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
970 break;
971 }
972
973 return bResult;
974}
975
dd0a774f 976void CARDvSetBSSMode(struct vnt_private *pDevice)
92b96797 977{
92b96797
FB
978 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
979 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
980 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
981 {
982 MACvSetBBType(pDevice, BB_TYPE_11G);
983 }
984 else
985 {
986 MACvSetBBType(pDevice, pDevice->byBBType);
987 }
988 pDevice->byPacketType = CARDbyGetPktType(pDevice);
989
990 if (pDevice->byBBType == BB_TYPE_11A) {
991 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
992 } else if (pDevice->byBBType == BB_TYPE_11B) {
993 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
994 } else if (pDevice->byBBType == BB_TYPE_11G) {
995 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
996 }
997
998 vUpdateIFS(pDevice);
999 CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
1000
1001 if ( pDevice->byBBType == BB_TYPE_11A ) {
1002 //request by Jack 2005-04-26
1003 if (pDevice->byRFType == RF_AIROHA7230) {
1004 pDevice->abyBBVGA[0] = 0x20;
1005 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1006 }
1007 pDevice->abyBBVGA[2] = 0x10;
1008 pDevice->abyBBVGA[3] = 0x10;
1009 } else {
1010 //request by Jack 2005-04-26
1011 if (pDevice->byRFType == RF_AIROHA7230) {
1012 pDevice->abyBBVGA[0] = 0x1C;
1013 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1014 }
1015 pDevice->abyBBVGA[2] = 0x0;
1016 pDevice->abyBBVGA[3] = 0x0;
1017 }
1018}
1019
1020/*
1021 *
1022 * Description:
1023 * Do Channel Switch defined in 802.11h
1024 *
1025 * Parameters:
1026 * In:
1027 * hDeviceContext - device structure point
1028 * Out:
1029 * none
1030 *
1031 * Return Value: none.
1032 *
1033-*/
dd0a774f
MP
1034int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode,
1035 u8 byNewChannel, u8 byCount)
92b96797 1036{
dd0a774f 1037 int bResult = TRUE;
92b96797 1038
14c5ef57
MP
1039 if (byCount == 0) {
1040 pDevice->vnt_mgmt.uCurrChannel = byNewChannel;
1041 CARDbSetMediaChannel(pDevice, byNewChannel);
1042 return bResult;
1043 }
92b96797
FB
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 }
cd74ea33 1052 return bResult;
92b96797
FB
1053}
1054
1055
1056
1057
1058
1059
This page took 0.367904 seconds and 5 git commands to generate.