Btrfs: device_list_add() should not update list when mounted
[linux/fpc-iii.git] / drivers / staging / vt6655 / card.c
blob05bf48a24f45a6bcae2bb677548e037bf936698f
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 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
28 * CARDvSetLoopbackMode - Set Loopback mode
29 * CARDbSoftwareReset - Sortware reset NIC
30 * CARDqGetTSFOffset - Calculate TSFOffset
31 * CARDbGetCurrentTSF - Read Current NIC TSF counter
32 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
33 * CARDvSetFirstNextTBTT - Set NIC Beacon time
34 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
35 * CARDbRadioPowerOff - Turn Off NIC Radio Power
36 * CARDbRadioPowerOn - Turn On NIC Radio Power
37 * CARDbSetWEPMode - Set NIC Wep mode
38 * CARDbSetTxPower - Set NIC tx power
40 * Revision History:
41 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
42 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
43 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
47 #include "tmacro.h"
48 #include "card.h"
49 #include "baseband.h"
50 #include "mac.h"
51 #include "desc.h"
52 #include "rf.h"
53 #include "vntwifi.h"
54 #include "power.h"
55 #include "key.h"
56 #include "rc4.h"
57 #include "country.h"
58 #include "channel.h"
60 /*--------------------- Static Definitions -------------------------*/
62 static int msglevel = MSG_LEVEL_INFO;
64 #define C_SIFS_A 16 // micro sec.
65 #define C_SIFS_BG 10
67 #define C_EIFS 80 // micro sec.
69 #define C_SLOT_SHORT 9 // micro sec.
70 #define C_SLOT_LONG 20
72 #define C_CWMIN_A 15 // slot time
73 #define C_CWMIN_B 31
75 #define C_CWMAX 1023 // slot time
77 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
79 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
80 static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
81 //6M, 9M, 12M, 48M
82 static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
83 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
84 static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
85 //1M, 2M, 5M, 11M,
86 static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
88 /*--------------------- Static Variables --------------------------*/
90 const unsigned short cwRXBCNTSFOff[MAX_RATE] =
91 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
93 /*--------------------- Static Functions --------------------------*/
95 static
96 void
97 s_vCalculateOFDMRParameter(
98 unsigned char byRate,
99 CARD_PHY_TYPE ePHYType,
100 unsigned char *pbyTxRate,
101 unsigned char *pbyRsvTime
104 /*--------------------- Export Functions --------------------------*/
107 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
109 * Parameters:
110 * In:
111 * wRate - Tx Rate
112 * byPktType - Tx Packet type
113 * Out:
114 * pbyTxRate - pointer to RSPINF TxRate field
115 * pbyRsvTime - pointer to RSPINF RsvTime field
117 * Return Value: none
120 static
121 void
122 s_vCalculateOFDMRParameter(
123 unsigned char byRate,
124 CARD_PHY_TYPE ePHYType,
125 unsigned char *pbyTxRate,
126 unsigned char *pbyRsvTime
129 switch (byRate) {
130 case RATE_6M:
131 if (ePHYType == PHY_TYPE_11A) {//5GHZ
132 *pbyTxRate = 0x9B;
133 *pbyRsvTime = 44;
134 } else {
135 *pbyTxRate = 0x8B;
136 *pbyRsvTime = 50;
138 break;
140 case RATE_9M:
141 if (ePHYType == PHY_TYPE_11A) {//5GHZ
142 *pbyTxRate = 0x9F;
143 *pbyRsvTime = 36;
144 } else {
145 *pbyTxRate = 0x8F;
146 *pbyRsvTime = 42;
148 break;
150 case RATE_12M:
151 if (ePHYType == PHY_TYPE_11A) {//5GHZ
152 *pbyTxRate = 0x9A;
153 *pbyRsvTime = 32;
154 } else {
155 *pbyTxRate = 0x8A;
156 *pbyRsvTime = 38;
158 break;
160 case RATE_18M:
161 if (ePHYType == PHY_TYPE_11A) {//5GHZ
162 *pbyTxRate = 0x9E;
163 *pbyRsvTime = 28;
164 } else {
165 *pbyTxRate = 0x8E;
166 *pbyRsvTime = 34;
168 break;
170 case RATE_36M:
171 if (ePHYType == PHY_TYPE_11A) {//5GHZ
172 *pbyTxRate = 0x9D;
173 *pbyRsvTime = 24;
174 } else {
175 *pbyTxRate = 0x8D;
176 *pbyRsvTime = 30;
178 break;
180 case RATE_48M:
181 if (ePHYType == PHY_TYPE_11A) {//5GHZ
182 *pbyTxRate = 0x98;
183 *pbyRsvTime = 24;
184 } else {
185 *pbyTxRate = 0x88;
186 *pbyRsvTime = 30;
188 break;
190 case RATE_54M:
191 if (ePHYType == PHY_TYPE_11A) {//5GHZ
192 *pbyTxRate = 0x9C;
193 *pbyRsvTime = 24;
194 } else {
195 *pbyTxRate = 0x8C;
196 *pbyRsvTime = 30;
198 break;
200 case RATE_24M:
201 default:
202 if (ePHYType == PHY_TYPE_11A) {//5GHZ
203 *pbyTxRate = 0x99;
204 *pbyRsvTime = 28;
205 } else {
206 *pbyTxRate = 0x89;
207 *pbyRsvTime = 34;
209 break;
214 * Description: Set RSPINF
216 * Parameters:
217 * In:
218 * pDevice - The adapter to be set
219 * Out:
220 * none
222 * Return Value: None.
225 static
226 void
227 s_vSetRSPINF(PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
229 unsigned char byServ = 0, bySignal = 0; // For CCK
230 unsigned short wLen = 0;
231 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
233 //Set to Page1
234 MACvSelectPage1(pDevice->PortOffset);
236 //RSPINF_b_1
237 BBvCalculateParameter(pDevice,
239 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
240 PK_TYPE_11B,
241 &wLen,
242 &byServ,
243 &bySignal
246 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
247 ///RSPINF_b_2
248 BBvCalculateParameter(pDevice,
250 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
251 PK_TYPE_11B,
252 &wLen,
253 &byServ,
254 &bySignal
257 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
258 //RSPINF_b_5
259 BBvCalculateParameter(pDevice,
261 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
262 PK_TYPE_11B,
263 &wLen,
264 &byServ,
265 &bySignal
268 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
269 //RSPINF_b_11
270 BBvCalculateParameter(pDevice,
272 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
273 PK_TYPE_11B,
274 &wLen,
275 &byServ,
276 &bySignal
279 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
280 //RSPINF_a_6
281 s_vCalculateOFDMRParameter(RATE_6M,
282 ePHYType,
283 &byTxRate,
284 &byRsvTime);
285 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
286 //RSPINF_a_9
287 s_vCalculateOFDMRParameter(RATE_9M,
288 ePHYType,
289 &byTxRate,
290 &byRsvTime);
291 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
292 //RSPINF_a_12
293 s_vCalculateOFDMRParameter(RATE_12M,
294 ePHYType,
295 &byTxRate,
296 &byRsvTime);
297 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
298 //RSPINF_a_18
299 s_vCalculateOFDMRParameter(RATE_18M,
300 ePHYType,
301 &byTxRate,
302 &byRsvTime);
303 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
304 //RSPINF_a_24
305 s_vCalculateOFDMRParameter(RATE_24M,
306 ePHYType,
307 &byTxRate,
308 &byRsvTime);
309 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
310 //RSPINF_a_36
311 s_vCalculateOFDMRParameter(
312 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
313 ePHYType,
314 &byTxRate,
315 &byRsvTime);
316 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
317 //RSPINF_a_48
318 s_vCalculateOFDMRParameter(
319 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
320 ePHYType,
321 &byTxRate,
322 &byRsvTime);
323 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
324 //RSPINF_a_54
325 s_vCalculateOFDMRParameter(
326 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
327 ePHYType,
328 &byTxRate,
329 &byRsvTime);
330 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
331 //RSPINF_a_72
332 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
333 //Set to Page0
334 MACvSelectPage0(pDevice->PortOffset);
337 /*--------------------- Export Functions --------------------------*/
340 * Description: Get Card short preamble option value
342 * Parameters:
343 * In:
344 * pDevice - The adapter to be set
345 * Out:
346 * none
348 * Return Value: true if short preamble; otherwise false
351 bool CARDbIsShortPreamble(void *pDeviceHandler)
353 PSDevice pDevice = (PSDevice) pDeviceHandler;
354 if (pDevice->byPreambleType == 0)
355 return false;
357 return true;
361 * Description: Get Card short slot time option value
363 * Parameters:
364 * In:
365 * pDevice - The adapter to be set
366 * Out:
367 * none
369 * Return Value: true if short slot time; otherwise false
372 bool CARDbIsShorSlotTime(void *pDeviceHandler)
374 PSDevice pDevice = (PSDevice) pDeviceHandler;
375 return pDevice->bShortSlotTime;
379 * Description: Update IFS
381 * Parameters:
382 * In:
383 * pDevice - The adapter to be set
384 * Out:
385 * none
387 * Return Value: None.
390 bool CARDbSetPhyParameter(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
392 PSDevice pDevice = (PSDevice) pDeviceHandler;
393 unsigned char byCWMaxMin = 0;
394 unsigned char bySlot = 0;
395 unsigned char bySIFS = 0;
396 unsigned char byDIFS = 0;
397 unsigned char byData;
398 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
399 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
401 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
402 if (ePHYType == PHY_TYPE_11A) {
403 if (pSupportRates == NULL)
404 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
406 if (pDevice->byRFType == RF_AIROHA7230) {
407 // AL7230 use single PAPE and connect to PAPE_2.4G
408 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
409 pDevice->abyBBVGA[0] = 0x20;
410 pDevice->abyBBVGA[2] = 0x10;
411 pDevice->abyBBVGA[3] = 0x10;
412 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
413 if (byData == 0x1C)
414 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
416 } else if (pDevice->byRFType == RF_UW2452) {
417 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
418 pDevice->abyBBVGA[0] = 0x18;
419 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
420 if (byData == 0x14) {
421 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
422 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
424 } else {
425 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
427 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
428 bySlot = C_SLOT_SHORT;
429 bySIFS = C_SIFS_A;
430 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
431 byCWMaxMin = 0xA4;
432 } else if (ePHYType == PHY_TYPE_11B) {
433 if (pSupportRates == NULL)
434 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
436 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
437 if (pDevice->byRFType == RF_AIROHA7230) {
438 pDevice->abyBBVGA[0] = 0x1C;
439 pDevice->abyBBVGA[2] = 0x00;
440 pDevice->abyBBVGA[3] = 0x00;
441 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
442 if (byData == 0x20)
443 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
445 } else if (pDevice->byRFType == RF_UW2452) {
446 pDevice->abyBBVGA[0] = 0x14;
447 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
448 if (byData == 0x18) {
449 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
450 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
453 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
454 bySlot = C_SLOT_LONG;
455 bySIFS = C_SIFS_BG;
456 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
457 byCWMaxMin = 0xA5;
458 } else {// PK_TYPE_11GA & PK_TYPE_11GB
459 if (pSupportRates == NULL) {
460 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
461 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
463 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
464 if (pDevice->byRFType == RF_AIROHA7230) {
465 pDevice->abyBBVGA[0] = 0x1C;
466 pDevice->abyBBVGA[2] = 0x00;
467 pDevice->abyBBVGA[3] = 0x00;
468 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
469 if (byData == 0x20)
470 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
472 } else if (pDevice->byRFType == RF_UW2452) {
473 pDevice->abyBBVGA[0] = 0x14;
474 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
475 if (byData == 0x18) {
476 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
477 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
480 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
481 bySIFS = C_SIFS_BG;
482 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
483 bySlot = C_SLOT_SHORT;
484 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
485 } else {
486 bySlot = C_SLOT_LONG;
487 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
489 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M)
490 byCWMaxMin = 0xA4;
491 else
492 byCWMaxMin = 0xA5;
494 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
495 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
496 if (pDevice->bProtectMode)
497 MACvEnableProtectMD(pDevice->PortOffset);
498 else
499 MACvDisableProtectMD(pDevice->PortOffset);
502 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
503 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
504 if (pDevice->bBarkerPreambleMd)
505 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
506 else
507 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
511 if (pDevice->byRFType == RF_RFMD2959) {
512 // bcs TX_PE will reserve 3 us
513 // hardware's processing time here is 2 us.
514 bySIFS -= 3;
515 byDIFS -= 3;
516 //{{ RobertYu: 20041202
517 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
518 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
521 if (pDevice->bySIFS != bySIFS) {
522 pDevice->bySIFS = bySIFS;
523 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
525 if (pDevice->byDIFS != byDIFS) {
526 pDevice->byDIFS = byDIFS;
527 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
529 if (pDevice->byEIFS != C_EIFS) {
530 pDevice->byEIFS = C_EIFS;
531 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
533 if (pDevice->bySlot != bySlot) {
534 pDevice->bySlot = bySlot;
535 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
536 if (pDevice->bySlot == C_SLOT_SHORT)
537 pDevice->bShortSlotTime = true;
538 else
539 pDevice->bShortSlotTime = false;
541 BBvSetShortSlotTime(pDevice);
543 if (pDevice->byCWMaxMin != byCWMaxMin) {
544 pDevice->byCWMaxMin = byCWMaxMin;
545 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
547 if (VNTWIFIbIsShortPreamble(wCapInfo))
548 pDevice->byPreambleType = pDevice->byShortPreamble;
549 else
550 pDevice->byPreambleType = 0;
552 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
553 pDevice->eCurrentPHYType = ePHYType;
554 // set for NDIS OID_802_11SUPPORTED_RATES
555 return true;
559 * Description: Sync. TSF counter to BSS
560 * Get TSF offset and write to HW
562 * Parameters:
563 * In:
564 * pDevice - The adapter to be sync.
565 * byRxRate - data rate of receive beacon
566 * qwBSSTimestamp - Rx BCN's TSF
567 * qwLocalTSF - Local TSF
568 * Out:
569 * none
571 * Return Value: none
574 bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
576 PSDevice pDevice = (PSDevice) pDeviceHandler;
577 QWORD qwTSFOffset;
579 HIDWORD(qwTSFOffset) = 0;
580 LODWORD(qwTSFOffset) = 0;
582 if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
583 (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
584 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
585 // adjust TSF
586 // HW's TSF add TSF Offset reg
587 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
588 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
589 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
591 return true;
595 * Description: Set NIC TSF counter for first Beacon time
596 * Get NEXTTBTT from adjusted TSF and Beacon Interval
598 * Parameters:
599 * In:
600 * pDevice - The adapter to be set.
601 * wBeaconInterval - Beacon Interval
602 * Out:
603 * none
605 * Return Value: true if succeed; otherwise false
608 bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval)
610 PSDevice pDevice = (PSDevice) pDeviceHandler;
611 unsigned int uBeaconInterval = 0;
612 unsigned int uLowNextTBTT = 0;
613 unsigned int uHighRemain = 0;
614 unsigned int uLowRemain = 0;
615 QWORD qwNextTBTT;
617 HIDWORD(qwNextTBTT) = 0;
618 LODWORD(qwNextTBTT) = 0;
619 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
620 uBeaconInterval = wBeaconInterval * 1024;
621 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
622 uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
623 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
624 // high dword (mod) bcn
625 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
626 % uBeaconInterval;
627 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
628 uLowRemain = uBeaconInterval - uLowRemain;
630 // check if carry when add one beacon interval
631 if ((~uLowNextTBTT) < uLowRemain)
632 HIDWORD(qwNextTBTT)++;
634 LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
636 // set HW beacon interval
637 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
638 pDevice->wBeaconInterval = wBeaconInterval;
639 // Set NextTBTT
640 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
641 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
642 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
644 return true;
648 * Description: Card Stop Hardware Tx
650 * Parameters:
651 * In:
652 * pDeviceHandler - The adapter to be set
653 * ePktType - Packet type to stop
654 * Out:
655 * none
657 * Return Value: true if all data packet complete; otherwise false.
660 bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
662 PSDevice pDevice = (PSDevice) pDeviceHandler;
664 if (ePktType == PKT_TYPE_802_11_ALL) {
665 pDevice->bStopBeacon = true;
666 pDevice->bStopTx0Pkt = true;
667 pDevice->bStopDataPkt = true;
668 } else if (ePktType == PKT_TYPE_802_11_BCN) {
669 pDevice->bStopBeacon = true;
670 } else if (ePktType == PKT_TYPE_802_11_MNG) {
671 pDevice->bStopTx0Pkt = true;
672 } else if (ePktType == PKT_TYPE_802_11_DATA) {
673 pDevice->bStopDataPkt = true;
676 if (pDevice->bStopBeacon == true) {
677 if (pDevice->bIsBeaconBufReadySet == true) {
678 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
679 pDevice->cbBeaconBufReadySetCnt++;
680 return false;
683 pDevice->bIsBeaconBufReadySet = false;
684 pDevice->cbBeaconBufReadySetCnt = 0;
685 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
687 // wait all TD0 complete
688 if (pDevice->bStopTx0Pkt == true) {
689 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
690 return false;
692 // wait all Data TD complete
693 if (pDevice->bStopDataPkt == true) {
694 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
695 return false;
698 return true;
702 * Description: Card Start Hardware Tx
704 * Parameters:
705 * In:
706 * pDeviceHandler - The adapter to be set
707 * ePktType - Packet type to start
708 * Out:
709 * none
711 * Return Value: true if success; false if failed.
714 bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
716 PSDevice pDevice = (PSDevice) pDeviceHandler;
718 if (ePktType == PKT_TYPE_802_11_ALL) {
719 pDevice->bStopBeacon = false;
720 pDevice->bStopTx0Pkt = false;
721 pDevice->bStopDataPkt = false;
722 } else if (ePktType == PKT_TYPE_802_11_BCN) {
723 pDevice->bStopBeacon = false;
724 } else if (ePktType == PKT_TYPE_802_11_MNG) {
725 pDevice->bStopTx0Pkt = false;
726 } else if (ePktType == PKT_TYPE_802_11_DATA) {
727 pDevice->bStopDataPkt = false;
730 if ((pDevice->bStopBeacon == false) &&
731 (pDevice->bBeaconBufReady == true) &&
732 (pDevice->eOPMode == OP_MODE_ADHOC)) {
733 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
736 return true;
740 * Description: Card Set BSSID value
742 * Parameters:
743 * In:
744 * pDeviceHandler - The adapter to be set
745 * pbyBSSID - pointer to BSSID field
746 * bAdhoc - flag to indicate IBSS
747 * Out:
748 * none
750 * Return Value: true if success; false if failed.
753 bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
755 PSDevice pDevice = (PSDevice) pDeviceHandler;
757 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
758 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
759 if (eOPMode == OP_MODE_ADHOC)
760 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
761 else
762 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
764 if (eOPMode == OP_MODE_AP)
765 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
766 else
767 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
769 if (eOPMode == OP_MODE_UNKNOWN) {
770 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
771 pDevice->bBSSIDFilter = false;
772 pDevice->byRxMode &= ~RCR_BSSID;
773 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
774 } else {
775 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
776 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
777 pDevice->bBSSIDFilter = true;
778 pDevice->byRxMode |= RCR_BSSID;
780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode);
782 // Adopt BSS state in Adapter Device Object
783 pDevice->eOPMode = eOPMode;
784 return true;
788 * Description: Card indicate status
790 * Parameters:
791 * In:
792 * pDeviceHandler - The adapter to be set
793 * eStatus - Status
794 * Out:
795 * none
797 * Return Value: true if success; false if failed.
802 * Description: Save Assoc info. contain in assoc. response frame
804 * Parameters:
805 * In:
806 * pDevice - The adapter to be set
807 * wCapabilityInfo - Capability information
808 * wStatus - Status code
809 * wAID - Assoc. ID
810 * uLen - Length of IEs
811 * pbyIEs - pointer to IEs
812 * Out:
813 * none
815 * Return Value: true if succeed; otherwise false
818 bool CARDbSetTxDataRate(
819 void *pDeviceHandler,
820 unsigned short wDataRate
823 PSDevice pDevice = (PSDevice) pDeviceHandler;
825 pDevice->wCurrentRate = wDataRate;
826 return true;
831 * Routine Description:
832 * Consider to power down when no more packets to tx or rx.
834 * Parameters:
835 * In:
836 * pDevice - The adapter to be set
837 * Out:
838 * none
840 * Return Value: true if power down success; otherwise false
843 bool
844 CARDbPowerDown(
845 void *pDeviceHandler
848 PSDevice pDevice = (PSDevice)pDeviceHandler;
849 unsigned int uIdx;
851 // check if already in Doze mode
852 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
853 return true;
855 // Froce PSEN on
856 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
858 // check if all TD are empty,
860 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
861 if (pDevice->iTDUsed[uIdx] != 0)
862 return false;
865 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
866 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
867 return true;
871 * Description: Turn off Radio power
873 * Parameters:
874 * In:
875 * pDevice - The adapter to be turned off
876 * Out:
877 * none
879 * Return Value: true if success; otherwise false
882 bool CARDbRadioPowerOff(void *pDeviceHandler)
884 PSDevice pDevice = (PSDevice)pDeviceHandler;
885 bool bResult = true;
887 if (pDevice->bRadioOff == true)
888 return true;
890 switch (pDevice->byRFType) {
891 case RF_RFMD2959:
892 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
893 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
894 break;
896 case RF_AIROHA:
897 case RF_AL2230S:
898 case RF_AIROHA7230: //RobertYu:20050104
899 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
900 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
901 break;
905 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
907 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
909 pDevice->bRadioOff = true;
910 //2007-0409-03,<Add> by chester
911 printk("chester power off\n");
912 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
913 return bResult;
917 * Description: Turn on Radio power
919 * Parameters:
920 * In:
921 * pDevice - The adapter to be turned on
922 * Out:
923 * none
925 * Return Value: true if success; otherwise false
928 bool CARDbRadioPowerOn(void *pDeviceHandler)
930 PSDevice pDevice = (PSDevice) pDeviceHandler;
931 bool bResult = true;
932 printk("chester power on\n");
933 if (pDevice->bRadioControlOff == true) {
934 if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
935 if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
936 return false; }
938 if (pDevice->bRadioOff == false) {
939 printk("chester pbRadioOff\n");
940 return true; }
942 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
944 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
946 switch (pDevice->byRFType) {
947 case RF_RFMD2959:
948 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
949 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
950 break;
952 case RF_AIROHA:
953 case RF_AL2230S:
954 case RF_AIROHA7230: //RobertYu:20050104
955 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
956 SOFTPWRCTL_SWPE3));
957 break;
961 pDevice->bRadioOff = false;
962 // 2007-0409-03,<Add> by chester
963 printk("chester power on\n");
964 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
965 return bResult;
968 bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID)
970 PSDevice pDevice = (PSDevice) pDeviceHandler;
972 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
973 return true;
978 * Description:
979 * Add BSSID in PMKID Candidate list.
981 * Parameters:
982 * In:
983 * hDeviceContext - device structure point
984 * pbyBSSID - BSSID address for adding
985 * wRSNCap - BSS's RSN capability
986 * Out:
987 * none
989 * Return Value: none.
992 bool
993 CARDbAdd_PMKID_Candidate(
994 void *pDeviceHandler,
995 unsigned char *pbyBSSID,
996 bool bRSNCapExist,
997 unsigned short wRSNCap
1000 PSDevice pDevice = (PSDevice) pDeviceHandler;
1001 PPMKID_CANDIDATE pCandidateList;
1002 unsigned int ii = 0;
1004 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1006 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n");
1008 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1011 for (ii = 0; ii < 6; ii++)
1012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii));
1014 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
1016 // Update Old Candidate
1017 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1018 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1019 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
1020 if (bRSNCapExist && (wRSNCap & BIT0))
1021 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1022 else
1023 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1025 return true;
1029 // New Candidate
1030 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1031 if (bRSNCapExist && (wRSNCap & BIT0))
1032 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1033 else
1034 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1036 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1037 pDevice->gsPMKIDCandidate.NumCandidates++;
1038 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1039 return true;
1042 void *
1043 CARDpGetCurrentAddress(
1044 void *pDeviceHandler
1047 PSDevice pDevice = (PSDevice) pDeviceHandler;
1049 return pDevice->abyCurrentNetAddr;
1054 * Description:
1055 * Start Spectrum Measure defined in 802.11h
1057 * Parameters:
1058 * In:
1059 * hDeviceContext - device structure point
1060 * Out:
1061 * none
1063 * Return Value: none.
1066 bool
1067 CARDbStartMeasure(
1068 void *pDeviceHandler,
1069 void *pvMeasureEIDs,
1070 unsigned int uNumOfMeasureEIDs
1073 PSDevice pDevice = (PSDevice) pDeviceHandler;
1074 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1075 QWORD qwCurrTSF;
1076 QWORD qwStartTSF;
1077 bool bExpired = true;
1078 unsigned short wDuration = 0;
1080 if ((pEID == NULL) ||
1081 (uNumOfMeasureEIDs == 0)) {
1082 return true;
1084 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1085 if (pDevice->bMeasureInProgress == true) {
1086 pDevice->bMeasureInProgress = false;
1087 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1088 MACvSelectPage1(pDevice->PortOffset);
1089 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1090 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1091 // clear measure control
1092 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1093 MACvSelectPage0(pDevice->PortOffset);
1094 set_channel(pDevice, pDevice->byOrgChannel);
1095 MACvSelectPage1(pDevice->PortOffset);
1096 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1097 MACvSelectPage0(pDevice->PortOffset);
1099 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1101 do {
1102 pDevice->pCurrMeasureEID = pEID;
1103 pEID++;
1104 pDevice->uNumOfMeasureEIDs--;
1106 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1107 HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1108 LODWORD(qwStartTSF) = LODWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1109 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1110 wDuration += 1; // 1 TU for channel switching
1112 if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1113 // start immediately by setting start TSF == current TSF + 2 TU
1114 LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1115 HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
1116 if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF))
1117 HIDWORD(qwStartTSF)++;
1119 bExpired = false;
1120 break;
1121 } else {
1122 // start at setting start TSF - 1TU(for channel switching)
1123 if (LODWORD(qwStartTSF) < 1024)
1124 HIDWORD(qwStartTSF)--;
1126 LODWORD(qwStartTSF) -= 1024;
1129 if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1130 ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1131 (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1133 bExpired = false;
1134 break;
1136 VNTWIFIbMeasureReport(pDevice->pMgmt,
1137 false,
1138 pDevice->pCurrMeasureEID,
1139 MEASURE_MODE_LATE,
1140 pDevice->byBasicMap,
1141 pDevice->byCCAFraction,
1142 pDevice->abyRPIs
1144 } else {
1145 // hardware do not support measure
1146 VNTWIFIbMeasureReport(pDevice->pMgmt,
1147 false,
1148 pDevice->pCurrMeasureEID,
1149 MEASURE_MODE_INCAPABLE,
1150 pDevice->byBasicMap,
1151 pDevice->byCCAFraction,
1152 pDevice->abyRPIs
1155 } while (pDevice->uNumOfMeasureEIDs != 0);
1157 if (!bExpired) {
1158 MACvSelectPage1(pDevice->PortOffset);
1159 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1160 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1161 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1162 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1163 MACvSelectPage0(pDevice->PortOffset);
1164 } else {
1165 // all measure start time expired we should complete action
1166 VNTWIFIbMeasureReport(pDevice->pMgmt,
1167 true,
1168 NULL,
1170 pDevice->byBasicMap,
1171 pDevice->byCCAFraction,
1172 pDevice->abyRPIs
1175 return true;
1180 * Description:
1181 * Do Channel Switch defined in 802.11h
1183 * Parameters:
1184 * In:
1185 * hDeviceContext - device structure point
1186 * Out:
1187 * none
1189 * Return Value: none.
1192 bool
1193 CARDbChannelSwitch(
1194 void *pDeviceHandler,
1195 unsigned char byMode,
1196 unsigned char byNewChannel,
1197 unsigned char byCount
1200 PSDevice pDevice = (PSDevice) pDeviceHandler;
1201 bool bResult = true;
1203 if (byCount == 0) {
1204 bResult = set_channel(pDevice, byNewChannel);
1205 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1206 MACvSelectPage1(pDevice->PortOffset);
1207 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1208 MACvSelectPage0(pDevice->PortOffset);
1209 return bResult;
1211 pDevice->byChannelSwitchCount = byCount;
1212 pDevice->byNewChannel = byNewChannel;
1213 pDevice->bChannelSwitch = true;
1214 if (byMode == 1)
1215 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1217 return bResult;
1222 * Description:
1223 * Handle Quiet EID defined in 802.11h
1225 * Parameters:
1226 * In:
1227 * hDeviceContext - device structure point
1228 * Out:
1229 * none
1231 * Return Value: none.
1234 bool
1235 CARDbSetQuiet(
1236 void *pDeviceHandler,
1237 bool bResetQuiet,
1238 unsigned char byQuietCount,
1239 unsigned char byQuietPeriod,
1240 unsigned short wQuietDuration,
1241 unsigned short wQuietOffset
1244 PSDevice pDevice = (PSDevice) pDeviceHandler;
1245 unsigned int ii = 0;
1247 if (bResetQuiet) {
1248 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1249 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
1250 pDevice->sQuiet[ii].bEnable = false;
1252 pDevice->uQuietEnqueue = 0;
1253 pDevice->bEnableFirstQuiet = false;
1254 pDevice->bQuietEnable = false;
1255 pDevice->byQuietStartCount = byQuietCount;
1257 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1258 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1259 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1260 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1261 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1262 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1263 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1264 pDevice->uQuietEnqueue++;
1265 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1266 if (pDevice->byQuietStartCount < byQuietCount)
1267 pDevice->byQuietStartCount = byQuietCount;
1269 return true;
1274 * Description:
1275 * Do Quiet, It will be called by either ISR(after start)
1276 * or VNTWIFI(before start) so we do not need a SPINLOCK
1278 * Parameters:
1279 * In:
1280 * hDeviceContext - device structure point
1281 * Out:
1282 * none
1284 * Return Value: none.
1287 bool
1288 CARDbStartQuiet(
1289 void *pDeviceHandler
1292 PSDevice pDevice = (PSDevice) pDeviceHandler;
1293 unsigned int ii = 0;
1294 unsigned long dwStartTime = 0xFFFFFFFF;
1295 unsigned int uCurrentQuietIndex = 0;
1296 unsigned long dwNextTime = 0;
1297 unsigned long dwGap = 0;
1298 unsigned long dwDuration = 0;
1300 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1301 if ((pDevice->sQuiet[ii].bEnable == true) &&
1302 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1303 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1304 uCurrentQuietIndex = ii;
1307 if (dwStartTime == 0xFFFFFFFF) {
1308 // no more quiet
1309 pDevice->bQuietEnable = false;
1310 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1311 } else {
1312 if (pDevice->bQuietEnable == false) {
1313 // first quiet
1314 pDevice->byQuietStartCount--;
1315 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1316 dwNextTime %= pDevice->wBeaconInterval;
1317 MACvSelectPage1(pDevice->PortOffset);
1318 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1319 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1320 if (pDevice->byQuietStartCount == 0) {
1321 pDevice->bEnableFirstQuiet = false;
1322 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1323 } else {
1324 pDevice->bEnableFirstQuiet = true;
1326 MACvSelectPage0(pDevice->PortOffset);
1327 } else {
1328 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1329 // overlap with previous Quiet
1330 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1331 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1332 // return false to indicate next quiet expired, should call this function again
1333 return false;
1335 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1336 dwGap = 0;
1337 } else {
1338 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1339 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1341 // set GAP and Next duration
1342 MACvSelectPage1(pDevice->PortOffset);
1343 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1344 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1345 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1346 MACvSelectPage0(pDevice->PortOffset);
1348 pDevice->bQuietEnable = true;
1349 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1350 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1351 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1352 // not period disable current quiet element
1353 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1354 } else {
1355 // set next period start time
1356 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1357 dwNextTime *= pDevice->wBeaconInterval;
1358 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1360 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1361 // decreament all time to avoid wrap around
1362 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1363 if (pDevice->sQuiet[ii].bEnable == true)
1364 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1367 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1370 return true;
1375 * Description:
1376 * Set Local Power Constraint
1378 * Parameters:
1379 * In:
1380 * hDeviceContext - device structure point
1381 * Out:
1382 * none
1384 * Return Value: none.
1387 void
1388 CARDvSetPowerConstraint(
1389 void *pDeviceHandler,
1390 unsigned char byChannel,
1391 char byPower
1394 PSDevice pDevice = (PSDevice) pDeviceHandler;
1396 if (byChannel > CB_MAX_CHANNEL_24G) {
1397 if (pDevice->bCountryInfo5G == true)
1398 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1400 } else {
1401 if (pDevice->bCountryInfo24G == true)
1402 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1409 * Description:
1410 * Set Local Power Constraint
1412 * Parameters:
1413 * In:
1414 * hDeviceContext - device structure point
1415 * Out:
1416 * none
1418 * Return Value: none.
1421 void
1422 CARDvGetPowerCapability(
1423 void *pDeviceHandler,
1424 unsigned char *pbyMinPower,
1425 unsigned char *pbyMaxPower
1428 PSDevice pDevice = (PSDevice) pDeviceHandler;
1429 unsigned char byDec = 0;
1431 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1432 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1433 if (pDevice->byRFType == RF_UW2452) {
1434 byDec *= 3;
1435 byDec >>= 1;
1436 } else {
1437 byDec <<= 1;
1439 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1444 * Description:
1445 * Get Current Tx Power
1447 * Parameters:
1448 * In:
1449 * hDeviceContext - device structure point
1450 * Out:
1451 * none
1453 * Return Value: none.
1456 char
1457 CARDbyGetTransmitPower(
1458 void *pDeviceHandler
1461 PSDevice pDevice = (PSDevice) pDeviceHandler;
1463 return pDevice->byCurPwrdBm;
1466 //xxx
1467 void
1468 CARDvSafeResetTx(
1469 void *pDeviceHandler
1472 PSDevice pDevice = (PSDevice) pDeviceHandler;
1473 unsigned int uu;
1474 PSTxDesc pCurrTD;
1476 // initialize TD index
1477 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1478 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1480 for (uu = 0; uu < TYPE_MAXTD; uu++)
1481 pDevice->iTDUsed[uu] = 0;
1483 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1484 pCurrTD = &(pDevice->apTD0Rings[uu]);
1485 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1486 // init all Tx Packet pointer to NULL
1488 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1489 pCurrTD = &(pDevice->apTD1Rings[uu]);
1490 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1491 // init all Tx Packet pointer to NULL
1494 // set MAC TD pointer
1495 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1496 (pDevice->td0_pool_dma));
1498 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1499 (pDevice->td1_pool_dma));
1501 // set MAC Beacon TX pointer
1502 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1503 (pDevice->tx_beacon_dma));
1508 * Description:
1509 * Reset Rx
1511 * Parameters:
1512 * In:
1513 * pDevice - Pointer to the adapter
1514 * Out:
1515 * none
1517 * Return Value: none
1520 void
1521 CARDvSafeResetRx(
1522 void *pDeviceHandler
1525 PSDevice pDevice = (PSDevice) pDeviceHandler;
1526 unsigned int uu;
1527 PSRxDesc pDesc;
1529 // initialize RD index
1530 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1531 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1533 // init state, all RD is chip's
1534 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1535 pDesc = &(pDevice->aRD0Ring[uu]);
1536 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1537 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1538 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1541 // init state, all RD is chip's
1542 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1543 pDesc = &(pDevice->aRD1Ring[uu]);
1544 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1545 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1546 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1549 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1550 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1552 // set perPkt mode
1553 MACvRx0PerPktMode(pDevice->PortOffset);
1554 MACvRx1PerPktMode(pDevice->PortOffset);
1555 // set MAC RD pointer
1556 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1557 pDevice->rd0_pool_dma);
1559 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1560 pDevice->rd1_pool_dma);
1564 * Description: Get response Control frame rate in CCK mode
1566 * Parameters:
1567 * In:
1568 * pDevice - The adapter to be set
1569 * wRateIdx - Receiving data rate
1570 * Out:
1571 * none
1573 * Return Value: response Control frame rate
1576 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
1578 PSDevice pDevice = (PSDevice) pDeviceHandler;
1579 unsigned int ui = (unsigned int) wRateIdx;
1581 while (ui > RATE_1M) {
1582 if (pDevice->wBasicRate & ((unsigned short)1 << ui))
1583 return (unsigned short)ui;
1585 ui--;
1587 return (unsigned short)RATE_1M;
1591 * Description: Get response Control frame rate in OFDM mode
1593 * Parameters:
1594 * In:
1595 * pDevice - The adapter to be set
1596 * wRateIdx - Receiving data rate
1597 * Out:
1598 * none
1600 * Return Value: response Control frame rate
1603 unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx)
1605 PSDevice pDevice = (PSDevice) pDeviceHandler;
1606 unsigned int ui = (unsigned int) wRateIdx;
1608 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate);
1610 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1611 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1612 if (wRateIdx > RATE_24M)
1613 wRateIdx = RATE_24M;
1614 return wRateIdx;
1616 while (ui > RATE_11M) {
1617 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1618 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui);
1619 return (unsigned short)ui;
1621 ui--;
1623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n");
1624 return (unsigned short)RATE_24M;
1628 * Description: Set RSPINF
1630 * Parameters:
1631 * In:
1632 * pDevice - The adapter to be set
1633 * Out:
1634 * none
1636 * Return Value: None.
1639 void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
1641 PSDevice pDevice = (PSDevice) pDeviceHandler;
1642 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1643 unsigned short wLen = 0x0000;
1644 unsigned char byTxRate, byRsvTime; //For OFDM
1646 //Set to Page1
1647 MACvSelectPage1(pDevice->PortOffset);
1649 //RSPINF_b_1
1650 BBvCalculateParameter(pDevice,
1652 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1653 PK_TYPE_11B,
1654 &wLen,
1655 &byServ,
1656 &bySignal
1659 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1660 ///RSPINF_b_2
1661 BBvCalculateParameter(pDevice,
1663 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1664 PK_TYPE_11B,
1665 &wLen,
1666 &byServ,
1667 &bySignal
1670 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1671 //RSPINF_b_5
1672 BBvCalculateParameter(pDevice,
1674 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1675 PK_TYPE_11B,
1676 &wLen,
1677 &byServ,
1678 &bySignal
1681 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1682 //RSPINF_b_11
1683 BBvCalculateParameter(pDevice,
1685 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1686 PK_TYPE_11B,
1687 &wLen,
1688 &byServ,
1689 &bySignal
1692 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1693 //RSPINF_a_6
1694 s_vCalculateOFDMRParameter(RATE_6M,
1695 ePHYType,
1696 &byTxRate,
1697 &byRsvTime);
1698 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1699 //RSPINF_a_9
1700 s_vCalculateOFDMRParameter(RATE_9M,
1701 ePHYType,
1702 &byTxRate,
1703 &byRsvTime);
1704 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1705 //RSPINF_a_12
1706 s_vCalculateOFDMRParameter(RATE_12M,
1707 ePHYType,
1708 &byTxRate,
1709 &byRsvTime);
1710 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1711 //RSPINF_a_18
1712 s_vCalculateOFDMRParameter(RATE_18M,
1713 ePHYType,
1714 &byTxRate,
1715 &byRsvTime);
1716 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1717 //RSPINF_a_24
1718 s_vCalculateOFDMRParameter(RATE_24M,
1719 ePHYType,
1720 &byTxRate,
1721 &byRsvTime);
1722 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1723 //RSPINF_a_36
1724 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1725 ePHYType,
1726 &byTxRate,
1727 &byRsvTime);
1728 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1729 //RSPINF_a_48
1730 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1731 ePHYType,
1732 &byTxRate,
1733 &byRsvTime);
1734 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1735 //RSPINF_a_54
1736 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1737 ePHYType,
1738 &byTxRate,
1739 &byRsvTime);
1740 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
1742 //RSPINF_a_72
1743 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1744 ePHYType,
1745 &byTxRate,
1746 &byRsvTime);
1747 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1748 //Set to Page0
1749 MACvSelectPage0(pDevice->PortOffset);
1753 * Description: Update IFS
1755 * Parameters:
1756 * In:
1757 * pDevice - The adapter to be set
1758 * Out:
1759 * none
1761 * Return Value: None.
1764 void vUpdateIFS(void *pDeviceHandler)
1766 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1767 PSDevice pDevice = (PSDevice) pDeviceHandler;
1769 unsigned char byMaxMin = 0;
1770 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1771 pDevice->uSlot = C_SLOT_SHORT;
1772 pDevice->uSIFS = C_SIFS_A;
1773 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1774 pDevice->uCwMin = C_CWMIN_A;
1775 byMaxMin = 4;
1776 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
1777 pDevice->uSlot = C_SLOT_LONG;
1778 pDevice->uSIFS = C_SIFS_BG;
1779 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1780 pDevice->uCwMin = C_CWMIN_B;
1781 byMaxMin = 5;
1782 } else { // PK_TYPE_11GA & PK_TYPE_11GB
1783 pDevice->uSIFS = C_SIFS_BG;
1784 if (pDevice->bShortSlotTime)
1785 pDevice->uSlot = C_SLOT_SHORT;
1786 else
1787 pDevice->uSlot = C_SLOT_LONG;
1789 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1790 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1791 pDevice->uCwMin = C_CWMIN_A;
1792 byMaxMin = 4;
1793 } else {
1794 pDevice->uCwMin = C_CWMIN_B;
1795 byMaxMin = 5;
1799 pDevice->uCwMax = C_CWMAX;
1800 pDevice->uEIFS = C_EIFS;
1801 if (pDevice->byRFType == RF_RFMD2959) {
1802 // bcs TX_PE will reserve 3 us
1803 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1804 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1805 } else {
1806 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1807 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1809 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1810 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1811 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1812 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1815 void CARDvUpdateBasicTopRate(void *pDeviceHandler)
1817 PSDevice pDevice = (PSDevice) pDeviceHandler;
1818 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1819 unsigned char ii;
1821 //Determines the highest basic rate.
1822 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1823 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1824 byTopOFDM = ii;
1825 break;
1828 pDevice->byTopOFDMBasicRate = byTopOFDM;
1830 for (ii = RATE_11M;; ii--) {
1831 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1832 byTopCCK = ii;
1833 break;
1835 if (ii == RATE_1M)
1836 break;
1838 pDevice->byTopCCKBasicRate = byTopCCK;
1841 bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx)
1843 PSDevice pDevice = (PSDevice) pDeviceHandler;
1844 unsigned short wRate = (unsigned short)(1<<wRateIdx);
1846 pDevice->wBasicRate |= wRate;
1848 //Determines the highest basic rate.
1849 CARDvUpdateBasicTopRate((void *)pDevice);
1851 return true;
1854 bool CARDbIsOFDMinBasicRate(void *pDeviceHandler)
1856 PSDevice pDevice = (PSDevice)pDeviceHandler;
1857 int ii;
1859 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1860 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1861 return true;
1863 return false;
1866 unsigned char CARDbyGetPktType(void *pDeviceHandler)
1868 PSDevice pDevice = (PSDevice) pDeviceHandler;
1870 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
1871 return (unsigned char)pDevice->byBBType;
1872 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
1873 return PK_TYPE_11GA;
1874 else
1875 return PK_TYPE_11GB;
1879 * Description: Set NIC Loopback mode
1881 * Parameters:
1882 * In:
1883 * pDevice - The adapter to be set
1884 * wLoopbackMode - Loopback mode to be set
1885 * Out:
1886 * none
1888 * Return Value: none
1891 void CARDvSetLoopbackMode(unsigned long dwIoBase, unsigned short wLoopbackMode)
1893 switch (wLoopbackMode) {
1894 case CARD_LB_NONE:
1895 case CARD_LB_MAC:
1896 case CARD_LB_PHY:
1897 break;
1898 default:
1899 ASSERT(false);
1900 break;
1902 // set MAC loopback
1903 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1904 // set Baseband loopback
1908 * Description: Software Reset NIC
1910 * Parameters:
1911 * In:
1912 * pDevice - The adapter to be reset
1913 * Out:
1914 * none
1916 * Return Value: none
1919 bool CARDbSoftwareReset(void *pDeviceHandler)
1921 PSDevice pDevice = (PSDevice) pDeviceHandler;
1923 // reset MAC
1924 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1925 return false;
1927 return true;
1931 * Description: Calculate TSF offset of two TSF input
1932 * Get TSF Offset from RxBCN's TSF and local TSF
1934 * Parameters:
1935 * In:
1936 * pDevice - The adapter to be sync.
1937 * qwTSF1 - Rx BCN's TSF
1938 * qwTSF2 - Local TSF
1939 * Out:
1940 * none
1942 * Return Value: TSF Offset value
1945 QWORD CARDqGetTSFOffset(unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
1947 QWORD qwTSFOffset;
1948 unsigned short wRxBcnTSFOffst = 0;
1950 HIDWORD(qwTSFOffset) = 0;
1951 LODWORD(qwTSFOffset) = 0;
1952 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
1953 (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
1954 if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst))
1955 (qwTSF2).u.dwHighDword++;
1957 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
1958 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
1959 // if borrow needed
1960 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1;
1961 } else {
1962 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
1964 return qwTSFOffset;
1968 * Description: Read NIC TSF counter
1969 * Get local TSF counter
1971 * Parameters:
1972 * In:
1973 * pDevice - The adapter to be read
1974 * Out:
1975 * qwCurrTSF - Current TSF counter
1977 * Return Value: true if success; otherwise false
1980 bool CARDbGetCurrentTSF(unsigned long dwIoBase, PQWORD pqwCurrTSF)
1982 unsigned short ww;
1983 unsigned char byData;
1985 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
1986 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1987 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
1988 if (!(byData & TFTCTL_TSFCNTRRD))
1989 break;
1991 if (ww == W_MAX_TIMEOUT)
1992 return false;
1993 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
1994 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
1996 return true;
2000 * Description: Read NIC TSF counter
2001 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2003 * Parameters:
2004 * In:
2005 * qwTSF - Current TSF counter
2006 * wbeaconInterval - Beacon Interval
2007 * Out:
2008 * qwCurrTSF - Current TSF counter
2010 * Return Value: TSF value of next Beacon
2013 QWORD CARDqGetNextTBTT(QWORD qwTSF, unsigned short wBeaconInterval)
2015 unsigned int uLowNextTBTT;
2016 unsigned int uHighRemain, uLowRemain;
2017 unsigned int uBeaconInterval;
2019 uBeaconInterval = wBeaconInterval * 1024;
2020 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
2021 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
2022 // low dword (mod) bcn
2023 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
2024 // high dword (mod) bcn
2025 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
2026 % uBeaconInterval;
2027 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2028 uLowRemain = uBeaconInterval - uLowRemain;
2030 // check if carry when add one beacon interval
2031 if ((~uLowNextTBTT) < uLowRemain)
2032 HIDWORD(qwTSF)++;
2034 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
2036 return qwTSF;
2040 * Description: Set NIC TSF counter for first Beacon time
2041 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2043 * Parameters:
2044 * In:
2045 * dwIoBase - IO Base
2046 * wBeaconInterval - Beacon Interval
2047 * Out:
2048 * none
2050 * Return Value: none
2053 void CARDvSetFirstNextTBTT(unsigned long dwIoBase, unsigned short wBeaconInterval)
2055 QWORD qwNextTBTT;
2057 HIDWORD(qwNextTBTT) = 0;
2058 LODWORD(qwNextTBTT) = 0;
2059 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
2060 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2061 // Set NextTBTT
2062 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
2063 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
2064 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2066 return;
2070 * Description: Sync NIC TSF counter for Beacon time
2071 * Get NEXTTBTT and write to HW
2073 * Parameters:
2074 * In:
2075 * pDevice - The adapter to be set
2076 * qwTSF - Current TSF counter
2077 * wBeaconInterval - Beacon Interval
2078 * Out:
2079 * none
2081 * Return Value: none
2084 void CARDvUpdateNextTBTT(unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
2086 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2087 // Set NextTBTT
2088 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
2089 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
2090 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8xh:%8xh] \n",
2092 (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
2094 return;