mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / staging / vt6656 / card.c
blob34a24b78c1a7902eefcc10748090907812da54b1
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 struct vnt_phy_field phy[4];
323 u8 abyTxRate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
324 u8 abyRsvTime[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
325 u8 abyData[34];
326 int i;
328 //RSPINF_b_1
329 BBvCalculateParameter(pDevice, 14,
330 swGetCCKControlRate(pDevice, RATE_1M), PK_TYPE_11B, &phy[0]);
332 ///RSPINF_b_2
333 BBvCalculateParameter(pDevice, 14,
334 swGetCCKControlRate(pDevice, RATE_2M), PK_TYPE_11B, &phy[1]);
336 //RSPINF_b_5
337 BBvCalculateParameter(pDevice, 14,
338 swGetCCKControlRate(pDevice, RATE_5M), PK_TYPE_11B, &phy[2]);
340 //RSPINF_b_11
341 BBvCalculateParameter(pDevice, 14,
342 swGetCCKControlRate(pDevice, RATE_11M), PK_TYPE_11B, &phy[3]);
344 //RSPINF_a_6
345 CARDvCalculateOFDMRParameter (RATE_6M,
346 byBBType,
347 &abyTxRate[0],
348 &abyRsvTime[0]);
350 //RSPINF_a_9
351 CARDvCalculateOFDMRParameter (RATE_9M,
352 byBBType,
353 &abyTxRate[1],
354 &abyRsvTime[1]);
356 //RSPINF_a_12
357 CARDvCalculateOFDMRParameter (RATE_12M,
358 byBBType,
359 &abyTxRate[2],
360 &abyRsvTime[2]);
362 //RSPINF_a_18
363 CARDvCalculateOFDMRParameter (RATE_18M,
364 byBBType,
365 &abyTxRate[3],
366 &abyRsvTime[3]);
368 //RSPINF_a_24
369 CARDvCalculateOFDMRParameter (RATE_24M,
370 byBBType,
371 &abyTxRate[4],
372 &abyRsvTime[4]);
374 //RSPINF_a_36
375 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_36M),
376 byBBType,
377 &abyTxRate[5],
378 &abyRsvTime[5]);
380 //RSPINF_a_48
381 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_48M),
382 byBBType,
383 &abyTxRate[6],
384 &abyRsvTime[6]);
386 //RSPINF_a_54
387 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
388 byBBType,
389 &abyTxRate[7],
390 &abyRsvTime[7]);
392 //RSPINF_a_72
393 CARDvCalculateOFDMRParameter (swGetOFDMControlRate(pDevice, RATE_54M),
394 byBBType,
395 &abyTxRate[8],
396 &abyRsvTime[8]);
398 put_unaligned(phy[0].len, (u16 *)&abyData[0]);
399 abyData[2] = phy[0].signal;
400 abyData[3] = phy[0].service;
402 put_unaligned(phy[1].len, (u16 *)&abyData[4]);
403 abyData[6] = phy[1].signal;
404 abyData[7] = phy[1].service;
406 put_unaligned(phy[2].len, (u16 *)&abyData[8]);
407 abyData[10] = phy[2].signal;
408 abyData[11] = phy[2].service;
410 put_unaligned(phy[3].len, (u16 *)&abyData[12]);
411 abyData[14] = phy[3].signal;
412 abyData[15] = phy[3].service;
414 for (i = 0; i < 9; i++) {
415 abyData[16+i*2] = abyTxRate[i];
416 abyData[16+i*2+1] = abyRsvTime[i];
419 CONTROLnsRequestOut(pDevice,
420 MESSAGE_TYPE_WRITE,
421 MAC_REG_RSPINF_B_1,
422 MESSAGE_REQUEST_MACREG,
424 &abyData[0]);
429 * Description: Update IFS
431 * Parameters:
432 * In:
433 * pDevice - The adapter to be set
434 * Out:
435 * none
437 * Return Value: None.
440 void vUpdateIFS(struct vnt_private *pDevice)
442 u8 byMaxMin = 0;
443 u8 byData[4];
445 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
446 pDevice->uSlot = C_SLOT_SHORT;
447 pDevice->uSIFS = C_SIFS_A;
448 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
449 pDevice->uCwMin = C_CWMIN_A;
450 byMaxMin = 4;
452 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
453 pDevice->uSlot = C_SLOT_LONG;
454 pDevice->uSIFS = C_SIFS_BG;
455 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
456 pDevice->uCwMin = C_CWMIN_B;
457 byMaxMin = 5;
459 else {// PK_TYPE_11GA & PK_TYPE_11GB
460 u8 byRate = 0;
461 bool bOFDMRate = false;
462 unsigned int ii = 0;
463 PWLAN_IE_SUPP_RATES pItemRates = NULL;
465 pDevice->uSIFS = C_SIFS_BG;
466 if (pDevice->bShortSlotTime) {
467 pDevice->uSlot = C_SLOT_SHORT;
468 } else {
469 pDevice->uSlot = C_SLOT_LONG;
471 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
473 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt.abyCurrSuppRates;
474 for (ii = 0; ii < pItemRates->len; ii++) {
475 byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
476 if (RATEwGetRateIdx(byRate) > RATE_11M) {
477 bOFDMRate = true;
478 break;
481 if (bOFDMRate == false) {
482 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt
483 .abyCurrExtSuppRates;
484 for (ii = 0; ii < pItemRates->len; ii++) {
485 byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
486 if (RATEwGetRateIdx(byRate) > RATE_11M) {
487 bOFDMRate = true;
488 break;
492 if (bOFDMRate == true) {
493 pDevice->uCwMin = C_CWMIN_A;
494 byMaxMin = 4;
495 } else {
496 pDevice->uCwMin = C_CWMIN_B;
497 byMaxMin = 5;
501 pDevice->uCwMax = C_CWMAX;
502 pDevice->uEIFS = C_EIFS;
504 byData[0] = (u8)pDevice->uSIFS;
505 byData[1] = (u8)pDevice->uDIFS;
506 byData[2] = (u8)pDevice->uEIFS;
507 byData[3] = (u8)pDevice->uSlot;
508 CONTROLnsRequestOut(pDevice,
509 MESSAGE_TYPE_WRITE,
510 MAC_REG_SIFS,
511 MESSAGE_REQUEST_MACREG,
513 &byData[0]);
515 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
516 CONTROLnsRequestOut(pDevice,
517 MESSAGE_TYPE_WRITE,
518 MAC_REG_CWMAXMIN0,
519 MESSAGE_REQUEST_MACREG,
521 &byMaxMin);
524 void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
526 u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
527 u8 ii;
529 //Determines the highest basic rate.
530 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
531 if ( (pDevice->wBasicRate) & ((u16)(1<<ii)) ) {
532 byTopOFDM = ii;
533 break;
536 pDevice->byTopOFDMBasicRate = byTopOFDM;
538 for (ii = RATE_11M;; ii --) {
539 if ( (pDevice->wBasicRate) & ((u16)(1<<ii)) ) {
540 byTopCCK = ii;
541 break;
543 if (ii == RATE_1M)
544 break;
546 pDevice->byTopCCKBasicRate = byTopCCK;
550 * Description: Set NIC Tx Basic Rate
552 * Parameters:
553 * In:
554 * pDevice - The adapter to be set
555 * wBasicRate - Basic Rate to be set
556 * Out:
557 * none
559 * Return Value: true if succeeded; false if failed.
562 void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx)
564 u16 wRate = (1 << wRateIdx);
566 pDevice->wBasicRate |= wRate;
568 //Determines the highest basic rate.
569 CARDvUpdateBasicTopRate(pDevice);
572 int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
574 int ii;
576 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
577 if ((pDevice->wBasicRate) & ((u16)(1<<ii)))
578 return true;
580 return false;
583 u8 CARDbyGetPktType(struct vnt_private *pDevice)
586 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
587 return (u8)pDevice->byBBType;
589 else if (CARDbIsOFDMinBasicRate(pDevice)) {
590 return PK_TYPE_11GA;
592 else {
593 return PK_TYPE_11GB;
598 * Description: Calculate TSF offset of two TSF input
599 * Get TSF Offset from RxBCN's TSF and local TSF
601 * Parameters:
602 * In:
603 * pDevice - The adapter to be sync.
604 * qwTSF1 - Rx BCN's TSF
605 * qwTSF2 - Local TSF
606 * Out:
607 * none
609 * Return Value: TSF Offset value
612 u64 CARDqGetTSFOffset(u8 byRxRate, u64 qwTSF1, u64 qwTSF2)
614 u64 qwTSFOffset = 0;
615 u16 wRxBcnTSFOffst = 0;
617 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
619 qwTSF2 += (u64)wRxBcnTSFOffst;
621 qwTSFOffset = qwTSF1 - qwTSF2;
623 return qwTSFOffset;
627 * Description: Sync. TSF counter to BSS
628 * Get TSF offset and write to HW
630 * Parameters:
631 * In:
632 * pDevice - The adapter to be sync.
633 * qwBSSTimestamp - Rx BCN's TSF
634 * qwLocalTSF - Local TSF
635 * Out:
636 * none
638 * Return Value: none
641 void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
642 u64 qwBSSTimestamp, u64 qwLocalTSF)
644 u64 qwTSFOffset = 0;
645 u8 pbyData[8];
647 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
648 // adjust TSF
649 // HW's TSF add TSF Offset reg
651 pbyData[0] = (u8)qwTSFOffset;
652 pbyData[1] = (u8)(qwTSFOffset >> 8);
653 pbyData[2] = (u8)(qwTSFOffset >> 16);
654 pbyData[3] = (u8)(qwTSFOffset >> 24);
655 pbyData[4] = (u8)(qwTSFOffset >> 32);
656 pbyData[5] = (u8)(qwTSFOffset >> 40);
657 pbyData[6] = (u8)(qwTSFOffset >> 48);
658 pbyData[7] = (u8)(qwTSFOffset >> 56);
660 CONTROLnsRequestOut(pDevice,
661 MESSAGE_TYPE_SET_TSFTBTT,
662 MESSAGE_REQUEST_TSF,
665 pbyData
670 * Description: Read NIC TSF counter
671 * Get local TSF counter
673 * Parameters:
674 * In:
675 * pDevice - The adapter to be read
676 * Out:
677 * qwCurrTSF - Current TSF counter
679 * Return Value: true if success; otherwise false
682 bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
685 *pqwCurrTSF = pDevice->qwCurrTSF;
687 return true;
691 * Description: Clear NIC TSF counter
692 * Clear local TSF counter
694 * Parameters:
695 * In:
696 * pDevice - The adapter to be read
698 * Return Value: true if success; otherwise false
701 bool CARDbClearCurrentTSF(struct vnt_private *pDevice)
704 MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
706 pDevice->qwCurrTSF = 0;
708 return true;
712 * Description: Read NIC TSF counter
713 * Get NEXTTBTT from adjusted TSF and Beacon Interval
715 * Parameters:
716 * In:
717 * qwTSF - Current TSF counter
718 * wbeaconInterval - Beacon Interval
719 * Out:
720 * qwCurrTSF - Current TSF counter
722 * Return Value: TSF value of next Beacon
725 u64 CARDqGetNextTBTT(u64 qwTSF, u16 wBeaconInterval)
728 unsigned int uLowNextTBTT;
729 unsigned int uHighRemain, uLowRemain;
730 unsigned int uBeaconInterval;
732 uBeaconInterval = wBeaconInterval * 1024;
733 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
734 uLowNextTBTT = ((qwTSF & 0xffffffffULL) >> 10) << 10;
735 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
736 uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32))
737 % uBeaconInterval;
738 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
739 uLowRemain = uBeaconInterval - uLowRemain;
741 // check if carry when add one beacon interval
742 if ((~uLowNextTBTT) < uLowRemain)
743 qwTSF = ((qwTSF >> 32) + 1) << 32;
745 qwTSF = (qwTSF & 0xffffffff00000000ULL) |
746 (u64)(uLowNextTBTT + uLowRemain);
748 return (qwTSF);
752 * Description: Set NIC TSF counter for first Beacon time
753 * Get NEXTTBTT from adjusted TSF and Beacon Interval
755 * Parameters:
756 * In:
757 * dwIoBase - IO Base
758 * wBeaconInterval - Beacon Interval
759 * Out:
760 * none
762 * Return Value: none
765 void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, u16 wBeaconInterval)
767 u64 qwNextTBTT = 0;
768 u8 pbyData[8];
770 CARDbClearCurrentTSF(pDevice);
771 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
772 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
773 // Set NextTBTT
775 pbyData[0] = (u8)qwNextTBTT;
776 pbyData[1] = (u8)(qwNextTBTT >> 8);
777 pbyData[2] = (u8)(qwNextTBTT >> 16);
778 pbyData[3] = (u8)(qwNextTBTT >> 24);
779 pbyData[4] = (u8)(qwNextTBTT >> 32);
780 pbyData[5] = (u8)(qwNextTBTT >> 40);
781 pbyData[6] = (u8)(qwNextTBTT >> 48);
782 pbyData[7] = (u8)(qwNextTBTT >> 56);
784 CONTROLnsRequestOut(pDevice,
785 MESSAGE_TYPE_SET_TSFTBTT,
786 MESSAGE_REQUEST_TBTT,
789 pbyData
792 return;
796 * Description: Sync NIC TSF counter for Beacon time
797 * Get NEXTTBTT and write to HW
799 * Parameters:
800 * In:
801 * pDevice - The adapter to be set
802 * qwTSF - Current TSF counter
803 * wBeaconInterval - Beacon Interval
804 * Out:
805 * none
807 * Return Value: none
810 void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
811 u16 wBeaconInterval)
813 u8 pbyData[8];
815 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
817 // Set NextTBTT
819 pbyData[0] = (u8)qwTSF;
820 pbyData[1] = (u8)(qwTSF >> 8);
821 pbyData[2] = (u8)(qwTSF >> 16);
822 pbyData[3] = (u8)(qwTSF >> 24);
823 pbyData[4] = (u8)(qwTSF >> 32);
824 pbyData[5] = (u8)(qwTSF >> 40);
825 pbyData[6] = (u8)(qwTSF >> 48);
826 pbyData[7] = (u8)(qwTSF >> 56);
828 CONTROLnsRequestOut(pDevice,
829 MESSAGE_TYPE_SET_TSFTBTT,
830 MESSAGE_REQUEST_TBTT,
833 pbyData
836 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
837 "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
839 return;
843 * Description: Turn off Radio power
845 * Parameters:
846 * In:
847 * pDevice - The adapter to be turned off
848 * Out:
849 * none
851 * Return Value: true if success; otherwise false
854 int CARDbRadioPowerOff(struct vnt_private *pDevice)
856 int bResult = true;
858 //if (pDevice->bRadioOff == true)
859 // return true;
861 pDevice->bRadioOff = true;
863 switch (pDevice->byRFType) {
864 case RF_AL2230:
865 case RF_AL2230S:
866 case RF_AIROHA7230:
867 case RF_VT3226: //RobertYu:20051111
868 case RF_VT3226D0:
869 case RF_VT3342A0: //RobertYu:20060609
870 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
871 break;
874 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
876 BBvSetDeepSleep(pDevice);
878 return bResult;
882 * Description: Turn on Radio power
884 * Parameters:
885 * In:
886 * pDevice - The adapter to be turned on
887 * Out:
888 * none
890 * Return Value: true if success; otherwise false
893 int CARDbRadioPowerOn(struct vnt_private *pDevice)
895 int bResult = true;
897 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
898 return false;
901 //if (pDevice->bRadioOff == false)
902 // return true;
904 pDevice->bRadioOff = false;
906 BBvExitDeepSleep(pDevice);
908 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
910 switch (pDevice->byRFType) {
911 case RF_AL2230:
912 case RF_AL2230S:
913 case RF_AIROHA7230:
914 case RF_VT3226: //RobertYu:20051111
915 case RF_VT3226D0:
916 case RF_VT3342A0: //RobertYu:20060609
917 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
918 break;
921 return bResult;
924 void CARDvSetBSSMode(struct vnt_private *pDevice)
926 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
927 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
928 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
930 MACvSetBBType(pDevice, BB_TYPE_11G);
932 else
934 MACvSetBBType(pDevice, pDevice->byBBType);
936 pDevice->byPacketType = CARDbyGetPktType(pDevice);
938 if (pDevice->byBBType == BB_TYPE_11A) {
939 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
940 } else if (pDevice->byBBType == BB_TYPE_11B) {
941 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
942 } else if (pDevice->byBBType == BB_TYPE_11G) {
943 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
946 vUpdateIFS(pDevice);
947 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
949 if ( pDevice->byBBType == BB_TYPE_11A ) {
950 //request by Jack 2005-04-26
951 if (pDevice->byRFType == RF_AIROHA7230) {
952 pDevice->abyBBVGA[0] = 0x20;
953 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
955 pDevice->abyBBVGA[2] = 0x10;
956 pDevice->abyBBVGA[3] = 0x10;
957 } else {
958 //request by Jack 2005-04-26
959 if (pDevice->byRFType == RF_AIROHA7230) {
960 pDevice->abyBBVGA[0] = 0x1C;
961 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
963 pDevice->abyBBVGA[2] = 0x0;
964 pDevice->abyBBVGA[3] = 0x0;