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 * priv - The adapter to be set
204 * Return Value: None.
206 bool CARDbSetPhyParameter(struct vnt_private
*priv
, 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 (priv
->byRFType
== RF_AIROHA7230
) {
218 /* AL7230 use single PAPE and connect to PAPE_2.4G */
219 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11G
);
220 priv
->abyBBVGA
[0] = 0x20;
221 priv
->abyBBVGA
[2] = 0x10;
222 priv
->abyBBVGA
[3] = 0x10;
223 BBbReadEmbedded(priv
, 0xE7, &byData
);
225 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
227 } else if (priv
->byRFType
== RF_UW2452
) {
228 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11A
);
229 priv
->abyBBVGA
[0] = 0x18;
230 BBbReadEmbedded(priv
, 0xE7, &byData
);
231 if (byData
== 0x14) {
232 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
233 BBbWriteEmbedded(priv
, 0xE1, 0x57);
236 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11A
);
238 BBbWriteEmbedded(priv
, 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(priv
->PortOffset
, BB_TYPE_11B
);
245 if (priv
->byRFType
== RF_AIROHA7230
) {
246 priv
->abyBBVGA
[0] = 0x1C;
247 priv
->abyBBVGA
[2] = 0x00;
248 priv
->abyBBVGA
[3] = 0x00;
249 BBbReadEmbedded(priv
, 0xE7, &byData
);
251 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
253 } else if (priv
->byRFType
== RF_UW2452
) {
254 priv
->abyBBVGA
[0] = 0x14;
255 BBbReadEmbedded(priv
, 0xE7, &byData
);
256 if (byData
== 0x18) {
257 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
258 BBbWriteEmbedded(priv
, 0xE1, 0xD3);
261 BBbWriteEmbedded(priv
, 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(priv
->PortOffset
, BB_TYPE_11G
);
268 if (priv
->byRFType
== RF_AIROHA7230
) {
269 priv
->abyBBVGA
[0] = 0x1C;
270 priv
->abyBBVGA
[2] = 0x00;
271 priv
->abyBBVGA
[3] = 0x00;
272 BBbReadEmbedded(priv
, 0xE7, &byData
);
274 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
276 } else if (priv
->byRFType
== RF_UW2452
) {
277 priv
->abyBBVGA
[0] = 0x14;
278 BBbReadEmbedded(priv
, 0xE7, &byData
);
279 if (byData
== 0x18) {
280 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
281 BBbWriteEmbedded(priv
, 0xE1, 0xD3);
284 BBbWriteEmbedded(priv
, 0x88, 0x08);
287 if (priv
->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 (priv
->basic_rates
& ((u32
)(0x1 << i
))) {
305 if (priv
->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 (priv
->bySIFS
!= bySIFS
) {
320 priv
->bySIFS
= bySIFS
;
321 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_SIFS
, priv
->bySIFS
);
323 if (priv
->byDIFS
!= byDIFS
) {
324 priv
->byDIFS
= byDIFS
;
325 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_DIFS
, priv
->byDIFS
);
327 if (priv
->byEIFS
!= C_EIFS
) {
328 priv
->byEIFS
= C_EIFS
;
329 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_EIFS
, priv
->byEIFS
);
331 if (priv
->bySlot
!= bySlot
) {
332 priv
->bySlot
= bySlot
;
333 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_SLOT
, priv
->bySlot
);
335 BBvSetShortSlotTime(priv
);
337 if (priv
->byCWMaxMin
!= byCWMaxMin
) {
338 priv
->byCWMaxMin
= byCWMaxMin
;
339 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_CWMAXMIN0
,
343 priv
->byPacketType
= CARDbyGetPktType(priv
);
345 CARDvSetRSPINF(priv
, bb_type
);
351 * Description: Sync. TSF counter to BSS
352 * Get TSF offset and write to HW
356 * priv - 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
*priv
, unsigned char byRxRate
,
371 CARDbGetCurrentTSF(priv
, &local_tsf
);
373 if (qwBSSTimestamp
!= local_tsf
) {
374 qwTSFOffset
= CARDqGetTSFOffset(byRxRate
, qwBSSTimestamp
,
376 /* adjust TSF, HW's TSF add TSF Offset reg */
377 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_TSFOFST
,
379 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_TSFOFST
+ 4,
380 (u32
)(qwTSFOffset
>> 32));
381 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TFTCTL
,
388 * Description: Set NIC TSF counter for first Beacon time
389 * Get NEXTTBTT from adjusted TSF and Beacon Interval
393 * priv - The adapter to be set.
394 * wBeaconInterval - Beacon Interval
398 * Return Value: true if succeed; otherwise false
400 bool CARDbSetBeaconPeriod(struct vnt_private
*priv
,
401 unsigned short wBeaconInterval
)
405 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
407 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
409 /* set HW beacon interval */
410 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_BI
, wBeaconInterval
);
411 priv
->wBeaconInterval
= wBeaconInterval
;
413 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
414 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_NEXTTBTT
+ 4,
415 (u32
)(qwNextTBTT
>> 32));
416 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
422 * Description: Turn off Radio power
426 * priv - The adapter to be turned off
430 * Return Value: true if success; otherwise false
432 bool CARDbRadioPowerOff(struct vnt_private
*priv
)
439 switch (priv
->byRFType
) {
441 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
443 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
450 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
452 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
457 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
459 BBvSetDeepSleep(priv
, priv
->byLocalID
);
461 priv
->bRadioOff
= true;
462 pr_debug("chester power off\n");
463 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_GPIOCTL0
,
464 LED_ACTSET
); /* LED issue */
469 * Description: Turn on Radio power
473 * priv - The adapter to be turned on
477 * Return Value: true if success; otherwise false
479 bool CARDbRadioPowerOn(struct vnt_private
*priv
)
483 pr_debug("chester power on\n");
484 if (priv
->bRadioControlOff
) {
485 if (priv
->bHWRadioOff
)
486 pr_debug("chester bHWRadioOff\n");
487 if (priv
->bRadioControlOff
)
488 pr_debug("chester bRadioControlOff\n");
491 if (!priv
->bRadioOff
) {
492 pr_debug("chester pbRadioOff\n");
495 BBvExitDeepSleep(priv
, priv
->byLocalID
);
497 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
499 switch (priv
->byRFType
) {
501 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
503 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
510 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
511 (SOFTPWRCTL_SWPE2
| SOFTPWRCTL_SWPE3
));
515 priv
->bRadioOff
= false;
516 pr_debug("chester power on\n");
517 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_GPIOCTL0
,
518 LED_ACTSET
); /* LED issue */
524 struct vnt_private
*priv
528 struct vnt_tx_desc
*pCurrTD
;
530 /* initialize TD index */
531 priv
->apTailTD
[0] = priv
->apCurrTD
[0] = &(priv
->apTD0Rings
[0]);
532 priv
->apTailTD
[1] = priv
->apCurrTD
[1] = &(priv
->apTD1Rings
[0]);
534 for (uu
= 0; uu
< TYPE_MAXTD
; uu
++)
535 priv
->iTDUsed
[uu
] = 0;
537 for (uu
= 0; uu
< priv
->opts
.tx_descs
[0]; uu
++) {
538 pCurrTD
= &(priv
->apTD0Rings
[uu
]);
539 pCurrTD
->td0
.owner
= OWNED_BY_HOST
;
540 /* init all Tx Packet pointer to NULL */
542 for (uu
= 0; uu
< priv
->opts
.tx_descs
[1]; uu
++) {
543 pCurrTD
= &(priv
->apTD1Rings
[uu
]);
544 pCurrTD
->td0
.owner
= OWNED_BY_HOST
;
545 /* init all Tx Packet pointer to NULL */
548 /* set MAC TD pointer */
549 MACvSetCurrTXDescAddr(TYPE_TXDMA0
, priv
, priv
->td0_pool_dma
);
551 MACvSetCurrTXDescAddr(TYPE_AC0DMA
, priv
, priv
->td1_pool_dma
);
553 /* set MAC Beacon TX pointer */
554 MACvSetCurrBCNTxDescAddr(priv
->PortOffset
,
555 (priv
->tx_beacon_dma
));
564 * priv - Pointer to the adapter
572 struct vnt_private
*priv
576 struct vnt_rx_desc
*pDesc
;
578 /* initialize RD index */
579 priv
->pCurrRD
[0] = &(priv
->aRD0Ring
[0]);
580 priv
->pCurrRD
[1] = &(priv
->aRD1Ring
[0]);
582 /* init state, all RD is chip's */
583 for (uu
= 0; uu
< priv
->opts
.rx_descs0
; uu
++) {
584 pDesc
= &(priv
->aRD0Ring
[uu
]);
585 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
586 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
587 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
590 /* init state, all RD is chip's */
591 for (uu
= 0; uu
< priv
->opts
.rx_descs1
; uu
++) {
592 pDesc
= &(priv
->aRD1Ring
[uu
]);
593 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
594 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
595 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
598 /* set perPkt mode */
599 MACvRx0PerPktMode(priv
->PortOffset
);
600 MACvRx1PerPktMode(priv
->PortOffset
);
601 /* set MAC RD pointer */
602 MACvSetCurrRx0DescAddr(priv
, priv
->rd0_pool_dma
);
604 MACvSetCurrRx1DescAddr(priv
, priv
->rd1_pool_dma
);
608 * Description: Get response Control frame rate in CCK mode
612 * priv - The adapter to be set
613 * wRateIdx - Receiving data rate
617 * Return Value: response Control frame rate
619 static unsigned short CARDwGetCCKControlRate(struct vnt_private
*priv
,
620 unsigned short wRateIdx
)
622 unsigned int ui
= (unsigned int)wRateIdx
;
624 while (ui
> RATE_1M
) {
625 if (priv
->basic_rates
& ((u32
)0x1 << ui
))
626 return (unsigned short)ui
;
630 return (unsigned short)RATE_1M
;
634 * Description: Get response Control frame rate in OFDM mode
638 * priv - The adapter to be set
639 * wRateIdx - Receiving data rate
643 * Return Value: response Control frame rate
645 static unsigned short CARDwGetOFDMControlRate(struct vnt_private
*priv
,
646 unsigned short wRateIdx
)
648 unsigned int ui
= (unsigned int)wRateIdx
;
650 pr_debug("BASIC RATE: %X\n", priv
->basic_rates
);
652 if (!CARDbIsOFDMinBasicRate((void *)priv
)) {
653 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx
);
654 if (wRateIdx
> RATE_24M
)
658 while (ui
> RATE_11M
) {
659 if (priv
->basic_rates
& ((u32
)0x1 << ui
)) {
660 pr_debug("CARDwGetOFDMControlRate : %d\n", ui
);
661 return (unsigned short)ui
;
665 pr_debug("CARDwGetOFDMControlRate: 6M\n");
666 return (unsigned short)RATE_24M
;
670 * Description: Set RSPINF
674 * priv - The adapter to be set
678 * Return Value: None.
680 void CARDvSetRSPINF(struct vnt_private
*priv
, u8 bb_type
)
682 union vnt_phy_field_swap phy
;
683 unsigned char byTxRate
, byRsvTime
; /* For OFDM */
686 spin_lock_irqsave(&priv
->lock
, flags
);
689 MACvSelectPage1(priv
->PortOffset
);
692 vnt_get_phy_field(priv
, 14,
693 CARDwGetCCKControlRate(priv
, RATE_1M
),
694 PK_TYPE_11B
, &phy
.field_read
);
696 /* swap over to get correct write order */
697 swap(phy
.swap
[0], phy
.swap
[1]);
699 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_1
, phy
.field_write
);
702 vnt_get_phy_field(priv
, 14,
703 CARDwGetCCKControlRate(priv
, RATE_2M
),
704 PK_TYPE_11B
, &phy
.field_read
);
706 swap(phy
.swap
[0], phy
.swap
[1]);
708 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_2
, phy
.field_write
);
711 vnt_get_phy_field(priv
, 14,
712 CARDwGetCCKControlRate(priv
, RATE_5M
),
713 PK_TYPE_11B
, &phy
.field_read
);
715 swap(phy
.swap
[0], phy
.swap
[1]);
717 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_5
, phy
.field_write
);
720 vnt_get_phy_field(priv
, 14,
721 CARDwGetCCKControlRate(priv
, RATE_11M
),
722 PK_TYPE_11B
, &phy
.field_read
);
724 swap(phy
.swap
[0], phy
.swap
[1]);
726 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_11
, phy
.field_write
);
729 s_vCalculateOFDMRParameter(RATE_6M
,
733 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_6
,
734 MAKEWORD(byTxRate
, byRsvTime
));
736 s_vCalculateOFDMRParameter(RATE_9M
,
740 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_9
,
741 MAKEWORD(byTxRate
, byRsvTime
));
743 s_vCalculateOFDMRParameter(RATE_12M
,
747 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_12
,
748 MAKEWORD(byTxRate
, byRsvTime
));
750 s_vCalculateOFDMRParameter(RATE_18M
,
754 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_18
,
755 MAKEWORD(byTxRate
, byRsvTime
));
757 s_vCalculateOFDMRParameter(RATE_24M
,
761 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_24
,
762 MAKEWORD(byTxRate
, byRsvTime
));
764 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
770 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_36
,
771 MAKEWORD(byTxRate
, byRsvTime
));
773 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
779 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_48
,
780 MAKEWORD(byTxRate
, byRsvTime
));
782 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
788 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_54
,
789 MAKEWORD(byTxRate
, byRsvTime
));
791 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
797 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_72
,
798 MAKEWORD(byTxRate
, byRsvTime
));
800 MACvSelectPage0(priv
->PortOffset
);
802 spin_unlock_irqrestore(&priv
->lock
, flags
);
805 void CARDvUpdateBasicTopRate(struct vnt_private
*priv
)
807 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
810 /* Determines the highest basic rate. */
811 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
812 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
817 priv
->byTopOFDMBasicRate
= byTopOFDM
;
819 for (ii
= RATE_11M
;; ii
--) {
820 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
827 priv
->byTopCCKBasicRate
= byTopCCK
;
830 bool CARDbIsOFDMinBasicRate(struct vnt_private
*priv
)
834 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
835 if ((priv
->basic_rates
) & ((u32
)BIT(ii
)))
841 unsigned char CARDbyGetPktType(struct vnt_private
*priv
)
843 if (priv
->byBBType
== BB_TYPE_11A
|| priv
->byBBType
== BB_TYPE_11B
)
844 return (unsigned char)priv
->byBBType
;
845 else if (CARDbIsOFDMinBasicRate((void *)priv
))
852 * Description: Set NIC Loopback mode
856 * priv - The adapter to be set
857 * wLoopbackMode - Loopback mode to be set
863 void CARDvSetLoopbackMode(struct vnt_private
*priv
,
864 unsigned short wLoopbackMode
)
866 switch (wLoopbackMode
) {
874 /* set MAC loopback */
875 MACvSetLoopbackMode(priv
, LOBYTE(wLoopbackMode
));
876 /* set Baseband loopback */
880 * Description: Software Reset NIC
884 * priv - The adapter to be reset
890 bool CARDbSoftwareReset(struct vnt_private
*priv
)
893 if (!MACbSafeSoftwareReset(priv
))
900 * Description: Calculate TSF offset of two TSF input
901 * Get TSF Offset from RxBCN's TSF and local TSF
905 * priv - The adapter to be sync.
906 * qwTSF1 - Rx BCN's TSF
911 * Return Value: TSF Offset value
913 u64
CARDqGetTSFOffset(unsigned char byRxRate
, u64 qwTSF1
, u64 qwTSF2
)
916 unsigned short wRxBcnTSFOffst
;
918 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
%MAX_RATE
];
920 qwTSF2
+= (u64
)wRxBcnTSFOffst
;
922 qwTSFOffset
= qwTSF1
- qwTSF2
;
928 * Description: Read NIC TSF counter
929 * Get local TSF counter
933 * priv - The adapter to be read
935 * qwCurrTSF - Current TSF counter
937 * Return Value: true if success; otherwise false
939 bool CARDbGetCurrentTSF(struct vnt_private
*priv
, u64
*pqwCurrTSF
)
941 void __iomem
*dwIoBase
= priv
->PortOffset
;
943 unsigned char byData
;
945 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
946 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
947 VNSvInPortB(dwIoBase
+ MAC_REG_TFTCTL
, &byData
);
948 if (!(byData
& TFTCTL_TSFCNTRRD
))
951 if (ww
== W_MAX_TIMEOUT
)
953 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
, (u32
*)pqwCurrTSF
);
954 VNSvInPortD(dwIoBase
+ MAC_REG_TSFCNTR
+ 4, (u32
*)pqwCurrTSF
+ 1);
960 * Description: Read NIC TSF counter
961 * Get NEXTTBTT from adjusted TSF and Beacon Interval
965 * qwTSF - Current TSF counter
966 * wbeaconInterval - Beacon Interval
968 * qwCurrTSF - Current TSF counter
970 * Return Value: TSF value of next Beacon
972 u64
CARDqGetNextTBTT(u64 qwTSF
, unsigned short wBeaconInterval
)
976 beacon_int
= wBeaconInterval
* 1024;
978 do_div(qwTSF
, beacon_int
);
987 * Description: Set NIC TSF counter for first Beacon time
988 * Get NEXTTBTT from adjusted TSF and Beacon Interval
993 * wBeaconInterval - Beacon Interval
999 void CARDvSetFirstNextTBTT(struct vnt_private
*priv
,
1000 unsigned short wBeaconInterval
)
1002 void __iomem
*dwIoBase
= priv
->PortOffset
;
1005 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
1007 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
1009 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
1010 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwNextTBTT
>> 32));
1011 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1015 * Description: Sync NIC TSF counter for Beacon time
1016 * Get NEXTTBTT and write to HW
1020 * priv - The adapter to be set
1021 * qwTSF - Current TSF counter
1022 * wBeaconInterval - Beacon Interval
1026 * Return Value: none
1028 void CARDvUpdateNextTBTT(struct vnt_private
*priv
, u64 qwTSF
,
1029 unsigned short wBeaconInterval
)
1031 void __iomem
*dwIoBase
= priv
->PortOffset
;
1033 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
1035 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
, (u32
)qwTSF
);
1036 VNSvOutPortD(dwIoBase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwTSF
>> 32));
1037 MACvRegBitsOn(dwIoBase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1038 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF
);