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 * CARDvUpdateBasicTopRate - Update BasicTopRate
25 * CARDbAddBasicRate - Add to BasicRateSet
26 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
27 * CARDvSetLoopbackMode - Set Loopback mode
28 * CARDbSoftwareReset - Sortware reset NIC
29 * CARDqGetTSFOffset - Calculate TSFOffset
30 * CARDbGetCurrentTSF - Read Current NIC TSF counter
31 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
32 * CARDvSetFirstNextTBTT - Set NIC Beacon time
33 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
34 * CARDbRadioPowerOff - Turn Off NIC Radio Power
35 * CARDbRadioPowerOn - Turn On NIC Radio Power
38 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
39 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
40 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
52 /*--------------------- Static Definitions -------------------------*/
54 #define C_SIFS_A 16 /* micro sec. */
57 #define C_EIFS 80 /* micro sec. */
59 #define C_SLOT_SHORT 9 /* micro sec. */
60 #define C_SLOT_LONG 20
62 #define C_CWMIN_A 15 /* slot time */
65 #define C_CWMAX 1023 /* slot time */
67 #define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
69 /*--------------------- Static Variables --------------------------*/
71 static const unsigned short cwRXBCNTSFOff
[MAX_RATE
] = {
72 17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
74 /*--------------------- Static Functions --------------------------*/
78 s_vCalculateOFDMRParameter(
81 unsigned char *pbyTxRate
,
82 unsigned char *pbyRsvTime
85 /*--------------------- Export Functions --------------------------*/
88 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
93 * byPktType - Tx Packet type
95 * pbyTxRate - pointer to RSPINF TxRate field
96 * pbyRsvTime - pointer to RSPINF RsvTime field
102 s_vCalculateOFDMRParameter(
103 unsigned char byRate
,
105 unsigned char *pbyTxRate
,
106 unsigned char *pbyRsvTime
111 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
121 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
131 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
141 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
151 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
161 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
171 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
182 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
193 /*--------------------- Export Functions --------------------------*/
196 * Description: Update IFS
200 * pDevice - The adapter to be set
204 * Return Value: None.
206 bool CARDbSetPhyParameter(struct vnt_private
*pDevice
, u8 bb_type
)
208 unsigned char byCWMaxMin
= 0;
209 unsigned char bySlot
= 0;
210 unsigned char bySIFS
= 0;
211 unsigned char byDIFS
= 0;
212 unsigned char byData
;
215 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
216 if (bb_type
== BB_TYPE_11A
) {
217 if (pDevice
->byRFType
== RF_AIROHA7230
) {
218 /* AL7230 use single PAPE and connect to PAPE_2.4G */
219 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11G
);
220 pDevice
->abyBBVGA
[0] = 0x20;
221 pDevice
->abyBBVGA
[2] = 0x10;
222 pDevice
->abyBBVGA
[3] = 0x10;
223 BBbReadEmbedded(pDevice
, 0xE7, &byData
);
225 BBbWriteEmbedded(pDevice
, 0xE7, pDevice
->abyBBVGA
[0]);
227 } else if (pDevice
->byRFType
== RF_UW2452
) {
228 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11A
);
229 pDevice
->abyBBVGA
[0] = 0x18;
230 BBbReadEmbedded(pDevice
, 0xE7, &byData
);
231 if (byData
== 0x14) {
232 BBbWriteEmbedded(pDevice
, 0xE7, pDevice
->abyBBVGA
[0]);
233 BBbWriteEmbedded(pDevice
, 0xE1, 0x57);
236 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11A
);
238 BBbWriteEmbedded(pDevice
, 0x88, 0x03);
239 bySlot
= C_SLOT_SHORT
;
241 byDIFS
= C_SIFS_A
+ 2*C_SLOT_SHORT
;
243 } else if (bb_type
== BB_TYPE_11B
) {
244 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11B
);
245 if (pDevice
->byRFType
== RF_AIROHA7230
) {
246 pDevice
->abyBBVGA
[0] = 0x1C;
247 pDevice
->abyBBVGA
[2] = 0x00;
248 pDevice
->abyBBVGA
[3] = 0x00;
249 BBbReadEmbedded(pDevice
, 0xE7, &byData
);
251 BBbWriteEmbedded(pDevice
, 0xE7, pDevice
->abyBBVGA
[0]);
253 } else if (pDevice
->byRFType
== RF_UW2452
) {
254 pDevice
->abyBBVGA
[0] = 0x14;
255 BBbReadEmbedded(pDevice
, 0xE7, &byData
);
256 if (byData
== 0x18) {
257 BBbWriteEmbedded(pDevice
, 0xE7, pDevice
->abyBBVGA
[0]);
258 BBbWriteEmbedded(pDevice
, 0xE1, 0xD3);
261 BBbWriteEmbedded(pDevice
, 0x88, 0x02);
262 bySlot
= C_SLOT_LONG
;
264 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
266 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
267 MACvSetBBType(pDevice
->PortOffset
, BB_TYPE_11G
);
268 if (pDevice
->byRFType
== RF_AIROHA7230
) {
269 pDevice
->abyBBVGA
[0] = 0x1C;
270 pDevice
->abyBBVGA
[2] = 0x00;
271 pDevice
->abyBBVGA
[3] = 0x00;
272 BBbReadEmbedded(pDevice
, 0xE7, &byData
);
274 BBbWriteEmbedded(pDevice
, 0xE7, pDevice
->abyBBVGA
[0]);
276 } else if (pDevice
->byRFType
== RF_UW2452
) {
277 pDevice
->abyBBVGA
[0] = 0x14;
278 BBbReadEmbedded(pDevice
, 0xE7, &byData
);
279 if (byData
== 0x18) {
280 BBbWriteEmbedded(pDevice
, 0xE7, pDevice
->abyBBVGA
[0]);
281 BBbWriteEmbedded(pDevice
, 0xE1, 0xD3);
284 BBbWriteEmbedded(pDevice
, 0x88, 0x08);
287 if (pDevice
->bShortSlotTime
) {
288 bySlot
= C_SLOT_SHORT
;
289 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_SHORT
;
291 bySlot
= C_SLOT_LONG
;
292 byDIFS
= C_SIFS_BG
+ 2*C_SLOT_LONG
;
297 for (i
= RATE_54M
; i
>= RATE_6M
; i
--) {
298 if (pDevice
->basic_rates
& ((u32
)(0x1 << i
))) {
305 if (pDevice
->byRFType
== RF_RFMD2959
) {
307 * bcs TX_PE will reserve 3 us hardware's processing
313 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
314 * better TX throughput; MAC will need 2 us to process, so the
315 * SIFS, DIFS can be shorter by 2 us.
319 if (pDevice
->bySIFS
!= bySIFS
) {
320 pDevice
->bySIFS
= bySIFS
;
321 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SIFS
, pDevice
->bySIFS
);
323 if (pDevice
->byDIFS
!= byDIFS
) {
324 pDevice
->byDIFS
= byDIFS
;
325 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_DIFS
, pDevice
->byDIFS
);
327 if (pDevice
->byEIFS
!= C_EIFS
) {
328 pDevice
->byEIFS
= C_EIFS
;
329 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_EIFS
, pDevice
->byEIFS
);
331 if (pDevice
->bySlot
!= bySlot
) {
332 pDevice
->bySlot
= bySlot
;
333 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SLOT
, pDevice
->bySlot
);
335 BBvSetShortSlotTime(pDevice
);
337 if (pDevice
->byCWMaxMin
!= byCWMaxMin
) {
338 pDevice
->byCWMaxMin
= byCWMaxMin
;
339 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_CWMAXMIN0
, pDevice
->byCWMaxMin
);
342 pDevice
->byPacketType
= CARDbyGetPktType(pDevice
);
344 CARDvSetRSPINF(pDevice
, bb_type
);
350 * Description: Sync. TSF counter to BSS
351 * Get TSF offset and write to HW
355 * pDevice - The adapter to be sync.
356 * byRxRate - data rate of receive beacon
357 * qwBSSTimestamp - Rx BCN's TSF
358 * qwLocalTSF - Local TSF
364 bool CARDbUpdateTSF(struct vnt_private
*pDevice
, unsigned char byRxRate
,
365 u64 qwBSSTimestamp
, u64 qwLocalTSF
)
369 if (qwBSSTimestamp
!= qwLocalTSF
) {
370 qwTSFOffset
= CARDqGetTSFOffset(byRxRate
, qwBSSTimestamp
, qwLocalTSF
);
371 /* adjust TSF, HW's TSF add TSF Offset reg */
372 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_TSFOFST
, (u32
)qwTSFOffset
);
373 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_TSFOFST
+ 4, (u32
)(qwTSFOffset
>> 32));
374 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TSFSYNCEN
);
380 * Description: Set NIC TSF counter for first Beacon time
381 * Get NEXTTBTT from adjusted TSF and Beacon Interval
385 * pDevice - The adapter to be set.
386 * wBeaconInterval - Beacon Interval
390 * Return Value: true if succeed; otherwise false
392 bool CARDbSetBeaconPeriod(struct vnt_private
*pDevice
,
393 unsigned short wBeaconInterval
)
397 CARDbGetCurrentTSF(pDevice
, &qwNextTBTT
); /* Get Local TSF counter */
399 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
401 /* set HW beacon interval */
402 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_BI
, wBeaconInterval
);
403 pDevice
->wBeaconInterval
= wBeaconInterval
;
405 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
406 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwNextTBTT
>> 32));
407 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
413 * Description: Turn off Radio power
417 * pDevice - The adapter to be turned off
421 * Return Value: true if success; otherwise false
423 bool CARDbRadioPowerOff(struct vnt_private
*pDevice
)
427 if (pDevice
->bRadioOff
== true)
430 switch (pDevice
->byRFType
) {
432 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_TXPEINV
);
433 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE1
);
439 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE2
);
440 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE3
);
445 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
447 BBvSetDeepSleep(pDevice
, pDevice
->byLocalID
);
449 pDevice
->bRadioOff
= true;
450 pr_debug("chester power off\n");
451 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_GPIOCTL0
, LED_ACTSET
); /* LED issue */
456 * Description: Turn on Radio power
460 * pDevice - The adapter to be turned on
464 * Return Value: true if success; otherwise false
466 bool CARDbRadioPowerOn(struct vnt_private
*pDevice
)
470 pr_debug("chester power on\n");
471 if (pDevice
->bRadioControlOff
== true) {
472 if (pDevice
->bHWRadioOff
== true)
473 pr_debug("chester bHWRadioOff\n");
474 if (pDevice
->bRadioControlOff
== true)
475 pr_debug("chester bRadioControlOff\n");
478 if (pDevice
->bRadioOff
== false) {
479 pr_debug("chester pbRadioOff\n");
482 BBvExitDeepSleep(pDevice
, pDevice
->byLocalID
);
484 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
486 switch (pDevice
->byRFType
) {
488 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_TXPEINV
);
489 MACvWordRegBitsOff(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPE1
);
495 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_SOFTPWRCTL
, (SOFTPWRCTL_SWPE2
|
501 pDevice
->bRadioOff
= false;
502 pr_debug("chester power on\n");
503 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_GPIOCTL0
, LED_ACTSET
); /* LED issue */
509 struct vnt_private
*pDevice
515 /* initialize TD index */
516 pDevice
->apTailTD
[0] = pDevice
->apCurrTD
[0] = &(pDevice
->apTD0Rings
[0]);
517 pDevice
->apTailTD
[1] = pDevice
->apCurrTD
[1] = &(pDevice
->apTD1Rings
[0]);
519 for (uu
= 0; uu
< TYPE_MAXTD
; uu
++)
520 pDevice
->iTDUsed
[uu
] = 0;
522 for (uu
= 0; uu
< pDevice
->sOpts
.nTxDescs
[0]; uu
++) {
523 pCurrTD
= &(pDevice
->apTD0Rings
[uu
]);
524 pCurrTD
->m_td0TD0
.f1Owner
= OWNED_BY_HOST
;
525 /* init all Tx Packet pointer to NULL */
527 for (uu
= 0; uu
< pDevice
->sOpts
.nTxDescs
[1]; uu
++) {
528 pCurrTD
= &(pDevice
->apTD1Rings
[uu
]);
529 pCurrTD
->m_td0TD0
.f1Owner
= OWNED_BY_HOST
;
530 /* init all Tx Packet pointer to NULL */
533 /* set MAC TD pointer */
534 MACvSetCurrTXDescAddr(TYPE_TXDMA0
, pDevice
->PortOffset
,
535 (pDevice
->td0_pool_dma
));
537 MACvSetCurrTXDescAddr(TYPE_AC0DMA
, pDevice
->PortOffset
,
538 (pDevice
->td1_pool_dma
));
540 /* set MAC Beacon TX pointer */
541 MACvSetCurrBCNTxDescAddr(pDevice
->PortOffset
,
542 (pDevice
->tx_beacon_dma
));
551 * pDevice - Pointer to the adapter
559 struct vnt_private
*pDevice
565 /* initialize RD index */
566 pDevice
->pCurrRD
[0] = &(pDevice
->aRD0Ring
[0]);
567 pDevice
->pCurrRD
[1] = &(pDevice
->aRD1Ring
[0]);
569 /* init state, all RD is chip's */
570 for (uu
= 0; uu
< pDevice
->sOpts
.nRxDescs0
; uu
++) {
571 pDesc
= &(pDevice
->aRD0Ring
[uu
]);
572 pDesc
->m_rd0RD0
.wResCount
= (unsigned short)(pDevice
->rx_buf_sz
);
573 pDesc
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
574 pDesc
->m_rd1RD1
.wReqCount
= (unsigned short)(pDevice
->rx_buf_sz
);
577 /* init state, all RD is chip's */
578 for (uu
= 0; uu
< pDevice
->sOpts
.nRxDescs1
; uu
++) {
579 pDesc
= &(pDevice
->aRD1Ring
[uu
]);
580 pDesc
->m_rd0RD0
.wResCount
= (unsigned short)(pDevice
->rx_buf_sz
);
581 pDesc
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
582 pDesc
->m_rd1RD1
.wReqCount
= (unsigned short)(pDevice
->rx_buf_sz
);
585 /* set perPkt mode */
586 MACvRx0PerPktMode(pDevice
->PortOffset
);
587 MACvRx1PerPktMode(pDevice
->PortOffset
);
588 /* set MAC RD pointer */
589 MACvSetCurrRx0DescAddr(pDevice
->PortOffset
,
590 pDevice
->rd0_pool_dma
);
592 MACvSetCurrRx1DescAddr(pDevice
->PortOffset
,
593 pDevice
->rd1_pool_dma
);
597 * Description: Get response Control frame rate in CCK mode
601 * pDevice - The adapter to be set
602 * wRateIdx - Receiving data rate
606 * Return Value: response Control frame rate
608 static unsigned short CARDwGetCCKControlRate(struct vnt_private
*pDevice
,
609 unsigned short wRateIdx
)
611 unsigned int ui
= (unsigned int) wRateIdx
;
613 while (ui
> RATE_1M
) {
614 if (pDevice
->basic_rates
& ((u32
)0x1 << ui
))
615 return (unsigned short)ui
;
619 return (unsigned short)RATE_1M
;
623 * Description: Get response Control frame rate in OFDM mode
627 * pDevice - The adapter to be set
628 * wRateIdx - Receiving data rate
632 * Return Value: response Control frame rate
634 static unsigned short CARDwGetOFDMControlRate(struct vnt_private
*pDevice
,
635 unsigned short wRateIdx
)
637 unsigned int ui
= (unsigned int) wRateIdx
;
639 pr_debug("BASIC RATE: %X\n", pDevice
->basic_rates
);
641 if (!CARDbIsOFDMinBasicRate((void *)pDevice
)) {
642 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx
);
643 if (wRateIdx
> RATE_24M
)
647 while (ui
> RATE_11M
) {
648 if (pDevice
->basic_rates
& ((u32
)0x1 << ui
)) {
649 pr_debug("CARDwGetOFDMControlRate : %d\n", ui
);
650 return (unsigned short)ui
;
654 pr_debug("CARDwGetOFDMControlRate: 6M\n");
655 return (unsigned short)RATE_24M
;
659 * Description: Set RSPINF
663 * pDevice - The adapter to be set
667 * Return Value: None.
669 void CARDvSetRSPINF(struct vnt_private
*pDevice
, u8 bb_type
)
671 union vnt_phy_field_swap phy
;
672 unsigned char byTxRate
, byRsvTime
; /* For OFDM */
675 spin_lock_irqsave(&pDevice
->lock
, flags
);
678 MACvSelectPage1(pDevice
->PortOffset
);
681 vnt_get_phy_field(pDevice
, 14,
682 CARDwGetCCKControlRate(pDevice
, RATE_1M
),
683 PK_TYPE_11B
, &phy
.field_read
);
685 /* swap over to get correct write order */
686 swap(phy
.swap
[0], phy
.swap
[1]);
688 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_1
, phy
.field_write
);
691 vnt_get_phy_field(pDevice
, 14,
692 CARDwGetCCKControlRate(pDevice
, RATE_2M
),
693 PK_TYPE_11B
, &phy
.field_read
);
695 swap(phy
.swap
[0], phy
.swap
[1]);
697 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_2
, phy
.field_write
);
700 vnt_get_phy_field(pDevice
, 14,
701 CARDwGetCCKControlRate(pDevice
, RATE_5M
),
702 PK_TYPE_11B
, &phy
.field_read
);
704 swap(phy
.swap
[0], phy
.swap
[1]);
706 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_5
, phy
.field_write
);
709 vnt_get_phy_field(pDevice
, 14,
710 CARDwGetCCKControlRate(pDevice
, RATE_11M
),
711 PK_TYPE_11B
, &phy
.field_read
);
713 swap(phy
.swap
[0], phy
.swap
[1]);
715 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_RSPINF_B_11
, phy
.field_write
);
718 s_vCalculateOFDMRParameter(RATE_6M
,
722 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_6
, MAKEWORD(byTxRate
, byRsvTime
));
724 s_vCalculateOFDMRParameter(RATE_9M
,
728 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_9
, MAKEWORD(byTxRate
, byRsvTime
));
730 s_vCalculateOFDMRParameter(RATE_12M
,
734 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_12
, MAKEWORD(byTxRate
, byRsvTime
));
736 s_vCalculateOFDMRParameter(RATE_18M
,
740 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_18
, MAKEWORD(byTxRate
, byRsvTime
));
742 s_vCalculateOFDMRParameter(RATE_24M
,
746 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_24
, MAKEWORD(byTxRate
, byRsvTime
));
748 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_36M
),
752 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_36
, MAKEWORD(byTxRate
, byRsvTime
));
754 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_48M
),
758 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_48
, MAKEWORD(byTxRate
, byRsvTime
));
760 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_54M
),
764 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_54
, MAKEWORD(byTxRate
, byRsvTime
));
766 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice
, RATE_54M
),
770 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_RSPINF_A_72
, MAKEWORD(byTxRate
, byRsvTime
));
772 MACvSelectPage0(pDevice
->PortOffset
);
774 spin_unlock_irqrestore(&pDevice
->lock
, flags
);
777 void CARDvUpdateBasicTopRate(struct vnt_private
*pDevice
)
779 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
782 /* Determines the highest basic rate. */
783 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
784 if ((pDevice
->basic_rates
) & ((u32
)(1 << ii
))) {
789 pDevice
->byTopOFDMBasicRate
= byTopOFDM
;
791 for (ii
= RATE_11M
;; ii
--) {
792 if ((pDevice
->basic_rates
) & ((u32
)(1 << ii
))) {
799 pDevice
->byTopCCKBasicRate
= byTopCCK
;
802 bool CARDbIsOFDMinBasicRate(struct vnt_private
*pDevice
)
806 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
807 if ((pDevice
->basic_rates
) & ((u32
)(1 << ii
)))
813 unsigned char CARDbyGetPktType(struct vnt_private
*pDevice
)
816 if (pDevice
->byBBType
== BB_TYPE_11A
|| pDevice
->byBBType
== BB_TYPE_11B
)
817 return (unsigned char)pDevice
->byBBType
;
818 else if (CARDbIsOFDMinBasicRate((void *)pDevice
))
825 * Description: Set NIC Loopback mode
829 * pDevice - The adapter to be set
830 * wLoopbackMode - Loopback mode to be set
836 void CARDvSetLoopbackMode(struct vnt_private
*priv
, unsigned short wLoopbackMode
)
838 void __iomem
*dwIoBase
= priv
->PortOffset
;
840 switch (wLoopbackMode
) {
849 /* set MAC loopback */
850 MACvSetLoopbackMode(dwIoBase
, LOBYTE(wLoopbackMode
));
851 /* set Baseband loopback */
855 * Description: Software Reset NIC
859 * pDevice - The adapter to be reset
865 bool CARDbSoftwareReset(struct vnt_private
*pDevice
)
869 if (!MACbSafeSoftwareReset(pDevice
->PortOffset
))
876 * Description: Calculate TSF offset of two TSF input
877 * Get TSF Offset from RxBCN's TSF and local TSF
881 * pDevice - The adapter to be sync.
882 * qwTSF1 - Rx BCN's TSF
887 * Return Value: TSF Offset value
889 u64
CARDqGetTSFOffset(unsigned char byRxRate
, u64 qwTSF1
, u64 qwTSF2
)
892 unsigned short wRxBcnTSFOffst
= 0;
894 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
%MAX_RATE
];
896 qwTSF2
+= (u64
)wRxBcnTSFOffst
;
898 qwTSFOffset
= qwTSF1
- qwTSF2
;
904 * Description: Read NIC TSF counter
905 * Get local TSF counter
909 * pDevice - The adapter to be read
911 * qwCurrTSF - Current TSF counter
913 * Return Value: true if success; otherwise false
915 bool CARDbGetCurrentTSF(struct vnt_private
*priv
, u64
*pqwCurrTSF
)
917 void __iomem
*dwIoBase
= priv
->PortOffset
;
919 unsigned char byData
;
921 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
922 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
923 VNSvInPortB(dwIoBase
+ MAC_REG_TFTCTL
, &byData
);
924 if (!(byData
& TFTCTL_TSFCNTRRD
))
927 if (ww
== W_MAX_TIMEOUT
)
929 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
, (u32
*)pqwCurrTSF
);
930 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
+ 4, (u32
*)pqwCurrTSF
+ 1);
936 * Description: Read NIC TSF counter
937 * Get NEXTTBTT from adjusted TSF and Beacon Interval
941 * qwTSF - Current TSF counter
942 * wbeaconInterval - Beacon Interval
944 * qwCurrTSF - Current TSF counter
946 * Return Value: TSF value of next Beacon
948 u64
CARDqGetNextTBTT(u64 qwTSF
, unsigned short wBeaconInterval
)
952 beacon_int
= wBeaconInterval
* 1024;
954 do_div(qwTSF
, beacon_int
);
963 * Description: Set NIC TSF counter for first Beacon time
964 * Get NEXTTBTT from adjusted TSF and Beacon Interval
969 * wBeaconInterval - Beacon Interval
975 void CARDvSetFirstNextTBTT(struct vnt_private
*priv
, unsigned short wBeaconInterval
)
977 void __iomem
*dwIoBase
= priv
->PortOffset
;
980 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
982 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
984 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
985 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwNextTBTT
>> 32));
986 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
990 * Description: Sync NIC TSF counter for Beacon time
991 * Get NEXTTBTT and write to HW
995 * pDevice - The adapter to be set
996 * qwTSF - Current TSF counter
997 * wBeaconInterval - Beacon Interval
1001 * Return Value: none
1003 void CARDvUpdateNextTBTT(struct vnt_private
*priv
, u64 qwTSF
, unsigned short wBeaconInterval
)
1005 void __iomem
*dwIoBase
= priv
->PortOffset
;
1007 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
1009 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, (u32
)qwTSF
);
1010 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwTSF
>> 32));
1011 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1012 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF
);