Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / drivers / staging / vt6655 / card.c
blobdb38ca05113064a8e9879b328f8ee8d272653974
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 - Calculate TSFOffset
32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
33 * CARDqGetNextTBTT - Calculate 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.
71 #define C_SLOT_SHORT 9 // micro sec.
72 #define C_SLOT_LONG 20
74 #define C_CWMIN_A 15 // slot time
75 #define C_CWMIN_B 31
77 #define C_CWMAX 1023 // slot time
79 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
81 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
82 static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
83 //6M, 9M, 12M, 48M
84 static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
85 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
86 static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
87 //1M, 2M, 5M, 11M,
88 static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
90 /*--------------------- Static Variables --------------------------*/
92 const unsigned short cwRXBCNTSFOff[MAX_RATE] =
93 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
95 /*--------------------- Static Functions --------------------------*/
97 static
98 void
99 s_vCalculateOFDMRParameter(
100 unsigned char byRate,
101 CARD_PHY_TYPE ePHYType,
102 unsigned char *pbyTxRate,
103 unsigned char *pbyRsvTime
106 /*--------------------- Export Functions --------------------------*/
109 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
111 * Parameters:
112 * In:
113 * wRate - Tx Rate
114 * byPktType - Tx Packet type
115 * Out:
116 * pbyTxRate - pointer to RSPINF TxRate field
117 * pbyRsvTime - pointer to RSPINF RsvTime field
119 * Return Value: none
122 static
123 void
124 s_vCalculateOFDMRParameter(
125 unsigned char byRate,
126 CARD_PHY_TYPE ePHYType,
127 unsigned char *pbyTxRate,
128 unsigned char *pbyRsvTime
131 switch (byRate) {
132 case RATE_6M:
133 if (ePHYType == PHY_TYPE_11A) {//5GHZ
134 *pbyTxRate = 0x9B;
135 *pbyRsvTime = 44;
136 } else {
137 *pbyTxRate = 0x8B;
138 *pbyRsvTime = 50;
140 break;
142 case RATE_9M:
143 if (ePHYType == PHY_TYPE_11A) {//5GHZ
144 *pbyTxRate = 0x9F;
145 *pbyRsvTime = 36;
146 } else {
147 *pbyTxRate = 0x8F;
148 *pbyRsvTime = 42;
150 break;
152 case RATE_12M:
153 if (ePHYType == PHY_TYPE_11A) {//5GHZ
154 *pbyTxRate = 0x9A;
155 *pbyRsvTime = 32;
156 } else {
157 *pbyTxRate = 0x8A;
158 *pbyRsvTime = 38;
160 break;
162 case RATE_18M:
163 if (ePHYType == PHY_TYPE_11A) {//5GHZ
164 *pbyTxRate = 0x9E;
165 *pbyRsvTime = 28;
166 } else {
167 *pbyTxRate = 0x8E;
168 *pbyRsvTime = 34;
170 break;
172 case RATE_36M:
173 if (ePHYType == PHY_TYPE_11A) {//5GHZ
174 *pbyTxRate = 0x9D;
175 *pbyRsvTime = 24;
176 } else {
177 *pbyTxRate = 0x8D;
178 *pbyRsvTime = 30;
180 break;
182 case RATE_48M:
183 if (ePHYType == PHY_TYPE_11A) {//5GHZ
184 *pbyTxRate = 0x98;
185 *pbyRsvTime = 24;
186 } else {
187 *pbyTxRate = 0x88;
188 *pbyRsvTime = 30;
190 break;
192 case RATE_54M:
193 if (ePHYType == PHY_TYPE_11A) {//5GHZ
194 *pbyTxRate = 0x9C;
195 *pbyRsvTime = 24;
196 } else {
197 *pbyTxRate = 0x8C;
198 *pbyRsvTime = 30;
200 break;
202 case RATE_24M:
203 default:
204 if (ePHYType == PHY_TYPE_11A) {//5GHZ
205 *pbyTxRate = 0x99;
206 *pbyRsvTime = 28;
207 } else {
208 *pbyTxRate = 0x89;
209 *pbyRsvTime = 34;
211 break;
216 * Description: Set RSPINF
218 * Parameters:
219 * In:
220 * pDevice - The adapter to be set
221 * Out:
222 * none
224 * Return Value: None.
227 static
228 void
229 s_vSetRSPINF(PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
231 unsigned char byServ = 0, bySignal = 0; // For CCK
232 unsigned short wLen = 0;
233 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
235 //Set to Page1
236 MACvSelectPage1(pDevice->PortOffset);
238 //RSPINF_b_1
239 BBvCalculateParameter(pDevice,
241 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
242 PK_TYPE_11B,
243 &wLen,
244 &byServ,
245 &bySignal
248 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
249 ///RSPINF_b_2
250 BBvCalculateParameter(pDevice,
252 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
253 PK_TYPE_11B,
254 &wLen,
255 &byServ,
256 &bySignal
259 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
260 //RSPINF_b_5
261 BBvCalculateParameter(pDevice,
263 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
264 PK_TYPE_11B,
265 &wLen,
266 &byServ,
267 &bySignal
270 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
271 //RSPINF_b_11
272 BBvCalculateParameter(pDevice,
274 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
275 PK_TYPE_11B,
276 &wLen,
277 &byServ,
278 &bySignal
281 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
282 //RSPINF_a_6
283 s_vCalculateOFDMRParameter(RATE_6M,
284 ePHYType,
285 &byTxRate,
286 &byRsvTime);
287 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
288 //RSPINF_a_9
289 s_vCalculateOFDMRParameter(RATE_9M,
290 ePHYType,
291 &byTxRate,
292 &byRsvTime);
293 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
294 //RSPINF_a_12
295 s_vCalculateOFDMRParameter(RATE_12M,
296 ePHYType,
297 &byTxRate,
298 &byRsvTime);
299 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
300 //RSPINF_a_18
301 s_vCalculateOFDMRParameter(RATE_18M,
302 ePHYType,
303 &byTxRate,
304 &byRsvTime);
305 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
306 //RSPINF_a_24
307 s_vCalculateOFDMRParameter(RATE_24M,
308 ePHYType,
309 &byTxRate,
310 &byRsvTime);
311 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
312 //RSPINF_a_36
313 s_vCalculateOFDMRParameter(
314 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
315 ePHYType,
316 &byTxRate,
317 &byRsvTime);
318 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
319 //RSPINF_a_48
320 s_vCalculateOFDMRParameter(
321 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
322 ePHYType,
323 &byTxRate,
324 &byRsvTime);
325 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
326 //RSPINF_a_54
327 s_vCalculateOFDMRParameter(
328 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
329 ePHYType,
330 &byTxRate,
331 &byRsvTime);
332 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
333 //RSPINF_a_72
334 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
335 //Set to Page0
336 MACvSelectPage0(pDevice->PortOffset);
339 /*--------------------- Export Functions --------------------------*/
342 * Description: Card Send packet function
344 * Parameters:
345 * In:
346 * pDeviceHandler - The adapter to be set
347 * pPacket - Packet buffer pointer
348 * ePktType - Packet type
349 * uLength - Packet length
350 * Out:
351 * none
353 * Return Value: true if succeeded; false if failed.
357 bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength) {
358 PSDevice pDevice = (PSDevice) pDeviceHandler;
359 if (ePktType == PKT_TYPE_802_11_MNG) {
360 return TXbTD0Send(pDevice, pPacket, uLength);
361 } else if (ePktType == PKT_TYPE_802_11_BCN) {
362 return TXbBeaconSend(pDevice, pPacket, uLength);
363 } if (ePktType == PKT_TYPE_802_11_DATA) {
364 return TXbTD1Send(pDevice, pPacket, uLength);
367 return true;
372 * Description: Get Card short preamble option value
374 * Parameters:
375 * In:
376 * pDevice - The adapter to be set
377 * Out:
378 * none
380 * Return Value: true if short preamble; otherwise false
383 bool CARDbIsShortPreamble(void *pDeviceHandler)
385 PSDevice pDevice = (PSDevice) pDeviceHandler;
386 if (pDevice->byPreambleType == 0) {
387 return false;
389 return true;
393 * Description: Get Card short slot time option value
395 * Parameters:
396 * In:
397 * pDevice - The adapter to be set
398 * Out:
399 * none
401 * Return Value: true if short slot time; otherwise false
404 bool CARDbIsShorSlotTime(void *pDeviceHandler)
406 PSDevice pDevice = (PSDevice) pDeviceHandler;
407 return pDevice->bShortSlotTime;
411 * Description: Update IFS
413 * Parameters:
414 * In:
415 * pDevice - The adapter to be set
416 * Out:
417 * none
419 * Return Value: None.
422 bool CARDbSetPhyParameter(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
424 PSDevice pDevice = (PSDevice) pDeviceHandler;
425 unsigned char byCWMaxMin = 0;
426 unsigned char bySlot = 0;
427 unsigned char bySIFS = 0;
428 unsigned char byDIFS = 0;
429 unsigned char byData;
430 // PWLAN_IE_SUPP_RATES pRates = NULL;
431 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
432 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
434 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
435 if (ePHYType == PHY_TYPE_11A) {
436 if (pSupportRates == NULL) {
437 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
439 if (pDevice->byRFType == RF_AIROHA7230) {
440 // AL7230 use single PAPE and connect to PAPE_2.4G
441 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
442 pDevice->abyBBVGA[0] = 0x20;
443 pDevice->abyBBVGA[2] = 0x10;
444 pDevice->abyBBVGA[3] = 0x10;
445 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
446 if (byData == 0x1C) {
447 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
449 } else if (pDevice->byRFType == RF_UW2452) {
450 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
451 pDevice->abyBBVGA[0] = 0x18;
452 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
453 if (byData == 0x14) {
454 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
455 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
457 } else {
458 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
460 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
461 bySlot = C_SLOT_SHORT;
462 bySIFS = C_SIFS_A;
463 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
464 byCWMaxMin = 0xA4;
465 } else if (ePHYType == PHY_TYPE_11B) {
466 if (pSupportRates == NULL) {
467 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
469 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
470 if (pDevice->byRFType == RF_AIROHA7230) {
471 pDevice->abyBBVGA[0] = 0x1C;
472 pDevice->abyBBVGA[2] = 0x00;
473 pDevice->abyBBVGA[3] = 0x00;
474 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
475 if (byData == 0x20) {
476 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
478 } else if (pDevice->byRFType == RF_UW2452) {
479 pDevice->abyBBVGA[0] = 0x14;
480 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
481 if (byData == 0x18) {
482 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
483 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
486 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
487 bySlot = C_SLOT_LONG;
488 bySIFS = C_SIFS_BG;
489 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
490 byCWMaxMin = 0xA5;
491 } else {// PK_TYPE_11GA & PK_TYPE_11GB
492 if (pSupportRates == NULL) {
493 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
494 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
496 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
497 if (pDevice->byRFType == RF_AIROHA7230) {
498 pDevice->abyBBVGA[0] = 0x1C;
499 pDevice->abyBBVGA[2] = 0x00;
500 pDevice->abyBBVGA[3] = 0x00;
501 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
502 if (byData == 0x20) {
503 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
505 } else if (pDevice->byRFType == RF_UW2452) {
506 pDevice->abyBBVGA[0] = 0x14;
507 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
508 if (byData == 0x18) {
509 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
510 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
513 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
514 bySIFS = C_SIFS_BG;
515 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
516 bySlot = C_SLOT_SHORT;
517 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
518 } else {
519 bySlot = C_SLOT_LONG;
520 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
522 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
523 byCWMaxMin = 0xA4;
524 } else {
525 byCWMaxMin = 0xA5;
527 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
528 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
529 if (pDevice->bProtectMode) {
530 MACvEnableProtectMD(pDevice->PortOffset);
531 } else {
532 MACvDisableProtectMD(pDevice->PortOffset);
535 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
536 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
537 if (pDevice->bBarkerPreambleMd) {
538 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
539 } else {
540 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
545 if (pDevice->byRFType == RF_RFMD2959) {
546 // bcs TX_PE will reserve 3 us
547 // hardware's processing time here is 2 us.
548 bySIFS -= 3;
549 byDIFS -= 3;
550 //{{ RobertYu: 20041202
551 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
552 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
555 if (pDevice->bySIFS != bySIFS) {
556 pDevice->bySIFS = bySIFS;
557 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
559 if (pDevice->byDIFS != byDIFS) {
560 pDevice->byDIFS = byDIFS;
561 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
563 if (pDevice->byEIFS != C_EIFS) {
564 pDevice->byEIFS = C_EIFS;
565 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
567 if (pDevice->bySlot != bySlot) {
568 pDevice->bySlot = bySlot;
569 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
570 if (pDevice->bySlot == C_SLOT_SHORT) {
571 pDevice->bShortSlotTime = true;
572 } else {
573 pDevice->bShortSlotTime = false;
575 BBvSetShortSlotTime(pDevice);
577 if (pDevice->byCWMaxMin != byCWMaxMin) {
578 pDevice->byCWMaxMin = byCWMaxMin;
579 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
581 if (VNTWIFIbIsShortPreamble(wCapInfo)) {
582 pDevice->byPreambleType = pDevice->byShortPreamble;
583 } else {
584 pDevice->byPreambleType = 0;
586 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
587 pDevice->eCurrentPHYType = ePHYType;
588 // set for NDIS OID_802_11SUPPORTED_RATES
589 return true;
593 * Description: Sync. TSF counter to BSS
594 * Get TSF offset and write to HW
596 * Parameters:
597 * In:
598 * pDevice - The adapter to be sync.
599 * byRxRate - data rate of receive beacon
600 * qwBSSTimestamp - Rx BCN's TSF
601 * qwLocalTSF - Local TSF
602 * Out:
603 * none
605 * Return Value: none
608 bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
610 PSDevice pDevice = (PSDevice) pDeviceHandler;
611 QWORD qwTSFOffset;
613 HIDWORD(qwTSFOffset) = 0;
614 LODWORD(qwTSFOffset) = 0;
616 if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
617 (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
618 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
619 // adjust TSF
620 // HW's TSF add TSF Offset reg
621 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
622 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
623 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
625 return true;
629 * Description: Set NIC TSF counter for first Beacon time
630 * Get NEXTTBTT from adjusted TSF and Beacon Interval
632 * Parameters:
633 * In:
634 * pDevice - The adapter to be set.
635 * wBeaconInterval - Beacon Interval
636 * Out:
637 * none
639 * Return Value: true if succeed; otherwise false
642 bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval)
644 PSDevice pDevice = (PSDevice) pDeviceHandler;
645 unsigned int uBeaconInterval = 0;
646 unsigned int uLowNextTBTT = 0;
647 unsigned int uHighRemain = 0;
648 unsigned int uLowRemain = 0;
649 QWORD qwNextTBTT;
651 HIDWORD(qwNextTBTT) = 0;
652 LODWORD(qwNextTBTT) = 0;
653 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
654 uBeaconInterval = wBeaconInterval * 1024;
655 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
656 uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
657 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
658 // high dword (mod) bcn
659 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
660 % uBeaconInterval;
661 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
662 uLowRemain = uBeaconInterval - uLowRemain;
664 // check if carry when add one beacon interval
665 if ((~uLowNextTBTT) < uLowRemain) {
666 HIDWORD(qwNextTBTT)++;
668 LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
670 // set HW beacon interval
671 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
672 pDevice->wBeaconInterval = wBeaconInterval;
673 // Set NextTBTT
674 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
675 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
676 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
678 return true;
682 * Description: Card Stop Hardware Tx
684 * Parameters:
685 * In:
686 * pDeviceHandler - The adapter to be set
687 * ePktType - Packet type to stop
688 * Out:
689 * none
691 * Return Value: true if all data packet complete; otherwise false.
694 bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
696 PSDevice pDevice = (PSDevice) pDeviceHandler;
698 if (ePktType == PKT_TYPE_802_11_ALL) {
699 pDevice->bStopBeacon = true;
700 pDevice->bStopTx0Pkt = true;
701 pDevice->bStopDataPkt = true;
702 } else if (ePktType == PKT_TYPE_802_11_BCN) {
703 pDevice->bStopBeacon = true;
704 } else if (ePktType == PKT_TYPE_802_11_MNG) {
705 pDevice->bStopTx0Pkt = true;
706 } else if (ePktType == PKT_TYPE_802_11_DATA) {
707 pDevice->bStopDataPkt = true;
710 if (pDevice->bStopBeacon == true) {
711 if (pDevice->bIsBeaconBufReadySet == true) {
712 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
713 pDevice->cbBeaconBufReadySetCnt++;
714 return false;
717 pDevice->bIsBeaconBufReadySet = false;
718 pDevice->cbBeaconBufReadySetCnt = 0;
719 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
721 // wait all TD0 complete
722 if (pDevice->bStopTx0Pkt == true) {
723 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
724 return false;
727 // wait all Data TD complete
728 if (pDevice->bStopDataPkt == true) {
729 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
730 return false;
734 return true;
738 * Description: Card Start Hardware Tx
740 * Parameters:
741 * In:
742 * pDeviceHandler - The adapter to be set
743 * ePktType - Packet type to start
744 * Out:
745 * none
747 * Return Value: true if success; false if failed.
750 bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
752 PSDevice pDevice = (PSDevice) pDeviceHandler;
754 if (ePktType == PKT_TYPE_802_11_ALL) {
755 pDevice->bStopBeacon = false;
756 pDevice->bStopTx0Pkt = false;
757 pDevice->bStopDataPkt = false;
758 } else if (ePktType == PKT_TYPE_802_11_BCN) {
759 pDevice->bStopBeacon = false;
760 } else if (ePktType == PKT_TYPE_802_11_MNG) {
761 pDevice->bStopTx0Pkt = false;
762 } else if (ePktType == PKT_TYPE_802_11_DATA) {
763 pDevice->bStopDataPkt = false;
766 if ((pDevice->bStopBeacon == false) &&
767 (pDevice->bBeaconBufReady == true) &&
768 (pDevice->eOPMode == OP_MODE_ADHOC)) {
769 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
772 return true;
776 * Description: Card Set BSSID value
778 * Parameters:
779 * In:
780 * pDeviceHandler - The adapter to be set
781 * pbyBSSID - pointer to BSSID field
782 * bAdhoc - flag to indicate IBSS
783 * Out:
784 * none
786 * Return Value: true if success; false if failed.
789 bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
791 PSDevice pDevice = (PSDevice) pDeviceHandler;
793 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
794 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
795 if (eOPMode == OP_MODE_ADHOC) {
796 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
797 } else {
798 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
800 if (eOPMode == OP_MODE_AP) {
801 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
802 } else {
803 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
805 if (eOPMode == OP_MODE_UNKNOWN) {
806 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
807 pDevice->bBSSIDFilter = false;
808 pDevice->byRxMode &= ~RCR_BSSID;
809 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
810 } else {
811 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
812 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
813 pDevice->bBSSIDFilter = true;
814 pDevice->byRxMode |= RCR_BSSID;
816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode);
818 // Adopt BSS state in Adapter Device Object
819 pDevice->eOPMode = eOPMode;
820 return true;
824 * Description: Card indicate status
826 * Parameters:
827 * In:
828 * pDeviceHandler - The adapter to be set
829 * eStatus - Status
830 * Out:
831 * none
833 * Return Value: true if success; false if failed.
838 * Description: Save Assoc info. contain in assoc. response frame
840 * Parameters:
841 * In:
842 * pDevice - The adapter to be set
843 * wCapabilityInfo - Capability information
844 * wStatus - Status code
845 * wAID - Assoc. ID
846 * uLen - Length of IEs
847 * pbyIEs - pointer to IEs
848 * Out:
849 * none
851 * Return Value: true if succeed; otherwise false
854 bool CARDbSetTxDataRate(
855 void *pDeviceHandler,
856 unsigned short wDataRate
859 PSDevice pDevice = (PSDevice) pDeviceHandler;
861 pDevice->wCurrentRate = wDataRate;
862 return true;
867 * Routine Description:
868 * Consider to power down when no more packets to tx or rx.
870 * Parameters:
871 * In:
872 * pDevice - The adapter to be set
873 * Out:
874 * none
876 * Return Value: true if power down success; otherwise false
879 bool
880 CARDbPowerDown(
881 void *pDeviceHandler
884 PSDevice pDevice = (PSDevice)pDeviceHandler;
885 unsigned int uIdx;
887 // check if already in Doze mode
888 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
889 return true;
891 // Froce PSEN on
892 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
894 // check if all TD are empty,
896 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
897 if (pDevice->iTDUsed[uIdx] != 0)
898 return false;
901 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
902 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
903 return true;
907 * Description: Turn off Radio power
909 * Parameters:
910 * In:
911 * pDevice - The adapter to be turned off
912 * Out:
913 * none
915 * Return Value: true if success; otherwise false
918 bool CARDbRadioPowerOff(void *pDeviceHandler)
920 PSDevice pDevice = (PSDevice)pDeviceHandler;
921 bool bResult = true;
923 if (pDevice->bRadioOff == true)
924 return true;
926 switch (pDevice->byRFType) {
927 case RF_RFMD2959:
928 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
929 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
930 break;
932 case RF_AIROHA:
933 case RF_AL2230S:
934 case RF_AIROHA7230: //RobertYu:20050104
935 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
936 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
937 break;
941 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
943 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
945 pDevice->bRadioOff = true;
946 //2007-0409-03,<Add> by chester
947 printk("chester power off\n");
948 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
949 return bResult;
953 * Description: Turn on Radio power
955 * Parameters:
956 * In:
957 * pDevice - The adapter to be turned on
958 * Out:
959 * none
961 * Return Value: true if success; otherwise false
964 bool CARDbRadioPowerOn(void *pDeviceHandler)
966 PSDevice pDevice = (PSDevice) pDeviceHandler;
967 bool bResult = true;
968 printk("chester power on\n");
969 if (pDevice->bRadioControlOff == true) {
970 if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
971 if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
972 return false; }
974 if (pDevice->bRadioOff == false) {
975 printk("chester pbRadioOff\n");
976 return true; }
978 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
980 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
982 switch (pDevice->byRFType) {
983 case RF_RFMD2959:
984 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
985 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
986 break;
988 case RF_AIROHA:
989 case RF_AL2230S:
990 case RF_AIROHA7230: //RobertYu:20050104
991 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
992 SOFTPWRCTL_SWPE3));
993 break;
997 pDevice->bRadioOff = false;
998 // 2007-0409-03,<Add> by chester
999 printk("chester power on\n");
1000 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
1001 return bResult;
1004 bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID)
1006 PSDevice pDevice = (PSDevice) pDeviceHandler;
1008 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
1009 return true;
1014 * Description:
1015 * Add BSSID in PMKID Candidate list.
1017 * Parameters:
1018 * In:
1019 * hDeviceContext - device structure point
1020 * pbyBSSID - BSSID address for adding
1021 * wRSNCap - BSS's RSN capability
1022 * Out:
1023 * none
1025 * Return Value: none.
1028 bool
1029 CARDbAdd_PMKID_Candidate(
1030 void *pDeviceHandler,
1031 unsigned char *pbyBSSID,
1032 bool bRSNCapExist,
1033 unsigned short wRSNCap
1036 PSDevice pDevice = (PSDevice) pDeviceHandler;
1037 PPMKID_CANDIDATE pCandidateList;
1038 unsigned int ii = 0;
1040 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1042 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1043 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n");
1044 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1047 for (ii = 0; ii < 6; ii++) {
1048 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii));
1050 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
1052 // Update Old Candidate
1053 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1054 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1055 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
1056 if (bRSNCapExist && (wRSNCap & BIT0)) {
1057 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1058 } else {
1059 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1061 return true;
1065 // New Candidate
1066 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1067 if (bRSNCapExist && (wRSNCap & BIT0)) {
1068 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1069 } else {
1070 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1072 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1073 pDevice->gsPMKIDCandidate.NumCandidates++;
1074 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1075 return true;
1078 void *
1079 CARDpGetCurrentAddress(
1080 void *pDeviceHandler
1083 PSDevice pDevice = (PSDevice) pDeviceHandler;
1085 return pDevice->abyCurrentNetAddr;
1090 * Description:
1091 * Start Spectrum Measure defined in 802.11h
1093 * Parameters:
1094 * In:
1095 * hDeviceContext - device structure point
1096 * Out:
1097 * none
1099 * Return Value: none.
1102 bool
1103 CARDbStartMeasure(
1104 void *pDeviceHandler,
1105 void *pvMeasureEIDs,
1106 unsigned int uNumOfMeasureEIDs
1109 PSDevice pDevice = (PSDevice) pDeviceHandler;
1110 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1111 QWORD qwCurrTSF;
1112 QWORD qwStartTSF;
1113 bool bExpired = true;
1114 unsigned short wDuration = 0;
1116 if ((pEID == NULL) ||
1117 (uNumOfMeasureEIDs == 0)) {
1118 return true;
1120 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1121 if (pDevice->bMeasureInProgress == true) {
1122 pDevice->bMeasureInProgress = false;
1123 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1124 MACvSelectPage1(pDevice->PortOffset);
1125 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1126 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1127 // clear measure control
1128 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1129 MACvSelectPage0(pDevice->PortOffset);
1130 set_channel(pDevice, pDevice->byOrgChannel);
1131 MACvSelectPage1(pDevice->PortOffset);
1132 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1133 MACvSelectPage0(pDevice->PortOffset);
1135 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1137 do {
1138 pDevice->pCurrMeasureEID = pEID;
1139 pEID++;
1140 pDevice->uNumOfMeasureEIDs--;
1142 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1143 HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1144 LODWORD(qwStartTSF) = LODWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1145 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1146 wDuration += 1; // 1 TU for channel switching
1148 if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1149 // start immediately by setting start TSF == current TSF + 2 TU
1150 LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1151 HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
1152 if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
1153 HIDWORD(qwStartTSF)++;
1155 bExpired = false;
1156 break;
1157 } else {
1158 // start at setting start TSF - 1TU(for channel switching)
1159 if (LODWORD(qwStartTSF) < 1024) {
1160 HIDWORD(qwStartTSF)--;
1162 LODWORD(qwStartTSF) -= 1024;
1165 if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1166 ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1167 (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1169 bExpired = false;
1170 break;
1172 VNTWIFIbMeasureReport(pDevice->pMgmt,
1173 false,
1174 pDevice->pCurrMeasureEID,
1175 MEASURE_MODE_LATE,
1176 pDevice->byBasicMap,
1177 pDevice->byCCAFraction,
1178 pDevice->abyRPIs
1180 } else {
1181 // hardware do not support measure
1182 VNTWIFIbMeasureReport(pDevice->pMgmt,
1183 false,
1184 pDevice->pCurrMeasureEID,
1185 MEASURE_MODE_INCAPABLE,
1186 pDevice->byBasicMap,
1187 pDevice->byCCAFraction,
1188 pDevice->abyRPIs
1191 } while (pDevice->uNumOfMeasureEIDs != 0);
1193 if (!bExpired) {
1194 MACvSelectPage1(pDevice->PortOffset);
1195 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1196 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1197 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1198 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1199 MACvSelectPage0(pDevice->PortOffset);
1200 } else {
1201 // all measure start time expired we should complete action
1202 VNTWIFIbMeasureReport(pDevice->pMgmt,
1203 true,
1204 NULL,
1206 pDevice->byBasicMap,
1207 pDevice->byCCAFraction,
1208 pDevice->abyRPIs
1211 return true;
1216 * Description:
1217 * Do Channel Switch defined in 802.11h
1219 * Parameters:
1220 * In:
1221 * hDeviceContext - device structure point
1222 * Out:
1223 * none
1225 * Return Value: none.
1228 bool
1229 CARDbChannelSwitch(
1230 void *pDeviceHandler,
1231 unsigned char byMode,
1232 unsigned char byNewChannel,
1233 unsigned char byCount
1236 PSDevice pDevice = (PSDevice) pDeviceHandler;
1237 bool bResult = true;
1239 if (byCount == 0) {
1240 bResult = set_channel(pDevice, byNewChannel);
1241 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1242 MACvSelectPage1(pDevice->PortOffset);
1243 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1244 MACvSelectPage0(pDevice->PortOffset);
1245 return bResult;
1247 pDevice->byChannelSwitchCount = byCount;
1248 pDevice->byNewChannel = byNewChannel;
1249 pDevice->bChannelSwitch = true;
1250 if (byMode == 1) {
1251 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1253 return bResult;
1258 * Description:
1259 * Handle Quiet EID defined in 802.11h
1261 * Parameters:
1262 * In:
1263 * hDeviceContext - device structure point
1264 * Out:
1265 * none
1267 * Return Value: none.
1270 bool
1271 CARDbSetQuiet(
1272 void *pDeviceHandler,
1273 bool bResetQuiet,
1274 unsigned char byQuietCount,
1275 unsigned char byQuietPeriod,
1276 unsigned short wQuietDuration,
1277 unsigned short wQuietOffset
1280 PSDevice pDevice = (PSDevice) pDeviceHandler;
1281 unsigned int ii = 0;
1283 if (bResetQuiet) {
1284 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1285 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1286 pDevice->sQuiet[ii].bEnable = false;
1288 pDevice->uQuietEnqueue = 0;
1289 pDevice->bEnableFirstQuiet = false;
1290 pDevice->bQuietEnable = false;
1291 pDevice->byQuietStartCount = byQuietCount;
1293 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1294 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1295 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1296 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1297 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1298 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1299 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1300 pDevice->uQuietEnqueue++;
1301 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1302 if (pDevice->byQuietStartCount < byQuietCount) {
1303 pDevice->byQuietStartCount = byQuietCount;
1305 } else {
1306 // we can not handle Quiet EID more
1308 return true;
1313 * Description:
1314 * Do Quiet, It will be called by either ISR(after start)
1315 * or VNTWIFI(before start) so we do not need a SPINLOCK
1317 * Parameters:
1318 * In:
1319 * hDeviceContext - device structure point
1320 * Out:
1321 * none
1323 * Return Value: none.
1326 bool
1327 CARDbStartQuiet(
1328 void *pDeviceHandler
1331 PSDevice pDevice = (PSDevice) pDeviceHandler;
1332 unsigned int ii = 0;
1333 unsigned long dwStartTime = 0xFFFFFFFF;
1334 unsigned int uCurrentQuietIndex = 0;
1335 unsigned long dwNextTime = 0;
1336 unsigned long dwGap = 0;
1337 unsigned long dwDuration = 0;
1339 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1340 if ((pDevice->sQuiet[ii].bEnable == true) &&
1341 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1342 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1343 uCurrentQuietIndex = ii;
1346 if (dwStartTime == 0xFFFFFFFF) {
1347 // no more quiet
1348 pDevice->bQuietEnable = false;
1349 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1350 } else {
1351 if (pDevice->bQuietEnable == false) {
1352 // first quiet
1353 pDevice->byQuietStartCount--;
1354 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1355 dwNextTime %= pDevice->wBeaconInterval;
1356 MACvSelectPage1(pDevice->PortOffset);
1357 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1358 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1359 if (pDevice->byQuietStartCount == 0) {
1360 pDevice->bEnableFirstQuiet = false;
1361 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1362 } else {
1363 pDevice->bEnableFirstQuiet = true;
1365 MACvSelectPage0(pDevice->PortOffset);
1366 } else {
1367 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1368 // overlap with previous Quiet
1369 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1370 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1371 // return false to indicate next quiet expired, should call this function again
1372 return false;
1374 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1375 dwGap = 0;
1376 } else {
1377 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1378 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1380 // set GAP and Next duration
1381 MACvSelectPage1(pDevice->PortOffset);
1382 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1383 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1384 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1385 MACvSelectPage0(pDevice->PortOffset);
1387 pDevice->bQuietEnable = true;
1388 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1389 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1390 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1391 // not period disable current quiet element
1392 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1393 } else {
1394 // set next period start time
1395 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1396 dwNextTime *= pDevice->wBeaconInterval;
1397 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1399 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1400 // decreament all time to avoid wrap around
1401 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1402 if (pDevice->sQuiet[ii].bEnable == true) {
1403 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1406 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1409 return true;
1414 * Description:
1415 * Set Local Power Constraint
1417 * Parameters:
1418 * In:
1419 * hDeviceContext - device structure point
1420 * Out:
1421 * none
1423 * Return Value: none.
1426 void
1427 CARDvSetPowerConstraint(
1428 void *pDeviceHandler,
1429 unsigned char byChannel,
1430 char byPower
1433 PSDevice pDevice = (PSDevice) pDeviceHandler;
1435 if (byChannel > CB_MAX_CHANNEL_24G) {
1436 if (pDevice->bCountryInfo5G == true) {
1437 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1439 } else {
1440 if (pDevice->bCountryInfo24G == true) {
1441 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1448 * Description:
1449 * Set Local Power Constraint
1451 * Parameters:
1452 * In:
1453 * hDeviceContext - device structure point
1454 * Out:
1455 * none
1457 * Return Value: none.
1460 void
1461 CARDvGetPowerCapability(
1462 void *pDeviceHandler,
1463 unsigned char *pbyMinPower,
1464 unsigned char *pbyMaxPower
1467 PSDevice pDevice = (PSDevice) pDeviceHandler;
1468 unsigned char byDec = 0;
1470 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1471 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1472 if (pDevice->byRFType == RF_UW2452) {
1473 byDec *= 3;
1474 byDec >>= 1;
1475 } else {
1476 byDec <<= 1;
1478 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1483 * Description:
1484 * Get Current Tx Power
1486 * Parameters:
1487 * In:
1488 * hDeviceContext - device structure point
1489 * Out:
1490 * none
1492 * Return Value: none.
1495 char
1496 CARDbyGetTransmitPower(
1497 void *pDeviceHandler
1500 PSDevice pDevice = (PSDevice) pDeviceHandler;
1502 return pDevice->byCurPwrdBm;
1505 //xxx
1506 void
1507 CARDvSafeResetTx(
1508 void *pDeviceHandler
1511 PSDevice pDevice = (PSDevice) pDeviceHandler;
1512 unsigned int uu;
1513 PSTxDesc pCurrTD;
1515 // initialize TD index
1516 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1517 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1519 for (uu = 0; uu < TYPE_MAXTD; uu++)
1520 pDevice->iTDUsed[uu] = 0;
1522 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1523 pCurrTD = &(pDevice->apTD0Rings[uu]);
1524 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1525 // init all Tx Packet pointer to NULL
1527 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1528 pCurrTD = &(pDevice->apTD1Rings[uu]);
1529 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1530 // init all Tx Packet pointer to NULL
1533 // set MAC TD pointer
1534 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1535 (pDevice->td0_pool_dma));
1537 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1538 (pDevice->td1_pool_dma));
1540 // set MAC Beacon TX pointer
1541 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1542 (pDevice->tx_beacon_dma));
1547 * Description:
1548 * Reset Rx
1550 * Parameters:
1551 * In:
1552 * pDevice - Pointer to the adapter
1553 * Out:
1554 * none
1556 * Return Value: none
1559 void
1560 CARDvSafeResetRx(
1561 void *pDeviceHandler
1564 PSDevice pDevice = (PSDevice) pDeviceHandler;
1565 unsigned int uu;
1566 PSRxDesc pDesc;
1568 // initialize RD index
1569 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1570 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1572 // init state, all RD is chip's
1573 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1574 pDesc = &(pDevice->aRD0Ring[uu]);
1575 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1576 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1577 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1580 // init state, all RD is chip's
1581 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1582 pDesc = &(pDevice->aRD1Ring[uu]);
1583 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1584 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1585 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1588 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1589 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1591 // set perPkt mode
1592 MACvRx0PerPktMode(pDevice->PortOffset);
1593 MACvRx1PerPktMode(pDevice->PortOffset);
1594 // set MAC RD pointer
1595 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1596 pDevice->rd0_pool_dma);
1598 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1599 pDevice->rd1_pool_dma);
1603 * Description: Get response Control frame rate in CCK mode
1605 * Parameters:
1606 * In:
1607 * pDevice - The adapter to be set
1608 * wRateIdx - Receiving data rate
1609 * Out:
1610 * none
1612 * Return Value: response Control frame rate
1615 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
1617 PSDevice pDevice = (PSDevice) pDeviceHandler;
1618 unsigned int ui = (unsigned int) wRateIdx;
1620 while (ui > RATE_1M) {
1621 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1622 return (unsigned short)ui;
1624 ui--;
1626 return (unsigned short)RATE_1M;
1630 * Description: Get response Control frame rate in OFDM mode
1632 * Parameters:
1633 * In:
1634 * pDevice - The adapter to be set
1635 * wRateIdx - Receiving data rate
1636 * Out:
1637 * none
1639 * Return Value: response Control frame rate
1642 unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx)
1644 PSDevice pDevice = (PSDevice) pDeviceHandler;
1645 unsigned int ui = (unsigned int) wRateIdx;
1647 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate);
1649 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1650 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1651 if (wRateIdx > RATE_24M)
1652 wRateIdx = RATE_24M;
1653 return wRateIdx;
1655 while (ui > RATE_11M) {
1656 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui);
1658 return (unsigned short)ui;
1660 ui--;
1662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n");
1663 return (unsigned short)RATE_24M;
1667 * Description: Set RSPINF
1669 * Parameters:
1670 * In:
1671 * pDevice - The adapter to be set
1672 * Out:
1673 * none
1675 * Return Value: None.
1678 void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
1680 PSDevice pDevice = (PSDevice) pDeviceHandler;
1681 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1682 unsigned short wLen = 0x0000;
1683 unsigned char byTxRate, byRsvTime; //For OFDM
1685 //Set to Page1
1686 MACvSelectPage1(pDevice->PortOffset);
1688 //RSPINF_b_1
1689 BBvCalculateParameter(pDevice,
1691 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1692 PK_TYPE_11B,
1693 &wLen,
1694 &byServ,
1695 &bySignal
1698 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1699 ///RSPINF_b_2
1700 BBvCalculateParameter(pDevice,
1702 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1703 PK_TYPE_11B,
1704 &wLen,
1705 &byServ,
1706 &bySignal
1709 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1710 //RSPINF_b_5
1711 BBvCalculateParameter(pDevice,
1713 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1714 PK_TYPE_11B,
1715 &wLen,
1716 &byServ,
1717 &bySignal
1720 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1721 //RSPINF_b_11
1722 BBvCalculateParameter(pDevice,
1724 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1725 PK_TYPE_11B,
1726 &wLen,
1727 &byServ,
1728 &bySignal
1731 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1732 //RSPINF_a_6
1733 s_vCalculateOFDMRParameter(RATE_6M,
1734 ePHYType,
1735 &byTxRate,
1736 &byRsvTime);
1737 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1738 //RSPINF_a_9
1739 s_vCalculateOFDMRParameter(RATE_9M,
1740 ePHYType,
1741 &byTxRate,
1742 &byRsvTime);
1743 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1744 //RSPINF_a_12
1745 s_vCalculateOFDMRParameter(RATE_12M,
1746 ePHYType,
1747 &byTxRate,
1748 &byRsvTime);
1749 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1750 //RSPINF_a_18
1751 s_vCalculateOFDMRParameter(RATE_18M,
1752 ePHYType,
1753 &byTxRate,
1754 &byRsvTime);
1755 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1756 //RSPINF_a_24
1757 s_vCalculateOFDMRParameter(RATE_24M,
1758 ePHYType,
1759 &byTxRate,
1760 &byRsvTime);
1761 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1762 //RSPINF_a_36
1763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1764 ePHYType,
1765 &byTxRate,
1766 &byRsvTime);
1767 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1768 //RSPINF_a_48
1769 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1770 ePHYType,
1771 &byTxRate,
1772 &byRsvTime);
1773 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1774 //RSPINF_a_54
1775 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1776 ePHYType,
1777 &byTxRate,
1778 &byRsvTime);
1779 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
1781 //RSPINF_a_72
1782 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1783 ePHYType,
1784 &byTxRate,
1785 &byRsvTime);
1786 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1787 //Set to Page0
1788 MACvSelectPage0(pDevice->PortOffset);
1792 * Description: Update IFS
1794 * Parameters:
1795 * In:
1796 * pDevice - The adapter to be set
1797 * Out:
1798 * none
1800 * Return Value: None.
1803 void vUpdateIFS(void *pDeviceHandler)
1805 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1806 PSDevice pDevice = (PSDevice) pDeviceHandler;
1808 unsigned char byMaxMin = 0;
1809 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1810 pDevice->uSlot = C_SLOT_SHORT;
1811 pDevice->uSIFS = C_SIFS_A;
1812 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1813 pDevice->uCwMin = C_CWMIN_A;
1814 byMaxMin = 4;
1815 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
1816 pDevice->uSlot = C_SLOT_LONG;
1817 pDevice->uSIFS = C_SIFS_BG;
1818 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1819 pDevice->uCwMin = C_CWMIN_B;
1820 byMaxMin = 5;
1821 } else { // PK_TYPE_11GA & PK_TYPE_11GB
1822 pDevice->uSIFS = C_SIFS_BG;
1823 if (pDevice->bShortSlotTime) {
1824 pDevice->uSlot = C_SLOT_SHORT;
1825 } else {
1826 pDevice->uSlot = C_SLOT_LONG;
1828 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1829 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1830 pDevice->uCwMin = C_CWMIN_A;
1831 byMaxMin = 4;
1832 } else {
1833 pDevice->uCwMin = C_CWMIN_B;
1834 byMaxMin = 5;
1838 pDevice->uCwMax = C_CWMAX;
1839 pDevice->uEIFS = C_EIFS;
1840 if (pDevice->byRFType == RF_RFMD2959) {
1841 // bcs TX_PE will reserve 3 us
1842 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1843 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1844 } else {
1845 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1846 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1848 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1849 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1850 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1851 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1854 void CARDvUpdateBasicTopRate(void *pDeviceHandler)
1856 PSDevice pDevice = (PSDevice) pDeviceHandler;
1857 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1858 unsigned char ii;
1860 //Determines the highest basic rate.
1861 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1862 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1863 byTopOFDM = ii;
1864 break;
1867 pDevice->byTopOFDMBasicRate = byTopOFDM;
1869 for (ii = RATE_11M;; ii--) {
1870 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1871 byTopCCK = ii;
1872 break;
1874 if (ii == RATE_1M)
1875 break;
1877 pDevice->byTopCCKBasicRate = byTopCCK;
1881 * Description: Set NIC Tx Basic Rate
1883 * Parameters:
1884 * In:
1885 * pDevice - The adapter to be set
1886 * wBasicRate - Basic Rate to be set
1887 * Out:
1888 * none
1890 * Return Value: true if succeeded; false if failed.
1893 bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx)
1895 PSDevice pDevice = (PSDevice) pDeviceHandler;
1896 unsigned short wRate = (unsigned short)(1<<wRateIdx);
1898 pDevice->wBasicRate |= wRate;
1900 //Determines the highest basic rate.
1901 CARDvUpdateBasicTopRate((void *)pDevice);
1903 return true;
1906 bool CARDbIsOFDMinBasicRate(void *pDeviceHandler)
1908 PSDevice pDevice = (PSDevice)pDeviceHandler;
1909 int ii;
1911 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1912 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1913 return true;
1915 return false;
1918 unsigned char CARDbyGetPktType(void *pDeviceHandler)
1920 PSDevice pDevice = (PSDevice) pDeviceHandler;
1922 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
1923 return (unsigned char)pDevice->byBBType;
1924 } else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
1925 return PK_TYPE_11GA;
1926 } else {
1927 return PK_TYPE_11GB;
1932 * Description: Set NIC Loopback mode
1934 * Parameters:
1935 * In:
1936 * pDevice - The adapter to be set
1937 * wLoopbackMode - Loopback mode to be set
1938 * Out:
1939 * none
1941 * Return Value: none
1944 void CARDvSetLoopbackMode(unsigned long dwIoBase, unsigned short wLoopbackMode)
1946 switch (wLoopbackMode) {
1947 case CARD_LB_NONE:
1948 case CARD_LB_MAC:
1949 case CARD_LB_PHY:
1950 break;
1951 default:
1952 ASSERT(false);
1953 break;
1955 // set MAC loopback
1956 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1957 // set Baseband loopback
1961 * Description: Software Reset NIC
1963 * Parameters:
1964 * In:
1965 * pDevice - The adapter to be reset
1966 * Out:
1967 * none
1969 * Return Value: none
1972 bool CARDbSoftwareReset(void *pDeviceHandler)
1974 PSDevice pDevice = (PSDevice) pDeviceHandler;
1976 // reset MAC
1977 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1978 return false;
1980 return true;
1984 * Description: Calculate TSF offset of two TSF input
1985 * Get TSF Offset from RxBCN's TSF and local TSF
1987 * Parameters:
1988 * In:
1989 * pDevice - The adapter to be sync.
1990 * qwTSF1 - Rx BCN's TSF
1991 * qwTSF2 - Local TSF
1992 * Out:
1993 * none
1995 * Return Value: TSF Offset value
1998 QWORD CARDqGetTSFOffset(unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
2000 QWORD qwTSFOffset;
2001 unsigned short wRxBcnTSFOffst = 0;
2003 HIDWORD(qwTSFOffset) = 0;
2004 LODWORD(qwTSFOffset) = 0;
2005 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
2006 (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
2007 if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
2008 (qwTSF2).u.dwHighDword++;
2010 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
2011 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
2012 // if borrow needed
2013 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1;
2014 } else {
2015 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
2017 return qwTSFOffset;
2021 * Description: Read NIC TSF counter
2022 * Get local TSF counter
2024 * Parameters:
2025 * In:
2026 * pDevice - The adapter to be read
2027 * Out:
2028 * qwCurrTSF - Current TSF counter
2030 * Return Value: true if success; otherwise false
2033 bool CARDbGetCurrentTSF(unsigned long dwIoBase, PQWORD pqwCurrTSF)
2035 unsigned short ww;
2036 unsigned char byData;
2038 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
2039 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
2040 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
2041 if (!(byData & TFTCTL_TSFCNTRRD))
2042 break;
2044 if (ww == W_MAX_TIMEOUT)
2045 return false;
2046 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
2047 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
2049 return true;
2053 * Description: Read NIC TSF counter
2054 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2056 * Parameters:
2057 * In:
2058 * qwTSF - Current TSF counter
2059 * wbeaconInterval - Beacon Interval
2060 * Out:
2061 * qwCurrTSF - Current TSF counter
2063 * Return Value: TSF value of next Beacon
2066 QWORD CARDqGetNextTBTT(QWORD qwTSF, unsigned short wBeaconInterval)
2068 unsigned int uLowNextTBTT;
2069 unsigned int uHighRemain, uLowRemain;
2070 unsigned int uBeaconInterval;
2072 uBeaconInterval = wBeaconInterval * 1024;
2073 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
2074 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
2075 // low dword (mod) bcn
2076 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
2077 // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
2078 // % uBeaconInterval;
2079 // high dword (mod) bcn
2080 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
2081 % uBeaconInterval;
2082 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2083 uLowRemain = uBeaconInterval - uLowRemain;
2085 // check if carry when add one beacon interval
2086 if ((~uLowNextTBTT) < uLowRemain)
2087 HIDWORD(qwTSF)++;
2089 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
2091 return qwTSF;
2095 * Description: Set NIC TSF counter for first Beacon time
2096 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2098 * Parameters:
2099 * In:
2100 * dwIoBase - IO Base
2101 * wBeaconInterval - Beacon Interval
2102 * Out:
2103 * none
2105 * Return Value: none
2108 void CARDvSetFirstNextTBTT(unsigned long dwIoBase, unsigned short wBeaconInterval)
2110 QWORD qwNextTBTT;
2112 HIDWORD(qwNextTBTT) = 0;
2113 LODWORD(qwNextTBTT) = 0;
2114 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
2115 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2116 // Set NextTBTT
2117 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
2118 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
2119 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2120 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
2121 return;
2125 * Description: Sync NIC TSF counter for Beacon time
2126 * Get NEXTTBTT and write to HW
2128 * Parameters:
2129 * In:
2130 * pDevice - The adapter to be set
2131 * qwTSF - Current TSF counter
2132 * wBeaconInterval - Beacon Interval
2133 * Out:
2134 * none
2136 * Return Value: none
2139 void CARDvUpdateNextTBTT(unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
2141 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2142 // Set NextTBTT
2143 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
2144 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
2145 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8xh:%8xh] \n",
2147 (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
2149 return;