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 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
28 * CARDvSetLoopbackMode - Set Loopback mode
29 * CARDbSoftwareReset - Sortware reset NIC
30 * CARDqGetTSFOffset - Calculate TSFOffset
31 * CARDbGetCurrentTSF - Read Current NIC TSF counter
32 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
33 * CARDvSetFirstNextTBTT - Set NIC Beacon time
34 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
35 * CARDbRadioPowerOff - Turn Off NIC Radio Power
36 * CARDbRadioPowerOn - Turn On NIC Radio Power
37 * CARDbSetWEPMode - Set NIC Wep mode
38 * CARDbSetTxPower - Set NIC tx power
41 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
42 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
43 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
60 /*--------------------- Static Definitions -------------------------*/
62 #define C_SIFS_A 16 // micro sec.
65 #define C_EIFS 80 // micro sec.
67 #define C_SLOT_SHORT 9 // micro sec.
68 #define C_SLOT_LONG 20
70 #define C_CWMIN_A 15 // slot time
73 #define C_CWMAX 1023 // slot time
75 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
77 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
78 static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
80 static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
81 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
82 static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
84 static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
86 /*--------------------- Static Variables --------------------------*/
88 static const unsigned short cwRXBCNTSFOff[MAX_RATE] =
89 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
91 /*--------------------- Static Functions --------------------------*/
95 s_vCalculateOFDMRParameter(
97 CARD_PHY_TYPE ePHYType,
98 unsigned char *pbyTxRate,
99 unsigned char *pbyRsvTime
102 /*--------------------- Export Functions --------------------------*/
105 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
110 * byPktType - Tx Packet type
112 * pbyTxRate - pointer to RSPINF TxRate field
113 * pbyRsvTime - pointer to RSPINF RsvTime field
120 s_vCalculateOFDMRParameter(
121 unsigned char byRate,
122 CARD_PHY_TYPE ePHYType,
123 unsigned char *pbyTxRate,
124 unsigned char *pbyRsvTime
129 if (ePHYType == PHY_TYPE_11A) {//5GHZ
139 if (ePHYType == PHY_TYPE_11A) {//5GHZ
149 if (ePHYType == PHY_TYPE_11A) {//5GHZ
159 if (ePHYType == PHY_TYPE_11A) {//5GHZ
169 if (ePHYType == PHY_TYPE_11A) {//5GHZ
179 if (ePHYType == PHY_TYPE_11A) {//5GHZ
189 if (ePHYType == PHY_TYPE_11A) {//5GHZ
200 if (ePHYType == PHY_TYPE_11A) {//5GHZ
212 * Description: Set RSPINF
216 * pDevice - The adapter to be set
220 * Return Value: None.
225 s_vSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
226 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
228 unsigned char byServ = 0, bySignal = 0; // For CCK
229 unsigned short wLen = 0;
230 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
233 MACvSelectPage1(pDevice->PortOffset);
236 BBvCalculateParameter(pDevice,
238 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
245 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
247 BBvCalculateParameter(pDevice,
249 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
256 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
258 BBvCalculateParameter(pDevice,
260 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
267 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
269 BBvCalculateParameter(pDevice,
271 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
278 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
280 s_vCalculateOFDMRParameter(RATE_6M,
284 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
286 s_vCalculateOFDMRParameter(RATE_9M,
290 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
292 s_vCalculateOFDMRParameter(RATE_12M,
296 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
298 s_vCalculateOFDMRParameter(RATE_18M,
302 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
304 s_vCalculateOFDMRParameter(RATE_24M,
308 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
310 s_vCalculateOFDMRParameter(
311 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
315 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
317 s_vCalculateOFDMRParameter(
318 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
322 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
324 s_vCalculateOFDMRParameter(
325 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
329 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
331 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
333 MACvSelectPage0(pDevice->PortOffset);
336 /*--------------------- Export Functions --------------------------*/
339 * Description: Get Card short preamble option value
343 * pDevice - The adapter to be set
347 * Return Value: true if short preamble; otherwise false
350 bool CARDbIsShortPreamble(struct vnt_private *pDevice)
353 if (pDevice->byPreambleType == 0)
360 * Description: Get Card short slot time option value
364 * pDevice - The adapter to be set
368 * Return Value: true if short slot time; otherwise false
371 bool CARDbIsShorSlotTime(struct vnt_private *pDevice)
374 return pDevice->bShortSlotTime;
378 * Description: Update IFS
382 * pDevice - The adapter to be set
386 * Return Value: None.
389 bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
390 unsigned short wCapInfo, unsigned char byERPField,
391 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
393 unsigned char byCWMaxMin = 0;
394 unsigned char bySlot = 0;
395 unsigned char bySIFS = 0;
396 unsigned char byDIFS = 0;
397 unsigned char byData;
398 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
399 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
401 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
402 if (ePHYType == PHY_TYPE_11A) {
403 if (pSupportRates == NULL)
404 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
406 if (pDevice->byRFType == RF_AIROHA7230) {
407 // AL7230 use single PAPE and connect to PAPE_2.4G
408 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
409 pDevice->abyBBVGA[0] = 0x20;
410 pDevice->abyBBVGA[2] = 0x10;
411 pDevice->abyBBVGA[3] = 0x10;
412 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
414 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
416 } else if (pDevice->byRFType == RF_UW2452) {
417 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
418 pDevice->abyBBVGA[0] = 0x18;
419 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
420 if (byData == 0x14) {
421 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
422 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
425 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
427 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
428 bySlot = C_SLOT_SHORT;
430 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
432 } else if (ePHYType == PHY_TYPE_11B) {
433 if (pSupportRates == NULL)
434 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
436 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
437 if (pDevice->byRFType == RF_AIROHA7230) {
438 pDevice->abyBBVGA[0] = 0x1C;
439 pDevice->abyBBVGA[2] = 0x00;
440 pDevice->abyBBVGA[3] = 0x00;
441 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
443 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
445 } else if (pDevice->byRFType == RF_UW2452) {
446 pDevice->abyBBVGA[0] = 0x14;
447 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
448 if (byData == 0x18) {
449 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
450 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
453 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
454 bySlot = C_SLOT_LONG;
456 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
458 } else {// PK_TYPE_11GA & PK_TYPE_11GB
459 if (pSupportRates == NULL) {
460 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
461 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
463 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
464 if (pDevice->byRFType == RF_AIROHA7230) {
465 pDevice->abyBBVGA[0] = 0x1C;
466 pDevice->abyBBVGA[2] = 0x00;
467 pDevice->abyBBVGA[3] = 0x00;
468 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
470 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
472 } else if (pDevice->byRFType == RF_UW2452) {
473 pDevice->abyBBVGA[0] = 0x14;
474 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
475 if (byData == 0x18) {
476 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
477 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
480 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
482 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
483 bySlot = C_SLOT_SHORT;
484 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
486 bySlot = C_SLOT_LONG;
487 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
489 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M)
494 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
495 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
496 if (pDevice->bProtectMode)
497 MACvEnableProtectMD(pDevice->PortOffset);
499 MACvDisableProtectMD(pDevice->PortOffset);
502 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
503 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
504 if (pDevice->bBarkerPreambleMd)
505 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
507 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
511 if (pDevice->byRFType == RF_RFMD2959) {
512 // bcs TX_PE will reserve 3 us
513 // hardware's processing time here is 2 us.
516 //{{ RobertYu: 20041202
517 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
518 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
521 if (pDevice->bySIFS != bySIFS) {
522 pDevice->bySIFS = bySIFS;
523 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
525 if (pDevice->byDIFS != byDIFS) {
526 pDevice->byDIFS = byDIFS;
527 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
529 if (pDevice->byEIFS != C_EIFS) {
530 pDevice->byEIFS = C_EIFS;
531 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
533 if (pDevice->bySlot != bySlot) {
534 pDevice->bySlot = bySlot;
535 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
536 if (pDevice->bySlot == C_SLOT_SHORT)
537 pDevice->bShortSlotTime = true;
539 pDevice->bShortSlotTime = false;
541 BBvSetShortSlotTime(pDevice);
543 if (pDevice->byCWMaxMin != byCWMaxMin) {
544 pDevice->byCWMaxMin = byCWMaxMin;
545 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
547 if (VNTWIFIbIsShortPreamble(wCapInfo))
548 pDevice->byPreambleType = pDevice->byShortPreamble;
550 pDevice->byPreambleType = 0;
552 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
553 pDevice->eCurrentPHYType = ePHYType;
554 // set for NDIS OID_802_11SUPPORTED_RATES
559 * Description: Sync. TSF counter to BSS
560 * Get TSF offset and write to HW
564 * pDevice - The adapter to be sync.
565 * byRxRate - data rate of receive beacon
566 * qwBSSTimestamp - Rx BCN's TSF
567 * qwLocalTSF - Local TSF
574 bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
575 u64 qwBSSTimestamp, u64 qwLocalTSF)
579 if (qwBSSTimestamp != qwLocalTSF) {
580 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
582 // HW's TSF add TSF Offset reg
583 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
584 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
585 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
591 * Description: Set NIC TSF counter for first Beacon time
592 * Get NEXTTBTT from adjusted TSF and Beacon Interval
596 * pDevice - The adapter to be set.
597 * wBeaconInterval - Beacon Interval
601 * Return Value: true if succeed; otherwise false
604 bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
605 unsigned short wBeaconInterval)
609 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
611 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
613 // set HW beacon interval
614 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
615 pDevice->wBeaconInterval = wBeaconInterval;
617 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
618 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
619 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
625 * Description: Card Stop Hardware Tx
629 * pDeviceHandler - The adapter to be set
630 * ePktType - Packet type to stop
634 * Return Value: true if all data packet complete; otherwise false.
637 bool CARDbStopTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
640 if (ePktType == PKT_TYPE_802_11_ALL) {
641 pDevice->bStopBeacon = true;
642 pDevice->bStopTx0Pkt = true;
643 pDevice->bStopDataPkt = true;
644 } else if (ePktType == PKT_TYPE_802_11_BCN) {
645 pDevice->bStopBeacon = true;
646 } else if (ePktType == PKT_TYPE_802_11_MNG) {
647 pDevice->bStopTx0Pkt = true;
648 } else if (ePktType == PKT_TYPE_802_11_DATA) {
649 pDevice->bStopDataPkt = true;
652 if (pDevice->bStopBeacon == true) {
653 if (pDevice->bIsBeaconBufReadySet == true) {
654 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
655 pDevice->cbBeaconBufReadySetCnt++;
659 pDevice->bIsBeaconBufReadySet = false;
660 pDevice->cbBeaconBufReadySetCnt = 0;
661 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
663 // wait all TD0 complete
664 if (pDevice->bStopTx0Pkt == true) {
665 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
668 // wait all Data TD complete
669 if (pDevice->bStopDataPkt == true) {
670 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
678 * Description: Card Start Hardware Tx
682 * pDeviceHandler - The adapter to be set
683 * ePktType - Packet type to start
687 * Return Value: true if success; false if failed.
690 bool CARDbStartTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
693 if (ePktType == PKT_TYPE_802_11_ALL) {
694 pDevice->bStopBeacon = false;
695 pDevice->bStopTx0Pkt = false;
696 pDevice->bStopDataPkt = false;
697 } else if (ePktType == PKT_TYPE_802_11_BCN) {
698 pDevice->bStopBeacon = false;
699 } else if (ePktType == PKT_TYPE_802_11_MNG) {
700 pDevice->bStopTx0Pkt = false;
701 } else if (ePktType == PKT_TYPE_802_11_DATA) {
702 pDevice->bStopDataPkt = false;
705 if ((pDevice->bStopBeacon == false) &&
706 (pDevice->bBeaconBufReady == true) &&
707 (pDevice->eOPMode == OP_MODE_ADHOC)) {
708 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
715 * Description: Card Set BSSID value
719 * pDeviceHandler - The adapter to be set
720 * pbyBSSID - pointer to BSSID field
721 * bAdhoc - flag to indicate IBSS
725 * Return Value: true if success; false if failed.
728 bool CARDbSetBSSID(struct vnt_private *pDevice,
729 unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
732 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
733 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
734 if (eOPMode == OP_MODE_ADHOC)
735 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
737 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
739 if (eOPMode == OP_MODE_AP)
740 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
742 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
744 if (eOPMode == OP_MODE_UNKNOWN) {
745 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
746 pDevice->bBSSIDFilter = false;
747 pDevice->byRxMode &= ~RCR_BSSID;
748 pr_debug("wcmd: rx_mode = %x\n", pDevice->byRxMode);
750 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
751 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
752 pDevice->bBSSIDFilter = true;
753 pDevice->byRxMode |= RCR_BSSID;
755 pr_debug("wmgr: rx_mode = %x\n", pDevice->byRxMode);
757 // Adopt BSS state in Adapter Device Object
758 pDevice->eOPMode = eOPMode;
763 * Description: Card indicate status
767 * pDeviceHandler - The adapter to be set
772 * Return Value: true if success; false if failed.
777 * Description: Save Assoc info. contain in assoc. response frame
781 * pDevice - The adapter to be set
782 * wCapabilityInfo - Capability information
783 * wStatus - Status code
785 * uLen - Length of IEs
786 * pbyIEs - pointer to IEs
790 * Return Value: true if succeed; otherwise false
793 bool CARDbSetTxDataRate(
794 struct vnt_private *pDevice,
795 unsigned short wDataRate
799 pDevice->wCurrentRate = wDataRate;
805 * Routine Description:
806 * Consider to power down when no more packets to tx or rx.
810 * pDevice - The adapter to be set
814 * Return Value: true if power down success; otherwise false
819 struct vnt_private *pDevice
824 // check if already in Doze mode
825 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
829 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
831 // check if all TD are empty,
833 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
834 if (pDevice->iTDUsed[uIdx] != 0)
838 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
839 pr_debug("Go to Doze ZZZZZZZZZZZZZZZ\n");
844 * Description: Turn off Radio power
848 * pDevice - The adapter to be turned off
852 * Return Value: true if success; otherwise false
855 bool CARDbRadioPowerOff(struct vnt_private *pDevice)
859 if (pDevice->bRadioOff == true)
862 switch (pDevice->byRFType) {
864 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
865 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
870 case RF_AIROHA7230: //RobertYu:20050104
871 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
872 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
877 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
879 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
881 pDevice->bRadioOff = true;
882 //2007-0409-03,<Add> by chester
883 pr_debug("chester power off\n");
884 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
889 * Description: Turn on Radio power
893 * pDevice - The adapter to be turned on
897 * Return Value: true if success; otherwise false
900 bool CARDbRadioPowerOn(struct vnt_private *pDevice)
904 pr_debug("chester power on\n");
905 if (pDevice->bRadioControlOff == true) {
906 if (pDevice->bHWRadioOff == true)
907 pr_debug("chester bHWRadioOff\n");
908 if (pDevice->bRadioControlOff == true)
909 pr_debug("chester bRadioControlOff\n");
912 if (pDevice->bRadioOff == false) {
913 pr_debug("chester pbRadioOff\n");
916 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
918 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
920 switch (pDevice->byRFType) {
922 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
923 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
928 case RF_AIROHA7230: //RobertYu:20050104
929 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
935 pDevice->bRadioOff = false;
936 // 2007-0409-03,<Add> by chester
937 pr_debug("chester power on\n");
938 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
942 bool CARDbRemoveKey(struct vnt_private *pDevice, unsigned char *pbyBSSID)
945 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
952 * Add BSSID in PMKID Candidate list.
956 * hDeviceContext - device structure point
957 * pbyBSSID - BSSID address for adding
958 * wRSNCap - BSS's RSN capability
962 * Return Value: none.
966 CARDbAdd_PMKID_Candidate(
967 struct vnt_private *pDevice,
968 unsigned char *pbyBSSID,
970 unsigned short wRSNCap
973 struct pmkid_candidate *pCandidateList;
976 pr_debug("bAdd_PMKID_Candidate START: (%d)\n",
977 (int)pDevice->gsPMKIDCandidate.NumCandidates);
979 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
980 pr_debug("vFlush_PMKID_Candidate: 3\n");
981 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
984 for (ii = 0; ii < 6; ii++)
985 pr_debug("%02X ", *(pbyBSSID + ii));
989 // Update Old Candidate
990 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
991 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
992 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
993 if (bRSNCapExist && (wRSNCap & BIT0))
994 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
996 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1003 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1004 if (bRSNCapExist && (wRSNCap & BIT0))
1005 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1007 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1009 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1010 pDevice->gsPMKIDCandidate.NumCandidates++;
1011 pr_debug("NumCandidates:%d\n",
1012 (int)pDevice->gsPMKIDCandidate.NumCandidates);
1017 CARDpGetCurrentAddress(
1018 struct vnt_private *pDevice
1022 return pDevice->abyCurrentNetAddr;
1028 * Start Spectrum Measure defined in 802.11h
1032 * hDeviceContext - device structure point
1036 * Return Value: none.
1041 struct vnt_private *pDevice,
1042 void *pvMeasureEIDs,
1043 unsigned int uNumOfMeasureEIDs
1046 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1049 bool bExpired = true;
1050 unsigned short wDuration = 0;
1052 if ((pEID == NULL) ||
1053 (uNumOfMeasureEIDs == 0)) {
1056 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1057 if (pDevice->bMeasureInProgress == true) {
1058 pDevice->bMeasureInProgress = false;
1059 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1060 MACvSelectPage1(pDevice->PortOffset);
1061 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1062 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1063 // clear measure control
1064 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1065 MACvSelectPage0(pDevice->PortOffset);
1066 set_channel(pDevice, pDevice->byOrgChannel);
1067 MACvSelectPage1(pDevice->PortOffset);
1068 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1069 MACvSelectPage0(pDevice->PortOffset);
1071 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1074 pDevice->pCurrMeasureEID = pEID;
1076 pDevice->uNumOfMeasureEIDs--;
1078 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1079 qwStartTSF = *((u64 *)(pDevice->pCurrMeasureEID->sReq.abyStartTime));
1080 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1081 wDuration += 1; // 1 TU for channel switching
1083 if (qwStartTSF == 0) {
1084 // start immediately by setting start TSF == current TSF + 2 TU
1085 qwStartTSF = qwCurrTSF + 2048;
1090 // start at setting start TSF - 1TU(for channel switching)
1094 if (qwCurrTSF < qwStartTSF) {
1098 VNTWIFIbMeasureReport(pDevice->pMgmt,
1100 pDevice->pCurrMeasureEID,
1102 pDevice->byBasicMap,
1103 pDevice->byCCAFraction,
1107 // hardware do not support measure
1108 VNTWIFIbMeasureReport(pDevice->pMgmt,
1110 pDevice->pCurrMeasureEID,
1111 MEASURE_MODE_INCAPABLE,
1112 pDevice->byBasicMap,
1113 pDevice->byCCAFraction,
1117 } while (pDevice->uNumOfMeasureEIDs != 0);
1120 MACvSelectPage1(pDevice->PortOffset);
1121 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, (u32)qwStartTSF);
1122 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, (u32)(qwStartTSF >> 32));
1123 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1124 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1125 MACvSelectPage0(pDevice->PortOffset);
1127 // all measure start time expired we should complete action
1128 VNTWIFIbMeasureReport(pDevice->pMgmt,
1132 pDevice->byBasicMap,
1133 pDevice->byCCAFraction,
1143 * Do Channel Switch defined in 802.11h
1147 * hDeviceContext - device structure point
1151 * Return Value: none.
1156 struct vnt_private *pDevice,
1157 unsigned char byMode,
1158 unsigned char byNewChannel,
1159 unsigned char byCount
1162 bool bResult = true;
1165 bResult = set_channel(pDevice, byNewChannel);
1166 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1167 MACvSelectPage1(pDevice->PortOffset);
1168 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1169 MACvSelectPage0(pDevice->PortOffset);
1172 pDevice->byChannelSwitchCount = byCount;
1173 pDevice->byNewChannel = byNewChannel;
1174 pDevice->bChannelSwitch = true;
1176 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1184 * Handle Quiet EID defined in 802.11h
1188 * hDeviceContext - device structure point
1192 * Return Value: none.
1197 struct vnt_private *pDevice,
1199 unsigned char byQuietCount,
1200 unsigned char byQuietPeriod,
1201 unsigned short wQuietDuration,
1202 unsigned short wQuietOffset
1205 unsigned int ii = 0;
1208 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1209 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
1210 pDevice->sQuiet[ii].bEnable = false;
1212 pDevice->uQuietEnqueue = 0;
1213 pDevice->bEnableFirstQuiet = false;
1214 pDevice->bQuietEnable = false;
1215 pDevice->byQuietStartCount = byQuietCount;
1217 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1218 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1219 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1220 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1221 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1222 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1223 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1224 pDevice->uQuietEnqueue++;
1225 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1226 if (pDevice->byQuietStartCount < byQuietCount)
1227 pDevice->byQuietStartCount = byQuietCount;
1235 * Do Quiet, It will be called by either ISR(after start)
1236 * or VNTWIFI(before start) so we do not need a SPINLOCK
1240 * hDeviceContext - device structure point
1244 * Return Value: none.
1249 struct vnt_private *pDevice
1252 unsigned int ii = 0;
1253 unsigned long dwStartTime = 0xFFFFFFFF;
1254 unsigned int uCurrentQuietIndex = 0;
1255 unsigned long dwNextTime = 0;
1256 unsigned long dwGap = 0;
1257 unsigned long dwDuration = 0;
1259 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1260 if ((pDevice->sQuiet[ii].bEnable == true) &&
1261 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1262 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1263 uCurrentQuietIndex = ii;
1266 if (dwStartTime == 0xFFFFFFFF) {
1268 pDevice->bQuietEnable = false;
1269 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1271 if (pDevice->bQuietEnable == false) {
1273 pDevice->byQuietStartCount--;
1274 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1275 dwNextTime %= pDevice->wBeaconInterval;
1276 MACvSelectPage1(pDevice->PortOffset);
1277 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1278 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1279 if (pDevice->byQuietStartCount == 0) {
1280 pDevice->bEnableFirstQuiet = false;
1281 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1283 pDevice->bEnableFirstQuiet = true;
1285 MACvSelectPage0(pDevice->PortOffset);
1287 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1288 // overlap with previous Quiet
1289 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1290 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1291 // return false to indicate next quiet expired, should call this function again
1294 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1297 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1298 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1300 // set GAP and Next duration
1301 MACvSelectPage1(pDevice->PortOffset);
1302 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1303 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1304 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1305 MACvSelectPage0(pDevice->PortOffset);
1307 pDevice->bQuietEnable = true;
1308 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1309 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1310 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1311 // not period disable current quiet element
1312 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1314 // set next period start time
1315 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1316 dwNextTime *= pDevice->wBeaconInterval;
1317 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1319 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1320 // decreament all time to avoid wrap around
1321 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1322 if (pDevice->sQuiet[ii].bEnable == true)
1323 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1326 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1335 * Set Local Power Constraint
1339 * hDeviceContext - device structure point
1343 * Return Value: none.
1347 CARDvSetPowerConstraint(
1348 struct vnt_private *pDevice,
1349 unsigned char byChannel,
1354 if (byChannel > CB_MAX_CHANNEL_24G) {
1355 if (pDevice->bCountryInfo5G == true)
1356 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1359 if (pDevice->bCountryInfo24G == true)
1360 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1368 * Set Local Power Constraint
1372 * hDeviceContext - device structure point
1376 * Return Value: none.
1380 CARDvGetPowerCapability(
1381 struct vnt_private *pDevice,
1382 unsigned char *pbyMinPower,
1383 unsigned char *pbyMaxPower
1386 unsigned char byDec = 0;
1388 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1389 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1390 if (pDevice->byRFType == RF_UW2452) {
1396 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1402 * Get Current Tx Power
1406 * hDeviceContext - device structure point
1410 * Return Value: none.
1414 CARDbyGetTransmitPower(
1415 struct vnt_private *pDevice
1419 return pDevice->byCurPwrdBm;
1425 struct vnt_private *pDevice
1431 // initialize TD index
1432 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1433 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1435 for (uu = 0; uu < TYPE_MAXTD; uu++)
1436 pDevice->iTDUsed[uu] = 0;
1438 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1439 pCurrTD = &(pDevice->apTD0Rings[uu]);
1440 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1441 // init all Tx Packet pointer to NULL
1443 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1444 pCurrTD = &(pDevice->apTD1Rings[uu]);
1445 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1446 // init all Tx Packet pointer to NULL
1449 // set MAC TD pointer
1450 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1451 (pDevice->td0_pool_dma));
1453 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1454 (pDevice->td1_pool_dma));
1456 // set MAC Beacon TX pointer
1457 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1458 (pDevice->tx_beacon_dma));
1468 * pDevice - Pointer to the adapter
1472 * Return Value: none
1477 struct vnt_private *pDevice
1483 // initialize RD index
1484 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1485 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1487 // init state, all RD is chip's
1488 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1489 pDesc = &(pDevice->aRD0Ring[uu]);
1490 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1491 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1492 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1495 // init state, all RD is chip's
1496 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1497 pDesc = &(pDevice->aRD1Ring[uu]);
1498 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1499 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1500 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1503 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1504 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1507 MACvRx0PerPktMode(pDevice->PortOffset);
1508 MACvRx1PerPktMode(pDevice->PortOffset);
1509 // set MAC RD pointer
1510 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1511 pDevice->rd0_pool_dma);
1513 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1514 pDevice->rd1_pool_dma);
1518 * Description: Get response Control frame rate in CCK mode
1522 * pDevice - The adapter to be set
1523 * wRateIdx - Receiving data rate
1527 * Return Value: response Control frame rate
1530 static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
1531 unsigned short wRateIdx)
1533 unsigned int ui = (unsigned int) wRateIdx;
1535 while (ui > RATE_1M) {
1536 if (pDevice->wBasicRate & ((unsigned short)1 << ui))
1537 return (unsigned short)ui;
1541 return (unsigned short)RATE_1M;
1545 * Description: Get response Control frame rate in OFDM mode
1549 * pDevice - The adapter to be set
1550 * wRateIdx - Receiving data rate
1554 * Return Value: response Control frame rate
1557 static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
1558 unsigned short wRateIdx)
1560 unsigned int ui = (unsigned int) wRateIdx;
1562 pr_debug("BASIC RATE: %X\n", pDevice->wBasicRate);
1564 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1565 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1566 if (wRateIdx > RATE_24M)
1567 wRateIdx = RATE_24M;
1570 while (ui > RATE_11M) {
1571 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1572 pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
1573 return (unsigned short)ui;
1577 pr_debug("CARDwGetOFDMControlRate: 6M\n");
1578 return (unsigned short)RATE_24M;
1582 * Description: Set RSPINF
1586 * pDevice - The adapter to be set
1590 * Return Value: None.
1593 void CARDvSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType)
1595 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1596 unsigned short wLen = 0x0000;
1597 unsigned char byTxRate, byRsvTime; //For OFDM
1600 MACvSelectPage1(pDevice->PortOffset);
1603 BBvCalculateParameter(pDevice,
1605 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1612 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1614 BBvCalculateParameter(pDevice,
1616 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1623 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1625 BBvCalculateParameter(pDevice,
1627 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1634 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1636 BBvCalculateParameter(pDevice,
1638 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1645 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1647 s_vCalculateOFDMRParameter(RATE_6M,
1651 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1653 s_vCalculateOFDMRParameter(RATE_9M,
1657 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1659 s_vCalculateOFDMRParameter(RATE_12M,
1663 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1665 s_vCalculateOFDMRParameter(RATE_18M,
1669 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1671 s_vCalculateOFDMRParameter(RATE_24M,
1675 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1677 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1681 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1683 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1687 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1689 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1693 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
1696 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1700 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1702 MACvSelectPage0(pDevice->PortOffset);
1706 * Description: Update IFS
1710 * pDevice - The adapter to be set
1714 * Return Value: None.
1717 void vUpdateIFS(struct vnt_private *pDevice)
1719 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
1721 unsigned char byMaxMin = 0;
1723 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1724 pDevice->uSlot = C_SLOT_SHORT;
1725 pDevice->uSIFS = C_SIFS_A;
1726 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1727 pDevice->uCwMin = C_CWMIN_A;
1729 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
1730 pDevice->uSlot = C_SLOT_LONG;
1731 pDevice->uSIFS = C_SIFS_BG;
1732 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1733 pDevice->uCwMin = C_CWMIN_B;
1735 } else { // PK_TYPE_11GA & PK_TYPE_11GB
1736 pDevice->uSIFS = C_SIFS_BG;
1737 if (pDevice->bShortSlotTime)
1738 pDevice->uSlot = C_SLOT_SHORT;
1740 pDevice->uSlot = C_SLOT_LONG;
1742 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1743 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1744 pDevice->uCwMin = C_CWMIN_A;
1747 pDevice->uCwMin = C_CWMIN_B;
1752 pDevice->uCwMax = C_CWMAX;
1753 pDevice->uEIFS = C_EIFS;
1754 if (pDevice->byRFType == RF_RFMD2959) {
1755 // bcs TX_PE will reserve 3 us
1756 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1757 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1759 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1760 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1762 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1763 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1764 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1765 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1768 void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
1770 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1773 //Determines the highest basic rate.
1774 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1775 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1780 pDevice->byTopOFDMBasicRate = byTopOFDM;
1782 for (ii = RATE_11M;; ii--) {
1783 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1790 pDevice->byTopCCKBasicRate = byTopCCK;
1793 bool CARDbAddBasicRate(struct vnt_private *pDevice, unsigned short wRateIdx)
1795 unsigned short wRate = (unsigned short)(1<<wRateIdx);
1797 pDevice->wBasicRate |= wRate;
1799 //Determines the highest basic rate.
1800 CARDvUpdateBasicTopRate((void *)pDevice);
1805 bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
1809 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1810 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1816 unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
1819 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
1820 return (unsigned char)pDevice->byBBType;
1821 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
1822 return PK_TYPE_11GA;
1824 return PK_TYPE_11GB;
1828 * Description: Set NIC Loopback mode
1832 * pDevice - The adapter to be set
1833 * wLoopbackMode - Loopback mode to be set
1837 * Return Value: none
1840 void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
1842 switch (wLoopbackMode) {
1852 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1853 // set Baseband loopback
1857 * Description: Software Reset NIC
1861 * pDevice - The adapter to be reset
1865 * Return Value: none
1868 bool CARDbSoftwareReset(struct vnt_private *pDevice)
1872 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1879 * Description: Calculate TSF offset of two TSF input
1880 * Get TSF Offset from RxBCN's TSF and local TSF
1884 * pDevice - The adapter to be sync.
1885 * qwTSF1 - Rx BCN's TSF
1886 * qwTSF2 - Local TSF
1890 * Return Value: TSF Offset value
1893 u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
1895 u64 qwTSFOffset = 0;
1896 unsigned short wRxBcnTSFOffst = 0;
1898 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
1900 qwTSF2 += (u64)wRxBcnTSFOffst;
1902 qwTSFOffset = qwTSF1 - qwTSF2;
1908 * Description: Read NIC TSF counter
1909 * Get local TSF counter
1913 * pDevice - The adapter to be read
1915 * qwCurrTSF - Current TSF counter
1917 * Return Value: true if success; otherwise false
1920 bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF)
1923 unsigned char byData;
1925 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
1926 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1927 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
1928 if (!(byData & TFTCTL_TSFCNTRRD))
1931 if (ww == W_MAX_TIMEOUT)
1933 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
1934 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
1940 * Description: Read NIC TSF counter
1941 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1945 * qwTSF - Current TSF counter
1946 * wbeaconInterval - Beacon Interval
1948 * qwCurrTSF - Current TSF counter
1950 * Return Value: TSF value of next Beacon
1953 u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
1957 beacon_int = wBeaconInterval * 1024;
1960 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
1963 do_div(qwTSF, beacon_int);
1965 qwTSF *= beacon_int;
1972 * Description: Set NIC TSF counter for first Beacon time
1973 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1977 * dwIoBase - IO Base
1978 * wBeaconInterval - Beacon Interval
1982 * Return Value: none
1985 void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval)
1989 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
1991 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
1993 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
1994 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
1995 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
1999 * Description: Sync NIC TSF counter for Beacon time
2000 * Get NEXTTBTT and write to HW
2004 * pDevice - The adapter to be set
2005 * qwTSF - Current TSF counter
2006 * wBeaconInterval - Beacon Interval
2010 * Return Value: none
2013 void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval)
2015 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2017 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
2018 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
2019 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2020 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);