xenbus_client.c: correct exit path for xenbus_map_ring_valloc_hvm
[linux/fpc-iii.git] / drivers / staging / vt6656 / card.c
blob24291aee58b5575485e7d4dd1c720a09e854a596
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 - Calculate TSFOffset
32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
33 * CARDqGetNextTBTT - Calculate 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 definition type of dwIoBase.
44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
48 #include "device.h"
49 #include "tmacro.h"
50 #include "card.h"
51 #include "baseband.h"
52 #include "mac.h"
53 #include "desc.h"
54 #include "rf.h"
55 #include "power.h"
56 #include "key.h"
57 #include "rc4.h"
58 #include "country.h"
59 #include "datarate.h"
60 #include "rndis.h"
61 #include "control.h"
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 static int msglevel =MSG_LEVEL_INFO;
66 //const u16 cwRXBCNTSFOff[MAX_RATE] =
67 //{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
69 const u16 cwRXBCNTSFOff[MAX_RATE] =
70 {192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3};
73 * Description: Set NIC media channel
75 * Parameters:
76 * In:
77 * pDevice - The adapter to be set
78 * uConnectionChannel - Channel to be set
79 * Out:
80 * none
82 void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel)
85 if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38
86 if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL))
87 uConnectionChannel = (CB_MAX_CHANNEL_24G+1);
88 } else {
89 if ((uConnectionChannel > CB_MAX_CHANNEL_24G) || (uConnectionChannel == 0)) // 1 ~ 14
90 uConnectionChannel = 1;
93 // clear NAV
94 MACvRegBitsOn(pDevice, MAC_REG_MACCR, MACCR_CLRNAV);
96 // Set Channel[7] = 0 to tell H/W channel is changing now.
97 MACvRegBitsOff(pDevice, MAC_REG_CHANNEL, 0x80);
99 //if (pMgmt->uCurrChannel == uConnectionChannel)
100 // return bResult;
102 CONTROLnsRequestOut(pDevice,
103 MESSAGE_TYPE_SELECT_CHANNLE,
104 (u16) uConnectionChannel,
107 NULL
110 //{{ RobertYu: 20041202
111 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
113 if (pDevice->byBBType == BB_TYPE_11A) {
114 pDevice->byCurPwr = 0xFF;
115 RFbRawSetPower(pDevice, pDevice->abyOFDMAPwrTbl[uConnectionChannel-15], RATE_54M);
116 } else if (pDevice->byBBType == BB_TYPE_11G) {
117 pDevice->byCurPwr = 0xFF;
118 RFbRawSetPower(pDevice, pDevice->abyOFDMPwrTbl[uConnectionChannel-1], RATE_54M);
119 } else {
120 pDevice->byCurPwr = 0xFF;
121 RFbRawSetPower(pDevice, pDevice->abyCCKPwrTbl[uConnectionChannel-1], RATE_1M);
123 ControlvWriteByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_CHANNEL,(u8)(uConnectionChannel|0x80));
127 * Description: Get CCK mode basic rate
129 * Parameters:
130 * In:
131 * pDevice - The adapter to be set
132 * wRateIdx - Receiving data rate
133 * Out:
134 * none
136 * Return Value: response Control frame rate
139 static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx)
141 u16 ui = wRateIdx;
143 while (ui > RATE_1M) {
144 if (pDevice->wBasicRate & (1 << ui))
145 return ui;
146 ui--;
149 return RATE_1M;
153 * Description: Get OFDM mode basic rate
155 * Parameters:
156 * In:
157 * pDevice - The adapter to be set
158 * wRateIdx - Receiving data rate
159 * Out:
160 * none
162 * Return Value: response Control frame rate
165 static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx)
167 u16 ui = wRateIdx;
169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n",
170 pDevice->wBasicRate);
172 if (!CARDbIsOFDMinBasicRate(pDevice)) {
173 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
174 "swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
175 if (wRateIdx > RATE_24M)
176 wRateIdx = RATE_24M;
177 return wRateIdx;
180 while (ui > RATE_11M) {
181 if (pDevice->wBasicRate & (1 << ui)) {
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
183 "swGetOFDMControlRate: %d\n", ui);
184 return ui;
186 ui--;
189 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n");
191 return RATE_24M;
195 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
197 * Parameters:
198 * In:
199 * wRate - Tx Rate
200 * byPktType - Tx Packet type
201 * Out:
202 * pbyTxRate - pointer to RSPINF TxRate field
203 * pbyRsvTime - pointer to RSPINF RsvTime field
205 * Return Value: none
208 void
209 CARDvCalculateOFDMRParameter (
210 u16 wRate,
211 u8 byBBType,
212 u8 * pbyTxRate,
213 u8 * pbyRsvTime
216 switch (wRate) {
217 case RATE_6M :
218 if (byBBType == BB_TYPE_11A) {//5GHZ
219 *pbyTxRate = 0x9B;
220 *pbyRsvTime = 24;
222 else {
223 *pbyTxRate = 0x8B;
224 *pbyRsvTime = 30;
226 break;
228 case RATE_9M :
229 if (byBBType == BB_TYPE_11A) {//5GHZ
230 *pbyTxRate = 0x9F;
231 *pbyRsvTime = 16;
233 else {
234 *pbyTxRate = 0x8F;
235 *pbyRsvTime = 22;
237 break;
239 case RATE_12M :
240 if (byBBType == BB_TYPE_11A) {//5GHZ
241 *pbyTxRate = 0x9A;
242 *pbyRsvTime = 12;
244 else {
245 *pbyTxRate = 0x8A;
246 *pbyRsvTime = 18;
248 break;
250 case RATE_18M :
251 if (byBBType == BB_TYPE_11A) {//5GHZ
252 *pbyTxRate = 0x9E;
253 *pbyRsvTime = 8;
255 else {
256 *pbyTxRate = 0x8E;
257 *pbyRsvTime = 14;
259 break;
261 case RATE_36M :
262 if (byBBType == BB_TYPE_11A) {//5GHZ
263 *pbyTxRate = 0x9D;
264 *pbyRsvTime = 4;
266 else {
267 *pbyTxRate = 0x8D;
268 *pbyRsvTime = 10;
270 break;
272 case RATE_48M :
273 if (byBBType == BB_TYPE_11A) {//5GHZ
274 *pbyTxRate = 0x98;
275 *pbyRsvTime = 4;
277 else {
278 *pbyTxRate = 0x88;
279 *pbyRsvTime = 10;
281 break;
283 case RATE_54M :
284 if (byBBType == BB_TYPE_11A) {//5GHZ
285 *pbyTxRate = 0x9C;
286 *pbyRsvTime = 4;
288 else {
289 *pbyTxRate = 0x8C;
290 *pbyRsvTime = 10;
292 break;
294 case RATE_24M :
295 default :
296 if (byBBType == BB_TYPE_11A) {//5GHZ
297 *pbyTxRate = 0x99;
298 *pbyRsvTime = 8;
300 else {
301 *pbyTxRate = 0x89;
302 *pbyRsvTime = 14;
304 break;
309 * Description: Set RSPINF
311 * Parameters:
312 * In:
313 * pDevice - The adapter to be set
314 * Out:
315 * none
317 * Return Value: None.
320 void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType)
322 u8 abyServ[4] = {0, 0, 0, 0}; /* For CCK */
323 u8 abySignal[4] = {0, 0, 0, 0};
324 u16 awLen[4] = {0, 0, 0, 0};
325 u8 abyTxRate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
326 u8 abyRsvTime[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
327 u8 abyData[34];
328 int i;
330 //RSPINF_b_1
331 BBvCalculateParameter(pDevice,
333 swGetCCKControlRate(pDevice, RATE_1M),
334 PK_TYPE_11B,
335 &awLen[0],
336 &abyServ[0],
337 &abySignal[0]
340 ///RSPINF_b_2
341 BBvCalculateParameter(pDevice,
343 swGetCCKControlRate(pDevice, RATE_2M),
344 PK_TYPE_11B,
345 &awLen[1],
346 &abyServ[1],
347 &abySignal[1]
350 //RSPINF_b_5
351 BBvCalculateParameter(pDevice,
353 swGetCCKControlRate(pDevice, RATE_5M),
354 PK_TYPE_11B,
355 &awLen[2],
356 &abyServ[2],
357 &abySignal[2]
360 //RSPINF_b_11
361 BBvCalculateParameter(pDevice,
363 swGetCCKControlRate(pDevice, RATE_11M),
364 PK_TYPE_11B,
365 &awLen[3],
366 &abyServ[3],
367 &abySignal[3]
370 //RSPINF_a_6
371 CARDvCalculateOFDMRParameter (RATE_6M,
372 byBBType,
373 &abyTxRate[0],
374 &abyRsvTime[0]);
376 //RSPINF_a_9
377 CARDvCalculateOFDMRParameter (RATE_9M,
378 byBBType,
379 &abyTxRate[1],
380 &abyRsvTime[1]);
382 //RSPINF_a_12
383 CARDvCalculateOFDMRParameter (RATE_12M,
384 byBBType,
385 &abyTxRate[2],
386 &abyRsvTime[2]);
388 //RSPINF_a_18
389 CARDvCalculateOFDMRParameter (RATE_18M,
390 byBBType,
391 &abyTxRate[3],
392 &abyRsvTime[3]);
394 //RSPINF_a_24
395 CARDvCalculateOFDMRParameter (RATE_24M,
396 byBBType,
397 &abyTxRate[4],
398 &abyRsvTime[4]);
400 //RSPINF_a_36
401 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
402 byBBType,
403 &abyTxRate[5],
404 &abyRsvTime[5]);
406 //RSPINF_a_48
407 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
408 byBBType,
409 &abyTxRate[6],
410 &abyRsvTime[6]);
412 //RSPINF_a_54
413 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
414 byBBType,
415 &abyTxRate[7],
416 &abyRsvTime[7]);
418 //RSPINF_a_72
419 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
420 byBBType,
421 &abyTxRate[8],
422 &abyRsvTime[8]);
424 abyData[0] = (u8)(awLen[0]&0xFF);
425 abyData[1] = (u8)(awLen[0]>>8);
426 abyData[2] = abySignal[0];
427 abyData[3] = abyServ[0];
429 abyData[4] = (u8)(awLen[1]&0xFF);
430 abyData[5] = (u8)(awLen[1]>>8);
431 abyData[6] = abySignal[1];
432 abyData[7] = abyServ[1];
434 abyData[8] = (u8)(awLen[2]&0xFF);
435 abyData[9] = (u8)(awLen[2]>>8);
436 abyData[10] = abySignal[2];
437 abyData[11] = abyServ[2];
439 abyData[12] = (u8)(awLen[3]&0xFF);
440 abyData[13] = (u8)(awLen[3]>>8);
441 abyData[14] = abySignal[3];
442 abyData[15] = abyServ[3];
444 for (i = 0; i < 9; i++) {
445 abyData[16+i*2] = abyTxRate[i];
446 abyData[16+i*2+1] = abyRsvTime[i];
449 CONTROLnsRequestOut(pDevice,
450 MESSAGE_TYPE_WRITE,
451 MAC_REG_RSPINF_B_1,
452 MESSAGE_REQUEST_MACREG,
454 &abyData[0]);
459 * Description: Update IFS
461 * Parameters:
462 * In:
463 * pDevice - The adapter to be set
464 * Out:
465 * none
467 * Return Value: None.
470 void vUpdateIFS(struct vnt_private *pDevice)
472 u8 byMaxMin = 0;
473 u8 byData[4];
475 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
476 pDevice->uSlot = C_SLOT_SHORT;
477 pDevice->uSIFS = C_SIFS_A;
478 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
479 pDevice->uCwMin = C_CWMIN_A;
480 byMaxMin = 4;
482 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
483 pDevice->uSlot = C_SLOT_LONG;
484 pDevice->uSIFS = C_SIFS_BG;
485 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
486 pDevice->uCwMin = C_CWMIN_B;
487 byMaxMin = 5;
489 else {// PK_TYPE_11GA & PK_TYPE_11GB
490 u8 byRate = 0;
491 bool bOFDMRate = false;
492 unsigned int ii = 0;
493 PWLAN_IE_SUPP_RATES pItemRates = NULL;
495 pDevice->uSIFS = C_SIFS_BG;
496 if (pDevice->bShortSlotTime) {
497 pDevice->uSlot = C_SLOT_SHORT;
498 } else {
499 pDevice->uSlot = C_SLOT_LONG;
501 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
503 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt.abyCurrSuppRates;
504 for (ii = 0; ii < pItemRates->len; ii++) {
505 byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
506 if (RATEwGetRateIdx(byRate) > RATE_11M) {
507 bOFDMRate = true;
508 break;
511 if (bOFDMRate == false) {
512 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt
513 .abyCurrExtSuppRates;
514 for (ii = 0; ii < pItemRates->len; ii++) {
515 byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
516 if (RATEwGetRateIdx(byRate) > RATE_11M) {
517 bOFDMRate = true;
518 break;
522 if (bOFDMRate == true) {
523 pDevice->uCwMin = C_CWMIN_A;
524 byMaxMin = 4;
525 } else {
526 pDevice->uCwMin = C_CWMIN_B;
527 byMaxMin = 5;
531 pDevice->uCwMax = C_CWMAX;
532 pDevice->uEIFS = C_EIFS;
534 byData[0] = (u8)pDevice->uSIFS;
535 byData[1] = (u8)pDevice->uDIFS;
536 byData[2] = (u8)pDevice->uEIFS;
537 byData[3] = (u8)pDevice->uSlot;
538 CONTROLnsRequestOut(pDevice,
539 MESSAGE_TYPE_WRITE,
540 MAC_REG_SIFS,
541 MESSAGE_REQUEST_MACREG,
543 &byData[0]);
545 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
546 CONTROLnsRequestOut(pDevice,
547 MESSAGE_TYPE_WRITE,
548 MAC_REG_CWMAXMIN0,
549 MESSAGE_REQUEST_MACREG,
551 &byMaxMin);
554 void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
556 u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
557 u8 ii;
559 //Determines the highest basic rate.
560 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
561 if ( (pDevice->wBasicRate) & ((u16)(1<<ii)) ) {
562 byTopOFDM = ii;
563 break;
566 pDevice->byTopOFDMBasicRate = byTopOFDM;
568 for (ii = RATE_11M;; ii --) {
569 if ( (pDevice->wBasicRate) & ((u16)(1<<ii)) ) {
570 byTopCCK = ii;
571 break;
573 if (ii == RATE_1M)
574 break;
576 pDevice->byTopCCKBasicRate = byTopCCK;
580 * Description: Set NIC Tx Basic Rate
582 * Parameters:
583 * In:
584 * pDevice - The adapter to be set
585 * wBasicRate - Basic Rate to be set
586 * Out:
587 * none
589 * Return Value: true if succeeded; false if failed.
592 void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx)
594 u16 wRate = (1 << wRateIdx);
596 pDevice->wBasicRate |= wRate;
598 //Determines the highest basic rate.
599 CARDvUpdateBasicTopRate(pDevice);
602 int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
604 int ii;
606 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
607 if ((pDevice->wBasicRate) & ((u16)(1<<ii)))
608 return true;
610 return false;
613 u8 CARDbyGetPktType(struct vnt_private *pDevice)
616 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
617 return (u8)pDevice->byBBType;
619 else if (CARDbIsOFDMinBasicRate(pDevice)) {
620 return PK_TYPE_11GA;
622 else {
623 return PK_TYPE_11GB;
628 * Description: Calculate TSF offset of two TSF input
629 * Get TSF Offset from RxBCN's TSF and local TSF
631 * Parameters:
632 * In:
633 * pDevice - The adapter to be sync.
634 * qwTSF1 - Rx BCN's TSF
635 * qwTSF2 - Local TSF
636 * Out:
637 * none
639 * Return Value: TSF Offset value
642 u64 CARDqGetTSFOffset(u8 byRxRate, u64 qwTSF1, u64 qwTSF2)
644 u64 qwTSFOffset = 0;
645 u16 wRxBcnTSFOffst = 0;
647 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
649 qwTSF2 += (u64)wRxBcnTSFOffst;
651 qwTSFOffset = qwTSF1 - qwTSF2;
653 return qwTSFOffset;
657 * Description: Sync. TSF counter to BSS
658 * Get TSF offset and write to HW
660 * Parameters:
661 * In:
662 * pDevice - The adapter to be sync.
663 * qwBSSTimestamp - Rx BCN's TSF
664 * qwLocalTSF - Local TSF
665 * Out:
666 * none
668 * Return Value: none
671 void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
672 u64 qwBSSTimestamp, u64 qwLocalTSF)
674 u64 qwTSFOffset = 0;
675 u8 pbyData[8];
677 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
678 // adjust TSF
679 // HW's TSF add TSF Offset reg
681 pbyData[0] = (u8)qwTSFOffset;
682 pbyData[1] = (u8)(qwTSFOffset >> 8);
683 pbyData[2] = (u8)(qwTSFOffset >> 16);
684 pbyData[3] = (u8)(qwTSFOffset >> 24);
685 pbyData[4] = (u8)(qwTSFOffset >> 32);
686 pbyData[5] = (u8)(qwTSFOffset >> 40);
687 pbyData[6] = (u8)(qwTSFOffset >> 48);
688 pbyData[7] = (u8)(qwTSFOffset >> 56);
690 CONTROLnsRequestOut(pDevice,
691 MESSAGE_TYPE_SET_TSFTBTT,
692 MESSAGE_REQUEST_TSF,
695 pbyData
700 * Description: Read NIC TSF counter
701 * Get local TSF counter
703 * Parameters:
704 * In:
705 * pDevice - The adapter to be read
706 * Out:
707 * qwCurrTSF - Current TSF counter
709 * Return Value: true if success; otherwise false
712 bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
715 *pqwCurrTSF = pDevice->qwCurrTSF;
717 return true;
721 * Description: Clear NIC TSF counter
722 * Clear local TSF counter
724 * Parameters:
725 * In:
726 * pDevice - The adapter to be read
728 * Return Value: true if success; otherwise false
731 bool CARDbClearCurrentTSF(struct vnt_private *pDevice)
734 MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
736 pDevice->qwCurrTSF = 0;
738 return true;
742 * Description: Read NIC TSF counter
743 * Get NEXTTBTT from adjusted TSF and Beacon Interval
745 * Parameters:
746 * In:
747 * qwTSF - Current TSF counter
748 * wbeaconInterval - Beacon Interval
749 * Out:
750 * qwCurrTSF - Current TSF counter
752 * Return Value: TSF value of next Beacon
755 u64 CARDqGetNextTBTT(u64 qwTSF, u16 wBeaconInterval)
758 unsigned int uLowNextTBTT;
759 unsigned int uHighRemain, uLowRemain;
760 unsigned int uBeaconInterval;
762 uBeaconInterval = wBeaconInterval * 1024;
763 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
764 uLowNextTBTT = ((qwTSF & 0xffffffffU) >> 10) << 10;
765 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
766 uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32))
767 % uBeaconInterval;
768 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
769 uLowRemain = uBeaconInterval - uLowRemain;
771 // check if carry when add one beacon interval
772 if ((~uLowNextTBTT) < uLowRemain)
773 qwTSF = ((qwTSF >> 32) + 1) << 32;
775 qwTSF = (qwTSF & 0xffffffff00000000ULL) |
776 (u64)(uLowNextTBTT + uLowRemain);
778 return (qwTSF);
782 * Description: Set NIC TSF counter for first Beacon time
783 * Get NEXTTBTT from adjusted TSF and Beacon Interval
785 * Parameters:
786 * In:
787 * dwIoBase - IO Base
788 * wBeaconInterval - Beacon Interval
789 * Out:
790 * none
792 * Return Value: none
795 void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, u16 wBeaconInterval)
797 u64 qwNextTBTT = 0;
798 u8 pbyData[8];
800 CARDbClearCurrentTSF(pDevice);
801 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
802 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
803 // Set NextTBTT
805 pbyData[0] = (u8)qwNextTBTT;
806 pbyData[1] = (u8)(qwNextTBTT >> 8);
807 pbyData[2] = (u8)(qwNextTBTT >> 16);
808 pbyData[3] = (u8)(qwNextTBTT >> 24);
809 pbyData[4] = (u8)(qwNextTBTT >> 32);
810 pbyData[5] = (u8)(qwNextTBTT >> 40);
811 pbyData[6] = (u8)(qwNextTBTT >> 48);
812 pbyData[7] = (u8)(qwNextTBTT >> 56);
814 CONTROLnsRequestOut(pDevice,
815 MESSAGE_TYPE_SET_TSFTBTT,
816 MESSAGE_REQUEST_TBTT,
819 pbyData
822 return;
826 * Description: Sync NIC TSF counter for Beacon time
827 * Get NEXTTBTT and write to HW
829 * Parameters:
830 * In:
831 * pDevice - The adapter to be set
832 * qwTSF - Current TSF counter
833 * wBeaconInterval - Beacon Interval
834 * Out:
835 * none
837 * Return Value: none
840 void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
841 u16 wBeaconInterval)
843 u8 pbyData[8];
845 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
847 // Set NextTBTT
849 pbyData[0] = (u8)qwTSF;
850 pbyData[1] = (u8)(qwTSF >> 8);
851 pbyData[2] = (u8)(qwTSF >> 16);
852 pbyData[3] = (u8)(qwTSF >> 24);
853 pbyData[4] = (u8)(qwTSF >> 32);
854 pbyData[5] = (u8)(qwTSF >> 40);
855 pbyData[6] = (u8)(qwTSF >> 48);
856 pbyData[7] = (u8)(qwTSF >> 56);
858 CONTROLnsRequestOut(pDevice,
859 MESSAGE_TYPE_SET_TSFTBTT,
860 MESSAGE_REQUEST_TBTT,
863 pbyData
866 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
867 "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
869 return;
873 * Description: Turn off Radio power
875 * Parameters:
876 * In:
877 * pDevice - The adapter to be turned off
878 * Out:
879 * none
881 * Return Value: true if success; otherwise false
884 int CARDbRadioPowerOff(struct vnt_private *pDevice)
886 int bResult = true;
888 //if (pDevice->bRadioOff == true)
889 // return true;
891 pDevice->bRadioOff = true;
893 switch (pDevice->byRFType) {
894 case RF_AL2230:
895 case RF_AL2230S:
896 case RF_AIROHA7230:
897 case RF_VT3226: //RobertYu:20051111
898 case RF_VT3226D0:
899 case RF_VT3342A0: //RobertYu:20060609
900 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
901 break;
904 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
906 BBvSetDeepSleep(pDevice);
908 return bResult;
912 * Description: Turn on Radio power
914 * Parameters:
915 * In:
916 * pDevice - The adapter to be turned on
917 * Out:
918 * none
920 * Return Value: true if success; otherwise false
923 int CARDbRadioPowerOn(struct vnt_private *pDevice)
925 int bResult = true;
927 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
928 return false;
931 //if (pDevice->bRadioOff == false)
932 // return true;
934 pDevice->bRadioOff = false;
936 BBvExitDeepSleep(pDevice);
938 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
940 switch (pDevice->byRFType) {
941 case RF_AL2230:
942 case RF_AL2230S:
943 case RF_AIROHA7230:
944 case RF_VT3226: //RobertYu:20051111
945 case RF_VT3226D0:
946 case RF_VT3342A0: //RobertYu:20060609
947 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
948 break;
951 return bResult;
954 void CARDvSetBSSMode(struct vnt_private *pDevice)
956 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
957 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
958 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
960 MACvSetBBType(pDevice, BB_TYPE_11G);
962 else
964 MACvSetBBType(pDevice, pDevice->byBBType);
966 pDevice->byPacketType = CARDbyGetPktType(pDevice);
968 if (pDevice->byBBType == BB_TYPE_11A) {
969 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
970 } else if (pDevice->byBBType == BB_TYPE_11B) {
971 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
972 } else if (pDevice->byBBType == BB_TYPE_11G) {
973 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
976 vUpdateIFS(pDevice);
977 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
979 if ( pDevice->byBBType == BB_TYPE_11A ) {
980 //request by Jack 2005-04-26
981 if (pDevice->byRFType == RF_AIROHA7230) {
982 pDevice->abyBBVGA[0] = 0x20;
983 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
985 pDevice->abyBBVGA[2] = 0x10;
986 pDevice->abyBBVGA[3] = 0x10;
987 } else {
988 //request by Jack 2005-04-26
989 if (pDevice->byRFType == RF_AIROHA7230) {
990 pDevice->abyBBVGA[0] = 0x1C;
991 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
993 pDevice->abyBBVGA[2] = 0x0;
994 pDevice->abyBBVGA[3] = 0x0;