gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / staging / vt6655 / card.c
blobe65c9825ea5af5c76aed4c887c25dcb2f3a1ca97
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: card.c
7 * Purpose: Provide functions to setup NIC operation mode
8 * Functions:
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
24 * Revision History:
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().
31 #include "tmacro.h"
32 #include "card.h"
33 #include "baseband.h"
34 #include "mac.h"
35 #include "desc.h"
36 #include "rf.h"
37 #include "power.h"
39 /*--------------------- Static Definitions -------------------------*/
41 #define C_SIFS_A 16 /* micro sec. */
42 #define C_SIFS_BG 10
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 */
50 #define C_CWMIN_B 31
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.
72 * Parameters:
73 * In:
74 * wRate - Tx Rate
75 * byPktType - Tx Packet type
76 * Out:
77 * pbyTxRate - pointer to RSPINF TxRate field
78 * pbyRsvTime - pointer to RSPINF RsvTime field
80 * Return Value: none
82 static void s_vCalculateOFDMRParameter(unsigned char byRate,
83 u8 bb_type,
84 unsigned char *pbyTxRate,
85 unsigned char *pbyRsvTime)
87 switch (byRate) {
88 case RATE_6M:
89 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
90 *pbyTxRate = 0x9B;
91 *pbyRsvTime = 44;
92 } else {
93 *pbyTxRate = 0x8B;
94 *pbyRsvTime = 50;
96 break;
98 case RATE_9M:
99 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
100 *pbyTxRate = 0x9F;
101 *pbyRsvTime = 36;
102 } else {
103 *pbyTxRate = 0x8F;
104 *pbyRsvTime = 42;
106 break;
108 case RATE_12M:
109 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
110 *pbyTxRate = 0x9A;
111 *pbyRsvTime = 32;
112 } else {
113 *pbyTxRate = 0x8A;
114 *pbyRsvTime = 38;
116 break;
118 case RATE_18M:
119 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
120 *pbyTxRate = 0x9E;
121 *pbyRsvTime = 28;
122 } else {
123 *pbyTxRate = 0x8E;
124 *pbyRsvTime = 34;
126 break;
128 case RATE_36M:
129 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
130 *pbyTxRate = 0x9D;
131 *pbyRsvTime = 24;
132 } else {
133 *pbyTxRate = 0x8D;
134 *pbyRsvTime = 30;
136 break;
138 case RATE_48M:
139 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
140 *pbyTxRate = 0x98;
141 *pbyRsvTime = 24;
142 } else {
143 *pbyTxRate = 0x88;
144 *pbyRsvTime = 30;
146 break;
148 case RATE_54M:
149 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
150 *pbyTxRate = 0x9C;
151 *pbyRsvTime = 24;
152 } else {
153 *pbyTxRate = 0x8C;
154 *pbyRsvTime = 30;
156 break;
158 case RATE_24M:
159 default:
160 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
161 *pbyTxRate = 0x99;
162 *pbyRsvTime = 28;
163 } else {
164 *pbyTxRate = 0x89;
165 *pbyRsvTime = 34;
167 break;
171 /*--------------------- Export Functions --------------------------*/
174 * Description: Update IFS
176 * Parameters:
177 * In:
178 * priv - The adapter to be set
179 * Out:
180 * none
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;
191 int i;
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);
202 if (byData == 0x1C)
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);
213 } else {
214 MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
216 BBbWriteEmbedded(priv, 0x88, 0x03);
217 bySlot = C_SLOT_SHORT;
218 bySIFS = C_SIFS_A;
219 byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
220 byCWMaxMin = 0xA4;
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);
228 if (byData == 0x20)
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;
241 bySIFS = C_SIFS_BG;
242 byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
243 byCWMaxMin = 0xA5;
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);
251 if (byData == 0x20)
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);
263 bySIFS = C_SIFS_BG;
265 if (priv->bShortSlotTime) {
266 bySlot = C_SLOT_SHORT;
267 byDIFS = C_SIFS_BG + 2 * C_SLOT_SHORT;
268 } else {
269 bySlot = C_SLOT_LONG;
270 byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
273 byCWMaxMin = 0xa4;
275 for (i = RATE_54M; i >= RATE_6M; i--) {
276 if (priv->basic_rates & ((u32)(0x1 << i))) {
277 byCWMaxMin |= 0x1;
278 break;
283 if (priv->byRFType == RF_RFMD2959) {
285 * bcs TX_PE will reserve 3 us hardware's processing
286 * time here is 2 us.
288 bySIFS -= 3;
289 byDIFS -= 3;
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,
318 priv->byCWMaxMin);
321 priv->byPacketType = CARDbyGetPktType(priv);
323 CARDvSetRSPINF(priv, bb_type);
325 return true;
329 * Description: Sync. TSF counter to BSS
330 * Get TSF offset and write to HW
332 * Parameters:
333 * In:
334 * priv - The adapter to be sync.
335 * byRxRate - data rate of receive beacon
336 * qwBSSTimestamp - Rx BCN's TSF
337 * qwLocalTSF - Local TSF
338 * Out:
339 * none
341 * Return Value: none
343 bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate,
344 u64 qwBSSTimestamp)
346 u64 local_tsf;
347 u64 qwTSFOffset = 0;
349 CARDbGetCurrentTSF(priv, &local_tsf);
351 if (qwBSSTimestamp != local_tsf) {
352 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp,
353 local_tsf);
354 /* adjust TSF, HW's TSF add TSF Offset reg */
355 VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST,
356 (u32)qwTSFOffset);
357 VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST + 4,
358 (u32)(qwTSFOffset >> 32));
359 MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL,
360 TFTCTL_TSFSYNCEN);
362 return true;
366 * Description: Set NIC TSF counter for first Beacon time
367 * Get NEXTTBTT from adjusted TSF and Beacon Interval
369 * Parameters:
370 * In:
371 * priv - The adapter to be set.
372 * wBeaconInterval - Beacon Interval
373 * Out:
374 * none
376 * Return Value: true if succeed; otherwise false
378 bool CARDbSetBeaconPeriod(struct vnt_private *priv,
379 unsigned short wBeaconInterval)
381 u64 qwNextTBTT = 0;
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;
390 /* Set NextTBTT */
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);
396 return true;
400 * Description: Turn off Radio power
402 * Parameters:
403 * In:
404 * priv - The adapter to be turned off
405 * Out:
406 * none
409 void CARDbRadioPowerOff(struct vnt_private *priv)
411 if (priv->bRadioOff)
412 return;
414 switch (priv->byRFType) {
415 case RF_RFMD2959:
416 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
417 SOFTPWRCTL_TXPEINV);
418 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
419 SOFTPWRCTL_SWPE1);
420 break;
422 case RF_AIROHA:
423 case RF_AL2230S:
424 case RF_AIROHA7230:
425 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
426 SOFTPWRCTL_SWPE2);
427 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
428 SOFTPWRCTL_SWPE3);
429 break;
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
445 * Parameters:
446 * In:
447 * priv - The adapter to be turned on
448 * Out:
449 * none
451 * Return Value: true if success; otherwise false
453 bool CARDbRadioPowerOn(struct vnt_private *priv)
455 bool bResult = true;
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");
463 return false; }
465 if (!priv->bRadioOff) {
466 pr_debug("chester pbRadioOff\n");
467 return true; }
469 BBvExitDeepSleep(priv, priv->byLocalID);
471 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
473 switch (priv->byRFType) {
474 case RF_RFMD2959:
475 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
476 SOFTPWRCTL_TXPEINV);
477 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
478 SOFTPWRCTL_SWPE1);
479 break;
481 case RF_AIROHA:
482 case RF_AL2230S:
483 case RF_AIROHA7230:
484 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
485 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
486 break;
489 priv->bRadioOff = false;
490 pr_debug("chester power on\n");
491 MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0,
492 LED_ACTSET); /* LED issue */
493 return bResult;
496 void CARDvSafeResetTx(struct vnt_private *priv)
498 unsigned int uu;
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));
533 * Description:
534 * Reset Rx
536 * Parameters:
537 * In:
538 * priv - Pointer to the adapter
539 * Out:
540 * none
542 * Return Value: none
544 void CARDvSafeResetRx(struct vnt_private *priv)
546 unsigned int uu;
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
581 * Parameters:
582 * In:
583 * priv - The adapter to be set
584 * wRateIdx - Receiving data rate
585 * Out:
586 * none
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;
599 ui--;
601 return (unsigned short)RATE_1M;
605 * Description: Get response Control frame rate in OFDM mode
607 * Parameters:
608 * In:
609 * priv - The adapter to be set
610 * wRateIdx - Receiving data rate
611 * Out:
612 * none
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)
626 wRateIdx = RATE_24M;
627 return wRateIdx;
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;
634 ui--;
636 pr_debug("%s: 6M\n", __func__);
637 return (unsigned short)RATE_24M;
641 * Description: Set RSPINF
643 * Parameters:
644 * In:
645 * priv - The adapter to be set
646 * Out:
647 * none
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 */
655 unsigned long flags;
657 spin_lock_irqsave(&priv->lock, flags);
659 /* Set to Page1 */
660 MACvSelectPage1(priv->PortOffset);
662 /* RSPINF_b_1 */
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);
672 /* RSPINF_b_2 */
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);
681 /* RSPINF_b_5 */
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);
690 /* RSPINF_b_11 */
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);
699 /* RSPINF_a_6 */
700 s_vCalculateOFDMRParameter(RATE_6M,
701 bb_type,
702 &byTxRate,
703 &byRsvTime);
704 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_6,
705 MAKEWORD(byTxRate, byRsvTime));
706 /* RSPINF_a_9 */
707 s_vCalculateOFDMRParameter(RATE_9M,
708 bb_type,
709 &byTxRate,
710 &byRsvTime);
711 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_9,
712 MAKEWORD(byTxRate, byRsvTime));
713 /* RSPINF_a_12 */
714 s_vCalculateOFDMRParameter(RATE_12M,
715 bb_type,
716 &byTxRate,
717 &byRsvTime);
718 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_12,
719 MAKEWORD(byTxRate, byRsvTime));
720 /* RSPINF_a_18 */
721 s_vCalculateOFDMRParameter(RATE_18M,
722 bb_type,
723 &byTxRate,
724 &byRsvTime);
725 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_18,
726 MAKEWORD(byTxRate, byRsvTime));
727 /* RSPINF_a_24 */
728 s_vCalculateOFDMRParameter(RATE_24M,
729 bb_type,
730 &byTxRate,
731 &byRsvTime);
732 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_24,
733 MAKEWORD(byTxRate, byRsvTime));
734 /* RSPINF_a_36 */
735 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv,
736 RATE_36M),
737 bb_type,
738 &byTxRate,
739 &byRsvTime);
740 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_36,
741 MAKEWORD(byTxRate, byRsvTime));
742 /* RSPINF_a_48 */
743 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv,
744 RATE_48M),
745 bb_type,
746 &byTxRate,
747 &byRsvTime);
748 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_48,
749 MAKEWORD(byTxRate, byRsvTime));
750 /* RSPINF_a_54 */
751 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv,
752 RATE_54M),
753 bb_type,
754 &byTxRate,
755 &byRsvTime);
756 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_54,
757 MAKEWORD(byTxRate, byRsvTime));
758 /* RSPINF_a_72 */
759 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv,
760 RATE_54M),
761 bb_type,
762 &byTxRate,
763 &byRsvTime);
764 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_72,
765 MAKEWORD(byTxRate, byRsvTime));
766 /* Set to Page0 */
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;
775 unsigned char ii;
777 /* Determines the highest basic rate. */
778 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
779 if ((priv->basic_rates) & ((u32)(1 << ii))) {
780 byTopOFDM = ii;
781 break;
784 priv->byTopOFDMBasicRate = byTopOFDM;
786 for (ii = RATE_11M;; ii--) {
787 if ((priv->basic_rates) & ((u32)(1 << ii))) {
788 byTopCCK = ii;
789 break;
791 if (ii == RATE_1M)
792 break;
794 priv->byTopCCKBasicRate = byTopCCK;
797 bool CARDbIsOFDMinBasicRate(struct vnt_private *priv)
799 int ii;
801 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
802 if ((priv->basic_rates) & ((u32)BIT(ii)))
803 return true;
805 return false;
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))
813 return PK_TYPE_11GA;
814 else
815 return PK_TYPE_11GB;
819 * Description: Set NIC Loopback mode
821 * Parameters:
822 * In:
823 * priv - The adapter to be set
824 * wLoopbackMode - Loopback mode to be set
825 * Out:
826 * none
828 * Return Value: none
830 void CARDvSetLoopbackMode(struct vnt_private *priv,
831 unsigned short wLoopbackMode)
833 switch (wLoopbackMode) {
834 case CARD_LB_NONE:
835 case CARD_LB_MAC:
836 case CARD_LB_PHY:
837 break;
838 default:
839 break;
841 /* set MAC loopback */
842 MACvSetLoopbackMode(priv, LOBYTE(wLoopbackMode));
843 /* set Baseband loopback */
847 * Description: Software Reset NIC
849 * Parameters:
850 * In:
851 * priv - The adapter to be reset
852 * Out:
853 * none
855 * Return Value: none
857 bool CARDbSoftwareReset(struct vnt_private *priv)
859 /* reset MAC */
860 if (!MACbSafeSoftwareReset(priv))
861 return false;
863 return true;
867 * Description: Calculate TSF offset of two TSF input
868 * Get TSF Offset from RxBCN's TSF and local TSF
870 * Parameters:
871 * In:
872 * priv - The adapter to be sync.
873 * qwTSF1 - Rx BCN's TSF
874 * qwTSF2 - Local TSF
875 * Out:
876 * none
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
895 * Parameters:
896 * In:
897 * priv - The adapter to be read
898 * Out:
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;
906 unsigned short ww;
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))
913 break;
915 if (ww == W_MAX_TIMEOUT)
916 return false;
917 VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
918 VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
920 return true;
924 * Description: Read NIC TSF counter
925 * Get NEXTTBTT from adjusted TSF and Beacon Interval
927 * Parameters:
928 * In:
929 * qwTSF - Current TSF counter
930 * wbeaconInterval - Beacon Interval
931 * Out:
932 * qwCurrTSF - Current TSF counter
934 * Return Value: TSF value of next Beacon
936 u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
938 u32 beacon_int;
940 beacon_int = wBeaconInterval * 1024;
941 if (beacon_int) {
942 do_div(qwTSF, beacon_int);
943 qwTSF += 1;
944 qwTSF *= beacon_int;
947 return qwTSF;
951 * Description: Set NIC TSF counter for first Beacon time
952 * Get NEXTTBTT from adjusted TSF and Beacon Interval
954 * Parameters:
955 * In:
956 * iobase - IO Base
957 * wBeaconInterval - Beacon Interval
958 * Out:
959 * none
961 * Return Value: none
963 void CARDvSetFirstNextTBTT(struct vnt_private *priv,
964 unsigned short wBeaconInterval)
966 void __iomem *iobase = priv->PortOffset;
967 u64 qwNextTBTT = 0;
969 CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
971 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
972 /* Set NextTBTT */
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
982 * Parameters:
983 * In:
984 * priv - The adapter to be set
985 * qwTSF - Current TSF counter
986 * wBeaconInterval - Beacon Interval
987 * Out:
988 * none
990 * Return Value: none
992 void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF,
993 unsigned short wBeaconInterval)
995 void __iomem *iobase = priv->PortOffset;
997 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
998 /* Set NextTBTT */
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);