tty/serial: atmel_serial: whitespace and braces modifications
[zen-stable.git] / drivers / staging / vt6656 / card.c
bloba49053bd7c65e1977fcbfb8ef3951c0cad290ae3
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(void *pDeviceHandler, unsigned int 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 WORD swGetCCKControlRate(void *pDeviceHandler, WORD wRateIdx)
161 PSDevice pDevice = (PSDevice) pDeviceHandler;
162 unsigned int ui = (unsigned int)wRateIdx;
163 while (ui > RATE_1M) {
164 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
165 return (WORD)ui;
167 ui --;
169 return (WORD)RATE_1M;
173 * Description: Get OFDM mode basic rate
175 * Parameters:
176 * In:
177 * pDevice - The adapter to be set
178 * wRateIdx - Receiving data rate
179 * Out:
180 * none
182 * Return Value: response Control frame rate
185 static WORD swGetOFDMControlRate(void *pDeviceHandler, WORD wRateIdx)
187 PSDevice pDevice = (PSDevice) pDeviceHandler;
188 unsigned int ui = (unsigned int)wRateIdx;
190 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
192 if (!CARDbIsOFDMinBasicRate(pDevice)) {
193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
194 if (wRateIdx > RATE_24M)
195 wRateIdx = RATE_24M;
196 return wRateIdx;
198 while (ui > RATE_11M) {
199 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
200 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate : %d\n", ui);
201 return (WORD)ui;
203 ui --;
205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n");
206 return (WORD)RATE_24M;
210 * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
212 * Parameters:
213 * In:
214 * wRate - Tx Rate
215 * byPktType - Tx Packet type
216 * Out:
217 * pbyTxRate - pointer to RSPINF TxRate field
218 * pbyRsvTime - pointer to RSPINF RsvTime field
220 * Return Value: none
223 void
224 CARDvCaculateOFDMRParameter (
225 WORD wRate,
226 BYTE byBBType,
227 PBYTE pbyTxRate,
228 PBYTE pbyRsvTime
231 switch (wRate) {
232 case RATE_6M :
233 if (byBBType == BB_TYPE_11A) {//5GHZ
234 *pbyTxRate = 0x9B;
235 *pbyRsvTime = 24;
237 else {
238 *pbyTxRate = 0x8B;
239 *pbyRsvTime = 30;
241 break;
243 case RATE_9M :
244 if (byBBType == BB_TYPE_11A) {//5GHZ
245 *pbyTxRate = 0x9F;
246 *pbyRsvTime = 16;
248 else {
249 *pbyTxRate = 0x8F;
250 *pbyRsvTime = 22;
252 break;
254 case RATE_12M :
255 if (byBBType == BB_TYPE_11A) {//5GHZ
256 *pbyTxRate = 0x9A;
257 *pbyRsvTime = 12;
259 else {
260 *pbyTxRate = 0x8A;
261 *pbyRsvTime = 18;
263 break;
265 case RATE_18M :
266 if (byBBType == BB_TYPE_11A) {//5GHZ
267 *pbyTxRate = 0x9E;
268 *pbyRsvTime = 8;
270 else {
271 *pbyTxRate = 0x8E;
272 *pbyRsvTime = 14;
274 break;
276 case RATE_36M :
277 if (byBBType == BB_TYPE_11A) {//5GHZ
278 *pbyTxRate = 0x9D;
279 *pbyRsvTime = 4;
281 else {
282 *pbyTxRate = 0x8D;
283 *pbyRsvTime = 10;
285 break;
287 case RATE_48M :
288 if (byBBType == BB_TYPE_11A) {//5GHZ
289 *pbyTxRate = 0x98;
290 *pbyRsvTime = 4;
292 else {
293 *pbyTxRate = 0x88;
294 *pbyRsvTime = 10;
296 break;
298 case RATE_54M :
299 if (byBBType == BB_TYPE_11A) {//5GHZ
300 *pbyTxRate = 0x9C;
301 *pbyRsvTime = 4;
303 else {
304 *pbyTxRate = 0x8C;
305 *pbyRsvTime = 10;
307 break;
309 case RATE_24M :
310 default :
311 if (byBBType == BB_TYPE_11A) {//5GHZ
312 *pbyTxRate = 0x99;
313 *pbyRsvTime = 8;
315 else {
316 *pbyTxRate = 0x89;
317 *pbyRsvTime = 14;
319 break;
324 * Description: Set RSPINF
326 * Parameters:
327 * In:
328 * pDevice - The adapter to be set
329 * Out:
330 * none
332 * Return Value: None.
335 void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType)
337 PSDevice pDevice = (PSDevice) pDeviceHandler;
338 BYTE abyServ[4] = {0,0,0,0}; // For CCK
339 BYTE abySignal[4] = {0,0,0,0};
340 WORD awLen[4] = {0,0,0,0};
341 BYTE abyTxRate[9] = {0,0,0,0,0,0,0,0,0}; // For OFDM
342 BYTE abyRsvTime[9] = {0,0,0,0,0,0,0,0,0};
343 BYTE abyData[34];
344 int i;
346 //RSPINF_b_1
347 BBvCaculateParameter(pDevice,
349 swGetCCKControlRate(pDevice, RATE_1M),
350 PK_TYPE_11B,
351 &awLen[0],
352 &abyServ[0],
353 &abySignal[0]
356 ///RSPINF_b_2
357 BBvCaculateParameter(pDevice,
359 swGetCCKControlRate(pDevice, RATE_2M),
360 PK_TYPE_11B,
361 &awLen[1],
362 &abyServ[1],
363 &abySignal[1]
366 //RSPINF_b_5
367 BBvCaculateParameter(pDevice,
369 swGetCCKControlRate(pDevice, RATE_5M),
370 PK_TYPE_11B,
371 &awLen[2],
372 &abyServ[2],
373 &abySignal[2]
376 //RSPINF_b_11
377 BBvCaculateParameter(pDevice,
379 swGetCCKControlRate(pDevice, RATE_11M),
380 PK_TYPE_11B,
381 &awLen[3],
382 &abyServ[3],
383 &abySignal[3]
386 //RSPINF_a_6
387 CARDvCaculateOFDMRParameter (RATE_6M,
388 byBBType,
389 &abyTxRate[0],
390 &abyRsvTime[0]);
392 //RSPINF_a_9
393 CARDvCaculateOFDMRParameter (RATE_9M,
394 byBBType,
395 &abyTxRate[1],
396 &abyRsvTime[1]);
398 //RSPINF_a_12
399 CARDvCaculateOFDMRParameter (RATE_12M,
400 byBBType,
401 &abyTxRate[2],
402 &abyRsvTime[2]);
404 //RSPINF_a_18
405 CARDvCaculateOFDMRParameter (RATE_18M,
406 byBBType,
407 &abyTxRate[3],
408 &abyRsvTime[3]);
410 //RSPINF_a_24
411 CARDvCaculateOFDMRParameter (RATE_24M,
412 byBBType,
413 &abyTxRate[4],
414 &abyRsvTime[4]);
416 //RSPINF_a_36
417 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
418 byBBType,
419 &abyTxRate[5],
420 &abyRsvTime[5]);
422 //RSPINF_a_48
423 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
424 byBBType,
425 &abyTxRate[6],
426 &abyRsvTime[6]);
428 //RSPINF_a_54
429 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
430 byBBType,
431 &abyTxRate[7],
432 &abyRsvTime[7]);
434 //RSPINF_a_72
435 CARDvCaculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
436 byBBType,
437 &abyTxRate[8],
438 &abyRsvTime[8]);
440 abyData[0] = (BYTE)(awLen[0]&0xFF);
441 abyData[1] = (BYTE)(awLen[0]>>8);
442 abyData[2] = abySignal[0];
443 abyData[3] = abyServ[0];
445 abyData[4] = (BYTE)(awLen[1]&0xFF);
446 abyData[5] = (BYTE)(awLen[1]>>8);
447 abyData[6] = abySignal[1];
448 abyData[7] = abyServ[1];
450 abyData[8] = (BYTE)(awLen[2]&0xFF);
451 abyData[9] = (BYTE)(awLen[2]>>8);
452 abyData[10] = abySignal[2];
453 abyData[11] = abyServ[2];
455 abyData[12] = (BYTE)(awLen[3]&0xFF);
456 abyData[13] = (BYTE)(awLen[3]>>8);
457 abyData[14] = abySignal[3];
458 abyData[15] = abyServ[3];
460 for (i = 0; i < 9; i++) {
461 abyData[16+i*2] = abyTxRate[i];
462 abyData[16+i*2+1] = abyRsvTime[i];
465 CONTROLnsRequestOut(pDevice,
466 MESSAGE_TYPE_WRITE,
467 MAC_REG_RSPINF_B_1,
468 MESSAGE_REQUEST_MACREG,
470 &abyData[0]);
475 * Description: Update IFS
477 * Parameters:
478 * In:
479 * pDevice - The adapter to be set
480 * Out:
481 * none
483 * Return Value: None.
486 void vUpdateIFS(void *pDeviceHandler)
488 PSDevice pDevice = (PSDevice) pDeviceHandler;
489 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
490 BYTE byMaxMin = 0;
491 BYTE byData[4];
493 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
494 pDevice->uSlot = C_SLOT_SHORT;
495 pDevice->uSIFS = C_SIFS_A;
496 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
497 pDevice->uCwMin = C_CWMIN_A;
498 byMaxMin = 4;
500 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
501 pDevice->uSlot = C_SLOT_LONG;
502 pDevice->uSIFS = C_SIFS_BG;
503 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
504 pDevice->uCwMin = C_CWMIN_B;
505 byMaxMin = 5;
507 else {// PK_TYPE_11GA & PK_TYPE_11GB
508 BYTE byRate = 0;
509 BOOL bOFDMRate = FALSE;
510 unsigned int ii = 0;
511 PWLAN_IE_SUPP_RATES pItemRates = NULL;
513 pDevice->uSIFS = C_SIFS_BG;
514 if (pDevice->bShortSlotTime) {
515 pDevice->uSlot = C_SLOT_SHORT;
516 } else {
517 pDevice->uSlot = C_SLOT_LONG;
519 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
521 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrSuppRates;
522 for (ii = 0; ii < pItemRates->len; ii++) {
523 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
524 if (RATEwGetRateIdx(byRate) > RATE_11M) {
525 bOFDMRate = TRUE;
526 break;
529 if (bOFDMRate == FALSE) {
530 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrExtSuppRates;
531 for (ii = 0; ii < pItemRates->len; ii++) {
532 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
533 if (RATEwGetRateIdx(byRate) > RATE_11M) {
534 bOFDMRate = TRUE;
535 break;
539 if (bOFDMRate == TRUE) {
540 pDevice->uCwMin = C_CWMIN_A;
541 byMaxMin = 4;
542 } else {
543 pDevice->uCwMin = C_CWMIN_B;
544 byMaxMin = 5;
548 pDevice->uCwMax = C_CWMAX;
549 pDevice->uEIFS = C_EIFS;
551 byData[0] = (BYTE)pDevice->uSIFS;
552 byData[1] = (BYTE)pDevice->uDIFS;
553 byData[2] = (BYTE)pDevice->uEIFS;
554 byData[3] = (BYTE)pDevice->uSlot;
555 CONTROLnsRequestOut(pDevice,
556 MESSAGE_TYPE_WRITE,
557 MAC_REG_SIFS,
558 MESSAGE_REQUEST_MACREG,
560 &byData[0]);
562 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
563 CONTROLnsRequestOut(pDevice,
564 MESSAGE_TYPE_WRITE,
565 MAC_REG_CWMAXMIN0,
566 MESSAGE_REQUEST_MACREG,
568 &byMaxMin);
571 void CARDvUpdateBasicTopRate(void *pDeviceHandler)
573 PSDevice pDevice = (PSDevice) pDeviceHandler;
574 BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
575 BYTE ii;
577 //Determines the highest basic rate.
578 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
579 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
580 byTopOFDM = ii;
581 break;
584 pDevice->byTopOFDMBasicRate = byTopOFDM;
586 for (ii = RATE_11M;; ii --) {
587 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
588 byTopCCK = ii;
589 break;
591 if (ii == RATE_1M)
592 break;
594 pDevice->byTopCCKBasicRate = byTopCCK;
598 * Description: Set NIC Tx Basic Rate
600 * Parameters:
601 * In:
602 * pDevice - The adapter to be set
603 * wBasicRate - Basic Rate to be set
604 * Out:
605 * none
607 * Return Value: TRUE if succeeded; FALSE if failed.
610 BOOL CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx)
612 PSDevice pDevice = (PSDevice) pDeviceHandler;
613 WORD wRate = (WORD)(1<<wRateIdx);
615 pDevice->wBasicRate |= wRate;
617 //Determines the highest basic rate.
618 CARDvUpdateBasicTopRate(pDevice);
620 return(TRUE);
623 BOOL CARDbIsOFDMinBasicRate(void *pDeviceHandler)
625 PSDevice pDevice = (PSDevice) pDeviceHandler;
626 int ii;
628 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
629 if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
630 return TRUE;
632 return FALSE;
635 BYTE CARDbyGetPktType(void *pDeviceHandler)
637 PSDevice pDevice = (PSDevice) pDeviceHandler;
639 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
640 return (BYTE)pDevice->byBBType;
642 else if (CARDbIsOFDMinBasicRate(pDevice)) {
643 return PK_TYPE_11GA;
645 else {
646 return PK_TYPE_11GB;
652 * Description: Caculate TSF offset of two TSF input
653 * Get TSF Offset from RxBCN's TSF and local TSF
655 * Parameters:
656 * In:
657 * pDevice - The adapter to be sync.
658 * qwTSF1 - Rx BCN's TSF
659 * qwTSF2 - Local TSF
660 * Out:
661 * none
663 * Return Value: TSF Offset value
666 QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2)
668 QWORD qwTSFOffset;
669 WORD wRxBcnTSFOffst = 0;
671 HIDWORD(qwTSFOffset) = 0;
672 LODWORD(qwTSFOffset) = 0;
674 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
675 (qwTSF2).u.dwLowDword += (DWORD)(wRxBcnTSFOffst);
676 if ((qwTSF2).u.dwLowDword < (DWORD)(wRxBcnTSFOffst)) {
677 (qwTSF2).u.dwHighDword++;
679 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
680 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
681 // if borrow needed
682 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
684 else {
685 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
687 return (qwTSFOffset);
693 * Description: Sync. TSF counter to BSS
694 * Get TSF offset and write to HW
696 * Parameters:
697 * In:
698 * pDevice - The adapter to be sync.
699 * qwBSSTimestamp - Rx BCN's TSF
700 * qwLocalTSF - Local TSF
701 * Out:
702 * none
704 * Return Value: none
707 void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate,
708 QWORD qwBSSTimestamp, QWORD qwLocalTSF)
711 PSDevice pDevice = (PSDevice) pDeviceHandler;
712 QWORD qwTSFOffset;
713 DWORD dwTSFOffset1,dwTSFOffset2;
714 BYTE pbyData[8];
716 HIDWORD(qwTSFOffset) = 0;
717 LODWORD(qwTSFOffset) = 0;
719 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
720 // adjust TSF
721 // HW's TSF add TSF Offset reg
722 dwTSFOffset1 = LODWORD(qwTSFOffset);
723 dwTSFOffset2 = HIDWORD(qwTSFOffset);
726 pbyData[0] = (BYTE)dwTSFOffset1;
727 pbyData[1] = (BYTE)(dwTSFOffset1>>8);
728 pbyData[2] = (BYTE)(dwTSFOffset1>>16);
729 pbyData[3] = (BYTE)(dwTSFOffset1>>24);
730 pbyData[4] = (BYTE)dwTSFOffset2;
731 pbyData[5] = (BYTE)(dwTSFOffset2>>8);
732 pbyData[6] = (BYTE)(dwTSFOffset2>>16);
733 pbyData[7] = (BYTE)(dwTSFOffset2>>24);
735 CONTROLnsRequestOut(pDevice,
736 MESSAGE_TYPE_SET_TSFTBTT,
737 MESSAGE_REQUEST_TSF,
740 pbyData
745 * Description: Read NIC TSF counter
746 * Get local TSF counter
748 * Parameters:
749 * In:
750 * pDevice - The adapter to be read
751 * Out:
752 * qwCurrTSF - Current TSF counter
754 * Return Value: TRUE if success; otherwise FALSE
757 BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF)
759 PSDevice pDevice = (PSDevice) pDeviceHandler;
761 LODWORD(*pqwCurrTSF) = LODWORD(pDevice->qwCurrTSF);
762 HIDWORD(*pqwCurrTSF) = HIDWORD(pDevice->qwCurrTSF);
764 return(TRUE);
769 * Description: Clear NIC TSF counter
770 * Clear local TSF counter
772 * Parameters:
773 * In:
774 * pDevice - The adapter to be read
776 * Return Value: TRUE if success; otherwise FALSE
779 BOOL CARDbClearCurrentTSF(void *pDeviceHandler)
781 PSDevice pDevice = (PSDevice) pDeviceHandler;
783 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTRST);
785 LODWORD(pDevice->qwCurrTSF) = 0;
786 HIDWORD(pDevice->qwCurrTSF) = 0;
788 return(TRUE);
792 * Description: Read NIC TSF counter
793 * Get NEXTTBTT from adjusted TSF and Beacon Interval
795 * Parameters:
796 * In:
797 * qwTSF - Current TSF counter
798 * wbeaconInterval - Beacon Interval
799 * Out:
800 * qwCurrTSF - Current TSF counter
802 * Return Value: TSF value of next Beacon
805 QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval)
808 unsigned int uLowNextTBTT;
809 unsigned int uHighRemain, uLowRemain;
810 unsigned int uBeaconInterval;
812 uBeaconInterval = wBeaconInterval * 1024;
813 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
814 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
815 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
816 uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
817 % uBeaconInterval;
818 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
819 uLowRemain = uBeaconInterval - uLowRemain;
821 // check if carry when add one beacon interval
822 if ((~uLowNextTBTT) < uLowRemain)
823 HIDWORD(qwTSF) ++ ;
825 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
827 return (qwTSF);
832 * Description: Set NIC TSF counter for first Beacon time
833 * Get NEXTTBTT from adjusted TSF and Beacon Interval
835 * Parameters:
836 * In:
837 * dwIoBase - IO Base
838 * wBeaconInterval - Beacon Interval
839 * Out:
840 * none
842 * Return Value: none
845 void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval)
848 PSDevice pDevice = (PSDevice) pDeviceHandler;
849 QWORD qwNextTBTT;
850 DWORD dwLoTBTT,dwHiTBTT;
851 BYTE pbyData[8];
853 HIDWORD(qwNextTBTT) = 0;
854 LODWORD(qwNextTBTT) = 0;
855 CARDbClearCurrentTSF(pDevice);
856 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
857 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
858 // Set NextTBTT
860 dwLoTBTT = LODWORD(qwNextTBTT);
861 dwHiTBTT = HIDWORD(qwNextTBTT);
863 pbyData[0] = (BYTE)dwLoTBTT;
864 pbyData[1] = (BYTE)(dwLoTBTT>>8);
865 pbyData[2] = (BYTE)(dwLoTBTT>>16);
866 pbyData[3] = (BYTE)(dwLoTBTT>>24);
867 pbyData[4] = (BYTE)dwHiTBTT;
868 pbyData[5] = (BYTE)(dwHiTBTT>>8);
869 pbyData[6] = (BYTE)(dwHiTBTT>>16);
870 pbyData[7] = (BYTE)(dwHiTBTT>>24);
872 CONTROLnsRequestOut(pDevice,
873 MESSAGE_TYPE_SET_TSFTBTT,
874 MESSAGE_REQUEST_TBTT,
877 pbyData
880 return;
885 * Description: Sync NIC TSF counter for Beacon time
886 * Get NEXTTBTT and write to HW
888 * Parameters:
889 * In:
890 * pDevice - The adapter to be set
891 * qwTSF - Current TSF counter
892 * wBeaconInterval - Beacon Interval
893 * Out:
894 * none
896 * Return Value: none
899 void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF,
900 WORD wBeaconInterval)
902 PSDevice pDevice = (PSDevice) pDeviceHandler;
903 DWORD dwLoTBTT,dwHiTBTT;
904 BYTE pbyData[8];
906 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
908 // Set NextTBTT
909 dwLoTBTT = LODWORD(qwTSF);
910 dwHiTBTT = HIDWORD(qwTSF);
912 pbyData[0] = (BYTE)dwLoTBTT;
913 pbyData[1] = (BYTE)(dwLoTBTT>>8);
914 pbyData[2] = (BYTE)(dwLoTBTT>>16);
915 pbyData[3] = (BYTE)(dwLoTBTT>>24);
916 pbyData[4] = (BYTE)dwHiTBTT;
917 pbyData[5] = (BYTE)(dwHiTBTT>>8);
918 pbyData[6] = (BYTE)(dwHiTBTT>>16);
919 pbyData[7] = (BYTE)(dwHiTBTT>>24);
921 CONTROLnsRequestOut(pDevice,
922 MESSAGE_TYPE_SET_TSFTBTT,
923 MESSAGE_REQUEST_TBTT,
926 pbyData
930 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",(int)HIDWORD(qwTSF), (int)LODWORD(qwTSF));
932 return;
936 * Description: Turn off Radio power
938 * Parameters:
939 * In:
940 * pDevice - The adapter to be turned off
941 * Out:
942 * none
944 * Return Value: TRUE if success; otherwise FALSE
947 BOOL CARDbRadioPowerOff(void *pDeviceHandler)
949 PSDevice pDevice = (PSDevice) pDeviceHandler;
950 BOOL bResult = TRUE;
952 //if (pDevice->bRadioOff == TRUE)
953 // return TRUE;
955 pDevice->bRadioOff = TRUE;
957 switch (pDevice->byRFType) {
958 case RF_AL2230:
959 case RF_AL2230S:
960 case RF_AIROHA7230:
961 case RF_VT3226: //RobertYu:20051111
962 case RF_VT3226D0:
963 case RF_VT3342A0: //RobertYu:20060609
964 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
965 break;
968 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
970 BBvSetDeepSleep(pDevice);
972 return bResult;
977 * Description: Turn on Radio power
979 * Parameters:
980 * In:
981 * pDevice - The adapter to be turned on
982 * Out:
983 * none
985 * Return Value: TRUE if success; otherwise FALSE
988 BOOL CARDbRadioPowerOn(void *pDeviceHandler)
990 PSDevice pDevice = (PSDevice) pDeviceHandler;
991 BOOL bResult = TRUE;
994 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
995 return FALSE;
998 //if (pDevice->bRadioOff == FALSE)
999 // return TRUE;
1001 pDevice->bRadioOff = FALSE;
1003 BBvExitDeepSleep(pDevice);
1005 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
1007 switch (pDevice->byRFType) {
1008 case RF_AL2230:
1009 case RF_AL2230S:
1010 case RF_AIROHA7230:
1011 case RF_VT3226: //RobertYu:20051111
1012 case RF_VT3226D0:
1013 case RF_VT3342A0: //RobertYu:20060609
1014 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
1015 break;
1018 return bResult;
1021 void CARDvSetBSSMode(void *pDeviceHandler)
1023 PSDevice pDevice = (PSDevice) pDeviceHandler;
1024 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
1025 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
1026 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
1028 MACvSetBBType(pDevice, BB_TYPE_11G);
1030 else
1032 MACvSetBBType(pDevice, pDevice->byBBType);
1034 pDevice->byPacketType = CARDbyGetPktType(pDevice);
1036 if (pDevice->byBBType == BB_TYPE_11A) {
1037 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
1038 } else if (pDevice->byBBType == BB_TYPE_11B) {
1039 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
1040 } else if (pDevice->byBBType == BB_TYPE_11G) {
1041 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
1044 vUpdateIFS(pDevice);
1045 CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
1047 if ( pDevice->byBBType == BB_TYPE_11A ) {
1048 //request by Jack 2005-04-26
1049 if (pDevice->byRFType == RF_AIROHA7230) {
1050 pDevice->abyBBVGA[0] = 0x20;
1051 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1053 pDevice->abyBBVGA[2] = 0x10;
1054 pDevice->abyBBVGA[3] = 0x10;
1055 } else {
1056 //request by Jack 2005-04-26
1057 if (pDevice->byRFType == RF_AIROHA7230) {
1058 pDevice->abyBBVGA[0] = 0x1C;
1059 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
1061 pDevice->abyBBVGA[2] = 0x0;
1062 pDevice->abyBBVGA[3] = 0x0;
1068 * Description:
1069 * Do Channel Switch defined in 802.11h
1071 * Parameters:
1072 * In:
1073 * hDeviceContext - device structure point
1074 * Out:
1075 * none
1077 * Return Value: none.
1080 BOOL
1081 CARDbChannelSwitch (
1082 void *pDeviceHandler,
1083 BYTE byMode,
1084 BYTE byNewChannel,
1085 BYTE byCount
1088 PSDevice pDevice = (PSDevice) pDeviceHandler;
1089 BOOL bResult = TRUE;
1091 if (byCount == 0) {
1092 pDevice->sMgmtObj.uCurrChannel = byNewChannel;
1093 bResult = CARDbSetMediaChannel(pDevice, byNewChannel);
1095 return bResult;
1097 pDevice->byChannelSwitchCount = byCount;
1098 pDevice->byNewChannel = byNewChannel;
1099 pDevice->bChannelSwitch = TRUE;
1101 if (byMode == 1) {
1102 //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1103 pDevice->bStopDataPkt = TRUE;
1105 return bResult;