Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
card.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
18  *
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
40  *
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().
45  *
46  */
47 
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"
60 
61 /*--------------------- Static Definitions -------------------------*/
62 
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 static int msglevel =MSG_LEVEL_INFO;
65 
66 #define C_SIFS_A 16 // micro sec.
67 #define C_SIFS_BG 10
68 
69 #define C_EIFS 80 // micro sec.
70 
71 
72 #define C_SLOT_SHORT 9 // micro sec.
73 #define C_SLOT_LONG 20
74 
75 #define C_CWMIN_A 15 // slot time
76 #define C_CWMIN_B 31
77 
78 #define C_CWMAX 1023 // slot time
79 
80 #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
81 
82  //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
83 static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
84  //6M, 9M, 12M, 48M
85 static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
86  //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
87 static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
88  //1M, 2M, 5M, 11M,
89 static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
90 
91 
92 /*--------------------- Static Variables --------------------------*/
93 
94 
95 const unsigned short cwRXBCNTSFOff[MAX_RATE] =
96 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
97 
98 
99 /*--------------------- Static Functions --------------------------*/
100 
101 static
102 void
103 s_vCalculateOFDMRParameter(
104  unsigned char byRate,
105  CARD_PHY_TYPE ePHYType,
106  unsigned char *pbyTxRate,
107  unsigned char *pbyRsvTime
108  );
109 
110 
111 /*--------------------- Export Functions --------------------------*/
112 
113 /*
114  * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
115  *
116  * Parameters:
117  * In:
118  * wRate - Tx Rate
119  * byPktType - Tx Packet type
120  * Out:
121  * pbyTxRate - pointer to RSPINF TxRate field
122  * pbyRsvTime - pointer to RSPINF RsvTime field
123  *
124  * Return Value: none
125  *
126  */
127 static
128 void
129 s_vCalculateOFDMRParameter (
130  unsigned char byRate,
131  CARD_PHY_TYPE ePHYType,
132  unsigned char *pbyTxRate,
133  unsigned char *pbyRsvTime
134  )
135 {
136  switch (byRate) {
137  case RATE_6M :
138  if (ePHYType == PHY_TYPE_11A) {//5GHZ
139  *pbyTxRate = 0x9B;
140  *pbyRsvTime = 44;
141  }
142  else {
143  *pbyTxRate = 0x8B;
144  *pbyRsvTime = 50;
145  }
146  break;
147 
148  case RATE_9M :
149  if (ePHYType == PHY_TYPE_11A) {//5GHZ
150  *pbyTxRate = 0x9F;
151  *pbyRsvTime = 36;
152  }
153  else {
154  *pbyTxRate = 0x8F;
155  *pbyRsvTime = 42;
156  }
157  break;
158 
159  case RATE_12M :
160  if (ePHYType == PHY_TYPE_11A) {//5GHZ
161  *pbyTxRate = 0x9A;
162  *pbyRsvTime = 32;
163  }
164  else {
165  *pbyTxRate = 0x8A;
166  *pbyRsvTime = 38;
167  }
168  break;
169 
170  case RATE_18M :
171  if (ePHYType == PHY_TYPE_11A) {//5GHZ
172  *pbyTxRate = 0x9E;
173  *pbyRsvTime = 28;
174  }
175  else {
176  *pbyTxRate = 0x8E;
177  *pbyRsvTime = 34;
178  }
179  break;
180 
181  case RATE_36M :
182  if (ePHYType == PHY_TYPE_11A) {//5GHZ
183  *pbyTxRate = 0x9D;
184  *pbyRsvTime = 24;
185  }
186  else {
187  *pbyTxRate = 0x8D;
188  *pbyRsvTime = 30;
189  }
190  break;
191 
192  case RATE_48M :
193  if (ePHYType == PHY_TYPE_11A) {//5GHZ
194  *pbyTxRate = 0x98;
195  *pbyRsvTime = 24;
196  }
197  else {
198  *pbyTxRate = 0x88;
199  *pbyRsvTime = 30;
200  }
201  break;
202 
203  case RATE_54M :
204  if (ePHYType == PHY_TYPE_11A) {//5GHZ
205  *pbyTxRate = 0x9C;
206  *pbyRsvTime = 24;
207  }
208  else {
209  *pbyTxRate = 0x8C;
210  *pbyRsvTime = 30;
211  }
212  break;
213 
214  case RATE_24M :
215  default :
216  if (ePHYType == PHY_TYPE_11A) {//5GHZ
217  *pbyTxRate = 0x99;
218  *pbyRsvTime = 28;
219  }
220  else {
221  *pbyTxRate = 0x89;
222  *pbyRsvTime = 34;
223  }
224  break;
225  }
226 }
227 
228 
229 
230 /*
231  * Description: Set RSPINF
232  *
233  * Parameters:
234  * In:
235  * pDevice - The adapter to be set
236  * Out:
237  * none
238  *
239  * Return Value: None.
240  *
241  */
242 static
243 void
244 s_vSetRSPINF (PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
245 {
246  unsigned char byServ = 0, bySignal = 0; // For CCK
247  unsigned short wLen = 0;
248  unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
249 
250  //Set to Page1
251  MACvSelectPage1(pDevice->PortOffset);
252 
253  //RSPINF_b_1
254  BBvCalculateParameter(pDevice,
255  14,
256  VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
257  PK_TYPE_11B,
258  &wLen,
259  &byServ,
260  &bySignal
261  );
262 
263  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
265  BBvCalculateParameter(pDevice,
266  14,
267  VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
268  PK_TYPE_11B,
269  &wLen,
270  &byServ,
271  &bySignal
272  );
273 
274  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
275  //RSPINF_b_5
276  BBvCalculateParameter(pDevice,
277  14,
278  VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
279  PK_TYPE_11B,
280  &wLen,
281  &byServ,
282  &bySignal
283  );
284 
285  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
286  //RSPINF_b_11
287  BBvCalculateParameter(pDevice,
288  14,
289  VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
290  PK_TYPE_11B,
291  &wLen,
292  &byServ,
293  &bySignal
294  );
295 
296  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
297  //RSPINF_a_6
298  s_vCalculateOFDMRParameter(RATE_6M,
299  ePHYType,
300  &byTxRate,
301  &byRsvTime);
302  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
303  //RSPINF_a_9
304  s_vCalculateOFDMRParameter(RATE_9M,
305  ePHYType,
306  &byTxRate,
307  &byRsvTime);
308  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
309  //RSPINF_a_12
310  s_vCalculateOFDMRParameter(RATE_12M,
311  ePHYType,
312  &byTxRate,
313  &byRsvTime);
314  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
315  //RSPINF_a_18
316  s_vCalculateOFDMRParameter(RATE_18M,
317  ePHYType,
318  &byTxRate,
319  &byRsvTime);
320  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
321  //RSPINF_a_24
322  s_vCalculateOFDMRParameter(RATE_24M,
323  ePHYType,
324  &byTxRate,
325  &byRsvTime);
326  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
327  //RSPINF_a_36
328  s_vCalculateOFDMRParameter(
329  VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
330  ePHYType,
331  &byTxRate,
332  &byRsvTime);
333  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
334  //RSPINF_a_48
335  s_vCalculateOFDMRParameter(
336  VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
337  ePHYType,
338  &byTxRate,
339  &byRsvTime);
340  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
341  //RSPINF_a_54
342  s_vCalculateOFDMRParameter(
343  VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
344  ePHYType,
345  &byTxRate,
346  &byRsvTime);
347  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
348  //RSPINF_a_72
349  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
350  //Set to Page0
351  MACvSelectPage0(pDevice->PortOffset);
352 }
353 
354 /*--------------------- Export Functions --------------------------*/
355 
356 /*
357  * Description: Card Send packet function
358  *
359  * Parameters:
360  * In:
361  * pDeviceHandler - The adapter to be set
362  * pPacket - Packet buffer pointer
363  * ePktType - Packet type
364  * uLength - Packet length
365  * Out:
366  * none
367  *
368  * Return Value: true if succeeded; false if failed.
369  *
370  */
371 /*
372 bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength)
373 {
374  PSDevice pDevice = (PSDevice) pDeviceHandler;
375  if (ePktType == PKT_TYPE_802_11_MNG) {
376  return TXbTD0Send(pDevice, pPacket, uLength);
377  } else if (ePktType == PKT_TYPE_802_11_BCN) {
378  return TXbBeaconSend(pDevice, pPacket, uLength);
379  } if (ePktType == PKT_TYPE_802_11_DATA) {
380  return TXbTD1Send(pDevice, pPacket, uLength);
381  }
382 
383  return (true);
384 }
385 */
386 
387 
388 /*
389  * Description: Get Card short preamble option value
390  *
391  * Parameters:
392  * In:
393  * pDevice - The adapter to be set
394  * Out:
395  * none
396  *
397  * Return Value: true if short preamble; otherwise false
398  *
399  */
400 bool CARDbIsShortPreamble (void *pDeviceHandler)
401 {
402  PSDevice pDevice = (PSDevice) pDeviceHandler;
403  if (pDevice->byPreambleType == 0) {
404  return(false);
405  }
406  return(true);
407 }
408 
409 /*
410  * Description: Get Card short slot time option value
411  *
412  * Parameters:
413  * In:
414  * pDevice - The adapter to be set
415  * Out:
416  * none
417  *
418  * Return Value: true if short slot time; otherwise false
419  *
420  */
421 bool CARDbIsShorSlotTime (void *pDeviceHandler)
422 {
423  PSDevice pDevice = (PSDevice) pDeviceHandler;
424  return(pDevice->bShortSlotTime);
425 }
426 
427 
428 /*
429  * Description: Update IFS
430  *
431  * Parameters:
432  * In:
433  * pDevice - The adapter to be set
434  * Out:
435  * none
436  *
437  * Return Value: None.
438  *
439  */
440 bool CARDbSetPhyParameter (void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
441 {
442  PSDevice pDevice = (PSDevice) pDeviceHandler;
443  unsigned char byCWMaxMin = 0;
444  unsigned char bySlot = 0;
445  unsigned char bySIFS = 0;
446  unsigned char byDIFS = 0;
447  unsigned char byData;
448 // PWLAN_IE_SUPP_RATES pRates = NULL;
449  PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
450  PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
451 
452 
453  //Set SIFS, DIFS, EIFS, SlotTime, CwMin
454  if (ePHYType == PHY_TYPE_11A) {
455  if (pSupportRates == NULL) {
456  pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
457  }
458  if (pDevice->byRFType == RF_AIROHA7230) {
459  // AL7230 use single PAPE and connect to PAPE_2.4G
461  pDevice->abyBBVGA[0] = 0x20;
462  pDevice->abyBBVGA[2] = 0x10;
463  pDevice->abyBBVGA[3] = 0x10;
464  BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
465  if (byData == 0x1C) {
466  BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
467  }
468  } else if (pDevice->byRFType == RF_UW2452) {
470  pDevice->abyBBVGA[0] = 0x18;
471  BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
472  if (byData == 0x14) {
473  BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
474  BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
475  }
476  } else {
478  }
479  BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
480  bySlot = C_SLOT_SHORT;
481  bySIFS = C_SIFS_A;
482  byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
483  byCWMaxMin = 0xA4;
484  } else if (ePHYType == PHY_TYPE_11B) {
485  if (pSupportRates == NULL) {
486  pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
487  }
489  if (pDevice->byRFType == RF_AIROHA7230) {
490  pDevice->abyBBVGA[0] = 0x1C;
491  pDevice->abyBBVGA[2] = 0x00;
492  pDevice->abyBBVGA[3] = 0x00;
493  BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
494  if (byData == 0x20) {
495  BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
496  }
497  } else if (pDevice->byRFType == RF_UW2452) {
498  pDevice->abyBBVGA[0] = 0x14;
499  BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
500  if (byData == 0x18) {
501  BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
502  BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
503  }
504  }
505  BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
506  bySlot = C_SLOT_LONG;
507  bySIFS = C_SIFS_BG;
508  byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
509  byCWMaxMin = 0xA5;
510  } else {// PK_TYPE_11GA & PK_TYPE_11GB
511  if (pSupportRates == NULL) {
512  pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
513  pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
514  }
516  if (pDevice->byRFType == RF_AIROHA7230) {
517  pDevice->abyBBVGA[0] = 0x1C;
518  pDevice->abyBBVGA[2] = 0x00;
519  pDevice->abyBBVGA[3] = 0x00;
520  BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
521  if (byData == 0x20) {
522  BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
523  }
524  } else if (pDevice->byRFType == RF_UW2452) {
525  pDevice->abyBBVGA[0] = 0x14;
526  BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
527  if (byData == 0x18) {
528  BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
529  BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
530  }
531  }
532  BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
533  bySIFS = C_SIFS_BG;
534  if(VNTWIFIbIsShortSlotTime(wCapInfo)) {
535  bySlot = C_SLOT_SHORT;
536  byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
537  } else {
538  bySlot = C_SLOT_LONG;
539  byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
540  }
541  if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
542  byCWMaxMin = 0xA4;
543  } else {
544  byCWMaxMin = 0xA5;
545  }
546  if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
547  pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
548  if (pDevice->bProtectMode) {
550  } else {
552  }
553  }
554  if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
555  pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
556  if (pDevice->bBarkerPreambleMd) {
558  } else {
560  }
561  }
562  }
563 
564  if (pDevice->byRFType == RF_RFMD2959) {
565  // bcs TX_PE will reserve 3 us
566  // hardware's processing time here is 2 us.
567  bySIFS -= 3;
568  byDIFS -= 3;
569  //{{ RobertYu: 20041202
572  }
573 
574  if (pDevice->bySIFS != bySIFS) {
575  pDevice->bySIFS = bySIFS;
576  VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
577  }
578  if (pDevice->byDIFS != byDIFS) {
579  pDevice->byDIFS = byDIFS;
580  VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
581  }
582  if (pDevice->byEIFS != C_EIFS) {
583  pDevice->byEIFS = C_EIFS;
584  VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
585  }
586  if (pDevice->bySlot != bySlot) {
587  pDevice->bySlot = bySlot;
588  VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
589  if (pDevice->bySlot == C_SLOT_SHORT) {
590  pDevice->bShortSlotTime = true;
591  } else {
592  pDevice->bShortSlotTime = false;
593  }
594  BBvSetShortSlotTime(pDevice);
595  }
596  if (pDevice->byCWMaxMin != byCWMaxMin) {
597  pDevice->byCWMaxMin = byCWMaxMin;
598  VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
599  }
600  if (VNTWIFIbIsShortPreamble(wCapInfo)) {
601  pDevice->byPreambleType = pDevice->byShortPreamble;
602  } else {
603  pDevice->byPreambleType = 0;
604  }
605  s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
606  pDevice->eCurrentPHYType = ePHYType;
607  // set for NDIS OID_802_11SUPPORTED_RATES
608  return (true);
609 }
610 
611 /*
612  * Description: Sync. TSF counter to BSS
613  * Get TSF offset and write to HW
614  *
615  * Parameters:
616  * In:
617  * pDevice - The adapter to be sync.
618  * byRxRate - data rate of receive beacon
619  * qwBSSTimestamp - Rx BCN's TSF
620  * qwLocalTSF - Local TSF
621  * Out:
622  * none
623  *
624  * Return Value: none
625  *
626  */
627 bool CARDbUpdateTSF (void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
628 {
629  PSDevice pDevice = (PSDevice) pDeviceHandler;
630  QWORD qwTSFOffset;
631 
632  HIDWORD(qwTSFOffset) = 0;
633  LODWORD(qwTSFOffset) = 0;
634 
635  if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
636  (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
637  qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
638  // adjust TSF
639  // HW's TSF add TSF Offset reg
640  VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
641  VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
643  }
644  return(true);
645 }
646 
647 
648 /*
649  * Description: Set NIC TSF counter for first Beacon time
650  * Get NEXTTBTT from adjusted TSF and Beacon Interval
651  *
652  * Parameters:
653  * In:
654  * pDevice - The adapter to be set.
655  * wBeaconInterval - Beacon Interval
656  * Out:
657  * none
658  *
659  * Return Value: true if succeed; otherwise false
660  *
661  */
662 bool CARDbSetBeaconPeriod (void *pDeviceHandler, unsigned short wBeaconInterval)
663 {
664  PSDevice pDevice = (PSDevice) pDeviceHandler;
665  unsigned int uBeaconInterval = 0;
666  unsigned int uLowNextTBTT = 0;
667  unsigned int uHighRemain = 0;
668  unsigned int uLowRemain = 0;
669  QWORD qwNextTBTT;
670 
671  HIDWORD(qwNextTBTT) = 0;
672  LODWORD(qwNextTBTT) = 0;
673  CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
674  uBeaconInterval = wBeaconInterval * 1024;
675  // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
676  uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
677  uLowRemain = (uLowNextTBTT) % uBeaconInterval;
678  // high dword (mod) bcn
679  uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
680  % uBeaconInterval;
681  uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
682  uLowRemain = uBeaconInterval - uLowRemain;
683 
684  // check if carry when add one beacon interval
685  if ((~uLowNextTBTT) < uLowRemain) {
686  HIDWORD(qwNextTBTT) ++ ;
687  }
688  LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
689 
690  // set HW beacon interval
691  VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
692  pDevice->wBeaconInterval = wBeaconInterval;
693  // Set NextTBTT
694  VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
695  VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
697 
698  return(true);
699 }
700 
701 
702 
703 /*
704  * Description: Card Stop Hardware Tx
705  *
706  * Parameters:
707  * In:
708  * pDeviceHandler - The adapter to be set
709  * ePktType - Packet type to stop
710  * Out:
711  * none
712  *
713  * Return Value: true if all data packet complete; otherwise false.
714  *
715  */
716 bool CARDbStopTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
717 {
718  PSDevice pDevice = (PSDevice) pDeviceHandler;
719 
720 
721  if (ePktType == PKT_TYPE_802_11_ALL) {
722  pDevice->bStopBeacon = true;
723  pDevice->bStopTx0Pkt = true;
724  pDevice->bStopDataPkt = true;
725  } else if (ePktType == PKT_TYPE_802_11_BCN) {
726  pDevice->bStopBeacon = true;
727  } else if (ePktType == PKT_TYPE_802_11_MNG) {
728  pDevice->bStopTx0Pkt = true;
729  } else if (ePktType == PKT_TYPE_802_11_DATA) {
730  pDevice->bStopDataPkt = true;
731  }
732 
733  if (pDevice->bStopBeacon == true) {
734  if (pDevice->bIsBeaconBufReadySet == true) {
736  pDevice->cbBeaconBufReadySetCnt ++;
737  return(false);
738  }
739  }
740  pDevice->bIsBeaconBufReadySet = false;
741  pDevice->cbBeaconBufReadySetCnt = 0;
743  }
744  // wait all TD0 complete
745  if (pDevice->bStopTx0Pkt == true) {
746  if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
747  return(false);
748  }
749  }
750  // wait all Data TD complete
751  if (pDevice->bStopDataPkt == true) {
752  if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
753  return(false);
754  }
755  }
756 
757  return(true);
758 }
759 
760 
761 /*
762  * Description: Card Start Hardware Tx
763  *
764  * Parameters:
765  * In:
766  * pDeviceHandler - The adapter to be set
767  * ePktType - Packet type to start
768  * Out:
769  * none
770  *
771  * Return Value: true if success; false if failed.
772  *
773  */
774 bool CARDbStartTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
775 {
776  PSDevice pDevice = (PSDevice) pDeviceHandler;
777 
778 
779  if (ePktType == PKT_TYPE_802_11_ALL) {
780  pDevice->bStopBeacon = false;
781  pDevice->bStopTx0Pkt = false;
782  pDevice->bStopDataPkt = false;
783  } else if (ePktType == PKT_TYPE_802_11_BCN) {
784  pDevice->bStopBeacon = false;
785  } else if (ePktType == PKT_TYPE_802_11_MNG) {
786  pDevice->bStopTx0Pkt = false;
787  } else if (ePktType == PKT_TYPE_802_11_DATA) {
788  pDevice->bStopDataPkt = false;
789  }
790 
791  if ((pDevice->bStopBeacon == false) &&
792  (pDevice->bBeaconBufReady == true) &&
793  (pDevice->eOPMode == OP_MODE_ADHOC)) {
795  }
796 
797  return(true);
798 }
799 
800 
801 
802 /*
803  * Description: Card Set BSSID value
804  *
805  * Parameters:
806  * In:
807  * pDeviceHandler - The adapter to be set
808  * pbyBSSID - pointer to BSSID field
809  * bAdhoc - flag to indicate IBSS
810  * Out:
811  * none
812  *
813  * Return Value: true if success; false if failed.
814  *
815  */
816 bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
817 {
818  PSDevice pDevice = (PSDevice) pDeviceHandler;
819 
820  MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
821  memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
822  if (eOPMode == OP_MODE_ADHOC) {
824  } else {
826  }
827  if (eOPMode == OP_MODE_AP) {
829  } else {
831  }
832  if (eOPMode == OP_MODE_UNKNOWN) {
834  pDevice->bBSSIDFilter = false;
835  pDevice->byRxMode &= ~RCR_BSSID;
836  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
837  } else {
838  if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
840  pDevice->bBSSIDFilter = true;
841  pDevice->byRxMode |= RCR_BSSID;
842  }
843  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode );
844  }
845  // Adopt BSS state in Adapter Device Object
846  pDevice->eOPMode = eOPMode;
847  return(true);
848 }
849 
850 
851 /*
852  * Description: Card indicate status
853  *
854  * Parameters:
855  * In:
856  * pDeviceHandler - The adapter to be set
857  * eStatus - Status
858  * Out:
859  * none
860  *
861  * Return Value: true if success; false if failed.
862  *
863  */
864 
865 
866 
867 
868 /*
869  * Description: Save Assoc info. contain in assoc. response frame
870  *
871  * Parameters:
872  * In:
873  * pDevice - The adapter to be set
874  * wCapabilityInfo - Capability information
875  * wStatus - Status code
876  * wAID - Assoc. ID
877  * uLen - Length of IEs
878  * pbyIEs - pointer to IEs
879  * Out:
880  * none
881  *
882  * Return Value: true if succeed; otherwise false
883  *
884  */
886  void *pDeviceHandler,
887  unsigned short wDataRate
888  )
889 {
890  PSDevice pDevice = (PSDevice) pDeviceHandler;
891 
892  pDevice->wCurrentRate = wDataRate;
893  return(true);
894 }
895 
896 /*+
897  *
898  * Routine Description:
899  * Consider to power down when no more packets to tx or rx.
900  *
901  * Parameters:
902  * In:
903  * pDevice - The adapter to be set
904  * Out:
905  * none
906  *
907  * Return Value: true if power down success; otherwise false
908  *
909 -*/
910 bool
912  void *pDeviceHandler
913  )
914 {
915  PSDevice pDevice = (PSDevice)pDeviceHandler;
916  unsigned int uIdx;
917 
918  // check if already in Doze mode
920  return true;
921 
922  // Froce PSEN on
924 
925  // check if all TD are empty,
926 
927  for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
928  if (pDevice->iTDUsed[uIdx] != 0)
929  return false;
930  }
931 
933  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Go to Doze ZZZZZZZZZZZZZZZ\n");
934  return true;
935 }
936 
937 /*
938  * Description: Turn off Radio power
939  *
940  * Parameters:
941  * In:
942  * pDevice - The adapter to be turned off
943  * Out:
944  * none
945  *
946  * Return Value: true if success; otherwise false
947  *
948  */
949 bool CARDbRadioPowerOff (void *pDeviceHandler)
950 {
951  PSDevice pDevice = (PSDevice) pDeviceHandler;
952  bool bResult = true;
953 
954  if (pDevice->bRadioOff == true)
955  return true;
956 
957 
958  switch (pDevice->byRFType) {
959 
960  case RF_RFMD2959:
963  break;
964 
965  case RF_AIROHA:
966  case RF_AL2230S:
967  case RF_AIROHA7230: //RobertYu:20050104
970  break;
971 
972  }
973 
975 
976  BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
977 
978  pDevice->bRadioOff = true;
979  //2007-0409-03,<Add> by chester
980 printk("chester power off\n");
981 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
982  return bResult;
983 }
984 
985 
986 /*
987  * Description: Turn on Radio power
988  *
989  * Parameters:
990  * In:
991  * pDevice - The adapter to be turned on
992  * Out:
993  * none
994  *
995  * Return Value: true if success; otherwise false
996  *
997  */
998 bool CARDbRadioPowerOn (void *pDeviceHandler)
999 {
1000  PSDevice pDevice = (PSDevice) pDeviceHandler;
1001  bool bResult = true;
1002 printk("chester power on\n");
1003  if (pDevice->bRadioControlOff == true){
1004 if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
1005 if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
1006  return false;}
1007 
1008  if (pDevice->bRadioOff == false)
1009  {
1010 printk("chester pbRadioOff\n");
1011 return true;}
1012 
1013  BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
1014 
1016 
1017  switch (pDevice->byRFType) {
1018 
1019  case RF_RFMD2959:
1022  break;
1023 
1024  case RF_AIROHA:
1025  case RF_AL2230S:
1026  case RF_AIROHA7230: //RobertYu:20050104
1028  SOFTPWRCTL_SWPE3));
1029  break;
1030 
1031  }
1032 
1033  pDevice->bRadioOff = false;
1034 // 2007-0409-03,<Add> by chester
1035 printk("chester power on\n");
1036 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
1037  return bResult;
1038 }
1039 
1040 
1041 
1042 bool CARDbRemoveKey (void *pDeviceHandler, unsigned char *pbyBSSID)
1043 {
1044  PSDevice pDevice = (PSDevice) pDeviceHandler;
1045 
1046  KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
1047  return (true);
1048 }
1049 
1050 
1051 /*
1052  *
1053  * Description:
1054  * Add BSSID in PMKID Candidate list.
1055  *
1056  * Parameters:
1057  * In:
1058  * hDeviceContext - device structure point
1059  * pbyBSSID - BSSID address for adding
1060  * wRSNCap - BSS's RSN capability
1061  * Out:
1062  * none
1063  *
1064  * Return Value: none.
1065  *
1066 -*/
1067 bool
1069  void *pDeviceHandler,
1070  unsigned char *pbyBSSID,
1071  bool bRSNCapExist,
1072  unsigned short wRSNCap
1073  )
1074 {
1075  PSDevice pDevice = (PSDevice) pDeviceHandler;
1076  PPMKID_CANDIDATE pCandidateList;
1077  unsigned int ii = 0;
1078 
1079  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1080 
1081  if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1082  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 3\n");
1083  memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1084  }
1085 
1086  for (ii = 0; ii < 6; ii++) {
1087  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02X ", *(pbyBSSID + ii));
1088  }
1090 
1091 
1092  // Update Old Candidate
1093  for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1094  pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1095  if ( !memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
1096  if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
1098  } else {
1099  pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1100  }
1101  return true;
1102  }
1103  }
1104 
1105  // New Candidate
1106  pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1107  if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
1109  } else {
1110  pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1111  }
1112  memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1113  pDevice->gsPMKIDCandidate.NumCandidates++;
1114  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1115  return true;
1116 }
1117 
1118 void *
1120  void *pDeviceHandler
1121  )
1122 {
1123  PSDevice pDevice = (PSDevice) pDeviceHandler;
1124 
1125  return (pDevice->abyCurrentNetAddr);
1126 }
1127 
1128 /*
1129  *
1130  * Description:
1131  * Start Spectrum Measure defined in 802.11h
1132  *
1133  * Parameters:
1134  * In:
1135  * hDeviceContext - device structure point
1136  * Out:
1137  * none
1138  *
1139  * Return Value: none.
1140  *
1141 -*/
1142 bool
1144  void *pDeviceHandler,
1145  void *pvMeasureEIDs,
1146  unsigned int uNumOfMeasureEIDs
1147  )
1148 {
1149  PSDevice pDevice = (PSDevice) pDeviceHandler;
1150  PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1151  QWORD qwCurrTSF;
1152  QWORD qwStartTSF;
1153  bool bExpired = true;
1154  unsigned short wDuration = 0;
1155 
1156  if ((pEID == NULL) ||
1157  (uNumOfMeasureEIDs == 0)) {
1158  return (true);
1159  }
1160  CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1161  if (pDevice->bMeasureInProgress == true) {
1162  pDevice->bMeasureInProgress = false;
1163  VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1164  MACvSelectPage1(pDevice->PortOffset);
1165  VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1166  VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1167  // clear measure control
1169  MACvSelectPage0(pDevice->PortOffset);
1170  set_channel(pDevice, pDevice->byOrgChannel);
1171  MACvSelectPage1(pDevice->PortOffset);
1173  MACvSelectPage0(pDevice->PortOffset);
1174  }
1175  pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1176 
1177  do {
1178  pDevice->pCurrMeasureEID = pEID;
1179  pEID++;
1180  pDevice->uNumOfMeasureEIDs--;
1181 
1182  if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1183  HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1184  LODWORD(qwStartTSF) = LODWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1185  wDuration = *((unsigned short *) (pDevice->pCurrMeasureEID->sReq.abyDuration));
1186  wDuration += 1; // 1 TU for channel switching
1187 
1188  if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1189  // start immediately by setting start TSF == current TSF + 2 TU
1190  LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1191  HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
1192  if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
1193  HIDWORD(qwStartTSF)++;
1194  }
1195  bExpired = false;
1196  break;
1197  } else {
1198  // start at setting start TSF - 1TU(for channel switching)
1199  if (LODWORD(qwStartTSF) < 1024) {
1200  HIDWORD(qwStartTSF)--;
1201  }
1202  LODWORD(qwStartTSF) -= 1024;
1203  }
1204 
1205  if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1206  ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1207  (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1208  ) {
1209  bExpired = false;
1210  break;
1211  }
1212  VNTWIFIbMeasureReport( pDevice->pMgmt,
1213  false,
1214  pDevice->pCurrMeasureEID,
1216  pDevice->byBasicMap,
1217  pDevice->byCCAFraction,
1218  pDevice->abyRPIs
1219  );
1220  } else {
1221  // hardware do not support measure
1222  VNTWIFIbMeasureReport( pDevice->pMgmt,
1223  false,
1224  pDevice->pCurrMeasureEID,
1226  pDevice->byBasicMap,
1227  pDevice->byCCAFraction,
1228  pDevice->abyRPIs
1229  );
1230  }
1231  } while (pDevice->uNumOfMeasureEIDs != 0);
1232 
1233  if (bExpired == false) {
1234  MACvSelectPage1(pDevice->PortOffset);
1235  VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1236  VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1237  VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1239  MACvSelectPage0(pDevice->PortOffset);
1240  } else {
1241  // all measure start time expired we should complete action
1242  VNTWIFIbMeasureReport( pDevice->pMgmt,
1243  true,
1244  NULL,
1245  0,
1246  pDevice->byBasicMap,
1247  pDevice->byCCAFraction,
1248  pDevice->abyRPIs
1249  );
1250  }
1251  return (true);
1252 }
1253 
1254 
1255 /*
1256  *
1257  * Description:
1258  * Do Channel Switch defined in 802.11h
1259  *
1260  * Parameters:
1261  * In:
1262  * hDeviceContext - device structure point
1263  * Out:
1264  * none
1265  *
1266  * Return Value: none.
1267  *
1268 -*/
1269 bool
1271  void *pDeviceHandler,
1272  unsigned char byMode,
1273  unsigned char byNewChannel,
1274  unsigned char byCount
1275  )
1276 {
1277  PSDevice pDevice = (PSDevice) pDeviceHandler;
1278  bool bResult = true;
1279 
1280  if (byCount == 0) {
1281  bResult = set_channel(pDevice, byNewChannel);
1282  VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1283  MACvSelectPage1(pDevice->PortOffset);
1285  MACvSelectPage0(pDevice->PortOffset);
1286  return(bResult);
1287  }
1288  pDevice->byChannelSwitchCount = byCount;
1289  pDevice->byNewChannel = byNewChannel;
1290  pDevice->bChannelSwitch = true;
1291  if (byMode == 1) {
1292  bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1293  }
1294  return (bResult);
1295 }
1296 
1297 
1298 /*
1299  *
1300  * Description:
1301  * Handle Quiet EID defined in 802.11h
1302  *
1303  * Parameters:
1304  * In:
1305  * hDeviceContext - device structure point
1306  * Out:
1307  * none
1308  *
1309  * Return Value: none.
1310  *
1311 -*/
1312 bool
1314  void *pDeviceHandler,
1315  bool bResetQuiet,
1316  unsigned char byQuietCount,
1317  unsigned char byQuietPeriod,
1318  unsigned short wQuietDuration,
1319  unsigned short wQuietOffset
1320  )
1321 {
1322  PSDevice pDevice = (PSDevice) pDeviceHandler;
1323  unsigned int ii = 0;
1324 
1325  if (bResetQuiet == true) {
1327  for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1328  pDevice->sQuiet[ii].bEnable = false;
1329  }
1330  pDevice->uQuietEnqueue = 0;
1331  pDevice->bEnableFirstQuiet = false;
1332  pDevice->bQuietEnable = false;
1333  pDevice->byQuietStartCount = byQuietCount;
1334  }
1335  if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1336  pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1337  pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1338  pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1339  pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1340  pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1341  pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1342  pDevice->uQuietEnqueue++;
1343  pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1344  if (pDevice->byQuietStartCount < byQuietCount) {
1345  pDevice->byQuietStartCount = byQuietCount;
1346  }
1347  } else {
1348  // we can not handle Quiet EID more
1349  }
1350  return (true);
1351 }
1352 
1353 
1354 /*
1355  *
1356  * Description:
1357  * Do Quiet, It will be called by either ISR(after start)
1358  * or VNTWIFI(before start) so we do not need a SPINLOCK
1359  *
1360  * Parameters:
1361  * In:
1362  * hDeviceContext - device structure point
1363  * Out:
1364  * none
1365  *
1366  * Return Value: none.
1367  *
1368 -*/
1369 bool
1371  void *pDeviceHandler
1372  )
1373 {
1374  PSDevice pDevice = (PSDevice) pDeviceHandler;
1375  unsigned int ii = 0;
1376  unsigned long dwStartTime = 0xFFFFFFFF;
1377  unsigned int uCurrentQuietIndex = 0;
1378  unsigned long dwNextTime = 0;
1379  unsigned long dwGap = 0;
1380  unsigned long dwDuration = 0;
1381 
1382  for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1383  if ((pDevice->sQuiet[ii].bEnable == true) &&
1384  (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1385  dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1386  uCurrentQuietIndex = ii;
1387  }
1388  }
1389  if (dwStartTime == 0xFFFFFFFF) {
1390  // no more quiet
1391  pDevice->bQuietEnable = false;
1393  } else {
1394  if (pDevice->bQuietEnable == false) {
1395  // first quiet
1396  pDevice->byQuietStartCount--;
1397  dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1398  dwNextTime %= pDevice->wBeaconInterval;
1399  MACvSelectPage1(pDevice->PortOffset);
1400  VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1401  VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1402  if (pDevice->byQuietStartCount == 0) {
1403  pDevice->bEnableFirstQuiet = false;
1405  } else {
1406  pDevice->bEnableFirstQuiet = true;
1407  }
1408  MACvSelectPage0(pDevice->PortOffset);
1409  } else {
1410  if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1411  // overlap with previous Quiet
1412  dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1413  if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1414  // return false to indicate next quiet expired, should call this function again
1415  return (false);
1416  }
1417  dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1418  dwGap = 0;
1419  } else {
1420  dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1421  dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1422  }
1423  // set GAP and Next duration
1424  MACvSelectPage1(pDevice->PortOffset);
1425  VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1426  VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1428  MACvSelectPage0(pDevice->PortOffset);
1429  }
1430  pDevice->bQuietEnable = true;
1431  pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1432  pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1433  if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1434  // not period disable current quiet element
1435  pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1436  } else {
1437  // set next period start time
1438  dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1439  dwNextTime *= pDevice->wBeaconInterval;
1440  pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1441  }
1442  if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1443  // decreament all time to avoid wrap around
1444  for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1445  if (pDevice->sQuiet[ii].bEnable == true) {
1446  pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1447  }
1448  }
1449  pDevice->dwCurrentQuietEndTime -= 0x80000000;
1450  }
1451  }
1452  return (true);
1453 }
1454 
1455 /*
1456  *
1457  * Description:
1458  * Set Local Power Constraint
1459  *
1460  * Parameters:
1461  * In:
1462  * hDeviceContext - device structure point
1463  * Out:
1464  * none
1465  *
1466  * Return Value: none.
1467  *
1468 -*/
1469 void
1471  void *pDeviceHandler,
1472  unsigned char byChannel,
1473  char byPower
1474  )
1475 {
1476  PSDevice pDevice = (PSDevice) pDeviceHandler;
1477 
1478  if (byChannel > CB_MAX_CHANNEL_24G) {
1479  if (pDevice->bCountryInfo5G == true) {
1480  pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1481  }
1482  } else {
1483  if (pDevice->bCountryInfo24G == true) {
1484  pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1485  }
1486  }
1487 }
1488 
1489 
1490 /*
1491  *
1492  * Description:
1493  * Set Local Power Constraint
1494  *
1495  * Parameters:
1496  * In:
1497  * hDeviceContext - device structure point
1498  * Out:
1499  * none
1500  *
1501  * Return Value: none.
1502  *
1503 -*/
1504 void
1506  void *pDeviceHandler,
1507  unsigned char *pbyMinPower,
1508  unsigned char *pbyMaxPower
1509  )
1510 {
1511  PSDevice pDevice = (PSDevice) pDeviceHandler;
1512  unsigned char byDec = 0;
1513 
1514  *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1515  byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1516  if (pDevice->byRFType == RF_UW2452) {
1517  byDec *= 3;
1518  byDec >>= 1;
1519  } else {
1520  byDec <<= 1;
1521  }
1522  *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1523 }
1524 
1525 /*
1526  *
1527  * Description:
1528  * Get Current Tx Power
1529  *
1530  * Parameters:
1531  * In:
1532  * hDeviceContext - device structure point
1533  * Out:
1534  * none
1535  *
1536  * Return Value: none.
1537  *
1538  */
1539 char
1541  void *pDeviceHandler
1542  )
1543 {
1544  PSDevice pDevice = (PSDevice) pDeviceHandler;
1545 
1546  return (pDevice->byCurPwrdBm);
1547 }
1548 
1549 //xxx
1550 void
1552  void *pDeviceHandler
1553  )
1554 {
1555  PSDevice pDevice = (PSDevice) pDeviceHandler;
1556  unsigned int uu;
1557  PSTxDesc pCurrTD;
1558 
1559  // initialize TD index
1560  pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1561  pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1562 
1563  for (uu = 0; uu < TYPE_MAXTD; uu ++)
1564  pDevice->iTDUsed[uu] = 0;
1565 
1566  for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1567  pCurrTD = &(pDevice->apTD0Rings[uu]);
1568  pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1569  // init all Tx Packet pointer to NULL
1570  }
1571  for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1572  pCurrTD = &(pDevice->apTD1Rings[uu]);
1573  pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1574  // init all Tx Packet pointer to NULL
1575  }
1576 
1577  // set MAC TD pointer
1579  (pDevice->td0_pool_dma));
1580 
1582  (pDevice->td1_pool_dma));
1583 
1584  // set MAC Beacon TX pointer
1586  (pDevice->tx_beacon_dma));
1587 
1588 }
1589 
1590 
1591 
1592 /*+
1593  *
1594  * Description:
1595  * Reset Rx
1596  *
1597  * Parameters:
1598  * In:
1599  * pDevice - Pointer to the adapter
1600  * Out:
1601  * none
1602  *
1603  * Return Value: none
1604  *
1605 -*/
1606 void
1608  void *pDeviceHandler
1609  )
1610 {
1611  PSDevice pDevice = (PSDevice) pDeviceHandler;
1612  unsigned int uu;
1613  PSRxDesc pDesc;
1614 
1615 
1616 
1617  // initialize RD index
1618  pDevice->pCurrRD[0]=&(pDevice->aRD0Ring[0]);
1619  pDevice->pCurrRD[1]=&(pDevice->aRD1Ring[0]);
1620 
1621  // init state, all RD is chip's
1622  for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1623  pDesc =&(pDevice->aRD0Ring[uu]);
1624  pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1625  pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
1626  pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1627  }
1628 
1629  // init state, all RD is chip's
1630  for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1631  pDesc =&(pDevice->aRD1Ring[uu]);
1632  pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1633  pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
1634  pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1635  }
1636 
1637  pDevice->cbDFCB = CB_MAX_RX_FRAG;
1638  pDevice->cbFreeDFCB = pDevice->cbDFCB;
1639 
1640  // set perPkt mode
1641  MACvRx0PerPktMode(pDevice->PortOffset);
1642  MACvRx1PerPktMode(pDevice->PortOffset);
1643  // set MAC RD pointer
1645  pDevice->rd0_pool_dma);
1646 
1648  pDevice->rd1_pool_dma);
1649 }
1650 
1651 
1652 
1653 
1654 /*
1655  * Description: Get response Control frame rate in CCK mode
1656  *
1657  * Parameters:
1658  * In:
1659  * pDevice - The adapter to be set
1660  * wRateIdx - Receiving data rate
1661  * Out:
1662  * none
1663  *
1664  * Return Value: response Control frame rate
1665  *
1666  */
1667 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
1668 {
1669  PSDevice pDevice = (PSDevice) pDeviceHandler;
1670  unsigned int ui = (unsigned int) wRateIdx;
1671 
1672  while (ui > RATE_1M) {
1673  if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1674  return (unsigned short)ui;
1675  }
1676  ui --;
1677  }
1678  return (unsigned short)RATE_1M;
1679 }
1680 
1681 /*
1682  * Description: Get response Control frame rate in OFDM mode
1683  *
1684  * Parameters:
1685  * In:
1686  * pDevice - The adapter to be set
1687  * wRateIdx - Receiving data rate
1688  * Out:
1689  * none
1690  *
1691  * Return Value: response Control frame rate
1692  *
1693  */
1694 unsigned short CARDwGetOFDMControlRate (void *pDeviceHandler, unsigned short wRateIdx)
1695 {
1696  PSDevice pDevice = (PSDevice) pDeviceHandler;
1697  unsigned int ui = (unsigned int) wRateIdx;
1698 
1699  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
1700 
1701  if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1702  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1703  if (wRateIdx > RATE_24M)
1704  wRateIdx = RATE_24M;
1705  return wRateIdx;
1706  }
1707  while (ui > RATE_11M) {
1708  if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1709  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate : %d\n", ui);
1710  return (unsigned short)ui;
1711  }
1712  ui --;
1713  }
1714  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate: 6M\n");
1715  return (unsigned short)RATE_24M;
1716 }
1717 
1718 
1719 /*
1720  * Description: Set RSPINF
1721  *
1722  * Parameters:
1723  * In:
1724  * pDevice - The adapter to be set
1725  * Out:
1726  * none
1727  *
1728  * Return Value: None.
1729  *
1730  */
1731 void CARDvSetRSPINF (void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
1732 {
1733  PSDevice pDevice = (PSDevice) pDeviceHandler;
1734  unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1735  unsigned short wLen = 0x0000;
1736  unsigned char byTxRate, byRsvTime; //For OFDM
1737 
1738  //Set to Page1
1739  MACvSelectPage1(pDevice->PortOffset);
1740 
1741  //RSPINF_b_1
1742  BBvCalculateParameter(pDevice,
1743  14,
1744  CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1745  PK_TYPE_11B,
1746  &wLen,
1747  &byServ,
1748  &bySignal
1749  );
1750 
1751  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1753  BBvCalculateParameter(pDevice,
1754  14,
1755  CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1756  PK_TYPE_11B,
1757  &wLen,
1758  &byServ,
1759  &bySignal
1760  );
1761 
1762  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1763  //RSPINF_b_5
1764  BBvCalculateParameter(pDevice,
1765  14,
1766  CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1767  PK_TYPE_11B,
1768  &wLen,
1769  &byServ,
1770  &bySignal
1771  );
1772 
1773  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1774  //RSPINF_b_11
1775  BBvCalculateParameter(pDevice,
1776  14,
1777  CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1778  PK_TYPE_11B,
1779  &wLen,
1780  &byServ,
1781  &bySignal
1782  );
1783 
1784  VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
1785  //RSPINF_a_6
1786  s_vCalculateOFDMRParameter(RATE_6M,
1787  ePHYType,
1788  &byTxRate,
1789  &byRsvTime);
1790  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
1791  //RSPINF_a_9
1792  s_vCalculateOFDMRParameter(RATE_9M,
1793  ePHYType,
1794  &byTxRate,
1795  &byRsvTime);
1796  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
1797  //RSPINF_a_12
1798  s_vCalculateOFDMRParameter(RATE_12M,
1799  ePHYType,
1800  &byTxRate,
1801  &byRsvTime);
1802  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
1803  //RSPINF_a_18
1804  s_vCalculateOFDMRParameter(RATE_18M,
1805  ePHYType,
1806  &byTxRate,
1807  &byRsvTime);
1808  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
1809  //RSPINF_a_24
1810  s_vCalculateOFDMRParameter(RATE_24M,
1811  ePHYType,
1812  &byTxRate,
1813  &byRsvTime);
1814  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
1815  //RSPINF_a_36
1816  s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1817  ePHYType,
1818  &byTxRate,
1819  &byRsvTime);
1820  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
1821  //RSPINF_a_48
1822  s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1823  ePHYType,
1824  &byTxRate,
1825  &byRsvTime);
1826  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
1827  //RSPINF_a_54
1828  s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1829  ePHYType,
1830  &byTxRate,
1831  &byRsvTime);
1832  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
1833 
1834  //RSPINF_a_72
1835  s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1836  ePHYType,
1837  &byTxRate,
1838  &byRsvTime);
1839  VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
1840  //Set to Page0
1841  MACvSelectPage0(pDevice->PortOffset);
1842 }
1843 
1844 /*
1845  * Description: Update IFS
1846  *
1847  * Parameters:
1848  * In:
1849  * pDevice - The adapter to be set
1850  * Out:
1851  * none
1852  *
1853  * Return Value: None.
1854  *
1855  */
1856 void vUpdateIFS (void *pDeviceHandler)
1857 {
1858  //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1859  PSDevice pDevice = (PSDevice) pDeviceHandler;
1860 
1861  unsigned char byMaxMin = 0;
1862  if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
1863  pDevice->uSlot = C_SLOT_SHORT;
1864  pDevice->uSIFS = C_SIFS_A;
1865  pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1866  pDevice->uCwMin = C_CWMIN_A;
1867  byMaxMin = 4;
1868  }
1869  else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
1870  pDevice->uSlot = C_SLOT_LONG;
1871  pDevice->uSIFS = C_SIFS_BG;
1872  pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1873  pDevice->uCwMin = C_CWMIN_B;
1874  byMaxMin = 5;
1875  }
1876  else { // PK_TYPE_11GA & PK_TYPE_11GB
1877  pDevice->uSIFS = C_SIFS_BG;
1878  if (pDevice->bShortSlotTime) {
1879  pDevice->uSlot = C_SLOT_SHORT;
1880  } else {
1881  pDevice->uSlot = C_SLOT_LONG;
1882  }
1883  pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1884  if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1885  pDevice->uCwMin = C_CWMIN_A;
1886  byMaxMin = 4;
1887  }
1888  else {
1889  pDevice->uCwMin = C_CWMIN_B;
1890  byMaxMin = 5;
1891  }
1892  }
1893 
1894  pDevice->uCwMax = C_CWMAX;
1895  pDevice->uEIFS = C_EIFS;
1896  if (pDevice->byRFType == RF_RFMD2959) {
1897  // bcs TX_PE will reserve 3 us
1898  VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1899  VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1900  } else {
1901  VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1902  VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1903  }
1904  VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1905  VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1906  byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1907  VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1908 }
1909 
1910 void CARDvUpdateBasicTopRate (void *pDeviceHandler)
1911 {
1912  PSDevice pDevice = (PSDevice) pDeviceHandler;
1913  unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1914  unsigned char ii;
1915 
1916  //Determines the highest basic rate.
1917  for (ii = RATE_54M; ii >= RATE_6M; ii --) {
1918  if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
1919  byTopOFDM = ii;
1920  break;
1921  }
1922  }
1923  pDevice->byTopOFDMBasicRate = byTopOFDM;
1924 
1925  for (ii = RATE_11M;; ii --) {
1926  if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
1927  byTopCCK = ii;
1928  break;
1929  }
1930  if (ii == RATE_1M)
1931  break;
1932  }
1933  pDevice->byTopCCKBasicRate = byTopCCK;
1934 }
1935 
1936 
1937 /*
1938  * Description: Set NIC Tx Basic Rate
1939  *
1940  * Parameters:
1941  * In:
1942  * pDevice - The adapter to be set
1943  * wBasicRate - Basic Rate to be set
1944  * Out:
1945  * none
1946  *
1947  * Return Value: true if succeeded; false if failed.
1948  *
1949  */
1950 bool CARDbAddBasicRate (void *pDeviceHandler, unsigned short wRateIdx)
1951 {
1952  PSDevice pDevice = (PSDevice) pDeviceHandler;
1953  unsigned short wRate = (unsigned short)(1<<wRateIdx);
1954 
1955  pDevice->wBasicRate |= wRate;
1956 
1957  //Determines the highest basic rate.
1958  CARDvUpdateBasicTopRate((void *)pDevice);
1959 
1960  return(true);
1961 }
1962 
1963 bool CARDbIsOFDMinBasicRate (void *pDeviceHandler)
1964 {
1965  PSDevice pDevice = (PSDevice) pDeviceHandler;
1966  int ii;
1967 
1968  for (ii = RATE_54M; ii >= RATE_6M; ii --) {
1969  if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii)))
1970  return true;
1971  }
1972  return false;
1973 }
1974 
1975 unsigned char CARDbyGetPktType (void *pDeviceHandler)
1976 {
1977  PSDevice pDevice = (PSDevice) pDeviceHandler;
1978 
1979  if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
1980  return (unsigned char)pDevice->byBBType;
1981  }
1982  else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
1983  return PK_TYPE_11GA;
1984  }
1985  else {
1986  return PK_TYPE_11GB;
1987  }
1988 }
1989 
1990 /*
1991  * Description: Set NIC Loopback mode
1992  *
1993  * Parameters:
1994  * In:
1995  * pDevice - The adapter to be set
1996  * wLoopbackMode - Loopback mode to be set
1997  * Out:
1998  * none
1999  *
2000  * Return Value: none
2001  *
2002  */
2003 void CARDvSetLoopbackMode (unsigned long dwIoBase, unsigned short wLoopbackMode)
2004 {
2005  switch(wLoopbackMode) {
2006  case CARD_LB_NONE:
2007  case CARD_LB_MAC:
2008  case CARD_LB_PHY:
2009  break;
2010  default:
2011  ASSERT(false);
2012  break;
2013  }
2014  // set MAC loopback
2015  MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
2016  // set Baseband loopback
2017 }
2018 
2019 
2020 /*
2021  * Description: Software Reset NIC
2022  *
2023  * Parameters:
2024  * In:
2025  * pDevice - The adapter to be reset
2026  * Out:
2027  * none
2028  *
2029  * Return Value: none
2030  *
2031  */
2032 bool CARDbSoftwareReset (void *pDeviceHandler)
2033 {
2034  PSDevice pDevice = (PSDevice) pDeviceHandler;
2035 
2036  // reset MAC
2037  if (!MACbSafeSoftwareReset(pDevice->PortOffset))
2038  return false;
2039 
2040  return true;
2041 }
2042 
2043 
2044 /*
2045  * Description: Calculate TSF offset of two TSF input
2046  * Get TSF Offset from RxBCN's TSF and local TSF
2047  *
2048  * Parameters:
2049  * In:
2050  * pDevice - The adapter to be sync.
2051  * qwTSF1 - Rx BCN's TSF
2052  * qwTSF2 - Local TSF
2053  * Out:
2054  * none
2055  *
2056  * Return Value: TSF Offset value
2057  *
2058  */
2059 QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
2060 {
2061  QWORD qwTSFOffset;
2062  unsigned short wRxBcnTSFOffst= 0;
2063 
2064  HIDWORD(qwTSFOffset) = 0;
2065  LODWORD(qwTSFOffset) = 0;
2066  wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
2067  (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
2068  if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
2069  (qwTSF2).u.dwHighDword++;
2070  }
2071  LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
2072  if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
2073  // if borrow needed
2074  HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
2075  }
2076  else {
2077  HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
2078  };
2079  return (qwTSFOffset);
2080 }
2081 
2082 
2083 /*
2084  * Description: Read NIC TSF counter
2085  * Get local TSF counter
2086  *
2087  * Parameters:
2088  * In:
2089  * pDevice - The adapter to be read
2090  * Out:
2091  * qwCurrTSF - Current TSF counter
2092  *
2093  * Return Value: true if success; otherwise false
2094  *
2095  */
2096 bool CARDbGetCurrentTSF (unsigned long dwIoBase, PQWORD pqwCurrTSF)
2097 {
2098  unsigned short ww;
2099  unsigned char byData;
2100 
2102  for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
2103  VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
2104  if ( !(byData & TFTCTL_TSFCNTRRD))
2105  break;
2106  }
2107  if (ww == W_MAX_TIMEOUT)
2108  return(false);
2109  VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
2110  VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
2111 
2112  return(true);
2113 }
2114 
2115 
2116 /*
2117  * Description: Read NIC TSF counter
2118  * Get NEXTTBTT from adjusted TSF and Beacon Interval
2119  *
2120  * Parameters:
2121  * In:
2122  * qwTSF - Current TSF counter
2123  * wbeaconInterval - Beacon Interval
2124  * Out:
2125  * qwCurrTSF - Current TSF counter
2126  *
2127  * Return Value: TSF value of next Beacon
2128  *
2129  */
2131 {
2132 
2133  unsigned int uLowNextTBTT;
2134  unsigned int uHighRemain, uLowRemain;
2135  unsigned int uBeaconInterval;
2136 
2137  uBeaconInterval = wBeaconInterval * 1024;
2138  // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2139  uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
2140  // low dword (mod) bcn
2141  uLowRemain = (uLowNextTBTT) % uBeaconInterval;
2142 // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
2143 // % uBeaconInterval;
2144  // high dword (mod) bcn
2145  uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
2146  % uBeaconInterval;
2147  uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2148  uLowRemain = uBeaconInterval - uLowRemain;
2149 
2150  // check if carry when add one beacon interval
2151  if ((~uLowNextTBTT) < uLowRemain)
2152  HIDWORD(qwTSF) ++ ;
2153 
2154  LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
2155 
2156  return (qwTSF);
2157 }
2158 
2159 
2160 /*
2161  * Description: Set NIC TSF counter for first Beacon time
2162  * Get NEXTTBTT from adjusted TSF and Beacon Interval
2163  *
2164  * Parameters:
2165  * In:
2166  * dwIoBase - IO Base
2167  * wBeaconInterval - Beacon Interval
2168  * Out:
2169  * none
2170  *
2171  * Return Value: none
2172  *
2173  */
2174 void CARDvSetFirstNextTBTT (unsigned long dwIoBase, unsigned short wBeaconInterval)
2175 {
2176 
2177  QWORD qwNextTBTT;
2178 
2179  HIDWORD(qwNextTBTT) = 0;
2180  LODWORD(qwNextTBTT) = 0;
2181  CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
2182  qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2183  // Set NextTBTT
2184  VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
2185  VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
2187  //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
2188  return;
2189 }
2190 
2191 
2192 /*
2193  * Description: Sync NIC TSF counter for Beacon time
2194  * Get NEXTTBTT and write to HW
2195  *
2196  * Parameters:
2197  * In:
2198  * pDevice - The adapter to be set
2199  * qwTSF - Current TSF counter
2200  * wBeaconInterval - Beacon Interval
2201  * Out:
2202  * none
2203  *
2204  * Return Value: none
2205  *
2206  */
2207 void CARDvUpdateNextTBTT (unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
2208 {
2209 
2210  qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2211  // Set NextTBTT
2212  VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
2213  VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
2215  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",
2216  (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
2217 
2218  return;
2219 }
2220 
2221 
2222 
2223 
2224 
2225 
2226