include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / staging / vt6655 / card.c
blob2721e07984960cc2ff2c5c48469058ebe8665d91
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * File: card.c
20 * Purpose: Provide functions to setup NIC operation mode
21 * Functions:
22 * s_vSafeResetTx - Rest Tx
23 * CARDvSetRSPINF - Set RSPINF
24 * vUpdateIFS - Update slotTime,SIFS,DIFS, and EIFS
25 * CARDvUpdateBasicTopRate - Update BasicTopRate
26 * CARDbAddBasicRate - Add to BasicRateSet
27 * CARDbSetBasicRate - Set Basic Tx Rate
28 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
29 * CARDvSetLoopbackMode - Set Loopback mode
30 * CARDbSoftwareReset - Sortware reset NIC
31 * CARDqGetTSFOffset - Caculate TSFOffset
32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
33 * CARDqGetNextTBTT - Caculate Next Beacon TSF counter
34 * CARDvSetFirstNextTBTT - Set NIC Beacon time
35 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
36 * CARDbRadioPowerOff - Turn Off NIC Radio Power
37 * CARDbRadioPowerOn - Turn On NIC Radio Power
38 * CARDbSetWEPMode - Set NIC Wep mode
39 * CARDbSetTxPower - Set NIC tx power
41 * Revision History:
42 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
43 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
48 #include "tmacro.h"
49 #include "card.h"
50 #include "baseband.h"
51 #include "mac.h"
52 #include "desc.h"
53 #include "rf.h"
54 #include "vntwifi.h"
55 #include "power.h"
56 #include "key.h"
57 #include "rc4.h"
58 #include "country.h"
59 #include "channel.h"
61 /*--------------------- Static Definitions -------------------------*/
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 static int msglevel =MSG_LEVEL_INFO;
66 #define C_SIFS_A 16 // micro sec.
67 #define C_SIFS_BG 10
69 #define C_EIFS 80 // micro sec.
72 #define C_SLOT_SHORT 9 // micro sec.
73 #define C_SLOT_LONG 20
75 #define C_CWMIN_A 15 // slot time
76 #define C_CWMIN_B 31
78 #define C_CWMAX 1023 // slot time
80 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
82 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
83 static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
84 //6M, 9M, 12M, 48M
85 static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
86 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
87 static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
88 //1M, 2M, 5M, 11M,
89 static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
92 /*--------------------- Static Variables --------------------------*/
95 const unsigned short cwRXBCNTSFOff[MAX_RATE] =
96 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
99 /*--------------------- Static Functions --------------------------*/
101 static
102 void
103 s_vCaculateOFDMRParameter(
104 unsigned char byRate,
105 CARD_PHY_TYPE ePHYType,
106 unsigned char *pbyTxRate,
107 unsigned char *pbyRsvTime
111 /*--------------------- Export Functions --------------------------*/
114 * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
116 * Parameters:
117 * In:
118 * wRate - Tx Rate
119 * byPktType - Tx Packet type
120 * Out:
121 * pbyTxRate - pointer to RSPINF TxRate field
122 * pbyRsvTime - pointer to RSPINF RsvTime field
124 * Return Value: none
127 static
128 void
129 s_vCaculateOFDMRParameter (
130 unsigned char byRate,
131 CARD_PHY_TYPE ePHYType,
132 unsigned char *pbyTxRate,
133 unsigned char *pbyRsvTime
136 switch (byRate) {
137 case RATE_6M :
138 if (ePHYType == PHY_TYPE_11A) {//5GHZ
139 *pbyTxRate = 0x9B;
140 *pbyRsvTime = 44;
142 else {
143 *pbyTxRate = 0x8B;
144 *pbyRsvTime = 50;
146 break;
148 case RATE_9M :
149 if (ePHYType == PHY_TYPE_11A) {//5GHZ
150 *pbyTxRate = 0x9F;
151 *pbyRsvTime = 36;
153 else {
154 *pbyTxRate = 0x8F;
155 *pbyRsvTime = 42;
157 break;
159 case RATE_12M :
160 if (ePHYType == PHY_TYPE_11A) {//5GHZ
161 *pbyTxRate = 0x9A;
162 *pbyRsvTime = 32;
164 else {
165 *pbyTxRate = 0x8A;
166 *pbyRsvTime = 38;
168 break;
170 case RATE_18M :
171 if (ePHYType == PHY_TYPE_11A) {//5GHZ
172 *pbyTxRate = 0x9E;
173 *pbyRsvTime = 28;
175 else {
176 *pbyTxRate = 0x8E;
177 *pbyRsvTime = 34;
179 break;
181 case RATE_36M :
182 if (ePHYType == PHY_TYPE_11A) {//5GHZ
183 *pbyTxRate = 0x9D;
184 *pbyRsvTime = 24;
186 else {
187 *pbyTxRate = 0x8D;
188 *pbyRsvTime = 30;
190 break;
192 case RATE_48M :
193 if (ePHYType == PHY_TYPE_11A) {//5GHZ
194 *pbyTxRate = 0x98;
195 *pbyRsvTime = 24;
197 else {
198 *pbyTxRate = 0x88;
199 *pbyRsvTime = 30;
201 break;
203 case RATE_54M :
204 if (ePHYType == PHY_TYPE_11A) {//5GHZ
205 *pbyTxRate = 0x9C;
206 *pbyRsvTime = 24;
208 else {
209 *pbyTxRate = 0x8C;
210 *pbyRsvTime = 30;
212 break;
214 case RATE_24M :
215 default :
216 if (ePHYType == PHY_TYPE_11A) {//5GHZ
217 *pbyTxRate = 0x99;
218 *pbyRsvTime = 28;
220 else {
221 *pbyTxRate = 0x89;
222 *pbyRsvTime = 34;
224 break;
231 * Description: Set RSPINF
233 * Parameters:
234 * In:
235 * pDevice - The adapter to be set
236 * Out:
237 * none
239 * Return Value: None.
242 static
243 void
244 s_vSetRSPINF (PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
246 unsigned char byServ = 0, bySignal = 0; // For CCK
247 unsigned short wLen = 0;
248 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
250 //Set to Page1
251 MACvSelectPage1(pDevice->PortOffset);
253 //RSPINF_b_1
254 BBvCaculateParameter(pDevice,
256 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
257 PK_TYPE_11B,
258 &wLen,
259 &byServ,
260 &bySignal
263 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
264 ///RSPINF_b_2
265 BBvCaculateParameter(pDevice,
267 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
268 PK_TYPE_11B,
269 &wLen,
270 &byServ,
271 &bySignal
274 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
275 //RSPINF_b_5
276 BBvCaculateParameter(pDevice,
278 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
279 PK_TYPE_11B,
280 &wLen,
281 &byServ,
282 &bySignal
285 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
286 //RSPINF_b_11
287 BBvCaculateParameter(pDevice,
289 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
290 PK_TYPE_11B,
291 &wLen,
292 &byServ,
293 &bySignal
296 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
297 //RSPINF_a_6
298 s_vCaculateOFDMRParameter(RATE_6M,
299 ePHYType,
300 &byTxRate,
301 &byRsvTime);
302 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
303 //RSPINF_a_9
304 s_vCaculateOFDMRParameter(RATE_9M,
305 ePHYType,
306 &byTxRate,
307 &byRsvTime);
308 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
309 //RSPINF_a_12
310 s_vCaculateOFDMRParameter(RATE_12M,
311 ePHYType,
312 &byTxRate,
313 &byRsvTime);
314 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
315 //RSPINF_a_18
316 s_vCaculateOFDMRParameter(RATE_18M,
317 ePHYType,
318 &byTxRate,
319 &byRsvTime);
320 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
321 //RSPINF_a_24
322 s_vCaculateOFDMRParameter(RATE_24M,
323 ePHYType,
324 &byTxRate,
325 &byRsvTime);
326 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
327 //RSPINF_a_36
328 s_vCaculateOFDMRParameter(
329 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
330 ePHYType,
331 &byTxRate,
332 &byRsvTime);
333 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
334 //RSPINF_a_48
335 s_vCaculateOFDMRParameter(
336 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
337 ePHYType,
338 &byTxRate,
339 &byRsvTime);
340 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
341 //RSPINF_a_54
342 s_vCaculateOFDMRParameter(
343 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
344 ePHYType,
345 &byTxRate,
346 &byRsvTime);
347 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
348 //RSPINF_a_72
349 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
350 //Set to Page0
351 MACvSelectPage0(pDevice->PortOffset);
354 /*--------------------- Export Functions --------------------------*/
357 * Description: Card Send packet function
359 * Parameters:
360 * In:
361 * pDeviceHandler - The adapter to be set
362 * pPacket - Packet buffer pointer
363 * ePktType - Packet type
364 * uLength - Packet length
365 * Out:
366 * none
368 * Return Value: true if succeeded; false if failed.
372 bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength)
374 PSDevice pDevice = (PSDevice) pDeviceHandler;
375 if (ePktType == PKT_TYPE_802_11_MNG) {
376 return TXbTD0Send(pDevice, pPacket, uLength);
377 } else if (ePktType == PKT_TYPE_802_11_BCN) {
378 return TXbBeaconSend(pDevice, pPacket, uLength);
379 } if (ePktType == PKT_TYPE_802_11_DATA) {
380 return TXbTD1Send(pDevice, pPacket, uLength);
383 return (true);
389 * Description: Get Card short preamble option value
391 * Parameters:
392 * In:
393 * pDevice - The adapter to be set
394 * Out:
395 * none
397 * Return Value: true if short preamble; otherwise false
400 bool CARDbIsShortPreamble (void *pDeviceHandler)
402 PSDevice pDevice = (PSDevice) pDeviceHandler;
403 if (pDevice->byPreambleType == 0) {
404 return(false);
406 return(true);
410 * Description: Get Card short slot time option value
412 * Parameters:
413 * In:
414 * pDevice - The adapter to be set
415 * Out:
416 * none
418 * Return Value: true if short slot time; otherwise false
421 bool CARDbIsShorSlotTime (void *pDeviceHandler)
423 PSDevice pDevice = (PSDevice) pDeviceHandler;
424 return(pDevice->bShortSlotTime);
429 * Description: Update IFS
431 * Parameters:
432 * In:
433 * pDevice - The adapter to be set
434 * Out:
435 * none
437 * Return Value: None.
440 bool CARDbSetPhyParameter (void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
442 PSDevice pDevice = (PSDevice) pDeviceHandler;
443 unsigned char byCWMaxMin = 0;
444 unsigned char bySlot = 0;
445 unsigned char bySIFS = 0;
446 unsigned char byDIFS = 0;
447 unsigned char byData;
448 // PWLAN_IE_SUPP_RATES pRates = NULL;
449 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
450 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
453 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
454 if (ePHYType == PHY_TYPE_11A) {
455 if (pSupportRates == NULL) {
456 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
458 if (pDevice->byRFType == RF_AIROHA7230) {
459 // AL7230 use single PAPE and connect to PAPE_2.4G
460 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
461 pDevice->abyBBVGA[0] = 0x20;
462 pDevice->abyBBVGA[2] = 0x10;
463 pDevice->abyBBVGA[3] = 0x10;
464 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
465 if (byData == 0x1C) {
466 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
468 } else if (pDevice->byRFType == RF_UW2452) {
469 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
470 pDevice->abyBBVGA[0] = 0x18;
471 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
472 if (byData == 0x14) {
473 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
474 BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0x57);
476 } else {
477 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
479 BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x03);
480 bySlot = C_SLOT_SHORT;
481 bySIFS = C_SIFS_A;
482 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
483 byCWMaxMin = 0xA4;
484 } else if (ePHYType == PHY_TYPE_11B) {
485 if (pSupportRates == NULL) {
486 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
488 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
489 if (pDevice->byRFType == RF_AIROHA7230) {
490 pDevice->abyBBVGA[0] = 0x1C;
491 pDevice->abyBBVGA[2] = 0x00;
492 pDevice->abyBBVGA[3] = 0x00;
493 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
494 if (byData == 0x20) {
495 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
497 } else if (pDevice->byRFType == RF_UW2452) {
498 pDevice->abyBBVGA[0] = 0x14;
499 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
500 if (byData == 0x18) {
501 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
502 BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0xD3);
505 BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x02);
506 bySlot = C_SLOT_LONG;
507 bySIFS = C_SIFS_BG;
508 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
509 byCWMaxMin = 0xA5;
510 } else {// PK_TYPE_11GA & PK_TYPE_11GB
511 if (pSupportRates == NULL) {
512 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
513 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
515 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
516 if (pDevice->byRFType == RF_AIROHA7230) {
517 pDevice->abyBBVGA[0] = 0x1C;
518 pDevice->abyBBVGA[2] = 0x00;
519 pDevice->abyBBVGA[3] = 0x00;
520 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
521 if (byData == 0x20) {
522 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
524 } else if (pDevice->byRFType == RF_UW2452) {
525 pDevice->abyBBVGA[0] = 0x14;
526 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
527 if (byData == 0x18) {
528 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
529 BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0xD3);
532 BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x08);
533 bySIFS = C_SIFS_BG;
534 if(VNTWIFIbIsShortSlotTime(wCapInfo)) {
535 bySlot = C_SLOT_SHORT;
536 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
537 } else {
538 bySlot = C_SLOT_LONG;
539 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
541 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
542 byCWMaxMin = 0xA4;
543 } else {
544 byCWMaxMin = 0xA5;
546 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
547 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
548 if (pDevice->bProtectMode) {
549 MACvEnableProtectMD(pDevice->PortOffset);
550 } else {
551 MACvDisableProtectMD(pDevice->PortOffset);
554 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
555 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
556 if (pDevice->bBarkerPreambleMd) {
557 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
558 } else {
559 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
564 if (pDevice->byRFType == RF_RFMD2959) {
565 // bcs TX_PE will reserve 3 us
566 // hardware's processing time here is 2 us.
567 bySIFS -= 3;
568 byDIFS -= 3;
569 //{{ RobertYu: 20041202
570 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
571 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
574 if (pDevice->bySIFS != bySIFS) {
575 pDevice->bySIFS = bySIFS;
576 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
578 if (pDevice->byDIFS != byDIFS) {
579 pDevice->byDIFS = byDIFS;
580 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
582 if (pDevice->byEIFS != C_EIFS) {
583 pDevice->byEIFS = C_EIFS;
584 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
586 if (pDevice->bySlot != bySlot) {
587 pDevice->bySlot = bySlot;
588 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
589 if (pDevice->bySlot == C_SLOT_SHORT) {
590 pDevice->bShortSlotTime = true;
591 } else {
592 pDevice->bShortSlotTime = false;
594 BBvSetShortSlotTime(pDevice);
596 if (pDevice->byCWMaxMin != byCWMaxMin) {
597 pDevice->byCWMaxMin = byCWMaxMin;
598 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
600 if (VNTWIFIbIsShortPreamble(wCapInfo)) {
601 pDevice->byPreambleType = pDevice->byShortPreamble;
602 } else {
603 pDevice->byPreambleType = 0;
605 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
606 pDevice->eCurrentPHYType = ePHYType;
607 // set for NDIS OID_802_11SUPPORTED_RATES
608 return (true);
612 * Description: Sync. TSF counter to BSS
613 * Get TSF offset and write to HW
615 * Parameters:
616 * In:
617 * pDevice - The adapter to be sync.
618 * byRxRate - data rate of receive beacon
619 * qwBSSTimestamp - Rx BCN's TSF
620 * qwLocalTSF - Local TSF
621 * Out:
622 * none
624 * Return Value: none
627 bool CARDbUpdateTSF (void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
629 PSDevice pDevice = (PSDevice) pDeviceHandler;
630 QWORD qwTSFOffset;
632 HIDWORD(qwTSFOffset) = 0;
633 LODWORD(qwTSFOffset) = 0;
635 if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
636 (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
637 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
638 // adjust TSF
639 // HW's TSF add TSF Offset reg
640 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
641 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
642 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
644 return(true);
649 * Description: Set NIC TSF counter for first Beacon time
650 * Get NEXTTBTT from adjusted TSF and Beacon Interval
652 * Parameters:
653 * In:
654 * pDevice - The adapter to be set.
655 * wBeaconInterval - Beacon Interval
656 * Out:
657 * none
659 * Return Value: true if succeed; otherwise false
662 bool CARDbSetBeaconPeriod (void *pDeviceHandler, unsigned short wBeaconInterval)
664 PSDevice pDevice = (PSDevice) pDeviceHandler;
665 unsigned int uBeaconInterval = 0;
666 unsigned int uLowNextTBTT = 0;
667 unsigned int uHighRemain = 0;
668 unsigned int uLowRemain = 0;
669 QWORD qwNextTBTT;
671 HIDWORD(qwNextTBTT) = 0;
672 LODWORD(qwNextTBTT) = 0;
673 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
674 uBeaconInterval = wBeaconInterval * 1024;
675 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
676 uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
677 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
678 // high dword (mod) bcn
679 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
680 % uBeaconInterval;
681 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
682 uLowRemain = uBeaconInterval - uLowRemain;
684 // check if carry when add one beacon interval
685 if ((~uLowNextTBTT) < uLowRemain) {
686 HIDWORD(qwNextTBTT) ++ ;
688 LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
690 // set HW beacon interval
691 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
692 pDevice->wBeaconInterval = wBeaconInterval;
693 // Set NextTBTT
694 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
695 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
696 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
698 return(true);
704 * Description: Card Stop Hardware Tx
706 * Parameters:
707 * In:
708 * pDeviceHandler - The adapter to be set
709 * ePktType - Packet type to stop
710 * Out:
711 * none
713 * Return Value: true if all data packet complete; otherwise false.
716 bool CARDbStopTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
718 PSDevice pDevice = (PSDevice) pDeviceHandler;
721 if (ePktType == PKT_TYPE_802_11_ALL) {
722 pDevice->bStopBeacon = true;
723 pDevice->bStopTx0Pkt = true;
724 pDevice->bStopDataPkt = true;
725 } else if (ePktType == PKT_TYPE_802_11_BCN) {
726 pDevice->bStopBeacon = true;
727 } else if (ePktType == PKT_TYPE_802_11_MNG) {
728 pDevice->bStopTx0Pkt = true;
729 } else if (ePktType == PKT_TYPE_802_11_DATA) {
730 pDevice->bStopDataPkt = true;
733 if (pDevice->bStopBeacon == true) {
734 if (pDevice->bIsBeaconBufReadySet == true) {
735 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
736 pDevice->cbBeaconBufReadySetCnt ++;
737 return(false);
740 pDevice->bIsBeaconBufReadySet = false;
741 pDevice->cbBeaconBufReadySetCnt = 0;
742 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
744 // wait all TD0 complete
745 if (pDevice->bStopTx0Pkt == true) {
746 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
747 return(false);
750 // wait all Data TD complete
751 if (pDevice->bStopDataPkt == true) {
752 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
753 return(false);
757 return(true);
762 * Description: Card Start Hardware Tx
764 * Parameters:
765 * In:
766 * pDeviceHandler - The adapter to be set
767 * ePktType - Packet type to start
768 * Out:
769 * none
771 * Return Value: true if success; false if failed.
774 bool CARDbStartTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
776 PSDevice pDevice = (PSDevice) pDeviceHandler;
779 if (ePktType == PKT_TYPE_802_11_ALL) {
780 pDevice->bStopBeacon = false;
781 pDevice->bStopTx0Pkt = false;
782 pDevice->bStopDataPkt = false;
783 } else if (ePktType == PKT_TYPE_802_11_BCN) {
784 pDevice->bStopBeacon = false;
785 } else if (ePktType == PKT_TYPE_802_11_MNG) {
786 pDevice->bStopTx0Pkt = false;
787 } else if (ePktType == PKT_TYPE_802_11_DATA) {
788 pDevice->bStopDataPkt = false;
791 if ((pDevice->bStopBeacon == false) &&
792 (pDevice->bBeaconBufReady == true) &&
793 (pDevice->eOPMode == OP_MODE_ADHOC)) {
794 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
797 return(true);
803 * Description: Card Set BSSID value
805 * Parameters:
806 * In:
807 * pDeviceHandler - The adapter to be set
808 * pbyBSSID - pointer to BSSID field
809 * bAdhoc - flag to indicate IBSS
810 * Out:
811 * none
813 * Return Value: true if success; false if failed.
816 bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
818 PSDevice pDevice = (PSDevice) pDeviceHandler;
820 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
821 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
822 if (eOPMode == OP_MODE_ADHOC) {
823 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
824 } else {
825 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
827 if (eOPMode == OP_MODE_AP) {
828 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
829 } else {
830 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
832 if (eOPMode == OP_MODE_UNKNOWN) {
833 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
834 pDevice->bBSSIDFilter = false;
835 pDevice->byRxMode &= ~RCR_BSSID;
836 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
837 } else {
838 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
839 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
840 pDevice->bBSSIDFilter = true;
841 pDevice->byRxMode |= RCR_BSSID;
843 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode );
845 // Adopt BSS state in Adapter Device Object
846 pDevice->eOPMode = eOPMode;
847 return(true);
852 * Description: Card indicate status
854 * Parameters:
855 * In:
856 * pDeviceHandler - The adapter to be set
857 * eStatus - Status
858 * Out:
859 * none
861 * Return Value: true if success; false if failed.
869 * Description: Save Assoc info. contain in assoc. response frame
871 * Parameters:
872 * In:
873 * pDevice - The adapter to be set
874 * wCapabilityInfo - Capability information
875 * wStatus - Status code
876 * wAID - Assoc. ID
877 * uLen - Length of IEs
878 * pbyIEs - pointer to IEs
879 * Out:
880 * none
882 * Return Value: true if succeed; otherwise false
885 bool CARDbSetTxDataRate(
886 void *pDeviceHandler,
887 unsigned short wDataRate
890 PSDevice pDevice = (PSDevice) pDeviceHandler;
892 pDevice->wCurrentRate = wDataRate;
893 return(true);
898 * Routine Description:
899 * Consider to power down when no more packets to tx or rx.
901 * Parameters:
902 * In:
903 * pDevice - The adapter to be set
904 * Out:
905 * none
907 * Return Value: true if power down success; otherwise false
910 bool
911 CARDbPowerDown(
912 void *pDeviceHandler
915 PSDevice pDevice = (PSDevice)pDeviceHandler;
916 unsigned int uIdx;
918 // check if already in Doze mode
919 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
920 return true;
922 // Froce PSEN on
923 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
925 // check if all TD are empty,
927 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
928 if (pDevice->iTDUsed[uIdx] != 0)
929 return false;
932 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
933 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Go to Doze ZZZZZZZZZZZZZZZ\n");
934 return true;
938 * Description: Turn off Radio power
940 * Parameters:
941 * In:
942 * pDevice - The adapter to be turned off
943 * Out:
944 * none
946 * Return Value: true if success; otherwise false
949 bool CARDbRadioPowerOff (void *pDeviceHandler)
951 PSDevice pDevice = (PSDevice) pDeviceHandler;
952 bool bResult = true;
954 if (pDevice->bRadioOff == true)
955 return true;
958 switch (pDevice->byRFType) {
960 case RF_RFMD2959:
961 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
962 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
963 break;
965 case RF_AIROHA:
966 case RF_AL2230S:
967 case RF_AIROHA7230: //RobertYu:20050104
968 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
969 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
970 break;
974 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
976 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
978 pDevice->bRadioOff = true;
979 //2007-0409-03,<Add> by chester
980 printk("chester power off\n");
981 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
982 return bResult;
987 * Description: Turn on Radio power
989 * Parameters:
990 * In:
991 * pDevice - The adapter to be turned on
992 * Out:
993 * none
995 * Return Value: true if success; otherwise false
998 bool CARDbRadioPowerOn (void *pDeviceHandler)
1000 PSDevice pDevice = (PSDevice) pDeviceHandler;
1001 bool bResult = true;
1002 printk("chester power on\n");
1003 if (pDevice->bRadioControlOff == true){
1004 if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
1005 if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
1006 return false;}
1008 if (pDevice->bRadioOff == false)
1010 printk("chester pbRadioOff\n");
1011 return true;}
1013 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
1015 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
1017 switch (pDevice->byRFType) {
1019 case RF_RFMD2959:
1020 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
1021 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
1022 break;
1024 case RF_AIROHA:
1025 case RF_AL2230S:
1026 case RF_AIROHA7230: //RobertYu:20050104
1027 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
1028 SOFTPWRCTL_SWPE3));
1029 break;
1033 pDevice->bRadioOff = false;
1034 // 2007-0409-03,<Add> by chester
1035 printk("chester power on\n");
1036 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
1037 return bResult;
1042 bool CARDbRemoveKey (void *pDeviceHandler, unsigned char *pbyBSSID)
1044 PSDevice pDevice = (PSDevice) pDeviceHandler;
1046 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
1047 return (true);
1053 * Description:
1054 * Add BSSID in PMKID Candidate list.
1056 * Parameters:
1057 * In:
1058 * hDeviceContext - device structure point
1059 * pbyBSSID - BSSID address for adding
1060 * wRSNCap - BSS's RSN capability
1061 * Out:
1062 * none
1064 * Return Value: none.
1067 bool
1068 CARDbAdd_PMKID_Candidate (
1069 void *pDeviceHandler,
1070 unsigned char *pbyBSSID,
1071 bool bRSNCapExist,
1072 unsigned short wRSNCap
1075 PSDevice pDevice = (PSDevice) pDeviceHandler;
1076 PPMKID_CANDIDATE pCandidateList;
1077 unsigned int ii = 0;
1079 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1081 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1082 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 3\n");
1083 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1086 for (ii = 0; ii < 6; ii++) {
1087 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02X ", *(pbyBSSID + ii));
1089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1092 // Update Old Candidate
1093 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1094 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1095 if ( !memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
1096 if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
1097 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1098 } else {
1099 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1101 return true;
1105 // New Candidate
1106 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1107 if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
1108 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1109 } else {
1110 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1112 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1113 pDevice->gsPMKIDCandidate.NumCandidates++;
1114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1115 return true;
1118 void *
1119 CARDpGetCurrentAddress (
1120 void *pDeviceHandler
1123 PSDevice pDevice = (PSDevice) pDeviceHandler;
1125 return (pDevice->abyCurrentNetAddr);
1130 * Description:
1131 * Start Spectrum Measure defined in 802.11h
1133 * Parameters:
1134 * In:
1135 * hDeviceContext - device structure point
1136 * Out:
1137 * none
1139 * Return Value: none.
1142 bool
1143 CARDbStartMeasure (
1144 void *pDeviceHandler,
1145 void *pvMeasureEIDs,
1146 unsigned int uNumOfMeasureEIDs
1149 PSDevice pDevice = (PSDevice) pDeviceHandler;
1150 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1151 QWORD qwCurrTSF;
1152 QWORD qwStartTSF;
1153 bool bExpired = true;
1154 unsigned short wDuration = 0;
1156 if ((pEID == NULL) ||
1157 (uNumOfMeasureEIDs == 0)) {
1158 return (true);
1160 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1161 if (pDevice->bMeasureInProgress == true) {
1162 pDevice->bMeasureInProgress = false;
1163 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1164 MACvSelectPage1(pDevice->PortOffset);
1165 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1166 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1167 // clear measure control
1168 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1169 MACvSelectPage0(pDevice->PortOffset);
1170 set_channel(pDevice, pDevice->byOrgChannel);
1171 MACvSelectPage1(pDevice->PortOffset);
1172 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1173 MACvSelectPage0(pDevice->PortOffset);
1175 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1177 do {
1178 pDevice->pCurrMeasureEID = pEID;
1179 pEID++;
1180 pDevice->uNumOfMeasureEIDs--;
1182 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1183 HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1184 LODWORD(qwStartTSF) = LODWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1185 wDuration = *((unsigned short *) (pDevice->pCurrMeasureEID->sReq.abyDuration));
1186 wDuration += 1; // 1 TU for channel switching
1188 if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1189 // start immediately by setting start TSF == current TSF + 2 TU
1190 LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1191 HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
1192 if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
1193 HIDWORD(qwStartTSF)++;
1195 bExpired = false;
1196 break;
1197 } else {
1198 // start at setting start TSF - 1TU(for channel switching)
1199 if (LODWORD(qwStartTSF) < 1024) {
1200 HIDWORD(qwStartTSF)--;
1202 LODWORD(qwStartTSF) -= 1024;
1205 if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1206 ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1207 (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1209 bExpired = false;
1210 break;
1212 VNTWIFIbMeasureReport( pDevice->pMgmt,
1213 false,
1214 pDevice->pCurrMeasureEID,
1215 MEASURE_MODE_LATE,
1216 pDevice->byBasicMap,
1217 pDevice->byCCAFraction,
1218 pDevice->abyRPIs
1220 } else {
1221 // hardware do not support measure
1222 VNTWIFIbMeasureReport( pDevice->pMgmt,
1223 false,
1224 pDevice->pCurrMeasureEID,
1225 MEASURE_MODE_INCAPABLE,
1226 pDevice->byBasicMap,
1227 pDevice->byCCAFraction,
1228 pDevice->abyRPIs
1231 } while (pDevice->uNumOfMeasureEIDs != 0);
1233 if (bExpired == false) {
1234 MACvSelectPage1(pDevice->PortOffset);
1235 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1236 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1237 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1238 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1239 MACvSelectPage0(pDevice->PortOffset);
1240 } else {
1241 // all measure start time expired we should complete action
1242 VNTWIFIbMeasureReport( pDevice->pMgmt,
1243 true,
1244 NULL,
1246 pDevice->byBasicMap,
1247 pDevice->byCCAFraction,
1248 pDevice->abyRPIs
1251 return (true);
1257 * Description:
1258 * Do Channel Switch defined in 802.11h
1260 * Parameters:
1261 * In:
1262 * hDeviceContext - device structure point
1263 * Out:
1264 * none
1266 * Return Value: none.
1269 bool
1270 CARDbChannelSwitch (
1271 void *pDeviceHandler,
1272 unsigned char byMode,
1273 unsigned char byNewChannel,
1274 unsigned char byCount
1277 PSDevice pDevice = (PSDevice) pDeviceHandler;
1278 bool bResult = true;
1280 if (byCount == 0) {
1281 bResult = set_channel(pDevice, byNewChannel);
1282 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1283 MACvSelectPage1(pDevice->PortOffset);
1284 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1285 MACvSelectPage0(pDevice->PortOffset);
1286 return(bResult);
1288 pDevice->byChannelSwitchCount = byCount;
1289 pDevice->byNewChannel = byNewChannel;
1290 pDevice->bChannelSwitch = true;
1291 if (byMode == 1) {
1292 bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1294 return (bResult);
1300 * Description:
1301 * Handle Quiet EID defined in 802.11h
1303 * Parameters:
1304 * In:
1305 * hDeviceContext - device structure point
1306 * Out:
1307 * none
1309 * Return Value: none.
1312 bool
1313 CARDbSetQuiet (
1314 void *pDeviceHandler,
1315 bool bResetQuiet,
1316 unsigned char byQuietCount,
1317 unsigned char byQuietPeriod,
1318 unsigned short wQuietDuration,
1319 unsigned short wQuietOffset
1322 PSDevice pDevice = (PSDevice) pDeviceHandler;
1323 unsigned int ii = 0;
1325 if (bResetQuiet == true) {
1326 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1327 for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1328 pDevice->sQuiet[ii].bEnable = false;
1330 pDevice->uQuietEnqueue = 0;
1331 pDevice->bEnableFirstQuiet = false;
1332 pDevice->bQuietEnable = false;
1333 pDevice->byQuietStartCount = byQuietCount;
1335 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1336 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1337 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1338 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1339 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1340 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1341 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1342 pDevice->uQuietEnqueue++;
1343 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1344 if (pDevice->byQuietStartCount < byQuietCount) {
1345 pDevice->byQuietStartCount = byQuietCount;
1347 } else {
1348 // we can not handle Quiet EID more
1350 return (true);
1356 * Description:
1357 * Do Quiet, It will called by either ISR (after start) or VNTWIFI (before start) so do not need SPINLOCK
1359 * Parameters:
1360 * In:
1361 * hDeviceContext - device structure point
1362 * Out:
1363 * none
1365 * Return Value: none.
1368 bool
1369 CARDbStartQuiet (
1370 void *pDeviceHandler
1373 PSDevice pDevice = (PSDevice) pDeviceHandler;
1374 unsigned int ii = 0;
1375 unsigned long dwStartTime = 0xFFFFFFFF;
1376 unsigned int uCurrentQuietIndex = 0;
1377 unsigned long dwNextTime = 0;
1378 unsigned long dwGap = 0;
1379 unsigned long dwDuration = 0;
1381 for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1382 if ((pDevice->sQuiet[ii].bEnable == true) &&
1383 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1384 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1385 uCurrentQuietIndex = ii;
1388 if (dwStartTime == 0xFFFFFFFF) {
1389 // no more quiet
1390 pDevice->bQuietEnable = false;
1391 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1392 } else {
1393 if (pDevice->bQuietEnable == false) {
1394 // first quiet
1395 pDevice->byQuietStartCount--;
1396 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1397 dwNextTime %= pDevice->wBeaconInterval;
1398 MACvSelectPage1(pDevice->PortOffset);
1399 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1400 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1401 if (pDevice->byQuietStartCount == 0) {
1402 pDevice->bEnableFirstQuiet = false;
1403 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1404 } else {
1405 pDevice->bEnableFirstQuiet = true;
1407 MACvSelectPage0(pDevice->PortOffset);
1408 } else {
1409 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1410 // overlap with previous Quiet
1411 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1412 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1413 // return false to indicate next quiet expired, should call this function again
1414 return (false);
1416 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1417 dwGap = 0;
1418 } else {
1419 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1420 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1422 // set GAP and Next duration
1423 MACvSelectPage1(pDevice->PortOffset);
1424 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1425 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1426 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1427 MACvSelectPage0(pDevice->PortOffset);
1429 pDevice->bQuietEnable = true;
1430 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1431 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1432 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1433 // not period disable current quiet element
1434 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1435 } else {
1436 // set next period start time
1437 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1438 dwNextTime *= pDevice->wBeaconInterval;
1439 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1441 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1442 // decreament all time to avoid wrap around
1443 for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1444 if (pDevice->sQuiet[ii].bEnable == true) {
1445 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1448 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1451 return (true);
1456 * Description:
1457 * Set Local Power Constraint
1459 * Parameters:
1460 * In:
1461 * hDeviceContext - device structure point
1462 * Out:
1463 * none
1465 * Return Value: none.
1468 void
1469 CARDvSetPowerConstraint (
1470 void *pDeviceHandler,
1471 unsigned char byChannel,
1472 char byPower
1475 PSDevice pDevice = (PSDevice) pDeviceHandler;
1477 if (byChannel > CB_MAX_CHANNEL_24G) {
1478 if (pDevice->bCountryInfo5G == true) {
1479 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1481 } else {
1482 if (pDevice->bCountryInfo24G == true) {
1483 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1491 * Description:
1492 * Set Local Power Constraint
1494 * Parameters:
1495 * In:
1496 * hDeviceContext - device structure point
1497 * Out:
1498 * none
1500 * Return Value: none.
1503 void
1504 CARDvGetPowerCapability (
1505 void *pDeviceHandler,
1506 unsigned char *pbyMinPower,
1507 unsigned char *pbyMaxPower
1510 PSDevice pDevice = (PSDevice) pDeviceHandler;
1511 unsigned char byDec = 0;
1513 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1514 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1515 if (pDevice->byRFType == RF_UW2452) {
1516 byDec *= 3;
1517 byDec >>= 1;
1518 } else {
1519 byDec <<= 1;
1521 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1526 * Description:
1527 * Get Current Tx Power
1529 * Parameters:
1530 * In:
1531 * hDeviceContext - device structure point
1532 * Out:
1533 * none
1535 * Return Value: none.
1538 char
1539 CARDbyGetTransmitPower (
1540 void *pDeviceHandler
1543 PSDevice pDevice = (PSDevice) pDeviceHandler;
1545 return (pDevice->byCurPwrdBm);
1548 //xxx
1549 void
1550 CARDvSafeResetTx (
1551 void *pDeviceHandler
1554 PSDevice pDevice = (PSDevice) pDeviceHandler;
1555 unsigned int uu;
1556 PSTxDesc pCurrTD;
1558 // initialize TD index
1559 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1560 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1562 for (uu = 0; uu < TYPE_MAXTD; uu ++)
1563 pDevice->iTDUsed[uu] = 0;
1565 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1566 pCurrTD = &(pDevice->apTD0Rings[uu]);
1567 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1568 // init all Tx Packet pointer to NULL
1570 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1571 pCurrTD = &(pDevice->apTD1Rings[uu]);
1572 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1573 // init all Tx Packet pointer to NULL
1576 // set MAC TD pointer
1577 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1578 (pDevice->td0_pool_dma));
1580 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1581 (pDevice->td1_pool_dma));
1583 // set MAC Beacon TX pointer
1584 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1585 (pDevice->tx_beacon_dma));
1593 * Description:
1594 * Reset Rx
1596 * Parameters:
1597 * In:
1598 * pDevice - Pointer to the adapter
1599 * Out:
1600 * none
1602 * Return Value: none
1605 void
1606 CARDvSafeResetRx (
1607 void *pDeviceHandler
1610 PSDevice pDevice = (PSDevice) pDeviceHandler;
1611 unsigned int uu;
1612 PSRxDesc pDesc;
1616 // initialize RD index
1617 pDevice->pCurrRD[0]=&(pDevice->aRD0Ring[0]);
1618 pDevice->pCurrRD[1]=&(pDevice->aRD1Ring[0]);
1620 // init state, all RD is chip's
1621 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1622 pDesc =&(pDevice->aRD0Ring[uu]);
1623 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1624 pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
1625 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1628 // init state, all RD is chip's
1629 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1630 pDesc =&(pDevice->aRD1Ring[uu]);
1631 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1632 pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
1633 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1636 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1637 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1639 // set perPkt mode
1640 MACvRx0PerPktMode(pDevice->PortOffset);
1641 MACvRx1PerPktMode(pDevice->PortOffset);
1642 // set MAC RD pointer
1643 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1644 pDevice->rd0_pool_dma);
1646 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1647 pDevice->rd1_pool_dma);
1654 * Description: Get response Control frame rate in CCK mode
1656 * Parameters:
1657 * In:
1658 * pDevice - The adapter to be set
1659 * wRateIdx - Receiving data rate
1660 * Out:
1661 * none
1663 * Return Value: response Control frame rate
1666 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
1668 PSDevice pDevice = (PSDevice) pDeviceHandler;
1669 unsigned int ui = (unsigned int) wRateIdx;
1671 while (ui > RATE_1M) {
1672 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1673 return (unsigned short)ui;
1675 ui --;
1677 return (unsigned short)RATE_1M;
1681 * Description: Get response Control frame rate in OFDM mode
1683 * Parameters:
1684 * In:
1685 * pDevice - The adapter to be set
1686 * wRateIdx - Receiving data rate
1687 * Out:
1688 * none
1690 * Return Value: response Control frame rate
1693 unsigned short CARDwGetOFDMControlRate (void *pDeviceHandler, unsigned short wRateIdx)
1695 PSDevice pDevice = (PSDevice) pDeviceHandler;
1696 unsigned int ui = (unsigned int) wRateIdx;
1698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
1700 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1702 if (wRateIdx > RATE_24M)
1703 wRateIdx = RATE_24M;
1704 return wRateIdx;
1706 while (ui > RATE_11M) {
1707 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1708 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate : %d\n", ui);
1709 return (unsigned short)ui;
1711 ui --;
1713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate: 6M\n");
1714 return (unsigned short)RATE_24M;
1719 * Description: Set RSPINF
1721 * Parameters:
1722 * In:
1723 * pDevice - The adapter to be set
1724 * Out:
1725 * none
1727 * Return Value: None.
1730 void CARDvSetRSPINF (void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
1732 PSDevice pDevice = (PSDevice) pDeviceHandler;
1733 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1734 unsigned short wLen = 0x0000;
1735 unsigned char byTxRate, byRsvTime; //For OFDM
1737 //Set to Page1
1738 MACvSelectPage1(pDevice->PortOffset);
1740 //RSPINF_b_1
1741 BBvCaculateParameter(pDevice,
1743 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1744 PK_TYPE_11B,
1745 &wLen,
1746 &byServ,
1747 &bySignal
1750 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1751 ///RSPINF_b_2
1752 BBvCaculateParameter(pDevice,
1754 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1755 PK_TYPE_11B,
1756 &wLen,
1757 &byServ,
1758 &bySignal
1761 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1762 //RSPINF_b_5
1763 BBvCaculateParameter(pDevice,
1765 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1766 PK_TYPE_11B,
1767 &wLen,
1768 &byServ,
1769 &bySignal
1772 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1773 //RSPINF_b_11
1774 BBvCaculateParameter(pDevice,
1776 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1777 PK_TYPE_11B,
1778 &wLen,
1779 &byServ,
1780 &bySignal
1783 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1784 //RSPINF_a_6
1785 s_vCaculateOFDMRParameter(RATE_6M,
1786 ePHYType,
1787 &byTxRate,
1788 &byRsvTime);
1789 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
1790 //RSPINF_a_9
1791 s_vCaculateOFDMRParameter(RATE_9M,
1792 ePHYType,
1793 &byTxRate,
1794 &byRsvTime);
1795 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
1796 //RSPINF_a_12
1797 s_vCaculateOFDMRParameter(RATE_12M,
1798 ePHYType,
1799 &byTxRate,
1800 &byRsvTime);
1801 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
1802 //RSPINF_a_18
1803 s_vCaculateOFDMRParameter(RATE_18M,
1804 ePHYType,
1805 &byTxRate,
1806 &byRsvTime);
1807 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
1808 //RSPINF_a_24
1809 s_vCaculateOFDMRParameter(RATE_24M,
1810 ePHYType,
1811 &byTxRate,
1812 &byRsvTime);
1813 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
1814 //RSPINF_a_36
1815 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1816 ePHYType,
1817 &byTxRate,
1818 &byRsvTime);
1819 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
1820 //RSPINF_a_48
1821 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1822 ePHYType,
1823 &byTxRate,
1824 &byRsvTime);
1825 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
1826 //RSPINF_a_54
1827 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1828 ePHYType,
1829 &byTxRate,
1830 &byRsvTime);
1831 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
1833 //RSPINF_a_72
1834 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1835 ePHYType,
1836 &byTxRate,
1837 &byRsvTime);
1838 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
1839 //Set to Page0
1840 MACvSelectPage0(pDevice->PortOffset);
1844 * Description: Update IFS
1846 * Parameters:
1847 * In:
1848 * pDevice - The adapter to be set
1849 * Out:
1850 * none
1852 * Return Value: None.
1855 void vUpdateIFS (void *pDeviceHandler)
1857 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1858 PSDevice pDevice = (PSDevice) pDeviceHandler;
1860 unsigned char byMaxMin = 0;
1861 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
1862 pDevice->uSlot = C_SLOT_SHORT;
1863 pDevice->uSIFS = C_SIFS_A;
1864 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1865 pDevice->uCwMin = C_CWMIN_A;
1866 byMaxMin = 4;
1868 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
1869 pDevice->uSlot = C_SLOT_LONG;
1870 pDevice->uSIFS = C_SIFS_BG;
1871 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1872 pDevice->uCwMin = C_CWMIN_B;
1873 byMaxMin = 5;
1875 else { // PK_TYPE_11GA & PK_TYPE_11GB
1876 pDevice->uSIFS = C_SIFS_BG;
1877 if (pDevice->bShortSlotTime) {
1878 pDevice->uSlot = C_SLOT_SHORT;
1879 } else {
1880 pDevice->uSlot = C_SLOT_LONG;
1882 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1883 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1884 pDevice->uCwMin = C_CWMIN_A;
1885 byMaxMin = 4;
1887 else {
1888 pDevice->uCwMin = C_CWMIN_B;
1889 byMaxMin = 5;
1893 pDevice->uCwMax = C_CWMAX;
1894 pDevice->uEIFS = C_EIFS;
1895 if (pDevice->byRFType == RF_RFMD2959) {
1896 // bcs TX_PE will reserve 3 us
1897 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1898 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1899 } else {
1900 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1901 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1903 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1904 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1905 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1906 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1909 void CARDvUpdateBasicTopRate (void *pDeviceHandler)
1911 PSDevice pDevice = (PSDevice) pDeviceHandler;
1912 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1913 unsigned char ii;
1915 //Determines the highest basic rate.
1916 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
1917 if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
1918 byTopOFDM = ii;
1919 break;
1922 pDevice->byTopOFDMBasicRate = byTopOFDM;
1924 for (ii = RATE_11M;; ii --) {
1925 if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
1926 byTopCCK = ii;
1927 break;
1929 if (ii == RATE_1M)
1930 break;
1932 pDevice->byTopCCKBasicRate = byTopCCK;
1937 * Description: Set NIC Tx Basic Rate
1939 * Parameters:
1940 * In:
1941 * pDevice - The adapter to be set
1942 * wBasicRate - Basic Rate to be set
1943 * Out:
1944 * none
1946 * Return Value: true if succeeded; false if failed.
1949 bool CARDbAddBasicRate (void *pDeviceHandler, unsigned short wRateIdx)
1951 PSDevice pDevice = (PSDevice) pDeviceHandler;
1952 unsigned short wRate = (unsigned short)(1<<wRateIdx);
1954 pDevice->wBasicRate |= wRate;
1956 //Determines the highest basic rate.
1957 CARDvUpdateBasicTopRate((void *)pDevice);
1959 return(true);
1962 bool CARDbIsOFDMinBasicRate (void *pDeviceHandler)
1964 PSDevice pDevice = (PSDevice) pDeviceHandler;
1965 int ii;
1967 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
1968 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii)))
1969 return true;
1971 return false;
1974 unsigned char CARDbyGetPktType (void *pDeviceHandler)
1976 PSDevice pDevice = (PSDevice) pDeviceHandler;
1978 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
1979 return (unsigned char)pDevice->byBBType;
1981 else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
1982 return PK_TYPE_11GA;
1984 else {
1985 return PK_TYPE_11GB;
1990 * Description: Set NIC Loopback mode
1992 * Parameters:
1993 * In:
1994 * pDevice - The adapter to be set
1995 * wLoopbackMode - Loopback mode to be set
1996 * Out:
1997 * none
1999 * Return Value: none
2002 void CARDvSetLoopbackMode (unsigned long dwIoBase, unsigned short wLoopbackMode)
2004 switch(wLoopbackMode) {
2005 case CARD_LB_NONE:
2006 case CARD_LB_MAC:
2007 case CARD_LB_PHY:
2008 break;
2009 default:
2010 ASSERT(false);
2011 break;
2013 // set MAC loopback
2014 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
2015 // set Baseband loopback
2020 * Description: Software Reset NIC
2022 * Parameters:
2023 * In:
2024 * pDevice - The adapter to be reset
2025 * Out:
2026 * none
2028 * Return Value: none
2031 bool CARDbSoftwareReset (void *pDeviceHandler)
2033 PSDevice pDevice = (PSDevice) pDeviceHandler;
2035 // reset MAC
2036 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
2037 return false;
2039 return true;
2044 * Description: Caculate TSF offset of two TSF input
2045 * Get TSF Offset from RxBCN's TSF and local TSF
2047 * Parameters:
2048 * In:
2049 * pDevice - The adapter to be sync.
2050 * qwTSF1 - Rx BCN's TSF
2051 * qwTSF2 - Local TSF
2052 * Out:
2053 * none
2055 * Return Value: TSF Offset value
2058 QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
2060 QWORD qwTSFOffset;
2061 unsigned short wRxBcnTSFOffst= 0;
2063 HIDWORD(qwTSFOffset) = 0;
2064 LODWORD(qwTSFOffset) = 0;
2065 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
2066 (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
2067 if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
2068 (qwTSF2).u.dwHighDword++;
2070 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
2071 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
2072 // if borrow needed
2073 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
2075 else {
2076 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
2078 return (qwTSFOffset);
2083 * Description: Read NIC TSF counter
2084 * Get local TSF counter
2086 * Parameters:
2087 * In:
2088 * pDevice - The adapter to be read
2089 * Out:
2090 * qwCurrTSF - Current TSF counter
2092 * Return Value: true if success; otherwise false
2095 bool CARDbGetCurrentTSF (unsigned long dwIoBase, PQWORD pqwCurrTSF)
2097 unsigned short ww;
2098 unsigned char byData;
2100 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
2101 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
2102 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
2103 if ( !(byData & TFTCTL_TSFCNTRRD))
2104 break;
2106 if (ww == W_MAX_TIMEOUT)
2107 return(false);
2108 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
2109 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
2111 return(true);
2116 * Description: Read NIC TSF counter
2117 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2119 * Parameters:
2120 * In:
2121 * qwTSF - Current TSF counter
2122 * wbeaconInterval - Beacon Interval
2123 * Out:
2124 * qwCurrTSF - Current TSF counter
2126 * Return Value: TSF value of next Beacon
2129 QWORD CARDqGetNextTBTT (QWORD qwTSF, unsigned short wBeaconInterval)
2132 unsigned int uLowNextTBTT;
2133 unsigned int uHighRemain, uLowRemain;
2134 unsigned int uBeaconInterval;
2136 uBeaconInterval = wBeaconInterval * 1024;
2137 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2138 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
2139 // low dword (mod) bcn
2140 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
2141 // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
2142 // % uBeaconInterval;
2143 // high dword (mod) bcn
2144 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
2145 % uBeaconInterval;
2146 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2147 uLowRemain = uBeaconInterval - uLowRemain;
2149 // check if carry when add one beacon interval
2150 if ((~uLowNextTBTT) < uLowRemain)
2151 HIDWORD(qwTSF) ++ ;
2153 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
2155 return (qwTSF);
2160 * Description: Set NIC TSF counter for first Beacon time
2161 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2163 * Parameters:
2164 * In:
2165 * dwIoBase - IO Base
2166 * wBeaconInterval - Beacon Interval
2167 * Out:
2168 * none
2170 * Return Value: none
2173 void CARDvSetFirstNextTBTT (unsigned long dwIoBase, unsigned short wBeaconInterval)
2176 QWORD qwNextTBTT;
2178 HIDWORD(qwNextTBTT) = 0;
2179 LODWORD(qwNextTBTT) = 0;
2180 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
2181 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2182 // Set NextTBTT
2183 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
2184 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
2185 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2186 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
2187 return;
2192 * Description: Sync NIC TSF counter for Beacon time
2193 * Get NEXTTBTT and write to HW
2195 * Parameters:
2196 * In:
2197 * pDevice - The adapter to be set
2198 * qwTSF - Current TSF counter
2199 * wBeaconInterval - Beacon Interval
2200 * Out:
2201 * none
2203 * Return Value: none
2206 void CARDvUpdateNextTBTT (unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
2209 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2210 // Set NextTBTT
2211 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
2212 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
2213 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",
2215 (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
2217 return;