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
560 void CARDvSafeResetRx(struct vnt_private
*priv
)
563 struct vnt_rx_desc
*pDesc
;
565 /* initialize RD index */
566 priv
->pCurrRD
[0] = &priv
->aRD0Ring
[0];
567 priv
->pCurrRD
[1] = &priv
->aRD1Ring
[0];
569 /* init state, all RD is chip's */
570 for (uu
= 0; uu
< priv
->opts
.rx_descs0
; uu
++) {
571 pDesc
= &priv
->aRD0Ring
[uu
];
572 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
573 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
574 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
577 /* init state, all RD is chip's */
578 for (uu
= 0; uu
< priv
->opts
.rx_descs1
; uu
++) {
579 pDesc
= &priv
->aRD1Ring
[uu
];
580 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
581 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
582 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
585 /* set perPkt mode */
586 MACvRx0PerPktMode(priv
->PortOffset
);
587 MACvRx1PerPktMode(priv
->PortOffset
);
588 /* set MAC RD pointer */
589 MACvSetCurrRx0DescAddr(priv
, priv
->rd0_pool_dma
);
591 MACvSetCurrRx1DescAddr(priv
, priv
->rd1_pool_dma
);
595 * Description: Get response Control frame rate in CCK mode
599 * priv - The adapter to be set
600 * wRateIdx - Receiving data rate
604 * Return Value: response Control frame rate
606 static unsigned short CARDwGetCCKControlRate(struct vnt_private
*priv
,
607 unsigned short wRateIdx
)
609 unsigned int ui
= (unsigned int)wRateIdx
;
611 while (ui
> RATE_1M
) {
612 if (priv
->basic_rates
& ((u32
)0x1 << ui
))
613 return (unsigned short)ui
;
617 return (unsigned short)RATE_1M
;
621 * Description: Get response Control frame rate in OFDM mode
625 * priv - The adapter to be set
626 * wRateIdx - Receiving data rate
630 * Return Value: response Control frame rate
632 static unsigned short CARDwGetOFDMControlRate(struct vnt_private
*priv
,
633 unsigned short wRateIdx
)
635 unsigned int ui
= (unsigned int)wRateIdx
;
637 pr_debug("BASIC RATE: %X\n", priv
->basic_rates
);
639 if (!CARDbIsOFDMinBasicRate((void *)priv
)) {
640 pr_debug("%s:(NO OFDM) %d\n", __func__
, wRateIdx
);
641 if (wRateIdx
> RATE_24M
)
645 while (ui
> RATE_11M
) {
646 if (priv
->basic_rates
& ((u32
)0x1 << ui
)) {
647 pr_debug("%s : %d\n", __func__
, ui
);
648 return (unsigned short)ui
;
652 pr_debug("%s: 6M\n", __func__
);
653 return (unsigned short)RATE_24M
;
657 * Description: Set RSPINF
661 * priv - The adapter to be set
665 * Return Value: None.
667 void CARDvSetRSPINF(struct vnt_private
*priv
, u8 bb_type
)
669 union vnt_phy_field_swap phy
;
670 unsigned char byTxRate
, byRsvTime
; /* For OFDM */
673 spin_lock_irqsave(&priv
->lock
, flags
);
676 MACvSelectPage1(priv
->PortOffset
);
679 vnt_get_phy_field(priv
, 14,
680 CARDwGetCCKControlRate(priv
, 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(priv
->PortOffset
+ MAC_REG_RSPINF_B_1
, phy
.field_write
);
689 vnt_get_phy_field(priv
, 14,
690 CARDwGetCCKControlRate(priv
, RATE_2M
),
691 PK_TYPE_11B
, &phy
.field_read
);
693 swap(phy
.swap
[0], phy
.swap
[1]);
695 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_2
, phy
.field_write
);
698 vnt_get_phy_field(priv
, 14,
699 CARDwGetCCKControlRate(priv
, RATE_5M
),
700 PK_TYPE_11B
, &phy
.field_read
);
702 swap(phy
.swap
[0], phy
.swap
[1]);
704 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_5
, phy
.field_write
);
707 vnt_get_phy_field(priv
, 14,
708 CARDwGetCCKControlRate(priv
, RATE_11M
),
709 PK_TYPE_11B
, &phy
.field_read
);
711 swap(phy
.swap
[0], phy
.swap
[1]);
713 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_11
, phy
.field_write
);
716 s_vCalculateOFDMRParameter(RATE_6M
,
720 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_6
,
721 MAKEWORD(byTxRate
, byRsvTime
));
723 s_vCalculateOFDMRParameter(RATE_9M
,
727 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_9
,
728 MAKEWORD(byTxRate
, byRsvTime
));
730 s_vCalculateOFDMRParameter(RATE_12M
,
734 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_12
,
735 MAKEWORD(byTxRate
, byRsvTime
));
737 s_vCalculateOFDMRParameter(RATE_18M
,
741 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_18
,
742 MAKEWORD(byTxRate
, byRsvTime
));
744 s_vCalculateOFDMRParameter(RATE_24M
,
748 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_24
,
749 MAKEWORD(byTxRate
, byRsvTime
));
751 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
757 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_36
,
758 MAKEWORD(byTxRate
, byRsvTime
));
760 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
766 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_48
,
767 MAKEWORD(byTxRate
, byRsvTime
));
769 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
775 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_54
,
776 MAKEWORD(byTxRate
, byRsvTime
));
778 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
784 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_72
,
785 MAKEWORD(byTxRate
, byRsvTime
));
787 MACvSelectPage0(priv
->PortOffset
);
789 spin_unlock_irqrestore(&priv
->lock
, flags
);
792 void CARDvUpdateBasicTopRate(struct vnt_private
*priv
)
794 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
797 /* Determines the highest basic rate. */
798 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
799 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
804 priv
->byTopOFDMBasicRate
= byTopOFDM
;
806 for (ii
= RATE_11M
;; ii
--) {
807 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
814 priv
->byTopCCKBasicRate
= byTopCCK
;
817 bool CARDbIsOFDMinBasicRate(struct vnt_private
*priv
)
821 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
822 if ((priv
->basic_rates
) & ((u32
)BIT(ii
)))
828 unsigned char CARDbyGetPktType(struct vnt_private
*priv
)
830 if (priv
->byBBType
== BB_TYPE_11A
|| priv
->byBBType
== BB_TYPE_11B
)
831 return (unsigned char)priv
->byBBType
;
832 else if (CARDbIsOFDMinBasicRate((void *)priv
))
839 * Description: Set NIC Loopback mode
843 * priv - The adapter to be set
844 * wLoopbackMode - Loopback mode to be set
850 void CARDvSetLoopbackMode(struct vnt_private
*priv
,
851 unsigned short wLoopbackMode
)
853 switch (wLoopbackMode
) {
861 /* set MAC loopback */
862 MACvSetLoopbackMode(priv
, LOBYTE(wLoopbackMode
));
863 /* set Baseband loopback */
867 * Description: Software Reset NIC
871 * priv - The adapter to be reset
877 bool CARDbSoftwareReset(struct vnt_private
*priv
)
880 if (!MACbSafeSoftwareReset(priv
))
887 * Description: Calculate TSF offset of two TSF input
888 * Get TSF Offset from RxBCN's TSF and local TSF
892 * priv - The adapter to be sync.
893 * qwTSF1 - Rx BCN's TSF
898 * Return Value: TSF Offset value
900 u64
CARDqGetTSFOffset(unsigned char byRxRate
, u64 qwTSF1
, u64 qwTSF2
)
902 unsigned short wRxBcnTSFOffst
;
904 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
% MAX_RATE
];
906 qwTSF2
+= (u64
)wRxBcnTSFOffst
;
908 return qwTSF1
- qwTSF2
;
912 * Description: Read NIC TSF counter
913 * Get local TSF counter
917 * priv - The adapter to be read
919 * qwCurrTSF - Current TSF counter
921 * Return Value: true if success; otherwise false
923 bool CARDbGetCurrentTSF(struct vnt_private
*priv
, u64
*pqwCurrTSF
)
925 void __iomem
*iobase
= priv
->PortOffset
;
927 unsigned char byData
;
929 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
930 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
931 VNSvInPortB(iobase
+ MAC_REG_TFTCTL
, &byData
);
932 if (!(byData
& TFTCTL_TSFCNTRRD
))
935 if (ww
== W_MAX_TIMEOUT
)
937 VNSvInPortD(iobase
+ MAC_REG_TSFCNTR
, (u32
*)pqwCurrTSF
);
938 VNSvInPortD(iobase
+ MAC_REG_TSFCNTR
+ 4, (u32
*)pqwCurrTSF
+ 1);
944 * Description: Read NIC TSF counter
945 * Get NEXTTBTT from adjusted TSF and Beacon Interval
949 * qwTSF - Current TSF counter
950 * wbeaconInterval - Beacon Interval
952 * qwCurrTSF - Current TSF counter
954 * Return Value: TSF value of next Beacon
956 u64
CARDqGetNextTBTT(u64 qwTSF
, unsigned short wBeaconInterval
)
960 beacon_int
= wBeaconInterval
* 1024;
962 do_div(qwTSF
, beacon_int
);
971 * Description: Set NIC TSF counter for first Beacon time
972 * Get NEXTTBTT from adjusted TSF and Beacon Interval
977 * wBeaconInterval - Beacon Interval
983 void CARDvSetFirstNextTBTT(struct vnt_private
*priv
,
984 unsigned short wBeaconInterval
)
986 void __iomem
*iobase
= priv
->PortOffset
;
989 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
991 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
993 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
994 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwNextTBTT
>> 32));
995 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
999 * Description: Sync NIC TSF counter for Beacon time
1000 * Get NEXTTBTT and write to HW
1004 * priv - The adapter to be set
1005 * qwTSF - Current TSF counter
1006 * wBeaconInterval - Beacon Interval
1010 * Return Value: none
1012 void CARDvUpdateNextTBTT(struct vnt_private
*priv
, u64 qwTSF
,
1013 unsigned short wBeaconInterval
)
1015 void __iomem
*iobase
= priv
->PortOffset
;
1017 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
1019 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
, (u32
)qwTSF
);
1020 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwTSF
>> 32));
1021 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1022 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF
);