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 - 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
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.
71 #define C_SLOT_SHORT 9 // micro sec.
72 #define C_SLOT_LONG 20
74 #define C_CWMIN_A 15 // slot time
77 #define C_CWMAX 1023 // slot time
79 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
81 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
82 static unsigned char abyDefaultSuppRatesG
[] = {WLAN_EID_SUPP_RATES
, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
84 static unsigned char abyDefaultExtSuppRatesG
[] = {WLAN_EID_EXTSUPP_RATES
, 4, 0x0C, 0x12, 0x18, 0x60};
85 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
86 static unsigned char abyDefaultSuppRatesA
[] = {WLAN_EID_SUPP_RATES
, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
88 static unsigned char abyDefaultSuppRatesB
[] = {WLAN_EID_SUPP_RATES
, 4, 0x02, 0x04, 0x0B, 0x16};
90 /*--------------------- Static Variables --------------------------*/
92 const unsigned short cwRXBCNTSFOff
[MAX_RATE
] =
93 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
95 /*--------------------- Static Functions --------------------------*/
99 s_vCalculateOFDMRParameter(
100 unsigned char byRate
,
101 CARD_PHY_TYPE ePHYType
,
102 unsigned char *pbyTxRate
,
103 unsigned char *pbyRsvTime
106 /*--------------------- Export Functions --------------------------*/
109 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
114 * byPktType - Tx Packet type
116 * pbyTxRate - pointer to RSPINF TxRate field
117 * pbyRsvTime - pointer to RSPINF RsvTime field
124 s_vCalculateOFDMRParameter(
125 unsigned char byRate
,
126 CARD_PHY_TYPE ePHYType
,
127 unsigned char *pbyTxRate
,
128 unsigned char *pbyRsvTime
133 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
143 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
153 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
163 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
173 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
183 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
193 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
204 if (ePHYType
== PHY_TYPE_11A
) {//5GHZ
216 * Description: Set RSPINF
220 * pDevice - The adapter to be set
224 * Return Value: None.
229 s_vSetRSPINF(PSDevice pDevice
, CARD_PHY_TYPE ePHYType
, void *pvSupportRateIEs
, void *pvExtSupportRateIEs
)
231 unsigned char byServ
= 0, bySignal
= 0; // For CCK
232 unsigned short wLen
= 0;
233 unsigned char byTxRate
= 0, byRsvTime
= 0; // For OFDM
236 MACvSelectPage1(pDevice
->PortOffset
);
239 BBvCalculateParameter(pDevice
,
241 VNTWIFIbyGetACKTxRate(RATE_1M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
248 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_1
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
250 BBvCalculateParameter(pDevice
,
252 VNTWIFIbyGetACKTxRate(RATE_2M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
259 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_2
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
261 BBvCalculateParameter(pDevice
,
263 VNTWIFIbyGetACKTxRate(RATE_5M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
270 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_5
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
272 BBvCalculateParameter(pDevice
,
274 VNTWIFIbyGetACKTxRate(RATE_11M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
281 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_11
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
283 s_vCalculateOFDMRParameter(RATE_6M
,
287 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_6
, MAKEWORD(byTxRate
, byRsvTime
));
289 s_vCalculateOFDMRParameter(RATE_9M
,
293 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_9
, MAKEWORD(byTxRate
, byRsvTime
));
295 s_vCalculateOFDMRParameter(RATE_12M
,
299 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_12
, MAKEWORD(byTxRate
, byRsvTime
));
301 s_vCalculateOFDMRParameter(RATE_18M
,
305 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_18
, MAKEWORD(byTxRate
, byRsvTime
));
307 s_vCalculateOFDMRParameter(RATE_24M
,
311 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_24
, MAKEWORD(byTxRate
, byRsvTime
));
313 s_vCalculateOFDMRParameter(
314 VNTWIFIbyGetACKTxRate(RATE_36M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
318 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_36
, MAKEWORD(byTxRate
, byRsvTime
));
320 s_vCalculateOFDMRParameter(
321 VNTWIFIbyGetACKTxRate(RATE_48M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
325 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_48
, MAKEWORD(byTxRate
, byRsvTime
));
327 s_vCalculateOFDMRParameter(
328 VNTWIFIbyGetACKTxRate(RATE_54M
, pvSupportRateIEs
, pvExtSupportRateIEs
),
332 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_54
, MAKEWORD(byTxRate
, byRsvTime
));
334 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_72
, MAKEWORD(byTxRate
, byRsvTime
));
336 MACvSelectPage0(pDevice
->PortOffset
);
339 /*--------------------- Export Functions --------------------------*/
342 * Description: Card Send packet function
346 * pDeviceHandler - The adapter to be set
347 * pPacket - Packet buffer pointer
348 * ePktType - Packet type
349 * uLength - Packet length
353 * Return Value: true if succeeded; false if failed.
357 bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength) {
358 PSDevice pDevice = (PSDevice) pDeviceHandler;
359 if (ePktType == PKT_TYPE_802_11_MNG) {
360 return TXbTD0Send(pDevice, pPacket, uLength);
361 } else if (ePktType == PKT_TYPE_802_11_BCN) {
362 return TXbBeaconSend(pDevice, pPacket, uLength);
363 } if (ePktType == PKT_TYPE_802_11_DATA) {
364 return TXbTD1Send(pDevice, pPacket, uLength);
372 * Description: Get Card short preamble option value
376 * pDevice - The adapter to be set
380 * Return Value: true if short preamble; otherwise false
383 bool CARDbIsShortPreamble(void *pDeviceHandler
)
385 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
386 if (pDevice
->byPreambleType
== 0) {
393 * Description: Get Card short slot time option value
397 * pDevice - The adapter to be set
401 * Return Value: true if short slot time; otherwise false
404 bool CARDbIsShorSlotTime(void *pDeviceHandler
)
406 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
407 return pDevice
->bShortSlotTime
;
411 * Description: Update IFS
415 * pDevice - The adapter to be set
419 * Return Value: None.
422 bool CARDbSetPhyParameter(void *pDeviceHandler
, CARD_PHY_TYPE ePHYType
, unsigned short wCapInfo
, unsigned char byERPField
, void *pvSupportRateIEs
, void *pvExtSupportRateIEs
)
424 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
425 unsigned char byCWMaxMin
= 0;
426 unsigned char bySlot
= 0;
427 unsigned char bySIFS
= 0;
428 unsigned char byDIFS
= 0;
429 unsigned char byData
;
430 // PWLAN_IE_SUPP_RATES pRates = NULL;
431 PWLAN_IE_SUPP_RATES pSupportRates
= (PWLAN_IE_SUPP_RATES
) pvSupportRateIEs
;
432 PWLAN_IE_SUPP_RATES pExtSupportRates
= (PWLAN_IE_SUPP_RATES
) pvExtSupportRateIEs
;
434 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
435 if (ePHYType
== PHY_TYPE_11A
) {
436 if (pSupportRates
== NULL
) {
437 pSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultSuppRatesA
;
439 if (pDevice
->byRFType
== RF_AIROHA7230
) {
440 // AL7230 use single PAPE and connect to PAPE_2.4G
441 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11G
);
442 pDevice
->abyBBVGA
[0] = 0x20;
443 pDevice
->abyBBVGA
[2] = 0x10;
444 pDevice
->abyBBVGA
[3] = 0x10;
445 BBbReadEmbedded(pDevice
->PortOffset
, 0xE7, &byData
);
446 if (byData
== 0x1C) {
447 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
449 } else if (pDevice
->byRFType
== RF_UW2452
) {
450 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11A
);
451 pDevice
->abyBBVGA
[0] = 0x18;
452 BBbReadEmbedded(pDevice
->PortOffset
, 0xE7, &byData
);
453 if (byData
== 0x14) {
454 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
455 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE1, 0x57);
458 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11A
);
460 BBbWriteEmbedded(pDevice
->PortOffset
, 0x88, 0x03);
461 bySlot
= C_SLOT_SHORT
;
463 byDIFS
= C_SIFS_A
+ 2*C_SLOT_SHORT
;
465 } else if (ePHYType
== PHY_TYPE_11B
) {
466 if (pSupportRates
== NULL
) {
467 pSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultSuppRatesB
;
469 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11B
);
470 if (pDevice
->byRFType
== RF_AIROHA7230
) {
471 pDevice
->abyBBVGA
[0] = 0x1C;
472 pDevice
->abyBBVGA
[2] = 0x00;
473 pDevice
->abyBBVGA
[3] = 0x00;
474 BBbReadEmbedded(pDevice
->PortOffset
, 0xE7, &byData
);
475 if (byData
== 0x20) {
476 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
478 } else if (pDevice
->byRFType
== RF_UW2452
) {
479 pDevice
->abyBBVGA
[0] = 0x14;
480 BBbReadEmbedded(pDevice
->PortOffset
, 0xE7, &byData
);
481 if (byData
== 0x18) {
482 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
483 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE1, 0xD3);
486 BBbWriteEmbedded(pDevice
->PortOffset
, 0x88, 0x02);
487 bySlot
= C_SLOT_LONG
;
489 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
491 } else {// PK_TYPE_11GA & PK_TYPE_11GB
492 if (pSupportRates
== NULL
) {
493 pSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultSuppRatesG
;
494 pExtSupportRates
= (PWLAN_IE_SUPP_RATES
) abyDefaultExtSuppRatesG
;
496 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11G
);
497 if (pDevice
->byRFType
== RF_AIROHA7230
) {
498 pDevice
->abyBBVGA
[0] = 0x1C;
499 pDevice
->abyBBVGA
[2] = 0x00;
500 pDevice
->abyBBVGA
[3] = 0x00;
501 BBbReadEmbedded(pDevice
->PortOffset
, 0xE7, &byData
);
502 if (byData
== 0x20) {
503 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
505 } else if (pDevice
->byRFType
== RF_UW2452
) {
506 pDevice
->abyBBVGA
[0] = 0x14;
507 BBbReadEmbedded(pDevice
->PortOffset
, 0xE7, &byData
);
508 if (byData
== 0x18) {
509 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE7, pDevice
->abyBBVGA
[0]);
510 BBbWriteEmbedded(pDevice
->PortOffset
, 0xE1, 0xD3);
513 BBbWriteEmbedded(pDevice
->PortOffset
, 0x88, 0x08);
515 if (VNTWIFIbIsShortSlotTime(wCapInfo
)) {
516 bySlot
= C_SLOT_SHORT
;
517 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_SHORT
;
519 bySlot
= C_SLOT_LONG
;
520 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
522 if (VNTWIFIbyGetMaxSupportRate(pSupportRates
, pExtSupportRates
) > RATE_11M
) {
527 if (pDevice
->bProtectMode
!= VNTWIFIbIsProtectMode(byERPField
)) {
528 pDevice
->bProtectMode
= VNTWIFIbIsProtectMode(byERPField
);
529 if (pDevice
->bProtectMode
) {
530 MACvEnableProtectMD(pDevice
->PortOffset
);
532 MACvDisableProtectMD(pDevice
->PortOffset
);
535 if (pDevice
->bBarkerPreambleMd
!= VNTWIFIbIsBarkerMode(byERPField
)) {
536 pDevice
->bBarkerPreambleMd
= VNTWIFIbIsBarkerMode(byERPField
);
537 if (pDevice
->bBarkerPreambleMd
) {
538 MACvEnableBarkerPreambleMd(pDevice
->PortOffset
);
540 MACvDisableBarkerPreambleMd(pDevice
->PortOffset
);
545 if (pDevice
->byRFType
== RF_RFMD2959
) {
546 // bcs TX_PE will reserve 3 us
547 // hardware's processing time here is 2 us.
550 //{{ RobertYu: 20041202
551 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
552 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
555 if (pDevice
->bySIFS
!= bySIFS
) {
556 pDevice
->bySIFS
= bySIFS
;
557 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, pDevice
->bySIFS
);
559 if (pDevice
->byDIFS
!= byDIFS
) {
560 pDevice
->byDIFS
= byDIFS
;
561 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, pDevice
->byDIFS
);
563 if (pDevice
->byEIFS
!= C_EIFS
) {
564 pDevice
->byEIFS
= C_EIFS
;
565 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_EIFS
, pDevice
->byEIFS
);
567 if (pDevice
->bySlot
!= bySlot
) {
568 pDevice
->bySlot
= bySlot
;
569 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SLOT
, pDevice
->bySlot
);
570 if (pDevice
->bySlot
== C_SLOT_SHORT
) {
571 pDevice
->bShortSlotTime
= true;
573 pDevice
->bShortSlotTime
= false;
575 BBvSetShortSlotTime(pDevice
);
577 if (pDevice
->byCWMaxMin
!= byCWMaxMin
) {
578 pDevice
->byCWMaxMin
= byCWMaxMin
;
579 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_CWMAXMIN0
, pDevice
->byCWMaxMin
);
581 if (VNTWIFIbIsShortPreamble(wCapInfo
)) {
582 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
584 pDevice
->byPreambleType
= 0;
586 s_vSetRSPINF(pDevice
, ePHYType
, pSupportRates
, pExtSupportRates
);
587 pDevice
->eCurrentPHYType
= ePHYType
;
588 // set for NDIS OID_802_11SUPPORTED_RATES
593 * Description: Sync. TSF counter to BSS
594 * Get TSF offset and write to HW
598 * pDevice - The adapter to be sync.
599 * byRxRate - data rate of receive beacon
600 * qwBSSTimestamp - Rx BCN's TSF
601 * qwLocalTSF - Local TSF
608 bool CARDbUpdateTSF(void *pDeviceHandler
, unsigned char byRxRate
, QWORD qwBSSTimestamp
, QWORD qwLocalTSF
)
610 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
613 HIDWORD(qwTSFOffset
) = 0;
614 LODWORD(qwTSFOffset
) = 0;
616 if ((HIDWORD(qwBSSTimestamp
) != HIDWORD(qwLocalTSF
)) ||
617 (LODWORD(qwBSSTimestamp
) != LODWORD(qwLocalTSF
))) {
618 qwTSFOffset
= CARDqGetTSFOffset(byRxRate
, qwBSSTimestamp
, qwLocalTSF
);
620 // HW's TSF add TSF Offset reg
621 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_TSFOFST
, LODWORD(qwTSFOffset
));
622 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_TSFOFST
+ 4, HIDWORD(qwTSFOffset
));
623 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TSFSYNCEN
);
629 * Description: Set NIC TSF counter for first Beacon time
630 * Get NEXTTBTT from adjusted TSF and Beacon Interval
634 * pDevice - The adapter to be set.
635 * wBeaconInterval - Beacon Interval
639 * Return Value: true if succeed; otherwise false
642 bool CARDbSetBeaconPeriod(void *pDeviceHandler
, unsigned short wBeaconInterval
)
644 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
645 unsigned int uBeaconInterval
= 0;
646 unsigned int uLowNextTBTT
= 0;
647 unsigned int uHighRemain
= 0;
648 unsigned int uLowRemain
= 0;
651 HIDWORD(qwNextTBTT
) = 0;
652 LODWORD(qwNextTBTT
) = 0;
653 CARDbGetCurrentTSF(pDevice
->PortOffset
, &qwNextTBTT
); //Get Local TSF counter
654 uBeaconInterval
= wBeaconInterval
* 1024;
655 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
656 uLowNextTBTT
= (LODWORD(qwNextTBTT
) >> 10) << 10;
657 uLowRemain
= (uLowNextTBTT
) % uBeaconInterval
;
658 // high dword (mod) bcn
659 uHighRemain
= (((0xffffffff % uBeaconInterval
) + 1) * HIDWORD(qwNextTBTT
))
661 uLowRemain
= (uHighRemain
+ uLowRemain
) % uBeaconInterval
;
662 uLowRemain
= uBeaconInterval
- uLowRemain
;
664 // check if carry when add one beacon interval
665 if ((~uLowNextTBTT
) < uLowRemain
) {
666 HIDWORD(qwNextTBTT
)++;
668 LODWORD(qwNextTBTT
) = uLowNextTBTT
+ uLowRemain
;
670 // set HW beacon interval
671 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_BI
, wBeaconInterval
);
672 pDevice
->wBeaconInterval
= wBeaconInterval
;
674 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_NEXTTBTT
, LODWORD(qwNextTBTT
));
675 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_NEXTTBTT
+ 4, HIDWORD(qwNextTBTT
));
676 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
682 * Description: Card Stop Hardware Tx
686 * pDeviceHandler - The adapter to be set
687 * ePktType - Packet type to stop
691 * Return Value: true if all data packet complete; otherwise false.
694 bool CARDbStopTxPacket(void *pDeviceHandler
, CARD_PKT_TYPE ePktType
)
696 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
698 if (ePktType
== PKT_TYPE_802_11_ALL
) {
699 pDevice
->bStopBeacon
= true;
700 pDevice
->bStopTx0Pkt
= true;
701 pDevice
->bStopDataPkt
= true;
702 } else if (ePktType
== PKT_TYPE_802_11_BCN
) {
703 pDevice
->bStopBeacon
= true;
704 } else if (ePktType
== PKT_TYPE_802_11_MNG
) {
705 pDevice
->bStopTx0Pkt
= true;
706 } else if (ePktType
== PKT_TYPE_802_11_DATA
) {
707 pDevice
->bStopDataPkt
= true;
710 if (pDevice
->bStopBeacon
== true) {
711 if (pDevice
->bIsBeaconBufReadySet
== true) {
712 if (pDevice
->cbBeaconBufReadySetCnt
< WAIT_BEACON_TX_DOWN_TMO
) {
713 pDevice
->cbBeaconBufReadySetCnt
++;
717 pDevice
->bIsBeaconBufReadySet
= false;
718 pDevice
->cbBeaconBufReadySetCnt
= 0;
719 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
721 // wait all TD0 complete
722 if (pDevice
->bStopTx0Pkt
== true) {
723 if (pDevice
->iTDUsed
[TYPE_TXDMA0
] != 0) {
727 // wait all Data TD complete
728 if (pDevice
->bStopDataPkt
== true) {
729 if (pDevice
->iTDUsed
[TYPE_AC0DMA
] != 0) {
738 * Description: Card Start Hardware Tx
742 * pDeviceHandler - The adapter to be set
743 * ePktType - Packet type to start
747 * Return Value: true if success; false if failed.
750 bool CARDbStartTxPacket(void *pDeviceHandler
, CARD_PKT_TYPE ePktType
)
752 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
754 if (ePktType
== PKT_TYPE_802_11_ALL
) {
755 pDevice
->bStopBeacon
= false;
756 pDevice
->bStopTx0Pkt
= false;
757 pDevice
->bStopDataPkt
= false;
758 } else if (ePktType
== PKT_TYPE_802_11_BCN
) {
759 pDevice
->bStopBeacon
= false;
760 } else if (ePktType
== PKT_TYPE_802_11_MNG
) {
761 pDevice
->bStopTx0Pkt
= false;
762 } else if (ePktType
== PKT_TYPE_802_11_DATA
) {
763 pDevice
->bStopDataPkt
= false;
766 if ((pDevice
->bStopBeacon
== false) &&
767 (pDevice
->bBeaconBufReady
== true) &&
768 (pDevice
->eOPMode
== OP_MODE_ADHOC
)) {
769 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
776 * Description: Card Set BSSID value
780 * pDeviceHandler - The adapter to be set
781 * pbyBSSID - pointer to BSSID field
782 * bAdhoc - flag to indicate IBSS
786 * Return Value: true if success; false if failed.
789 bool CARDbSetBSSID(void *pDeviceHandler
, unsigned char *pbyBSSID
, CARD_OP_MODE eOPMode
)
791 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
793 MACvWriteBSSIDAddress(pDevice
->PortOffset
, pbyBSSID
);
794 memcpy(pDevice
->abyBSSID
, pbyBSSID
, WLAN_BSSID_LEN
);
795 if (eOPMode
== OP_MODE_ADHOC
) {
796 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_ADHOC
);
798 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_ADHOC
);
800 if (eOPMode
== OP_MODE_AP
) {
801 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_AP
);
803 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_AP
);
805 if (eOPMode
== OP_MODE_UNKNOWN
) {
806 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_BSSID
);
807 pDevice
->bBSSIDFilter
= false;
808 pDevice
->byRxMode
&= ~RCR_BSSID
;
809 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wcmd: rx_mode = %x\n", pDevice
->byRxMode
);
811 if (is_zero_ether_addr(pDevice
->abyBSSID
) == false) {
812 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_BSSID
);
813 pDevice
->bBSSIDFilter
= true;
814 pDevice
->byRxMode
|= RCR_BSSID
;
816 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wmgr: rx_mode = %x\n", pDevice
->byRxMode
);
818 // Adopt BSS state in Adapter Device Object
819 pDevice
->eOPMode
= eOPMode
;
824 * Description: Card indicate status
828 * pDeviceHandler - The adapter to be set
833 * Return Value: true if success; false if failed.
838 * Description: Save Assoc info. contain in assoc. response frame
842 * pDevice - The adapter to be set
843 * wCapabilityInfo - Capability information
844 * wStatus - Status code
846 * uLen - Length of IEs
847 * pbyIEs - pointer to IEs
851 * Return Value: true if succeed; otherwise false
854 bool CARDbSetTxDataRate(
855 void *pDeviceHandler
,
856 unsigned short wDataRate
859 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
861 pDevice
->wCurrentRate
= wDataRate
;
867 * Routine Description:
868 * Consider to power down when no more packets to tx or rx.
872 * pDevice - The adapter to be set
876 * Return Value: true if power down success; otherwise false
884 PSDevice pDevice
= (PSDevice
)pDeviceHandler
;
887 // check if already in Doze mode
888 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
))
892 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PSEN
);
894 // check if all TD are empty,
896 for (uIdx
= 0; uIdx
< TYPE_MAXTD
; uIdx
++) {
897 if (pDevice
->iTDUsed
[uIdx
] != 0)
901 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
902 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
907 * Description: Turn off Radio power
911 * pDevice - The adapter to be turned off
915 * Return Value: true if success; otherwise false
918 bool CARDbRadioPowerOff(void *pDeviceHandler
)
920 PSDevice pDevice
= (PSDevice
)pDeviceHandler
;
923 if (pDevice
->bRadioOff
== true)
926 switch (pDevice
->byRFType
) {
928 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_TXPEINV
);
929 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE1
);
934 case RF_AIROHA7230
: //RobertYu:20050104
935 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE2
);
936 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE3
);
941 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
943 BBvSetDeepSleep(pDevice
->PortOffset
, pDevice
->byLocalID
);
945 pDevice
->bRadioOff
= true;
946 //2007-0409-03,<Add> by chester
947 printk("chester power off\n");
948 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_GPIOCTL0
, LED_ACTSET
); //LED issue
953 * Description: Turn on Radio power
957 * pDevice - The adapter to be turned on
961 * Return Value: true if success; otherwise false
964 bool CARDbRadioPowerOn(void *pDeviceHandler
)
966 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
968 printk("chester power on\n");
969 if (pDevice
->bRadioControlOff
== true) {
970 if (pDevice
->bHWRadioOff
== true) printk("chester bHWRadioOff\n");
971 if (pDevice
->bRadioControlOff
== true) printk("chester bRadioControlOff\n");
974 if (pDevice
->bRadioOff
== false) {
975 printk("chester pbRadioOff\n");
978 BBvExitDeepSleep(pDevice
->PortOffset
, pDevice
->byLocalID
);
980 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
982 switch (pDevice
->byRFType
) {
984 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_TXPEINV
);
985 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE1
);
990 case RF_AIROHA7230
: //RobertYu:20050104
991 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, (SOFTPWRCTL_SWPE2
|
997 pDevice
->bRadioOff
= false;
998 // 2007-0409-03,<Add> by chester
999 printk("chester power on\n");
1000 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_GPIOCTL0
, LED_ACTSET
); //LED issue
1004 bool CARDbRemoveKey(void *pDeviceHandler
, unsigned char *pbyBSSID
)
1006 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1008 KeybRemoveAllKey(&(pDevice
->sKey
), pbyBSSID
, pDevice
->PortOffset
);
1015 * Add BSSID in PMKID Candidate list.
1019 * hDeviceContext - device structure point
1020 * pbyBSSID - BSSID address for adding
1021 * wRSNCap - BSS's RSN capability
1025 * Return Value: none.
1029 CARDbAdd_PMKID_Candidate(
1030 void *pDeviceHandler
,
1031 unsigned char *pbyBSSID
,
1033 unsigned short wRSNCap
1036 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1037 PPMKID_CANDIDATE pCandidateList
;
1038 unsigned int ii
= 0;
1040 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice
->gsPMKIDCandidate
.NumCandidates
);
1042 if (pDevice
->gsPMKIDCandidate
.NumCandidates
>= MAX_PMKIDLIST
) {
1043 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vFlush_PMKID_Candidate: 3\n");
1044 memset(&pDevice
->gsPMKIDCandidate
, 0, sizeof(SPMKIDCandidateEvent
));
1047 for (ii
= 0; ii
< 6; ii
++) {
1048 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02X ", *(pbyBSSID
+ ii
));
1050 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
1052 // Update Old Candidate
1053 for (ii
= 0; ii
< pDevice
->gsPMKIDCandidate
.NumCandidates
; ii
++) {
1054 pCandidateList
= &pDevice
->gsPMKIDCandidate
.CandidateList
[ii
];
1055 if (!memcmp(pCandidateList
->BSSID
, pbyBSSID
, ETH_ALEN
)) {
1056 if (bRSNCapExist
&& (wRSNCap
& BIT0
)) {
1057 pCandidateList
->Flags
|= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
1059 pCandidateList
->Flags
&= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
);
1066 pCandidateList
= &pDevice
->gsPMKIDCandidate
.CandidateList
[pDevice
->gsPMKIDCandidate
.NumCandidates
];
1067 if (bRSNCapExist
&& (wRSNCap
& BIT0
)) {
1068 pCandidateList
->Flags
|= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
1070 pCandidateList
->Flags
&= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
);
1072 memcpy(pCandidateList
->BSSID
, pbyBSSID
, ETH_ALEN
);
1073 pDevice
->gsPMKIDCandidate
.NumCandidates
++;
1074 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"NumCandidates:%d\n", (int)pDevice
->gsPMKIDCandidate
.NumCandidates
);
1079 CARDpGetCurrentAddress(
1080 void *pDeviceHandler
1083 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1085 return pDevice
->abyCurrentNetAddr
;
1091 * Start Spectrum Measure defined in 802.11h
1095 * hDeviceContext - device structure point
1099 * Return Value: none.
1104 void *pDeviceHandler
,
1105 void *pvMeasureEIDs
,
1106 unsigned int uNumOfMeasureEIDs
1109 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1110 PWLAN_IE_MEASURE_REQ pEID
= (PWLAN_IE_MEASURE_REQ
) pvMeasureEIDs
;
1113 bool bExpired
= true;
1114 unsigned short wDuration
= 0;
1116 if ((pEID
== NULL
) ||
1117 (uNumOfMeasureEIDs
== 0)) {
1120 CARDbGetCurrentTSF(pDevice
->PortOffset
, &qwCurrTSF
);
1121 if (pDevice
->bMeasureInProgress
== true) {
1122 pDevice
->bMeasureInProgress
= false;
1123 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, pDevice
->byOrgRCR
);
1124 MACvSelectPage1(pDevice
->PortOffset
);
1125 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
, pDevice
->dwOrgMAR0
);
1126 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR4
, pDevice
->dwOrgMAR4
);
1127 // clear measure control
1128 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_EN
);
1129 MACvSelectPage0(pDevice
->PortOffset
);
1130 set_channel(pDevice
, pDevice
->byOrgChannel
);
1131 MACvSelectPage1(pDevice
->PortOffset
);
1132 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
1133 MACvSelectPage0(pDevice
->PortOffset
);
1135 pDevice
->uNumOfMeasureEIDs
= uNumOfMeasureEIDs
;
1138 pDevice
->pCurrMeasureEID
= pEID
;
1140 pDevice
->uNumOfMeasureEIDs
--;
1142 if (pDevice
->byLocalID
> REV_ID_VT3253_B1
) {
1143 HIDWORD(qwStartTSF
) = HIDWORD(*((PQWORD
)(pDevice
->pCurrMeasureEID
->sReq
.abyStartTime
)));
1144 LODWORD(qwStartTSF
) = LODWORD(*((PQWORD
)(pDevice
->pCurrMeasureEID
->sReq
.abyStartTime
)));
1145 wDuration
= *((unsigned short *)(pDevice
->pCurrMeasureEID
->sReq
.abyDuration
));
1146 wDuration
+= 1; // 1 TU for channel switching
1148 if ((LODWORD(qwStartTSF
) == 0) && (HIDWORD(qwStartTSF
) == 0)) {
1149 // start immediately by setting start TSF == current TSF + 2 TU
1150 LODWORD(qwStartTSF
) = LODWORD(qwCurrTSF
) + 2048;
1151 HIDWORD(qwStartTSF
) = HIDWORD(qwCurrTSF
);
1152 if (LODWORD(qwCurrTSF
) > LODWORD(qwStartTSF
)) {
1153 HIDWORD(qwStartTSF
)++;
1158 // start at setting start TSF - 1TU(for channel switching)
1159 if (LODWORD(qwStartTSF
) < 1024) {
1160 HIDWORD(qwStartTSF
)--;
1162 LODWORD(qwStartTSF
) -= 1024;
1165 if ((HIDWORD(qwCurrTSF
) < HIDWORD(qwStartTSF
)) ||
1166 ((HIDWORD(qwCurrTSF
) == HIDWORD(qwStartTSF
)) &&
1167 (LODWORD(qwCurrTSF
) < LODWORD(qwStartTSF
)))
1172 VNTWIFIbMeasureReport(pDevice
->pMgmt
,
1174 pDevice
->pCurrMeasureEID
,
1176 pDevice
->byBasicMap
,
1177 pDevice
->byCCAFraction
,
1181 // hardware do not support measure
1182 VNTWIFIbMeasureReport(pDevice
->pMgmt
,
1184 pDevice
->pCurrMeasureEID
,
1185 MEASURE_MODE_INCAPABLE
,
1186 pDevice
->byBasicMap
,
1187 pDevice
->byCCAFraction
,
1191 } while (pDevice
->uNumOfMeasureEIDs
!= 0);
1194 MACvSelectPage1(pDevice
->PortOffset
);
1195 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MSRSTART
, LODWORD(qwStartTSF
));
1196 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MSRSTART
+ 4, HIDWORD(qwStartTSF
));
1197 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_MSRDURATION
, wDuration
);
1198 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_EN
);
1199 MACvSelectPage0(pDevice
->PortOffset
);
1201 // all measure start time expired we should complete action
1202 VNTWIFIbMeasureReport(pDevice
->pMgmt
,
1206 pDevice
->byBasicMap
,
1207 pDevice
->byCCAFraction
,
1217 * Do Channel Switch defined in 802.11h
1221 * hDeviceContext - device structure point
1225 * Return Value: none.
1230 void *pDeviceHandler
,
1231 unsigned char byMode
,
1232 unsigned char byNewChannel
,
1233 unsigned char byCount
1236 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1237 bool bResult
= true;
1240 bResult
= set_channel(pDevice
, byNewChannel
);
1241 VNTWIFIbChannelSwitch(pDevice
->pMgmt
, byNewChannel
);
1242 MACvSelectPage1(pDevice
->PortOffset
);
1243 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
1244 MACvSelectPage0(pDevice
->PortOffset
);
1247 pDevice
->byChannelSwitchCount
= byCount
;
1248 pDevice
->byNewChannel
= byNewChannel
;
1249 pDevice
->bChannelSwitch
= true;
1251 bResult
= CARDbStopTxPacket(pDevice
, PKT_TYPE_802_11_ALL
);
1259 * Handle Quiet EID defined in 802.11h
1263 * hDeviceContext - device structure point
1267 * Return Value: none.
1272 void *pDeviceHandler
,
1274 unsigned char byQuietCount
,
1275 unsigned char byQuietPeriod
,
1276 unsigned short wQuietDuration
,
1277 unsigned short wQuietOffset
1280 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1281 unsigned int ii
= 0;
1284 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
1285 for (ii
= 0; ii
< MAX_QUIET_COUNT
; ii
++) {
1286 pDevice
->sQuiet
[ii
].bEnable
= false;
1288 pDevice
->uQuietEnqueue
= 0;
1289 pDevice
->bEnableFirstQuiet
= false;
1290 pDevice
->bQuietEnable
= false;
1291 pDevice
->byQuietStartCount
= byQuietCount
;
1293 if (pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].bEnable
== false) {
1294 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].bEnable
= true;
1295 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].byPeriod
= byQuietPeriod
;
1296 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].wDuration
= wQuietDuration
;
1297 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].dwStartTime
= (unsigned long) byQuietCount
;
1298 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].dwStartTime
*= pDevice
->wBeaconInterval
;
1299 pDevice
->sQuiet
[pDevice
->uQuietEnqueue
].dwStartTime
+= wQuietOffset
;
1300 pDevice
->uQuietEnqueue
++;
1301 pDevice
->uQuietEnqueue
%= MAX_QUIET_COUNT
;
1302 if (pDevice
->byQuietStartCount
< byQuietCount
) {
1303 pDevice
->byQuietStartCount
= byQuietCount
;
1306 // we can not handle Quiet EID more
1314 * Do Quiet, It will be called by either ISR(after start)
1315 * or VNTWIFI(before start) so we do not need a SPINLOCK
1319 * hDeviceContext - device structure point
1323 * Return Value: none.
1328 void *pDeviceHandler
1331 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1332 unsigned int ii
= 0;
1333 unsigned long dwStartTime
= 0xFFFFFFFF;
1334 unsigned int uCurrentQuietIndex
= 0;
1335 unsigned long dwNextTime
= 0;
1336 unsigned long dwGap
= 0;
1337 unsigned long dwDuration
= 0;
1339 for (ii
= 0; ii
< MAX_QUIET_COUNT
; ii
++) {
1340 if ((pDevice
->sQuiet
[ii
].bEnable
== true) &&
1341 (dwStartTime
> pDevice
->sQuiet
[ii
].dwStartTime
)) {
1342 dwStartTime
= pDevice
->sQuiet
[ii
].dwStartTime
;
1343 uCurrentQuietIndex
= ii
;
1346 if (dwStartTime
== 0xFFFFFFFF) {
1348 pDevice
->bQuietEnable
= false;
1349 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
1351 if (pDevice
->bQuietEnable
== false) {
1353 pDevice
->byQuietStartCount
--;
1354 dwNextTime
= pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
;
1355 dwNextTime
%= pDevice
->wBeaconInterval
;
1356 MACvSelectPage1(pDevice
->PortOffset
);
1357 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETINIT
, (unsigned short) dwNextTime
);
1358 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETDUR
, (unsigned short) pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
);
1359 if (pDevice
->byQuietStartCount
== 0) {
1360 pDevice
->bEnableFirstQuiet
= false;
1361 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
1363 pDevice
->bEnableFirstQuiet
= true;
1365 MACvSelectPage0(pDevice
->PortOffset
);
1367 if (pDevice
->dwCurrentQuietEndTime
> pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
) {
1368 // overlap with previous Quiet
1369 dwGap
= pDevice
->dwCurrentQuietEndTime
- pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
;
1370 if (dwGap
>= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
) {
1371 // return false to indicate next quiet expired, should call this function again
1374 dwDuration
= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
- dwGap
;
1377 dwGap
= pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
- pDevice
->dwCurrentQuietEndTime
;
1378 dwDuration
= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
;
1380 // set GAP and Next duration
1381 MACvSelectPage1(pDevice
->PortOffset
);
1382 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETGAP
, (unsigned short) dwGap
);
1383 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_QUIETDUR
, (unsigned short) dwDuration
);
1384 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_QUIETRPT
);
1385 MACvSelectPage0(pDevice
->PortOffset
);
1387 pDevice
->bQuietEnable
= true;
1388 pDevice
->dwCurrentQuietEndTime
= pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
;
1389 pDevice
->dwCurrentQuietEndTime
+= pDevice
->sQuiet
[uCurrentQuietIndex
].wDuration
;
1390 if (pDevice
->sQuiet
[uCurrentQuietIndex
].byPeriod
== 0) {
1391 // not period disable current quiet element
1392 pDevice
->sQuiet
[uCurrentQuietIndex
].bEnable
= false;
1394 // set next period start time
1395 dwNextTime
= (unsigned long) pDevice
->sQuiet
[uCurrentQuietIndex
].byPeriod
;
1396 dwNextTime
*= pDevice
->wBeaconInterval
;
1397 pDevice
->sQuiet
[uCurrentQuietIndex
].dwStartTime
= dwNextTime
;
1399 if (pDevice
->dwCurrentQuietEndTime
> 0x80010000) {
1400 // decreament all time to avoid wrap around
1401 for (ii
= 0; ii
< MAX_QUIET_COUNT
; ii
++) {
1402 if (pDevice
->sQuiet
[ii
].bEnable
== true) {
1403 pDevice
->sQuiet
[ii
].dwStartTime
-= 0x80000000;
1406 pDevice
->dwCurrentQuietEndTime
-= 0x80000000;
1415 * Set Local Power Constraint
1419 * hDeviceContext - device structure point
1423 * Return Value: none.
1427 CARDvSetPowerConstraint(
1428 void *pDeviceHandler
,
1429 unsigned char byChannel
,
1433 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1435 if (byChannel
> CB_MAX_CHANNEL_24G
) {
1436 if (pDevice
->bCountryInfo5G
== true) {
1437 pDevice
->abyLocalPwr
[byChannel
] = pDevice
->abyRegPwr
[byChannel
] - byPower
;
1440 if (pDevice
->bCountryInfo24G
== true) {
1441 pDevice
->abyLocalPwr
[byChannel
] = pDevice
->abyRegPwr
[byChannel
] - byPower
;
1449 * Set Local Power Constraint
1453 * hDeviceContext - device structure point
1457 * Return Value: none.
1461 CARDvGetPowerCapability(
1462 void *pDeviceHandler
,
1463 unsigned char *pbyMinPower
,
1464 unsigned char *pbyMaxPower
1467 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1468 unsigned char byDec
= 0;
1470 *pbyMaxPower
= pDevice
->abyOFDMDefaultPwr
[pDevice
->byCurrentCh
];
1471 byDec
= pDevice
->abyOFDMPwrTbl
[pDevice
->byCurrentCh
];
1472 if (pDevice
->byRFType
== RF_UW2452
) {
1478 *pbyMinPower
= pDevice
->abyOFDMDefaultPwr
[pDevice
->byCurrentCh
] - byDec
;
1484 * Get Current Tx Power
1488 * hDeviceContext - device structure point
1492 * Return Value: none.
1496 CARDbyGetTransmitPower(
1497 void *pDeviceHandler
1500 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1502 return pDevice
->byCurPwrdBm
;
1508 void *pDeviceHandler
1511 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1515 // initialize TD index
1516 pDevice
->apTailTD
[0] = pDevice
->apCurrTD
[0] = &(pDevice
->apTD0Rings
[0]);
1517 pDevice
->apTailTD
[1] = pDevice
->apCurrTD
[1] = &(pDevice
->apTD1Rings
[0]);
1519 for (uu
= 0; uu
< TYPE_MAXTD
; uu
++)
1520 pDevice
->iTDUsed
[uu
] = 0;
1522 for (uu
= 0; uu
< pDevice
->sOpts
.nTxDescs
[0]; uu
++) {
1523 pCurrTD
= &(pDevice
->apTD0Rings
[uu
]);
1524 pCurrTD
->m_td0TD0
.f1Owner
= OWNED_BY_HOST
;
1525 // init all Tx Packet pointer to NULL
1527 for (uu
= 0; uu
< pDevice
->sOpts
.nTxDescs
[1]; uu
++) {
1528 pCurrTD
= &(pDevice
->apTD1Rings
[uu
]);
1529 pCurrTD
->m_td0TD0
.f1Owner
= OWNED_BY_HOST
;
1530 // init all Tx Packet pointer to NULL
1533 // set MAC TD pointer
1534 MACvSetCurrTXDescAddr(TYPE_TXDMA0
, pDevice
->PortOffset
,
1535 (pDevice
->td0_pool_dma
));
1537 MACvSetCurrTXDescAddr(TYPE_AC0DMA
, pDevice
->PortOffset
,
1538 (pDevice
->td1_pool_dma
));
1540 // set MAC Beacon TX pointer
1541 MACvSetCurrBCNTxDescAddr(pDevice
->PortOffset
,
1542 (pDevice
->tx_beacon_dma
));
1552 * pDevice - Pointer to the adapter
1556 * Return Value: none
1561 void *pDeviceHandler
1564 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1568 // initialize RD index
1569 pDevice
->pCurrRD
[0] = &(pDevice
->aRD0Ring
[0]);
1570 pDevice
->pCurrRD
[1] = &(pDevice
->aRD1Ring
[0]);
1572 // init state, all RD is chip's
1573 for (uu
= 0; uu
< pDevice
->sOpts
.nRxDescs0
; uu
++) {
1574 pDesc
= &(pDevice
->aRD0Ring
[uu
]);
1575 pDesc
->m_rd0RD0
.wResCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1576 pDesc
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
1577 pDesc
->m_rd1RD1
.wReqCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1580 // init state, all RD is chip's
1581 for (uu
= 0; uu
< pDevice
->sOpts
.nRxDescs1
; uu
++) {
1582 pDesc
= &(pDevice
->aRD1Ring
[uu
]);
1583 pDesc
->m_rd0RD0
.wResCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1584 pDesc
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
1585 pDesc
->m_rd1RD1
.wReqCount
= (unsigned short)(pDevice
->rx_buf_sz
);
1588 pDevice
->cbDFCB
= CB_MAX_RX_FRAG
;
1589 pDevice
->cbFreeDFCB
= pDevice
->cbDFCB
;
1592 MACvRx0PerPktMode(pDevice
->PortOffset
);
1593 MACvRx1PerPktMode(pDevice
->PortOffset
);
1594 // set MAC RD pointer
1595 MACvSetCurrRx0DescAddr(pDevice
->PortOffset
,
1596 pDevice
->rd0_pool_dma
);
1598 MACvSetCurrRx1DescAddr(pDevice
->PortOffset
,
1599 pDevice
->rd1_pool_dma
);
1603 * Description: Get response Control frame rate in CCK mode
1607 * pDevice - The adapter to be set
1608 * wRateIdx - Receiving data rate
1612 * Return Value: response Control frame rate
1615 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler
, unsigned short wRateIdx
)
1617 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1618 unsigned int ui
= (unsigned int) wRateIdx
;
1620 while (ui
> RATE_1M
) {
1621 if (pDevice
->wBasicRate
& ((unsigned short)1 << ui
)) {
1622 return (unsigned short)ui
;
1626 return (unsigned short)RATE_1M
;
1630 * Description: Get response Control frame rate in OFDM mode
1634 * pDevice - The adapter to be set
1635 * wRateIdx - Receiving data rate
1639 * Return Value: response Control frame rate
1642 unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler
, unsigned short wRateIdx
)
1644 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1645 unsigned int ui
= (unsigned int) wRateIdx
;
1647 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BASIC RATE: %X\n", pDevice
->wBasicRate
);
1649 if (!CARDbIsOFDMinBasicRate((void *)pDevice
)) {
1650 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx
);
1651 if (wRateIdx
> RATE_24M
)
1652 wRateIdx
= RATE_24M
;
1655 while (ui
> RATE_11M
) {
1656 if (pDevice
->wBasicRate
& ((unsigned short)1 << ui
)) {
1657 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CARDwGetOFDMControlRate : %d\n", ui
);
1658 return (unsigned short)ui
;
1662 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CARDwGetOFDMControlRate: 6M\n");
1663 return (unsigned short)RATE_24M
;
1667 * Description: Set RSPINF
1671 * pDevice - The adapter to be set
1675 * Return Value: None.
1678 void CARDvSetRSPINF(void *pDeviceHandler
, CARD_PHY_TYPE ePHYType
)
1680 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1681 unsigned char byServ
= 0x00, bySignal
= 0x00; //For CCK
1682 unsigned short wLen
= 0x0000;
1683 unsigned char byTxRate
, byRsvTime
; //For OFDM
1686 MACvSelectPage1(pDevice
->PortOffset
);
1689 BBvCalculateParameter(pDevice
,
1691 CARDwGetCCKControlRate((void *)pDevice
, RATE_1M
),
1698 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_1
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
1700 BBvCalculateParameter(pDevice
,
1702 CARDwGetCCKControlRate((void *)pDevice
, RATE_2M
),
1709 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_2
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
1711 BBvCalculateParameter(pDevice
,
1713 CARDwGetCCKControlRate((void *)pDevice
, RATE_5M
),
1720 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_5
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
1722 BBvCalculateParameter(pDevice
,
1724 CARDwGetCCKControlRate((void *)pDevice
, RATE_11M
),
1731 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_11
, MAKEDWORD(wLen
, MAKEWORD(bySignal
, byServ
)));
1733 s_vCalculateOFDMRParameter(RATE_6M
,
1737 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_6
, MAKEWORD(byTxRate
, byRsvTime
));
1739 s_vCalculateOFDMRParameter(RATE_9M
,
1743 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_9
, MAKEWORD(byTxRate
, byRsvTime
));
1745 s_vCalculateOFDMRParameter(RATE_12M
,
1749 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_12
, MAKEWORD(byTxRate
, byRsvTime
));
1751 s_vCalculateOFDMRParameter(RATE_18M
,
1755 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_18
, MAKEWORD(byTxRate
, byRsvTime
));
1757 s_vCalculateOFDMRParameter(RATE_24M
,
1761 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_24
, MAKEWORD(byTxRate
, byRsvTime
));
1763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_36M
),
1767 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_36
, MAKEWORD(byTxRate
, byRsvTime
));
1769 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_48M
),
1773 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_48
, MAKEWORD(byTxRate
, byRsvTime
));
1775 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_54M
),
1779 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_54
, MAKEWORD(byTxRate
, byRsvTime
));
1782 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_54M
),
1786 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_72
, MAKEWORD(byTxRate
, byRsvTime
));
1788 MACvSelectPage0(pDevice
->PortOffset
);
1792 * Description: Update IFS
1796 * pDevice - The adapter to be set
1800 * Return Value: None.
1803 void vUpdateIFS(void *pDeviceHandler
)
1805 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1806 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1808 unsigned char byMaxMin
= 0;
1809 if (pDevice
->byPacketType
== PK_TYPE_11A
) {//0000 0000 0000 0000,11a
1810 pDevice
->uSlot
= C_SLOT_SHORT
;
1811 pDevice
->uSIFS
= C_SIFS_A
;
1812 pDevice
->uDIFS
= C_SIFS_A
+ 2*C_SLOT_SHORT
;
1813 pDevice
->uCwMin
= C_CWMIN_A
;
1815 } else if (pDevice
->byPacketType
== PK_TYPE_11B
) {//0000 0001 0000 0000,11b
1816 pDevice
->uSlot
= C_SLOT_LONG
;
1817 pDevice
->uSIFS
= C_SIFS_BG
;
1818 pDevice
->uDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
1819 pDevice
->uCwMin
= C_CWMIN_B
;
1821 } else { // PK_TYPE_11GA & PK_TYPE_11GB
1822 pDevice
->uSIFS
= C_SIFS_BG
;
1823 if (pDevice
->bShortSlotTime
) {
1824 pDevice
->uSlot
= C_SLOT_SHORT
;
1826 pDevice
->uSlot
= C_SLOT_LONG
;
1828 pDevice
->uDIFS
= C_SIFS_BG
+ 2*pDevice
->uSlot
;
1829 if (pDevice
->wBasicRate
& 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1830 pDevice
->uCwMin
= C_CWMIN_A
;
1833 pDevice
->uCwMin
= C_CWMIN_B
;
1838 pDevice
->uCwMax
= C_CWMAX
;
1839 pDevice
->uEIFS
= C_EIFS
;
1840 if (pDevice
->byRFType
== RF_RFMD2959
) {
1841 // bcs TX_PE will reserve 3 us
1842 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, (unsigned char)(pDevice
->uSIFS
- 3));
1843 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, (unsigned char)(pDevice
->uDIFS
- 3));
1845 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, (unsigned char)pDevice
->uSIFS
);
1846 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, (unsigned char)pDevice
->uDIFS
);
1848 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_EIFS
, (unsigned char)pDevice
->uEIFS
);
1849 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SLOT
, (unsigned char)pDevice
->uSlot
);
1850 byMaxMin
|= 0xA0;//1010 1111,C_CWMAX = 1023
1851 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_CWMAXMIN0
, (unsigned char)byMaxMin
);
1854 void CARDvUpdateBasicTopRate(void *pDeviceHandler
)
1856 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1857 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
1860 //Determines the highest basic rate.
1861 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
1862 if ((pDevice
->wBasicRate
) & ((unsigned short)(1<<ii
))) {
1867 pDevice
->byTopOFDMBasicRate
= byTopOFDM
;
1869 for (ii
= RATE_11M
;; ii
--) {
1870 if ((pDevice
->wBasicRate
) & ((unsigned short)(1<<ii
))) {
1877 pDevice
->byTopCCKBasicRate
= byTopCCK
;
1881 * Description: Set NIC Tx Basic Rate
1885 * pDevice - The adapter to be set
1886 * wBasicRate - Basic Rate to be set
1890 * Return Value: true if succeeded; false if failed.
1893 bool CARDbAddBasicRate(void *pDeviceHandler
, unsigned short wRateIdx
)
1895 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1896 unsigned short wRate
= (unsigned short)(1<<wRateIdx
);
1898 pDevice
->wBasicRate
|= wRate
;
1900 //Determines the highest basic rate.
1901 CARDvUpdateBasicTopRate((void *)pDevice
);
1906 bool CARDbIsOFDMinBasicRate(void *pDeviceHandler
)
1908 PSDevice pDevice
= (PSDevice
)pDeviceHandler
;
1911 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
1912 if ((pDevice
->wBasicRate
) & ((unsigned short)(1 << ii
)))
1918 unsigned char CARDbyGetPktType(void *pDeviceHandler
)
1920 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1922 if (pDevice
->byBBType
== BB_TYPE_11A
|| pDevice
->byBBType
== BB_TYPE_11B
) {
1923 return (unsigned char)pDevice
->byBBType
;
1924 } else if (CARDbIsOFDMinBasicRate((void *)pDevice
)) {
1925 return PK_TYPE_11GA
;
1927 return PK_TYPE_11GB
;
1932 * Description: Set NIC Loopback mode
1936 * pDevice - The adapter to be set
1937 * wLoopbackMode - Loopback mode to be set
1941 * Return Value: none
1944 void CARDvSetLoopbackMode(unsigned long dwIoBase
, unsigned short wLoopbackMode
)
1946 switch (wLoopbackMode
) {
1956 MACvSetLoopbackMode(dwIoBase
, LOBYTE(wLoopbackMode
));
1957 // set Baseband loopback
1961 * Description: Software Reset NIC
1965 * pDevice - The adapter to be reset
1969 * Return Value: none
1972 bool CARDbSoftwareReset(void *pDeviceHandler
)
1974 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
1977 if (!MACbSafeSoftwareReset(pDevice
->PortOffset
))
1984 * Description: Calculate TSF offset of two TSF input
1985 * Get TSF Offset from RxBCN's TSF and local TSF
1989 * pDevice - The adapter to be sync.
1990 * qwTSF1 - Rx BCN's TSF
1991 * qwTSF2 - Local TSF
1995 * Return Value: TSF Offset value
1998 QWORD
CARDqGetTSFOffset(unsigned char byRxRate
, QWORD qwTSF1
, QWORD qwTSF2
)
2001 unsigned short wRxBcnTSFOffst
= 0;
2003 HIDWORD(qwTSFOffset
) = 0;
2004 LODWORD(qwTSFOffset
) = 0;
2005 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
%MAX_RATE
];
2006 (qwTSF2
).u
.dwLowDword
+= (unsigned long)(wRxBcnTSFOffst
);
2007 if ((qwTSF2
).u
.dwLowDword
< (unsigned long)(wRxBcnTSFOffst
)) {
2008 (qwTSF2
).u
.dwHighDword
++;
2010 LODWORD(qwTSFOffset
) = LODWORD(qwTSF1
) - LODWORD(qwTSF2
);
2011 if (LODWORD(qwTSF1
) < LODWORD(qwTSF2
)) {
2013 HIDWORD(qwTSFOffset
) = HIDWORD(qwTSF1
) - HIDWORD(qwTSF2
) - 1;
2015 HIDWORD(qwTSFOffset
) = HIDWORD(qwTSF1
) - HIDWORD(qwTSF2
);
2021 * Description: Read NIC TSF counter
2022 * Get local TSF counter
2026 * pDevice - The adapter to be read
2028 * qwCurrTSF - Current TSF counter
2030 * Return Value: true if success; otherwise false
2033 bool CARDbGetCurrentTSF(unsigned long dwIoBase
, PQWORD pqwCurrTSF
)
2036 unsigned char byData
;
2038 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
2039 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
2040 VNSvInPortB(dwIoBase
+ MAC_REG_TFTCTL
, &byData
);
2041 if (!(byData
& TFTCTL_TSFCNTRRD
))
2044 if (ww
== W_MAX_TIMEOUT
)
2046 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
, &LODWORD(*pqwCurrTSF
));
2047 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
+ 4, &HIDWORD(*pqwCurrTSF
));
2053 * Description: Read NIC TSF counter
2054 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2058 * qwTSF - Current TSF counter
2059 * wbeaconInterval - Beacon Interval
2061 * qwCurrTSF - Current TSF counter
2063 * Return Value: TSF value of next Beacon
2066 QWORD
CARDqGetNextTBTT(QWORD qwTSF
, unsigned short wBeaconInterval
)
2068 unsigned int uLowNextTBTT
;
2069 unsigned int uHighRemain
, uLowRemain
;
2070 unsigned int uBeaconInterval
;
2072 uBeaconInterval
= wBeaconInterval
* 1024;
2073 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
2074 uLowNextTBTT
= (LODWORD(qwTSF
) >> 10) << 10;
2075 // low dword (mod) bcn
2076 uLowRemain
= (uLowNextTBTT
) % uBeaconInterval
;
2077 // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
2078 // % uBeaconInterval;
2079 // high dword (mod) bcn
2080 uHighRemain
= (((0xffffffff % uBeaconInterval
) + 1) * HIDWORD(qwTSF
))
2082 uLowRemain
= (uHighRemain
+ uLowRemain
) % uBeaconInterval
;
2083 uLowRemain
= uBeaconInterval
- uLowRemain
;
2085 // check if carry when add one beacon interval
2086 if ((~uLowNextTBTT
) < uLowRemain
)
2089 LODWORD(qwTSF
) = uLowNextTBTT
+ uLowRemain
;
2095 * Description: Set NIC TSF counter for first Beacon time
2096 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2100 * dwIoBase - IO Base
2101 * wBeaconInterval - Beacon Interval
2105 * Return Value: none
2108 void CARDvSetFirstNextTBTT(unsigned long dwIoBase
, unsigned short wBeaconInterval
)
2112 HIDWORD(qwNextTBTT
) = 0;
2113 LODWORD(qwNextTBTT
) = 0;
2114 CARDbGetCurrentTSF(dwIoBase
, &qwNextTBTT
); //Get Local TSF counter
2115 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
2117 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, LODWORD(qwNextTBTT
));
2118 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, HIDWORD(qwNextTBTT
));
2119 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
2120 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
2125 * Description: Sync NIC TSF counter for Beacon time
2126 * Get NEXTTBTT and write to HW
2130 * pDevice - The adapter to be set
2131 * qwTSF - Current TSF counter
2132 * wBeaconInterval - Beacon Interval
2136 * Return Value: none
2139 void CARDvUpdateNextTBTT(unsigned long dwIoBase
, QWORD qwTSF
, unsigned short wBeaconInterval
)
2141 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
2143 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, LODWORD(qwTSF
));
2144 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, HIDWORD(qwTSF
));
2145 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
2146 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Card:Update Next TBTT[%8xh:%8xh] \n",
2147 (unsigned int) HIDWORD(qwTSF
), (unsigned int) LODWORD(qwTSF
));