2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
20 * Purpose: Provide functions to setup NIC operation mode
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
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().
61 /*--------------------- Static Definitions -------------------------*/
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 static int msglevel
=MSG_LEVEL_INFO
;
66 #define C_SIFS_A 16 // micro sec.
69 #define C_EIFS 80 // micro sec.
72 #define C_SLOT_SHORT 9 // micro sec.
73 #define C_SLOT_LONG 20
75 #define C_CWMIN_A 15 // slot time
78 #define C_CWMAX 1023 // slot time
80 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
82 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
83 static unsigned char abyDefaultSuppRatesG
[] = {WLAN_EID_SUPP_RATES
, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
85 static unsigned char abyDefaultExtSuppRatesG
[] = {WLAN_EID_EXTSUPP_RATES
, 4, 0x0C, 0x12, 0x18, 0x60};
86 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
87 static unsigned char abyDefaultSuppRatesA
[] = {WLAN_EID_SUPP_RATES
, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
89 static unsigned char abyDefaultSuppRatesB
[] = {WLAN_EID_SUPP_RATES
, 4, 0x02, 0x04, 0x0B, 0x16};
92 /*--------------------- Static Variables --------------------------*/
95 const unsigned short cwRXBCNTSFOff
[MAX_RATE
] =
96 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
99 /*--------------------- Static Functions --------------------------*/
103 s_vCaculateOFDMRParameter(
104 unsigned char byRate
,
105 CARD_PHY_TYPE ePHYType
,
106 unsigned char *pbyTxRate
,
107 unsigned char *pbyRsvTime
111 /*--------------------- Export Functions --------------------------*/
114 * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
119 * byPktType - Tx Packet type
121 * pbyTxRate - pointer to RSPINF TxRate field
122 * pbyRsvTime - pointer to RSPINF RsvTime field
129 s_vCaculateOFDMRParameter (
130 unsigned char byRate
,
131 CARD_PHY_TYPE ePHYType
,
132 unsigned char *pbyTxRate
,
133 unsigned char *pbyRsvTime
138 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
149 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
160 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
171 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
182 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
193 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
204 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
216 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
231 * Description: Set RSPINF
235 * pDevice - The adapter to be set
239 * Return Value: None.
244 s_vSetRSPINF (PSDevice pDevice
, CARD_PHY_TYPE ePHYType
, void *pvSupportRateIEs
, void *pvExtSupportRateIEs
)
246 unsigned char byServ
= 0, bySignal
= 0; // For CCK
247 unsigned short wLen
= 0;
248 unsigned char byTxRate
= 0, byRsvTime
= 0; // For OFDM
251 MACvSelectPage1(pDevice
->PortOffset
);
254 BBvCaculateParameter(pDevice
,
256 VNTWIFIbyGetACKTxRate(RATE_1M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
263 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_1
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
265 BBvCaculateParameter(pDevice
,
267 VNTWIFIbyGetACKTxRate(RATE_2M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
274 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_2
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
276 BBvCaculateParameter(pDevice
,
278 VNTWIFIbyGetACKTxRate(RATE_5M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
285 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_5
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
287 BBvCaculateParameter(pDevice
,
289 VNTWIFIbyGetACKTxRate(RATE_11M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
296 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_11
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
298 s_vCaculateOFDMRParameter(RATE_6M
,
302 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_6
, MAKEWORD(byTxRate
,byRsvTime
));
304 s_vCaculateOFDMRParameter(RATE_9M
,
308 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_9
, MAKEWORD(byTxRate
,byRsvTime
));
310 s_vCaculateOFDMRParameter(RATE_12M
,
314 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_12
, MAKEWORD(byTxRate
,byRsvTime
));
316 s_vCaculateOFDMRParameter(RATE_18M
,
320 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_18
, MAKEWORD(byTxRate
,byRsvTime
));
322 s_vCaculateOFDMRParameter(RATE_24M
,
326 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_24
, MAKEWORD(byTxRate
,byRsvTime
));
328 s_vCaculateOFDMRParameter(
329 VNTWIFIbyGetACKTxRate(RATE_36M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
333 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_36
, MAKEWORD(byTxRate
,byRsvTime
));
335 s_vCaculateOFDMRParameter(
336 VNTWIFIbyGetACKTxRate(RATE_48M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
340 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_48
, MAKEWORD(byTxRate
,byRsvTime
));
342 s_vCaculateOFDMRParameter(
343 VNTWIFIbyGetACKTxRate(RATE_54M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
347 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_54
, MAKEWORD(byTxRate
,byRsvTime
));
349 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_72
, MAKEWORD(byTxRate
,byRsvTime
));
351 MACvSelectPage0(pDevice
->PortOffset
);
354 /*--------------------- Export Functions --------------------------*/
357 * Description: Card Send packet function
361 * pDeviceHandler - The adapter to be set
362 * pPacket - Packet buffer pointer
363 * ePktType - Packet type
364 * uLength - Packet length
368 * Return Value: true if succeeded; false if failed.
372 bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength)
374 PSDevice pDevice = (PSDevice) pDeviceHandler;
375 if (ePktType == PKT_TYPE_802_11_MNG) {
376 return TXbTD0Send(pDevice, pPacket, uLength);
377 } else if (ePktType == PKT_TYPE_802_11_BCN) {
378 return TXbBeaconSend(pDevice, pPacket, uLength);
379 } if (ePktType == PKT_TYPE_802_11_DATA) {
380 return TXbTD1Send(pDevice, pPacket, uLength);
389 * Description: Get Card short preamble option value
393 * pDevice - The adapter to be set
397 * Return Value: true if short preamble; otherwise false
400 bool CARDbIsShortPreamble (void *pDeviceHandler
)
402 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
403 if (pDevice
->byPreambleType
== 0) {
410 * Description: Get Card short slot time option value
414 * pDevice - The adapter to be set
418 * Return Value: true if short slot time; otherwise false
421 bool CARDbIsShorSlotTime (void *pDeviceHandler
)
423 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
424 return(pDevice
->bShortSlotTime
);
429 * Description: Update IFS
433 * pDevice - The adapter to be set
437 * Return Value: None.
440 bool CARDbSetPhyParameter (void *pDeviceHandler
, CARD_PHY_TYPE ePHYType
, unsigned short wCapInfo
, unsigned char byERPField
, void *pvSupportRateIEs
, void *pvExtSupportRateIEs
)
442 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
443 unsigned char byCWMaxMin
= 0;
444 unsigned char bySlot
= 0;
445 unsigned char bySIFS
= 0;
446 unsigned char byDIFS
= 0;
447 unsigned char byData
;
448 // PWLAN_IE_SUPP_RATES pRates = NULL;
449 PWLAN_IE_SUPP_RATES pSupportRates
= (PWLAN_IE_SUPP_RATES
) pvSupportRateIEs
;
450 PWLAN_IE_SUPP_RATES pExtSupportRates
= (PWLAN_IE_SUPP_RATES
) pvExtSupportRateIEs
;
453 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
454 if (ePHYType
== PHY_TYPE_11A
) {
455 if (pSupportRates
== NULL
) {
456 pSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultSuppRatesA
;
458 if (pDevice
->byRFType
== RF_AIROHA7230
) {
459 // AL7230 use single PAPE and connect to PAPE_2.4G
460 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11G
);
461 pDevice
->abyBBVGA
[0] = 0x20;
462 pDevice
->abyBBVGA
[2] = 0x10;
463 pDevice
->abyBBVGA
[3] = 0x10;
464 BBbReadEmbeded(pDevice
->PortOffset
, 0xE7, &byData
);
465 if (byData
== 0x1C) {
466 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
468 } else if (pDevice
->byRFType
== RF_UW2452
) {
469 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11A
);
470 pDevice
->abyBBVGA
[0] = 0x18;
471 BBbReadEmbeded(pDevice
->PortOffset
, 0xE7, &byData
);
472 if (byData
== 0x14) {
473 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
474 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE1, 0x57);
477 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11A
);
479 BBbWriteEmbeded(pDevice
->PortOffset
, 0x88, 0x03);
480 bySlot
= C_SLOT_SHORT
;
482 byDIFS
= C_SIFS_A
+ 2*C_SLOT_SHORT
;
484 } else if (ePHYType
== PHY_TYPE_11B
) {
485 if (pSupportRates
== NULL
) {
486 pSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultSuppRatesB
;
488 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11B
);
489 if (pDevice
->byRFType
== RF_AIROHA7230
) {
490 pDevice
->abyBBVGA
[0] = 0x1C;
491 pDevice
->abyBBVGA
[2] = 0x00;
492 pDevice
->abyBBVGA
[3] = 0x00;
493 BBbReadEmbeded(pDevice
->PortOffset
, 0xE7, &byData
);
494 if (byData
== 0x20) {
495 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
497 } else if (pDevice
->byRFType
== RF_UW2452
) {
498 pDevice
->abyBBVGA
[0] = 0x14;
499 BBbReadEmbeded(pDevice
->PortOffset
, 0xE7, &byData
);
500 if (byData
== 0x18) {
501 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
502 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE1, 0xD3);
505 BBbWriteEmbeded(pDevice
->PortOffset
, 0x88, 0x02);
506 bySlot
= C_SLOT_LONG
;
508 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
510 } else {// PK_TYPE_11GA & PK_TYPE_11GB
511 if (pSupportRates
== NULL
) {
512 pSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultSuppRatesG
;
513 pExtSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultExtSuppRatesG
;
515 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11G
);
516 if (pDevice
->byRFType
== RF_AIROHA7230
) {
517 pDevice
->abyBBVGA
[0] = 0x1C;
518 pDevice
->abyBBVGA
[2] = 0x00;
519 pDevice
->abyBBVGA
[3] = 0x00;
520 BBbReadEmbeded(pDevice
->PortOffset
, 0xE7, &byData
);
521 if (byData
== 0x20) {
522 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
524 } else if (pDevice
->byRFType
== RF_UW2452
) {
525 pDevice
->abyBBVGA
[0] = 0x14;
526 BBbReadEmbeded(pDevice
->PortOffset
, 0xE7, &byData
);
527 if (byData
== 0x18) {
528 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
529 BBbWriteEmbeded(pDevice
->PortOffset
, 0xE1, 0xD3);
532 BBbWriteEmbeded(pDevice
->PortOffset
, 0x88, 0x08);
534 if(VNTWIFIbIsShortSlotTime(wCapInfo
)) {
535 bySlot
= C_SLOT_SHORT
;
536 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_SHORT
;
538 bySlot
= C_SLOT_LONG
;
539 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
541 if (VNTWIFIbyGetMaxSupportRate(pSupportRates
, pExtSupportRates
) > RATE_11M
) {
546 if (pDevice
->bProtectMode
!= VNTWIFIbIsProtectMode(byERPField
)) {
547 pDevice
->bProtectMode
= VNTWIFIbIsProtectMode(byERPField
);
548 if (pDevice
->bProtectMode
) {
549 MACvEnableProtectMD(pDevice
->PortOffset
);
551 MACvDisableProtectMD(pDevice
->PortOffset
);
554 if (pDevice
->bBarkerPreambleMd
!= VNTWIFIbIsBarkerMode(byERPField
)) {
555 pDevice
->bBarkerPreambleMd
= VNTWIFIbIsBarkerMode(byERPField
);
556 if (pDevice
->bBarkerPreambleMd
) {
557 MACvEnableBarkerPreambleMd(pDevice
->PortOffset
);
559 MACvDisableBarkerPreambleMd(pDevice
->PortOffset
);
564 if (pDevice
->byRFType
== RF_RFMD2959
) {
565 // bcs TX_PE will reserve 3 us
566 // hardware's processing time here is 2 us.
569 //{{ RobertYu: 20041202
570 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
571 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
574 if (pDevice
->bySIFS
!= bySIFS
) {
575 pDevice
->bySIFS
= bySIFS
;
576 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, pDevice
->bySIFS
);
578 if (pDevice
->byDIFS
!= byDIFS
) {
579 pDevice
->byDIFS
= byDIFS
;
580 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, pDevice
->byDIFS
);
582 if (pDevice
->byEIFS
!= C_EIFS
) {
583 pDevice
->byEIFS
= C_EIFS
;
584 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_EIFS
, pDevice
->byEIFS
);
586 if (pDevice
->bySlot
!= bySlot
) {
587 pDevice
->bySlot
= bySlot
;
588 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SLOT
, pDevice
->bySlot
);
589 if (pDevice
->bySlot
== C_SLOT_SHORT
) {
590 pDevice
->bShortSlotTime
= true;
592 pDevice
->bShortSlotTime
= false;
594 BBvSetShortSlotTime(pDevice
);
596 if (pDevice
->byCWMaxMin
!= byCWMaxMin
) {
597 pDevice
->byCWMaxMin
= byCWMaxMin
;
598 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_CWMAXMIN0
, pDevice
->byCWMaxMin
);
600 if (VNTWIFIbIsShortPreamble(wCapInfo
)) {
601 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
603 pDevice
->byPreambleType
= 0;
605 s_vSetRSPINF(pDevice
, ePHYType
, pSupportRates
, pExtSupportRates
);
606 pDevice
->eCurrentPHYType
= ePHYType
;
607 // set for NDIS OID_802_11SUPPORTED_RATES
612 * Description: Sync. TSF counter to BSS
613 * Get TSF offset and write to HW
617 * pDevice - The adapter to be sync.
618 * byRxRate - data rate of receive beacon
619 * qwBSSTimestamp - Rx BCN's TSF
620 * qwLocalTSF - Local TSF
627 bool CARDbUpdateTSF (void *pDeviceHandler
, unsigned char byRxRate
, QWORD qwBSSTimestamp
, QWORD qwLocalTSF
)
629 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
632 HIDWORD(qwTSFOffset
) = 0;
633 LODWORD(qwTSFOffset
) = 0;
635 if ((HIDWORD(qwBSSTimestamp
) != HIDWORD(qwLocalTSF
)) ||
636 (LODWORD(qwBSSTimestamp
) != LODWORD(qwLocalTSF
))) {
637 qwTSFOffset
= CARDqGetTSFOffset(byRxRate
, qwBSSTimestamp
, qwLocalTSF
);
639 // HW's TSF add TSF Offset reg
640 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_TSFOFST
, LODWORD(qwTSFOffset
));
641 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_TSFOFST
+ 4, HIDWORD(qwTSFOffset
));
642 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TSFSYNCEN
);
649 * Description: Set NIC TSF counter for first Beacon time
650 * Get NEXTTBTT from adjusted TSF and Beacon Interval
654 * pDevice - The adapter to be set.
655 * wBeaconInterval - Beacon Interval
659 * Return Value: true if succeed; otherwise false
662 bool CARDbSetBeaconPeriod (void *pDeviceHandler
, unsigned short wBeaconInterval
)
664 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
665 unsigned int uBeaconInterval
= 0;
666 unsigned int uLowNextTBTT
= 0;
667 unsigned int uHighRemain
= 0;
668 unsigned int uLowRemain
= 0;
671 HIDWORD(qwNextTBTT
) = 0;
672 LODWORD(qwNextTBTT
) = 0;
673 CARDbGetCurrentTSF(pDevice
->PortOffset
, &qwNextTBTT
); //Get Local TSF counter
674 uBeaconInterval
= wBeaconInterval
* 1024;
675 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
676 uLowNextTBTT
= (LODWORD(qwNextTBTT
) >> 10) << 10;
677 uLowRemain
= (uLowNextTBTT
) % uBeaconInterval
;
678 // high dword (mod) bcn
679 uHighRemain
= (((0xffffffff % uBeaconInterval
) + 1) * HIDWORD(qwNextTBTT
))
681 uLowRemain
= (uHighRemain
+ uLowRemain
) % uBeaconInterval
;
682 uLowRemain
= uBeaconInterval
- uLowRemain
;
684 // check if carry when add one beacon interval
685 if ((~uLowNextTBTT
) < uLowRemain
) {
686 HIDWORD(qwNextTBTT
) ++ ;
688 LODWORD(qwNextTBTT
) = uLowNextTBTT
+ uLowRemain
;
690 // set HW beacon interval
691 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_BI
, wBeaconInterval
);
692 pDevice
->wBeaconInterval
= wBeaconInterval
;
694 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_NEXTTBTT
, LODWORD(qwNextTBTT
));
695 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_NEXTTBTT
+ 4, HIDWORD(qwNextTBTT
));
696 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
704 * Description: Card Stop Hardware Tx
708 * pDeviceHandler - The adapter to be set
709 * ePktType - Packet type to stop
713 * Return Value: true if all data packet complete; otherwise false.
716 bool CARDbStopTxPacket (void *pDeviceHandler
, CARD_PKT_TYPE ePktType
)
718 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
721 if (ePktType
== PKT_TYPE_802_11_ALL
) {
722 pDevice
->bStopBeacon
= true;
723 pDevice
->bStopTx0Pkt
= true;
724 pDevice
->bStopDataPkt
= true;
725 } else if (ePktType
== PKT_TYPE_802_11_BCN
) {
726 pDevice
->bStopBeacon
= true;
727 } else if (ePktType
== PKT_TYPE_802_11_MNG
) {
728 pDevice
->bStopTx0Pkt
= true;
729 } else if (ePktType
== PKT_TYPE_802_11_DATA
) {
730 pDevice
->bStopDataPkt
= true;
733 if (pDevice
->bStopBeacon
== true) {
734 if (pDevice
->bIsBeaconBufReadySet
== true) {
735 if (pDevice
->cbBeaconBufReadySetCnt
< WAIT_BEACON_TX_DOWN_TMO
) {
736 pDevice
->cbBeaconBufReadySetCnt
++;
740 pDevice
->bIsBeaconBufReadySet
= false;
741 pDevice
->cbBeaconBufReadySetCnt
= 0;
742 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
744 // wait all TD0 complete
745 if (pDevice
->bStopTx0Pkt
== true) {
746 if (pDevice
->iTDUsed
[TYPE_TXDMA0
] != 0){
750 // wait all Data TD complete
751 if (pDevice
->bStopDataPkt
== true) {
752 if (pDevice
->iTDUsed
[TYPE_AC0DMA
] != 0){
762 * Description: Card Start Hardware Tx
766 * pDeviceHandler - The adapter to be set
767 * ePktType - Packet type to start
771 * Return Value: true if success; false if failed.
774 bool CARDbStartTxPacket (void *pDeviceHandler
, CARD_PKT_TYPE ePktType
)
776 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
779 if (ePktType
== PKT_TYPE_802_11_ALL
) {
780 pDevice
->bStopBeacon
= false;
781 pDevice
->bStopTx0Pkt
= false;
782 pDevice
->bStopDataPkt
= false;
783 } else if (ePktType
== PKT_TYPE_802_11_BCN
) {
784 pDevice
->bStopBeacon
= false;
785 } else if (ePktType
== PKT_TYPE_802_11_MNG
) {
786 pDevice
->bStopTx0Pkt
= false;
787 } else if (ePktType
== PKT_TYPE_802_11_DATA
) {
788 pDevice
->bStopDataPkt
= false;
791 if ((pDevice
->bStopBeacon
== false) &&
792 (pDevice
->bBeaconBufReady
== true) &&
793 (pDevice
->eOPMode
== OP_MODE_ADHOC
)) {
794 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
803 * Description: Card Set BSSID value
807 * pDeviceHandler - The adapter to be set
808 * pbyBSSID - pointer to BSSID field
809 * bAdhoc - flag to indicate IBSS
813 * Return Value: true if success; false if failed.
816 bool CARDbSetBSSID(void *pDeviceHandler
, unsigned char *pbyBSSID
, CARD_OP_MODE eOPMode
)
818 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
820 MACvWriteBSSIDAddress(pDevice
->PortOffset
, pbyBSSID
);
821 memcpy(pDevice
->abyBSSID
, pbyBSSID
, WLAN_BSSID_LEN
);
822 if (eOPMode
== OP_MODE_ADHOC
) {
823 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_ADHOC
);
825 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_ADHOC
);
827 if (eOPMode
== OP_MODE_AP
) {
828 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_AP
);
830 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_AP
);
832 if (eOPMode
== OP_MODE_UNKNOWN
) {
833 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_BSSID
);
834 pDevice
->bBSSIDFilter
= false;
835 pDevice
->byRxMode
&= ~RCR_BSSID
;
836 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wcmd: rx_mode = %x\n", pDevice
->byRxMode
);
838 if (is_zero_ether_addr(pDevice
->abyBSSID
) == false) {
839 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_BSSID
);
840 pDevice
->bBSSIDFilter
= true;
841 pDevice
->byRxMode
|= RCR_BSSID
;
843 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wmgr: rx_mode = %x\n", pDevice
->byRxMode
);
845 // Adopt BSS state in Adapter Device Object
846 pDevice
->eOPMode
= eOPMode
;
852 * Description: Card indicate status
856 * pDeviceHandler - The adapter to be set
861 * Return Value: true if success; false if failed.
869 * Description: Save Assoc info. contain in assoc. response frame
873 * pDevice - The adapter to be set
874 * wCapabilityInfo - Capability information
875 * wStatus - Status code
877 * uLen - Length of IEs
878 * pbyIEs - pointer to IEs
882 * Return Value: true if succeed; otherwise false
885 bool CARDbSetTxDataRate(
886 void *pDeviceHandler
,
887 unsigned short wDataRate
890 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
892 pDevice
->wCurrentRate
= wDataRate
;
898 * Routine Description:
899 * Consider to power down when no more packets to tx or rx.
903 * pDevice - The adapter to be set
907 * Return Value: true if power down success; otherwise false
915 PSDevice pDevice
= (PSDevice
)pDeviceHandler
;
918 // check if already in Doze mode
919 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
))
923 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
925 // check if all TD are empty,
927 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
928 if (pDevice
->iTDUsed
[uIdx
] != 0)
932 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
933 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
938 * Description: Turn off Radio power
942 * pDevice - The adapter to be turned off
946 * Return Value: true if success; otherwise false
949 bool CARDbRadioPowerOff (void *pDeviceHandler
)
951 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
954 if (pDevice
->bRadioOff
== true)
958 switch (pDevice
->byRFType
) {
961 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_TXPEINV
);
962 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE1
);
967 case RF_AIROHA7230
: //RobertYu:20050104
968 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE2
);
969 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE3
);
974 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
976 BBvSetDeepSleep(pDevice
->PortOffset
, pDevice
->byLocalID
);
978 pDevice
->bRadioOff
= true;
979 //2007-0409-03,<Add> by chester
980 printk("chester power off\n");
981 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_GPIOCTL0
, LED_ACTSET
); //LED issue
987 * Description: Turn on Radio power
991 * pDevice - The adapter to be turned on
995 * Return Value: true if success; otherwise false
998 bool CARDbRadioPowerOn (void *pDeviceHandler
)
1000 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1001 bool bResult
= true;
1002 printk("chester power on\n");
1003 if (pDevice
->bRadioControlOff
== true){
1004 if (pDevice
->bHWRadioOff
== true) printk("chester bHWRadioOff\n");
1005 if (pDevice
->bRadioControlOff
== true) printk("chester bRadioControlOff\n");
1008 if (pDevice
->bRadioOff
== false)
1010 printk("chester pbRadioOff\n");
1013 BBvExitDeepSleep(pDevice
->PortOffset
, pDevice
->byLocalID
);
1015 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
1017 switch (pDevice
->byRFType
) {
1020 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_TXPEINV
);
1021 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE1
);
1026 case RF_AIROHA7230
: //RobertYu:20050104
1027 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, (SOFTPWRCTL_SWPE2
|
1033 pDevice
->bRadioOff
= false;
1034 // 2007-0409-03,<Add> by chester
1035 printk("chester power on\n");
1036 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_GPIOCTL0
, LED_ACTSET
); //LED issue
1042 bool CARDbRemoveKey (void *pDeviceHandler
, unsigned char *pbyBSSID
)
1044 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1046 KeybRemoveAllKey(&(pDevice
->sKey
), pbyBSSID
, pDevice
->PortOffset
);
1054 * Add BSSID in PMKID Candidate list.
1058 * hDeviceContext - device structure point
1059 * pbyBSSID - BSSID address for adding
1060 * wRSNCap - BSS's RSN capability
1064 * Return Value: none.
1068 CARDbAdd_PMKID_Candidate (
1069 void *pDeviceHandler
,
1070 unsigned char *pbyBSSID
,
1072 unsigned short wRSNCap
1075 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1076 PPMKID_CANDIDATE pCandidateList
;
1077 unsigned int ii
= 0;
1079 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice
->gsPMKIDCandidate
.NumCandidates
);
1081 if (pDevice
->gsPMKIDCandidate
.NumCandidates
>= MAX_PMKIDLIST
) {
1082 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vFlush_PMKID_Candidate: 3\n");
1083 memset(&pDevice
->gsPMKIDCandidate
, 0, sizeof(SPMKIDCandidateEvent
));
1086 for (ii
= 0; ii
< 6; ii
++) {
1087 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02X ", *(pbyBSSID
+ ii
));
1089 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
1092 // Update Old Candidate
1093 for (ii
= 0; ii
< pDevice
->gsPMKIDCandidate
.NumCandidates
; ii
++) {
1094 pCandidateList
= &pDevice
->gsPMKIDCandidate
.CandidateList
[ii
];
1095 if ( !memcmp(pCandidateList
->BSSID
, pbyBSSID
, ETH_ALEN
)) {
1096 if ((bRSNCapExist
== true) && (wRSNCap
& BIT0
)) {
1097 pCandidateList
->Flags
|= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
1099 pCandidateList
->Flags
&= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
);
1106 pCandidateList
= &pDevice
->gsPMKIDCandidate
.CandidateList
[pDevice
->gsPMKIDCandidate
.NumCandidates
];
1107 if ((bRSNCapExist
== true) && (wRSNCap
& BIT0
)) {
1108 pCandidateList
->Flags
|= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
1110 pCandidateList
->Flags
&= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
);
1112 memcpy(pCandidateList
->BSSID
, pbyBSSID
, ETH_ALEN
);
1113 pDevice
->gsPMKIDCandidate
.NumCandidates
++;
1114 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"NumCandidates:%d\n", (int)pDevice
->gsPMKIDCandidate
.NumCandidates
);
1119 CARDpGetCurrentAddress (
1120 void *pDeviceHandler
1123 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1125 return (pDevice
->abyCurrentNetAddr
);
1131 * Start Spectrum Measure defined in 802.11h
1135 * hDeviceContext - device structure point
1139 * Return Value: none.
1144 void *pDeviceHandler
,
1145 void *pvMeasureEIDs
,
1146 unsigned int uNumOfMeasureEIDs
1149 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1150 PWLAN_IE_MEASURE_REQ pEID
= (PWLAN_IE_MEASURE_REQ
) pvMeasureEIDs
;
1153 bool bExpired
= true;
1154 unsigned short wDuration
= 0;
1156 if ((pEID
== NULL
) ||
1157 (uNumOfMeasureEIDs
== 0)) {
1160 CARDbGetCurrentTSF(pDevice
->PortOffset
, &qwCurrTSF
);
1161 if (pDevice
->bMeasureInProgress
== true) {
1162 pDevice
->bMeasureInProgress
= false;
1163 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, pDevice
->byOrgRCR
);
1164 MACvSelectPage1(pDevice
->PortOffset
);
1165 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
, pDevice
->dwOrgMAR0
);
1166 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR4
, pDevice
->dwOrgMAR4
);
1167 // clear measure control
1168 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_EN
);
1169 MACvSelectPage0(pDevice
->PortOffset
);
1170 set_channel(pDevice
, pDevice
->byOrgChannel
);
1171 MACvSelectPage1(pDevice
->PortOffset
);
1172 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
1173 MACvSelectPage0(pDevice
->PortOffset
);
1175 pDevice
->uNumOfMeasureEIDs
= uNumOfMeasureEIDs
;
1178 pDevice
->pCurrMeasureEID
= pEID
;
1180 pDevice
->uNumOfMeasureEIDs
--;
1182 if (pDevice
->byLocalID
> REV_ID_VT3253_B1
) {
1183 HIDWORD(qwStartTSF
) = HIDWORD(*((PQWORD
) (pDevice
->pCurrMeasureEID
->sReq
.abyStartTime
)));
1184 LODWORD(qwStartTSF
) = LODWORD(*((PQWORD
) (pDevice
->pCurrMeasureEID
->sReq
.abyStartTime
)));
1185 wDuration
= *((unsigned short *) (pDevice
->pCurrMeasureEID
->sReq
.abyDuration
));
1186 wDuration
+= 1; // 1 TU for channel switching
1188 if ((LODWORD(qwStartTSF
) == 0) && (HIDWORD(qwStartTSF
) == 0)) {
1189 // start immediately by setting start TSF == current TSF + 2 TU
1190 LODWORD(qwStartTSF
) = LODWORD(qwCurrTSF
) + 2048;
1191 HIDWORD(qwStartTSF
) = HIDWORD(qwCurrTSF
);
1192 if (LODWORD(qwCurrTSF
) > LODWORD(qwStartTSF
)) {
1193 HIDWORD(qwStartTSF
)++;
1198 // start at setting start TSF - 1TU(for channel switching)
1199 if (LODWORD(qwStartTSF
) < 1024) {
1200 HIDWORD(qwStartTSF
)--;
1202 LODWORD(qwStartTSF
) -= 1024;
1205 if ((HIDWORD(qwCurrTSF
) < HIDWORD(qwStartTSF
)) ||
1206 ((HIDWORD(qwCurrTSF
) == HIDWORD(qwStartTSF
)) &&
1207 (LODWORD(qwCurrTSF
) < LODWORD(qwStartTSF
)))
1212 VNTWIFIbMeasureReport( pDevice
->pMgmt
,
1214 pDevice
->pCurrMeasureEID
,
1216 pDevice
->byBasicMap
,
1217 pDevice
->byCCAFraction
,
1221 // hardware do not support measure
1222 VNTWIFIbMeasureReport( pDevice
->pMgmt
,
1224 pDevice
->pCurrMeasureEID
,
1225 MEASURE_MODE_INCAPABLE
,
1226 pDevice
->byBasicMap
,
1227 pDevice
->byCCAFraction
,
1231 } while (pDevice
->uNumOfMeasureEIDs
!= 0);
1233 if (bExpired
== false) {
1234 MACvSelectPage1(pDevice
->PortOffset
);
1235 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MSRSTART
, LODWORD(qwStartTSF
));
1236 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MSRSTART
+ 4, HIDWORD(qwStartTSF
));
1237 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_MSRDURATION
, wDuration
);
1238 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_EN
);
1239 MACvSelectPage0(pDevice
->PortOffset
);
1241 // all measure start time expired we should complete action
1242 VNTWIFIbMeasureReport( pDevice
->pMgmt
,
1246 pDevice
->byBasicMap
,
1247 pDevice
->byCCAFraction
,
1258 * Do Channel Switch defined in 802.11h
1262 * hDeviceContext - device structure point
1266 * Return Value: none.
1270 CARDbChannelSwitch (
1271 void *pDeviceHandler
,
1272 unsigned char byMode
,
1273 unsigned char byNewChannel
,
1274 unsigned char byCount
1277 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1278 bool bResult
= true;
1281 bResult
= set_channel(pDevice
, byNewChannel
);
1282 VNTWIFIbChannelSwitch(pDevice
->pMgmt
, byNewChannel
);
1283 MACvSelectPage1(pDevice
->PortOffset
);
1284 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
1285 MACvSelectPage0(pDevice
->PortOffset
);
1288 pDevice
->byChannelSwitchCount
= byCount
;
1289 pDevice
->byNewChannel
= byNewChannel
;
1290 pDevice
->bChannelSwitch
= true;
1292 bResult
=CARDbStopTxPacket(pDevice
, PKT_TYPE_802_11_ALL
);
1301 * Handle Quiet EID defined in 802.11h
1305 * hDeviceContext - device structure point
1309 * Return Value: none.
1314 void *pDeviceHandler
,
1316 unsigned char byQuietCount
,
1317 unsigned char byQuietPeriod
,
1318 unsigned short wQuietDuration
,
1319 unsigned short wQuietOffset
1322 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1323 unsigned int ii
= 0;
1325 if (bResetQuiet
== true) {
1326 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
1327 for(ii
=0;ii
<MAX_QUIET_COUNT
;ii
++) {
1328 pDevice
->sQuiet
[ii
].bEnable
= false;
1330 pDevice
->uQuietEnqueue
= 0;
1331 pDevice
->bEnableFirstQuiet
= false;
1332 pDevice
->bQuietEnable
= false;
1333 pDevice
->byQuietStartCount
= byQuietCount
;
1335 if (pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].bEnable
== false) {
1336 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].bEnable
= true;
1337 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].byPeriod
= byQuietPeriod
;
1338 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].wDuration
= wQuietDuration
;
1339 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].dwStartTime
= (unsigned long) byQuietCount
;
1340 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].dwStartTime
*= pDevice
->wBeaconInterval
;
1341 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].dwStartTime
+= wQuietOffset
;
1342 pDevice
->uQuietEnqueue
++;
1343 pDevice
->uQuietEnqueue
%= MAX_QUIET_COUNT
;
1344 if (pDevice
->byQuietStartCount
< byQuietCount
) {
1345 pDevice
->byQuietStartCount
= byQuietCount
;
1348 // we can not handle Quiet EID more
1357 * Do Quiet, It will called by either ISR (after start) or VNTWIFI (before start) so do not need SPINLOCK
1361 * hDeviceContext - device structure point
1365 * Return Value: none.
1370 void *pDeviceHandler
1373 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1374 unsigned int ii
= 0;
1375 unsigned long dwStartTime
= 0xFFFFFFFF;
1376 unsigned int uCurrentQuietIndex
= 0;
1377 unsigned long dwNextTime
= 0;
1378 unsigned long dwGap
= 0;
1379 unsigned long dwDuration
= 0;
1381 for(ii
=0;ii
<MAX_QUIET_COUNT
;ii
++) {
1382 if ((pDevice
->sQuiet
[ii
].bEnable
== true) &&
1383 (dwStartTime
> pDevice
->sQuiet
[ii
].dwStartTime
)) {
1384 dwStartTime
= pDevice
->sQuiet
[ii
].dwStartTime
;
1385 uCurrentQuietIndex
= ii
;
1388 if (dwStartTime
== 0xFFFFFFFF) {
1390 pDevice
->bQuietEnable
= false;
1391 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
1393 if (pDevice
->bQuietEnable
== false) {
1395 pDevice
->byQuietStartCount
--;
1396 dwNextTime
= pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
;
1397 dwNextTime
%= pDevice
->wBeaconInterval
;
1398 MACvSelectPage1(pDevice
->PortOffset
);
1399 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETINIT
, (unsigned short) dwNextTime
);
1400 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETDUR
, (unsigned short) pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
);
1401 if (pDevice
->byQuietStartCount
== 0) {
1402 pDevice
->bEnableFirstQuiet
= false;
1403 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
1405 pDevice
->bEnableFirstQuiet
= true;
1407 MACvSelectPage0(pDevice
->PortOffset
);
1409 if (pDevice
->dwCurrentQuietEndTime
> pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
) {
1410 // overlap with previous Quiet
1411 dwGap
= pDevice
->dwCurrentQuietEndTime
- pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
;
1412 if (dwGap
>= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
) {
1413 // return false to indicate next quiet expired, should call this function again
1416 dwDuration
= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
- dwGap
;
1419 dwGap
= pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
- pDevice
->dwCurrentQuietEndTime
;
1420 dwDuration
= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
;
1422 // set GAP and Next duration
1423 MACvSelectPage1(pDevice
->PortOffset
);
1424 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETGAP
, (unsigned short) dwGap
);
1425 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETDUR
, (unsigned short) dwDuration
);
1426 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_QUIETRPT
);
1427 MACvSelectPage0(pDevice
->PortOffset
);
1429 pDevice
->bQuietEnable
= true;
1430 pDevice
->dwCurrentQuietEndTime
= pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
;
1431 pDevice
->dwCurrentQuietEndTime
+= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
;
1432 if (pDevice
->sQuiet
[uCurrentQuietIndex
].byPeriod
== 0) {
1433 // not period disable current quiet element
1434 pDevice
->sQuiet
[uCurrentQuietIndex
].bEnable
= false;
1436 // set next period start time
1437 dwNextTime
= (unsigned long) pDevice
->sQuiet
[uCurrentQuietIndex
].byPeriod
;
1438 dwNextTime
*= pDevice
->wBeaconInterval
;
1439 pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
= dwNextTime
;
1441 if (pDevice
->dwCurrentQuietEndTime
> 0x80010000) {
1442 // decreament all time to avoid wrap around
1443 for(ii
=0;ii
<MAX_QUIET_COUNT
;ii
++) {
1444 if (pDevice
->sQuiet
[ii
].bEnable
== true) {
1445 pDevice
->sQuiet
[ii
].dwStartTime
-= 0x80000000;
1448 pDevice
->dwCurrentQuietEndTime
-= 0x80000000;
1457 * Set Local Power Constraint
1461 * hDeviceContext - device structure point
1465 * Return Value: none.
1469 CARDvSetPowerConstraint (
1470 void *pDeviceHandler
,
1471 unsigned char byChannel
,
1475 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1477 if (byChannel
> CB_MAX_CHANNEL_24G
) {
1478 if (pDevice
->bCountryInfo5G
== true) {
1479 pDevice
->abyLocalPwr
[byChannel
] = pDevice
->abyRegPwr
[byChannel
] - byPower
;
1482 if (pDevice
->bCountryInfo24G
== true) {
1483 pDevice
->abyLocalPwr
[byChannel
] = pDevice
->abyRegPwr
[byChannel
] - byPower
;
1492 * Set Local Power Constraint
1496 * hDeviceContext - device structure point
1500 * Return Value: none.
1504 CARDvGetPowerCapability (
1505 void *pDeviceHandler
,
1506 unsigned char *pbyMinPower
,
1507 unsigned char *pbyMaxPower
1510 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1511 unsigned char byDec
= 0;
1513 *pbyMaxPower
= pDevice
->abyOFDMDefaultPwr
[pDevice
->byCurrentCh
];
1514 byDec
= pDevice
->abyOFDMPwrTbl
[pDevice
->byCurrentCh
];
1515 if (pDevice
->byRFType
== RF_UW2452
) {
1521 *pbyMinPower
= pDevice
->abyOFDMDefaultPwr
[pDevice
->byCurrentCh
] - byDec
;
1527 * Get Current Tx Power
1531 * hDeviceContext - device structure point
1535 * Return Value: none.
1539 CARDbyGetTransmitPower (
1540 void *pDeviceHandler
1543 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1545 return (pDevice
->byCurPwrdBm
);
1551 void *pDeviceHandler
1554 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1558 // initialize TD index
1559 pDevice
->apTailTD
[0] = pDevice
->apCurrTD
[0] = &(pDevice
->apTD0Rings
[0]);
1560 pDevice
->apTailTD
[1] = pDevice
->apCurrTD
[1] = &(pDevice
->apTD1Rings
[0]);
1562 for (uu
= 0; uu
< TYPE_MAXTD
; uu
++)
1563 pDevice
->iTDUsed
[uu
] = 0;
1565 for (uu
= 0; uu
< pDevice
->sOpts
.nTxDescs
[0]; uu
++) {
1566 pCurrTD
= &(pDevice
->apTD0Rings
[uu
]);
1567 pCurrTD
->m_td0TD0
.f1Owner
= OWNED_BY_HOST
;
1568 // init all Tx Packet pointer to NULL
1570 for (uu
= 0; uu
< pDevice
->sOpts
.nTxDescs
[1]; uu
++) {
1571 pCurrTD
= &(pDevice
->apTD1Rings
[uu
]);
1572 pCurrTD
->m_td0TD0
.f1Owner
= OWNED_BY_HOST
;
1573 // init all Tx Packet pointer to NULL
1576 // set MAC TD pointer
1577 MACvSetCurrTXDescAddr(TYPE_TXDMA0
, pDevice
->PortOffset
,
1578 (pDevice
->td0_pool_dma
));
1580 MACvSetCurrTXDescAddr(TYPE_AC0DMA
, pDevice
->PortOffset
,
1581 (pDevice
->td1_pool_dma
));
1583 // set MAC Beacon TX pointer
1584 MACvSetCurrBCNTxDescAddr(pDevice
->PortOffset
,
1585 (pDevice
->tx_beacon_dma
));
1598 * pDevice - Pointer to the adapter
1602 * Return Value: none
1607 void *pDeviceHandler
1610 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1616 // initialize RD index
1617 pDevice
->pCurrRD
[0]=&(pDevice
->aRD0Ring
[0]);
1618 pDevice
->pCurrRD
[1]=&(pDevice
->aRD1Ring
[0]);
1620 // init state, all RD is chip's
1621 for (uu
= 0; uu
< pDevice
->sOpts
.nRxDescs0
; uu
++) {
1622 pDesc
=&(pDevice
->aRD0Ring
[uu
]);
1623 pDesc
->m_rd0RD0
.wResCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1624 pDesc
->m_rd0RD0
.f1Owner
=OWNED_BY_NIC
;
1625 pDesc
->m_rd1RD1
.wReqCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1628 // init state, all RD is chip's
1629 for (uu
= 0; uu
< pDevice
->sOpts
.nRxDescs1
; uu
++) {
1630 pDesc
=&(pDevice
->aRD1Ring
[uu
]);
1631 pDesc
->m_rd0RD0
.wResCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1632 pDesc
->m_rd0RD0
.f1Owner
=OWNED_BY_NIC
;
1633 pDesc
->m_rd1RD1
.wReqCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1636 pDevice
->cbDFCB
= CB_MAX_RX_FRAG
;
1637 pDevice
->cbFreeDFCB
= pDevice
->cbDFCB
;
1640 MACvRx0PerPktMode(pDevice
->PortOffset
);
1641 MACvRx1PerPktMode(pDevice
->PortOffset
);
1642 // set MAC RD pointer
1643 MACvSetCurrRx0DescAddr(pDevice
->PortOffset
,
1644 pDevice
->rd0_pool_dma
);
1646 MACvSetCurrRx1DescAddr(pDevice
->PortOffset
,
1647 pDevice
->rd1_pool_dma
);
1654 * Description: Get response Control frame rate in CCK mode
1658 * pDevice - The adapter to be set
1659 * wRateIdx - Receiving data rate
1663 * Return Value: response Control frame rate
1666 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler
, unsigned short wRateIdx
)
1668 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1669 unsigned int ui
= (unsigned int) wRateIdx
;
1671 while (ui
> RATE_1M
) {
1672 if (pDevice
->wBasicRate
& ((unsigned short)1 << ui
)) {
1673 return (unsigned short)ui
;
1677 return (unsigned short)RATE_1M
;
1681 * Description: Get response Control frame rate in OFDM mode
1685 * pDevice - The adapter to be set
1686 * wRateIdx - Receiving data rate
1690 * Return Value: response Control frame rate
1693 unsigned short CARDwGetOFDMControlRate (void *pDeviceHandler
, unsigned short wRateIdx
)
1695 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1696 unsigned int ui
= (unsigned int) wRateIdx
;
1698 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BASIC RATE: %X\n", pDevice
->wBasicRate
);
1700 if (!CARDbIsOFDMinBasicRate((void *)pDevice
)) {
1701 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx
);
1702 if (wRateIdx
> RATE_24M
)
1703 wRateIdx
= RATE_24M
;
1706 while (ui
> RATE_11M
) {
1707 if (pDevice
->wBasicRate
& ((unsigned short)1 << ui
)) {
1708 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CARDwGetOFDMControlRate : %d\n", ui
);
1709 return (unsigned short)ui
;
1713 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CARDwGetOFDMControlRate: 6M\n");
1714 return (unsigned short)RATE_24M
;
1719 * Description: Set RSPINF
1723 * pDevice - The adapter to be set
1727 * Return Value: None.
1730 void CARDvSetRSPINF (void *pDeviceHandler
, CARD_PHY_TYPE ePHYType
)
1732 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1733 unsigned char byServ
= 0x00, bySignal
= 0x00; //For CCK
1734 unsigned short wLen
= 0x0000;
1735 unsigned char byTxRate
, byRsvTime
; //For OFDM
1738 MACvSelectPage1(pDevice
->PortOffset
);
1741 BBvCaculateParameter(pDevice
,
1743 CARDwGetCCKControlRate((void *)pDevice
, RATE_1M
),
1750 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_1
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
1752 BBvCaculateParameter(pDevice
,
1754 CARDwGetCCKControlRate((void *)pDevice
, RATE_2M
),
1761 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_2
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
1763 BBvCaculateParameter(pDevice
,
1765 CARDwGetCCKControlRate((void *)pDevice
, RATE_5M
),
1772 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_5
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
1774 BBvCaculateParameter(pDevice
,
1776 CARDwGetCCKControlRate((void *)pDevice
, RATE_11M
),
1783 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_11
, MAKEDWORD(wLen
,MAKEWORD(bySignal
,byServ
)));
1785 s_vCaculateOFDMRParameter(RATE_6M
,
1789 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_6
, MAKEWORD(byTxRate
,byRsvTime
));
1791 s_vCaculateOFDMRParameter(RATE_9M
,
1795 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_9
, MAKEWORD(byTxRate
,byRsvTime
));
1797 s_vCaculateOFDMRParameter(RATE_12M
,
1801 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_12
, MAKEWORD(byTxRate
,byRsvTime
));
1803 s_vCaculateOFDMRParameter(RATE_18M
,
1807 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_18
, MAKEWORD(byTxRate
,byRsvTime
));
1809 s_vCaculateOFDMRParameter(RATE_24M
,
1813 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_24
, MAKEWORD(byTxRate
,byRsvTime
));
1815 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_36M
),
1819 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_36
, MAKEWORD(byTxRate
,byRsvTime
));
1821 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_48M
),
1825 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_48
, MAKEWORD(byTxRate
,byRsvTime
));
1827 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_54M
),
1831 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_54
, MAKEWORD(byTxRate
,byRsvTime
));
1834 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_54M
),
1838 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_72
, MAKEWORD(byTxRate
,byRsvTime
));
1840 MACvSelectPage0(pDevice
->PortOffset
);
1844 * Description: Update IFS
1848 * pDevice - The adapter to be set
1852 * Return Value: None.
1855 void vUpdateIFS (void *pDeviceHandler
)
1857 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1858 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1860 unsigned char byMaxMin
= 0;
1861 if (pDevice
->byPacketType
==PK_TYPE_11A
) {//0000 0000 0000 0000,11a
1862 pDevice
->uSlot
= C_SLOT_SHORT
;
1863 pDevice
->uSIFS
= C_SIFS_A
;
1864 pDevice
->uDIFS
= C_SIFS_A
+ 2*C_SLOT_SHORT
;
1865 pDevice
->uCwMin
= C_CWMIN_A
;
1868 else if (pDevice
->byPacketType
==PK_TYPE_11B
) {//0000 0001 0000 0000,11b
1869 pDevice
->uSlot
= C_SLOT_LONG
;
1870 pDevice
->uSIFS
= C_SIFS_BG
;
1871 pDevice
->uDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
1872 pDevice
->uCwMin
= C_CWMIN_B
;
1875 else { // PK_TYPE_11GA & PK_TYPE_11GB
1876 pDevice
->uSIFS
= C_SIFS_BG
;
1877 if (pDevice
->bShortSlotTime
) {
1878 pDevice
->uSlot
= C_SLOT_SHORT
;
1880 pDevice
->uSlot
= C_SLOT_LONG
;
1882 pDevice
->uDIFS
= C_SIFS_BG
+ 2*pDevice
->uSlot
;
1883 if (pDevice
->wBasicRate
& 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1884 pDevice
->uCwMin
= C_CWMIN_A
;
1888 pDevice
->uCwMin
= C_CWMIN_B
;
1893 pDevice
->uCwMax
= C_CWMAX
;
1894 pDevice
->uEIFS
= C_EIFS
;
1895 if (pDevice
->byRFType
== RF_RFMD2959
) {
1896 // bcs TX_PE will reserve 3 us
1897 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, (unsigned char)(pDevice
->uSIFS
- 3));
1898 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, (unsigned char)(pDevice
->uDIFS
- 3));
1900 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, (unsigned char)pDevice
->uSIFS
);
1901 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, (unsigned char)pDevice
->uDIFS
);
1903 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_EIFS
, (unsigned char)pDevice
->uEIFS
);
1904 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SLOT
, (unsigned char)pDevice
->uSlot
);
1905 byMaxMin
|= 0xA0;//1010 1111,C_CWMAX = 1023
1906 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_CWMAXMIN0
, (unsigned char)byMaxMin
);
1909 void CARDvUpdateBasicTopRate (void *pDeviceHandler
)
1911 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1912 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
1915 //Determines the highest basic rate.
1916 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
1917 if ( (pDevice
->wBasicRate
) & ((unsigned short)(1<<ii
)) ) {
1922 pDevice
->byTopOFDMBasicRate
= byTopOFDM
;
1924 for (ii
= RATE_11M
;; ii
--) {
1925 if ( (pDevice
->wBasicRate
) & ((unsigned short)(1<<ii
)) ) {
1932 pDevice
->byTopCCKBasicRate
= byTopCCK
;
1937 * Description: Set NIC Tx Basic Rate
1941 * pDevice - The adapter to be set
1942 * wBasicRate - Basic Rate to be set
1946 * Return Value: true if succeeded; false if failed.
1949 bool CARDbAddBasicRate (void *pDeviceHandler
, unsigned short wRateIdx
)
1951 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1952 unsigned short wRate
= (unsigned short)(1<<wRateIdx
);
1954 pDevice
->wBasicRate
|= wRate
;
1956 //Determines the highest basic rate.
1957 CARDvUpdateBasicTopRate((void *)pDevice
);
1962 bool CARDbIsOFDMinBasicRate (void *pDeviceHandler
)
1964 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1967 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
1968 if ((pDevice
->wBasicRate
) & ((unsigned short)(1<<ii
)))
1974 unsigned char CARDbyGetPktType (void *pDeviceHandler
)
1976 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1978 if (pDevice
->byBBType
== BB_TYPE_11A
|| pDevice
->byBBType
== BB_TYPE_11B
) {
1979 return (unsigned char)pDevice
->byBBType
;
1981 else if (CARDbIsOFDMinBasicRate((void *)pDevice
)) {
1982 return PK_TYPE_11GA
;
1985 return PK_TYPE_11GB
;
1990 * Description: Set NIC Loopback mode
1994 * pDevice - The adapter to be set
1995 * wLoopbackMode - Loopback mode to be set
1999 * Return Value: none
2002 void CARDvSetLoopbackMode (unsigned long dwIoBase
, unsigned short wLoopbackMode
)
2004 switch(wLoopbackMode
) {
2014 MACvSetLoopbackMode(dwIoBase
, LOBYTE(wLoopbackMode
));
2015 // set Baseband loopback
2020 * Description: Software Reset NIC
2024 * pDevice - The adapter to be reset
2028 * Return Value: none
2031 bool CARDbSoftwareReset (void *pDeviceHandler
)
2033 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
2036 if (!MACbSafeSoftwareReset(pDevice
->PortOffset
))
2044 * Description: Caculate TSF offset of two TSF input
2045 * Get TSF Offset from RxBCN's TSF and local TSF
2049 * pDevice - The adapter to be sync.
2050 * qwTSF1 - Rx BCN's TSF
2051 * qwTSF2 - Local TSF
2055 * Return Value: TSF Offset value
2058 QWORD
CARDqGetTSFOffset (unsigned char byRxRate
, QWORD qwTSF1
, QWORD qwTSF2
)
2061 unsigned short wRxBcnTSFOffst
= 0;
2063 HIDWORD(qwTSFOffset
) = 0;
2064 LODWORD(qwTSFOffset
) = 0;
2065 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
%MAX_RATE
];
2066 (qwTSF2
).u
.dwLowDword
+= (unsigned long)(wRxBcnTSFOffst
);
2067 if ((qwTSF2
).u
.dwLowDword
< (unsigned long)(wRxBcnTSFOffst
)) {
2068 (qwTSF2
).u
.dwHighDword
++;
2070 LODWORD(qwTSFOffset
) = LODWORD(qwTSF1
) - LODWORD(qwTSF2
);
2071 if (LODWORD(qwTSF1
) < LODWORD(qwTSF2
)) {
2073 HIDWORD(qwTSFOffset
) = HIDWORD(qwTSF1
) - HIDWORD(qwTSF2
) - 1 ;
2076 HIDWORD(qwTSFOffset
) = HIDWORD(qwTSF1
) - HIDWORD(qwTSF2
);
2078 return (qwTSFOffset
);
2083 * Description: Read NIC TSF counter
2084 * Get local TSF counter
2088 * pDevice - The adapter to be read
2090 * qwCurrTSF - Current TSF counter
2092 * Return Value: true if success; otherwise false
2095 bool CARDbGetCurrentTSF (unsigned long dwIoBase
, PQWORD pqwCurrTSF
)
2098 unsigned char byData
;
2100 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
2101 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
2102 VNSvInPortB(dwIoBase
+ MAC_REG_TFTCTL
, &byData
);
2103 if ( !(byData
& TFTCTL_TSFCNTRRD
))
2106 if (ww
== W_MAX_TIMEOUT
)
2108 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
, &LODWORD(*pqwCurrTSF
));
2109 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
+ 4, &HIDWORD(*pqwCurrTSF
));
2116 * Description: Read NIC TSF counter
2117 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2121 * qwTSF - Current TSF counter
2122 * wbeaconInterval - Beacon Interval
2124 * qwCurrTSF - Current TSF counter
2126 * Return Value: TSF value of next Beacon
2129 QWORD
CARDqGetNextTBTT (QWORD qwTSF
, unsigned short wBeaconInterval
)
2132 unsigned int uLowNextTBTT
;
2133 unsigned int uHighRemain
, uLowRemain
;
2134 unsigned int uBeaconInterval
;
2136 uBeaconInterval
= wBeaconInterval
* 1024;
2137 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2138 uLowNextTBTT
= (LODWORD(qwTSF
) >> 10) << 10;
2139 // low dword (mod) bcn
2140 uLowRemain
= (uLowNextTBTT
) % uBeaconInterval
;
2141 // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
2142 // % uBeaconInterval;
2143 // high dword (mod) bcn
2144 uHighRemain
= (((0xffffffff % uBeaconInterval
) + 1) * HIDWORD(qwTSF
))
2146 uLowRemain
= (uHighRemain
+ uLowRemain
) % uBeaconInterval
;
2147 uLowRemain
= uBeaconInterval
- uLowRemain
;
2149 // check if carry when add one beacon interval
2150 if ((~uLowNextTBTT
) < uLowRemain
)
2153 LODWORD(qwTSF
) = uLowNextTBTT
+ uLowRemain
;
2160 * Description: Set NIC TSF counter for first Beacon time
2161 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2165 * dwIoBase - IO Base
2166 * wBeaconInterval - Beacon Interval
2170 * Return Value: none
2173 void CARDvSetFirstNextTBTT (unsigned long dwIoBase
, unsigned short wBeaconInterval
)
2178 HIDWORD(qwNextTBTT
) = 0;
2179 LODWORD(qwNextTBTT
) = 0;
2180 CARDbGetCurrentTSF(dwIoBase
, &qwNextTBTT
); //Get Local TSF counter
2181 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
2183 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, LODWORD(qwNextTBTT
));
2184 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, HIDWORD(qwNextTBTT
));
2185 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
2186 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
2192 * Description: Sync NIC TSF counter for Beacon time
2193 * Get NEXTTBTT and write to HW
2197 * pDevice - The adapter to be set
2198 * qwTSF - Current TSF counter
2199 * wBeaconInterval - Beacon Interval
2203 * Return Value: none
2206 void CARDvUpdateNextTBTT (unsigned long dwIoBase
, QWORD qwTSF
, unsigned short wBeaconInterval
)
2209 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
2211 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, LODWORD(qwTSF
));
2212 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, HIDWORD(qwTSF
));
2213 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
2214 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Card:Update Next TBTT[%8xh:%8xh] \n",
2215 (unsigned int) HIDWORD(qwTSF
), (unsigned int) LODWORD(qwTSF
));