Linux 4.16.11
[linux/fpc-iii.git] / drivers / staging / vt6655 / card.c
blobea0a4b57852c2219191a75192e3e6792f059c9d6
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
64 void
65 s_vCalculateOFDMRParameter(
66 unsigned char byRate,
67 u8 bb_type,
68 unsigned char *pbyTxRate,
69 unsigned char *pbyRsvTime
72 /*--------------------- Export Functions --------------------------*/
75 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
77 * Parameters:
78 * In:
79 * wRate - Tx Rate
80 * byPktType - Tx Packet type
81 * Out:
82 * pbyTxRate - pointer to RSPINF TxRate field
83 * pbyRsvTime - pointer to RSPINF RsvTime field
85 * Return Value: none
87 static
88 void
89 s_vCalculateOFDMRParameter(
90 unsigned char byRate,
91 u8 bb_type,
92 unsigned char *pbyTxRate,
93 unsigned char *pbyRsvTime
96 switch (byRate) {
97 case RATE_6M:
98 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
99 *pbyTxRate = 0x9B;
100 *pbyRsvTime = 44;
101 } else {
102 *pbyTxRate = 0x8B;
103 *pbyRsvTime = 50;
105 break;
107 case RATE_9M:
108 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
109 *pbyTxRate = 0x9F;
110 *pbyRsvTime = 36;
111 } else {
112 *pbyTxRate = 0x8F;
113 *pbyRsvTime = 42;
115 break;
117 case RATE_12M:
118 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
119 *pbyTxRate = 0x9A;
120 *pbyRsvTime = 32;
121 } else {
122 *pbyTxRate = 0x8A;
123 *pbyRsvTime = 38;
125 break;
127 case RATE_18M:
128 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
129 *pbyTxRate = 0x9E;
130 *pbyRsvTime = 28;
131 } else {
132 *pbyTxRate = 0x8E;
133 *pbyRsvTime = 34;
135 break;
137 case RATE_36M:
138 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
139 *pbyTxRate = 0x9D;
140 *pbyRsvTime = 24;
141 } else {
142 *pbyTxRate = 0x8D;
143 *pbyRsvTime = 30;
145 break;
147 case RATE_48M:
148 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
149 *pbyTxRate = 0x98;
150 *pbyRsvTime = 24;
151 } else {
152 *pbyTxRate = 0x88;
153 *pbyRsvTime = 30;
155 break;
157 case RATE_54M:
158 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
159 *pbyTxRate = 0x9C;
160 *pbyRsvTime = 24;
161 } else {
162 *pbyTxRate = 0x8C;
163 *pbyRsvTime = 30;
165 break;
167 case RATE_24M:
168 default:
169 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
170 *pbyTxRate = 0x99;
171 *pbyRsvTime = 28;
172 } else {
173 *pbyTxRate = 0x89;
174 *pbyRsvTime = 34;
176 break;
180 /*--------------------- Export Functions --------------------------*/
183 * Description: Update IFS
185 * Parameters:
186 * In:
187 * priv - The adapter to be set
188 * Out:
189 * none
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;
200 int i;
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);
211 if (byData == 0x1C)
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);
222 } else {
223 MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
225 BBbWriteEmbedded(priv, 0x88, 0x03);
226 bySlot = C_SLOT_SHORT;
227 bySIFS = C_SIFS_A;
228 byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
229 byCWMaxMin = 0xA4;
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);
237 if (byData == 0x20)
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;
250 bySIFS = C_SIFS_BG;
251 byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
252 byCWMaxMin = 0xA5;
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);
260 if (byData == 0x20)
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);
272 bySIFS = C_SIFS_BG;
274 if (priv->bShortSlotTime) {
275 bySlot = C_SLOT_SHORT;
276 byDIFS = C_SIFS_BG + 2 * C_SLOT_SHORT;
277 } else {
278 bySlot = C_SLOT_LONG;
279 byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
282 byCWMaxMin = 0xa4;
284 for (i = RATE_54M; i >= RATE_6M; i--) {
285 if (priv->basic_rates & ((u32)(0x1 << i))) {
286 byCWMaxMin |= 0x1;
287 break;
292 if (priv->byRFType == RF_RFMD2959) {
294 * bcs TX_PE will reserve 3 us hardware's processing
295 * time here is 2 us.
297 bySIFS -= 3;
298 byDIFS -= 3;
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,
327 priv->byCWMaxMin);
330 priv->byPacketType = CARDbyGetPktType(priv);
332 CARDvSetRSPINF(priv, bb_type);
334 return true;
338 * Description: Sync. TSF counter to BSS
339 * Get TSF offset and write to HW
341 * Parameters:
342 * In:
343 * priv - The adapter to be sync.
344 * byRxRate - data rate of receive beacon
345 * qwBSSTimestamp - Rx BCN's TSF
346 * qwLocalTSF - Local TSF
347 * Out:
348 * none
350 * Return Value: none
352 bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate,
353 u64 qwBSSTimestamp)
355 u64 local_tsf;
356 u64 qwTSFOffset = 0;
358 CARDbGetCurrentTSF(priv, &local_tsf);
360 if (qwBSSTimestamp != local_tsf) {
361 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp,
362 local_tsf);
363 /* adjust TSF, HW's TSF add TSF Offset reg */
364 VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST,
365 (u32)qwTSFOffset);
366 VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST + 4,
367 (u32)(qwTSFOffset >> 32));
368 MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL,
369 TFTCTL_TSFSYNCEN);
371 return true;
375 * Description: Set NIC TSF counter for first Beacon time
376 * Get NEXTTBTT from adjusted TSF and Beacon Interval
378 * Parameters:
379 * In:
380 * priv - The adapter to be set.
381 * wBeaconInterval - Beacon Interval
382 * Out:
383 * none
385 * Return Value: true if succeed; otherwise false
387 bool CARDbSetBeaconPeriod(struct vnt_private *priv,
388 unsigned short wBeaconInterval)
390 u64 qwNextTBTT = 0;
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;
399 /* Set NextTBTT */
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);
405 return true;
409 * Description: Turn off Radio power
411 * Parameters:
412 * In:
413 * priv - The adapter to be turned off
414 * Out:
415 * none
417 * Return Value: true if success; otherwise false
419 bool CARDbRadioPowerOff(struct vnt_private *priv)
421 bool bResult = true;
423 if (priv->bRadioOff)
424 return true;
426 switch (priv->byRFType) {
427 case RF_RFMD2959:
428 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
429 SOFTPWRCTL_TXPEINV);
430 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
431 SOFTPWRCTL_SWPE1);
432 break;
434 case RF_AIROHA:
435 case RF_AL2230S:
436 case RF_AIROHA7230:
437 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
438 SOFTPWRCTL_SWPE2);
439 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
440 SOFTPWRCTL_SWPE3);
441 break;
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 */
452 return bResult;
456 * Description: Turn on Radio power
458 * Parameters:
459 * In:
460 * priv - The adapter to be turned on
461 * Out:
462 * none
464 * Return Value: true if success; otherwise false
466 bool CARDbRadioPowerOn(struct vnt_private *priv)
468 bool bResult = true;
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");
476 return false; }
478 if (!priv->bRadioOff) {
479 pr_debug("chester pbRadioOff\n");
480 return true; }
482 BBvExitDeepSleep(priv, priv->byLocalID);
484 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
486 switch (priv->byRFType) {
487 case RF_RFMD2959:
488 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
489 SOFTPWRCTL_TXPEINV);
490 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
491 SOFTPWRCTL_SWPE1);
492 break;
494 case RF_AIROHA:
495 case RF_AL2230S:
496 case RF_AIROHA7230:
497 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
498 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
499 break;
502 priv->bRadioOff = false;
503 pr_debug("chester power on\n");
504 MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0,
505 LED_ACTSET); /* LED issue */
506 return bResult;
509 void
510 CARDvSafeResetTx(
511 struct vnt_private *priv
514 unsigned int uu;
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));
549 * Description:
550 * Reset Rx
552 * Parameters:
553 * In:
554 * priv - Pointer to the adapter
555 * Out:
556 * none
558 * Return Value: none
560 void
561 CARDvSafeResetRx(
562 struct vnt_private *priv
565 unsigned int uu;
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
600 * Parameters:
601 * In:
602 * priv - The adapter to be set
603 * wRateIdx - Receiving data rate
604 * Out:
605 * none
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;
618 ui--;
620 return (unsigned short)RATE_1M;
624 * Description: Get response Control frame rate in OFDM mode
626 * Parameters:
627 * In:
628 * priv - The adapter to be set
629 * wRateIdx - Receiving data rate
630 * Out:
631 * none
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)
645 wRateIdx = RATE_24M;
646 return wRateIdx;
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;
653 ui--;
655 pr_debug("%s: 6M\n", __func__);
656 return (unsigned short)RATE_24M;
660 * Description: Set RSPINF
662 * Parameters:
663 * In:
664 * priv - The adapter to be set
665 * Out:
666 * none
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 */
674 unsigned long flags;
676 spin_lock_irqsave(&priv->lock, flags);
678 /* Set to Page1 */
679 MACvSelectPage1(priv->PortOffset);
681 /* RSPINF_b_1 */
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);
691 /* RSPINF_b_2 */
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);
700 /* RSPINF_b_5 */
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);
709 /* RSPINF_b_11 */
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);
718 /* RSPINF_a_6 */
719 s_vCalculateOFDMRParameter(RATE_6M,
720 bb_type,
721 &byTxRate,
722 &byRsvTime);
723 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_6,
724 MAKEWORD(byTxRate, byRsvTime));
725 /* RSPINF_a_9 */
726 s_vCalculateOFDMRParameter(RATE_9M,
727 bb_type,
728 &byTxRate,
729 &byRsvTime);
730 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_9,
731 MAKEWORD(byTxRate, byRsvTime));
732 /* RSPINF_a_12 */
733 s_vCalculateOFDMRParameter(RATE_12M,
734 bb_type,
735 &byTxRate,
736 &byRsvTime);
737 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_12,
738 MAKEWORD(byTxRate, byRsvTime));
739 /* RSPINF_a_18 */
740 s_vCalculateOFDMRParameter(RATE_18M,
741 bb_type,
742 &byTxRate,
743 &byRsvTime);
744 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_18,
745 MAKEWORD(byTxRate, byRsvTime));
746 /* RSPINF_a_24 */
747 s_vCalculateOFDMRParameter(RATE_24M,
748 bb_type,
749 &byTxRate,
750 &byRsvTime);
751 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_24,
752 MAKEWORD(byTxRate, byRsvTime));
753 /* RSPINF_a_36 */
754 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
755 (void *)priv,
756 RATE_36M),
757 bb_type,
758 &byTxRate,
759 &byRsvTime);
760 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_36,
761 MAKEWORD(byTxRate, byRsvTime));
762 /* RSPINF_a_48 */
763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
764 (void *)priv,
765 RATE_48M),
766 bb_type,
767 &byTxRate,
768 &byRsvTime);
769 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_48,
770 MAKEWORD(byTxRate, byRsvTime));
771 /* RSPINF_a_54 */
772 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
773 (void *)priv,
774 RATE_54M),
775 bb_type,
776 &byTxRate,
777 &byRsvTime);
778 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_54,
779 MAKEWORD(byTxRate, byRsvTime));
780 /* RSPINF_a_72 */
781 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
782 (void *)priv,
783 RATE_54M),
784 bb_type,
785 &byTxRate,
786 &byRsvTime);
787 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_72,
788 MAKEWORD(byTxRate, byRsvTime));
789 /* Set to Page0 */
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;
798 unsigned char ii;
800 /* Determines the highest basic rate. */
801 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
802 if ((priv->basic_rates) & ((u32)(1 << ii))) {
803 byTopOFDM = ii;
804 break;
807 priv->byTopOFDMBasicRate = byTopOFDM;
809 for (ii = RATE_11M;; ii--) {
810 if ((priv->basic_rates) & ((u32)(1 << ii))) {
811 byTopCCK = ii;
812 break;
814 if (ii == RATE_1M)
815 break;
817 priv->byTopCCKBasicRate = byTopCCK;
820 bool CARDbIsOFDMinBasicRate(struct vnt_private *priv)
822 int ii;
824 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
825 if ((priv->basic_rates) & ((u32)BIT(ii)))
826 return true;
828 return false;
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))
836 return PK_TYPE_11GA;
837 else
838 return PK_TYPE_11GB;
842 * Description: Set NIC Loopback mode
844 * Parameters:
845 * In:
846 * priv - The adapter to be set
847 * wLoopbackMode - Loopback mode to be set
848 * Out:
849 * none
851 * Return Value: none
853 void CARDvSetLoopbackMode(struct vnt_private *priv,
854 unsigned short wLoopbackMode)
856 switch (wLoopbackMode) {
857 case CARD_LB_NONE:
858 case CARD_LB_MAC:
859 case CARD_LB_PHY:
860 break;
861 default:
862 break;
864 /* set MAC loopback */
865 MACvSetLoopbackMode(priv, LOBYTE(wLoopbackMode));
866 /* set Baseband loopback */
870 * Description: Software Reset NIC
872 * Parameters:
873 * In:
874 * priv - The adapter to be reset
875 * Out:
876 * none
878 * Return Value: none
880 bool CARDbSoftwareReset(struct vnt_private *priv)
882 /* reset MAC */
883 if (!MACbSafeSoftwareReset(priv))
884 return false;
886 return true;
890 * Description: Calculate TSF offset of two TSF input
891 * Get TSF Offset from RxBCN's TSF and local TSF
893 * Parameters:
894 * In:
895 * priv - The adapter to be sync.
896 * qwTSF1 - Rx BCN's TSF
897 * qwTSF2 - Local TSF
898 * Out:
899 * none
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
918 * Parameters:
919 * In:
920 * priv - The adapter to be read
921 * Out:
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;
929 unsigned short ww;
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))
936 break;
938 if (ww == W_MAX_TIMEOUT)
939 return false;
940 VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
941 VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
943 return true;
947 * Description: Read NIC TSF counter
948 * Get NEXTTBTT from adjusted TSF and Beacon Interval
950 * Parameters:
951 * In:
952 * qwTSF - Current TSF counter
953 * wbeaconInterval - Beacon Interval
954 * Out:
955 * qwCurrTSF - Current TSF counter
957 * Return Value: TSF value of next Beacon
959 u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
961 u32 beacon_int;
963 beacon_int = wBeaconInterval * 1024;
964 if (beacon_int) {
965 do_div(qwTSF, beacon_int);
966 qwTSF += 1;
967 qwTSF *= beacon_int;
970 return qwTSF;
974 * Description: Set NIC TSF counter for first Beacon time
975 * Get NEXTTBTT from adjusted TSF and Beacon Interval
977 * Parameters:
978 * In:
979 * iobase - IO Base
980 * wBeaconInterval - Beacon Interval
981 * Out:
982 * none
984 * Return Value: none
986 void CARDvSetFirstNextTBTT(struct vnt_private *priv,
987 unsigned short wBeaconInterval)
989 void __iomem *iobase = priv->PortOffset;
990 u64 qwNextTBTT = 0;
992 CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
994 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
995 /* Set NextTBTT */
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
1005 * Parameters:
1006 * In:
1007 * priv - The adapter to be set
1008 * qwTSF - Current TSF counter
1009 * wBeaconInterval - Beacon Interval
1010 * Out:
1011 * none
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);
1021 /* Set NextTBTT */
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);