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 union vnt_phy_field_swap phy;
229 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
232 MACvSelectPage1(pDevice->PortOffset);
235 vnt_get_phy_field(pDevice,
237 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
241 /* swap over to get correct write order */
242 swap(phy.swap[0], phy.swap[1]);
244 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
247 vnt_get_phy_field(pDevice, 14,
248 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
249 PK_TYPE_11B, &phy.field_read);
251 swap(phy.swap[0], phy.swap[1]);
253 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
256 vnt_get_phy_field(pDevice, 14,
257 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
258 PK_TYPE_11B, &phy.field_read);
260 swap(phy.swap[0], phy.swap[1]);
262 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
265 vnt_get_phy_field(pDevice, 14,
266 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
267 PK_TYPE_11B, &phy.field_read);
269 swap(phy.swap[0], phy.swap[1]);
271 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
274 s_vCalculateOFDMRParameter(RATE_6M,
278 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
280 s_vCalculateOFDMRParameter(RATE_9M,
284 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
286 s_vCalculateOFDMRParameter(RATE_12M,
290 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
292 s_vCalculateOFDMRParameter(RATE_18M,
296 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
298 s_vCalculateOFDMRParameter(RATE_24M,
302 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
304 s_vCalculateOFDMRParameter(
305 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
309 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
311 s_vCalculateOFDMRParameter(
312 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
316 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
318 s_vCalculateOFDMRParameter(
319 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
323 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
325 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
327 MACvSelectPage0(pDevice->PortOffset);
330 /*--------------------- Export Functions --------------------------*/
333 * Description: Get Card short preamble option value
337 * pDevice - The adapter to be set
341 * Return Value: true if short preamble; otherwise false
344 bool CARDbIsShortPreamble(struct vnt_private *pDevice)
347 if (pDevice->byPreambleType == 0)
354 * Description: Get Card short slot time option value
358 * pDevice - The adapter to be set
362 * Return Value: true if short slot time; otherwise false
365 bool CARDbIsShorSlotTime(struct vnt_private *pDevice)
368 return pDevice->bShortSlotTime;
372 * Description: Update IFS
376 * pDevice - The adapter to be set
380 * Return Value: None.
383 bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
384 unsigned short wCapInfo, unsigned char byERPField,
385 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
387 unsigned char byCWMaxMin = 0;
388 unsigned char bySlot = 0;
389 unsigned char bySIFS = 0;
390 unsigned char byDIFS = 0;
391 unsigned char byData;
392 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
393 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
395 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
396 if (ePHYType == PHY_TYPE_11A) {
397 if (pSupportRates == NULL)
398 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
400 if (pDevice->byRFType == RF_AIROHA7230) {
401 // AL7230 use single PAPE and connect to PAPE_2.4G
402 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
403 pDevice->abyBBVGA[0] = 0x20;
404 pDevice->abyBBVGA[2] = 0x10;
405 pDevice->abyBBVGA[3] = 0x10;
406 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
408 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
410 } else if (pDevice->byRFType == RF_UW2452) {
411 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
412 pDevice->abyBBVGA[0] = 0x18;
413 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
414 if (byData == 0x14) {
415 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
416 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
419 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
421 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
422 bySlot = C_SLOT_SHORT;
424 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
426 } else if (ePHYType == PHY_TYPE_11B) {
427 if (pSupportRates == NULL)
428 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
430 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
431 if (pDevice->byRFType == RF_AIROHA7230) {
432 pDevice->abyBBVGA[0] = 0x1C;
433 pDevice->abyBBVGA[2] = 0x00;
434 pDevice->abyBBVGA[3] = 0x00;
435 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
437 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
439 } else if (pDevice->byRFType == RF_UW2452) {
440 pDevice->abyBBVGA[0] = 0x14;
441 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
442 if (byData == 0x18) {
443 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
444 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
447 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
448 bySlot = C_SLOT_LONG;
450 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
452 } else {// PK_TYPE_11GA & PK_TYPE_11GB
453 if (pSupportRates == NULL) {
454 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
455 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
457 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
458 if (pDevice->byRFType == RF_AIROHA7230) {
459 pDevice->abyBBVGA[0] = 0x1C;
460 pDevice->abyBBVGA[2] = 0x00;
461 pDevice->abyBBVGA[3] = 0x00;
462 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
464 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
466 } else if (pDevice->byRFType == RF_UW2452) {
467 pDevice->abyBBVGA[0] = 0x14;
468 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
469 if (byData == 0x18) {
470 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
471 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
474 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
476 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
477 bySlot = C_SLOT_SHORT;
478 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
480 bySlot = C_SLOT_LONG;
481 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
483 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M)
488 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
489 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
490 if (pDevice->bProtectMode)
491 MACvEnableProtectMD(pDevice->PortOffset);
493 MACvDisableProtectMD(pDevice->PortOffset);
496 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
497 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
498 if (pDevice->bBarkerPreambleMd)
499 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
501 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
505 if (pDevice->byRFType == RF_RFMD2959) {
506 // bcs TX_PE will reserve 3 us
507 // hardware's processing time here is 2 us.
510 //{{ RobertYu: 20041202
511 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
512 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
515 if (pDevice->bySIFS != bySIFS) {
516 pDevice->bySIFS = bySIFS;
517 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
519 if (pDevice->byDIFS != byDIFS) {
520 pDevice->byDIFS = byDIFS;
521 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
523 if (pDevice->byEIFS != C_EIFS) {
524 pDevice->byEIFS = C_EIFS;
525 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
527 if (pDevice->bySlot != bySlot) {
528 pDevice->bySlot = bySlot;
529 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
530 if (pDevice->bySlot == C_SLOT_SHORT)
531 pDevice->bShortSlotTime = true;
533 pDevice->bShortSlotTime = false;
535 BBvSetShortSlotTime(pDevice);
537 if (pDevice->byCWMaxMin != byCWMaxMin) {
538 pDevice->byCWMaxMin = byCWMaxMin;
539 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
541 if (VNTWIFIbIsShortPreamble(wCapInfo))
542 pDevice->byPreambleType = pDevice->byShortPreamble;
544 pDevice->byPreambleType = 0;
546 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
547 pDevice->eCurrentPHYType = ePHYType;
548 // set for NDIS OID_802_11SUPPORTED_RATES
553 * Description: Sync. TSF counter to BSS
554 * Get TSF offset and write to HW
558 * pDevice - The adapter to be sync.
559 * byRxRate - data rate of receive beacon
560 * qwBSSTimestamp - Rx BCN's TSF
561 * qwLocalTSF - Local TSF
568 bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
569 u64 qwBSSTimestamp, u64 qwLocalTSF)
573 if (qwBSSTimestamp != qwLocalTSF) {
574 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
576 // HW's TSF add TSF Offset reg
577 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
578 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
579 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
585 * Description: Set NIC TSF counter for first Beacon time
586 * Get NEXTTBTT from adjusted TSF and Beacon Interval
590 * pDevice - The adapter to be set.
591 * wBeaconInterval - Beacon Interval
595 * Return Value: true if succeed; otherwise false
598 bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
599 unsigned short wBeaconInterval)
603 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
605 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
607 // set HW beacon interval
608 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
609 pDevice->wBeaconInterval = wBeaconInterval;
611 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
612 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
613 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
619 * Description: Card Stop Hardware Tx
623 * pDeviceHandler - The adapter to be set
624 * ePktType - Packet type to stop
628 * Return Value: true if all data packet complete; otherwise false.
631 bool CARDbStopTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
634 if (ePktType == PKT_TYPE_802_11_ALL) {
635 pDevice->bStopBeacon = true;
636 pDevice->bStopTx0Pkt = true;
637 pDevice->bStopDataPkt = true;
638 } else if (ePktType == PKT_TYPE_802_11_BCN) {
639 pDevice->bStopBeacon = true;
640 } else if (ePktType == PKT_TYPE_802_11_MNG) {
641 pDevice->bStopTx0Pkt = true;
642 } else if (ePktType == PKT_TYPE_802_11_DATA) {
643 pDevice->bStopDataPkt = true;
646 if (pDevice->bStopBeacon == true) {
647 if (pDevice->bIsBeaconBufReadySet == true) {
648 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
649 pDevice->cbBeaconBufReadySetCnt++;
653 pDevice->bIsBeaconBufReadySet = false;
654 pDevice->cbBeaconBufReadySetCnt = 0;
655 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
657 // wait all TD0 complete
658 if (pDevice->bStopTx0Pkt == true) {
659 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
662 // wait all Data TD complete
663 if (pDevice->bStopDataPkt == true) {
664 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
672 * Description: Card Start Hardware Tx
676 * pDeviceHandler - The adapter to be set
677 * ePktType - Packet type to start
681 * Return Value: true if success; false if failed.
684 bool CARDbStartTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
687 if (ePktType == PKT_TYPE_802_11_ALL) {
688 pDevice->bStopBeacon = false;
689 pDevice->bStopTx0Pkt = false;
690 pDevice->bStopDataPkt = false;
691 } else if (ePktType == PKT_TYPE_802_11_BCN) {
692 pDevice->bStopBeacon = false;
693 } else if (ePktType == PKT_TYPE_802_11_MNG) {
694 pDevice->bStopTx0Pkt = false;
695 } else if (ePktType == PKT_TYPE_802_11_DATA) {
696 pDevice->bStopDataPkt = false;
699 if ((pDevice->bStopBeacon == false) &&
700 (pDevice->bBeaconBufReady == true) &&
701 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) {
702 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
709 * Description: Card Set BSSID value
713 * pDeviceHandler - The adapter to be set
714 * pbyBSSID - pointer to BSSID field
715 * bAdhoc - flag to indicate IBSS
719 * Return Value: true if success; false if failed.
722 bool CARDbSetBSSID(struct vnt_private *pDevice,
723 unsigned char *pbyBSSID, enum nl80211_iftype op_mode)
726 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
727 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
728 if (op_mode == NL80211_IFTYPE_ADHOC)
729 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
731 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
733 if (op_mode == NL80211_IFTYPE_AP)
734 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
736 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
738 if (op_mode == NL80211_IFTYPE_UNSPECIFIED) {
739 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
740 pDevice->bBSSIDFilter = false;
741 pDevice->byRxMode &= ~RCR_BSSID;
742 pr_debug("wcmd: rx_mode = %x\n", pDevice->byRxMode);
744 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
745 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
746 pDevice->bBSSIDFilter = true;
747 pDevice->byRxMode |= RCR_BSSID;
749 pr_debug("wmgr: rx_mode = %x\n", pDevice->byRxMode);
751 // Adopt BSS state in Adapter Device Object
752 pDevice->op_mode = op_mode;
757 * Description: Card indicate status
761 * pDeviceHandler - The adapter to be set
766 * Return Value: true if success; false if failed.
771 * Description: Save Assoc info. contain in assoc. response frame
775 * pDevice - The adapter to be set
776 * wCapabilityInfo - Capability information
777 * wStatus - Status code
779 * uLen - Length of IEs
780 * pbyIEs - pointer to IEs
784 * Return Value: true if succeed; otherwise false
787 bool CARDbSetTxDataRate(
788 struct vnt_private *pDevice,
789 unsigned short wDataRate
793 pDevice->wCurrentRate = wDataRate;
799 * Routine Description:
800 * Consider to power down when no more packets to tx or rx.
804 * pDevice - The adapter to be set
808 * Return Value: true if power down success; otherwise false
813 struct vnt_private *pDevice
818 // check if already in Doze mode
819 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
823 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
825 // check if all TD are empty,
827 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
828 if (pDevice->iTDUsed[uIdx] != 0)
832 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
833 pr_debug("Go to Doze ZZZZZZZZZZZZZZZ\n");
838 * Description: Turn off Radio power
842 * pDevice - The adapter to be turned off
846 * Return Value: true if success; otherwise false
849 bool CARDbRadioPowerOff(struct vnt_private *pDevice)
853 if (pDevice->bRadioOff == true)
856 switch (pDevice->byRFType) {
858 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
859 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
864 case RF_AIROHA7230: //RobertYu:20050104
865 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
866 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
871 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
873 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
875 pDevice->bRadioOff = true;
876 //2007-0409-03,<Add> by chester
877 pr_debug("chester power off\n");
878 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
883 * Description: Turn on Radio power
887 * pDevice - The adapter to be turned on
891 * Return Value: true if success; otherwise false
894 bool CARDbRadioPowerOn(struct vnt_private *pDevice)
898 pr_debug("chester power on\n");
899 if (pDevice->bRadioControlOff == true) {
900 if (pDevice->bHWRadioOff == true)
901 pr_debug("chester bHWRadioOff\n");
902 if (pDevice->bRadioControlOff == true)
903 pr_debug("chester bRadioControlOff\n");
906 if (pDevice->bRadioOff == false) {
907 pr_debug("chester pbRadioOff\n");
910 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
912 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
914 switch (pDevice->byRFType) {
916 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
917 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
922 case RF_AIROHA7230: //RobertYu:20050104
923 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
929 pDevice->bRadioOff = false;
930 // 2007-0409-03,<Add> by chester
931 pr_debug("chester power on\n");
932 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
936 bool CARDbRemoveKey(struct vnt_private *pDevice, unsigned char *pbyBSSID)
939 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
946 * Add BSSID in PMKID Candidate list.
950 * hDeviceContext - device structure point
951 * pbyBSSID - BSSID address for adding
952 * wRSNCap - BSS's RSN capability
956 * Return Value: none.
960 CARDbAdd_PMKID_Candidate(
961 struct vnt_private *pDevice,
962 unsigned char *pbyBSSID,
964 unsigned short wRSNCap
967 struct pmkid_candidate *pCandidateList;
970 pr_debug("bAdd_PMKID_Candidate START: (%d)\n",
971 (int)pDevice->gsPMKIDCandidate.NumCandidates);
973 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
974 pr_debug("vFlush_PMKID_Candidate: 3\n");
975 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
978 for (ii = 0; ii < 6; ii++)
979 pr_debug("%02X ", *(pbyBSSID + ii));
983 // Update Old Candidate
984 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
985 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
986 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
987 if (bRSNCapExist && (wRSNCap & BIT0))
988 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
990 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
997 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
998 if (bRSNCapExist && (wRSNCap & BIT0))
999 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1001 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1003 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1004 pDevice->gsPMKIDCandidate.NumCandidates++;
1005 pr_debug("NumCandidates:%d\n",
1006 (int)pDevice->gsPMKIDCandidate.NumCandidates);
1011 CARDpGetCurrentAddress(
1012 struct vnt_private *pDevice
1016 return pDevice->abyCurrentNetAddr;
1022 * Start Spectrum Measure defined in 802.11h
1026 * hDeviceContext - device structure point
1030 * Return Value: none.
1035 struct vnt_private *pDevice,
1036 void *pvMeasureEIDs,
1037 unsigned int uNumOfMeasureEIDs
1040 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1043 bool bExpired = true;
1044 unsigned short wDuration = 0;
1046 if ((pEID == NULL) ||
1047 (uNumOfMeasureEIDs == 0)) {
1050 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1051 if (pDevice->bMeasureInProgress == true) {
1052 pDevice->bMeasureInProgress = false;
1053 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1054 MACvSelectPage1(pDevice->PortOffset);
1055 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1056 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1057 // clear measure control
1058 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1059 MACvSelectPage0(pDevice->PortOffset);
1060 set_channel(pDevice, pDevice->byOrgChannel);
1061 MACvSelectPage1(pDevice->PortOffset);
1062 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1063 MACvSelectPage0(pDevice->PortOffset);
1065 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1068 pDevice->pCurrMeasureEID = pEID;
1070 pDevice->uNumOfMeasureEIDs--;
1072 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1073 qwStartTSF = *((u64 *)(pDevice->pCurrMeasureEID->sReq.abyStartTime));
1074 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1075 wDuration += 1; // 1 TU for channel switching
1077 if (qwStartTSF == 0) {
1078 // start immediately by setting start TSF == current TSF + 2 TU
1079 qwStartTSF = qwCurrTSF + 2048;
1084 // start at setting start TSF - 1TU(for channel switching)
1088 if (qwCurrTSF < qwStartTSF) {
1092 VNTWIFIbMeasureReport(pDevice->pMgmt,
1094 pDevice->pCurrMeasureEID,
1096 pDevice->byBasicMap,
1097 pDevice->byCCAFraction,
1101 // hardware do not support measure
1102 VNTWIFIbMeasureReport(pDevice->pMgmt,
1104 pDevice->pCurrMeasureEID,
1105 MEASURE_MODE_INCAPABLE,
1106 pDevice->byBasicMap,
1107 pDevice->byCCAFraction,
1111 } while (pDevice->uNumOfMeasureEIDs != 0);
1114 MACvSelectPage1(pDevice->PortOffset);
1115 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, (u32)qwStartTSF);
1116 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, (u32)(qwStartTSF >> 32));
1117 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1118 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1119 MACvSelectPage0(pDevice->PortOffset);
1121 // all measure start time expired we should complete action
1122 VNTWIFIbMeasureReport(pDevice->pMgmt,
1126 pDevice->byBasicMap,
1127 pDevice->byCCAFraction,
1137 * Do Channel Switch defined in 802.11h
1141 * hDeviceContext - device structure point
1145 * Return Value: none.
1150 struct vnt_private *pDevice,
1151 unsigned char byMode,
1152 unsigned char byNewChannel,
1153 unsigned char byCount
1156 bool bResult = true;
1159 bResult = set_channel(pDevice, byNewChannel);
1160 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1161 MACvSelectPage1(pDevice->PortOffset);
1162 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1163 MACvSelectPage0(pDevice->PortOffset);
1166 pDevice->byChannelSwitchCount = byCount;
1167 pDevice->byNewChannel = byNewChannel;
1168 pDevice->bChannelSwitch = true;
1170 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1178 * Handle Quiet EID defined in 802.11h
1182 * hDeviceContext - device structure point
1186 * Return Value: none.
1191 struct vnt_private *pDevice,
1193 unsigned char byQuietCount,
1194 unsigned char byQuietPeriod,
1195 unsigned short wQuietDuration,
1196 unsigned short wQuietOffset
1199 unsigned int ii = 0;
1202 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1203 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
1204 pDevice->sQuiet[ii].bEnable = false;
1206 pDevice->uQuietEnqueue = 0;
1207 pDevice->bEnableFirstQuiet = false;
1208 pDevice->bQuietEnable = false;
1209 pDevice->byQuietStartCount = byQuietCount;
1211 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1212 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1213 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1214 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1215 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1216 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1217 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1218 pDevice->uQuietEnqueue++;
1219 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1220 if (pDevice->byQuietStartCount < byQuietCount)
1221 pDevice->byQuietStartCount = byQuietCount;
1229 * Do Quiet, It will be called by either ISR(after start)
1230 * or VNTWIFI(before start) so we do not need a SPINLOCK
1234 * hDeviceContext - device structure point
1238 * Return Value: none.
1243 struct vnt_private *pDevice
1246 unsigned int ii = 0;
1247 unsigned long dwStartTime = 0xFFFFFFFF;
1248 unsigned int uCurrentQuietIndex = 0;
1249 unsigned long dwNextTime = 0;
1250 unsigned long dwGap = 0;
1251 unsigned long dwDuration = 0;
1253 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1254 if ((pDevice->sQuiet[ii].bEnable == true) &&
1255 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1256 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1257 uCurrentQuietIndex = ii;
1260 if (dwStartTime == 0xFFFFFFFF) {
1262 pDevice->bQuietEnable = false;
1263 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1265 if (pDevice->bQuietEnable == false) {
1267 pDevice->byQuietStartCount--;
1268 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1269 dwNextTime %= pDevice->wBeaconInterval;
1270 MACvSelectPage1(pDevice->PortOffset);
1271 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1272 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1273 if (pDevice->byQuietStartCount == 0) {
1274 pDevice->bEnableFirstQuiet = false;
1275 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1277 pDevice->bEnableFirstQuiet = true;
1279 MACvSelectPage0(pDevice->PortOffset);
1281 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1282 // overlap with previous Quiet
1283 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1284 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1285 // return false to indicate next quiet expired, should call this function again
1288 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1291 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1292 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1294 // set GAP and Next duration
1295 MACvSelectPage1(pDevice->PortOffset);
1296 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1297 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1298 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1299 MACvSelectPage0(pDevice->PortOffset);
1301 pDevice->bQuietEnable = true;
1302 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1303 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1304 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1305 // not period disable current quiet element
1306 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1308 // set next period start time
1309 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1310 dwNextTime *= pDevice->wBeaconInterval;
1311 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1313 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1314 // decreament all time to avoid wrap around
1315 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1316 if (pDevice->sQuiet[ii].bEnable == true)
1317 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1320 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1329 * Set Local Power Constraint
1333 * hDeviceContext - device structure point
1337 * Return Value: none.
1341 CARDvSetPowerConstraint(
1342 struct vnt_private *pDevice,
1343 unsigned char byChannel,
1348 if (byChannel > CB_MAX_CHANNEL_24G) {
1349 if (pDevice->bCountryInfo5G == true)
1350 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1353 if (pDevice->bCountryInfo24G == true)
1354 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1362 * Set Local Power Constraint
1366 * hDeviceContext - device structure point
1370 * Return Value: none.
1374 CARDvGetPowerCapability(
1375 struct vnt_private *pDevice,
1376 unsigned char *pbyMinPower,
1377 unsigned char *pbyMaxPower
1380 unsigned char byDec = 0;
1382 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1383 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1384 if (pDevice->byRFType == RF_UW2452) {
1390 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1396 * Get Current Tx Power
1400 * hDeviceContext - device structure point
1404 * Return Value: none.
1408 CARDbyGetTransmitPower(
1409 struct vnt_private *pDevice
1413 return pDevice->byCurPwrdBm;
1419 struct vnt_private *pDevice
1425 // initialize TD index
1426 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1427 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1429 for (uu = 0; uu < TYPE_MAXTD; uu++)
1430 pDevice->iTDUsed[uu] = 0;
1432 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1433 pCurrTD = &(pDevice->apTD0Rings[uu]);
1434 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1435 // init all Tx Packet pointer to NULL
1437 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1438 pCurrTD = &(pDevice->apTD1Rings[uu]);
1439 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1440 // init all Tx Packet pointer to NULL
1443 // set MAC TD pointer
1444 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1445 (pDevice->td0_pool_dma));
1447 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1448 (pDevice->td1_pool_dma));
1450 // set MAC Beacon TX pointer
1451 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1452 (pDevice->tx_beacon_dma));
1462 * pDevice - Pointer to the adapter
1466 * Return Value: none
1471 struct vnt_private *pDevice
1477 // initialize RD index
1478 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1479 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1481 // init state, all RD is chip's
1482 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1483 pDesc = &(pDevice->aRD0Ring[uu]);
1484 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1485 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1486 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1489 // init state, all RD is chip's
1490 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1491 pDesc = &(pDevice->aRD1Ring[uu]);
1492 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1493 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1494 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1497 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1498 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1501 MACvRx0PerPktMode(pDevice->PortOffset);
1502 MACvRx1PerPktMode(pDevice->PortOffset);
1503 // set MAC RD pointer
1504 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1505 pDevice->rd0_pool_dma);
1507 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1508 pDevice->rd1_pool_dma);
1512 * Description: Get response Control frame rate in CCK mode
1516 * pDevice - The adapter to be set
1517 * wRateIdx - Receiving data rate
1521 * Return Value: response Control frame rate
1524 static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
1525 unsigned short wRateIdx)
1527 unsigned int ui = (unsigned int) wRateIdx;
1529 while (ui > RATE_1M) {
1530 if (pDevice->wBasicRate & ((unsigned short)1 << ui))
1531 return (unsigned short)ui;
1535 return (unsigned short)RATE_1M;
1539 * Description: Get response Control frame rate in OFDM mode
1543 * pDevice - The adapter to be set
1544 * wRateIdx - Receiving data rate
1548 * Return Value: response Control frame rate
1551 static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
1552 unsigned short wRateIdx)
1554 unsigned int ui = (unsigned int) wRateIdx;
1556 pr_debug("BASIC RATE: %X\n", pDevice->wBasicRate);
1558 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1559 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1560 if (wRateIdx > RATE_24M)
1561 wRateIdx = RATE_24M;
1564 while (ui > RATE_11M) {
1565 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1566 pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
1567 return (unsigned short)ui;
1571 pr_debug("CARDwGetOFDMControlRate: 6M\n");
1572 return (unsigned short)RATE_24M;
1576 * Description: Set RSPINF
1580 * pDevice - The adapter to be set
1584 * Return Value: None.
1587 void CARDvSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType)
1589 union vnt_phy_field_swap phy;
1590 unsigned char byTxRate, byRsvTime; //For OFDM
1593 MACvSelectPage1(pDevice->PortOffset);
1596 vnt_get_phy_field(pDevice, 14,
1597 CARDwGetCCKControlRate(pDevice, RATE_1M),
1598 PK_TYPE_11B, &phy.field_read);
1600 /* swap over to get correct write order */
1601 swap(phy.swap[0], phy.swap[1]);
1603 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
1606 vnt_get_phy_field(pDevice, 14,
1607 CARDwGetCCKControlRate(pDevice, RATE_2M),
1608 PK_TYPE_11B, &phy.field_read);
1610 swap(phy.swap[0], phy.swap[1]);
1612 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
1615 vnt_get_phy_field(pDevice, 14,
1616 CARDwGetCCKControlRate(pDevice, RATE_5M),
1617 PK_TYPE_11B, &phy.field_read);
1619 swap(phy.swap[0], phy.swap[1]);
1621 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
1624 vnt_get_phy_field(pDevice, 14,
1625 CARDwGetCCKControlRate(pDevice, RATE_11M),
1626 PK_TYPE_11B, &phy.field_read);
1628 swap(phy.swap[0], phy.swap[1]);
1630 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
1633 s_vCalculateOFDMRParameter(RATE_6M,
1637 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1639 s_vCalculateOFDMRParameter(RATE_9M,
1643 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1645 s_vCalculateOFDMRParameter(RATE_12M,
1649 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1651 s_vCalculateOFDMRParameter(RATE_18M,
1655 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1657 s_vCalculateOFDMRParameter(RATE_24M,
1661 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1663 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1667 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1669 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1673 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1675 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1679 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
1682 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1686 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1688 MACvSelectPage0(pDevice->PortOffset);
1692 * Description: Update IFS
1696 * pDevice - The adapter to be set
1700 * Return Value: None.
1703 void vUpdateIFS(struct vnt_private *pDevice)
1705 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
1707 unsigned char byMaxMin = 0;
1709 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1710 pDevice->uSlot = C_SLOT_SHORT;
1711 pDevice->uSIFS = C_SIFS_A;
1712 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1713 pDevice->uCwMin = C_CWMIN_A;
1715 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
1716 pDevice->uSlot = C_SLOT_LONG;
1717 pDevice->uSIFS = C_SIFS_BG;
1718 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1719 pDevice->uCwMin = C_CWMIN_B;
1721 } else { // PK_TYPE_11GA & PK_TYPE_11GB
1722 pDevice->uSIFS = C_SIFS_BG;
1723 if (pDevice->bShortSlotTime)
1724 pDevice->uSlot = C_SLOT_SHORT;
1726 pDevice->uSlot = C_SLOT_LONG;
1728 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1729 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1730 pDevice->uCwMin = C_CWMIN_A;
1733 pDevice->uCwMin = C_CWMIN_B;
1738 pDevice->uCwMax = C_CWMAX;
1739 pDevice->uEIFS = C_EIFS;
1740 if (pDevice->byRFType == RF_RFMD2959) {
1741 // bcs TX_PE will reserve 3 us
1742 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1743 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1745 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1746 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1748 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1749 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1750 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1751 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1754 void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
1756 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1759 //Determines the highest basic rate.
1760 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1761 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1766 pDevice->byTopOFDMBasicRate = byTopOFDM;
1768 for (ii = RATE_11M;; ii--) {
1769 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1776 pDevice->byTopCCKBasicRate = byTopCCK;
1779 bool CARDbAddBasicRate(struct vnt_private *pDevice, unsigned short wRateIdx)
1781 unsigned short wRate = (unsigned short)(1<<wRateIdx);
1783 pDevice->wBasicRate |= wRate;
1785 //Determines the highest basic rate.
1786 CARDvUpdateBasicTopRate((void *)pDevice);
1791 bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
1795 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1796 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1802 unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
1805 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
1806 return (unsigned char)pDevice->byBBType;
1807 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
1808 return PK_TYPE_11GA;
1810 return PK_TYPE_11GB;
1814 * Description: Set NIC Loopback mode
1818 * pDevice - The adapter to be set
1819 * wLoopbackMode - Loopback mode to be set
1823 * Return Value: none
1826 void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
1828 switch (wLoopbackMode) {
1838 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1839 // set Baseband loopback
1843 * Description: Software Reset NIC
1847 * pDevice - The adapter to be reset
1851 * Return Value: none
1854 bool CARDbSoftwareReset(struct vnt_private *pDevice)
1858 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1865 * Description: Calculate TSF offset of two TSF input
1866 * Get TSF Offset from RxBCN's TSF and local TSF
1870 * pDevice - The adapter to be sync.
1871 * qwTSF1 - Rx BCN's TSF
1872 * qwTSF2 - Local TSF
1876 * Return Value: TSF Offset value
1879 u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
1881 u64 qwTSFOffset = 0;
1882 unsigned short wRxBcnTSFOffst = 0;
1884 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
1886 qwTSF2 += (u64)wRxBcnTSFOffst;
1888 qwTSFOffset = qwTSF1 - qwTSF2;
1894 * Description: Read NIC TSF counter
1895 * Get local TSF counter
1899 * pDevice - The adapter to be read
1901 * qwCurrTSF - Current TSF counter
1903 * Return Value: true if success; otherwise false
1906 bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF)
1909 unsigned char byData;
1911 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
1912 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1913 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
1914 if (!(byData & TFTCTL_TSFCNTRRD))
1917 if (ww == W_MAX_TIMEOUT)
1919 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
1920 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
1926 * Description: Read NIC TSF counter
1927 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1931 * qwTSF - Current TSF counter
1932 * wbeaconInterval - Beacon Interval
1934 * qwCurrTSF - Current TSF counter
1936 * Return Value: TSF value of next Beacon
1939 u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
1943 beacon_int = wBeaconInterval * 1024;
1946 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
1949 do_div(qwTSF, beacon_int);
1951 qwTSF *= beacon_int;
1958 * Description: Set NIC TSF counter for first Beacon time
1959 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1963 * dwIoBase - IO Base
1964 * wBeaconInterval - Beacon Interval
1968 * Return Value: none
1971 void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval)
1975 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
1977 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
1979 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
1980 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
1981 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
1985 * Description: Sync NIC TSF counter for Beacon time
1986 * Get NEXTTBTT and write to HW
1990 * pDevice - The adapter to be set
1991 * qwTSF - Current TSF counter
1992 * wBeaconInterval - Beacon Interval
1996 * Return Value: none
1999 void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval)
2001 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2003 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
2004 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
2005 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2006 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);