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 --------------------------*/
63 static void s_vCalculateOFDMRParameter(unsigned char byRate
, u8 bb_type
,
64 unsigned char *pbyTxRate
,
65 unsigned char *pbyRsvTime
);
67 /*--------------------- Export Functions --------------------------*/
70 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
75 * byPktType - Tx Packet type
77 * pbyTxRate - pointer to RSPINF TxRate field
78 * pbyRsvTime - pointer to RSPINF RsvTime field
82 static void s_vCalculateOFDMRParameter(unsigned char byRate
,
84 unsigned char *pbyTxRate
,
85 unsigned char *pbyRsvTime
)
89 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
99 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
109 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
119 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
129 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
139 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
149 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
160 if (bb_type
== BB_TYPE_11A
) { /* 5GHZ */
171 /*--------------------- Export Functions --------------------------*/
174 * Description: Update IFS
178 * priv - The adapter to be set
182 * Return Value: None.
184 bool CARDbSetPhyParameter(struct vnt_private
*priv
, u8 bb_type
)
186 unsigned char byCWMaxMin
= 0;
187 unsigned char bySlot
= 0;
188 unsigned char bySIFS
= 0;
189 unsigned char byDIFS
= 0;
190 unsigned char byData
;
193 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
194 if (bb_type
== BB_TYPE_11A
) {
195 if (priv
->byRFType
== RF_AIROHA7230
) {
196 /* AL7230 use single PAPE and connect to PAPE_2.4G */
197 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11G
);
198 priv
->abyBBVGA
[0] = 0x20;
199 priv
->abyBBVGA
[2] = 0x10;
200 priv
->abyBBVGA
[3] = 0x10;
201 BBbReadEmbedded(priv
, 0xE7, &byData
);
203 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
205 } else if (priv
->byRFType
== RF_UW2452
) {
206 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11A
);
207 priv
->abyBBVGA
[0] = 0x18;
208 BBbReadEmbedded(priv
, 0xE7, &byData
);
209 if (byData
== 0x14) {
210 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
211 BBbWriteEmbedded(priv
, 0xE1, 0x57);
214 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11A
);
216 BBbWriteEmbedded(priv
, 0x88, 0x03);
217 bySlot
= C_SLOT_SHORT
;
219 byDIFS
= C_SIFS_A
+ 2 * C_SLOT_SHORT
;
221 } else if (bb_type
== BB_TYPE_11B
) {
222 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11B
);
223 if (priv
->byRFType
== RF_AIROHA7230
) {
224 priv
->abyBBVGA
[0] = 0x1C;
225 priv
->abyBBVGA
[2] = 0x00;
226 priv
->abyBBVGA
[3] = 0x00;
227 BBbReadEmbedded(priv
, 0xE7, &byData
);
229 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
231 } else if (priv
->byRFType
== RF_UW2452
) {
232 priv
->abyBBVGA
[0] = 0x14;
233 BBbReadEmbedded(priv
, 0xE7, &byData
);
234 if (byData
== 0x18) {
235 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
236 BBbWriteEmbedded(priv
, 0xE1, 0xD3);
239 BBbWriteEmbedded(priv
, 0x88, 0x02);
240 bySlot
= C_SLOT_LONG
;
242 byDIFS
= C_SIFS_BG
+ 2 * C_SLOT_LONG
;
244 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
245 MACvSetBBType(priv
->PortOffset
, BB_TYPE_11G
);
246 if (priv
->byRFType
== RF_AIROHA7230
) {
247 priv
->abyBBVGA
[0] = 0x1C;
248 priv
->abyBBVGA
[2] = 0x00;
249 priv
->abyBBVGA
[3] = 0x00;
250 BBbReadEmbedded(priv
, 0xE7, &byData
);
252 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
254 } else if (priv
->byRFType
== RF_UW2452
) {
255 priv
->abyBBVGA
[0] = 0x14;
256 BBbReadEmbedded(priv
, 0xE7, &byData
);
257 if (byData
== 0x18) {
258 BBbWriteEmbedded(priv
, 0xE7, priv
->abyBBVGA
[0]);
259 BBbWriteEmbedded(priv
, 0xE1, 0xD3);
262 BBbWriteEmbedded(priv
, 0x88, 0x08);
265 if (priv
->bShortSlotTime
) {
266 bySlot
= C_SLOT_SHORT
;
267 byDIFS
= C_SIFS_BG
+ 2 * C_SLOT_SHORT
;
269 bySlot
= C_SLOT_LONG
;
270 byDIFS
= C_SIFS_BG
+ 2 * C_SLOT_LONG
;
275 for (i
= RATE_54M
; i
>= RATE_6M
; i
--) {
276 if (priv
->basic_rates
& ((u32
)(0x1 << i
))) {
283 if (priv
->byRFType
== RF_RFMD2959
) {
285 * bcs TX_PE will reserve 3 us hardware's processing
291 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
292 * better TX throughput; MAC will need 2 us to process, so the
293 * SIFS, DIFS can be shorter by 2 us.
297 if (priv
->bySIFS
!= bySIFS
) {
298 priv
->bySIFS
= bySIFS
;
299 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_SIFS
, priv
->bySIFS
);
301 if (priv
->byDIFS
!= byDIFS
) {
302 priv
->byDIFS
= byDIFS
;
303 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_DIFS
, priv
->byDIFS
);
305 if (priv
->byEIFS
!= C_EIFS
) {
306 priv
->byEIFS
= C_EIFS
;
307 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_EIFS
, priv
->byEIFS
);
309 if (priv
->bySlot
!= bySlot
) {
310 priv
->bySlot
= bySlot
;
311 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_SLOT
, priv
->bySlot
);
313 BBvSetShortSlotTime(priv
);
315 if (priv
->byCWMaxMin
!= byCWMaxMin
) {
316 priv
->byCWMaxMin
= byCWMaxMin
;
317 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_CWMAXMIN0
,
321 priv
->byPacketType
= CARDbyGetPktType(priv
);
323 CARDvSetRSPINF(priv
, bb_type
);
329 * Description: Sync. TSF counter to BSS
330 * Get TSF offset and write to HW
334 * priv - The adapter to be sync.
335 * byRxRate - data rate of receive beacon
336 * qwBSSTimestamp - Rx BCN's TSF
337 * qwLocalTSF - Local TSF
343 bool CARDbUpdateTSF(struct vnt_private
*priv
, unsigned char byRxRate
,
349 CARDbGetCurrentTSF(priv
, &local_tsf
);
351 if (qwBSSTimestamp
!= local_tsf
) {
352 qwTSFOffset
= CARDqGetTSFOffset(byRxRate
, qwBSSTimestamp
,
354 /* adjust TSF, HW's TSF add TSF Offset reg */
355 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_TSFOFST
,
357 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_TSFOFST
+ 4,
358 (u32
)(qwTSFOffset
>> 32));
359 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TFTCTL
,
366 * Description: Set NIC TSF counter for first Beacon time
367 * Get NEXTTBTT from adjusted TSF and Beacon Interval
371 * priv - The adapter to be set.
372 * wBeaconInterval - Beacon Interval
376 * Return Value: true if succeed; otherwise false
378 bool CARDbSetBeaconPeriod(struct vnt_private
*priv
,
379 unsigned short wBeaconInterval
)
383 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
385 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
387 /* set HW beacon interval */
388 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_BI
, wBeaconInterval
);
389 priv
->wBeaconInterval
= wBeaconInterval
;
391 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
392 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_NEXTTBTT
+ 4,
393 (u32
)(qwNextTBTT
>> 32));
394 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
400 * Description: Turn off Radio power
404 * priv - The adapter to be turned off
409 void CARDbRadioPowerOff(struct vnt_private
*priv
)
414 switch (priv
->byRFType
) {
416 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
418 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
425 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
427 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
432 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
434 BBvSetDeepSleep(priv
, priv
->byLocalID
);
436 priv
->bRadioOff
= true;
437 pr_debug("chester power off\n");
438 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_GPIOCTL0
,
439 LED_ACTSET
); /* LED issue */
443 * Description: Turn on Radio power
447 * priv - The adapter to be turned on
451 * Return Value: true if success; otherwise false
453 bool CARDbRadioPowerOn(struct vnt_private
*priv
)
457 pr_debug("chester power on\n");
458 if (priv
->bRadioControlOff
) {
459 if (priv
->bHWRadioOff
)
460 pr_debug("chester bHWRadioOff\n");
461 if (priv
->bRadioControlOff
)
462 pr_debug("chester bRadioControlOff\n");
465 if (!priv
->bRadioOff
) {
466 pr_debug("chester pbRadioOff\n");
469 BBvExitDeepSleep(priv
, priv
->byLocalID
);
471 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_RXON
);
473 switch (priv
->byRFType
) {
475 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
477 MACvWordRegBitsOff(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
484 MACvWordRegBitsOn(priv
->PortOffset
, MAC_REG_SOFTPWRCTL
,
485 (SOFTPWRCTL_SWPE2
| SOFTPWRCTL_SWPE3
));
489 priv
->bRadioOff
= false;
490 pr_debug("chester power on\n");
491 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_GPIOCTL0
,
492 LED_ACTSET
); /* LED issue */
496 void CARDvSafeResetTx(struct vnt_private
*priv
)
499 struct vnt_tx_desc
*pCurrTD
;
501 /* initialize TD index */
502 priv
->apTailTD
[0] = &priv
->apTD0Rings
[0];
503 priv
->apCurrTD
[0] = &priv
->apTD0Rings
[0];
505 priv
->apTailTD
[1] = &priv
->apTD1Rings
[0];
506 priv
->apCurrTD
[1] = &priv
->apTD1Rings
[0];
508 for (uu
= 0; uu
< TYPE_MAXTD
; uu
++)
509 priv
->iTDUsed
[uu
] = 0;
511 for (uu
= 0; uu
< priv
->opts
.tx_descs
[0]; uu
++) {
512 pCurrTD
= &priv
->apTD0Rings
[uu
];
513 pCurrTD
->td0
.owner
= OWNED_BY_HOST
;
514 /* init all Tx Packet pointer to NULL */
516 for (uu
= 0; uu
< priv
->opts
.tx_descs
[1]; uu
++) {
517 pCurrTD
= &priv
->apTD1Rings
[uu
];
518 pCurrTD
->td0
.owner
= OWNED_BY_HOST
;
519 /* init all Tx Packet pointer to NULL */
522 /* set MAC TD pointer */
523 MACvSetCurrTXDescAddr(TYPE_TXDMA0
, priv
, priv
->td0_pool_dma
);
525 MACvSetCurrTXDescAddr(TYPE_AC0DMA
, priv
, priv
->td1_pool_dma
);
527 /* set MAC Beacon TX pointer */
528 MACvSetCurrBCNTxDescAddr(priv
->PortOffset
,
529 (priv
->tx_beacon_dma
));
538 * priv - Pointer to the adapter
544 void CARDvSafeResetRx(struct vnt_private
*priv
)
547 struct vnt_rx_desc
*pDesc
;
549 /* initialize RD index */
550 priv
->pCurrRD
[0] = &priv
->aRD0Ring
[0];
551 priv
->pCurrRD
[1] = &priv
->aRD1Ring
[0];
553 /* init state, all RD is chip's */
554 for (uu
= 0; uu
< priv
->opts
.rx_descs0
; uu
++) {
555 pDesc
= &priv
->aRD0Ring
[uu
];
556 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
557 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
558 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
561 /* init state, all RD is chip's */
562 for (uu
= 0; uu
< priv
->opts
.rx_descs1
; uu
++) {
563 pDesc
= &priv
->aRD1Ring
[uu
];
564 pDesc
->rd0
.res_count
= cpu_to_le16(priv
->rx_buf_sz
);
565 pDesc
->rd0
.owner
= OWNED_BY_NIC
;
566 pDesc
->rd1
.req_count
= cpu_to_le16(priv
->rx_buf_sz
);
569 /* set perPkt mode */
570 MACvRx0PerPktMode(priv
->PortOffset
);
571 MACvRx1PerPktMode(priv
->PortOffset
);
572 /* set MAC RD pointer */
573 MACvSetCurrRx0DescAddr(priv
, priv
->rd0_pool_dma
);
575 MACvSetCurrRx1DescAddr(priv
, priv
->rd1_pool_dma
);
579 * Description: Get response Control frame rate in CCK mode
583 * priv - The adapter to be set
584 * wRateIdx - Receiving data rate
588 * Return Value: response Control frame rate
590 static unsigned short CARDwGetCCKControlRate(struct vnt_private
*priv
,
591 unsigned short wRateIdx
)
593 unsigned int ui
= (unsigned int)wRateIdx
;
595 while (ui
> RATE_1M
) {
596 if (priv
->basic_rates
& ((u32
)0x1 << ui
))
597 return (unsigned short)ui
;
601 return (unsigned short)RATE_1M
;
605 * Description: Get response Control frame rate in OFDM mode
609 * priv - The adapter to be set
610 * wRateIdx - Receiving data rate
614 * Return Value: response Control frame rate
616 static unsigned short CARDwGetOFDMControlRate(struct vnt_private
*priv
,
617 unsigned short wRateIdx
)
619 unsigned int ui
= (unsigned int)wRateIdx
;
621 pr_debug("BASIC RATE: %X\n", priv
->basic_rates
);
623 if (!CARDbIsOFDMinBasicRate((void *)priv
)) {
624 pr_debug("%s:(NO OFDM) %d\n", __func__
, wRateIdx
);
625 if (wRateIdx
> RATE_24M
)
629 while (ui
> RATE_11M
) {
630 if (priv
->basic_rates
& ((u32
)0x1 << ui
)) {
631 pr_debug("%s : %d\n", __func__
, ui
);
632 return (unsigned short)ui
;
636 pr_debug("%s: 6M\n", __func__
);
637 return (unsigned short)RATE_24M
;
641 * Description: Set RSPINF
645 * priv - The adapter to be set
649 * Return Value: None.
651 void CARDvSetRSPINF(struct vnt_private
*priv
, u8 bb_type
)
653 union vnt_phy_field_swap phy
;
654 unsigned char byTxRate
, byRsvTime
; /* For OFDM */
657 spin_lock_irqsave(&priv
->lock
, flags
);
660 MACvSelectPage1(priv
->PortOffset
);
663 vnt_get_phy_field(priv
, 14,
664 CARDwGetCCKControlRate(priv
, RATE_1M
),
665 PK_TYPE_11B
, &phy
.field_read
);
667 /* swap over to get correct write order */
668 swap(phy
.swap
[0], phy
.swap
[1]);
670 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_1
, phy
.field_write
);
673 vnt_get_phy_field(priv
, 14,
674 CARDwGetCCKControlRate(priv
, RATE_2M
),
675 PK_TYPE_11B
, &phy
.field_read
);
677 swap(phy
.swap
[0], phy
.swap
[1]);
679 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_2
, phy
.field_write
);
682 vnt_get_phy_field(priv
, 14,
683 CARDwGetCCKControlRate(priv
, RATE_5M
),
684 PK_TYPE_11B
, &phy
.field_read
);
686 swap(phy
.swap
[0], phy
.swap
[1]);
688 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_5
, phy
.field_write
);
691 vnt_get_phy_field(priv
, 14,
692 CARDwGetCCKControlRate(priv
, RATE_11M
),
693 PK_TYPE_11B
, &phy
.field_read
);
695 swap(phy
.swap
[0], phy
.swap
[1]);
697 VNSvOutPortD(priv
->PortOffset
+ MAC_REG_RSPINF_B_11
, phy
.field_write
);
700 s_vCalculateOFDMRParameter(RATE_6M
,
704 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_6
,
705 MAKEWORD(byTxRate
, byRsvTime
));
707 s_vCalculateOFDMRParameter(RATE_9M
,
711 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_9
,
712 MAKEWORD(byTxRate
, byRsvTime
));
714 s_vCalculateOFDMRParameter(RATE_12M
,
718 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_12
,
719 MAKEWORD(byTxRate
, byRsvTime
));
721 s_vCalculateOFDMRParameter(RATE_18M
,
725 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_18
,
726 MAKEWORD(byTxRate
, byRsvTime
));
728 s_vCalculateOFDMRParameter(RATE_24M
,
732 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_24
,
733 MAKEWORD(byTxRate
, byRsvTime
));
735 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv
,
740 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_36
,
741 MAKEWORD(byTxRate
, byRsvTime
));
743 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv
,
748 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_48
,
749 MAKEWORD(byTxRate
, byRsvTime
));
751 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv
,
756 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_54
,
757 MAKEWORD(byTxRate
, byRsvTime
));
759 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv
,
764 VNSvOutPortW(priv
->PortOffset
+ MAC_REG_RSPINF_A_72
,
765 MAKEWORD(byTxRate
, byRsvTime
));
767 MACvSelectPage0(priv
->PortOffset
);
769 spin_unlock_irqrestore(&priv
->lock
, flags
);
772 void CARDvUpdateBasicTopRate(struct vnt_private
*priv
)
774 unsigned char byTopOFDM
= RATE_24M
, byTopCCK
= RATE_1M
;
777 /* Determines the highest basic rate. */
778 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
779 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
784 priv
->byTopOFDMBasicRate
= byTopOFDM
;
786 for (ii
= RATE_11M
;; ii
--) {
787 if ((priv
->basic_rates
) & ((u32
)(1 << ii
))) {
794 priv
->byTopCCKBasicRate
= byTopCCK
;
797 bool CARDbIsOFDMinBasicRate(struct vnt_private
*priv
)
801 for (ii
= RATE_54M
; ii
>= RATE_6M
; ii
--) {
802 if ((priv
->basic_rates
) & ((u32
)BIT(ii
)))
808 unsigned char CARDbyGetPktType(struct vnt_private
*priv
)
810 if (priv
->byBBType
== BB_TYPE_11A
|| priv
->byBBType
== BB_TYPE_11B
)
811 return (unsigned char)priv
->byBBType
;
812 else if (CARDbIsOFDMinBasicRate((void *)priv
))
819 * Description: Set NIC Loopback mode
823 * priv - The adapter to be set
824 * wLoopbackMode - Loopback mode to be set
830 void CARDvSetLoopbackMode(struct vnt_private
*priv
,
831 unsigned short wLoopbackMode
)
833 switch (wLoopbackMode
) {
841 /* set MAC loopback */
842 MACvSetLoopbackMode(priv
, LOBYTE(wLoopbackMode
));
843 /* set Baseband loopback */
847 * Description: Software Reset NIC
851 * priv - The adapter to be reset
857 bool CARDbSoftwareReset(struct vnt_private
*priv
)
860 if (!MACbSafeSoftwareReset(priv
))
867 * Description: Calculate TSF offset of two TSF input
868 * Get TSF Offset from RxBCN's TSF and local TSF
872 * priv - The adapter to be sync.
873 * qwTSF1 - Rx BCN's TSF
878 * Return Value: TSF Offset value
880 u64
CARDqGetTSFOffset(unsigned char byRxRate
, u64 qwTSF1
, u64 qwTSF2
)
882 unsigned short wRxBcnTSFOffst
;
884 wRxBcnTSFOffst
= cwRXBCNTSFOff
[byRxRate
% MAX_RATE
];
886 qwTSF2
+= (u64
)wRxBcnTSFOffst
;
888 return qwTSF1
- qwTSF2
;
892 * Description: Read NIC TSF counter
893 * Get local TSF counter
897 * priv - The adapter to be read
899 * qwCurrTSF - Current TSF counter
901 * Return Value: true if success; otherwise false
903 bool CARDbGetCurrentTSF(struct vnt_private
*priv
, u64
*pqwCurrTSF
)
905 void __iomem
*iobase
= priv
->PortOffset
;
907 unsigned char byData
;
909 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TSFCNTRRD
);
910 for (ww
= 0; ww
< W_MAX_TIMEOUT
; ww
++) {
911 VNSvInPortB(iobase
+ MAC_REG_TFTCTL
, &byData
);
912 if (!(byData
& TFTCTL_TSFCNTRRD
))
915 if (ww
== W_MAX_TIMEOUT
)
917 VNSvInPortD(iobase
+ MAC_REG_TSFCNTR
, (u32
*)pqwCurrTSF
);
918 VNSvInPortD(iobase
+ MAC_REG_TSFCNTR
+ 4, (u32
*)pqwCurrTSF
+ 1);
924 * Description: Read NIC TSF counter
925 * Get NEXTTBTT from adjusted TSF and Beacon Interval
929 * qwTSF - Current TSF counter
930 * wbeaconInterval - Beacon Interval
932 * qwCurrTSF - Current TSF counter
934 * Return Value: TSF value of next Beacon
936 u64
CARDqGetNextTBTT(u64 qwTSF
, unsigned short wBeaconInterval
)
940 beacon_int
= wBeaconInterval
* 1024;
942 do_div(qwTSF
, beacon_int
);
951 * Description: Set NIC TSF counter for first Beacon time
952 * Get NEXTTBTT from adjusted TSF and Beacon Interval
957 * wBeaconInterval - Beacon Interval
963 void CARDvSetFirstNextTBTT(struct vnt_private
*priv
,
964 unsigned short wBeaconInterval
)
966 void __iomem
*iobase
= priv
->PortOffset
;
969 CARDbGetCurrentTSF(priv
, &qwNextTBTT
); /* Get Local TSF counter */
971 qwNextTBTT
= CARDqGetNextTBTT(qwNextTBTT
, wBeaconInterval
);
973 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
, (u32
)qwNextTBTT
);
974 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwNextTBTT
>> 32));
975 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
979 * Description: Sync NIC TSF counter for Beacon time
980 * Get NEXTTBTT and write to HW
984 * priv - The adapter to be set
985 * qwTSF - Current TSF counter
986 * wBeaconInterval - Beacon Interval
992 void CARDvUpdateNextTBTT(struct vnt_private
*priv
, u64 qwTSF
,
993 unsigned short wBeaconInterval
)
995 void __iomem
*iobase
= priv
->PortOffset
;
997 qwTSF
= CARDqGetNextTBTT(qwTSF
, wBeaconInterval
);
999 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
, (u32
)qwTSF
);
1000 VNSvOutPortD(iobase
+ MAC_REG_NEXTTBTT
+ 4, (u32
)(qwTSF
>> 32));
1001 MACvRegBitsOn(iobase
, MAC_REG_TFTCTL
, TFTCTL_TBTTSYNCEN
);
1002 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF
);