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
39 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
40 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
41 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
53 /*--------------------- Static Definitions -------------------------*/
55 #define C_SIFS_A 16 /* micro sec. */
58 #define C_EIFS 80 /* micro sec. */
60 #define C_SLOT_SHORT 9 /* micro sec. */
61 #define C_SLOT_LONG 20
63 #define C_CWMIN_A 15 /* slot time */
66 #define C_CWMAX 1023 /* slot time */
68 #define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
70 /*--------------------- Static Variables --------------------------*/
72 static const unsigned short cwRXBCNTSFOff[MAX_RATE] =
73 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
75 /*--------------------- Static Functions --------------------------*/
79 s_vCalculateOFDMRParameter(
81 CARD_PHY_TYPE ePHYType,
82 unsigned char *pbyTxRate,
83 unsigned char *pbyRsvTime
86 /*--------------------- Export Functions --------------------------*/
89 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
94 * byPktType - Tx Packet type
96 * pbyTxRate - pointer to RSPINF TxRate field
97 * pbyRsvTime - pointer to RSPINF RsvTime field
103 s_vCalculateOFDMRParameter(
104 unsigned char byRate,
105 CARD_PHY_TYPE ePHYType,
106 unsigned char *pbyTxRate,
107 unsigned char *pbyRsvTime
112 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
122 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
132 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
142 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
152 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
162 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
172 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
183 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
194 /*--------------------- Export Functions --------------------------*/
197 * Description: Update IFS
201 * pDevice - The adapter to be set
205 * Return Value: None.
207 bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
208 unsigned short wCapInfo, unsigned char byERPField,
209 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
211 unsigned char byCWMaxMin = 0;
212 unsigned char bySlot = 0;
213 unsigned char bySIFS = 0;
214 unsigned char byDIFS = 0;
215 unsigned char byData;
218 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
219 if (ePHYType == PHY_TYPE_11A) {
220 if (pDevice->byRFType == RF_AIROHA7230) {
221 /* AL7230 use single PAPE and connect to PAPE_2.4G */
222 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
223 pDevice->abyBBVGA[0] = 0x20;
224 pDevice->abyBBVGA[2] = 0x10;
225 pDevice->abyBBVGA[3] = 0x10;
226 BBbReadEmbedded(pDevice, 0xE7, &byData);
228 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
230 } else if (pDevice->byRFType == RF_UW2452) {
231 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
232 pDevice->abyBBVGA[0] = 0x18;
233 BBbReadEmbedded(pDevice, 0xE7, &byData);
234 if (byData == 0x14) {
235 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
236 BBbWriteEmbedded(pDevice, 0xE1, 0x57);
239 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
241 BBbWriteEmbedded(pDevice, 0x88, 0x03);
242 bySlot = C_SLOT_SHORT;
244 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
246 } else if (ePHYType == PHY_TYPE_11B) {
247 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
248 if (pDevice->byRFType == RF_AIROHA7230) {
249 pDevice->abyBBVGA[0] = 0x1C;
250 pDevice->abyBBVGA[2] = 0x00;
251 pDevice->abyBBVGA[3] = 0x00;
252 BBbReadEmbedded(pDevice, 0xE7, &byData);
254 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
256 } else if (pDevice->byRFType == RF_UW2452) {
257 pDevice->abyBBVGA[0] = 0x14;
258 BBbReadEmbedded(pDevice, 0xE7, &byData);
259 if (byData == 0x18) {
260 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
261 BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
264 BBbWriteEmbedded(pDevice, 0x88, 0x02);
265 bySlot = C_SLOT_LONG;
267 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
269 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
270 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
271 if (pDevice->byRFType == RF_AIROHA7230) {
272 pDevice->abyBBVGA[0] = 0x1C;
273 pDevice->abyBBVGA[2] = 0x00;
274 pDevice->abyBBVGA[3] = 0x00;
275 BBbReadEmbedded(pDevice, 0xE7, &byData);
277 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
279 } else if (pDevice->byRFType == RF_UW2452) {
280 pDevice->abyBBVGA[0] = 0x14;
281 BBbReadEmbedded(pDevice, 0xE7, &byData);
282 if (byData == 0x18) {
283 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
284 BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
287 BBbWriteEmbedded(pDevice, 0x88, 0x08);
290 if (pDevice->bShortSlotTime) {
291 bySlot = C_SLOT_SHORT;
292 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
294 bySlot = C_SLOT_LONG;
295 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
300 for (i = RATE_54M; i >= RATE_6M; i--) {
301 if (pDevice->basic_rates & ((u32)(0x1 << i))) {
308 if (pDevice->byRFType == RF_RFMD2959) {
310 * bcs TX_PE will reserve 3 us hardware's processing
316 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
317 * better TX throughput; MAC will need 2 us to process, so the
318 * SIFS, DIFS can be shorter by 2 us.
322 if (pDevice->bySIFS != bySIFS) {
323 pDevice->bySIFS = bySIFS;
324 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
326 if (pDevice->byDIFS != byDIFS) {
327 pDevice->byDIFS = byDIFS;
328 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
330 if (pDevice->byEIFS != C_EIFS) {
331 pDevice->byEIFS = C_EIFS;
332 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
334 if (pDevice->bySlot != bySlot) {
335 pDevice->bySlot = bySlot;
336 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
338 BBvSetShortSlotTime(pDevice);
340 if (pDevice->byCWMaxMin != byCWMaxMin) {
341 pDevice->byCWMaxMin = byCWMaxMin;
342 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
345 CARDvSetRSPINF(pDevice, ePHYType);
351 * Description: Sync. TSF counter to BSS
352 * Get TSF offset and write to HW
356 * pDevice - The adapter to be sync.
357 * byRxRate - data rate of receive beacon
358 * qwBSSTimestamp - Rx BCN's TSF
359 * qwLocalTSF - Local TSF
365 bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
366 u64 qwBSSTimestamp, u64 qwLocalTSF)
370 if (qwBSSTimestamp != qwLocalTSF) {
371 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
372 /* adjust TSF, HW's TSF add TSF Offset reg */
373 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
374 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
375 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
381 * Description: Set NIC TSF counter for first Beacon time
382 * Get NEXTTBTT from adjusted TSF and Beacon Interval
386 * pDevice - The adapter to be set.
387 * wBeaconInterval - Beacon Interval
391 * Return Value: true if succeed; otherwise false
393 bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
394 unsigned short wBeaconInterval)
398 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); /* Get Local TSF counter */
400 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
402 /* set HW beacon interval */
403 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
404 pDevice->wBeaconInterval = wBeaconInterval;
406 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
407 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
408 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
414 * Description: Turn off Radio power
418 * pDevice - The adapter to be turned off
422 * Return Value: true if success; otherwise false
424 bool CARDbRadioPowerOff(struct vnt_private *pDevice)
428 if (pDevice->bRadioOff == true)
431 switch (pDevice->byRFType) {
433 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
434 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
440 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
441 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
446 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
448 BBvSetDeepSleep(pDevice, pDevice->byLocalID);
450 pDevice->bRadioOff = true;
451 pr_debug("chester power off\n");
452 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
457 * Description: Turn on Radio power
461 * pDevice - The adapter to be turned on
465 * Return Value: true if success; otherwise false
467 bool CARDbRadioPowerOn(struct vnt_private *pDevice)
471 pr_debug("chester power on\n");
472 if (pDevice->bRadioControlOff == true) {
473 if (pDevice->bHWRadioOff == true)
474 pr_debug("chester bHWRadioOff\n");
475 if (pDevice->bRadioControlOff == true)
476 pr_debug("chester bRadioControlOff\n");
479 if (pDevice->bRadioOff == false) {
480 pr_debug("chester pbRadioOff\n");
483 BBvExitDeepSleep(pDevice, pDevice->byLocalID);
485 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
487 switch (pDevice->byRFType) {
489 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
490 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
496 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
502 pDevice->bRadioOff = false;
503 pr_debug("chester power on\n");
504 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
510 struct vnt_private *pDevice
516 /* initialize TD index */
517 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
518 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
520 for (uu = 0; uu < TYPE_MAXTD; uu++)
521 pDevice->iTDUsed[uu] = 0;
523 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
524 pCurrTD = &(pDevice->apTD0Rings[uu]);
525 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
526 /* init all Tx Packet pointer to NULL */
528 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
529 pCurrTD = &(pDevice->apTD1Rings[uu]);
530 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
531 /* init all Tx Packet pointer to NULL */
534 /* set MAC TD pointer */
535 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
536 (pDevice->td0_pool_dma));
538 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
539 (pDevice->td1_pool_dma));
541 /* set MAC Beacon TX pointer */
542 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
543 (pDevice->tx_beacon_dma));
552 * pDevice - Pointer to the adapter
560 struct vnt_private *pDevice
566 /* initialize RD index */
567 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
568 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
570 /* init state, all RD is chip's */
571 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
572 pDesc = &(pDevice->aRD0Ring[uu]);
573 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
574 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
575 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
578 /* init state, all RD is chip's */
579 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
580 pDesc = &(pDevice->aRD1Ring[uu]);
581 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
582 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
583 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
586 /* set perPkt mode */
587 MACvRx0PerPktMode(pDevice->PortOffset);
588 MACvRx1PerPktMode(pDevice->PortOffset);
589 /* set MAC RD pointer */
590 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
591 pDevice->rd0_pool_dma);
593 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
594 pDevice->rd1_pool_dma);
598 * Description: Get response Control frame rate in CCK mode
602 * pDevice - The adapter to be set
603 * wRateIdx - Receiving data rate
607 * Return Value: response Control frame rate
609 static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
610 unsigned short wRateIdx)
612 unsigned int ui = (unsigned int) wRateIdx;
614 while (ui > RATE_1M) {
615 if (pDevice->basic_rates & ((u32)0x1 << ui))
616 return (unsigned short)ui;
620 return (unsigned short)RATE_1M;
624 * Description: Get response Control frame rate in OFDM mode
628 * pDevice - The adapter to be set
629 * wRateIdx - Receiving data rate
633 * Return Value: response Control frame rate
635 static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
636 unsigned short wRateIdx)
638 unsigned int ui = (unsigned int) wRateIdx;
640 pr_debug("BASIC RATE: %X\n", pDevice->basic_rates);
642 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
643 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
644 if (wRateIdx > RATE_24M)
648 while (ui > RATE_11M) {
649 if (pDevice->basic_rates & ((u32)0x1 << ui)) {
650 pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
651 return (unsigned short)ui;
655 pr_debug("CARDwGetOFDMControlRate: 6M\n");
656 return (unsigned short)RATE_24M;
660 * Description: Set RSPINF
664 * pDevice - The adapter to be set
668 * Return Value: None.
670 void CARDvSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType)
672 union vnt_phy_field_swap phy;
673 unsigned char byTxRate, byRsvTime; /* For OFDM */
676 MACvSelectPage1(pDevice->PortOffset);
679 vnt_get_phy_field(pDevice, 14,
680 CARDwGetCCKControlRate(pDevice, RATE_1M),
681 PK_TYPE_11B, &phy.field_read);
683 /* swap over to get correct write order */
684 swap(phy.swap[0], phy.swap[1]);
686 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
689 vnt_get_phy_field(pDevice, 14,
690 CARDwGetCCKControlRate(pDevice, RATE_2M),
691 PK_TYPE_11B, &phy.field_read);
693 swap(phy.swap[0], phy.swap[1]);
695 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
698 vnt_get_phy_field(pDevice, 14,
699 CARDwGetCCKControlRate(pDevice, RATE_5M),
700 PK_TYPE_11B, &phy.field_read);
702 swap(phy.swap[0], phy.swap[1]);
704 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
707 vnt_get_phy_field(pDevice, 14,
708 CARDwGetCCKControlRate(pDevice, RATE_11M),
709 PK_TYPE_11B, &phy.field_read);
711 swap(phy.swap[0], phy.swap[1]);
713 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
716 s_vCalculateOFDMRParameter(RATE_6M,
720 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
722 s_vCalculateOFDMRParameter(RATE_9M,
726 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
728 s_vCalculateOFDMRParameter(RATE_12M,
732 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
734 s_vCalculateOFDMRParameter(RATE_18M,
738 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
740 s_vCalculateOFDMRParameter(RATE_24M,
744 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
746 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
750 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
752 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
756 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
758 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
762 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
764 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
768 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
770 MACvSelectPage0(pDevice->PortOffset);
774 * Description: Update IFS
778 * pDevice - The adapter to be set
782 * Return Value: None.
784 void vUpdateIFS(struct vnt_private *pDevice)
786 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
788 unsigned char byMaxMin = 0;
790 if (pDevice->byPacketType == PK_TYPE_11A) { /*0000 0000 0000 0000,11a*/
791 pDevice->uSlot = C_SLOT_SHORT;
792 pDevice->uSIFS = C_SIFS_A;
793 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
794 pDevice->uCwMin = C_CWMIN_A;
796 } else if (pDevice->byPacketType == PK_TYPE_11B) {
797 /* 0000 0001 0000 0000,11b */
798 pDevice->uSlot = C_SLOT_LONG;
799 pDevice->uSIFS = C_SIFS_BG;
800 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
801 pDevice->uCwMin = C_CWMIN_B;
803 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
804 pDevice->uSIFS = C_SIFS_BG;
805 if (pDevice->bShortSlotTime)
806 pDevice->uSlot = C_SLOT_SHORT;
808 pDevice->uSlot = C_SLOT_LONG;
810 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
811 if (pDevice->wBasicRate & 0x0150) {
812 /* 0000 0001 0101 0000,24M,12M,6M */
813 pDevice->uCwMin = C_CWMIN_A;
816 pDevice->uCwMin = C_CWMIN_B;
821 pDevice->uCwMax = C_CWMAX;
822 pDevice->uEIFS = C_EIFS;
823 if (pDevice->byRFType == RF_RFMD2959) {
824 /* bcs TX_PE will reserve 3 us */
825 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
826 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
828 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
829 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
831 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
832 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
833 byMaxMin |= 0xA0; /* 1010 1111,C_CWMAX = 1023 */
834 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
837 void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
839 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
842 /* Determines the highest basic rate. */
843 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
844 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
849 pDevice->byTopOFDMBasicRate = byTopOFDM;
851 for (ii = RATE_11M;; ii--) {
852 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
859 pDevice->byTopCCKBasicRate = byTopCCK;
862 bool CARDbAddBasicRate(struct vnt_private *pDevice, unsigned short wRateIdx)
864 unsigned short wRate = (unsigned short)(1<<wRateIdx);
866 pDevice->wBasicRate |= wRate;
868 /* Determines the highest basic rate. */
869 CARDvUpdateBasicTopRate((void *)pDevice);
874 bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
878 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
879 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
885 unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
888 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
889 return (unsigned char)pDevice->byBBType;
890 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
897 * Description: Set NIC Loopback mode
901 * pDevice - The adapter to be set
902 * wLoopbackMode - Loopback mode to be set
908 void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
910 switch (wLoopbackMode) {
919 /* set MAC loopback */
920 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
921 /* set Baseband loopback */
925 * Description: Software Reset NIC
929 * pDevice - The adapter to be reset
935 bool CARDbSoftwareReset(struct vnt_private *pDevice)
939 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
946 * Description: Calculate TSF offset of two TSF input
947 * Get TSF Offset from RxBCN's TSF and local TSF
951 * pDevice - The adapter to be sync.
952 * qwTSF1 - Rx BCN's TSF
957 * Return Value: TSF Offset value
959 u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
962 unsigned short wRxBcnTSFOffst = 0;
964 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
966 qwTSF2 += (u64)wRxBcnTSFOffst;
968 qwTSFOffset = qwTSF1 - qwTSF2;
974 * Description: Read NIC TSF counter
975 * Get local TSF counter
979 * pDevice - The adapter to be read
981 * qwCurrTSF - Current TSF counter
983 * Return Value: true if success; otherwise false
985 bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF)
988 unsigned char byData;
990 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
991 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
992 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
993 if (!(byData & TFTCTL_TSFCNTRRD))
996 if (ww == W_MAX_TIMEOUT)
998 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
999 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
1005 * Description: Read NIC TSF counter
1006 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1010 * qwTSF - Current TSF counter
1011 * wbeaconInterval - Beacon Interval
1013 * qwCurrTSF - Current TSF counter
1015 * Return Value: TSF value of next Beacon
1017 u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
1021 beacon_int = wBeaconInterval * 1024;
1023 do_div(qwTSF, beacon_int);
1025 qwTSF *= beacon_int;
1032 * Description: Set NIC TSF counter for first Beacon time
1033 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1037 * dwIoBase - IO Base
1038 * wBeaconInterval - Beacon Interval
1042 * Return Value: none
1044 void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval)
1048 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); /* Get Local TSF counter */
1050 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
1052 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
1053 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
1054 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
1058 * Description: Sync NIC TSF counter for Beacon time
1059 * Get NEXTTBTT and write to HW
1063 * pDevice - The adapter to be set
1064 * qwTSF - Current TSF counter
1065 * wBeaconInterval - Beacon Interval
1069 * Return Value: none
1071 void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval)
1073 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
1075 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
1076 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
1077 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
1078 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);