1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
7 * Purpose: Provide functions to setup NIC operation mode
9 * s_vSafeResetTx - Rest Tx
10 * CARDvSetRSPINF - Set RSPINF
11 * CARDvUpdateBasicTopRate - Update BasicTopRate
12 * CARDbAddBasicRate - Add to BasicRateSet
13 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
14 * CARDvSetLoopbackMode - Set Loopback mode
15 * CARDbSoftwareReset - Sortware reset NIC
16 * CARDqGetTSFOffset - Calculate TSFOffset
17 * CARDbGetCurrentTSF - Read Current NIC TSF counter
18 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
19 * CARDvSetFirstNextTBTT - Set NIC Beacon time
20 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
21 * CARDbRadioPowerOff - Turn Off NIC Radio Power
22 * CARDbRadioPowerOn - Turn On NIC Radio Power
25 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
26 * 08-26-2003 Kyle Hsu: Modify the defination type of iobase.
27 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
39 /*--------------------- Static Definitions -------------------------*/
41 #define C_SIFS_A 16 /* micro sec. */
44 #define C_EIFS 80 /* micro sec. */
46 #define C_SLOT_SHORT 9 /* micro sec. */
47 #define C_SLOT_LONG 20
49 #define C_CWMIN_A 15 /* slot time */
52 #define C_CWMAX 1023 /* slot time */
54 #define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
56 /*--------------------- Static Variables --------------------------*/
58 static const unsigned short cwRXBCNTSFOff
[MAX_RATE
] = {
59 17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
61 /*--------------------- Static Functions --------------------------*/
65 s_vCalculateOFDMRParameter(
68 unsigned char *pbyTxRate
,
69 unsigned char *pbyRsvTime
72 /*--------------------- Export Functions --------------------------*/
75 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
80 * byPktType - Tx Packet type
82 * pbyTxRate - pointer to RSPINF TxRate field
83 * pbyRsvTime - pointer to RSPINF RsvTime field
89 s_vCalculateOFDMRParameter(
92 unsigned char *pbyTxRate
,
93 unsigned char *pbyRsvTime
98 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
108 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
118 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
128 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
138 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
148 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
158 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
169 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
180 /*--------------------- Export Functions --------------------------*/
183 * Description: Update IFS
187 * priv - The adapter to be set
191 * Return Value: None.
193 bool CARDbSetPhyParameter(struct vnt_private
*priv
, u8 bb_type
)
195 unsigned char byCWMaxMin
= 0;
196 unsigned char bySlot
= 0;
197 unsigned char bySIFS
= 0;
198 unsigned char byDIFS
= 0;
199 unsigned char byData
;
202 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
203 if (bb_type
== BB_TYPE_11A
) {
204 if (priv
->byRFType
== RF_AIROHA7230
) {
205 /* AL7230 use single PAPE and connect to PAPE_2.4G */
206 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11G
);
207 priv
->abyBBVGA
[0] = 0x20;
208 priv
->abyBBVGA
[2] = 0x10;
209 priv
->abyBBVGA
[3] = 0x10;
210 BBbReadEmbedded(priv
, 0xE7, &byData
);
212 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
214 } else if (priv
->byRFType
== RF_UW2452
) {
215 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11A
);
216 priv
->abyBBVGA
[0] = 0x18;
217 BBbReadEmbedded(priv
, 0xE7, &byData
);
218 if (byData
== 0x14) {
219 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
220 BBbWriteEmbedded(priv
, 0xE1, 0x57);
223 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11A
);
225 BBbWriteEmbedded(priv
, 0x88, 0x03);
226 bySlot
= C_SLOT_SHORT
;
228 byDIFS
= C_SIFS_A
+ 2 * C_SLOT_SHORT
;
230 } else if (bb_type
== BB_TYPE_11B
) {
231 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11B
);
232 if (priv
->byRFType
== RF_AIROHA7230
) {
233 priv
->abyBBVGA
[0] = 0x1C;
234 priv
->abyBBVGA
[2] = 0x00;
235 priv
->abyBBVGA
[3] = 0x00;
236 BBbReadEmbedded(priv
, 0xE7, &byData
);
238 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
240 } else if (priv
->byRFType
== RF_UW2452
) {
241 priv
->abyBBVGA
[0] = 0x14;
242 BBbReadEmbedded(priv
, 0xE7, &byData
);
243 if (byData
== 0x18) {
244 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
245 BBbWriteEmbedded(priv
, 0xE1, 0xD3);
248 BBbWriteEmbedded(priv
, 0x88, 0x02);
249 bySlot
= C_SLOT_LONG
;
251 byDIFS
= C_SIFS_BG
+ 2 * C_SLOT_LONG
;
253 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
254 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11G
);
255 if (priv
->byRFType
== RF_AIROHA7230
) {
256 priv
->abyBBVGA
[0] = 0x1C;
257 priv
->abyBBVGA
[2] = 0x00;
258 priv
->abyBBVGA
[3] = 0x00;
259 BBbReadEmbedded(priv
, 0xE7, &byData
);
261 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
263 } else if (priv
->byRFType
== RF_UW2452
) {
264 priv
->abyBBVGA
[0] = 0x14;
265 BBbReadEmbedded(priv
, 0xE7, &byData
);
266 if (byData
== 0x18) {
267 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
268 BBbWriteEmbedded(priv
, 0xE1, 0xD3);
271 BBbWriteEmbedded(priv
, 0x88, 0x08);
274 if (priv
->bShortSlotTime
) {
275 bySlot
= C_SLOT_SHORT
;
276 byDIFS
= C_SIFS_BG
+ 2 * C_SLOT_SHORT
;
278 bySlot
= C_SLOT_LONG
;
279 byDIFS
= C_SIFS_BG
+ 2 * C_SLOT_LONG
;
284 for (i
= RATE_54M
; i
>= RATE_6M
; i
--) {
285 if (priv
->basic_rates
& ((u32
)(0x1 << i
))) {
292 if (priv
->byRFType
== RF_RFMD2959
) {
294 * bcs TX_PE will reserve 3 us hardware's processing
300 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
301 * better TX throughput; MAC will need 2 us to process, so the
302 * SIFS, DIFS can be shorter by 2 us.
306 if (priv
->bySIFS
!= bySIFS
) {
307 priv
->bySIFS
= bySIFS
;
308 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_SIFS
, priv
->bySIFS
);
310 if (priv
->byDIFS
!= byDIFS
) {
311 priv
->byDIFS
= byDIFS
;
312 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_DIFS
, priv
->byDIFS
);
314 if (priv
->byEIFS
!= C_EIFS
) {
315 priv
->byEIFS
= C_EIFS
;
316 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_EIFS
, priv
->byEIFS
);
318 if (priv
->bySlot
!= bySlot
) {
319 priv
->bySlot
= bySlot
;
320 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_SLOT
, priv
->bySlot
);
322 BBvSetShortSlotTime(priv
);
324 if (priv
->byCWMaxMin
!= byCWMaxMin
) {
325 priv
->byCWMaxMin
= byCWMaxMin
;
326 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_CWMAXMIN0
,
330 priv
->byPacketType
= CARDbyGetPktType(priv
);
332 CARDvSetRSPINF(priv
, bb_type
);
338 * Description: Sync. TSF counter to BSS
339 * Get TSF offset and write to HW
343 * priv - The adapter to be sync.
344 * byRxRate - data rate of receive beacon
345 * qwBSSTimestamp - Rx BCN's TSF
346 * qwLocalTSF - Local TSF
352 bool CARDbUpdateTSF(struct vnt_private
*priv
, unsigned char byRxRate
,
358 CARDbGetCurrentTSF(priv
, &local_tsf
);
360 if (qwBSSTimestamp
!= local_tsf
) {
361 qwTSFOffset
= CARDqGetTSFOffset(byRxRate
, qwBSSTimestamp
,
363 /* adjust TSF, HW's TSF add TSF Offset reg */
364 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_TSFOFST
,
366 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_TSFOFST
+ 4,
367 (u32
)(qwTSFOffset
>> 32));
368 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TFTCTL
,
375 * Description: Set NIC TSF counter for first Beacon time
376 * Get NEXTTBTT from adjusted TSF and Beacon Interval
380 * priv - The adapter to be set.
381 * wBeaconInterval - Beacon Interval
385 * Return Value: true if succeed; otherwise false
387 bool CARDbSetBeaconPeriod(struct vnt_private
*priv
,
388 unsigned short wBeaconInterval
)
392 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
394 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
396 /* set HW beacon interval */
397 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_BI
, wBeaconInterval
);
398 priv
->wBeaconInterval
= wBeaconInterval
;
400 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
401 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_NEXTTBTT
+ 4,
402 (u32
)(qwNextTBTT
>> 32));
403 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
409 * Description: Turn off Radio power
413 * priv - The adapter to be turned off
417 * Return Value: true if success; otherwise false
419 bool CARDbRadioPowerOff(struct vnt_private
*priv
)
426 switch (priv
->byRFType
) {
428 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
430 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
437 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
439 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
444 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
446 BBvSetDeepSleep(priv
, priv
->byLocalID
);
448 priv
->bRadioOff
= true;
449 pr_debug("chester power off\n");
450 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_GPIOCTL0
,
451 LED_ACTSET
); /* LED issue */
456 * Description: Turn on Radio power
460 * priv - The adapter to be turned on
464 * Return Value: true if success; otherwise false
466 bool CARDbRadioPowerOn(struct vnt_private
*priv
)
470 pr_debug("chester power on\n");
471 if (priv
->bRadioControlOff
) {
472 if (priv
->bHWRadioOff
)
473 pr_debug("chester bHWRadioOff\n");
474 if (priv
->bRadioControlOff
)
475 pr_debug("chester bRadioControlOff\n");
478 if (!priv
->bRadioOff
) {
479 pr_debug("chester pbRadioOff\n");
482 BBvExitDeepSleep(priv
, priv
->byLocalID
);
484 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
486 switch (priv
->byRFType
) {
488 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
490 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
497 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
498 (SOFTPWRCTL_SWPE2
| SOFTPWRCTL_SWPE3
));
502 priv
->bRadioOff
= false;
503 pr_debug("chester power on\n");
504 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_GPIOCTL0
,
505 LED_ACTSET
); /* LED issue */
511 struct vnt_private
*priv
515 struct vnt_tx_desc
*pCurrTD
;
517 /* initialize TD index */
518 priv
->apTailTD
[0] = &priv
->apTD0Rings
[0];
519 priv
->apCurrTD
[0] = &priv
->apTD0Rings
[0];
521 priv
->apTailTD
[1] = &priv
->apTD1Rings
[0];
522 priv
->apCurrTD
[1] = &priv
->apTD1Rings
[0];
524 for (uu
= 0; uu
< TYPE_MAXTD
; uu
++)
525 priv
->iTDUsed
[uu
] = 0;
527 for (uu
= 0; uu
< priv
->opts
.tx_descs
[0]; uu
++) {
528 pCurrTD
= &priv
->apTD0Rings
[uu
];
529 pCurrTD
->td0
.owner
= OWNED_BY_HOST
;
530 /* init all Tx Packet pointer to NULL */
532 for (uu
= 0; uu
< priv
->opts
.tx_descs
[1]; uu
++) {
533 pCurrTD
= &priv
->apTD1Rings
[uu
];
534 pCurrTD
->td0
.owner
= OWNED_BY_HOST
;
535 /* init all Tx Packet pointer to NULL */
538 /* set MAC TD pointer */
539 MACvSetCurrTXDescAddr(TYPE_TXDMA0
, priv
, priv
->td0_pool_dma
);
541 MACvSetCurrTXDescAddr(TYPE_AC0DMA
, priv
, priv
->td1_pool_dma
);
543 /* set MAC Beacon TX pointer */
544 MACvSetCurrBCNTxDescAddr(priv
->PortOffset
,
545 (priv
->tx_beacon_dma
));
554 * priv - Pointer to the adapter
562 struct vnt_private
*priv
566 struct vnt_rx_desc
*pDesc
;
568 /* initialize RD index */
569 priv
->pCurrRD
[0] = &priv
->aRD0Ring
[0];
570 priv
->pCurrRD
[1] = &priv
->aRD1Ring
[0];
572 /* init state, all RD is chip's */
573 for (uu
= 0; uu
< priv
->opts
.rx_descs0
; uu
++) {
574 pDesc
= &priv
->aRD0Ring
[uu
];
575 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
576 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
577 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
580 /* init state, all RD is chip's */
581 for (uu
= 0; uu
< priv
->opts
.rx_descs1
; uu
++) {
582 pDesc
= &priv
->aRD1Ring
[uu
];
583 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
584 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
585 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
588 /* set perPkt mode */
589 MACvRx0PerPktMode(priv
->PortOffset
);
590 MACvRx1PerPktMode(priv
->PortOffset
);
591 /* set MAC RD pointer */
592 MACvSetCurrRx0DescAddr(priv
, priv
->rd0_pool_dma
);
594 MACvSetCurrRx1DescAddr(priv
, priv
->rd1_pool_dma
);
598 * Description: Get response Control frame rate in CCK mode
602 * priv - 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
*priv
,
610 unsigned short wRateIdx
)
612 unsigned int ui
= (unsigned int)wRateIdx
;
614 while (ui
> RATE_1M
) {
615 if (priv
->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 * priv - 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
*priv
,
636 unsigned short wRateIdx
)
638 unsigned int ui
= (unsigned int)wRateIdx
;
640 pr_debug("BASIC RATE: %X\n", priv
->basic_rates
);
642 if (!CARDbIsOFDMinBasicRate((void *)priv
)) {
643 pr_debug("%s:(NO OFDM) %d\n", __func__
, wRateIdx
);
644 if (wRateIdx
> RATE_24M
)
648 while (ui
> RATE_11M
) {
649 if (priv
->basic_rates
& ((u32
)0x1 << ui
)) {
650 pr_debug("%s : %d\n", __func__
, ui
);
651 return (unsigned short)ui
;
655 pr_debug("%s: 6M\n", __func__
);
656 return (unsigned short)RATE_24M
;
660 * Description: Set RSPINF
664 * priv - The adapter to be set
668 * Return Value: None.
670 void CARDvSetRSPINF(struct vnt_private
*priv
, u8 bb_type
)
672 union vnt_phy_field_swap phy
;
673 unsigned char byTxRate
, byRsvTime
; /* For OFDM */
676 spin_lock_irqsave(&priv
->lock
, flags
);
679 MACvSelectPage1(priv
->PortOffset
);
682 vnt_get_phy_field(priv
, 14,
683 CARDwGetCCKControlRate(priv
, RATE_1M
),
684 PK_TYPE_11B
, &phy
.field_read
);
686 /* swap over to get correct write order */
687 swap(phy
.swap
[0], phy
.swap
[1]);
689 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_1
, phy
.field_write
);
692 vnt_get_phy_field(priv
, 14,
693 CARDwGetCCKControlRate(priv
, RATE_2M
),
694 PK_TYPE_11B
, &phy
.field_read
);
696 swap(phy
.swap
[0], phy
.swap
[1]);
698 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_2
, phy
.field_write
);
701 vnt_get_phy_field(priv
, 14,
702 CARDwGetCCKControlRate(priv
, RATE_5M
),
703 PK_TYPE_11B
, &phy
.field_read
);
705 swap(phy
.swap
[0], phy
.swap
[1]);
707 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_5
, phy
.field_write
);
710 vnt_get_phy_field(priv
, 14,
711 CARDwGetCCKControlRate(priv
, RATE_11M
),
712 PK_TYPE_11B
, &phy
.field_read
);
714 swap(phy
.swap
[0], phy
.swap
[1]);
716 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_11
, phy
.field_write
);
719 s_vCalculateOFDMRParameter(RATE_6M
,
723 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_6
,
724 MAKEWORD(byTxRate
, byRsvTime
));
726 s_vCalculateOFDMRParameter(RATE_9M
,
730 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_9
,
731 MAKEWORD(byTxRate
, byRsvTime
));
733 s_vCalculateOFDMRParameter(RATE_12M
,
737 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_12
,
738 MAKEWORD(byTxRate
, byRsvTime
));
740 s_vCalculateOFDMRParameter(RATE_18M
,
744 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_18
,
745 MAKEWORD(byTxRate
, byRsvTime
));
747 s_vCalculateOFDMRParameter(RATE_24M
,
751 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_24
,
752 MAKEWORD(byTxRate
, byRsvTime
));
754 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
760 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_36
,
761 MAKEWORD(byTxRate
, byRsvTime
));
763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
769 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_48
,
770 MAKEWORD(byTxRate
, byRsvTime
));
772 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
778 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_54
,
779 MAKEWORD(byTxRate
, byRsvTime
));
781 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
787 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_72
,
788 MAKEWORD(byTxRate
, byRsvTime
));
790 MACvSelectPage0(priv
->PortOffset
);
792 spin_unlock_irqrestore(&priv
->lock
, flags
);
795 void CARDvUpdateBasicTopRate(struct vnt_private
*priv
)
797 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
800 /* Determines the highest basic rate. */
801 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
802 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
807 priv
->byTopOFDMBasicRate
= byTopOFDM
;
809 for (ii
= RATE_11M
;; ii
--) {
810 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
817 priv
->byTopCCKBasicRate
= byTopCCK
;
820 bool CARDbIsOFDMinBasicRate(struct vnt_private
*priv
)
824 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
825 if ((priv
->basic_rates
) & ((u32
)BIT(ii
)))
831 unsigned char CARDbyGetPktType(struct vnt_private
*priv
)
833 if (priv
->byBBType
== BB_TYPE_11A
|| priv
->byBBType
== BB_TYPE_11B
)
834 return (unsigned char)priv
->byBBType
;
835 else if (CARDbIsOFDMinBasicRate((void *)priv
))
842 * Description: Set NIC Loopback mode
846 * priv - The adapter to be set
847 * wLoopbackMode - Loopback mode to be set
853 void CARDvSetLoopbackMode(struct vnt_private
*priv
,
854 unsigned short wLoopbackMode
)
856 switch (wLoopbackMode
) {
864 /* set MAC loopback */
865 MACvSetLoopbackMode(priv
, LOBYTE(wLoopbackMode
));
866 /* set Baseband loopback */
870 * Description: Software Reset NIC
874 * priv - The adapter to be reset
880 bool CARDbSoftwareReset(struct vnt_private
*priv
)
883 if (!MACbSafeSoftwareReset(priv
))
890 * Description: Calculate TSF offset of two TSF input
891 * Get TSF Offset from RxBCN's TSF and local TSF
895 * priv - The adapter to be sync.
896 * qwTSF1 - Rx BCN's TSF
901 * Return Value: TSF Offset value
903 u64
CARDqGetTSFOffset(unsigned char byRxRate
, u64 qwTSF1
, u64 qwTSF2
)
905 unsigned short wRxBcnTSFOffst
;
907 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
% MAX_RATE
];
909 qwTSF2
+= (u64
)wRxBcnTSFOffst
;
911 return qwTSF1
- qwTSF2
;
915 * Description: Read NIC TSF counter
916 * Get local TSF counter
920 * priv - The adapter to be read
922 * qwCurrTSF - Current TSF counter
924 * Return Value: true if success; otherwise false
926 bool CARDbGetCurrentTSF(struct vnt_private
*priv
, u64
*pqwCurrTSF
)
928 void __iomem
*iobase
= priv
->PortOffset
;
930 unsigned char byData
;
932 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
933 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
934 VNSvInPortB(iobase
+ MAC_REG_TFTCTL
, &byData
);
935 if (!(byData
& TFTCTL_TSFCNTRRD
))
938 if (ww
== W_MAX_TIMEOUT
)
940 VNSvInPortD(iobase
+ MAC_REG_TSFCNTR
, (u32
*)pqwCurrTSF
);
941 VNSvInPortD(iobase
+ MAC_REG_TSFCNTR
+ 4, (u32
*)pqwCurrTSF
+ 1);
947 * Description: Read NIC TSF counter
948 * Get NEXTTBTT from adjusted TSF and Beacon Interval
952 * qwTSF - Current TSF counter
953 * wbeaconInterval - Beacon Interval
955 * qwCurrTSF - Current TSF counter
957 * Return Value: TSF value of next Beacon
959 u64
CARDqGetNextTBTT(u64 qwTSF
, unsigned short wBeaconInterval
)
963 beacon_int
= wBeaconInterval
* 1024;
965 do_div(qwTSF
, beacon_int
);
974 * Description: Set NIC TSF counter for first Beacon time
975 * Get NEXTTBTT from adjusted TSF and Beacon Interval
980 * wBeaconInterval - Beacon Interval
986 void CARDvSetFirstNextTBTT(struct vnt_private
*priv
,
987 unsigned short wBeaconInterval
)
989 void __iomem
*iobase
= priv
->PortOffset
;
992 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
994 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
996 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
997 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwNextTBTT
>> 32));
998 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1002 * Description: Sync NIC TSF counter for Beacon time
1003 * Get NEXTTBTT and write to HW
1007 * priv - The adapter to be set
1008 * qwTSF - Current TSF counter
1009 * wBeaconInterval - Beacon Interval
1013 * Return Value: none
1015 void CARDvUpdateNextTBTT(struct vnt_private
*priv
, u64 qwTSF
,
1016 unsigned short wBeaconInterval
)
1018 void __iomem
*iobase
= priv
->PortOffset
;
1020 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
1022 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
, (u32
)qwTSF
);
1023 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwTSF
>> 32));
1024 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1025 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF
);