blob: e29dcd85f5d105b325037f751a6d75dd03ac1c1b [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
Forest Bond5449c682009-04-25 10:30:44 -040027 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
28 * CARDvSetLoopbackMode - Set Loopback mode
29 * CARDbSoftwareReset - Sortware reset NIC
Justin P. Mattock7664ec82012-08-20 08:43:15 -070030 * CARDqGetTSFOffset - Calculate TSFOffset
Forest Bond5449c682009-04-25 10:30:44 -040031 * CARDbGetCurrentTSF - Read Current NIC TSF counter
Justin P. Mattock7664ec82012-08-20 08:43:15 -070032 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
Forest Bond5449c682009-04-25 10:30:44 -040033 * CARDvSetFirstNextTBTT - Set NIC Beacon time
34 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
35 * CARDbRadioPowerOff - Turn Off NIC Radio Power
36 * CARDbRadioPowerOn - Turn On NIC Radio Power
37 * CARDbSetWEPMode - Set NIC Wep mode
38 * CARDbSetTxPower - Set NIC tx power
39 *
40 * Revision History:
41 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
42 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
43 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
44 *
45 */
46
Forest Bond5449c682009-04-25 10:30:44 -040047#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040048#include "card.h"
Forest Bond5449c682009-04-25 10:30:44 -040049#include "baseband.h"
Forest Bond5449c682009-04-25 10:30:44 -040050#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040051#include "desc.h"
Forest Bond5449c682009-04-25 10:30:44 -040052#include "rf.h"
Forest Bond5449c682009-04-25 10:30:44 -040053#include "vntwifi.h"
Forest Bond5449c682009-04-25 10:30:44 -040054#include "power.h"
Forest Bond5449c682009-04-25 10:30:44 -040055#include "key.h"
Forest Bond5449c682009-04-25 10:30:44 -040056#include "rc4.h"
Forest Bond5449c682009-04-25 10:30:44 -040057#include "country.h"
Charles Clément79566eb2010-06-21 10:39:51 -070058#include "channel.h"
Forest Bond5449c682009-04-25 10:30:44 -040059
60/*--------------------- Static Definitions -------------------------*/
61
Joe Perchesd4945f02013-03-18 10:44:40 -070062static int msglevel = MSG_LEVEL_INFO;
Forest Bond5449c682009-04-25 10:30:44 -040063
64#define C_SIFS_A 16 // micro sec.
65#define C_SIFS_BG 10
66
67#define C_EIFS 80 // micro sec.
68
Forest Bond5449c682009-04-25 10:30:44 -040069#define C_SLOT_SHORT 9 // micro sec.
70#define C_SLOT_LONG 20
71
72#define C_CWMIN_A 15 // slot time
73#define C_CWMIN_B 31
74
75#define C_CWMAX 1023 // slot time
76
Forest Bond5449c682009-04-25 10:30:44 -040077#define WAIT_BEACON_TX_DOWN_TMO 3 // Times
78
Joe Perchesd4945f02013-03-18 10:44:40 -070079//1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
Charles Clément3fc9b582010-06-24 11:02:27 -070080static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
Joe Perchesd4945f02013-03-18 10:44:40 -070081//6M, 9M, 12M, 48M
Charles Clément3fc9b582010-06-24 11:02:27 -070082static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
Joe Perchesd4945f02013-03-18 10:44:40 -070083//6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
Charles Clément3fc9b582010-06-24 11:02:27 -070084static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
Joe Perchesd4945f02013-03-18 10:44:40 -070085//1M, 2M, 5M, 11M,
Charles Clément3fc9b582010-06-24 11:02:27 -070086static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
Forest Bond5449c682009-04-25 10:30:44 -040087
Forest Bond5449c682009-04-25 10:30:44 -040088/*--------------------- Static Variables --------------------------*/
89
Guillaume Clement9e4c5c22014-07-22 22:08:28 +020090static const unsigned short cwRXBCNTSFOff[MAX_RATE] =
Forest Bond5449c682009-04-25 10:30:44 -040091{17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
92
Forest Bond5449c682009-04-25 10:30:44 -040093/*--------------------- Static Functions --------------------------*/
94
95static
Charles Clément6b35b7b2010-05-07 12:30:19 -070096void
Justin P. Mattock7664ec82012-08-20 08:43:15 -070097s_vCalculateOFDMRParameter(
Joe Perchesd4945f02013-03-18 10:44:40 -070098 unsigned char byRate,
99 CARD_PHY_TYPE ePHYType,
100 unsigned char *pbyTxRate,
101 unsigned char *pbyRsvTime
102);
Forest Bond5449c682009-04-25 10:30:44 -0400103
Forest Bond5449c682009-04-25 10:30:44 -0400104/*--------------------- Export Functions --------------------------*/
105
Forest Bond5449c682009-04-25 10:30:44 -0400106/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -0700107 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond5449c682009-04-25 10:30:44 -0400108 *
109 * Parameters:
110 * In:
111 * wRate - Tx Rate
112 * byPktType - Tx Packet type
113 * Out:
114 * pbyTxRate - pointer to RSPINF TxRate field
115 * pbyRsvTime - pointer to RSPINF RsvTime field
116 *
117 * Return Value: none
118 *
119 */
120static
Charles Clément6b35b7b2010-05-07 12:30:19 -0700121void
Joe Perchesd4945f02013-03-18 10:44:40 -0700122s_vCalculateOFDMRParameter(
123 unsigned char byRate,
124 CARD_PHY_TYPE ePHYType,
125 unsigned char *pbyTxRate,
126 unsigned char *pbyRsvTime
127)
Forest Bond5449c682009-04-25 10:30:44 -0400128{
Joe Perchesd4945f02013-03-18 10:44:40 -0700129 switch (byRate) {
130 case RATE_6M:
131 if (ePHYType == PHY_TYPE_11A) {//5GHZ
132 *pbyTxRate = 0x9B;
133 *pbyRsvTime = 44;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700134 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700135 *pbyTxRate = 0x8B;
136 *pbyRsvTime = 50;
137 }
138 break;
Forest Bond5449c682009-04-25 10:30:44 -0400139
Joe Perchesd4945f02013-03-18 10:44:40 -0700140 case RATE_9M:
141 if (ePHYType == PHY_TYPE_11A) {//5GHZ
142 *pbyTxRate = 0x9F;
143 *pbyRsvTime = 36;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700144 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700145 *pbyTxRate = 0x8F;
146 *pbyRsvTime = 42;
147 }
148 break;
Forest Bond5449c682009-04-25 10:30:44 -0400149
Joe Perchesd4945f02013-03-18 10:44:40 -0700150 case RATE_12M:
151 if (ePHYType == PHY_TYPE_11A) {//5GHZ
152 *pbyTxRate = 0x9A;
153 *pbyRsvTime = 32;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700154 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700155 *pbyTxRate = 0x8A;
156 *pbyRsvTime = 38;
157 }
158 break;
Forest Bond5449c682009-04-25 10:30:44 -0400159
Joe Perchesd4945f02013-03-18 10:44:40 -0700160 case RATE_18M:
161 if (ePHYType == PHY_TYPE_11A) {//5GHZ
162 *pbyTxRate = 0x9E;
163 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700164 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700165 *pbyTxRate = 0x8E;
166 *pbyRsvTime = 34;
167 }
168 break;
Forest Bond5449c682009-04-25 10:30:44 -0400169
Joe Perchesd4945f02013-03-18 10:44:40 -0700170 case RATE_36M:
171 if (ePHYType == PHY_TYPE_11A) {//5GHZ
172 *pbyTxRate = 0x9D;
173 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700174 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700175 *pbyTxRate = 0x8D;
176 *pbyRsvTime = 30;
177 }
178 break;
Forest Bond5449c682009-04-25 10:30:44 -0400179
Joe Perchesd4945f02013-03-18 10:44:40 -0700180 case RATE_48M:
181 if (ePHYType == PHY_TYPE_11A) {//5GHZ
182 *pbyTxRate = 0x98;
183 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700184 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700185 *pbyTxRate = 0x88;
186 *pbyRsvTime = 30;
187 }
188 break;
Forest Bond5449c682009-04-25 10:30:44 -0400189
Joe Perchesd4945f02013-03-18 10:44:40 -0700190 case RATE_54M:
191 if (ePHYType == PHY_TYPE_11A) {//5GHZ
192 *pbyTxRate = 0x9C;
193 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700194 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700195 *pbyTxRate = 0x8C;
196 *pbyRsvTime = 30;
197 }
198 break;
Forest Bond5449c682009-04-25 10:30:44 -0400199
Joe Perchesd4945f02013-03-18 10:44:40 -0700200 case RATE_24M:
201 default:
202 if (ePHYType == PHY_TYPE_11A) {//5GHZ
203 *pbyTxRate = 0x99;
204 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700205 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700206 *pbyTxRate = 0x89;
207 *pbyRsvTime = 34;
208 }
209 break;
210 }
Forest Bond5449c682009-04-25 10:30:44 -0400211}
212
Forest Bond5449c682009-04-25 10:30:44 -0400213/*
214 * Description: Set RSPINF
215 *
216 * Parameters:
217 * In:
218 * pDevice - The adapter to be set
219 * Out:
220 * none
221 *
222 * Return Value: None.
223 *
224 */
225static
Charles Clément6b35b7b2010-05-07 12:30:19 -0700226void
Joe Perchesd4945f02013-03-18 10:44:40 -0700227s_vSetRSPINF(PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
Forest Bond5449c682009-04-25 10:30:44 -0400228{
Joe Perchesd4945f02013-03-18 10:44:40 -0700229 unsigned char byServ = 0, bySignal = 0; // For CCK
230 unsigned short wLen = 0;
231 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
Forest Bond5449c682009-04-25 10:30:44 -0400232
Joe Perchesd4945f02013-03-18 10:44:40 -0700233 //Set to Page1
234 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400235
Joe Perchesd4945f02013-03-18 10:44:40 -0700236 //RSPINF_b_1
237 BBvCalculateParameter(pDevice,
238 14,
239 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
240 PK_TYPE_11B,
241 &wLen,
242 &byServ,
243 &bySignal
244);
Forest Bond5449c682009-04-25 10:30:44 -0400245
Joe Perchesd4945f02013-03-18 10:44:40 -0700246 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
247 ///RSPINF_b_2
248 BBvCalculateParameter(pDevice,
249 14,
250 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
251 PK_TYPE_11B,
252 &wLen,
253 &byServ,
254 &bySignal
255);
Forest Bond5449c682009-04-25 10:30:44 -0400256
Joe Perchesd4945f02013-03-18 10:44:40 -0700257 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
258 //RSPINF_b_5
259 BBvCalculateParameter(pDevice,
260 14,
261 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
262 PK_TYPE_11B,
263 &wLen,
264 &byServ,
265 &bySignal
266);
Forest Bond5449c682009-04-25 10:30:44 -0400267
Joe Perchesd4945f02013-03-18 10:44:40 -0700268 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
269 //RSPINF_b_11
270 BBvCalculateParameter(pDevice,
271 14,
272 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
273 PK_TYPE_11B,
274 &wLen,
275 &byServ,
276 &bySignal
277);
Forest Bond5449c682009-04-25 10:30:44 -0400278
Joe Perchesd4945f02013-03-18 10:44:40 -0700279 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
280 //RSPINF_a_6
281 s_vCalculateOFDMRParameter(RATE_6M,
282 ePHYType,
283 &byTxRate,
284 &byRsvTime);
285 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
286 //RSPINF_a_9
287 s_vCalculateOFDMRParameter(RATE_9M,
288 ePHYType,
289 &byTxRate,
290 &byRsvTime);
291 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
292 //RSPINF_a_12
293 s_vCalculateOFDMRParameter(RATE_12M,
294 ePHYType,
295 &byTxRate,
296 &byRsvTime);
297 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
298 //RSPINF_a_18
299 s_vCalculateOFDMRParameter(RATE_18M,
300 ePHYType,
301 &byTxRate,
302 &byRsvTime);
303 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
304 //RSPINF_a_24
305 s_vCalculateOFDMRParameter(RATE_24M,
306 ePHYType,
307 &byTxRate,
308 &byRsvTime);
309 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
310 //RSPINF_a_36
311 s_vCalculateOFDMRParameter(
312 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
313 ePHYType,
314 &byTxRate,
315 &byRsvTime);
316 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
317 //RSPINF_a_48
318 s_vCalculateOFDMRParameter(
319 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
320 ePHYType,
321 &byTxRate,
322 &byRsvTime);
323 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
324 //RSPINF_a_54
325 s_vCalculateOFDMRParameter(
326 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
327 ePHYType,
328 &byTxRate,
329 &byRsvTime);
330 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
331 //RSPINF_a_72
332 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
333 //Set to Page0
334 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400335}
336
Forest Bond5449c682009-04-25 10:30:44 -0400337/*--------------------- Export Functions --------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -0400338
339/*
Forest Bond5449c682009-04-25 10:30:44 -0400340 * Description: Get Card short preamble option value
341 *
342 * Parameters:
343 * In:
344 * pDevice - The adapter to be set
345 * Out:
346 * none
347 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200348 * Return Value: true if short preamble; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400349 *
350 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700351bool CARDbIsShortPreamble(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400352{
Joe Perchesd4945f02013-03-18 10:44:40 -0700353 PSDevice pDevice = (PSDevice) pDeviceHandler;
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300354
Guido Martínezbc5cf652014-04-19 16:45:00 -0300355 if (pDevice->byPreambleType == 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700356 return false;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300357
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700358 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400359}
360
361/*
362 * Description: Get Card short slot time option value
363 *
364 * Parameters:
365 * In:
366 * pDevice - The adapter to be set
367 * Out:
368 * none
369 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200370 * Return Value: true if short slot time; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400371 *
372 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700373bool CARDbIsShorSlotTime(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400374{
Joe Perchesd4945f02013-03-18 10:44:40 -0700375 PSDevice pDevice = (PSDevice) pDeviceHandler;
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300376
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700377 return pDevice->bShortSlotTime;
Forest Bond5449c682009-04-25 10:30:44 -0400378}
379
Forest Bond5449c682009-04-25 10:30:44 -0400380/*
381 * Description: Update IFS
382 *
383 * Parameters:
384 * In:
385 * pDevice - The adapter to be set
386 * Out:
387 * none
388 *
389 * Return Value: None.
390 *
391 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700392bool CARDbSetPhyParameter(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
Forest Bond5449c682009-04-25 10:30:44 -0400393{
Joe Perchesd4945f02013-03-18 10:44:40 -0700394 PSDevice pDevice = (PSDevice) pDeviceHandler;
395 unsigned char byCWMaxMin = 0;
396 unsigned char bySlot = 0;
397 unsigned char bySIFS = 0;
398 unsigned char byDIFS = 0;
399 unsigned char byData;
Joe Perchesd4945f02013-03-18 10:44:40 -0700400 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
401 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
Forest Bond5449c682009-04-25 10:30:44 -0400402
Joe Perchesd4945f02013-03-18 10:44:40 -0700403 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
404 if (ePHYType == PHY_TYPE_11A) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300405 if (pSupportRates == NULL)
Joe Perchesd4945f02013-03-18 10:44:40 -0700406 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300407
Joe Perchesd4945f02013-03-18 10:44:40 -0700408 if (pDevice->byRFType == RF_AIROHA7230) {
409 // AL7230 use single PAPE and connect to PAPE_2.4G
410 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
411 pDevice->abyBBVGA[0] = 0x20;
412 pDevice->abyBBVGA[2] = 0x10;
413 pDevice->abyBBVGA[3] = 0x10;
414 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300415 if (byData == 0x1C)
Joe Perchesd4945f02013-03-18 10:44:40 -0700416 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300417
Joe Perchesd4945f02013-03-18 10:44:40 -0700418 } else if (pDevice->byRFType == RF_UW2452) {
419 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
420 pDevice->abyBBVGA[0] = 0x18;
421 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
422 if (byData == 0x14) {
423 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
424 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
425 }
426 } else {
427 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
428 }
429 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
430 bySlot = C_SLOT_SHORT;
431 bySIFS = C_SIFS_A;
432 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
433 byCWMaxMin = 0xA4;
434 } else if (ePHYType == PHY_TYPE_11B) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300435 if (pSupportRates == NULL)
Joe Perchesd4945f02013-03-18 10:44:40 -0700436 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300437
Joe Perchesd4945f02013-03-18 10:44:40 -0700438 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
439 if (pDevice->byRFType == RF_AIROHA7230) {
440 pDevice->abyBBVGA[0] = 0x1C;
441 pDevice->abyBBVGA[2] = 0x00;
442 pDevice->abyBBVGA[3] = 0x00;
443 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300444 if (byData == 0x20)
Joe Perchesd4945f02013-03-18 10:44:40 -0700445 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300446
Joe Perchesd4945f02013-03-18 10:44:40 -0700447 } else if (pDevice->byRFType == RF_UW2452) {
448 pDevice->abyBBVGA[0] = 0x14;
449 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
450 if (byData == 0x18) {
451 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
452 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
453 }
454 }
455 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
456 bySlot = C_SLOT_LONG;
457 bySIFS = C_SIFS_BG;
458 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
459 byCWMaxMin = 0xA5;
460 } else {// PK_TYPE_11GA & PK_TYPE_11GB
461 if (pSupportRates == NULL) {
462 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
463 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
464 }
465 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
466 if (pDevice->byRFType == RF_AIROHA7230) {
467 pDevice->abyBBVGA[0] = 0x1C;
468 pDevice->abyBBVGA[2] = 0x00;
469 pDevice->abyBBVGA[3] = 0x00;
470 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300471 if (byData == 0x20)
Joe Perchesd4945f02013-03-18 10:44:40 -0700472 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300473
Joe Perchesd4945f02013-03-18 10:44:40 -0700474 } else if (pDevice->byRFType == RF_UW2452) {
475 pDevice->abyBBVGA[0] = 0x14;
476 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
477 if (byData == 0x18) {
478 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
479 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
480 }
481 }
482 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
483 bySIFS = C_SIFS_BG;
484 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
485 bySlot = C_SLOT_SHORT;
486 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
487 } else {
488 bySlot = C_SLOT_LONG;
489 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
490 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300491 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M)
Joe Perchesd4945f02013-03-18 10:44:40 -0700492 byCWMaxMin = 0xA4;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300493 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700494 byCWMaxMin = 0xA5;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300495
Joe Perchesd4945f02013-03-18 10:44:40 -0700496 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
497 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300498 if (pDevice->bProtectMode)
Joe Perchesd4945f02013-03-18 10:44:40 -0700499 MACvEnableProtectMD(pDevice->PortOffset);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300500 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700501 MACvDisableProtectMD(pDevice->PortOffset);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300502
Joe Perchesd4945f02013-03-18 10:44:40 -0700503 }
504 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
505 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300506 if (pDevice->bBarkerPreambleMd)
Joe Perchesd4945f02013-03-18 10:44:40 -0700507 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300508 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700509 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
Joe Perchesd4945f02013-03-18 10:44:40 -0700510 }
511 }
Forest Bond5449c682009-04-25 10:30:44 -0400512
Joe Perchesd4945f02013-03-18 10:44:40 -0700513 if (pDevice->byRFType == RF_RFMD2959) {
514 // bcs TX_PE will reserve 3 us
515 // hardware's processing time here is 2 us.
516 bySIFS -= 3;
517 byDIFS -= 3;
518 //{{ RobertYu: 20041202
519 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
520 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
521 }
Forest Bond5449c682009-04-25 10:30:44 -0400522
Joe Perchesd4945f02013-03-18 10:44:40 -0700523 if (pDevice->bySIFS != bySIFS) {
524 pDevice->bySIFS = bySIFS;
525 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
526 }
527 if (pDevice->byDIFS != byDIFS) {
528 pDevice->byDIFS = byDIFS;
529 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
530 }
531 if (pDevice->byEIFS != C_EIFS) {
532 pDevice->byEIFS = C_EIFS;
533 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
534 }
535 if (pDevice->bySlot != bySlot) {
536 pDevice->bySlot = bySlot;
537 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300538 if (pDevice->bySlot == C_SLOT_SHORT)
Joe Perchesd4945f02013-03-18 10:44:40 -0700539 pDevice->bShortSlotTime = true;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300540 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700541 pDevice->bShortSlotTime = false;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300542
Joe Perchesd4945f02013-03-18 10:44:40 -0700543 BBvSetShortSlotTime(pDevice);
544 }
545 if (pDevice->byCWMaxMin != byCWMaxMin) {
546 pDevice->byCWMaxMin = byCWMaxMin;
547 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
548 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300549 if (VNTWIFIbIsShortPreamble(wCapInfo))
Joe Perchesd4945f02013-03-18 10:44:40 -0700550 pDevice->byPreambleType = pDevice->byShortPreamble;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300551 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700552 pDevice->byPreambleType = 0;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300553
Joe Perchesd4945f02013-03-18 10:44:40 -0700554 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
555 pDevice->eCurrentPHYType = ePHYType;
556 // set for NDIS OID_802_11SUPPORTED_RATES
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700557 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400558}
559
560/*
561 * Description: Sync. TSF counter to BSS
562 * Get TSF offset and write to HW
563 *
564 * Parameters:
565 * In:
566 * pDevice - The adapter to be sync.
567 * byRxRate - data rate of receive beacon
568 * qwBSSTimestamp - Rx BCN's TSF
569 * qwLocalTSF - Local TSF
570 * Out:
571 * none
572 *
573 * Return Value: none
574 *
575 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700576bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
Forest Bond5449c682009-04-25 10:30:44 -0400577{
Joe Perchesd4945f02013-03-18 10:44:40 -0700578 PSDevice pDevice = (PSDevice) pDeviceHandler;
579 QWORD qwTSFOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400580
Joe Perchesd4945f02013-03-18 10:44:40 -0700581 HIDWORD(qwTSFOffset) = 0;
582 LODWORD(qwTSFOffset) = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400583
Joe Perchesd4945f02013-03-18 10:44:40 -0700584 if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
585 (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
586 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
587 // adjust TSF
588 // HW's TSF add TSF Offset reg
589 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
590 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
591 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
592 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700593 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400594}
595
Forest Bond5449c682009-04-25 10:30:44 -0400596/*
597 * Description: Set NIC TSF counter for first Beacon time
598 * Get NEXTTBTT from adjusted TSF and Beacon Interval
599 *
600 * Parameters:
601 * In:
602 * pDevice - The adapter to be set.
603 * wBeaconInterval - Beacon Interval
604 * Out:
605 * none
606 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200607 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400608 *
609 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700610bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400611{
Joe Perchesd4945f02013-03-18 10:44:40 -0700612 PSDevice pDevice = (PSDevice) pDeviceHandler;
613 unsigned int uBeaconInterval = 0;
614 unsigned int uLowNextTBTT = 0;
615 unsigned int uHighRemain = 0;
616 unsigned int uLowRemain = 0;
617 QWORD qwNextTBTT;
Forest Bond5449c682009-04-25 10:30:44 -0400618
Joe Perchesd4945f02013-03-18 10:44:40 -0700619 HIDWORD(qwNextTBTT) = 0;
620 LODWORD(qwNextTBTT) = 0;
621 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
622 uBeaconInterval = wBeaconInterval * 1024;
623 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
624 uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
625 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
626 // high dword (mod) bcn
627 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
628 % uBeaconInterval;
629 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
630 uLowRemain = uBeaconInterval - uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -0400631
Joe Perchesd4945f02013-03-18 10:44:40 -0700632 // check if carry when add one beacon interval
Guido Martínezbc5cf652014-04-19 16:45:00 -0300633 if ((~uLowNextTBTT) < uLowRemain)
Joe Perchesd4945f02013-03-18 10:44:40 -0700634 HIDWORD(qwNextTBTT)++;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300635
Joe Perchesd4945f02013-03-18 10:44:40 -0700636 LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -0400637
Joe Perchesd4945f02013-03-18 10:44:40 -0700638 // set HW beacon interval
639 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
640 pDevice->wBeaconInterval = wBeaconInterval;
641 // Set NextTBTT
642 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
643 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
644 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -0400645
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700646 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400647}
648
Forest Bond5449c682009-04-25 10:30:44 -0400649/*
650 * Description: Card Stop Hardware Tx
651 *
652 * Parameters:
653 * In:
654 * pDeviceHandler - The adapter to be set
655 * ePktType - Packet type to stop
656 * Out:
657 * none
658 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200659 * Return Value: true if all data packet complete; otherwise false.
Forest Bond5449c682009-04-25 10:30:44 -0400660 *
661 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700662bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400663{
Joe Perchesd4945f02013-03-18 10:44:40 -0700664 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400665
Joe Perchesd4945f02013-03-18 10:44:40 -0700666 if (ePktType == PKT_TYPE_802_11_ALL) {
667 pDevice->bStopBeacon = true;
668 pDevice->bStopTx0Pkt = true;
669 pDevice->bStopDataPkt = true;
670 } else if (ePktType == PKT_TYPE_802_11_BCN) {
671 pDevice->bStopBeacon = true;
672 } else if (ePktType == PKT_TYPE_802_11_MNG) {
673 pDevice->bStopTx0Pkt = true;
674 } else if (ePktType == PKT_TYPE_802_11_DATA) {
675 pDevice->bStopDataPkt = true;
676 }
Forest Bond5449c682009-04-25 10:30:44 -0400677
Joe Perchesd4945f02013-03-18 10:44:40 -0700678 if (pDevice->bStopBeacon == true) {
679 if (pDevice->bIsBeaconBufReadySet == true) {
680 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
681 pDevice->cbBeaconBufReadySetCnt++;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700682 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700683 }
684 }
685 pDevice->bIsBeaconBufReadySet = false;
686 pDevice->cbBeaconBufReadySetCnt = 0;
687 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
688 }
689 // wait all TD0 complete
690 if (pDevice->bStopTx0Pkt == true) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300691 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700692 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700693 }
694 // wait all Data TD complete
695 if (pDevice->bStopDataPkt == true) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300696 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700697 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700698 }
Forest Bond5449c682009-04-25 10:30:44 -0400699
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700700 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400701}
702
Forest Bond5449c682009-04-25 10:30:44 -0400703/*
704 * Description: Card Start Hardware Tx
705 *
706 * Parameters:
707 * In:
708 * pDeviceHandler - The adapter to be set
709 * ePktType - Packet type to start
710 * Out:
711 * none
712 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200713 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400714 *
715 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700716bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400717{
Joe Perchesd4945f02013-03-18 10:44:40 -0700718 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400719
Joe Perchesd4945f02013-03-18 10:44:40 -0700720 if (ePktType == PKT_TYPE_802_11_ALL) {
721 pDevice->bStopBeacon = false;
722 pDevice->bStopTx0Pkt = false;
723 pDevice->bStopDataPkt = false;
724 } else if (ePktType == PKT_TYPE_802_11_BCN) {
725 pDevice->bStopBeacon = false;
726 } else if (ePktType == PKT_TYPE_802_11_MNG) {
727 pDevice->bStopTx0Pkt = false;
728 } else if (ePktType == PKT_TYPE_802_11_DATA) {
729 pDevice->bStopDataPkt = false;
730 }
Forest Bond5449c682009-04-25 10:30:44 -0400731
Joe Perchesd4945f02013-03-18 10:44:40 -0700732 if ((pDevice->bStopBeacon == false) &&
733 (pDevice->bBeaconBufReady == true) &&
734 (pDevice->eOPMode == OP_MODE_ADHOC)) {
735 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
736 }
Forest Bond5449c682009-04-25 10:30:44 -0400737
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700738 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400739}
740
Forest Bond5449c682009-04-25 10:30:44 -0400741/*
742 * Description: Card Set BSSID value
743 *
744 * Parameters:
745 * In:
746 * pDeviceHandler - The adapter to be set
747 * pbyBSSID - pointer to BSSID field
748 * bAdhoc - flag to indicate IBSS
749 * Out:
750 * none
751 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200752 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400753 *
754 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200755bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
Forest Bond5449c682009-04-25 10:30:44 -0400756{
Joe Perchesd4945f02013-03-18 10:44:40 -0700757 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400758
Joe Perchesd4945f02013-03-18 10:44:40 -0700759 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
760 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300761 if (eOPMode == OP_MODE_ADHOC)
Joe Perchesd4945f02013-03-18 10:44:40 -0700762 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300763 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700764 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300765
766 if (eOPMode == OP_MODE_AP)
Joe Perchesd4945f02013-03-18 10:44:40 -0700767 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300768 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700769 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300770
Joe Perchesd4945f02013-03-18 10:44:40 -0700771 if (eOPMode == OP_MODE_UNKNOWN) {
772 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
773 pDevice->bBSSIDFilter = false;
774 pDevice->byRxMode &= ~RCR_BSSID;
775 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
776 } else {
777 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
778 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
779 pDevice->bBSSIDFilter = true;
780 pDevice->byRxMode |= RCR_BSSID;
781 }
782 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode);
783 }
784 // Adopt BSS state in Adapter Device Object
785 pDevice->eOPMode = eOPMode;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700786 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400787}
788
Forest Bond5449c682009-04-25 10:30:44 -0400789/*
790 * Description: Card indicate status
791 *
792 * Parameters:
793 * In:
794 * pDeviceHandler - The adapter to be set
795 * eStatus - Status
796 * Out:
797 * none
798 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200799 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400800 *
801 */
802
Forest Bond5449c682009-04-25 10:30:44 -0400803/*
804 * Description: Save Assoc info. contain in assoc. response frame
805 *
806 * Parameters:
807 * In:
808 * pDevice - The adapter to be set
809 * wCapabilityInfo - Capability information
810 * wStatus - Status code
811 * wAID - Assoc. ID
812 * uLen - Length of IEs
813 * pbyIEs - pointer to IEs
814 * Out:
815 * none
816 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200817 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400818 *
819 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200820bool CARDbSetTxDataRate(
Joe Perchesd4945f02013-03-18 10:44:40 -0700821 void *pDeviceHandler,
822 unsigned short wDataRate
823)
Forest Bond5449c682009-04-25 10:30:44 -0400824{
Joe Perchesd4945f02013-03-18 10:44:40 -0700825 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400826
Joe Perchesd4945f02013-03-18 10:44:40 -0700827 pDevice->wCurrentRate = wDataRate;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700828 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400829}
830
831/*+
832 *
833 * Routine Description:
834 * Consider to power down when no more packets to tx or rx.
835 *
836 * Parameters:
837 * In:
838 * pDevice - The adapter to be set
839 * Out:
840 * none
841 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200842 * Return Value: true if power down success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400843 *
Joe Perchesd4945f02013-03-18 10:44:40 -0700844 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +0200845bool
Forest Bond5449c682009-04-25 10:30:44 -0400846CARDbPowerDown(
Joe Perchesd4945f02013-03-18 10:44:40 -0700847 void *pDeviceHandler
848)
Forest Bond5449c682009-04-25 10:30:44 -0400849{
Joe Perchesd4945f02013-03-18 10:44:40 -0700850 PSDevice pDevice = (PSDevice)pDeviceHandler;
851 unsigned int uIdx;
Forest Bond5449c682009-04-25 10:30:44 -0400852
Joe Perchesd4945f02013-03-18 10:44:40 -0700853 // check if already in Doze mode
854 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
855 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400856
Joe Perchesd4945f02013-03-18 10:44:40 -0700857 // Froce PSEN on
858 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -0400859
Joe Perchesd4945f02013-03-18 10:44:40 -0700860 // check if all TD are empty,
Forest Bond5449c682009-04-25 10:30:44 -0400861
Joe Perchesd4945f02013-03-18 10:44:40 -0700862 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
863 if (pDevice->iTDUsed[uIdx] != 0)
864 return false;
865 }
Forest Bond5449c682009-04-25 10:30:44 -0400866
Joe Perchesd4945f02013-03-18 10:44:40 -0700867 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
868 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
869 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400870}
871
872/*
873 * Description: Turn off Radio power
874 *
875 * Parameters:
876 * In:
877 * pDevice - The adapter to be turned off
878 * Out:
879 * none
880 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200881 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400882 *
883 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700884bool CARDbRadioPowerOff(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400885{
Joe Perchesd4945f02013-03-18 10:44:40 -0700886 PSDevice pDevice = (PSDevice)pDeviceHandler;
887 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -0400888
Joe Perchesd4945f02013-03-18 10:44:40 -0700889 if (pDevice->bRadioOff == true)
890 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400891
Joe Perchesd4945f02013-03-18 10:44:40 -0700892 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700893 case RF_RFMD2959:
894 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
895 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
896 break;
Forest Bond5449c682009-04-25 10:30:44 -0400897
Joe Perchesd4945f02013-03-18 10:44:40 -0700898 case RF_AIROHA:
899 case RF_AL2230S:
900 case RF_AIROHA7230: //RobertYu:20050104
901 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
902 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
903 break;
Forest Bond5449c682009-04-25 10:30:44 -0400904
Joe Perchesd4945f02013-03-18 10:44:40 -0700905 }
Forest Bond5449c682009-04-25 10:30:44 -0400906
Joe Perchesd4945f02013-03-18 10:44:40 -0700907 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400908
Joe Perchesd4945f02013-03-18 10:44:40 -0700909 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400910
Joe Perchesd4945f02013-03-18 10:44:40 -0700911 pDevice->bRadioOff = true;
912 //2007-0409-03,<Add> by chester
913 printk("chester power off\n");
914 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
915 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400916}
917
Forest Bond5449c682009-04-25 10:30:44 -0400918/*
919 * Description: Turn on Radio power
920 *
921 * Parameters:
922 * In:
923 * pDevice - The adapter to be turned on
924 * Out:
925 * none
926 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200927 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400928 *
929 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700930bool CARDbRadioPowerOn(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400931{
Joe Perchesd4945f02013-03-18 10:44:40 -0700932 PSDevice pDevice = (PSDevice) pDeviceHandler;
933 bool bResult = true;
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300934
Joe Perchesd4945f02013-03-18 10:44:40 -0700935 printk("chester power on\n");
936 if (pDevice->bRadioControlOff == true) {
937 if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
938 if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
939 return false; }
Forest Bond5449c682009-04-25 10:30:44 -0400940
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700941 if (pDevice->bRadioOff == false) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700942 printk("chester pbRadioOff\n");
943 return true; }
Forest Bond5449c682009-04-25 10:30:44 -0400944
Joe Perchesd4945f02013-03-18 10:44:40 -0700945 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400946
Joe Perchesd4945f02013-03-18 10:44:40 -0700947 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400948
Joe Perchesd4945f02013-03-18 10:44:40 -0700949 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700950 case RF_RFMD2959:
951 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
952 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
953 break;
Forest Bond5449c682009-04-25 10:30:44 -0400954
Joe Perchesd4945f02013-03-18 10:44:40 -0700955 case RF_AIROHA:
956 case RF_AL2230S:
957 case RF_AIROHA7230: //RobertYu:20050104
958 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
959 SOFTPWRCTL_SWPE3));
960 break;
Forest Bond5449c682009-04-25 10:30:44 -0400961
Joe Perchesd4945f02013-03-18 10:44:40 -0700962 }
Forest Bond5449c682009-04-25 10:30:44 -0400963
Joe Perchesd4945f02013-03-18 10:44:40 -0700964 pDevice->bRadioOff = false;
Forest Bond5449c682009-04-25 10:30:44 -0400965// 2007-0409-03,<Add> by chester
Joe Perchesd4945f02013-03-18 10:44:40 -0700966 printk("chester power on\n");
967 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
968 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400969}
970
Joe Perchesd4945f02013-03-18 10:44:40 -0700971bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID)
Forest Bond5449c682009-04-25 10:30:44 -0400972{
Joe Perchesd4945f02013-03-18 10:44:40 -0700973 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400974
Joe Perchesd4945f02013-03-18 10:44:40 -0700975 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700976 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400977}
978
Forest Bond5449c682009-04-25 10:30:44 -0400979/*
980 *
981 * Description:
982 * Add BSSID in PMKID Candidate list.
983 *
984 * Parameters:
985 * In:
986 * hDeviceContext - device structure point
987 * pbyBSSID - BSSID address for adding
988 * wRSNCap - BSS's RSN capability
989 * Out:
990 * none
991 *
992 * Return Value: none.
993 *
Joe Perchesd4945f02013-03-18 10:44:40 -0700994 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +0200995bool
Joe Perchesd4945f02013-03-18 10:44:40 -0700996CARDbAdd_PMKID_Candidate(
997 void *pDeviceHandler,
998 unsigned char *pbyBSSID,
999 bool bRSNCapExist,
1000 unsigned short wRSNCap
1001)
Forest Bond5449c682009-04-25 10:30:44 -04001002{
Joe Perchesd4945f02013-03-18 10:44:40 -07001003 PSDevice pDevice = (PSDevice) pDeviceHandler;
Martin Kepplingerff87dbc2014-06-16 18:05:36 +02001004 struct pmkid_candidate *pCandidateList;
Joe Perchesd4945f02013-03-18 10:44:40 -07001005 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001006
Joe Perchesd4945f02013-03-18 10:44:40 -07001007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
Forest Bond5449c682009-04-25 10:30:44 -04001008
Joe Perchesd4945f02013-03-18 10:44:40 -07001009 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1010 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n");
1011 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1012 }
Forest Bond5449c682009-04-25 10:30:44 -04001013
Guido Martínezbc5cf652014-04-19 16:45:00 -03001014 for (ii = 0; ii < 6; ii++)
Joe Perchesd4945f02013-03-18 10:44:40 -07001015 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii));
Guido Martínezbc5cf652014-04-19 16:45:00 -03001016
Joe Perchesd4945f02013-03-18 10:44:40 -07001017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
Forest Bond5449c682009-04-25 10:30:44 -04001018
Joe Perchesd4945f02013-03-18 10:44:40 -07001019 // Update Old Candidate
1020 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1021 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1022 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001023 if (bRSNCapExist && (wRSNCap & BIT0))
Joe Perchesd4945f02013-03-18 10:44:40 -07001024 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001025 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001026 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001027
Joe Perchesd4945f02013-03-18 10:44:40 -07001028 return true;
1029 }
1030 }
Forest Bond5449c682009-04-25 10:30:44 -04001031
Joe Perchesd4945f02013-03-18 10:44:40 -07001032 // New Candidate
1033 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
Guido Martínezbc5cf652014-04-19 16:45:00 -03001034 if (bRSNCapExist && (wRSNCap & BIT0))
Joe Perchesd4945f02013-03-18 10:44:40 -07001035 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001036 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001037 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001038
Joe Perchesd4945f02013-03-18 10:44:40 -07001039 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1040 pDevice->gsPMKIDCandidate.NumCandidates++;
1041 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1042 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001043}
1044
Charles Clément830a6192010-05-07 12:30:20 -07001045void *
Joe Perchesd4945f02013-03-18 10:44:40 -07001046CARDpGetCurrentAddress(
1047 void *pDeviceHandler
1048)
Forest Bond5449c682009-04-25 10:30:44 -04001049{
Joe Perchesd4945f02013-03-18 10:44:40 -07001050 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001051
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001052 return pDevice->abyCurrentNetAddr;
Forest Bond5449c682009-04-25 10:30:44 -04001053}
1054
Forest Bond5449c682009-04-25 10:30:44 -04001055/*
1056 *
1057 * Description:
1058 * Start Spectrum Measure defined in 802.11h
1059 *
1060 * Parameters:
1061 * In:
1062 * hDeviceContext - device structure point
1063 * Out:
1064 * none
1065 *
1066 * Return Value: none.
1067 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001068 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001069bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001070CARDbStartMeasure(
1071 void *pDeviceHandler,
1072 void *pvMeasureEIDs,
1073 unsigned int uNumOfMeasureEIDs
1074)
Forest Bond5449c682009-04-25 10:30:44 -04001075{
Joe Perchesd4945f02013-03-18 10:44:40 -07001076 PSDevice pDevice = (PSDevice) pDeviceHandler;
1077 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1078 QWORD qwCurrTSF;
1079 QWORD qwStartTSF;
1080 bool bExpired = true;
1081 unsigned short wDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001082
Joe Perchesd4945f02013-03-18 10:44:40 -07001083 if ((pEID == NULL) ||
1084 (uNumOfMeasureEIDs == 0)) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001085 return true;
Joe Perchesd4945f02013-03-18 10:44:40 -07001086 }
1087 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1088 if (pDevice->bMeasureInProgress == true) {
1089 pDevice->bMeasureInProgress = false;
1090 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1091 MACvSelectPage1(pDevice->PortOffset);
1092 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1093 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1094 // clear measure control
1095 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1096 MACvSelectPage0(pDevice->PortOffset);
1097 set_channel(pDevice, pDevice->byOrgChannel);
1098 MACvSelectPage1(pDevice->PortOffset);
1099 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1100 MACvSelectPage0(pDevice->PortOffset);
1101 }
1102 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
Forest Bond5449c682009-04-25 10:30:44 -04001103
Joe Perchesd4945f02013-03-18 10:44:40 -07001104 do {
1105 pDevice->pCurrMeasureEID = pEID;
1106 pEID++;
1107 pDevice->uNumOfMeasureEIDs--;
Forest Bond5449c682009-04-25 10:30:44 -04001108
Joe Perchesd4945f02013-03-18 10:44:40 -07001109 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1110 HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1111 LODWORD(qwStartTSF) = LODWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1112 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1113 wDuration += 1; // 1 TU for channel switching
Forest Bond5449c682009-04-25 10:30:44 -04001114
Joe Perchesd4945f02013-03-18 10:44:40 -07001115 if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1116 // start immediately by setting start TSF == current TSF + 2 TU
1117 LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1118 HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001119 if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF))
Joe Perchesd4945f02013-03-18 10:44:40 -07001120 HIDWORD(qwStartTSF)++;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001121
Joe Perchesd4945f02013-03-18 10:44:40 -07001122 bExpired = false;
1123 break;
1124 } else {
1125 // start at setting start TSF - 1TU(for channel switching)
Guido Martínezbc5cf652014-04-19 16:45:00 -03001126 if (LODWORD(qwStartTSF) < 1024)
Joe Perchesd4945f02013-03-18 10:44:40 -07001127 HIDWORD(qwStartTSF)--;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001128
Joe Perchesd4945f02013-03-18 10:44:40 -07001129 LODWORD(qwStartTSF) -= 1024;
1130 }
Forest Bond5449c682009-04-25 10:30:44 -04001131
Joe Perchesd4945f02013-03-18 10:44:40 -07001132 if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1133 ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1134 (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1135) {
1136 bExpired = false;
1137 break;
1138 }
1139 VNTWIFIbMeasureReport(pDevice->pMgmt,
1140 false,
1141 pDevice->pCurrMeasureEID,
1142 MEASURE_MODE_LATE,
1143 pDevice->byBasicMap,
1144 pDevice->byCCAFraction,
1145 pDevice->abyRPIs
1146 );
1147 } else {
1148 // hardware do not support measure
1149 VNTWIFIbMeasureReport(pDevice->pMgmt,
1150 false,
1151 pDevice->pCurrMeasureEID,
1152 MEASURE_MODE_INCAPABLE,
1153 pDevice->byBasicMap,
1154 pDevice->byCCAFraction,
1155 pDevice->abyRPIs
1156 );
1157 }
1158 } while (pDevice->uNumOfMeasureEIDs != 0);
Forest Bond5449c682009-04-25 10:30:44 -04001159
Teodora Baluta1208f142013-11-10 17:12:42 +02001160 if (!bExpired) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001161 MACvSelectPage1(pDevice->PortOffset);
1162 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1163 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1164 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1165 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1166 MACvSelectPage0(pDevice->PortOffset);
1167 } else {
1168 // all measure start time expired we should complete action
1169 VNTWIFIbMeasureReport(pDevice->pMgmt,
1170 true,
1171 NULL,
1172 0,
1173 pDevice->byBasicMap,
1174 pDevice->byCCAFraction,
1175 pDevice->abyRPIs
1176 );
1177 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001178 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001179}
1180
Forest Bond5449c682009-04-25 10:30:44 -04001181/*
1182 *
1183 * Description:
1184 * Do Channel Switch defined in 802.11h
1185 *
1186 * Parameters:
1187 * In:
1188 * hDeviceContext - device structure point
1189 * Out:
1190 * none
1191 *
1192 * Return Value: none.
1193 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001194 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001195bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001196CARDbChannelSwitch(
1197 void *pDeviceHandler,
1198 unsigned char byMode,
1199 unsigned char byNewChannel,
1200 unsigned char byCount
1201)
Forest Bond5449c682009-04-25 10:30:44 -04001202{
Joe Perchesd4945f02013-03-18 10:44:40 -07001203 PSDevice pDevice = (PSDevice) pDeviceHandler;
1204 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -04001205
Joe Perchesd4945f02013-03-18 10:44:40 -07001206 if (byCount == 0) {
1207 bResult = set_channel(pDevice, byNewChannel);
1208 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1209 MACvSelectPage1(pDevice->PortOffset);
1210 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1211 MACvSelectPage0(pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001212 return bResult;
Joe Perchesd4945f02013-03-18 10:44:40 -07001213 }
1214 pDevice->byChannelSwitchCount = byCount;
1215 pDevice->byNewChannel = byNewChannel;
1216 pDevice->bChannelSwitch = true;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001217 if (byMode == 1)
Joe Perchesd4945f02013-03-18 10:44:40 -07001218 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001219
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001220 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -04001221}
1222
Forest Bond5449c682009-04-25 10:30:44 -04001223/*
1224 *
1225 * Description:
1226 * Handle Quiet EID defined in 802.11h
1227 *
1228 * Parameters:
1229 * In:
1230 * hDeviceContext - device structure point
1231 * Out:
1232 * none
1233 *
1234 * Return Value: none.
1235 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001236 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001237bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001238CARDbSetQuiet(
1239 void *pDeviceHandler,
1240 bool bResetQuiet,
1241 unsigned char byQuietCount,
1242 unsigned char byQuietPeriod,
1243 unsigned short wQuietDuration,
1244 unsigned short wQuietOffset
1245)
Forest Bond5449c682009-04-25 10:30:44 -04001246{
Joe Perchesd4945f02013-03-18 10:44:40 -07001247 PSDevice pDevice = (PSDevice) pDeviceHandler;
1248 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001249
Teodora Baluta1208f142013-11-10 17:12:42 +02001250 if (bResetQuiet) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001251 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
Guido Martínezbc5cf652014-04-19 16:45:00 -03001252 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
Joe Perchesd4945f02013-03-18 10:44:40 -07001253 pDevice->sQuiet[ii].bEnable = false;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001254
Joe Perchesd4945f02013-03-18 10:44:40 -07001255 pDevice->uQuietEnqueue = 0;
1256 pDevice->bEnableFirstQuiet = false;
1257 pDevice->bQuietEnable = false;
1258 pDevice->byQuietStartCount = byQuietCount;
1259 }
1260 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1261 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1262 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1263 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1264 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1265 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1266 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1267 pDevice->uQuietEnqueue++;
1268 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001269 if (pDevice->byQuietStartCount < byQuietCount)
Joe Perchesd4945f02013-03-18 10:44:40 -07001270 pDevice->byQuietStartCount = byQuietCount;
Joe Perchesd4945f02013-03-18 10:44:40 -07001271 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001272 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001273}
1274
Forest Bond5449c682009-04-25 10:30:44 -04001275/*
1276 *
1277 * Description:
Joe Perchesd4945f02013-03-18 10:44:40 -07001278 * Do Quiet, It will be called by either ISR(after start)
Justin P. Mattock789d1ae2012-08-20 08:43:13 -07001279 * or VNTWIFI(before start) so we do not need a SPINLOCK
Forest Bond5449c682009-04-25 10:30:44 -04001280 *
1281 * Parameters:
1282 * In:
1283 * hDeviceContext - device structure point
1284 * Out:
1285 * none
1286 *
1287 * Return Value: none.
1288 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001289 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001290bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001291CARDbStartQuiet(
1292 void *pDeviceHandler
1293)
Forest Bond5449c682009-04-25 10:30:44 -04001294{
Joe Perchesd4945f02013-03-18 10:44:40 -07001295 PSDevice pDevice = (PSDevice) pDeviceHandler;
1296 unsigned int ii = 0;
1297 unsigned long dwStartTime = 0xFFFFFFFF;
1298 unsigned int uCurrentQuietIndex = 0;
1299 unsigned long dwNextTime = 0;
1300 unsigned long dwGap = 0;
1301 unsigned long dwDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001302
Joe Perchesd4945f02013-03-18 10:44:40 -07001303 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1304 if ((pDevice->sQuiet[ii].bEnable == true) &&
1305 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1306 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1307 uCurrentQuietIndex = ii;
1308 }
1309 }
1310 if (dwStartTime == 0xFFFFFFFF) {
1311 // no more quiet
1312 pDevice->bQuietEnable = false;
1313 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1314 } else {
1315 if (pDevice->bQuietEnable == false) {
1316 // first quiet
1317 pDevice->byQuietStartCount--;
1318 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1319 dwNextTime %= pDevice->wBeaconInterval;
1320 MACvSelectPage1(pDevice->PortOffset);
1321 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1322 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1323 if (pDevice->byQuietStartCount == 0) {
1324 pDevice->bEnableFirstQuiet = false;
1325 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1326 } else {
1327 pDevice->bEnableFirstQuiet = true;
1328 }
1329 MACvSelectPage0(pDevice->PortOffset);
1330 } else {
1331 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1332 // overlap with previous Quiet
1333 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1334 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1335 // return false to indicate next quiet expired, should call this function again
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001336 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -07001337 }
1338 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1339 dwGap = 0;
1340 } else {
1341 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1342 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1343 }
1344 // set GAP and Next duration
1345 MACvSelectPage1(pDevice->PortOffset);
1346 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1347 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1348 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1349 MACvSelectPage0(pDevice->PortOffset);
1350 }
1351 pDevice->bQuietEnable = true;
1352 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1353 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1354 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1355 // not period disable current quiet element
1356 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1357 } else {
1358 // set next period start time
1359 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1360 dwNextTime *= pDevice->wBeaconInterval;
1361 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1362 }
1363 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1364 // decreament all time to avoid wrap around
1365 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001366 if (pDevice->sQuiet[ii].bEnable == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001367 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001368
Joe Perchesd4945f02013-03-18 10:44:40 -07001369 }
1370 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1371 }
1372 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001373 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001374}
1375
Forest Bond5449c682009-04-25 10:30:44 -04001376/*
1377 *
1378 * Description:
1379 * Set Local Power Constraint
1380 *
1381 * Parameters:
1382 * In:
1383 * hDeviceContext - device structure point
1384 * Out:
1385 * none
1386 *
1387 * Return Value: none.
1388 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001389 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001390void
Joe Perchesd4945f02013-03-18 10:44:40 -07001391CARDvSetPowerConstraint(
1392 void *pDeviceHandler,
1393 unsigned char byChannel,
1394 char byPower
1395)
Forest Bond5449c682009-04-25 10:30:44 -04001396{
Joe Perchesd4945f02013-03-18 10:44:40 -07001397 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001398
Joe Perchesd4945f02013-03-18 10:44:40 -07001399 if (byChannel > CB_MAX_CHANNEL_24G) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001400 if (pDevice->bCountryInfo5G == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001401 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001402
Joe Perchesd4945f02013-03-18 10:44:40 -07001403 } else {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001404 if (pDevice->bCountryInfo24G == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001405 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001406
Joe Perchesd4945f02013-03-18 10:44:40 -07001407 }
Forest Bond5449c682009-04-25 10:30:44 -04001408}
1409
Forest Bond5449c682009-04-25 10:30:44 -04001410/*
1411 *
1412 * Description:
1413 * Set Local Power Constraint
1414 *
1415 * Parameters:
1416 * In:
1417 * hDeviceContext - device structure point
1418 * Out:
1419 * none
1420 *
1421 * Return Value: none.
1422 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001423 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001424void
Joe Perchesd4945f02013-03-18 10:44:40 -07001425CARDvGetPowerCapability(
1426 void *pDeviceHandler,
1427 unsigned char *pbyMinPower,
1428 unsigned char *pbyMaxPower
1429)
Forest Bond5449c682009-04-25 10:30:44 -04001430{
Joe Perchesd4945f02013-03-18 10:44:40 -07001431 PSDevice pDevice = (PSDevice) pDeviceHandler;
1432 unsigned char byDec = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001433
Joe Perchesd4945f02013-03-18 10:44:40 -07001434 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1435 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1436 if (pDevice->byRFType == RF_UW2452) {
1437 byDec *= 3;
1438 byDec >>= 1;
1439 } else {
1440 byDec <<= 1;
1441 }
1442 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
Forest Bond5449c682009-04-25 10:30:44 -04001443}
1444
Forest Bond5449c682009-04-25 10:30:44 -04001445/*
1446 *
1447 * Description:
1448 * Get Current Tx Power
1449 *
1450 * Parameters:
1451 * In:
1452 * hDeviceContext - device structure point
1453 * Out:
1454 * none
1455 *
1456 * Return Value: none.
1457 *
Charles Clément79566eb2010-06-21 10:39:51 -07001458 */
Charles Clémentec28c7f2010-05-28 12:34:18 -07001459char
Joe Perchesd4945f02013-03-18 10:44:40 -07001460CARDbyGetTransmitPower(
1461 void *pDeviceHandler
1462)
Forest Bond5449c682009-04-25 10:30:44 -04001463{
Joe Perchesd4945f02013-03-18 10:44:40 -07001464 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001465
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001466 return pDevice->byCurPwrdBm;
Forest Bond5449c682009-04-25 10:30:44 -04001467}
1468
Forest Bond5449c682009-04-25 10:30:44 -04001469//xxx
Charles Clément6b35b7b2010-05-07 12:30:19 -07001470void
Joe Perchesd4945f02013-03-18 10:44:40 -07001471CARDvSafeResetTx(
1472 void *pDeviceHandler
1473)
Forest Bond5449c682009-04-25 10:30:44 -04001474{
Joe Perchesd4945f02013-03-18 10:44:40 -07001475 PSDevice pDevice = (PSDevice) pDeviceHandler;
1476 unsigned int uu;
1477 PSTxDesc pCurrTD;
Forest Bond5449c682009-04-25 10:30:44 -04001478
Joe Perchesd4945f02013-03-18 10:44:40 -07001479 // initialize TD index
1480 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1481 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001482
Joe Perchesd4945f02013-03-18 10:44:40 -07001483 for (uu = 0; uu < TYPE_MAXTD; uu++)
1484 pDevice->iTDUsed[uu] = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001485
Joe Perchesd4945f02013-03-18 10:44:40 -07001486 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1487 pCurrTD = &(pDevice->apTD0Rings[uu]);
1488 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1489 // init all Tx Packet pointer to NULL
1490 }
1491 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1492 pCurrTD = &(pDevice->apTD1Rings[uu]);
1493 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1494 // init all Tx Packet pointer to NULL
1495 }
Forest Bond5449c682009-04-25 10:30:44 -04001496
Joe Perchesd4945f02013-03-18 10:44:40 -07001497 // set MAC TD pointer
1498 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1499 (pDevice->td0_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001500
Joe Perchesd4945f02013-03-18 10:44:40 -07001501 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1502 (pDevice->td1_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001503
Joe Perchesd4945f02013-03-18 10:44:40 -07001504 // set MAC Beacon TX pointer
1505 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1506 (pDevice->tx_beacon_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001507}
1508
Forest Bond5449c682009-04-25 10:30:44 -04001509/*+
1510 *
1511 * Description:
1512 * Reset Rx
1513 *
1514 * Parameters:
1515 * In:
1516 * pDevice - Pointer to the adapter
1517 * Out:
1518 * none
1519 *
1520 * Return Value: none
1521 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001522 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001523void
Joe Perchesd4945f02013-03-18 10:44:40 -07001524CARDvSafeResetRx(
1525 void *pDeviceHandler
1526)
Forest Bond5449c682009-04-25 10:30:44 -04001527{
Joe Perchesd4945f02013-03-18 10:44:40 -07001528 PSDevice pDevice = (PSDevice) pDeviceHandler;
1529 unsigned int uu;
1530 PSRxDesc pDesc;
Forest Bond5449c682009-04-25 10:30:44 -04001531
Joe Perchesd4945f02013-03-18 10:44:40 -07001532 // initialize RD index
1533 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1534 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001535
Joe Perchesd4945f02013-03-18 10:44:40 -07001536 // init state, all RD is chip's
1537 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1538 pDesc = &(pDevice->aRD0Ring[uu]);
1539 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1540 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1541 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1542 }
Forest Bond5449c682009-04-25 10:30:44 -04001543
Joe Perchesd4945f02013-03-18 10:44:40 -07001544 // init state, all RD is chip's
1545 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1546 pDesc = &(pDevice->aRD1Ring[uu]);
1547 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1548 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1549 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1550 }
Forest Bond5449c682009-04-25 10:30:44 -04001551
Joe Perchesd4945f02013-03-18 10:44:40 -07001552 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1553 pDevice->cbFreeDFCB = pDevice->cbDFCB;
Forest Bond5449c682009-04-25 10:30:44 -04001554
Joe Perchesd4945f02013-03-18 10:44:40 -07001555 // set perPkt mode
1556 MACvRx0PerPktMode(pDevice->PortOffset);
1557 MACvRx1PerPktMode(pDevice->PortOffset);
1558 // set MAC RD pointer
1559 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1560 pDevice->rd0_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001561
Joe Perchesd4945f02013-03-18 10:44:40 -07001562 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1563 pDevice->rd1_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001564}
1565
Forest Bond5449c682009-04-25 10:30:44 -04001566/*
1567 * Description: Get response Control frame rate in CCK mode
1568 *
1569 * Parameters:
1570 * In:
1571 * pDevice - The adapter to be set
1572 * wRateIdx - Receiving data rate
1573 * Out:
1574 * none
1575 *
1576 * Return Value: response Control frame rate
1577 *
1578 */
Guillaume Clement9e4c5c22014-07-22 22:08:28 +02001579static unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001580{
Joe Perchesd4945f02013-03-18 10:44:40 -07001581 PSDevice pDevice = (PSDevice) pDeviceHandler;
1582 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001583
Joe Perchesd4945f02013-03-18 10:44:40 -07001584 while (ui > RATE_1M) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001585 if (pDevice->wBasicRate & ((unsigned short)1 << ui))
Joe Perchesd4945f02013-03-18 10:44:40 -07001586 return (unsigned short)ui;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001587
Joe Perchesd4945f02013-03-18 10:44:40 -07001588 ui--;
1589 }
1590 return (unsigned short)RATE_1M;
Forest Bond5449c682009-04-25 10:30:44 -04001591}
1592
1593/*
1594 * Description: Get response Control frame rate in OFDM mode
1595 *
1596 * Parameters:
1597 * In:
1598 * pDevice - The adapter to be set
1599 * wRateIdx - Receiving data rate
1600 * Out:
1601 * none
1602 *
1603 * Return Value: response Control frame rate
1604 *
1605 */
Guillaume Clement9e4c5c22014-07-22 22:08:28 +02001606static unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001607{
Joe Perchesd4945f02013-03-18 10:44:40 -07001608 PSDevice pDevice = (PSDevice) pDeviceHandler;
1609 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001610
Joe Perchesd4945f02013-03-18 10:44:40 -07001611 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate);
Forest Bond5449c682009-04-25 10:30:44 -04001612
Joe Perchesd4945f02013-03-18 10:44:40 -07001613 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1614 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1615 if (wRateIdx > RATE_24M)
1616 wRateIdx = RATE_24M;
1617 return wRateIdx;
1618 }
1619 while (ui > RATE_11M) {
1620 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui);
1622 return (unsigned short)ui;
1623 }
1624 ui--;
1625 }
1626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n");
1627 return (unsigned short)RATE_24M;
Forest Bond5449c682009-04-25 10:30:44 -04001628}
1629
Forest Bond5449c682009-04-25 10:30:44 -04001630/*
1631 * Description: Set RSPINF
1632 *
1633 * Parameters:
1634 * In:
1635 * pDevice - The adapter to be set
1636 * Out:
1637 * none
1638 *
1639 * Return Value: None.
1640 *
1641 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001642void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
Forest Bond5449c682009-04-25 10:30:44 -04001643{
Joe Perchesd4945f02013-03-18 10:44:40 -07001644 PSDevice pDevice = (PSDevice) pDeviceHandler;
1645 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1646 unsigned short wLen = 0x0000;
1647 unsigned char byTxRate, byRsvTime; //For OFDM
Forest Bond5449c682009-04-25 10:30:44 -04001648
Joe Perchesd4945f02013-03-18 10:44:40 -07001649 //Set to Page1
1650 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001651
Joe Perchesd4945f02013-03-18 10:44:40 -07001652 //RSPINF_b_1
1653 BBvCalculateParameter(pDevice,
1654 14,
1655 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1656 PK_TYPE_11B,
1657 &wLen,
1658 &byServ,
1659 &bySignal
1660);
Forest Bond5449c682009-04-25 10:30:44 -04001661
Joe Perchesd4945f02013-03-18 10:44:40 -07001662 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1663 ///RSPINF_b_2
1664 BBvCalculateParameter(pDevice,
1665 14,
1666 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1667 PK_TYPE_11B,
1668 &wLen,
1669 &byServ,
1670 &bySignal
1671);
Forest Bond5449c682009-04-25 10:30:44 -04001672
Joe Perchesd4945f02013-03-18 10:44:40 -07001673 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1674 //RSPINF_b_5
1675 BBvCalculateParameter(pDevice,
1676 14,
1677 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1678 PK_TYPE_11B,
1679 &wLen,
1680 &byServ,
1681 &bySignal
1682);
Forest Bond5449c682009-04-25 10:30:44 -04001683
Joe Perchesd4945f02013-03-18 10:44:40 -07001684 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1685 //RSPINF_b_11
1686 BBvCalculateParameter(pDevice,
1687 14,
1688 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1689 PK_TYPE_11B,
1690 &wLen,
1691 &byServ,
1692 &bySignal
1693);
Forest Bond5449c682009-04-25 10:30:44 -04001694
Joe Perchesd4945f02013-03-18 10:44:40 -07001695 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1696 //RSPINF_a_6
1697 s_vCalculateOFDMRParameter(RATE_6M,
1698 ePHYType,
1699 &byTxRate,
1700 &byRsvTime);
1701 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1702 //RSPINF_a_9
1703 s_vCalculateOFDMRParameter(RATE_9M,
1704 ePHYType,
1705 &byTxRate,
1706 &byRsvTime);
1707 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1708 //RSPINF_a_12
1709 s_vCalculateOFDMRParameter(RATE_12M,
1710 ePHYType,
1711 &byTxRate,
1712 &byRsvTime);
1713 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1714 //RSPINF_a_18
1715 s_vCalculateOFDMRParameter(RATE_18M,
1716 ePHYType,
1717 &byTxRate,
1718 &byRsvTime);
1719 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1720 //RSPINF_a_24
1721 s_vCalculateOFDMRParameter(RATE_24M,
1722 ePHYType,
1723 &byTxRate,
1724 &byRsvTime);
1725 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1726 //RSPINF_a_36
1727 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1728 ePHYType,
1729 &byTxRate,
1730 &byRsvTime);
1731 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1732 //RSPINF_a_48
1733 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1734 ePHYType,
1735 &byTxRate,
1736 &byRsvTime);
1737 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1738 //RSPINF_a_54
1739 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1740 ePHYType,
1741 &byTxRate,
1742 &byRsvTime);
1743 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
Forest Bond5449c682009-04-25 10:30:44 -04001744
Joe Perchesd4945f02013-03-18 10:44:40 -07001745 //RSPINF_a_72
1746 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1747 ePHYType,
1748 &byTxRate,
1749 &byRsvTime);
1750 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1751 //Set to Page0
1752 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001753}
1754
1755/*
1756 * Description: Update IFS
1757 *
1758 * Parameters:
1759 * In:
1760 * pDevice - The adapter to be set
1761 * Out:
1762 * none
1763 *
1764 * Return Value: None.
1765 *
1766 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001767void vUpdateIFS(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001768{
Joe Perchesd4945f02013-03-18 10:44:40 -07001769 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1770 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001771
Joe Perchesd4945f02013-03-18 10:44:40 -07001772 unsigned char byMaxMin = 0;
1773 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1774 pDevice->uSlot = C_SLOT_SHORT;
1775 pDevice->uSIFS = C_SIFS_A;
1776 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1777 pDevice->uCwMin = C_CWMIN_A;
1778 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001779 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
Joe Perchesd4945f02013-03-18 10:44:40 -07001780 pDevice->uSlot = C_SLOT_LONG;
1781 pDevice->uSIFS = C_SIFS_BG;
1782 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1783 pDevice->uCwMin = C_CWMIN_B;
1784 byMaxMin = 5;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001785 } else { // PK_TYPE_11GA & PK_TYPE_11GB
Joe Perchesd4945f02013-03-18 10:44:40 -07001786 pDevice->uSIFS = C_SIFS_BG;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001787 if (pDevice->bShortSlotTime)
Joe Perchesd4945f02013-03-18 10:44:40 -07001788 pDevice->uSlot = C_SLOT_SHORT;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001789 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001790 pDevice->uSlot = C_SLOT_LONG;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001791
Joe Perchesd4945f02013-03-18 10:44:40 -07001792 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1793 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1794 pDevice->uCwMin = C_CWMIN_A;
1795 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001796 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07001797 pDevice->uCwMin = C_CWMIN_B;
1798 byMaxMin = 5;
1799 }
1800 }
Forest Bond5449c682009-04-25 10:30:44 -04001801
Joe Perchesd4945f02013-03-18 10:44:40 -07001802 pDevice->uCwMax = C_CWMAX;
1803 pDevice->uEIFS = C_EIFS;
1804 if (pDevice->byRFType == RF_RFMD2959) {
1805 // bcs TX_PE will reserve 3 us
1806 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1807 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1808 } else {
1809 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1810 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1811 }
1812 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1813 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1814 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1815 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
Forest Bond5449c682009-04-25 10:30:44 -04001816}
1817
Joe Perchesd4945f02013-03-18 10:44:40 -07001818void CARDvUpdateBasicTopRate(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001819{
Joe Perchesd4945f02013-03-18 10:44:40 -07001820 PSDevice pDevice = (PSDevice) pDeviceHandler;
1821 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1822 unsigned char ii;
Forest Bond5449c682009-04-25 10:30:44 -04001823
Joe Perchesd4945f02013-03-18 10:44:40 -07001824 //Determines the highest basic rate.
1825 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1826 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1827 byTopOFDM = ii;
1828 break;
1829 }
1830 }
1831 pDevice->byTopOFDMBasicRate = byTopOFDM;
Forest Bond5449c682009-04-25 10:30:44 -04001832
Joe Perchesd4945f02013-03-18 10:44:40 -07001833 for (ii = RATE_11M;; ii--) {
1834 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1835 byTopCCK = ii;
1836 break;
1837 }
1838 if (ii == RATE_1M)
1839 break;
1840 }
1841 pDevice->byTopCCKBasicRate = byTopCCK;
Forest Bond5449c682009-04-25 10:30:44 -04001842}
1843
Joe Perchesd4945f02013-03-18 10:44:40 -07001844bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001845{
Joe Perchesd4945f02013-03-18 10:44:40 -07001846 PSDevice pDevice = (PSDevice) pDeviceHandler;
1847 unsigned short wRate = (unsigned short)(1<<wRateIdx);
Forest Bond5449c682009-04-25 10:30:44 -04001848
Joe Perchesd4945f02013-03-18 10:44:40 -07001849 pDevice->wBasicRate |= wRate;
Forest Bond5449c682009-04-25 10:30:44 -04001850
Joe Perchesd4945f02013-03-18 10:44:40 -07001851 //Determines the highest basic rate.
1852 CARDvUpdateBasicTopRate((void *)pDevice);
Forest Bond5449c682009-04-25 10:30:44 -04001853
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001854 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001855}
1856
Joe Perchesd4945f02013-03-18 10:44:40 -07001857bool CARDbIsOFDMinBasicRate(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001858{
Joe Perchesd4945f02013-03-18 10:44:40 -07001859 PSDevice pDevice = (PSDevice)pDeviceHandler;
1860 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001861
Joe Perchesd4945f02013-03-18 10:44:40 -07001862 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1863 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1864 return true;
1865 }
1866 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001867}
1868
Joe Perchesd4945f02013-03-18 10:44:40 -07001869unsigned char CARDbyGetPktType(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001870{
Joe Perchesd4945f02013-03-18 10:44:40 -07001871 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001872
Guido Martínezbc5cf652014-04-19 16:45:00 -03001873 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
Joe Perchesd4945f02013-03-18 10:44:40 -07001874 return (unsigned char)pDevice->byBBType;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001875 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
Joe Perchesd4945f02013-03-18 10:44:40 -07001876 return PK_TYPE_11GA;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001877 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001878 return PK_TYPE_11GB;
Forest Bond5449c682009-04-25 10:30:44 -04001879}
1880
1881/*
1882 * Description: Set NIC Loopback mode
1883 *
1884 * Parameters:
1885 * In:
1886 * pDevice - The adapter to be set
1887 * wLoopbackMode - Loopback mode to be set
1888 * Out:
1889 * none
1890 *
1891 * Return Value: none
1892 *
1893 */
Guillaume Clement16834402014-07-22 22:08:26 +02001894void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -04001895{
Joe Perchesd4945f02013-03-18 10:44:40 -07001896 switch (wLoopbackMode) {
1897 case CARD_LB_NONE:
1898 case CARD_LB_MAC:
1899 case CARD_LB_PHY:
1900 break;
1901 default:
1902 ASSERT(false);
1903 break;
1904 }
1905 // set MAC loopback
1906 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1907 // set Baseband loopback
Forest Bond5449c682009-04-25 10:30:44 -04001908}
1909
Forest Bond5449c682009-04-25 10:30:44 -04001910/*
1911 * Description: Software Reset NIC
1912 *
1913 * Parameters:
1914 * In:
1915 * pDevice - The adapter to be reset
1916 * Out:
1917 * none
1918 *
1919 * Return Value: none
1920 *
1921 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001922bool CARDbSoftwareReset(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001923{
Joe Perchesd4945f02013-03-18 10:44:40 -07001924 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001925
Joe Perchesd4945f02013-03-18 10:44:40 -07001926 // reset MAC
1927 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1928 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001929
Joe Perchesd4945f02013-03-18 10:44:40 -07001930 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001931}
1932
Forest Bond5449c682009-04-25 10:30:44 -04001933/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -07001934 * Description: Calculate TSF offset of two TSF input
Forest Bond5449c682009-04-25 10:30:44 -04001935 * Get TSF Offset from RxBCN's TSF and local TSF
1936 *
1937 * Parameters:
1938 * In:
1939 * pDevice - The adapter to be sync.
1940 * qwTSF1 - Rx BCN's TSF
1941 * qwTSF2 - Local TSF
1942 * Out:
1943 * none
1944 *
1945 * Return Value: TSF Offset value
1946 *
1947 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001948QWORD CARDqGetTSFOffset(unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
Forest Bond5449c682009-04-25 10:30:44 -04001949{
Joe Perchesd4945f02013-03-18 10:44:40 -07001950 QWORD qwTSFOffset;
1951 unsigned short wRxBcnTSFOffst = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001952
Joe Perchesd4945f02013-03-18 10:44:40 -07001953 HIDWORD(qwTSFOffset) = 0;
1954 LODWORD(qwTSFOffset) = 0;
1955 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
1956 (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001957 if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst))
Joe Perchesd4945f02013-03-18 10:44:40 -07001958 (qwTSF2).u.dwHighDword++;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001959
Joe Perchesd4945f02013-03-18 10:44:40 -07001960 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
1961 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
1962 // if borrow needed
1963 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001964 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07001965 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
Teodora Baluta88cc8502013-11-10 17:12:45 +02001966 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001967 return qwTSFOffset;
Forest Bond5449c682009-04-25 10:30:44 -04001968}
1969
Forest Bond5449c682009-04-25 10:30:44 -04001970/*
1971 * Description: Read NIC TSF counter
1972 * Get local TSF counter
1973 *
1974 * Parameters:
1975 * In:
1976 * pDevice - The adapter to be read
1977 * Out:
1978 * qwCurrTSF - Current TSF counter
1979 *
Charles Clément5a5a2a62010-08-01 17:15:49 +02001980 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -04001981 *
1982 */
Guillaume Clement16834402014-07-22 22:08:26 +02001983bool CARDbGetCurrentTSF(void __iomem *dwIoBase, PQWORD pqwCurrTSF)
Forest Bond5449c682009-04-25 10:30:44 -04001984{
Joe Perchesd4945f02013-03-18 10:44:40 -07001985 unsigned short ww;
1986 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -04001987
Joe Perchesd4945f02013-03-18 10:44:40 -07001988 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
1989 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1990 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
1991 if (!(byData & TFTCTL_TSFCNTRRD))
1992 break;
1993 }
1994 if (ww == W_MAX_TIMEOUT)
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001995 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -07001996 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
1997 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
Forest Bond5449c682009-04-25 10:30:44 -04001998
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001999 return true;
Forest Bond5449c682009-04-25 10:30:44 -04002000}
2001
Forest Bond5449c682009-04-25 10:30:44 -04002002/*
2003 * Description: Read NIC TSF counter
2004 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2005 *
2006 * Parameters:
2007 * In:
2008 * qwTSF - Current TSF counter
2009 * wbeaconInterval - Beacon Interval
2010 * Out:
2011 * qwCurrTSF - Current TSF counter
2012 *
2013 * Return Value: TSF value of next Beacon
2014 *
2015 */
Joe Perchesd4945f02013-03-18 10:44:40 -07002016QWORD CARDqGetNextTBTT(QWORD qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002017{
Joe Perchesd4945f02013-03-18 10:44:40 -07002018 unsigned int uLowNextTBTT;
2019 unsigned int uHighRemain, uLowRemain;
2020 unsigned int uBeaconInterval;
Forest Bond5449c682009-04-25 10:30:44 -04002021
Joe Perchesd4945f02013-03-18 10:44:40 -07002022 uBeaconInterval = wBeaconInterval * 1024;
2023 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
2024 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
2025 // low dword (mod) bcn
2026 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
Joe Perchesd4945f02013-03-18 10:44:40 -07002027 // high dword (mod) bcn
2028 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
2029 % uBeaconInterval;
2030 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2031 uLowRemain = uBeaconInterval - uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -04002032
Joe Perchesd4945f02013-03-18 10:44:40 -07002033 // check if carry when add one beacon interval
2034 if ((~uLowNextTBTT) < uLowRemain)
2035 HIDWORD(qwTSF)++;
Forest Bond5449c682009-04-25 10:30:44 -04002036
Joe Perchesd4945f02013-03-18 10:44:40 -07002037 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -04002038
Joe Perchesa4ef27a2013-03-18 20:55:38 -07002039 return qwTSF;
Forest Bond5449c682009-04-25 10:30:44 -04002040}
2041
Forest Bond5449c682009-04-25 10:30:44 -04002042/*
2043 * Description: Set NIC TSF counter for first Beacon time
2044 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2045 *
2046 * Parameters:
2047 * In:
2048 * dwIoBase - IO Base
2049 * wBeaconInterval - Beacon Interval
2050 * Out:
2051 * none
2052 *
2053 * Return Value: none
2054 *
2055 */
Guillaume Clement16834402014-07-22 22:08:26 +02002056void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002057{
Joe Perchesd4945f02013-03-18 10:44:40 -07002058 QWORD qwNextTBTT;
Forest Bond5449c682009-04-25 10:30:44 -04002059
Joe Perchesd4945f02013-03-18 10:44:40 -07002060 HIDWORD(qwNextTBTT) = 0;
2061 LODWORD(qwNextTBTT) = 0;
2062 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
2063 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2064 // Set NextTBTT
2065 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
2066 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
2067 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Guido Martínez4e8a7e52014-04-19 16:44:59 -03002068
Joe Perchesd4945f02013-03-18 10:44:40 -07002069 return;
Forest Bond5449c682009-04-25 10:30:44 -04002070}
2071
Forest Bond5449c682009-04-25 10:30:44 -04002072/*
2073 * Description: Sync NIC TSF counter for Beacon time
2074 * Get NEXTTBTT and write to HW
2075 *
2076 * Parameters:
2077 * In:
2078 * pDevice - The adapter to be set
2079 * qwTSF - Current TSF counter
2080 * wBeaconInterval - Beacon Interval
2081 * Out:
2082 * none
2083 *
2084 * Return Value: none
2085 *
2086 */
Guillaume Clement16834402014-07-22 22:08:26 +02002087void CARDvUpdateNextTBTT(void __iomem *dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002088{
Joe Perchesd4945f02013-03-18 10:44:40 -07002089 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2090 // Set NextTBTT
2091 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
2092 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
2093 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
2094 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8xh:%8xh] \n",
2095 (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
Forest Bond5449c682009-04-25 10:30:44 -04002096
Joe Perchesd4945f02013-03-18 10:44:40 -07002097 return;
Forest Bond5449c682009-04-25 10:30:44 -04002098}