blob: fbf18e23e78ecb3230cbf45787f3bf91bcc6610b [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
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
Justin P. Mattock7664ec82012-08-20 08:43:15 -070031 * CARDqGetTSFOffset - Calculate TSFOffset
Forest Bond5449c682009-04-25 10:30:44 -040032 * CARDbGetCurrentTSF - Read Current NIC TSF counter
Justin P. Mattock7664ec82012-08-20 08:43:15 -070033 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
Forest Bond5449c682009-04-25 10:30:44 -040034 * 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
Forest Bond5449c682009-04-25 10:30:44 -040048#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040049#include "card.h"
Forest Bond5449c682009-04-25 10:30:44 -040050#include "baseband.h"
Forest Bond5449c682009-04-25 10:30:44 -040051#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040052#include "desc.h"
Forest Bond5449c682009-04-25 10:30:44 -040053#include "rf.h"
Forest Bond5449c682009-04-25 10:30:44 -040054#include "vntwifi.h"
Forest Bond5449c682009-04-25 10:30:44 -040055#include "power.h"
Forest Bond5449c682009-04-25 10:30:44 -040056#include "key.h"
Forest Bond5449c682009-04-25 10:30:44 -040057#include "rc4.h"
Forest Bond5449c682009-04-25 10:30:44 -040058#include "country.h"
Charles Clément79566eb2010-06-21 10:39:51 -070059#include "channel.h"
Forest Bond5449c682009-04-25 10:30:44 -040060
61/*--------------------- Static Definitions -------------------------*/
62
63//static int msglevel =MSG_LEVEL_DEBUG;
Joe Perchesd4945f02013-03-18 10:44:40 -070064static int msglevel = MSG_LEVEL_INFO;
Forest Bond5449c682009-04-25 10:30:44 -040065
66#define C_SIFS_A 16 // micro sec.
67#define C_SIFS_BG 10
68
69#define C_EIFS 80 // micro sec.
70
Forest Bond5449c682009-04-25 10:30:44 -040071#define C_SLOT_SHORT 9 // micro sec.
72#define C_SLOT_LONG 20
73
74#define C_CWMIN_A 15 // slot time
75#define C_CWMIN_B 31
76
77#define C_CWMAX 1023 // slot time
78
Forest Bond5449c682009-04-25 10:30:44 -040079#define WAIT_BEACON_TX_DOWN_TMO 3 // Times
80
Joe Perchesd4945f02013-03-18 10:44:40 -070081//1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
Charles Clément3fc9b582010-06-24 11:02:27 -070082static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
Joe Perchesd4945f02013-03-18 10:44:40 -070083//6M, 9M, 12M, 48M
Charles Clément3fc9b582010-06-24 11:02:27 -070084static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
Joe Perchesd4945f02013-03-18 10:44:40 -070085//6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
Charles Clément3fc9b582010-06-24 11:02:27 -070086static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
Joe Perchesd4945f02013-03-18 10:44:40 -070087//1M, 2M, 5M, 11M,
Charles Clément3fc9b582010-06-24 11:02:27 -070088static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
Forest Bond5449c682009-04-25 10:30:44 -040089
Forest Bond5449c682009-04-25 10:30:44 -040090/*--------------------- Static Variables --------------------------*/
91
Charles Clément2986db52010-06-24 11:02:26 -070092const unsigned short cwRXBCNTSFOff[MAX_RATE] =
Forest Bond5449c682009-04-25 10:30:44 -040093{17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
94
Forest Bond5449c682009-04-25 10:30:44 -040095/*--------------------- Static Functions --------------------------*/
96
97static
Charles Clément6b35b7b2010-05-07 12:30:19 -070098void
Justin P. Mattock7664ec82012-08-20 08:43:15 -070099s_vCalculateOFDMRParameter(
Joe Perchesd4945f02013-03-18 10:44:40 -0700100 unsigned char byRate,
101 CARD_PHY_TYPE ePHYType,
102 unsigned char *pbyTxRate,
103 unsigned char *pbyRsvTime
104);
Forest Bond5449c682009-04-25 10:30:44 -0400105
Forest Bond5449c682009-04-25 10:30:44 -0400106/*--------------------- Export Functions --------------------------*/
107
Forest Bond5449c682009-04-25 10:30:44 -0400108/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -0700109 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond5449c682009-04-25 10:30:44 -0400110 *
111 * Parameters:
112 * In:
113 * wRate - Tx Rate
114 * byPktType - Tx Packet type
115 * Out:
116 * pbyTxRate - pointer to RSPINF TxRate field
117 * pbyRsvTime - pointer to RSPINF RsvTime field
118 *
119 * Return Value: none
120 *
121 */
122static
Charles Clément6b35b7b2010-05-07 12:30:19 -0700123void
Joe Perchesd4945f02013-03-18 10:44:40 -0700124s_vCalculateOFDMRParameter(
125 unsigned char byRate,
126 CARD_PHY_TYPE ePHYType,
127 unsigned char *pbyTxRate,
128 unsigned char *pbyRsvTime
129)
Forest Bond5449c682009-04-25 10:30:44 -0400130{
Joe Perchesd4945f02013-03-18 10:44:40 -0700131 switch (byRate) {
132 case RATE_6M:
133 if (ePHYType == PHY_TYPE_11A) {//5GHZ
134 *pbyTxRate = 0x9B;
135 *pbyRsvTime = 44;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700136 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700137 *pbyTxRate = 0x8B;
138 *pbyRsvTime = 50;
139 }
140 break;
Forest Bond5449c682009-04-25 10:30:44 -0400141
Joe Perchesd4945f02013-03-18 10:44:40 -0700142 case RATE_9M:
143 if (ePHYType == PHY_TYPE_11A) {//5GHZ
144 *pbyTxRate = 0x9F;
145 *pbyRsvTime = 36;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700146 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700147 *pbyTxRate = 0x8F;
148 *pbyRsvTime = 42;
149 }
150 break;
Forest Bond5449c682009-04-25 10:30:44 -0400151
Joe Perchesd4945f02013-03-18 10:44:40 -0700152 case RATE_12M:
153 if (ePHYType == PHY_TYPE_11A) {//5GHZ
154 *pbyTxRate = 0x9A;
155 *pbyRsvTime = 32;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700156 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700157 *pbyTxRate = 0x8A;
158 *pbyRsvTime = 38;
159 }
160 break;
Forest Bond5449c682009-04-25 10:30:44 -0400161
Joe Perchesd4945f02013-03-18 10:44:40 -0700162 case RATE_18M:
163 if (ePHYType == PHY_TYPE_11A) {//5GHZ
164 *pbyTxRate = 0x9E;
165 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700166 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700167 *pbyTxRate = 0x8E;
168 *pbyRsvTime = 34;
169 }
170 break;
Forest Bond5449c682009-04-25 10:30:44 -0400171
Joe Perchesd4945f02013-03-18 10:44:40 -0700172 case RATE_36M:
173 if (ePHYType == PHY_TYPE_11A) {//5GHZ
174 *pbyTxRate = 0x9D;
175 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700176 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700177 *pbyTxRate = 0x8D;
178 *pbyRsvTime = 30;
179 }
180 break;
Forest Bond5449c682009-04-25 10:30:44 -0400181
Joe Perchesd4945f02013-03-18 10:44:40 -0700182 case RATE_48M:
183 if (ePHYType == PHY_TYPE_11A) {//5GHZ
184 *pbyTxRate = 0x98;
185 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700186 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700187 *pbyTxRate = 0x88;
188 *pbyRsvTime = 30;
189 }
190 break;
Forest Bond5449c682009-04-25 10:30:44 -0400191
Joe Perchesd4945f02013-03-18 10:44:40 -0700192 case RATE_54M:
193 if (ePHYType == PHY_TYPE_11A) {//5GHZ
194 *pbyTxRate = 0x9C;
195 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700196 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700197 *pbyTxRate = 0x8C;
198 *pbyRsvTime = 30;
199 }
200 break;
Forest Bond5449c682009-04-25 10:30:44 -0400201
Joe Perchesd4945f02013-03-18 10:44:40 -0700202 case RATE_24M:
203 default:
204 if (ePHYType == PHY_TYPE_11A) {//5GHZ
205 *pbyTxRate = 0x99;
206 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700207 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700208 *pbyTxRate = 0x89;
209 *pbyRsvTime = 34;
210 }
211 break;
212 }
Forest Bond5449c682009-04-25 10:30:44 -0400213}
214
Forest Bond5449c682009-04-25 10:30:44 -0400215/*
216 * Description: Set RSPINF
217 *
218 * Parameters:
219 * In:
220 * pDevice - The adapter to be set
221 * Out:
222 * none
223 *
224 * Return Value: None.
225 *
226 */
227static
Charles Clément6b35b7b2010-05-07 12:30:19 -0700228void
Joe Perchesd4945f02013-03-18 10:44:40 -0700229s_vSetRSPINF(PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
Forest Bond5449c682009-04-25 10:30:44 -0400230{
Joe Perchesd4945f02013-03-18 10:44:40 -0700231 unsigned char byServ = 0, bySignal = 0; // For CCK
232 unsigned short wLen = 0;
233 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
Forest Bond5449c682009-04-25 10:30:44 -0400234
Joe Perchesd4945f02013-03-18 10:44:40 -0700235 //Set to Page1
236 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400237
Joe Perchesd4945f02013-03-18 10:44:40 -0700238 //RSPINF_b_1
239 BBvCalculateParameter(pDevice,
240 14,
241 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
242 PK_TYPE_11B,
243 &wLen,
244 &byServ,
245 &bySignal
246);
Forest Bond5449c682009-04-25 10:30:44 -0400247
Joe Perchesd4945f02013-03-18 10:44:40 -0700248 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
249 ///RSPINF_b_2
250 BBvCalculateParameter(pDevice,
251 14,
252 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
253 PK_TYPE_11B,
254 &wLen,
255 &byServ,
256 &bySignal
257);
Forest Bond5449c682009-04-25 10:30:44 -0400258
Joe Perchesd4945f02013-03-18 10:44:40 -0700259 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
260 //RSPINF_b_5
261 BBvCalculateParameter(pDevice,
262 14,
263 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
264 PK_TYPE_11B,
265 &wLen,
266 &byServ,
267 &bySignal
268);
Forest Bond5449c682009-04-25 10:30:44 -0400269
Joe Perchesd4945f02013-03-18 10:44:40 -0700270 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
271 //RSPINF_b_11
272 BBvCalculateParameter(pDevice,
273 14,
274 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
275 PK_TYPE_11B,
276 &wLen,
277 &byServ,
278 &bySignal
279);
Forest Bond5449c682009-04-25 10:30:44 -0400280
Joe Perchesd4945f02013-03-18 10:44:40 -0700281 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
282 //RSPINF_a_6
283 s_vCalculateOFDMRParameter(RATE_6M,
284 ePHYType,
285 &byTxRate,
286 &byRsvTime);
287 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
288 //RSPINF_a_9
289 s_vCalculateOFDMRParameter(RATE_9M,
290 ePHYType,
291 &byTxRate,
292 &byRsvTime);
293 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
294 //RSPINF_a_12
295 s_vCalculateOFDMRParameter(RATE_12M,
296 ePHYType,
297 &byTxRate,
298 &byRsvTime);
299 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
300 //RSPINF_a_18
301 s_vCalculateOFDMRParameter(RATE_18M,
302 ePHYType,
303 &byTxRate,
304 &byRsvTime);
305 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
306 //RSPINF_a_24
307 s_vCalculateOFDMRParameter(RATE_24M,
308 ePHYType,
309 &byTxRate,
310 &byRsvTime);
311 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
312 //RSPINF_a_36
313 s_vCalculateOFDMRParameter(
314 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
315 ePHYType,
316 &byTxRate,
317 &byRsvTime);
318 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
319 //RSPINF_a_48
320 s_vCalculateOFDMRParameter(
321 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
322 ePHYType,
323 &byTxRate,
324 &byRsvTime);
325 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
326 //RSPINF_a_54
327 s_vCalculateOFDMRParameter(
328 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
329 ePHYType,
330 &byTxRate,
331 &byRsvTime);
332 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
333 //RSPINF_a_72
334 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
335 //Set to Page0
336 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400337}
338
Forest Bond5449c682009-04-25 10:30:44 -0400339/*--------------------- Export Functions --------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -0400340
341/*
342 * Description: Card Send packet function
343 *
344 * Parameters:
345 * In:
346 * pDeviceHandler - The adapter to be set
347 * pPacket - Packet buffer pointer
348 * ePktType - Packet type
349 * uLength - Packet length
350 * Out:
351 * none
352 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200353 * Return Value: true if succeeded; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400354 *
355 */
356/*
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700357 bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700358 PSDevice pDevice = (PSDevice) pDeviceHandler;
359 if (ePktType == PKT_TYPE_802_11_MNG) {
360 return TXbTD0Send(pDevice, pPacket, uLength);
361 } else if (ePktType == PKT_TYPE_802_11_BCN) {
362 return TXbBeaconSend(pDevice, pPacket, uLength);
363 } if (ePktType == PKT_TYPE_802_11_DATA) {
364 return TXbTD1Send(pDevice, pPacket, uLength);
365 }
Forest Bond5449c682009-04-25 10:30:44 -0400366
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700367 return true;
Joe Perchesd4945f02013-03-18 10:44:40 -0700368 }
Forest Bond5449c682009-04-25 10:30:44 -0400369*/
370
Forest Bond5449c682009-04-25 10:30:44 -0400371/*
372 * Description: Get Card short preamble option value
373 *
374 * Parameters:
375 * In:
376 * pDevice - The adapter to be set
377 * Out:
378 * none
379 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200380 * Return Value: true if short preamble; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400381 *
382 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700383bool CARDbIsShortPreamble(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400384{
Joe Perchesd4945f02013-03-18 10:44:40 -0700385 PSDevice pDevice = (PSDevice) pDeviceHandler;
386 if (pDevice->byPreambleType == 0) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700387 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700388 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700389 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400390}
391
392/*
393 * Description: Get Card short slot time option value
394 *
395 * Parameters:
396 * In:
397 * pDevice - The adapter to be set
398 * Out:
399 * none
400 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200401 * Return Value: true if short slot time; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400402 *
403 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700404bool CARDbIsShorSlotTime(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400405{
Joe Perchesd4945f02013-03-18 10:44:40 -0700406 PSDevice pDevice = (PSDevice) pDeviceHandler;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700407 return pDevice->bShortSlotTime;
Forest Bond5449c682009-04-25 10:30:44 -0400408}
409
Forest Bond5449c682009-04-25 10:30:44 -0400410/*
411 * Description: Update IFS
412 *
413 * Parameters:
414 * In:
415 * pDevice - The adapter to be set
416 * Out:
417 * none
418 *
419 * Return Value: None.
420 *
421 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700422bool CARDbSetPhyParameter(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
Forest Bond5449c682009-04-25 10:30:44 -0400423{
Joe Perchesd4945f02013-03-18 10:44:40 -0700424 PSDevice pDevice = (PSDevice) pDeviceHandler;
425 unsigned char byCWMaxMin = 0;
426 unsigned char bySlot = 0;
427 unsigned char bySIFS = 0;
428 unsigned char byDIFS = 0;
429 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400430// PWLAN_IE_SUPP_RATES pRates = NULL;
Joe Perchesd4945f02013-03-18 10:44:40 -0700431 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
432 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
Forest Bond5449c682009-04-25 10:30:44 -0400433
Joe Perchesd4945f02013-03-18 10:44:40 -0700434 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
435 if (ePHYType == PHY_TYPE_11A) {
436 if (pSupportRates == NULL) {
437 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
438 }
439 if (pDevice->byRFType == RF_AIROHA7230) {
440 // AL7230 use single PAPE and connect to PAPE_2.4G
441 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
442 pDevice->abyBBVGA[0] = 0x20;
443 pDevice->abyBBVGA[2] = 0x10;
444 pDevice->abyBBVGA[3] = 0x10;
445 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
446 if (byData == 0x1C) {
447 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
448 }
449 } else if (pDevice->byRFType == RF_UW2452) {
450 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
451 pDevice->abyBBVGA[0] = 0x18;
452 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
453 if (byData == 0x14) {
454 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
455 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
456 }
457 } else {
458 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
459 }
460 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
461 bySlot = C_SLOT_SHORT;
462 bySIFS = C_SIFS_A;
463 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
464 byCWMaxMin = 0xA4;
465 } else if (ePHYType == PHY_TYPE_11B) {
466 if (pSupportRates == NULL) {
467 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
468 }
469 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
470 if (pDevice->byRFType == RF_AIROHA7230) {
471 pDevice->abyBBVGA[0] = 0x1C;
472 pDevice->abyBBVGA[2] = 0x00;
473 pDevice->abyBBVGA[3] = 0x00;
474 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
475 if (byData == 0x20) {
476 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
477 }
478 } else if (pDevice->byRFType == RF_UW2452) {
479 pDevice->abyBBVGA[0] = 0x14;
480 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
481 if (byData == 0x18) {
482 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
483 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
484 }
485 }
486 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
487 bySlot = C_SLOT_LONG;
488 bySIFS = C_SIFS_BG;
489 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
490 byCWMaxMin = 0xA5;
491 } else {// PK_TYPE_11GA & PK_TYPE_11GB
492 if (pSupportRates == NULL) {
493 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
494 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
495 }
496 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
497 if (pDevice->byRFType == RF_AIROHA7230) {
498 pDevice->abyBBVGA[0] = 0x1C;
499 pDevice->abyBBVGA[2] = 0x00;
500 pDevice->abyBBVGA[3] = 0x00;
501 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
502 if (byData == 0x20) {
503 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
504 }
505 } else if (pDevice->byRFType == RF_UW2452) {
506 pDevice->abyBBVGA[0] = 0x14;
507 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
508 if (byData == 0x18) {
509 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
510 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
511 }
512 }
513 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
514 bySIFS = C_SIFS_BG;
515 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
516 bySlot = C_SLOT_SHORT;
517 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
518 } else {
519 bySlot = C_SLOT_LONG;
520 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
521 }
522 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
523 byCWMaxMin = 0xA4;
524 } else {
525 byCWMaxMin = 0xA5;
526 }
527 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
528 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
529 if (pDevice->bProtectMode) {
530 MACvEnableProtectMD(pDevice->PortOffset);
531 } else {
532 MACvDisableProtectMD(pDevice->PortOffset);
533 }
534 }
535 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
536 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
537 if (pDevice->bBarkerPreambleMd) {
538 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
539 } else {
540 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
541 }
542 }
543 }
Forest Bond5449c682009-04-25 10:30:44 -0400544
Joe Perchesd4945f02013-03-18 10:44:40 -0700545 if (pDevice->byRFType == RF_RFMD2959) {
546 // bcs TX_PE will reserve 3 us
547 // hardware's processing time here is 2 us.
548 bySIFS -= 3;
549 byDIFS -= 3;
550 //{{ RobertYu: 20041202
551 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
552 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
553 }
Forest Bond5449c682009-04-25 10:30:44 -0400554
Joe Perchesd4945f02013-03-18 10:44:40 -0700555 if (pDevice->bySIFS != bySIFS) {
556 pDevice->bySIFS = bySIFS;
557 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
558 }
559 if (pDevice->byDIFS != byDIFS) {
560 pDevice->byDIFS = byDIFS;
561 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
562 }
563 if (pDevice->byEIFS != C_EIFS) {
564 pDevice->byEIFS = C_EIFS;
565 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
566 }
567 if (pDevice->bySlot != bySlot) {
568 pDevice->bySlot = bySlot;
569 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
570 if (pDevice->bySlot == C_SLOT_SHORT) {
571 pDevice->bShortSlotTime = true;
572 } else {
573 pDevice->bShortSlotTime = false;
574 }
575 BBvSetShortSlotTime(pDevice);
576 }
577 if (pDevice->byCWMaxMin != byCWMaxMin) {
578 pDevice->byCWMaxMin = byCWMaxMin;
579 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
580 }
581 if (VNTWIFIbIsShortPreamble(wCapInfo)) {
582 pDevice->byPreambleType = pDevice->byShortPreamble;
583 } else {
584 pDevice->byPreambleType = 0;
585 }
586 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
587 pDevice->eCurrentPHYType = ePHYType;
588 // set for NDIS OID_802_11SUPPORTED_RATES
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700589 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400590}
591
592/*
593 * Description: Sync. TSF counter to BSS
594 * Get TSF offset and write to HW
595 *
596 * Parameters:
597 * In:
598 * pDevice - The adapter to be sync.
599 * byRxRate - data rate of receive beacon
600 * qwBSSTimestamp - Rx BCN's TSF
601 * qwLocalTSF - Local TSF
602 * Out:
603 * none
604 *
605 * Return Value: none
606 *
607 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700608bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
Forest Bond5449c682009-04-25 10:30:44 -0400609{
Joe Perchesd4945f02013-03-18 10:44:40 -0700610 PSDevice pDevice = (PSDevice) pDeviceHandler;
611 QWORD qwTSFOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400612
Joe Perchesd4945f02013-03-18 10:44:40 -0700613 HIDWORD(qwTSFOffset) = 0;
614 LODWORD(qwTSFOffset) = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400615
Joe Perchesd4945f02013-03-18 10:44:40 -0700616 if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
617 (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
618 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
619 // adjust TSF
620 // HW's TSF add TSF Offset reg
621 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
622 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
623 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
624 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700625 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400626}
627
Forest Bond5449c682009-04-25 10:30:44 -0400628/*
629 * Description: Set NIC TSF counter for first Beacon time
630 * Get NEXTTBTT from adjusted TSF and Beacon Interval
631 *
632 * Parameters:
633 * In:
634 * pDevice - The adapter to be set.
635 * wBeaconInterval - Beacon Interval
636 * Out:
637 * none
638 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200639 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400640 *
641 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700642bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400643{
Joe Perchesd4945f02013-03-18 10:44:40 -0700644 PSDevice pDevice = (PSDevice) pDeviceHandler;
645 unsigned int uBeaconInterval = 0;
646 unsigned int uLowNextTBTT = 0;
647 unsigned int uHighRemain = 0;
648 unsigned int uLowRemain = 0;
649 QWORD qwNextTBTT;
Forest Bond5449c682009-04-25 10:30:44 -0400650
Joe Perchesd4945f02013-03-18 10:44:40 -0700651 HIDWORD(qwNextTBTT) = 0;
652 LODWORD(qwNextTBTT) = 0;
653 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
654 uBeaconInterval = wBeaconInterval * 1024;
655 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
656 uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
657 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
658 // high dword (mod) bcn
659 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
660 % uBeaconInterval;
661 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
662 uLowRemain = uBeaconInterval - uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -0400663
Joe Perchesd4945f02013-03-18 10:44:40 -0700664 // check if carry when add one beacon interval
665 if ((~uLowNextTBTT) < uLowRemain) {
666 HIDWORD(qwNextTBTT)++;
667 }
668 LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -0400669
Joe Perchesd4945f02013-03-18 10:44:40 -0700670 // set HW beacon interval
671 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
672 pDevice->wBeaconInterval = wBeaconInterval;
673 // Set NextTBTT
674 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
675 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
676 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -0400677
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700678 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400679}
680
Forest Bond5449c682009-04-25 10:30:44 -0400681/*
682 * Description: Card Stop Hardware Tx
683 *
684 * Parameters:
685 * In:
686 * pDeviceHandler - The adapter to be set
687 * ePktType - Packet type to stop
688 * Out:
689 * none
690 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200691 * Return Value: true if all data packet complete; otherwise false.
Forest Bond5449c682009-04-25 10:30:44 -0400692 *
693 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700694bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400695{
Joe Perchesd4945f02013-03-18 10:44:40 -0700696 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400697
Joe Perchesd4945f02013-03-18 10:44:40 -0700698 if (ePktType == PKT_TYPE_802_11_ALL) {
699 pDevice->bStopBeacon = true;
700 pDevice->bStopTx0Pkt = true;
701 pDevice->bStopDataPkt = true;
702 } else if (ePktType == PKT_TYPE_802_11_BCN) {
703 pDevice->bStopBeacon = true;
704 } else if (ePktType == PKT_TYPE_802_11_MNG) {
705 pDevice->bStopTx0Pkt = true;
706 } else if (ePktType == PKT_TYPE_802_11_DATA) {
707 pDevice->bStopDataPkt = true;
708 }
Forest Bond5449c682009-04-25 10:30:44 -0400709
Joe Perchesd4945f02013-03-18 10:44:40 -0700710 if (pDevice->bStopBeacon == true) {
711 if (pDevice->bIsBeaconBufReadySet == true) {
712 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
713 pDevice->cbBeaconBufReadySetCnt++;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700714 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700715 }
716 }
717 pDevice->bIsBeaconBufReadySet = false;
718 pDevice->cbBeaconBufReadySetCnt = 0;
719 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
720 }
721 // wait all TD0 complete
722 if (pDevice->bStopTx0Pkt == true) {
723 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700724 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700725 }
726 }
727 // wait all Data TD complete
728 if (pDevice->bStopDataPkt == true) {
729 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700730 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700731 }
732 }
Forest Bond5449c682009-04-25 10:30:44 -0400733
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700734 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400735}
736
Forest Bond5449c682009-04-25 10:30:44 -0400737/*
738 * Description: Card Start Hardware Tx
739 *
740 * Parameters:
741 * In:
742 * pDeviceHandler - The adapter to be set
743 * ePktType - Packet type to start
744 * Out:
745 * none
746 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200747 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400748 *
749 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700750bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400751{
Joe Perchesd4945f02013-03-18 10:44:40 -0700752 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400753
Joe Perchesd4945f02013-03-18 10:44:40 -0700754 if (ePktType == PKT_TYPE_802_11_ALL) {
755 pDevice->bStopBeacon = false;
756 pDevice->bStopTx0Pkt = false;
757 pDevice->bStopDataPkt = false;
758 } else if (ePktType == PKT_TYPE_802_11_BCN) {
759 pDevice->bStopBeacon = false;
760 } else if (ePktType == PKT_TYPE_802_11_MNG) {
761 pDevice->bStopTx0Pkt = false;
762 } else if (ePktType == PKT_TYPE_802_11_DATA) {
763 pDevice->bStopDataPkt = false;
764 }
Forest Bond5449c682009-04-25 10:30:44 -0400765
Joe Perchesd4945f02013-03-18 10:44:40 -0700766 if ((pDevice->bStopBeacon == false) &&
767 (pDevice->bBeaconBufReady == true) &&
768 (pDevice->eOPMode == OP_MODE_ADHOC)) {
769 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
770 }
Forest Bond5449c682009-04-25 10:30:44 -0400771
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700772 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400773}
774
Forest Bond5449c682009-04-25 10:30:44 -0400775/*
776 * Description: Card Set BSSID value
777 *
778 * Parameters:
779 * In:
780 * pDeviceHandler - The adapter to be set
781 * pbyBSSID - pointer to BSSID field
782 * bAdhoc - flag to indicate IBSS
783 * Out:
784 * none
785 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200786 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400787 *
788 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200789bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
Forest Bond5449c682009-04-25 10:30:44 -0400790{
Joe Perchesd4945f02013-03-18 10:44:40 -0700791 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400792
Joe Perchesd4945f02013-03-18 10:44:40 -0700793 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
794 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
795 if (eOPMode == OP_MODE_ADHOC) {
796 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
797 } else {
798 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
799 }
800 if (eOPMode == OP_MODE_AP) {
801 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
802 } else {
803 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
804 }
805 if (eOPMode == OP_MODE_UNKNOWN) {
806 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
807 pDevice->bBSSIDFilter = false;
808 pDevice->byRxMode &= ~RCR_BSSID;
809 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
810 } else {
811 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
812 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
813 pDevice->bBSSIDFilter = true;
814 pDevice->byRxMode |= RCR_BSSID;
815 }
816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode);
817 }
818 // Adopt BSS state in Adapter Device Object
819 pDevice->eOPMode = eOPMode;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700820 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400821}
822
Forest Bond5449c682009-04-25 10:30:44 -0400823/*
824 * Description: Card indicate status
825 *
826 * Parameters:
827 * In:
828 * pDeviceHandler - The adapter to be set
829 * eStatus - Status
830 * Out:
831 * none
832 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200833 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400834 *
835 */
836
Forest Bond5449c682009-04-25 10:30:44 -0400837/*
838 * Description: Save Assoc info. contain in assoc. response frame
839 *
840 * Parameters:
841 * In:
842 * pDevice - The adapter to be set
843 * wCapabilityInfo - Capability information
844 * wStatus - Status code
845 * wAID - Assoc. ID
846 * uLen - Length of IEs
847 * pbyIEs - pointer to IEs
848 * Out:
849 * none
850 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200851 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400852 *
853 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200854bool CARDbSetTxDataRate(
Joe Perchesd4945f02013-03-18 10:44:40 -0700855 void *pDeviceHandler,
856 unsigned short wDataRate
857)
Forest Bond5449c682009-04-25 10:30:44 -0400858{
Joe Perchesd4945f02013-03-18 10:44:40 -0700859 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400860
Joe Perchesd4945f02013-03-18 10:44:40 -0700861 pDevice->wCurrentRate = wDataRate;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700862 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400863}
864
865/*+
866 *
867 * Routine Description:
868 * Consider to power down when no more packets to tx or rx.
869 *
870 * Parameters:
871 * In:
872 * pDevice - The adapter to be set
873 * Out:
874 * none
875 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200876 * Return Value: true if power down success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400877 *
Joe Perchesd4945f02013-03-18 10:44:40 -0700878 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +0200879bool
Forest Bond5449c682009-04-25 10:30:44 -0400880CARDbPowerDown(
Joe Perchesd4945f02013-03-18 10:44:40 -0700881 void *pDeviceHandler
882)
Forest Bond5449c682009-04-25 10:30:44 -0400883{
Joe Perchesd4945f02013-03-18 10:44:40 -0700884 PSDevice pDevice = (PSDevice)pDeviceHandler;
885 unsigned int uIdx;
Forest Bond5449c682009-04-25 10:30:44 -0400886
Joe Perchesd4945f02013-03-18 10:44:40 -0700887 // check if already in Doze mode
888 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
889 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400890
Joe Perchesd4945f02013-03-18 10:44:40 -0700891 // Froce PSEN on
892 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -0400893
Joe Perchesd4945f02013-03-18 10:44:40 -0700894 // check if all TD are empty,
Forest Bond5449c682009-04-25 10:30:44 -0400895
Joe Perchesd4945f02013-03-18 10:44:40 -0700896 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
897 if (pDevice->iTDUsed[uIdx] != 0)
898 return false;
899 }
Forest Bond5449c682009-04-25 10:30:44 -0400900
Joe Perchesd4945f02013-03-18 10:44:40 -0700901 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
902 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
903 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400904}
905
906/*
907 * Description: Turn off Radio power
908 *
909 * Parameters:
910 * In:
911 * pDevice - The adapter to be turned off
912 * Out:
913 * none
914 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200915 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400916 *
917 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700918bool CARDbRadioPowerOff(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400919{
Joe Perchesd4945f02013-03-18 10:44:40 -0700920 PSDevice pDevice = (PSDevice)pDeviceHandler;
921 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -0400922
Joe Perchesd4945f02013-03-18 10:44:40 -0700923 if (pDevice->bRadioOff == true)
924 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400925
Joe Perchesd4945f02013-03-18 10:44:40 -0700926 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700927 case RF_RFMD2959:
928 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
929 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
930 break;
Forest Bond5449c682009-04-25 10:30:44 -0400931
Joe Perchesd4945f02013-03-18 10:44:40 -0700932 case RF_AIROHA:
933 case RF_AL2230S:
934 case RF_AIROHA7230: //RobertYu:20050104
935 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
936 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
937 break;
Forest Bond5449c682009-04-25 10:30:44 -0400938
Joe Perchesd4945f02013-03-18 10:44:40 -0700939 }
Forest Bond5449c682009-04-25 10:30:44 -0400940
Joe Perchesd4945f02013-03-18 10:44:40 -0700941 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400942
Joe Perchesd4945f02013-03-18 10:44:40 -0700943 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400944
Joe Perchesd4945f02013-03-18 10:44:40 -0700945 pDevice->bRadioOff = true;
946 //2007-0409-03,<Add> by chester
947 printk("chester power off\n");
948 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
949 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400950}
951
Forest Bond5449c682009-04-25 10:30:44 -0400952/*
953 * Description: Turn on Radio power
954 *
955 * Parameters:
956 * In:
957 * pDevice - The adapter to be turned on
958 * Out:
959 * none
960 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200961 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400962 *
963 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700964bool CARDbRadioPowerOn(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400965{
Joe Perchesd4945f02013-03-18 10:44:40 -0700966 PSDevice pDevice = (PSDevice) pDeviceHandler;
967 bool bResult = true;
968 printk("chester power on\n");
969 if (pDevice->bRadioControlOff == true) {
970 if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
971 if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
972 return false; }
Forest Bond5449c682009-04-25 10:30:44 -0400973
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700974 if (pDevice->bRadioOff == false) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700975 printk("chester pbRadioOff\n");
976 return true; }
Forest Bond5449c682009-04-25 10:30:44 -0400977
Joe Perchesd4945f02013-03-18 10:44:40 -0700978 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400979
Joe Perchesd4945f02013-03-18 10:44:40 -0700980 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400981
Joe Perchesd4945f02013-03-18 10:44:40 -0700982 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700983 case RF_RFMD2959:
984 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
985 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
986 break;
Forest Bond5449c682009-04-25 10:30:44 -0400987
Joe Perchesd4945f02013-03-18 10:44:40 -0700988 case RF_AIROHA:
989 case RF_AL2230S:
990 case RF_AIROHA7230: //RobertYu:20050104
991 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
992 SOFTPWRCTL_SWPE3));
993 break;
Forest Bond5449c682009-04-25 10:30:44 -0400994
Joe Perchesd4945f02013-03-18 10:44:40 -0700995 }
Forest Bond5449c682009-04-25 10:30:44 -0400996
Joe Perchesd4945f02013-03-18 10:44:40 -0700997 pDevice->bRadioOff = false;
Forest Bond5449c682009-04-25 10:30:44 -0400998// 2007-0409-03,<Add> by chester
Joe Perchesd4945f02013-03-18 10:44:40 -0700999 printk("chester power on\n");
1000 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
1001 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -04001002}
1003
Joe Perchesd4945f02013-03-18 10:44:40 -07001004bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID)
Forest Bond5449c682009-04-25 10:30:44 -04001005{
Joe Perchesd4945f02013-03-18 10:44:40 -07001006 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001007
Joe Perchesd4945f02013-03-18 10:44:40 -07001008 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001009 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001010}
1011
Forest Bond5449c682009-04-25 10:30:44 -04001012/*
1013 *
1014 * Description:
1015 * Add BSSID in PMKID Candidate list.
1016 *
1017 * Parameters:
1018 * In:
1019 * hDeviceContext - device structure point
1020 * pbyBSSID - BSSID address for adding
1021 * wRSNCap - BSS's RSN capability
1022 * Out:
1023 * none
1024 *
1025 * Return Value: none.
1026 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001027 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001028bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001029CARDbAdd_PMKID_Candidate(
1030 void *pDeviceHandler,
1031 unsigned char *pbyBSSID,
1032 bool bRSNCapExist,
1033 unsigned short wRSNCap
1034)
Forest Bond5449c682009-04-25 10:30:44 -04001035{
Joe Perchesd4945f02013-03-18 10:44:40 -07001036 PSDevice pDevice = (PSDevice) pDeviceHandler;
1037 PPMKID_CANDIDATE pCandidateList;
1038 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001039
Joe Perchesd4945f02013-03-18 10:44:40 -07001040 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
Forest Bond5449c682009-04-25 10:30:44 -04001041
Joe Perchesd4945f02013-03-18 10:44:40 -07001042 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1043 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n");
1044 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1045 }
Forest Bond5449c682009-04-25 10:30:44 -04001046
Joe Perchesd4945f02013-03-18 10:44:40 -07001047 for (ii = 0; ii < 6; ii++) {
1048 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii));
1049 }
1050 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
Forest Bond5449c682009-04-25 10:30:44 -04001051
Joe Perchesd4945f02013-03-18 10:44:40 -07001052 // Update Old Candidate
1053 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1054 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1055 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
1056 if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
1057 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1058 } else {
1059 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1060 }
1061 return true;
1062 }
1063 }
Forest Bond5449c682009-04-25 10:30:44 -04001064
Joe Perchesd4945f02013-03-18 10:44:40 -07001065 // New Candidate
1066 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1067 if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
1068 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1069 } else {
1070 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1071 }
1072 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1073 pDevice->gsPMKIDCandidate.NumCandidates++;
1074 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1075 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001076}
1077
Charles Clément830a6192010-05-07 12:30:20 -07001078void *
Joe Perchesd4945f02013-03-18 10:44:40 -07001079CARDpGetCurrentAddress(
1080 void *pDeviceHandler
1081)
Forest Bond5449c682009-04-25 10:30:44 -04001082{
Joe Perchesd4945f02013-03-18 10:44:40 -07001083 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001084
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001085 return pDevice->abyCurrentNetAddr;
Forest Bond5449c682009-04-25 10:30:44 -04001086}
1087
Forest Bond5449c682009-04-25 10:30:44 -04001088/*
1089 *
1090 * Description:
1091 * Start Spectrum Measure defined in 802.11h
1092 *
1093 * Parameters:
1094 * In:
1095 * hDeviceContext - device structure point
1096 * Out:
1097 * none
1098 *
1099 * Return Value: none.
1100 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001101 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001102bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001103CARDbStartMeasure(
1104 void *pDeviceHandler,
1105 void *pvMeasureEIDs,
1106 unsigned int uNumOfMeasureEIDs
1107)
Forest Bond5449c682009-04-25 10:30:44 -04001108{
Joe Perchesd4945f02013-03-18 10:44:40 -07001109 PSDevice pDevice = (PSDevice) pDeviceHandler;
1110 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1111 QWORD qwCurrTSF;
1112 QWORD qwStartTSF;
1113 bool bExpired = true;
1114 unsigned short wDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001115
Joe Perchesd4945f02013-03-18 10:44:40 -07001116 if ((pEID == NULL) ||
1117 (uNumOfMeasureEIDs == 0)) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001118 return true;
Joe Perchesd4945f02013-03-18 10:44:40 -07001119 }
1120 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1121 if (pDevice->bMeasureInProgress == true) {
1122 pDevice->bMeasureInProgress = false;
1123 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1124 MACvSelectPage1(pDevice->PortOffset);
1125 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1126 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1127 // clear measure control
1128 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1129 MACvSelectPage0(pDevice->PortOffset);
1130 set_channel(pDevice, pDevice->byOrgChannel);
1131 MACvSelectPage1(pDevice->PortOffset);
1132 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1133 MACvSelectPage0(pDevice->PortOffset);
1134 }
1135 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
Forest Bond5449c682009-04-25 10:30:44 -04001136
Joe Perchesd4945f02013-03-18 10:44:40 -07001137 do {
1138 pDevice->pCurrMeasureEID = pEID;
1139 pEID++;
1140 pDevice->uNumOfMeasureEIDs--;
Forest Bond5449c682009-04-25 10:30:44 -04001141
Joe Perchesd4945f02013-03-18 10:44:40 -07001142 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1143 HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1144 LODWORD(qwStartTSF) = LODWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1145 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1146 wDuration += 1; // 1 TU for channel switching
Forest Bond5449c682009-04-25 10:30:44 -04001147
Joe Perchesd4945f02013-03-18 10:44:40 -07001148 if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1149 // start immediately by setting start TSF == current TSF + 2 TU
1150 LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1151 HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
1152 if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
1153 HIDWORD(qwStartTSF)++;
1154 }
1155 bExpired = false;
1156 break;
1157 } else {
1158 // start at setting start TSF - 1TU(for channel switching)
1159 if (LODWORD(qwStartTSF) < 1024) {
1160 HIDWORD(qwStartTSF)--;
1161 }
1162 LODWORD(qwStartTSF) -= 1024;
1163 }
Forest Bond5449c682009-04-25 10:30:44 -04001164
Joe Perchesd4945f02013-03-18 10:44:40 -07001165 if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1166 ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1167 (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1168) {
1169 bExpired = false;
1170 break;
1171 }
1172 VNTWIFIbMeasureReport(pDevice->pMgmt,
1173 false,
1174 pDevice->pCurrMeasureEID,
1175 MEASURE_MODE_LATE,
1176 pDevice->byBasicMap,
1177 pDevice->byCCAFraction,
1178 pDevice->abyRPIs
1179 );
1180 } else {
1181 // hardware do not support measure
1182 VNTWIFIbMeasureReport(pDevice->pMgmt,
1183 false,
1184 pDevice->pCurrMeasureEID,
1185 MEASURE_MODE_INCAPABLE,
1186 pDevice->byBasicMap,
1187 pDevice->byCCAFraction,
1188 pDevice->abyRPIs
1189 );
1190 }
1191 } while (pDevice->uNumOfMeasureEIDs != 0);
Forest Bond5449c682009-04-25 10:30:44 -04001192
Joe Perchesd4945f02013-03-18 10:44:40 -07001193 if (bExpired == false) {
1194 MACvSelectPage1(pDevice->PortOffset);
1195 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1196 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1197 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1198 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1199 MACvSelectPage0(pDevice->PortOffset);
1200 } else {
1201 // all measure start time expired we should complete action
1202 VNTWIFIbMeasureReport(pDevice->pMgmt,
1203 true,
1204 NULL,
1205 0,
1206 pDevice->byBasicMap,
1207 pDevice->byCCAFraction,
1208 pDevice->abyRPIs
1209 );
1210 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001211 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001212}
1213
Forest Bond5449c682009-04-25 10:30:44 -04001214/*
1215 *
1216 * Description:
1217 * Do Channel Switch defined in 802.11h
1218 *
1219 * Parameters:
1220 * In:
1221 * hDeviceContext - device structure point
1222 * Out:
1223 * none
1224 *
1225 * Return Value: none.
1226 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001227 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001228bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001229CARDbChannelSwitch(
1230 void *pDeviceHandler,
1231 unsigned char byMode,
1232 unsigned char byNewChannel,
1233 unsigned char byCount
1234)
Forest Bond5449c682009-04-25 10:30:44 -04001235{
Joe Perchesd4945f02013-03-18 10:44:40 -07001236 PSDevice pDevice = (PSDevice) pDeviceHandler;
1237 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -04001238
Joe Perchesd4945f02013-03-18 10:44:40 -07001239 if (byCount == 0) {
1240 bResult = set_channel(pDevice, byNewChannel);
1241 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1242 MACvSelectPage1(pDevice->PortOffset);
1243 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1244 MACvSelectPage0(pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001245 return bResult;
Joe Perchesd4945f02013-03-18 10:44:40 -07001246 }
1247 pDevice->byChannelSwitchCount = byCount;
1248 pDevice->byNewChannel = byNewChannel;
1249 pDevice->bChannelSwitch = true;
1250 if (byMode == 1) {
1251 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1252 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001253 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -04001254}
1255
Forest Bond5449c682009-04-25 10:30:44 -04001256/*
1257 *
1258 * Description:
1259 * Handle Quiet EID defined in 802.11h
1260 *
1261 * Parameters:
1262 * In:
1263 * hDeviceContext - device structure point
1264 * Out:
1265 * none
1266 *
1267 * Return Value: none.
1268 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001269 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001270bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001271CARDbSetQuiet(
1272 void *pDeviceHandler,
1273 bool bResetQuiet,
1274 unsigned char byQuietCount,
1275 unsigned char byQuietPeriod,
1276 unsigned short wQuietDuration,
1277 unsigned short wQuietOffset
1278)
Forest Bond5449c682009-04-25 10:30:44 -04001279{
Joe Perchesd4945f02013-03-18 10:44:40 -07001280 PSDevice pDevice = (PSDevice) pDeviceHandler;
1281 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001282
Joe Perchesd4945f02013-03-18 10:44:40 -07001283 if (bResetQuiet == true) {
1284 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1285 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1286 pDevice->sQuiet[ii].bEnable = false;
1287 }
1288 pDevice->uQuietEnqueue = 0;
1289 pDevice->bEnableFirstQuiet = false;
1290 pDevice->bQuietEnable = false;
1291 pDevice->byQuietStartCount = byQuietCount;
1292 }
1293 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1294 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1295 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1296 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1297 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1298 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1299 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1300 pDevice->uQuietEnqueue++;
1301 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1302 if (pDevice->byQuietStartCount < byQuietCount) {
1303 pDevice->byQuietStartCount = byQuietCount;
1304 }
1305 } else {
1306 // we can not handle Quiet EID more
1307 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001308 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001309}
1310
Forest Bond5449c682009-04-25 10:30:44 -04001311/*
1312 *
1313 * Description:
Joe Perchesd4945f02013-03-18 10:44:40 -07001314 * Do Quiet, It will be called by either ISR(after start)
Justin P. Mattock789d1ae2012-08-20 08:43:13 -07001315 * or VNTWIFI(before start) so we do not need a SPINLOCK
Forest Bond5449c682009-04-25 10:30:44 -04001316 *
1317 * Parameters:
1318 * In:
1319 * hDeviceContext - device structure point
1320 * Out:
1321 * none
1322 *
1323 * Return Value: none.
1324 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001325 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001326bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001327CARDbStartQuiet(
1328 void *pDeviceHandler
1329)
Forest Bond5449c682009-04-25 10:30:44 -04001330{
Joe Perchesd4945f02013-03-18 10:44:40 -07001331 PSDevice pDevice = (PSDevice) pDeviceHandler;
1332 unsigned int ii = 0;
1333 unsigned long dwStartTime = 0xFFFFFFFF;
1334 unsigned int uCurrentQuietIndex = 0;
1335 unsigned long dwNextTime = 0;
1336 unsigned long dwGap = 0;
1337 unsigned long dwDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001338
Joe Perchesd4945f02013-03-18 10:44:40 -07001339 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1340 if ((pDevice->sQuiet[ii].bEnable == true) &&
1341 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1342 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1343 uCurrentQuietIndex = ii;
1344 }
1345 }
1346 if (dwStartTime == 0xFFFFFFFF) {
1347 // no more quiet
1348 pDevice->bQuietEnable = false;
1349 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1350 } else {
1351 if (pDevice->bQuietEnable == false) {
1352 // first quiet
1353 pDevice->byQuietStartCount--;
1354 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1355 dwNextTime %= pDevice->wBeaconInterval;
1356 MACvSelectPage1(pDevice->PortOffset);
1357 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1358 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1359 if (pDevice->byQuietStartCount == 0) {
1360 pDevice->bEnableFirstQuiet = false;
1361 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1362 } else {
1363 pDevice->bEnableFirstQuiet = true;
1364 }
1365 MACvSelectPage0(pDevice->PortOffset);
1366 } else {
1367 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1368 // overlap with previous Quiet
1369 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1370 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1371 // return false to indicate next quiet expired, should call this function again
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001372 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -07001373 }
1374 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1375 dwGap = 0;
1376 } else {
1377 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1378 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1379 }
1380 // set GAP and Next duration
1381 MACvSelectPage1(pDevice->PortOffset);
1382 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1383 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1384 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1385 MACvSelectPage0(pDevice->PortOffset);
1386 }
1387 pDevice->bQuietEnable = true;
1388 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1389 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1390 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1391 // not period disable current quiet element
1392 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1393 } else {
1394 // set next period start time
1395 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1396 dwNextTime *= pDevice->wBeaconInterval;
1397 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1398 }
1399 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1400 // decreament all time to avoid wrap around
1401 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1402 if (pDevice->sQuiet[ii].bEnable == true) {
1403 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1404 }
1405 }
1406 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1407 }
1408 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001409 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001410}
1411
Forest Bond5449c682009-04-25 10:30:44 -04001412/*
1413 *
1414 * Description:
1415 * Set Local Power Constraint
1416 *
1417 * Parameters:
1418 * In:
1419 * hDeviceContext - device structure point
1420 * Out:
1421 * none
1422 *
1423 * Return Value: none.
1424 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001425 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001426void
Joe Perchesd4945f02013-03-18 10:44:40 -07001427CARDvSetPowerConstraint(
1428 void *pDeviceHandler,
1429 unsigned char byChannel,
1430 char byPower
1431)
Forest Bond5449c682009-04-25 10:30:44 -04001432{
Joe Perchesd4945f02013-03-18 10:44:40 -07001433 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001434
Joe Perchesd4945f02013-03-18 10:44:40 -07001435 if (byChannel > CB_MAX_CHANNEL_24G) {
1436 if (pDevice->bCountryInfo5G == true) {
1437 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1438 }
1439 } else {
1440 if (pDevice->bCountryInfo24G == true) {
1441 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1442 }
1443 }
Forest Bond5449c682009-04-25 10:30:44 -04001444}
1445
Forest Bond5449c682009-04-25 10:30:44 -04001446/*
1447 *
1448 * Description:
1449 * Set Local Power Constraint
1450 *
1451 * Parameters:
1452 * In:
1453 * hDeviceContext - device structure point
1454 * Out:
1455 * none
1456 *
1457 * Return Value: none.
1458 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001459 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001460void
Joe Perchesd4945f02013-03-18 10:44:40 -07001461CARDvGetPowerCapability(
1462 void *pDeviceHandler,
1463 unsigned char *pbyMinPower,
1464 unsigned char *pbyMaxPower
1465)
Forest Bond5449c682009-04-25 10:30:44 -04001466{
Joe Perchesd4945f02013-03-18 10:44:40 -07001467 PSDevice pDevice = (PSDevice) pDeviceHandler;
1468 unsigned char byDec = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001469
Joe Perchesd4945f02013-03-18 10:44:40 -07001470 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1471 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1472 if (pDevice->byRFType == RF_UW2452) {
1473 byDec *= 3;
1474 byDec >>= 1;
1475 } else {
1476 byDec <<= 1;
1477 }
1478 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
Forest Bond5449c682009-04-25 10:30:44 -04001479}
1480
Forest Bond5449c682009-04-25 10:30:44 -04001481/*
1482 *
1483 * Description:
1484 * Get Current Tx Power
1485 *
1486 * Parameters:
1487 * In:
1488 * hDeviceContext - device structure point
1489 * Out:
1490 * none
1491 *
1492 * Return Value: none.
1493 *
Charles Clément79566eb2010-06-21 10:39:51 -07001494 */
Charles Clémentec28c7f2010-05-28 12:34:18 -07001495char
Joe Perchesd4945f02013-03-18 10:44:40 -07001496CARDbyGetTransmitPower(
1497 void *pDeviceHandler
1498)
Forest Bond5449c682009-04-25 10:30:44 -04001499{
Joe Perchesd4945f02013-03-18 10:44:40 -07001500 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001501
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001502 return pDevice->byCurPwrdBm;
Forest Bond5449c682009-04-25 10:30:44 -04001503}
1504
Forest Bond5449c682009-04-25 10:30:44 -04001505//xxx
Charles Clément6b35b7b2010-05-07 12:30:19 -07001506void
Joe Perchesd4945f02013-03-18 10:44:40 -07001507CARDvSafeResetTx(
1508 void *pDeviceHandler
1509)
Forest Bond5449c682009-04-25 10:30:44 -04001510{
Joe Perchesd4945f02013-03-18 10:44:40 -07001511 PSDevice pDevice = (PSDevice) pDeviceHandler;
1512 unsigned int uu;
1513 PSTxDesc pCurrTD;
Forest Bond5449c682009-04-25 10:30:44 -04001514
Joe Perchesd4945f02013-03-18 10:44:40 -07001515 // initialize TD index
1516 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1517 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001518
Joe Perchesd4945f02013-03-18 10:44:40 -07001519 for (uu = 0; uu < TYPE_MAXTD; uu++)
1520 pDevice->iTDUsed[uu] = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001521
Joe Perchesd4945f02013-03-18 10:44:40 -07001522 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1523 pCurrTD = &(pDevice->apTD0Rings[uu]);
1524 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1525 // init all Tx Packet pointer to NULL
1526 }
1527 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1528 pCurrTD = &(pDevice->apTD1Rings[uu]);
1529 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1530 // init all Tx Packet pointer to NULL
1531 }
Forest Bond5449c682009-04-25 10:30:44 -04001532
Joe Perchesd4945f02013-03-18 10:44:40 -07001533 // set MAC TD pointer
1534 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1535 (pDevice->td0_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001536
Joe Perchesd4945f02013-03-18 10:44:40 -07001537 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1538 (pDevice->td1_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001539
Joe Perchesd4945f02013-03-18 10:44:40 -07001540 // set MAC Beacon TX pointer
1541 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1542 (pDevice->tx_beacon_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001543}
1544
Forest Bond5449c682009-04-25 10:30:44 -04001545/*+
1546 *
1547 * Description:
1548 * Reset Rx
1549 *
1550 * Parameters:
1551 * In:
1552 * pDevice - Pointer to the adapter
1553 * Out:
1554 * none
1555 *
1556 * Return Value: none
1557 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001558 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001559void
Joe Perchesd4945f02013-03-18 10:44:40 -07001560CARDvSafeResetRx(
1561 void *pDeviceHandler
1562)
Forest Bond5449c682009-04-25 10:30:44 -04001563{
Joe Perchesd4945f02013-03-18 10:44:40 -07001564 PSDevice pDevice = (PSDevice) pDeviceHandler;
1565 unsigned int uu;
1566 PSRxDesc pDesc;
Forest Bond5449c682009-04-25 10:30:44 -04001567
Joe Perchesd4945f02013-03-18 10:44:40 -07001568 // initialize RD index
1569 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1570 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001571
Joe Perchesd4945f02013-03-18 10:44:40 -07001572 // init state, all RD is chip's
1573 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1574 pDesc = &(pDevice->aRD0Ring[uu]);
1575 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1576 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1577 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1578 }
Forest Bond5449c682009-04-25 10:30:44 -04001579
Joe Perchesd4945f02013-03-18 10:44:40 -07001580 // init state, all RD is chip's
1581 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1582 pDesc = &(pDevice->aRD1Ring[uu]);
1583 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1584 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1585 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1586 }
Forest Bond5449c682009-04-25 10:30:44 -04001587
Joe Perchesd4945f02013-03-18 10:44:40 -07001588 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1589 pDevice->cbFreeDFCB = pDevice->cbDFCB;
Forest Bond5449c682009-04-25 10:30:44 -04001590
Joe Perchesd4945f02013-03-18 10:44:40 -07001591 // set perPkt mode
1592 MACvRx0PerPktMode(pDevice->PortOffset);
1593 MACvRx1PerPktMode(pDevice->PortOffset);
1594 // set MAC RD pointer
1595 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1596 pDevice->rd0_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001597
Joe Perchesd4945f02013-03-18 10:44:40 -07001598 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1599 pDevice->rd1_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001600}
1601
Forest Bond5449c682009-04-25 10:30:44 -04001602/*
1603 * Description: Get response Control frame rate in CCK mode
1604 *
1605 * Parameters:
1606 * In:
1607 * pDevice - The adapter to be set
1608 * wRateIdx - Receiving data rate
1609 * Out:
1610 * none
1611 *
1612 * Return Value: response Control frame rate
1613 *
1614 */
Charles Clément2986db52010-06-24 11:02:26 -07001615unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001616{
Joe Perchesd4945f02013-03-18 10:44:40 -07001617 PSDevice pDevice = (PSDevice) pDeviceHandler;
1618 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001619
Joe Perchesd4945f02013-03-18 10:44:40 -07001620 while (ui > RATE_1M) {
1621 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1622 return (unsigned short)ui;
1623 }
1624 ui--;
1625 }
1626 return (unsigned short)RATE_1M;
Forest Bond5449c682009-04-25 10:30:44 -04001627}
1628
1629/*
1630 * Description: Get response Control frame rate in OFDM mode
1631 *
1632 * Parameters:
1633 * In:
1634 * pDevice - The adapter to be set
1635 * wRateIdx - Receiving data rate
1636 * Out:
1637 * none
1638 *
1639 * Return Value: response Control frame rate
1640 *
1641 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001642unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001643{
Joe Perchesd4945f02013-03-18 10:44:40 -07001644 PSDevice pDevice = (PSDevice) pDeviceHandler;
1645 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001646
Joe Perchesd4945f02013-03-18 10:44:40 -07001647 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate);
Forest Bond5449c682009-04-25 10:30:44 -04001648
Joe Perchesd4945f02013-03-18 10:44:40 -07001649 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1650 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1651 if (wRateIdx > RATE_24M)
1652 wRateIdx = RATE_24M;
1653 return wRateIdx;
1654 }
1655 while (ui > RATE_11M) {
1656 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui);
1658 return (unsigned short)ui;
1659 }
1660 ui--;
1661 }
1662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n");
1663 return (unsigned short)RATE_24M;
Forest Bond5449c682009-04-25 10:30:44 -04001664}
1665
Forest Bond5449c682009-04-25 10:30:44 -04001666/*
1667 * Description: Set RSPINF
1668 *
1669 * Parameters:
1670 * In:
1671 * pDevice - The adapter to be set
1672 * Out:
1673 * none
1674 *
1675 * Return Value: None.
1676 *
1677 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001678void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
Forest Bond5449c682009-04-25 10:30:44 -04001679{
Joe Perchesd4945f02013-03-18 10:44:40 -07001680 PSDevice pDevice = (PSDevice) pDeviceHandler;
1681 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1682 unsigned short wLen = 0x0000;
1683 unsigned char byTxRate, byRsvTime; //For OFDM
Forest Bond5449c682009-04-25 10:30:44 -04001684
Joe Perchesd4945f02013-03-18 10:44:40 -07001685 //Set to Page1
1686 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001687
Joe Perchesd4945f02013-03-18 10:44:40 -07001688 //RSPINF_b_1
1689 BBvCalculateParameter(pDevice,
1690 14,
1691 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1692 PK_TYPE_11B,
1693 &wLen,
1694 &byServ,
1695 &bySignal
1696);
Forest Bond5449c682009-04-25 10:30:44 -04001697
Joe Perchesd4945f02013-03-18 10:44:40 -07001698 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1699 ///RSPINF_b_2
1700 BBvCalculateParameter(pDevice,
1701 14,
1702 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1703 PK_TYPE_11B,
1704 &wLen,
1705 &byServ,
1706 &bySignal
1707);
Forest Bond5449c682009-04-25 10:30:44 -04001708
Joe Perchesd4945f02013-03-18 10:44:40 -07001709 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1710 //RSPINF_b_5
1711 BBvCalculateParameter(pDevice,
1712 14,
1713 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1714 PK_TYPE_11B,
1715 &wLen,
1716 &byServ,
1717 &bySignal
1718);
Forest Bond5449c682009-04-25 10:30:44 -04001719
Joe Perchesd4945f02013-03-18 10:44:40 -07001720 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1721 //RSPINF_b_11
1722 BBvCalculateParameter(pDevice,
1723 14,
1724 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1725 PK_TYPE_11B,
1726 &wLen,
1727 &byServ,
1728 &bySignal
1729);
Forest Bond5449c682009-04-25 10:30:44 -04001730
Joe Perchesd4945f02013-03-18 10:44:40 -07001731 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1732 //RSPINF_a_6
1733 s_vCalculateOFDMRParameter(RATE_6M,
1734 ePHYType,
1735 &byTxRate,
1736 &byRsvTime);
1737 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1738 //RSPINF_a_9
1739 s_vCalculateOFDMRParameter(RATE_9M,
1740 ePHYType,
1741 &byTxRate,
1742 &byRsvTime);
1743 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1744 //RSPINF_a_12
1745 s_vCalculateOFDMRParameter(RATE_12M,
1746 ePHYType,
1747 &byTxRate,
1748 &byRsvTime);
1749 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1750 //RSPINF_a_18
1751 s_vCalculateOFDMRParameter(RATE_18M,
1752 ePHYType,
1753 &byTxRate,
1754 &byRsvTime);
1755 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1756 //RSPINF_a_24
1757 s_vCalculateOFDMRParameter(RATE_24M,
1758 ePHYType,
1759 &byTxRate,
1760 &byRsvTime);
1761 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1762 //RSPINF_a_36
1763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1764 ePHYType,
1765 &byTxRate,
1766 &byRsvTime);
1767 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1768 //RSPINF_a_48
1769 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1770 ePHYType,
1771 &byTxRate,
1772 &byRsvTime);
1773 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1774 //RSPINF_a_54
1775 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1776 ePHYType,
1777 &byTxRate,
1778 &byRsvTime);
1779 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
Forest Bond5449c682009-04-25 10:30:44 -04001780
Joe Perchesd4945f02013-03-18 10:44:40 -07001781 //RSPINF_a_72
1782 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1783 ePHYType,
1784 &byTxRate,
1785 &byRsvTime);
1786 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1787 //Set to Page0
1788 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001789}
1790
1791/*
1792 * Description: Update IFS
1793 *
1794 * Parameters:
1795 * In:
1796 * pDevice - The adapter to be set
1797 * Out:
1798 * none
1799 *
1800 * Return Value: None.
1801 *
1802 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001803void vUpdateIFS(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001804{
Joe Perchesd4945f02013-03-18 10:44:40 -07001805 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1806 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001807
Joe Perchesd4945f02013-03-18 10:44:40 -07001808 unsigned char byMaxMin = 0;
1809 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1810 pDevice->uSlot = C_SLOT_SHORT;
1811 pDevice->uSIFS = C_SIFS_A;
1812 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1813 pDevice->uCwMin = C_CWMIN_A;
1814 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001815 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
Joe Perchesd4945f02013-03-18 10:44:40 -07001816 pDevice->uSlot = C_SLOT_LONG;
1817 pDevice->uSIFS = C_SIFS_BG;
1818 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1819 pDevice->uCwMin = C_CWMIN_B;
1820 byMaxMin = 5;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001821 } else { // PK_TYPE_11GA & PK_TYPE_11GB
Joe Perchesd4945f02013-03-18 10:44:40 -07001822 pDevice->uSIFS = C_SIFS_BG;
1823 if (pDevice->bShortSlotTime) {
1824 pDevice->uSlot = C_SLOT_SHORT;
1825 } else {
1826 pDevice->uSlot = C_SLOT_LONG;
1827 }
1828 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1829 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1830 pDevice->uCwMin = C_CWMIN_A;
1831 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001832 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07001833 pDevice->uCwMin = C_CWMIN_B;
1834 byMaxMin = 5;
1835 }
1836 }
Forest Bond5449c682009-04-25 10:30:44 -04001837
Joe Perchesd4945f02013-03-18 10:44:40 -07001838 pDevice->uCwMax = C_CWMAX;
1839 pDevice->uEIFS = C_EIFS;
1840 if (pDevice->byRFType == RF_RFMD2959) {
1841 // bcs TX_PE will reserve 3 us
1842 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1843 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1844 } else {
1845 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1846 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1847 }
1848 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1849 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1850 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1851 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
Forest Bond5449c682009-04-25 10:30:44 -04001852}
1853
Joe Perchesd4945f02013-03-18 10:44:40 -07001854void CARDvUpdateBasicTopRate(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001855{
Joe Perchesd4945f02013-03-18 10:44:40 -07001856 PSDevice pDevice = (PSDevice) pDeviceHandler;
1857 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1858 unsigned char ii;
Forest Bond5449c682009-04-25 10:30:44 -04001859
Joe Perchesd4945f02013-03-18 10:44:40 -07001860 //Determines the highest basic rate.
1861 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1862 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1863 byTopOFDM = ii;
1864 break;
1865 }
1866 }
1867 pDevice->byTopOFDMBasicRate = byTopOFDM;
Forest Bond5449c682009-04-25 10:30:44 -04001868
Joe Perchesd4945f02013-03-18 10:44:40 -07001869 for (ii = RATE_11M;; ii--) {
1870 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1871 byTopCCK = ii;
1872 break;
1873 }
1874 if (ii == RATE_1M)
1875 break;
1876 }
1877 pDevice->byTopCCKBasicRate = byTopCCK;
Forest Bond5449c682009-04-25 10:30:44 -04001878}
1879
Forest Bond5449c682009-04-25 10:30:44 -04001880/*
1881 * Description: Set NIC Tx Basic Rate
1882 *
1883 * Parameters:
1884 * In:
1885 * pDevice - The adapter to be set
1886 * wBasicRate - Basic Rate to be set
1887 * Out:
1888 * none
1889 *
Charles Clément5a5a2a62010-08-01 17:15:49 +02001890 * Return Value: true if succeeded; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -04001891 *
1892 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001893bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001894{
Joe Perchesd4945f02013-03-18 10:44:40 -07001895 PSDevice pDevice = (PSDevice) pDeviceHandler;
1896 unsigned short wRate = (unsigned short)(1<<wRateIdx);
Forest Bond5449c682009-04-25 10:30:44 -04001897
Joe Perchesd4945f02013-03-18 10:44:40 -07001898 pDevice->wBasicRate |= wRate;
Forest Bond5449c682009-04-25 10:30:44 -04001899
Joe Perchesd4945f02013-03-18 10:44:40 -07001900 //Determines the highest basic rate.
1901 CARDvUpdateBasicTopRate((void *)pDevice);
Forest Bond5449c682009-04-25 10:30:44 -04001902
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001903 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001904}
1905
Joe Perchesd4945f02013-03-18 10:44:40 -07001906bool CARDbIsOFDMinBasicRate(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001907{
Joe Perchesd4945f02013-03-18 10:44:40 -07001908 PSDevice pDevice = (PSDevice)pDeviceHandler;
1909 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001910
Joe Perchesd4945f02013-03-18 10:44:40 -07001911 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1912 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1913 return true;
1914 }
1915 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001916}
1917
Joe Perchesd4945f02013-03-18 10:44:40 -07001918unsigned char CARDbyGetPktType(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001919{
Joe Perchesd4945f02013-03-18 10:44:40 -07001920 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001921
Joe Perchesd4945f02013-03-18 10:44:40 -07001922 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
1923 return (unsigned char)pDevice->byBBType;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001924 } else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001925 return PK_TYPE_11GA;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001926 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07001927 return PK_TYPE_11GB;
1928 }
Forest Bond5449c682009-04-25 10:30:44 -04001929}
1930
1931/*
1932 * Description: Set NIC Loopback mode
1933 *
1934 * Parameters:
1935 * In:
1936 * pDevice - The adapter to be set
1937 * wLoopbackMode - Loopback mode to be set
1938 * Out:
1939 * none
1940 *
1941 * Return Value: none
1942 *
1943 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001944void CARDvSetLoopbackMode(unsigned long dwIoBase, unsigned short wLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -04001945{
Joe Perchesd4945f02013-03-18 10:44:40 -07001946 switch (wLoopbackMode) {
1947 case CARD_LB_NONE:
1948 case CARD_LB_MAC:
1949 case CARD_LB_PHY:
1950 break;
1951 default:
1952 ASSERT(false);
1953 break;
1954 }
1955 // set MAC loopback
1956 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1957 // set Baseband loopback
Forest Bond5449c682009-04-25 10:30:44 -04001958}
1959
Forest Bond5449c682009-04-25 10:30:44 -04001960/*
1961 * Description: Software Reset NIC
1962 *
1963 * Parameters:
1964 * In:
1965 * pDevice - The adapter to be reset
1966 * Out:
1967 * none
1968 *
1969 * Return Value: none
1970 *
1971 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001972bool CARDbSoftwareReset(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001973{
Joe Perchesd4945f02013-03-18 10:44:40 -07001974 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001975
Joe Perchesd4945f02013-03-18 10:44:40 -07001976 // reset MAC
1977 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1978 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001979
Joe Perchesd4945f02013-03-18 10:44:40 -07001980 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001981}
1982
Forest Bond5449c682009-04-25 10:30:44 -04001983/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -07001984 * Description: Calculate TSF offset of two TSF input
Forest Bond5449c682009-04-25 10:30:44 -04001985 * Get TSF Offset from RxBCN's TSF and local TSF
1986 *
1987 * Parameters:
1988 * In:
1989 * pDevice - The adapter to be sync.
1990 * qwTSF1 - Rx BCN's TSF
1991 * qwTSF2 - Local TSF
1992 * Out:
1993 * none
1994 *
1995 * Return Value: TSF Offset value
1996 *
1997 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001998QWORD CARDqGetTSFOffset(unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
Forest Bond5449c682009-04-25 10:30:44 -04001999{
Joe Perchesd4945f02013-03-18 10:44:40 -07002000 QWORD qwTSFOffset;
2001 unsigned short wRxBcnTSFOffst = 0;
Forest Bond5449c682009-04-25 10:30:44 -04002002
Joe Perchesd4945f02013-03-18 10:44:40 -07002003 HIDWORD(qwTSFOffset) = 0;
2004 LODWORD(qwTSFOffset) = 0;
2005 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
2006 (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
2007 if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
2008 (qwTSF2).u.dwHighDword++;
2009 }
2010 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
2011 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
2012 // if borrow needed
2013 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07002014 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07002015 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
2016 };
Joe Perchesa4ef27a2013-03-18 20:55:38 -07002017 return qwTSFOffset;
Forest Bond5449c682009-04-25 10:30:44 -04002018}
2019
Forest Bond5449c682009-04-25 10:30:44 -04002020/*
2021 * Description: Read NIC TSF counter
2022 * Get local TSF counter
2023 *
2024 * Parameters:
2025 * In:
2026 * pDevice - The adapter to be read
2027 * Out:
2028 * qwCurrTSF - Current TSF counter
2029 *
Charles Clément5a5a2a62010-08-01 17:15:49 +02002030 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -04002031 *
2032 */
Joe Perchesd4945f02013-03-18 10:44:40 -07002033bool CARDbGetCurrentTSF(unsigned long dwIoBase, PQWORD pqwCurrTSF)
Forest Bond5449c682009-04-25 10:30:44 -04002034{
Joe Perchesd4945f02013-03-18 10:44:40 -07002035 unsigned short ww;
2036 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -04002037
Joe Perchesd4945f02013-03-18 10:44:40 -07002038 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
2039 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
2040 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
2041 if (!(byData & TFTCTL_TSFCNTRRD))
2042 break;
2043 }
2044 if (ww == W_MAX_TIMEOUT)
Joe Perchesa4ef27a2013-03-18 20:55:38 -07002045 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -07002046 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
2047 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
Forest Bond5449c682009-04-25 10:30:44 -04002048
Joe Perchesa4ef27a2013-03-18 20:55:38 -07002049 return true;
Forest Bond5449c682009-04-25 10:30:44 -04002050}
2051
Forest Bond5449c682009-04-25 10:30:44 -04002052/*
2053 * Description: Read NIC TSF counter
2054 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2055 *
2056 * Parameters:
2057 * In:
2058 * qwTSF - Current TSF counter
2059 * wbeaconInterval - Beacon Interval
2060 * Out:
2061 * qwCurrTSF - Current TSF counter
2062 *
2063 * Return Value: TSF value of next Beacon
2064 *
2065 */
Joe Perchesd4945f02013-03-18 10:44:40 -07002066QWORD CARDqGetNextTBTT(QWORD qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002067{
Joe Perchesd4945f02013-03-18 10:44:40 -07002068 unsigned int uLowNextTBTT;
2069 unsigned int uHighRemain, uLowRemain;
2070 unsigned int uBeaconInterval;
Forest Bond5449c682009-04-25 10:30:44 -04002071
Joe Perchesd4945f02013-03-18 10:44:40 -07002072 uBeaconInterval = wBeaconInterval * 1024;
2073 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
2074 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
2075 // low dword (mod) bcn
2076 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
Forest Bond5449c682009-04-25 10:30:44 -04002077// uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
2078// % uBeaconInterval;
Joe Perchesd4945f02013-03-18 10:44:40 -07002079 // high dword (mod) bcn
2080 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
2081 % uBeaconInterval;
2082 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2083 uLowRemain = uBeaconInterval - uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -04002084
Joe Perchesd4945f02013-03-18 10:44:40 -07002085 // check if carry when add one beacon interval
2086 if ((~uLowNextTBTT) < uLowRemain)
2087 HIDWORD(qwTSF)++;
Forest Bond5449c682009-04-25 10:30:44 -04002088
Joe Perchesd4945f02013-03-18 10:44:40 -07002089 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -04002090
Joe Perchesa4ef27a2013-03-18 20:55:38 -07002091 return qwTSF;
Forest Bond5449c682009-04-25 10:30:44 -04002092}
2093
Forest Bond5449c682009-04-25 10:30:44 -04002094/*
2095 * Description: Set NIC TSF counter for first Beacon time
2096 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2097 *
2098 * Parameters:
2099 * In:
2100 * dwIoBase - IO Base
2101 * wBeaconInterval - Beacon Interval
2102 * Out:
2103 * none
2104 *
2105 * Return Value: none
2106 *
2107 */
Joe Perchesd4945f02013-03-18 10:44:40 -07002108void CARDvSetFirstNextTBTT(unsigned long dwIoBase, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002109{
Joe Perchesd4945f02013-03-18 10:44:40 -07002110 QWORD qwNextTBTT;
Forest Bond5449c682009-04-25 10:30:44 -04002111
Joe Perchesd4945f02013-03-18 10:44:40 -07002112 HIDWORD(qwNextTBTT) = 0;
2113 LODWORD(qwNextTBTT) = 0;
2114 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
2115 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2116 // Set NextTBTT
2117 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
2118 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
2119 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2120 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
2121 return;
Forest Bond5449c682009-04-25 10:30:44 -04002122}
2123
Forest Bond5449c682009-04-25 10:30:44 -04002124/*
2125 * Description: Sync NIC TSF counter for Beacon time
2126 * Get NEXTTBTT and write to HW
2127 *
2128 * Parameters:
2129 * In:
2130 * pDevice - The adapter to be set
2131 * qwTSF - Current TSF counter
2132 * wBeaconInterval - Beacon Interval
2133 * Out:
2134 * none
2135 *
2136 * Return Value: none
2137 *
2138 */
Joe Perchesd4945f02013-03-18 10:44:40 -07002139void CARDvUpdateNextTBTT(unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002140{
Joe Perchesd4945f02013-03-18 10:44:40 -07002141 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2142 // Set NextTBTT
2143 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
2144 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
2145 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8xh:%8xh] \n",
2147 (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
Forest Bond5449c682009-04-25 10:30:44 -04002148
Joe Perchesd4945f02013-03-18 10:44:40 -07002149 return;
Forest Bond5449c682009-04-25 10:30:44 -04002150}