spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / staging / vt6656 / card.c
blob9d09e9fd8e182edece0445d7c990b708588ae400
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 void CARDbSetMediaChannel(void *pDeviceHandler, unsigned int uConnectionChannel)
97 PSDevice pDevice = (PSDevice) pDeviceHandler;
99 if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38
100 if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL))
101 uConnectionChannel = (CB_MAX_CHANNEL_24G+1);
102 } else {
103 if ((uConnectionChannel > CB_MAX_CHANNEL_24G) || (uConnectionChannel == 0)) // 1 ~ 14
104 uConnectionChannel = 1;
107 // clear NAV
108 MACvRegBitsOn(pDevice, MAC_REG_MACCR, MACCR_CLRNAV);
110 // Set Channel[7] = 0 to tell H/W channel is changing now.
111 MACvRegBitsOff(pDevice, MAC_REG_CHANNEL, 0x80);
113 //if (pMgmt->uCurrChannel == uConnectionChannel)
114 // return bResult;
116 CONTROLnsRequestOut(pDevice,
117 MESSAGE_TYPE_SELECT_CHANNLE,
118 (WORD) uConnectionChannel,
121 NULL
124 //{{ RobertYu: 20041202
125 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
127 if (pDevice->byBBType == BB_TYPE_11A) {
128 pDevice->byCurPwr = 0xFF;
129 RFbRawSetPower(pDevice, pDevice->abyOFDMAPwrTbl[uConnectionChannel-15], RATE_54M);
130 } else if (pDevice->byBBType == BB_TYPE_11G) {
131 pDevice->byCurPwr = 0xFF;
132 RFbRawSetPower(pDevice, pDevice->abyOFDMPwrTbl[uConnectionChannel-1], RATE_54M);
133 } else {
134 pDevice->byCurPwr = 0xFF;
135 RFbRawSetPower(pDevice, pDevice->abyCCKPwrTbl[uConnectionChannel-1], RATE_1M);
137 ControlvWriteByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_CHANNEL,(BYTE)(uConnectionChannel|0x80));
141 * Description: Get CCK mode basic rate
143 * Parameters:
144 * In:
145 * pDevice - The adapter to be set
146 * wRateIdx - Receiving data rate
147 * Out:
148 * none
150 * Return Value: response Control frame rate
153 static WORD swGetCCKControlRate(void *pDeviceHandler, WORD wRateIdx)
155 PSDevice pDevice = (PSDevice) pDeviceHandler;
156 unsigned int ui = (unsigned int)wRateIdx;
157 while (ui > RATE_1M) {
158 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
159 return (WORD)ui;
161 ui --;
163 return (WORD)RATE_1M;
167 * Description: Get OFDM mode basic rate
169 * Parameters:
170 * In:
171 * pDevice - The adapter to be set
172 * wRateIdx - Receiving data rate
173 * Out:
174 * none
176 * Return Value: response Control frame rate
179 static WORD swGetOFDMControlRate(void *pDeviceHandler, WORD wRateIdx)
181 PSDevice pDevice = (PSDevice) pDeviceHandler;
182 unsigned int ui = (unsigned int)wRateIdx;
184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
186 if (!CARDbIsOFDMinBasicRate(pDevice)) {
187 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
188 if (wRateIdx > RATE_24M)
189 wRateIdx = RATE_24M;
190 return wRateIdx;
192 while (ui > RATE_11M) {
193 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate : %d\n", ui);
195 return (WORD)ui;
197 ui --;
199 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n");
200 return (WORD)RATE_24M;
204 * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
206 * Parameters:
207 * In:
208 * wRate - Tx Rate
209 * byPktType - Tx Packet type
210 * Out:
211 * pbyTxRate - pointer to RSPINF TxRate field
212 * pbyRsvTime - pointer to RSPINF RsvTime field
214 * Return Value: none
217 void
218 CARDvCaculateOFDMRParameter (
219 WORD wRate,
220 BYTE byBBType,
221 PBYTE pbyTxRate,
222 PBYTE pbyRsvTime
225 switch (wRate) {
226 case RATE_6M :
227 if (byBBType == BB_TYPE_11A) {//5GHZ
228 *pbyTxRate = 0x9B;
229 *pbyRsvTime = 24;
231 else {
232 *pbyTxRate = 0x8B;
233 *pbyRsvTime = 30;
235 break;
237 case RATE_9M :
238 if (byBBType == BB_TYPE_11A) {//5GHZ
239 *pbyTxRate = 0x9F;
240 *pbyRsvTime = 16;
242 else {
243 *pbyTxRate = 0x8F;
244 *pbyRsvTime = 22;
246 break;
248 case RATE_12M :
249 if (byBBType == BB_TYPE_11A) {//5GHZ
250 *pbyTxRate = 0x9A;
251 *pbyRsvTime = 12;
253 else {
254 *pbyTxRate = 0x8A;
255 *pbyRsvTime = 18;
257 break;
259 case RATE_18M :
260 if (byBBType == BB_TYPE_11A) {//5GHZ
261 *pbyTxRate = 0x9E;
262 *pbyRsvTime = 8;
264 else {
265 *pbyTxRate = 0x8E;
266 *pbyRsvTime = 14;
268 break;
270 case RATE_36M :
271 if (byBBType == BB_TYPE_11A) {//5GHZ
272 *pbyTxRate = 0x9D;
273 *pbyRsvTime = 4;
275 else {
276 *pbyTxRate = 0x8D;
277 *pbyRsvTime = 10;
279 break;
281 case RATE_48M :
282 if (byBBType == BB_TYPE_11A) {//5GHZ
283 *pbyTxRate = 0x98;
284 *pbyRsvTime = 4;
286 else {
287 *pbyTxRate = 0x88;
288 *pbyRsvTime = 10;
290 break;
292 case RATE_54M :
293 if (byBBType == BB_TYPE_11A) {//5GHZ
294 *pbyTxRate = 0x9C;
295 *pbyRsvTime = 4;
297 else {
298 *pbyTxRate = 0x8C;
299 *pbyRsvTime = 10;
301 break;
303 case RATE_24M :
304 default :
305 if (byBBType == BB_TYPE_11A) {//5GHZ
306 *pbyTxRate = 0x99;
307 *pbyRsvTime = 8;
309 else {
310 *pbyTxRate = 0x89;
311 *pbyRsvTime = 14;
313 break;
318 * Description: Set RSPINF
320 * Parameters:
321 * In:
322 * pDevice - The adapter to be set
323 * Out:
324 * none
326 * Return Value: None.
329 void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType)
331 PSDevice pDevice = (PSDevice) pDeviceHandler;
332 BYTE abyServ[4] = {0,0,0,0}; // For CCK
333 BYTE abySignal[4] = {0,0,0,0};
334 WORD awLen[4] = {0,0,0,0};
335 BYTE abyTxRate[9] = {0,0,0,0,0,0,0,0,0}; // For OFDM
336 BYTE abyRsvTime[9] = {0,0,0,0,0,0,0,0,0};
337 BYTE abyData[34];
338 int i;
340 //RSPINF_b_1
341 BBvCaculateParameter(pDevice,
343 swGetCCKControlRate(pDevice, RATE_1M),
344 PK_TYPE_11B,
345 &awLen[0],
346 &abyServ[0],
347 &abySignal[0]
350 ///RSPINF_b_2
351 BBvCaculateParameter(pDevice,
353 swGetCCKControlRate(pDevice, RATE_2M),
354 PK_TYPE_11B,
355 &awLen[1],
356 &abyServ[1],
357 &abySignal[1]
360 //RSPINF_b_5
361 BBvCaculateParameter(pDevice,
363 swGetCCKControlRate(pDevice, RATE_5M),
364 PK_TYPE_11B,
365 &awLen[2],
366 &abyServ[2],
367 &abySignal[2]
370 //RSPINF_b_11
371 BBvCaculateParameter(pDevice,
373 swGetCCKControlRate(pDevice, RATE_11M),
374 PK_TYPE_11B,
375 &awLen[3],
376 &abyServ[3],
377 &abySignal[3]
380 //RSPINF_a_6
381 CARDvCaculateOFDMRParameter (RATE_6M,
382 byBBType,
383 &abyTxRate[0],
384 &abyRsvTime[0]);
386 //RSPINF_a_9
387 CARDvCaculateOFDMRParameter (RATE_9M,
388 byBBType,
389 &abyTxRate[1],
390 &abyRsvTime[1]);
392 //RSPINF_a_12
393 CARDvCaculateOFDMRParameter (RATE_12M,
394 byBBType,
395 &abyTxRate[2],
396 &abyRsvTime[2]);
398 //RSPINF_a_18
399 CARDvCaculateOFDMRParameter (RATE_18M,
400 byBBType,
401 &abyTxRate[3],
402 &abyRsvTime[3]);
404 //RSPINF_a_24
405 CARDvCaculateOFDMRParameter (RATE_24M,
406 byBBType,
407 &abyTxRate[4],
408 &abyRsvTime[4]);
410 //RSPINF_a_36
411 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
412 byBBType,
413 &abyTxRate[5],
414 &abyRsvTime[5]);
416 //RSPINF_a_48
417 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
418 byBBType,
419 &abyTxRate[6],
420 &abyRsvTime[6]);
422 //RSPINF_a_54
423 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
424 byBBType,
425 &abyTxRate[7],
426 &abyRsvTime[7]);
428 //RSPINF_a_72
429 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
430 byBBType,
431 &abyTxRate[8],
432 &abyRsvTime[8]);
434 abyData[0] = (BYTE)(awLen[0]&0xFF);
435 abyData[1] = (BYTE)(awLen[0]>>8);
436 abyData[2] = abySignal[0];
437 abyData[3] = abyServ[0];
439 abyData[4] = (BYTE)(awLen[1]&0xFF);
440 abyData[5] = (BYTE)(awLen[1]>>8);
441 abyData[6] = abySignal[1];
442 abyData[7] = abyServ[1];
444 abyData[8] = (BYTE)(awLen[2]&0xFF);
445 abyData[9] = (BYTE)(awLen[2]>>8);
446 abyData[10] = abySignal[2];
447 abyData[11] = abyServ[2];
449 abyData[12] = (BYTE)(awLen[3]&0xFF);
450 abyData[13] = (BYTE)(awLen[3]>>8);
451 abyData[14] = abySignal[3];
452 abyData[15] = abyServ[3];
454 for (i = 0; i < 9; i++) {
455 abyData[16+i*2] = abyTxRate[i];
456 abyData[16+i*2+1] = abyRsvTime[i];
459 CONTROLnsRequestOut(pDevice,
460 MESSAGE_TYPE_WRITE,
461 MAC_REG_RSPINF_B_1,
462 MESSAGE_REQUEST_MACREG,
464 &abyData[0]);
469 * Description: Update IFS
471 * Parameters:
472 * In:
473 * pDevice - The adapter to be set
474 * Out:
475 * none
477 * Return Value: None.
480 void vUpdateIFS(void *pDeviceHandler)
482 PSDevice pDevice = (PSDevice) pDeviceHandler;
483 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
484 BYTE byMaxMin = 0;
485 BYTE byData[4];
487 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
488 pDevice->uSlot = C_SLOT_SHORT;
489 pDevice->uSIFS = C_SIFS_A;
490 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
491 pDevice->uCwMin = C_CWMIN_A;
492 byMaxMin = 4;
494 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
495 pDevice->uSlot = C_SLOT_LONG;
496 pDevice->uSIFS = C_SIFS_BG;
497 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
498 pDevice->uCwMin = C_CWMIN_B;
499 byMaxMin = 5;
501 else {// PK_TYPE_11GA & PK_TYPE_11GB
502 BYTE byRate = 0;
503 BOOL bOFDMRate = FALSE;
504 unsigned int ii = 0;
505 PWLAN_IE_SUPP_RATES pItemRates = NULL;
507 pDevice->uSIFS = C_SIFS_BG;
508 if (pDevice->bShortSlotTime) {
509 pDevice->uSlot = C_SLOT_SHORT;
510 } else {
511 pDevice->uSlot = C_SLOT_LONG;
513 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
515 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrSuppRates;
516 for (ii = 0; ii < pItemRates->len; ii++) {
517 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
518 if (RATEwGetRateIdx(byRate) > RATE_11M) {
519 bOFDMRate = TRUE;
520 break;
523 if (bOFDMRate == FALSE) {
524 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrExtSuppRates;
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;
533 if (bOFDMRate == TRUE) {
534 pDevice->uCwMin = C_CWMIN_A;
535 byMaxMin = 4;
536 } else {
537 pDevice->uCwMin = C_CWMIN_B;
538 byMaxMin = 5;
542 pDevice->uCwMax = C_CWMAX;
543 pDevice->uEIFS = C_EIFS;
545 byData[0] = (BYTE)pDevice->uSIFS;
546 byData[1] = (BYTE)pDevice->uDIFS;
547 byData[2] = (BYTE)pDevice->uEIFS;
548 byData[3] = (BYTE)pDevice->uSlot;
549 CONTROLnsRequestOut(pDevice,
550 MESSAGE_TYPE_WRITE,
551 MAC_REG_SIFS,
552 MESSAGE_REQUEST_MACREG,
554 &byData[0]);
556 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
557 CONTROLnsRequestOut(pDevice,
558 MESSAGE_TYPE_WRITE,
559 MAC_REG_CWMAXMIN0,
560 MESSAGE_REQUEST_MACREG,
562 &byMaxMin);
565 void CARDvUpdateBasicTopRate(void *pDeviceHandler)
567 PSDevice pDevice = (PSDevice) pDeviceHandler;
568 BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
569 BYTE ii;
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;
578 pDevice->byTopOFDMBasicRate = byTopOFDM;
580 for (ii = RATE_11M;; ii --) {
581 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
582 byTopCCK = ii;
583 break;
585 if (ii == RATE_1M)
586 break;
588 pDevice->byTopCCKBasicRate = byTopCCK;
592 * Description: Set NIC Tx Basic Rate
594 * Parameters:
595 * In:
596 * pDevice - The adapter to be set
597 * wBasicRate - Basic Rate to be set
598 * Out:
599 * none
601 * Return Value: TRUE if succeeded; FALSE if failed.
604 void CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx)
606 PSDevice pDevice = (PSDevice) pDeviceHandler;
607 WORD wRate = (WORD)(1<<wRateIdx);
609 pDevice->wBasicRate |= wRate;
611 //Determines the highest basic rate.
612 CARDvUpdateBasicTopRate(pDevice);
615 BOOL CARDbIsOFDMinBasicRate(void *pDeviceHandler)
617 PSDevice pDevice = (PSDevice) pDeviceHandler;
618 int ii;
620 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
621 if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
622 return TRUE;
624 return FALSE;
627 BYTE CARDbyGetPktType(void *pDeviceHandler)
629 PSDevice pDevice = (PSDevice) pDeviceHandler;
631 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
632 return (BYTE)pDevice->byBBType;
634 else if (CARDbIsOFDMinBasicRate(pDevice)) {
635 return PK_TYPE_11GA;
637 else {
638 return PK_TYPE_11GB;
644 * Description: Caculate TSF offset of two TSF input
645 * Get TSF Offset from RxBCN's TSF and local TSF
647 * Parameters:
648 * In:
649 * pDevice - The adapter to be sync.
650 * qwTSF1 - Rx BCN's TSF
651 * qwTSF2 - Local TSF
652 * Out:
653 * none
655 * Return Value: TSF Offset value
658 QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2)
660 QWORD qwTSFOffset;
661 WORD wRxBcnTSFOffst = 0;
663 HIDWORD(qwTSFOffset) = 0;
664 LODWORD(qwTSFOffset) = 0;
666 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
667 (qwTSF2).u.dwLowDword += (DWORD)(wRxBcnTSFOffst);
668 if ((qwTSF2).u.dwLowDword < (DWORD)(wRxBcnTSFOffst)) {
669 (qwTSF2).u.dwHighDword++;
671 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
672 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
673 // if borrow needed
674 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
676 else {
677 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
679 return (qwTSFOffset);
685 * Description: Sync. TSF counter to BSS
686 * Get TSF offset and write to HW
688 * Parameters:
689 * In:
690 * pDevice - The adapter to be sync.
691 * qwBSSTimestamp - Rx BCN's TSF
692 * qwLocalTSF - Local TSF
693 * Out:
694 * none
696 * Return Value: none
699 void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate,
700 QWORD qwBSSTimestamp, QWORD qwLocalTSF)
703 PSDevice pDevice = (PSDevice) pDeviceHandler;
704 QWORD qwTSFOffset;
705 DWORD dwTSFOffset1,dwTSFOffset2;
706 BYTE pbyData[8];
708 HIDWORD(qwTSFOffset) = 0;
709 LODWORD(qwTSFOffset) = 0;
711 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
712 // adjust TSF
713 // HW's TSF add TSF Offset reg
714 dwTSFOffset1 = LODWORD(qwTSFOffset);
715 dwTSFOffset2 = HIDWORD(qwTSFOffset);
718 pbyData[0] = (BYTE)dwTSFOffset1;
719 pbyData[1] = (BYTE)(dwTSFOffset1>>8);
720 pbyData[2] = (BYTE)(dwTSFOffset1>>16);
721 pbyData[3] = (BYTE)(dwTSFOffset1>>24);
722 pbyData[4] = (BYTE)dwTSFOffset2;
723 pbyData[5] = (BYTE)(dwTSFOffset2>>8);
724 pbyData[6] = (BYTE)(dwTSFOffset2>>16);
725 pbyData[7] = (BYTE)(dwTSFOffset2>>24);
727 CONTROLnsRequestOut(pDevice,
728 MESSAGE_TYPE_SET_TSFTBTT,
729 MESSAGE_REQUEST_TSF,
732 pbyData
737 * Description: Read NIC TSF counter
738 * Get local TSF counter
740 * Parameters:
741 * In:
742 * pDevice - The adapter to be read
743 * Out:
744 * qwCurrTSF - Current TSF counter
746 * Return Value: TRUE if success; otherwise FALSE
749 BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF)
751 PSDevice pDevice = (PSDevice) pDeviceHandler;
753 LODWORD(*pqwCurrTSF) = LODWORD(pDevice->qwCurrTSF);
754 HIDWORD(*pqwCurrTSF) = HIDWORD(pDevice->qwCurrTSF);
756 return(TRUE);
761 * Description: Clear NIC TSF counter
762 * Clear local TSF counter
764 * Parameters:
765 * In:
766 * pDevice - The adapter to be read
768 * Return Value: TRUE if success; otherwise FALSE
771 BOOL CARDbClearCurrentTSF(void *pDeviceHandler)
773 PSDevice pDevice = (PSDevice) pDeviceHandler;
775 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTRST);
777 LODWORD(pDevice->qwCurrTSF) = 0;
778 HIDWORD(pDevice->qwCurrTSF) = 0;
780 return(TRUE);
784 * Description: Read NIC TSF counter
785 * Get NEXTTBTT from adjusted TSF and Beacon Interval
787 * Parameters:
788 * In:
789 * qwTSF - Current TSF counter
790 * wbeaconInterval - Beacon Interval
791 * Out:
792 * qwCurrTSF - Current TSF counter
794 * Return Value: TSF value of next Beacon
797 QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval)
800 unsigned int uLowNextTBTT;
801 unsigned int uHighRemain, uLowRemain;
802 unsigned int uBeaconInterval;
804 uBeaconInterval = wBeaconInterval * 1024;
805 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
806 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
807 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
808 uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
809 % uBeaconInterval;
810 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
811 uLowRemain = uBeaconInterval - uLowRemain;
813 // check if carry when add one beacon interval
814 if ((~uLowNextTBTT) < uLowRemain)
815 HIDWORD(qwTSF) ++ ;
817 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
819 return (qwTSF);
824 * Description: Set NIC TSF counter for first Beacon time
825 * Get NEXTTBTT from adjusted TSF and Beacon Interval
827 * Parameters:
828 * In:
829 * dwIoBase - IO Base
830 * wBeaconInterval - Beacon Interval
831 * Out:
832 * none
834 * Return Value: none
837 void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval)
840 PSDevice pDevice = (PSDevice) pDeviceHandler;
841 QWORD qwNextTBTT;
842 DWORD dwLoTBTT,dwHiTBTT;
843 BYTE pbyData[8];
845 HIDWORD(qwNextTBTT) = 0;
846 LODWORD(qwNextTBTT) = 0;
847 CARDbClearCurrentTSF(pDevice);
848 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
849 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
850 // Set NextTBTT
852 dwLoTBTT = LODWORD(qwNextTBTT);
853 dwHiTBTT = HIDWORD(qwNextTBTT);
855 pbyData[0] = (BYTE)dwLoTBTT;
856 pbyData[1] = (BYTE)(dwLoTBTT>>8);
857 pbyData[2] = (BYTE)(dwLoTBTT>>16);
858 pbyData[3] = (BYTE)(dwLoTBTT>>24);
859 pbyData[4] = (BYTE)dwHiTBTT;
860 pbyData[5] = (BYTE)(dwHiTBTT>>8);
861 pbyData[6] = (BYTE)(dwHiTBTT>>16);
862 pbyData[7] = (BYTE)(dwHiTBTT>>24);
864 CONTROLnsRequestOut(pDevice,
865 MESSAGE_TYPE_SET_TSFTBTT,
866 MESSAGE_REQUEST_TBTT,
869 pbyData
872 return;
877 * Description: Sync NIC TSF counter for Beacon time
878 * Get NEXTTBTT and write to HW
880 * Parameters:
881 * In:
882 * pDevice - The adapter to be set
883 * qwTSF - Current TSF counter
884 * wBeaconInterval - Beacon Interval
885 * Out:
886 * none
888 * Return Value: none
891 void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF,
892 WORD wBeaconInterval)
894 PSDevice pDevice = (PSDevice) pDeviceHandler;
895 DWORD dwLoTBTT,dwHiTBTT;
896 BYTE pbyData[8];
898 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
900 // Set NextTBTT
901 dwLoTBTT = LODWORD(qwTSF);
902 dwHiTBTT = HIDWORD(qwTSF);
904 pbyData[0] = (BYTE)dwLoTBTT;
905 pbyData[1] = (BYTE)(dwLoTBTT>>8);
906 pbyData[2] = (BYTE)(dwLoTBTT>>16);
907 pbyData[3] = (BYTE)(dwLoTBTT>>24);
908 pbyData[4] = (BYTE)dwHiTBTT;
909 pbyData[5] = (BYTE)(dwHiTBTT>>8);
910 pbyData[6] = (BYTE)(dwHiTBTT>>16);
911 pbyData[7] = (BYTE)(dwHiTBTT>>24);
913 CONTROLnsRequestOut(pDevice,
914 MESSAGE_TYPE_SET_TSFTBTT,
915 MESSAGE_REQUEST_TBTT,
918 pbyData
922 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",(int)HIDWORD(qwTSF), (int)LODWORD(qwTSF));
924 return;
928 * Description: Turn off Radio power
930 * Parameters:
931 * In:
932 * pDevice - The adapter to be turned off
933 * Out:
934 * none
936 * Return Value: TRUE if success; otherwise FALSE
939 BOOL CARDbRadioPowerOff(void *pDeviceHandler)
941 PSDevice pDevice = (PSDevice) pDeviceHandler;
942 BOOL bResult = TRUE;
944 //if (pDevice->bRadioOff == TRUE)
945 // return TRUE;
947 pDevice->bRadioOff = TRUE;
949 switch (pDevice->byRFType) {
950 case RF_AL2230:
951 case RF_AL2230S:
952 case RF_AIROHA7230:
953 case RF_VT3226: //RobertYu:20051111
954 case RF_VT3226D0:
955 case RF_VT3342A0: //RobertYu:20060609
956 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
957 break;
960 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
962 BBvSetDeepSleep(pDevice);
964 return bResult;
969 * Description: Turn on Radio power
971 * Parameters:
972 * In:
973 * pDevice - The adapter to be turned on
974 * Out:
975 * none
977 * Return Value: TRUE if success; otherwise FALSE
980 BOOL CARDbRadioPowerOn(void *pDeviceHandler)
982 PSDevice pDevice = (PSDevice) pDeviceHandler;
983 BOOL bResult = TRUE;
986 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
987 return FALSE;
990 //if (pDevice->bRadioOff == FALSE)
991 // return TRUE;
993 pDevice->bRadioOff = FALSE;
995 BBvExitDeepSleep(pDevice);
997 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
999 switch (pDevice->byRFType) {
1000 case RF_AL2230:
1001 case RF_AL2230S:
1002 case RF_AIROHA7230:
1003 case RF_VT3226: //RobertYu:20051111
1004 case RF_VT3226D0:
1005 case RF_VT3342A0: //RobertYu:20060609
1006 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
1007 break;
1010 return bResult;
1013 void CARDvSetBSSMode(void *pDeviceHandler)
1015 PSDevice pDevice = (PSDevice) pDeviceHandler;
1016 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
1017 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
1018 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
1020 MACvSetBBType(pDevice, BB_TYPE_11G);
1022 else
1024 MACvSetBBType(pDevice, pDevice->byBBType);
1026 pDevice->byPacketType = CARDbyGetPktType(pDevice);
1028 if (pDevice->byBBType == BB_TYPE_11A) {
1029 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
1030 } else if (pDevice->byBBType == BB_TYPE_11B) {
1031 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
1032 } else if (pDevice->byBBType == BB_TYPE_11G) {
1033 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
1036 vUpdateIFS(pDevice);
1037 CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
1039 if ( pDevice->byBBType == BB_TYPE_11A ) {
1040 //request by Jack 2005-04-26
1041 if (pDevice->byRFType == RF_AIROHA7230) {
1042 pDevice->abyBBVGA[0] = 0x20;
1043 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1045 pDevice->abyBBVGA[2] = 0x10;
1046 pDevice->abyBBVGA[3] = 0x10;
1047 } else {
1048 //request by Jack 2005-04-26
1049 if (pDevice->byRFType == RF_AIROHA7230) {
1050 pDevice->abyBBVGA[0] = 0x1C;
1051 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1053 pDevice->abyBBVGA[2] = 0x0;
1054 pDevice->abyBBVGA[3] = 0x0;
1060 * Description:
1061 * Do Channel Switch defined in 802.11h
1063 * Parameters:
1064 * In:
1065 * hDeviceContext - device structure point
1066 * Out:
1067 * none
1069 * Return Value: none.
1072 BOOL
1073 CARDbChannelSwitch (
1074 void *pDeviceHandler,
1075 BYTE byMode,
1076 BYTE byNewChannel,
1077 BYTE byCount
1080 PSDevice pDevice = (PSDevice) pDeviceHandler;
1081 BOOL bResult = TRUE;
1083 if (byCount == 0) {
1084 pDevice->sMgmtObj.uCurrChannel = byNewChannel;
1085 CARDbSetMediaChannel(pDevice, byNewChannel);
1087 return bResult;
1089 pDevice->byChannelSwitchCount = byCount;
1090 pDevice->byNewChannel = byNewChannel;
1091 pDevice->bChannelSwitch = TRUE;
1093 if (byMode == 1) {
1094 //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1095 pDevice->bStopDataPkt = TRUE;
1097 return bResult;