Merge branch 'ixp4xx' of git://git.kernel.org/pub/scm/linux/kernel/git/chris/linux-2.6
[linux/fpc-iii.git] / drivers / staging / vt6656 / card.c
blobd73efeea2d5c0b0537607e5a1907f23e5b37d7ed
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
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
31 * CARDqGetTSFOffset - Caculate TSFOffset
32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
33 * CARDqGetNextTBTT - Caculate Next Beacon TSF counter
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
41 * Revision History:
42 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
43 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
48 #include "tmacro.h"
49 #include "card.h"
50 #include "baseband.h"
51 #include "mac.h"
52 #include "desc.h"
53 #include "rf.h"
54 #include "power.h"
55 #include "key.h"
56 #include "rc4.h"
57 #include "country.h"
58 #include "datarate.h"
59 #include "rndis.h"
60 #include "control.h"
62 /*--------------------- Static Definitions -------------------------*/
64 //static int msglevel =MSG_LEVEL_DEBUG;
65 static int msglevel =MSG_LEVEL_INFO;
68 /*--------------------- Static Definitions -------------------------*/
69 #define CB_TXPOWER_LEVEL 6
71 /*--------------------- Static Classes ----------------------------*/
73 /*--------------------- Static Variables --------------------------*/
74 //const WORD cwRXBCNTSFOff[MAX_RATE] =
75 //{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
77 const WORD cwRXBCNTSFOff[MAX_RATE] =
78 {192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3};
80 /*--------------------- Static Functions --------------------------*/
82 /*--------------------- Export Variables --------------------------*/
84 /*--------------------- Export Functions --------------------------*/
86 * Description: Set NIC media channel
88 * Parameters:
89 * In:
90 * pDevice - The adapter to be set
91 * uConnectionChannel - Channel to be set
92 * Out:
93 * none
95 * Return Value: TRUE if succeeded; FALSE if failed.
98 BOOL CARDbSetMediaChannel (PVOID pDeviceHandler, UINT uConnectionChannel)
100 PSDevice pDevice = (PSDevice) pDeviceHandler;
101 BOOL bResult = TRUE;
104 if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38
105 if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL))
106 uConnectionChannel = (CB_MAX_CHANNEL_24G+1);
107 } else {
108 if ((uConnectionChannel > CB_MAX_CHANNEL_24G) || (uConnectionChannel == 0)) // 1 ~ 14
109 uConnectionChannel = 1;
112 // clear NAV
113 MACvRegBitsOn(pDevice, MAC_REG_MACCR, MACCR_CLRNAV);
115 // Set Channel[7] = 0 to tell H/W channel is changing now.
116 MACvRegBitsOff(pDevice, MAC_REG_CHANNEL, 0x80);
118 //if (pMgmt->uCurrChannel == uConnectionChannel)
119 // return bResult;
121 CONTROLnsRequestOut(pDevice,
122 MESSAGE_TYPE_SELECT_CHANNLE,
123 (WORD) uConnectionChannel,
126 NULL
129 //{{ RobertYu: 20041202
130 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
132 if (pDevice->byBBType == BB_TYPE_11A) {
133 pDevice->byCurPwr = 0xFF;
134 RFbRawSetPower(pDevice, pDevice->abyOFDMAPwrTbl[uConnectionChannel-15], RATE_54M);
135 } else if (pDevice->byBBType == BB_TYPE_11G) {
136 pDevice->byCurPwr = 0xFF;
137 RFbRawSetPower(pDevice, pDevice->abyOFDMPwrTbl[uConnectionChannel-1], RATE_54M);
138 } else {
139 pDevice->byCurPwr = 0xFF;
140 RFbRawSetPower(pDevice, pDevice->abyCCKPwrTbl[uConnectionChannel-1], RATE_1M);
142 ControlvWriteByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_CHANNEL,(BYTE)(uConnectionChannel|0x80));
143 return(bResult);
147 * Description: Get CCK mode basic rate
149 * Parameters:
150 * In:
151 * pDevice - The adapter to be set
152 * wRateIdx - Receiving data rate
153 * Out:
154 * none
156 * Return Value: response Control frame rate
159 static
160 WORD swGetCCKControlRate(PVOID pDeviceHandler, WORD wRateIdx)
162 PSDevice pDevice = (PSDevice) pDeviceHandler;
163 UINT ui = (UINT)wRateIdx;
164 while (ui > RATE_1M) {
165 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
166 return (WORD)ui;
168 ui --;
170 return (WORD)RATE_1M;
174 * Description: Get OFDM mode basic rate
176 * Parameters:
177 * In:
178 * pDevice - The adapter to be set
179 * wRateIdx - Receiving data rate
180 * Out:
181 * none
183 * Return Value: response Control frame rate
186 static
187 WORD swGetOFDMControlRate (PVOID pDeviceHandler, WORD wRateIdx)
189 PSDevice pDevice = (PSDevice) pDeviceHandler;
190 UINT ui = (UINT)wRateIdx;
192 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
194 if (!CARDbIsOFDMinBasicRate(pDevice)) {
195 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
196 if (wRateIdx > RATE_24M)
197 wRateIdx = RATE_24M;
198 return wRateIdx;
200 while (ui > RATE_11M) {
201 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
202 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate : %d\n", ui);
203 return (WORD)ui;
205 ui --;
207 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n");
208 return (WORD)RATE_24M;
212 * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
214 * Parameters:
215 * In:
216 * wRate - Tx Rate
217 * byPktType - Tx Packet type
218 * Out:
219 * pbyTxRate - pointer to RSPINF TxRate field
220 * pbyRsvTime - pointer to RSPINF RsvTime field
222 * Return Value: none
225 VOID
226 CARDvCaculateOFDMRParameter (
227 IN WORD wRate,
228 IN BYTE byBBType,
229 OUT PBYTE pbyTxRate,
230 OUT PBYTE pbyRsvTime
233 switch (wRate) {
234 case RATE_6M :
235 if (byBBType == BB_TYPE_11A) {//5GHZ
236 *pbyTxRate = 0x9B;
237 *pbyRsvTime = 24;
239 else {
240 *pbyTxRate = 0x8B;
241 *pbyRsvTime = 30;
243 break;
245 case RATE_9M :
246 if (byBBType == BB_TYPE_11A) {//5GHZ
247 *pbyTxRate = 0x9F;
248 *pbyRsvTime = 16;
250 else {
251 *pbyTxRate = 0x8F;
252 *pbyRsvTime = 22;
254 break;
256 case RATE_12M :
257 if (byBBType == BB_TYPE_11A) {//5GHZ
258 *pbyTxRate = 0x9A;
259 *pbyRsvTime = 12;
261 else {
262 *pbyTxRate = 0x8A;
263 *pbyRsvTime = 18;
265 break;
267 case RATE_18M :
268 if (byBBType == BB_TYPE_11A) {//5GHZ
269 *pbyTxRate = 0x9E;
270 *pbyRsvTime = 8;
272 else {
273 *pbyTxRate = 0x8E;
274 *pbyRsvTime = 14;
276 break;
278 case RATE_36M :
279 if (byBBType == BB_TYPE_11A) {//5GHZ
280 *pbyTxRate = 0x9D;
281 *pbyRsvTime = 4;
283 else {
284 *pbyTxRate = 0x8D;
285 *pbyRsvTime = 10;
287 break;
289 case RATE_48M :
290 if (byBBType == BB_TYPE_11A) {//5GHZ
291 *pbyTxRate = 0x98;
292 *pbyRsvTime = 4;
294 else {
295 *pbyTxRate = 0x88;
296 *pbyRsvTime = 10;
298 break;
300 case RATE_54M :
301 if (byBBType == BB_TYPE_11A) {//5GHZ
302 *pbyTxRate = 0x9C;
303 *pbyRsvTime = 4;
305 else {
306 *pbyTxRate = 0x8C;
307 *pbyRsvTime = 10;
309 break;
311 case RATE_24M :
312 default :
313 if (byBBType == BB_TYPE_11A) {//5GHZ
314 *pbyTxRate = 0x99;
315 *pbyRsvTime = 8;
317 else {
318 *pbyTxRate = 0x89;
319 *pbyRsvTime = 14;
321 break;
326 * Description: Set RSPINF
328 * Parameters:
329 * In:
330 * pDevice - The adapter to be set
331 * Out:
332 * none
334 * Return Value: None.
337 void CARDvSetRSPINF (PVOID pDeviceHandler, BYTE byBBType)
339 PSDevice pDevice = (PSDevice) pDeviceHandler;
340 BYTE abyServ[4] = {0,0,0,0}; // For CCK
341 BYTE abySignal[4] = {0,0,0,0};
342 WORD awLen[4] = {0,0,0,0};
343 BYTE abyTxRate[9] = {0,0,0,0,0,0,0,0,0}; // For OFDM
344 BYTE abyRsvTime[9] = {0,0,0,0,0,0,0,0,0};
345 BYTE abyData[34];
346 int i;
348 //RSPINF_b_1
349 BBvCaculateParameter(pDevice,
351 swGetCCKControlRate(pDevice, RATE_1M),
352 PK_TYPE_11B,
353 &awLen[0],
354 &abyServ[0],
355 &abySignal[0]
358 ///RSPINF_b_2
359 BBvCaculateParameter(pDevice,
361 swGetCCKControlRate(pDevice, RATE_2M),
362 PK_TYPE_11B,
363 &awLen[1],
364 &abyServ[1],
365 &abySignal[1]
368 //RSPINF_b_5
369 BBvCaculateParameter(pDevice,
371 swGetCCKControlRate(pDevice, RATE_5M),
372 PK_TYPE_11B,
373 &awLen[2],
374 &abyServ[2],
375 &abySignal[2]
378 //RSPINF_b_11
379 BBvCaculateParameter(pDevice,
381 swGetCCKControlRate(pDevice, RATE_11M),
382 PK_TYPE_11B,
383 &awLen[3],
384 &abyServ[3],
385 &abySignal[3]
388 //RSPINF_a_6
389 CARDvCaculateOFDMRParameter (RATE_6M,
390 byBBType,
391 &abyTxRate[0],
392 &abyRsvTime[0]);
394 //RSPINF_a_9
395 CARDvCaculateOFDMRParameter (RATE_9M,
396 byBBType,
397 &abyTxRate[1],
398 &abyRsvTime[1]);
400 //RSPINF_a_12
401 CARDvCaculateOFDMRParameter (RATE_12M,
402 byBBType,
403 &abyTxRate[2],
404 &abyRsvTime[2]);
406 //RSPINF_a_18
407 CARDvCaculateOFDMRParameter (RATE_18M,
408 byBBType,
409 &abyTxRate[3],
410 &abyRsvTime[3]);
412 //RSPINF_a_24
413 CARDvCaculateOFDMRParameter (RATE_24M,
414 byBBType,
415 &abyTxRate[4],
416 &abyRsvTime[4]);
418 //RSPINF_a_36
419 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
420 byBBType,
421 &abyTxRate[5],
422 &abyRsvTime[5]);
424 //RSPINF_a_48
425 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
426 byBBType,
427 &abyTxRate[6],
428 &abyRsvTime[6]);
430 //RSPINF_a_54
431 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
432 byBBType,
433 &abyTxRate[7],
434 &abyRsvTime[7]);
436 //RSPINF_a_72
437 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
438 byBBType,
439 &abyTxRate[8],
440 &abyRsvTime[8]);
442 abyData[0] = (BYTE)(awLen[0]&0xFF);
443 abyData[1] = (BYTE)(awLen[0]>>8);
444 abyData[2] = abySignal[0];
445 abyData[3] = abyServ[0];
447 abyData[4] = (BYTE)(awLen[1]&0xFF);
448 abyData[5] = (BYTE)(awLen[1]>>8);
449 abyData[6] = abySignal[1];
450 abyData[7] = abyServ[1];
452 abyData[8] = (BYTE)(awLen[2]&0xFF);
453 abyData[9] = (BYTE)(awLen[2]>>8);
454 abyData[10] = abySignal[2];
455 abyData[11] = abyServ[2];
457 abyData[12] = (BYTE)(awLen[3]&0xFF);
458 abyData[13] = (BYTE)(awLen[3]>>8);
459 abyData[14] = abySignal[3];
460 abyData[15] = abyServ[3];
462 for(i=0;i<9;i++) {
463 abyData[16+i*2] = abyTxRate[i];
464 abyData[16+i*2+1] = abyRsvTime[i];
468 CONTROLnsRequestOut(pDevice,
469 MESSAGE_TYPE_WRITE,
470 MAC_REG_RSPINF_B_1,
471 MESSAGE_REQUEST_MACREG,
473 &abyData[0]);
478 * Description: Update IFS
480 * Parameters:
481 * In:
482 * pDevice - The adapter to be set
483 * Out:
484 * none
486 * Return Value: None.
489 void vUpdateIFS (PVOID pDeviceHandler)
491 PSDevice pDevice = (PSDevice) pDeviceHandler;
492 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
493 BYTE byMaxMin = 0;
494 BYTE byData[4];
496 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
497 pDevice->uSlot = C_SLOT_SHORT;
498 pDevice->uSIFS = C_SIFS_A;
499 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
500 pDevice->uCwMin = C_CWMIN_A;
501 byMaxMin = 4;
503 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
504 pDevice->uSlot = C_SLOT_LONG;
505 pDevice->uSIFS = C_SIFS_BG;
506 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
507 pDevice->uCwMin = C_CWMIN_B;
508 byMaxMin = 5;
510 else {// PK_TYPE_11GA & PK_TYPE_11GB
511 BYTE byRate = 0;
512 BOOL bOFDMRate = FALSE;
513 UINT ii = 0;
514 PWLAN_IE_SUPP_RATES pItemRates = NULL;
516 pDevice->uSIFS = C_SIFS_BG;
517 if (pDevice->bShortSlotTime) {
518 pDevice->uSlot = C_SLOT_SHORT;
519 } else {
520 pDevice->uSlot = C_SLOT_LONG;
522 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
524 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrSuppRates;
525 for (ii = 0; ii < pItemRates->len; ii++) {
526 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
527 if (RATEwGetRateIdx(byRate) > RATE_11M) {
528 bOFDMRate = TRUE;
529 break;
532 if (bOFDMRate == FALSE) {
533 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrExtSuppRates;
534 for (ii = 0; ii < pItemRates->len; ii++) {
535 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
536 if (RATEwGetRateIdx(byRate) > RATE_11M) {
537 bOFDMRate = TRUE;
538 break;
542 if (bOFDMRate == TRUE) {
543 pDevice->uCwMin = C_CWMIN_A;
544 byMaxMin = 4;
545 } else {
546 pDevice->uCwMin = C_CWMIN_B;
547 byMaxMin = 5;
551 pDevice->uCwMax = C_CWMAX;
552 pDevice->uEIFS = C_EIFS;
554 byData[0] = (BYTE)pDevice->uSIFS;
555 byData[1] = (BYTE)pDevice->uDIFS;
556 byData[2] = (BYTE)pDevice->uEIFS;
557 byData[3] = (BYTE)pDevice->uSlot;
558 CONTROLnsRequestOut(pDevice,
559 MESSAGE_TYPE_WRITE,
560 MAC_REG_SIFS,
561 MESSAGE_REQUEST_MACREG,
563 &byData[0]);
565 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
566 CONTROLnsRequestOut(pDevice,
567 MESSAGE_TYPE_WRITE,
568 MAC_REG_CWMAXMIN0,
569 MESSAGE_REQUEST_MACREG,
571 &byMaxMin);
574 void CARDvUpdateBasicTopRate (PVOID pDeviceHandler)
576 PSDevice pDevice = (PSDevice) pDeviceHandler;
577 BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
578 BYTE ii;
580 //Determines the highest basic rate.
581 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
582 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
583 byTopOFDM = ii;
584 break;
587 pDevice->byTopOFDMBasicRate = byTopOFDM;
589 for (ii = RATE_11M;; ii --) {
590 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
591 byTopCCK = ii;
592 break;
594 if (ii == RATE_1M)
595 break;
597 pDevice->byTopCCKBasicRate = byTopCCK;
601 * Description: Set NIC Tx Basic Rate
603 * Parameters:
604 * In:
605 * pDevice - The adapter to be set
606 * wBasicRate - Basic Rate to be set
607 * Out:
608 * none
610 * Return Value: TRUE if succeeded; FALSE if failed.
613 BOOL CARDbAddBasicRate (PVOID pDeviceHandler, WORD wRateIdx)
615 PSDevice pDevice = (PSDevice) pDeviceHandler;
616 WORD wRate = (WORD)(1<<wRateIdx);
618 pDevice->wBasicRate |= wRate;
620 //Determines the highest basic rate.
621 CARDvUpdateBasicTopRate(pDevice);
623 return(TRUE);
626 BOOL CARDbIsOFDMinBasicRate (PVOID pDeviceHandler)
628 PSDevice pDevice = (PSDevice) pDeviceHandler;
629 int ii;
631 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
632 if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
633 return TRUE;
635 return FALSE;
638 BYTE CARDbyGetPktType (PVOID pDeviceHandler)
640 PSDevice pDevice = (PSDevice) pDeviceHandler;
642 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
643 return (BYTE)pDevice->byBBType;
645 else if (CARDbIsOFDMinBasicRate(pDevice)) {
646 return PK_TYPE_11GA;
648 else {
649 return PK_TYPE_11GB;
655 * Description: Caculate TSF offset of two TSF input
656 * Get TSF Offset from RxBCN's TSF and local TSF
658 * Parameters:
659 * In:
660 * pDevice - The adapter to be sync.
661 * qwTSF1 - Rx BCN's TSF
662 * qwTSF2 - Local TSF
663 * Out:
664 * none
666 * Return Value: TSF Offset value
669 QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2)
671 QWORD qwTSFOffset;
672 WORD wRxBcnTSFOffst = 0;
674 HIDWORD(qwTSFOffset) = 0;
675 LODWORD(qwTSFOffset) = 0;
677 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
678 (qwTSF2).u.dwLowDword += (DWORD)(wRxBcnTSFOffst);
679 if ((qwTSF2).u.dwLowDword < (DWORD)(wRxBcnTSFOffst)) {
680 (qwTSF2).u.dwHighDword++;
682 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
683 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
684 // if borrow needed
685 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
687 else {
688 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
690 return (qwTSFOffset);
696 * Description: Sync. TSF counter to BSS
697 * Get TSF offset and write to HW
699 * Parameters:
700 * In:
701 * pDevice - The adapter to be sync.
702 * qwBSSTimestamp - Rx BCN's TSF
703 * qwLocalTSF - Local TSF
704 * Out:
705 * none
707 * Return Value: none
710 void CARDvAdjustTSF (PVOID pDeviceHandler, BYTE byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
713 PSDevice pDevice = (PSDevice) pDeviceHandler;
714 QWORD qwTSFOffset;
715 DWORD dwTSFOffset1,dwTSFOffset2;
716 BYTE pbyData[8];
718 HIDWORD(qwTSFOffset) = 0;
719 LODWORD(qwTSFOffset) = 0;
721 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
722 // adjust TSF
723 // HW's TSF add TSF Offset reg
724 dwTSFOffset1 = LODWORD(qwTSFOffset);
725 dwTSFOffset2 = HIDWORD(qwTSFOffset);
728 pbyData[0] = (BYTE)dwTSFOffset1;
729 pbyData[1] = (BYTE)(dwTSFOffset1>>8);
730 pbyData[2] = (BYTE)(dwTSFOffset1>>16);
731 pbyData[3] = (BYTE)(dwTSFOffset1>>24);
732 pbyData[4] = (BYTE)dwTSFOffset2;
733 pbyData[5] = (BYTE)(dwTSFOffset2>>8);
734 pbyData[6] = (BYTE)(dwTSFOffset2>>16);
735 pbyData[7] = (BYTE)(dwTSFOffset2>>24);
737 CONTROLnsRequestOut(pDevice,
738 MESSAGE_TYPE_SET_TSFTBTT,
739 MESSAGE_REQUEST_TSF,
742 pbyData
747 * Description: Read NIC TSF counter
748 * Get local TSF counter
750 * Parameters:
751 * In:
752 * pDevice - The adapter to be read
753 * Out:
754 * qwCurrTSF - Current TSF counter
756 * Return Value: TRUE if success; otherwise FALSE
759 BOOL CARDbGetCurrentTSF (PVOID pDeviceHandler, PQWORD pqwCurrTSF)
761 PSDevice pDevice = (PSDevice) pDeviceHandler;
763 LODWORD(*pqwCurrTSF) = LODWORD(pDevice->qwCurrTSF);
764 HIDWORD(*pqwCurrTSF) = HIDWORD(pDevice->qwCurrTSF);
766 return(TRUE);
771 * Description: Clear NIC TSF counter
772 * Clear local TSF counter
774 * Parameters:
775 * In:
776 * pDevice - The adapter to be read
778 * Return Value: TRUE if success; otherwise FALSE
781 BOOL CARDbClearCurrentTSF(PVOID pDeviceHandler)
783 PSDevice pDevice = (PSDevice) pDeviceHandler;
785 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTRST);
787 LODWORD(pDevice->qwCurrTSF) = 0;
788 HIDWORD(pDevice->qwCurrTSF) = 0;
790 return(TRUE);
794 * Description: Read NIC TSF counter
795 * Get NEXTTBTT from adjusted TSF and Beacon Interval
797 * Parameters:
798 * In:
799 * qwTSF - Current TSF counter
800 * wbeaconInterval - Beacon Interval
801 * Out:
802 * qwCurrTSF - Current TSF counter
804 * Return Value: TSF value of next Beacon
807 QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval)
810 UINT uLowNextTBTT;
811 UINT uHighRemain, uLowRemain;
812 UINT uBeaconInterval;
814 uBeaconInterval = wBeaconInterval * 1024;
815 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
816 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
817 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
818 uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
819 % uBeaconInterval;
820 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
821 uLowRemain = uBeaconInterval - uLowRemain;
823 // check if carry when add one beacon interval
824 if ((~uLowNextTBTT) < uLowRemain)
825 HIDWORD(qwTSF) ++ ;
827 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
829 return (qwTSF);
834 * Description: Set NIC TSF counter for first Beacon time
835 * Get NEXTTBTT from adjusted TSF and Beacon Interval
837 * Parameters:
838 * In:
839 * dwIoBase - IO Base
840 * wBeaconInterval - Beacon Interval
841 * Out:
842 * none
844 * Return Value: none
847 void CARDvSetFirstNextTBTT (PVOID pDeviceHandler, WORD wBeaconInterval)
850 PSDevice pDevice = (PSDevice) pDeviceHandler;
851 QWORD qwNextTBTT;
852 DWORD dwLoTBTT,dwHiTBTT;
853 BYTE pbyData[8];
855 HIDWORD(qwNextTBTT) = 0;
856 LODWORD(qwNextTBTT) = 0;
857 CARDbClearCurrentTSF(pDevice);
858 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
859 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
860 // Set NextTBTT
862 dwLoTBTT = LODWORD(qwNextTBTT);
863 dwHiTBTT = HIDWORD(qwNextTBTT);
865 pbyData[0] = (BYTE)dwLoTBTT;
866 pbyData[1] = (BYTE)(dwLoTBTT>>8);
867 pbyData[2] = (BYTE)(dwLoTBTT>>16);
868 pbyData[3] = (BYTE)(dwLoTBTT>>24);
869 pbyData[4] = (BYTE)dwHiTBTT;
870 pbyData[5] = (BYTE)(dwHiTBTT>>8);
871 pbyData[6] = (BYTE)(dwHiTBTT>>16);
872 pbyData[7] = (BYTE)(dwHiTBTT>>24);
874 CONTROLnsRequestOut(pDevice,
875 MESSAGE_TYPE_SET_TSFTBTT,
876 MESSAGE_REQUEST_TBTT,
879 pbyData
882 return;
887 * Description: Sync NIC TSF counter for Beacon time
888 * Get NEXTTBTT and write to HW
890 * Parameters:
891 * In:
892 * pDevice - The adapter to be set
893 * qwTSF - Current TSF counter
894 * wBeaconInterval - Beacon Interval
895 * Out:
896 * none
898 * Return Value: none
901 void CARDvUpdateNextTBTT (PVOID pDeviceHandler, QWORD qwTSF, WORD wBeaconInterval)
903 PSDevice pDevice = (PSDevice) pDeviceHandler;
904 DWORD dwLoTBTT,dwHiTBTT;
905 BYTE pbyData[8];
907 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
909 // Set NextTBTT
910 dwLoTBTT = LODWORD(qwTSF);
911 dwHiTBTT = HIDWORD(qwTSF);
913 pbyData[0] = (BYTE)dwLoTBTT;
914 pbyData[1] = (BYTE)(dwLoTBTT>>8);
915 pbyData[2] = (BYTE)(dwLoTBTT>>16);
916 pbyData[3] = (BYTE)(dwLoTBTT>>24);
917 pbyData[4] = (BYTE)dwHiTBTT;
918 pbyData[5] = (BYTE)(dwHiTBTT>>8);
919 pbyData[6] = (BYTE)(dwHiTBTT>>16);
920 pbyData[7] = (BYTE)(dwHiTBTT>>24);
922 CONTROLnsRequestOut(pDevice,
923 MESSAGE_TYPE_SET_TSFTBTT,
924 MESSAGE_REQUEST_TBTT,
927 pbyData
931 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",(int)HIDWORD(qwTSF), (int)LODWORD(qwTSF));
933 return;
937 * Description: Turn off Radio power
939 * Parameters:
940 * In:
941 * pDevice - The adapter to be turned off
942 * Out:
943 * none
945 * Return Value: TRUE if success; otherwise FALSE
948 BOOL CARDbRadioPowerOff (PVOID pDeviceHandler)
950 PSDevice pDevice = (PSDevice) pDeviceHandler;
951 BOOL bResult = TRUE;
953 //if (pDevice->bRadioOff == TRUE)
954 // return TRUE;
956 pDevice->bRadioOff = TRUE;
958 switch (pDevice->byRFType) {
959 case RF_AL2230:
960 case RF_AL2230S:
961 case RF_AIROHA7230:
962 case RF_VT3226: //RobertYu:20051111
963 case RF_VT3226D0:
964 case RF_VT3342A0: //RobertYu:20060609
965 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
966 break;
969 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
971 BBvSetDeepSleep(pDevice);
973 return bResult;
978 * Description: Turn on Radio power
980 * Parameters:
981 * In:
982 * pDevice - The adapter to be turned on
983 * Out:
984 * none
986 * Return Value: TRUE if success; otherwise FALSE
989 BOOL CARDbRadioPowerOn (PVOID pDeviceHandler)
991 PSDevice pDevice = (PSDevice) pDeviceHandler;
992 BOOL bResult = TRUE;
995 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
996 return FALSE;
999 //if (pDevice->bRadioOff == FALSE)
1000 // return TRUE;
1002 pDevice->bRadioOff = FALSE;
1004 BBvExitDeepSleep(pDevice);
1006 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
1008 switch (pDevice->byRFType) {
1009 case RF_AL2230:
1010 case RF_AL2230S:
1011 case RF_AIROHA7230:
1012 case RF_VT3226: //RobertYu:20051111
1013 case RF_VT3226D0:
1014 case RF_VT3342A0: //RobertYu:20060609
1015 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
1016 break;
1019 return bResult;
1022 void CARDvSetBSSMode (PVOID pDeviceHandler)
1024 PSDevice pDevice = (PSDevice) pDeviceHandler;
1025 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
1026 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
1027 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
1029 MACvSetBBType(pDevice, BB_TYPE_11G);
1031 else
1033 MACvSetBBType(pDevice, pDevice->byBBType);
1035 pDevice->byPacketType = CARDbyGetPktType(pDevice);
1037 if (pDevice->byBBType == BB_TYPE_11A) {
1038 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
1039 } else if (pDevice->byBBType == BB_TYPE_11B) {
1040 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
1041 } else if (pDevice->byBBType == BB_TYPE_11G) {
1042 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
1045 vUpdateIFS(pDevice);
1046 CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
1048 if ( pDevice->byBBType == BB_TYPE_11A ) {
1049 //request by Jack 2005-04-26
1050 if (pDevice->byRFType == RF_AIROHA7230) {
1051 pDevice->abyBBVGA[0] = 0x20;
1052 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1054 pDevice->abyBBVGA[2] = 0x10;
1055 pDevice->abyBBVGA[3] = 0x10;
1056 } else {
1057 //request by Jack 2005-04-26
1058 if (pDevice->byRFType == RF_AIROHA7230) {
1059 pDevice->abyBBVGA[0] = 0x1C;
1060 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1062 pDevice->abyBBVGA[2] = 0x0;
1063 pDevice->abyBBVGA[3] = 0x0;
1069 * Description:
1070 * Do Channel Switch defined in 802.11h
1072 * Parameters:
1073 * In:
1074 * hDeviceContext - device structure point
1075 * Out:
1076 * none
1078 * Return Value: none.
1081 BOOL
1082 CARDbChannelSwitch (
1083 IN PVOID pDeviceHandler,
1084 IN BYTE byMode,
1085 IN BYTE byNewChannel,
1086 IN BYTE byCount
1089 PSDevice pDevice = (PSDevice) pDeviceHandler;
1090 BOOL bResult = TRUE;
1092 if (byCount == 0) {
1093 pDevice->sMgmtObj.uCurrChannel = byNewChannel;
1094 bResult = CARDbSetMediaChannel(pDevice, byNewChannel);
1096 return(bResult);
1098 pDevice->byChannelSwitchCount = byCount;
1099 pDevice->byNewChannel = byNewChannel;
1100 pDevice->bChannelSwitch = TRUE;
1102 if (byMode == 1) {
1103 //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1104 pDevice->bStopDataPkt = TRUE;
1106 return (bResult);