blob: 5295463cb2bde334639dca256a32d40408258023 [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 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100576bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, u64 qwBSSTimestamp, u64 qwLocalTSF)
Forest Bond5449c682009-04-25 10:30:44 -0400577{
Joe Perchesd4945f02013-03-18 10:44:40 -0700578 PSDevice pDevice = (PSDevice) pDeviceHandler;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100579 u64 qwTSFOffset = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400580
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100581 if (qwBSSTimestamp != qwLocalTSF) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700582 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
583 // adjust TSF
584 // HW's TSF add TSF Offset reg
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100585 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
586 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -0700587 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
588 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700589 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400590}
591
Forest Bond5449c682009-04-25 10:30:44 -0400592/*
593 * Description: Set NIC TSF counter for first Beacon time
594 * Get NEXTTBTT from adjusted TSF and Beacon Interval
595 *
596 * Parameters:
597 * In:
598 * pDevice - The adapter to be set.
599 * wBeaconInterval - Beacon Interval
600 * Out:
601 * none
602 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200603 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400604 *
605 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700606bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400607{
Joe Perchesd4945f02013-03-18 10:44:40 -0700608 PSDevice pDevice = (PSDevice) pDeviceHandler;
609 unsigned int uBeaconInterval = 0;
610 unsigned int uLowNextTBTT = 0;
611 unsigned int uHighRemain = 0;
612 unsigned int uLowRemain = 0;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100613 u64 qwNextTBTT = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400614
Joe Perchesd4945f02013-03-18 10:44:40 -0700615 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
616 uBeaconInterval = wBeaconInterval * 1024;
617 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100618 uLowNextTBTT = ((qwNextTBTT & 0xffffffffULL) >> 10) << 10;
Joe Perchesd4945f02013-03-18 10:44:40 -0700619 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
620 // high dword (mod) bcn
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100621 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * (u32)(qwNextTBTT >> 32))
Joe Perchesd4945f02013-03-18 10:44:40 -0700622 % uBeaconInterval;
623 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
624 uLowRemain = uBeaconInterval - uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -0400625
Joe Perchesd4945f02013-03-18 10:44:40 -0700626 // check if carry when add one beacon interval
Guido Martínezbc5cf652014-04-19 16:45:00 -0300627 if ((~uLowNextTBTT) < uLowRemain)
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100628 qwNextTBTT = ((qwNextTBTT >> 32) + 1) << 32;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300629
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100630 qwNextTBTT = (qwNextTBTT & 0xffffffff00000000ULL) |
631 (u64)(uLowNextTBTT + uLowRemain);
Forest Bond5449c682009-04-25 10:30:44 -0400632
Joe Perchesd4945f02013-03-18 10:44:40 -0700633 // set HW beacon interval
634 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
635 pDevice->wBeaconInterval = wBeaconInterval;
636 // Set NextTBTT
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100637 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
638 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -0700639 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -0400640
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700641 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400642}
643
Forest Bond5449c682009-04-25 10:30:44 -0400644/*
645 * Description: Card Stop Hardware Tx
646 *
647 * Parameters:
648 * In:
649 * pDeviceHandler - The adapter to be set
650 * ePktType - Packet type to stop
651 * Out:
652 * none
653 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200654 * Return Value: true if all data packet complete; otherwise false.
Forest Bond5449c682009-04-25 10:30:44 -0400655 *
656 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700657bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400658{
Joe Perchesd4945f02013-03-18 10:44:40 -0700659 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400660
Joe Perchesd4945f02013-03-18 10:44:40 -0700661 if (ePktType == PKT_TYPE_802_11_ALL) {
662 pDevice->bStopBeacon = true;
663 pDevice->bStopTx0Pkt = true;
664 pDevice->bStopDataPkt = true;
665 } else if (ePktType == PKT_TYPE_802_11_BCN) {
666 pDevice->bStopBeacon = true;
667 } else if (ePktType == PKT_TYPE_802_11_MNG) {
668 pDevice->bStopTx0Pkt = true;
669 } else if (ePktType == PKT_TYPE_802_11_DATA) {
670 pDevice->bStopDataPkt = true;
671 }
Forest Bond5449c682009-04-25 10:30:44 -0400672
Joe Perchesd4945f02013-03-18 10:44:40 -0700673 if (pDevice->bStopBeacon == true) {
674 if (pDevice->bIsBeaconBufReadySet == true) {
675 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
676 pDevice->cbBeaconBufReadySetCnt++;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700677 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700678 }
679 }
680 pDevice->bIsBeaconBufReadySet = false;
681 pDevice->cbBeaconBufReadySetCnt = 0;
682 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
683 }
684 // wait all TD0 complete
685 if (pDevice->bStopTx0Pkt == true) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300686 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700687 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700688 }
689 // wait all Data TD complete
690 if (pDevice->bStopDataPkt == true) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300691 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700692 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700693 }
Forest Bond5449c682009-04-25 10:30:44 -0400694
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700695 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400696}
697
Forest Bond5449c682009-04-25 10:30:44 -0400698/*
699 * Description: Card Start Hardware Tx
700 *
701 * Parameters:
702 * In:
703 * pDeviceHandler - The adapter to be set
704 * ePktType - Packet type to start
705 * Out:
706 * none
707 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200708 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400709 *
710 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700711bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400712{
Joe Perchesd4945f02013-03-18 10:44:40 -0700713 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400714
Joe Perchesd4945f02013-03-18 10:44:40 -0700715 if (ePktType == PKT_TYPE_802_11_ALL) {
716 pDevice->bStopBeacon = false;
717 pDevice->bStopTx0Pkt = false;
718 pDevice->bStopDataPkt = false;
719 } else if (ePktType == PKT_TYPE_802_11_BCN) {
720 pDevice->bStopBeacon = false;
721 } else if (ePktType == PKT_TYPE_802_11_MNG) {
722 pDevice->bStopTx0Pkt = false;
723 } else if (ePktType == PKT_TYPE_802_11_DATA) {
724 pDevice->bStopDataPkt = false;
725 }
Forest Bond5449c682009-04-25 10:30:44 -0400726
Joe Perchesd4945f02013-03-18 10:44:40 -0700727 if ((pDevice->bStopBeacon == false) &&
728 (pDevice->bBeaconBufReady == true) &&
729 (pDevice->eOPMode == OP_MODE_ADHOC)) {
730 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
731 }
Forest Bond5449c682009-04-25 10:30:44 -0400732
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700733 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400734}
735
Forest Bond5449c682009-04-25 10:30:44 -0400736/*
737 * Description: Card Set BSSID value
738 *
739 * Parameters:
740 * In:
741 * pDeviceHandler - The adapter to be set
742 * pbyBSSID - pointer to BSSID field
743 * bAdhoc - flag to indicate IBSS
744 * Out:
745 * none
746 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200747 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400748 *
749 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200750bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
Forest Bond5449c682009-04-25 10:30:44 -0400751{
Joe Perchesd4945f02013-03-18 10:44:40 -0700752 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400753
Joe Perchesd4945f02013-03-18 10:44:40 -0700754 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
755 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300756 if (eOPMode == OP_MODE_ADHOC)
Joe Perchesd4945f02013-03-18 10:44:40 -0700757 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300758 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700759 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300760
761 if (eOPMode == OP_MODE_AP)
Joe Perchesd4945f02013-03-18 10:44:40 -0700762 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
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_AP);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300765
Joe Perchesd4945f02013-03-18 10:44:40 -0700766 if (eOPMode == OP_MODE_UNKNOWN) {
767 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
768 pDevice->bBSSIDFilter = false;
769 pDevice->byRxMode &= ~RCR_BSSID;
770 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
771 } else {
772 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
773 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
774 pDevice->bBSSIDFilter = true;
775 pDevice->byRxMode |= RCR_BSSID;
776 }
777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode);
778 }
779 // Adopt BSS state in Adapter Device Object
780 pDevice->eOPMode = eOPMode;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700781 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400782}
783
Forest Bond5449c682009-04-25 10:30:44 -0400784/*
785 * Description: Card indicate status
786 *
787 * Parameters:
788 * In:
789 * pDeviceHandler - The adapter to be set
790 * eStatus - Status
791 * Out:
792 * none
793 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200794 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400795 *
796 */
797
Forest Bond5449c682009-04-25 10:30:44 -0400798/*
799 * Description: Save Assoc info. contain in assoc. response frame
800 *
801 * Parameters:
802 * In:
803 * pDevice - The adapter to be set
804 * wCapabilityInfo - Capability information
805 * wStatus - Status code
806 * wAID - Assoc. ID
807 * uLen - Length of IEs
808 * pbyIEs - pointer to IEs
809 * Out:
810 * none
811 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200812 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400813 *
814 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200815bool CARDbSetTxDataRate(
Joe Perchesd4945f02013-03-18 10:44:40 -0700816 void *pDeviceHandler,
817 unsigned short wDataRate
818)
Forest Bond5449c682009-04-25 10:30:44 -0400819{
Joe Perchesd4945f02013-03-18 10:44:40 -0700820 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400821
Joe Perchesd4945f02013-03-18 10:44:40 -0700822 pDevice->wCurrentRate = wDataRate;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700823 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400824}
825
826/*+
827 *
828 * Routine Description:
829 * Consider to power down when no more packets to tx or rx.
830 *
831 * Parameters:
832 * In:
833 * pDevice - The adapter to be set
834 * Out:
835 * none
836 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200837 * Return Value: true if power down success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400838 *
Joe Perchesd4945f02013-03-18 10:44:40 -0700839 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +0200840bool
Forest Bond5449c682009-04-25 10:30:44 -0400841CARDbPowerDown(
Joe Perchesd4945f02013-03-18 10:44:40 -0700842 void *pDeviceHandler
843)
Forest Bond5449c682009-04-25 10:30:44 -0400844{
Joe Perchesd4945f02013-03-18 10:44:40 -0700845 PSDevice pDevice = (PSDevice)pDeviceHandler;
846 unsigned int uIdx;
Forest Bond5449c682009-04-25 10:30:44 -0400847
Joe Perchesd4945f02013-03-18 10:44:40 -0700848 // check if already in Doze mode
849 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
850 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400851
Joe Perchesd4945f02013-03-18 10:44:40 -0700852 // Froce PSEN on
853 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -0400854
Joe Perchesd4945f02013-03-18 10:44:40 -0700855 // check if all TD are empty,
Forest Bond5449c682009-04-25 10:30:44 -0400856
Joe Perchesd4945f02013-03-18 10:44:40 -0700857 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
858 if (pDevice->iTDUsed[uIdx] != 0)
859 return false;
860 }
Forest Bond5449c682009-04-25 10:30:44 -0400861
Joe Perchesd4945f02013-03-18 10:44:40 -0700862 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
863 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
864 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400865}
866
867/*
868 * Description: Turn off Radio power
869 *
870 * Parameters:
871 * In:
872 * pDevice - The adapter to be turned off
873 * Out:
874 * none
875 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200876 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400877 *
878 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700879bool CARDbRadioPowerOff(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400880{
Joe Perchesd4945f02013-03-18 10:44:40 -0700881 PSDevice pDevice = (PSDevice)pDeviceHandler;
882 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -0400883
Joe Perchesd4945f02013-03-18 10:44:40 -0700884 if (pDevice->bRadioOff == true)
885 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400886
Joe Perchesd4945f02013-03-18 10:44:40 -0700887 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700888 case RF_RFMD2959:
889 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
890 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
891 break;
Forest Bond5449c682009-04-25 10:30:44 -0400892
Joe Perchesd4945f02013-03-18 10:44:40 -0700893 case RF_AIROHA:
894 case RF_AL2230S:
895 case RF_AIROHA7230: //RobertYu:20050104
896 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
897 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
898 break;
Forest Bond5449c682009-04-25 10:30:44 -0400899
Joe Perchesd4945f02013-03-18 10:44:40 -0700900 }
Forest Bond5449c682009-04-25 10:30:44 -0400901
Joe Perchesd4945f02013-03-18 10:44:40 -0700902 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400903
Joe Perchesd4945f02013-03-18 10:44:40 -0700904 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400905
Joe Perchesd4945f02013-03-18 10:44:40 -0700906 pDevice->bRadioOff = true;
907 //2007-0409-03,<Add> by chester
Guillaume Clement941ead92014-07-25 01:06:21 +0200908 pr_debug("chester power off\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700909 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
910 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400911}
912
Forest Bond5449c682009-04-25 10:30:44 -0400913/*
914 * Description: Turn on Radio power
915 *
916 * Parameters:
917 * In:
918 * pDevice - The adapter to be turned on
919 * Out:
920 * none
921 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200922 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400923 *
924 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700925bool CARDbRadioPowerOn(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -0400926{
Joe Perchesd4945f02013-03-18 10:44:40 -0700927 PSDevice pDevice = (PSDevice) pDeviceHandler;
928 bool bResult = true;
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300929
Guillaume Clement941ead92014-07-25 01:06:21 +0200930 pr_debug("chester power on\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700931 if (pDevice->bRadioControlOff == true) {
Guillaume Clementa1613422014-07-25 01:06:22 +0200932 if (pDevice->bHWRadioOff == true)
933 pr_debug("chester bHWRadioOff\n");
934 if (pDevice->bRadioControlOff == true)
935 pr_debug("chester bRadioControlOff\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700936 return false; }
Forest Bond5449c682009-04-25 10:30:44 -0400937
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700938 if (pDevice->bRadioOff == false) {
Guillaume Clement941ead92014-07-25 01:06:21 +0200939 pr_debug("chester pbRadioOff\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700940 return true; }
Forest Bond5449c682009-04-25 10:30:44 -0400941
Joe Perchesd4945f02013-03-18 10:44:40 -0700942 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400943
Joe Perchesd4945f02013-03-18 10:44:40 -0700944 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400945
Joe Perchesd4945f02013-03-18 10:44:40 -0700946 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700947 case RF_RFMD2959:
948 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
949 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
950 break;
Forest Bond5449c682009-04-25 10:30:44 -0400951
Joe Perchesd4945f02013-03-18 10:44:40 -0700952 case RF_AIROHA:
953 case RF_AL2230S:
954 case RF_AIROHA7230: //RobertYu:20050104
955 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
956 SOFTPWRCTL_SWPE3));
957 break;
Forest Bond5449c682009-04-25 10:30:44 -0400958
Joe Perchesd4945f02013-03-18 10:44:40 -0700959 }
Forest Bond5449c682009-04-25 10:30:44 -0400960
Joe Perchesd4945f02013-03-18 10:44:40 -0700961 pDevice->bRadioOff = false;
Forest Bond5449c682009-04-25 10:30:44 -0400962// 2007-0409-03,<Add> by chester
Guillaume Clement941ead92014-07-25 01:06:21 +0200963 pr_debug("chester power on\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700964 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
965 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400966}
967
Joe Perchesd4945f02013-03-18 10:44:40 -0700968bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID)
Forest Bond5449c682009-04-25 10:30:44 -0400969{
Joe Perchesd4945f02013-03-18 10:44:40 -0700970 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400971
Joe Perchesd4945f02013-03-18 10:44:40 -0700972 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700973 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400974}
975
Forest Bond5449c682009-04-25 10:30:44 -0400976/*
977 *
978 * Description:
979 * Add BSSID in PMKID Candidate list.
980 *
981 * Parameters:
982 * In:
983 * hDeviceContext - device structure point
984 * pbyBSSID - BSSID address for adding
985 * wRSNCap - BSS's RSN capability
986 * Out:
987 * none
988 *
989 * Return Value: none.
990 *
Joe Perchesd4945f02013-03-18 10:44:40 -0700991 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +0200992bool
Joe Perchesd4945f02013-03-18 10:44:40 -0700993CARDbAdd_PMKID_Candidate(
994 void *pDeviceHandler,
995 unsigned char *pbyBSSID,
996 bool bRSNCapExist,
997 unsigned short wRSNCap
998)
Forest Bond5449c682009-04-25 10:30:44 -0400999{
Joe Perchesd4945f02013-03-18 10:44:40 -07001000 PSDevice pDevice = (PSDevice) pDeviceHandler;
Martin Kepplingerff87dbc2014-06-16 18:05:36 +02001001 struct pmkid_candidate *pCandidateList;
Joe Perchesd4945f02013-03-18 10:44:40 -07001002 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001003
Joe Perchesd4945f02013-03-18 10:44:40 -07001004 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
Forest Bond5449c682009-04-25 10:30:44 -04001005
Joe Perchesd4945f02013-03-18 10:44:40 -07001006 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n");
1008 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
1009 }
Forest Bond5449c682009-04-25 10:30:44 -04001010
Guido Martínezbc5cf652014-04-19 16:45:00 -03001011 for (ii = 0; ii < 6; ii++)
Joe Perchesd4945f02013-03-18 10:44:40 -07001012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii));
Guido Martínezbc5cf652014-04-19 16:45:00 -03001013
Joe Perchesd4945f02013-03-18 10:44:40 -07001014 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
Forest Bond5449c682009-04-25 10:30:44 -04001015
Joe Perchesd4945f02013-03-18 10:44:40 -07001016 // Update Old Candidate
1017 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1018 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1019 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001020 if (bRSNCapExist && (wRSNCap & BIT0))
Joe Perchesd4945f02013-03-18 10:44:40 -07001021 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001022 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001023 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001024
Joe Perchesd4945f02013-03-18 10:44:40 -07001025 return true;
1026 }
1027 }
Forest Bond5449c682009-04-25 10:30:44 -04001028
Joe Perchesd4945f02013-03-18 10:44:40 -07001029 // New Candidate
1030 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
Guido Martínezbc5cf652014-04-19 16:45:00 -03001031 if (bRSNCapExist && (wRSNCap & BIT0))
Joe Perchesd4945f02013-03-18 10:44:40 -07001032 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001033 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001034 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001035
Joe Perchesd4945f02013-03-18 10:44:40 -07001036 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1037 pDevice->gsPMKIDCandidate.NumCandidates++;
1038 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1039 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001040}
1041
Charles Clément830a6192010-05-07 12:30:20 -07001042void *
Joe Perchesd4945f02013-03-18 10:44:40 -07001043CARDpGetCurrentAddress(
1044 void *pDeviceHandler
1045)
Forest Bond5449c682009-04-25 10:30:44 -04001046{
Joe Perchesd4945f02013-03-18 10:44:40 -07001047 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001048
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001049 return pDevice->abyCurrentNetAddr;
Forest Bond5449c682009-04-25 10:30:44 -04001050}
1051
Forest Bond5449c682009-04-25 10:30:44 -04001052/*
1053 *
1054 * Description:
1055 * Start Spectrum Measure defined in 802.11h
1056 *
1057 * Parameters:
1058 * In:
1059 * hDeviceContext - device structure point
1060 * Out:
1061 * none
1062 *
1063 * Return Value: none.
1064 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001065 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001066bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001067CARDbStartMeasure(
1068 void *pDeviceHandler,
1069 void *pvMeasureEIDs,
1070 unsigned int uNumOfMeasureEIDs
1071)
Forest Bond5449c682009-04-25 10:30:44 -04001072{
Joe Perchesd4945f02013-03-18 10:44:40 -07001073 PSDevice pDevice = (PSDevice) pDeviceHandler;
1074 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001075 u64 qwCurrTSF;
1076 u64 qwStartTSF;
Joe Perchesd4945f02013-03-18 10:44:40 -07001077 bool bExpired = true;
1078 unsigned short wDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001079
Joe Perchesd4945f02013-03-18 10:44:40 -07001080 if ((pEID == NULL) ||
1081 (uNumOfMeasureEIDs == 0)) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001082 return true;
Joe Perchesd4945f02013-03-18 10:44:40 -07001083 }
1084 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1085 if (pDevice->bMeasureInProgress == true) {
1086 pDevice->bMeasureInProgress = false;
1087 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1088 MACvSelectPage1(pDevice->PortOffset);
1089 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1090 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1091 // clear measure control
1092 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1093 MACvSelectPage0(pDevice->PortOffset);
1094 set_channel(pDevice, pDevice->byOrgChannel);
1095 MACvSelectPage1(pDevice->PortOffset);
1096 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1097 MACvSelectPage0(pDevice->PortOffset);
1098 }
1099 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
Forest Bond5449c682009-04-25 10:30:44 -04001100
Joe Perchesd4945f02013-03-18 10:44:40 -07001101 do {
1102 pDevice->pCurrMeasureEID = pEID;
1103 pEID++;
1104 pDevice->uNumOfMeasureEIDs--;
Forest Bond5449c682009-04-25 10:30:44 -04001105
Joe Perchesd4945f02013-03-18 10:44:40 -07001106 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001107 qwStartTSF = *((u64 *)(pDevice->pCurrMeasureEID->sReq.abyStartTime));
Joe Perchesd4945f02013-03-18 10:44:40 -07001108 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1109 wDuration += 1; // 1 TU for channel switching
Forest Bond5449c682009-04-25 10:30:44 -04001110
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001111 if (qwStartTSF == 0) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001112 // start immediately by setting start TSF == current TSF + 2 TU
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001113 qwStartTSF = qwCurrTSF + 2048;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001114
Joe Perchesd4945f02013-03-18 10:44:40 -07001115 bExpired = false;
1116 break;
1117 } else {
1118 // start at setting start TSF - 1TU(for channel switching)
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001119 qwStartTSF -= 1024;
Joe Perchesd4945f02013-03-18 10:44:40 -07001120 }
Forest Bond5449c682009-04-25 10:30:44 -04001121
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001122 if (qwCurrTSF < qwStartTSF) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001123 bExpired = false;
1124 break;
1125 }
1126 VNTWIFIbMeasureReport(pDevice->pMgmt,
1127 false,
1128 pDevice->pCurrMeasureEID,
1129 MEASURE_MODE_LATE,
1130 pDevice->byBasicMap,
1131 pDevice->byCCAFraction,
1132 pDevice->abyRPIs
1133 );
1134 } else {
1135 // hardware do not support measure
1136 VNTWIFIbMeasureReport(pDevice->pMgmt,
1137 false,
1138 pDevice->pCurrMeasureEID,
1139 MEASURE_MODE_INCAPABLE,
1140 pDevice->byBasicMap,
1141 pDevice->byCCAFraction,
1142 pDevice->abyRPIs
1143 );
1144 }
1145 } while (pDevice->uNumOfMeasureEIDs != 0);
Forest Bond5449c682009-04-25 10:30:44 -04001146
Teodora Baluta1208f142013-11-10 17:12:42 +02001147 if (!bExpired) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001148 MACvSelectPage1(pDevice->PortOffset);
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001149 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, (u32)qwStartTSF);
1150 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, (u32)(qwStartTSF >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -07001151 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1152 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1153 MACvSelectPage0(pDevice->PortOffset);
1154 } else {
1155 // all measure start time expired we should complete action
1156 VNTWIFIbMeasureReport(pDevice->pMgmt,
1157 true,
1158 NULL,
1159 0,
1160 pDevice->byBasicMap,
1161 pDevice->byCCAFraction,
1162 pDevice->abyRPIs
1163 );
1164 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001165 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001166}
1167
Forest Bond5449c682009-04-25 10:30:44 -04001168/*
1169 *
1170 * Description:
1171 * Do Channel Switch defined in 802.11h
1172 *
1173 * Parameters:
1174 * In:
1175 * hDeviceContext - device structure point
1176 * Out:
1177 * none
1178 *
1179 * Return Value: none.
1180 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001181 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001182bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001183CARDbChannelSwitch(
1184 void *pDeviceHandler,
1185 unsigned char byMode,
1186 unsigned char byNewChannel,
1187 unsigned char byCount
1188)
Forest Bond5449c682009-04-25 10:30:44 -04001189{
Joe Perchesd4945f02013-03-18 10:44:40 -07001190 PSDevice pDevice = (PSDevice) pDeviceHandler;
1191 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -04001192
Joe Perchesd4945f02013-03-18 10:44:40 -07001193 if (byCount == 0) {
1194 bResult = set_channel(pDevice, byNewChannel);
1195 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1196 MACvSelectPage1(pDevice->PortOffset);
1197 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1198 MACvSelectPage0(pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001199 return bResult;
Joe Perchesd4945f02013-03-18 10:44:40 -07001200 }
1201 pDevice->byChannelSwitchCount = byCount;
1202 pDevice->byNewChannel = byNewChannel;
1203 pDevice->bChannelSwitch = true;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001204 if (byMode == 1)
Joe Perchesd4945f02013-03-18 10:44:40 -07001205 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001206
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001207 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -04001208}
1209
Forest Bond5449c682009-04-25 10:30:44 -04001210/*
1211 *
1212 * Description:
1213 * Handle Quiet EID defined in 802.11h
1214 *
1215 * Parameters:
1216 * In:
1217 * hDeviceContext - device structure point
1218 * Out:
1219 * none
1220 *
1221 * Return Value: none.
1222 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001223 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001224bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001225CARDbSetQuiet(
1226 void *pDeviceHandler,
1227 bool bResetQuiet,
1228 unsigned char byQuietCount,
1229 unsigned char byQuietPeriod,
1230 unsigned short wQuietDuration,
1231 unsigned short wQuietOffset
1232)
Forest Bond5449c682009-04-25 10:30:44 -04001233{
Joe Perchesd4945f02013-03-18 10:44:40 -07001234 PSDevice pDevice = (PSDevice) pDeviceHandler;
1235 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001236
Teodora Baluta1208f142013-11-10 17:12:42 +02001237 if (bResetQuiet) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001238 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
Guido Martínezbc5cf652014-04-19 16:45:00 -03001239 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
Joe Perchesd4945f02013-03-18 10:44:40 -07001240 pDevice->sQuiet[ii].bEnable = false;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001241
Joe Perchesd4945f02013-03-18 10:44:40 -07001242 pDevice->uQuietEnqueue = 0;
1243 pDevice->bEnableFirstQuiet = false;
1244 pDevice->bQuietEnable = false;
1245 pDevice->byQuietStartCount = byQuietCount;
1246 }
1247 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1248 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1249 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1250 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1251 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1252 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1253 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1254 pDevice->uQuietEnqueue++;
1255 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001256 if (pDevice->byQuietStartCount < byQuietCount)
Joe Perchesd4945f02013-03-18 10:44:40 -07001257 pDevice->byQuietStartCount = byQuietCount;
Joe Perchesd4945f02013-03-18 10:44:40 -07001258 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001259 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001260}
1261
Forest Bond5449c682009-04-25 10:30:44 -04001262/*
1263 *
1264 * Description:
Joe Perchesd4945f02013-03-18 10:44:40 -07001265 * Do Quiet, It will be called by either ISR(after start)
Justin P. Mattock789d1ae2012-08-20 08:43:13 -07001266 * or VNTWIFI(before start) so we do not need a SPINLOCK
Forest Bond5449c682009-04-25 10:30:44 -04001267 *
1268 * Parameters:
1269 * In:
1270 * hDeviceContext - device structure point
1271 * Out:
1272 * none
1273 *
1274 * Return Value: none.
1275 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001276 -*/
Charles Clément7b6a0012010-08-01 17:15:50 +02001277bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001278CARDbStartQuiet(
1279 void *pDeviceHandler
1280)
Forest Bond5449c682009-04-25 10:30:44 -04001281{
Joe Perchesd4945f02013-03-18 10:44:40 -07001282 PSDevice pDevice = (PSDevice) pDeviceHandler;
1283 unsigned int ii = 0;
1284 unsigned long dwStartTime = 0xFFFFFFFF;
1285 unsigned int uCurrentQuietIndex = 0;
1286 unsigned long dwNextTime = 0;
1287 unsigned long dwGap = 0;
1288 unsigned long dwDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001289
Joe Perchesd4945f02013-03-18 10:44:40 -07001290 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1291 if ((pDevice->sQuiet[ii].bEnable == true) &&
1292 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1293 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1294 uCurrentQuietIndex = ii;
1295 }
1296 }
1297 if (dwStartTime == 0xFFFFFFFF) {
1298 // no more quiet
1299 pDevice->bQuietEnable = false;
1300 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1301 } else {
1302 if (pDevice->bQuietEnable == false) {
1303 // first quiet
1304 pDevice->byQuietStartCount--;
1305 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1306 dwNextTime %= pDevice->wBeaconInterval;
1307 MACvSelectPage1(pDevice->PortOffset);
1308 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1309 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1310 if (pDevice->byQuietStartCount == 0) {
1311 pDevice->bEnableFirstQuiet = false;
1312 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1313 } else {
1314 pDevice->bEnableFirstQuiet = true;
1315 }
1316 MACvSelectPage0(pDevice->PortOffset);
1317 } else {
1318 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1319 // overlap with previous Quiet
1320 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1321 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1322 // return false to indicate next quiet expired, should call this function again
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001323 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -07001324 }
1325 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1326 dwGap = 0;
1327 } else {
1328 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1329 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1330 }
1331 // set GAP and Next duration
1332 MACvSelectPage1(pDevice->PortOffset);
1333 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1334 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1335 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1336 MACvSelectPage0(pDevice->PortOffset);
1337 }
1338 pDevice->bQuietEnable = true;
1339 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1340 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1341 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1342 // not period disable current quiet element
1343 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1344 } else {
1345 // set next period start time
1346 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1347 dwNextTime *= pDevice->wBeaconInterval;
1348 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1349 }
1350 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1351 // decreament all time to avoid wrap around
1352 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001353 if (pDevice->sQuiet[ii].bEnable == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001354 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001355
Joe Perchesd4945f02013-03-18 10:44:40 -07001356 }
1357 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1358 }
1359 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001360 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001361}
1362
Forest Bond5449c682009-04-25 10:30:44 -04001363/*
1364 *
1365 * Description:
1366 * Set Local Power Constraint
1367 *
1368 * Parameters:
1369 * In:
1370 * hDeviceContext - device structure point
1371 * Out:
1372 * none
1373 *
1374 * Return Value: none.
1375 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001376 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001377void
Joe Perchesd4945f02013-03-18 10:44:40 -07001378CARDvSetPowerConstraint(
1379 void *pDeviceHandler,
1380 unsigned char byChannel,
1381 char byPower
1382)
Forest Bond5449c682009-04-25 10:30:44 -04001383{
Joe Perchesd4945f02013-03-18 10:44:40 -07001384 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001385
Joe Perchesd4945f02013-03-18 10:44:40 -07001386 if (byChannel > CB_MAX_CHANNEL_24G) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001387 if (pDevice->bCountryInfo5G == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001388 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001389
Joe Perchesd4945f02013-03-18 10:44:40 -07001390 } else {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001391 if (pDevice->bCountryInfo24G == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001392 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001393
Joe Perchesd4945f02013-03-18 10:44:40 -07001394 }
Forest Bond5449c682009-04-25 10:30:44 -04001395}
1396
Forest Bond5449c682009-04-25 10:30:44 -04001397/*
1398 *
1399 * Description:
1400 * Set Local Power Constraint
1401 *
1402 * Parameters:
1403 * In:
1404 * hDeviceContext - device structure point
1405 * Out:
1406 * none
1407 *
1408 * Return Value: none.
1409 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001410 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001411void
Joe Perchesd4945f02013-03-18 10:44:40 -07001412CARDvGetPowerCapability(
1413 void *pDeviceHandler,
1414 unsigned char *pbyMinPower,
1415 unsigned char *pbyMaxPower
1416)
Forest Bond5449c682009-04-25 10:30:44 -04001417{
Joe Perchesd4945f02013-03-18 10:44:40 -07001418 PSDevice pDevice = (PSDevice) pDeviceHandler;
1419 unsigned char byDec = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001420
Joe Perchesd4945f02013-03-18 10:44:40 -07001421 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1422 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1423 if (pDevice->byRFType == RF_UW2452) {
1424 byDec *= 3;
1425 byDec >>= 1;
1426 } else {
1427 byDec <<= 1;
1428 }
1429 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
Forest Bond5449c682009-04-25 10:30:44 -04001430}
1431
Forest Bond5449c682009-04-25 10:30:44 -04001432/*
1433 *
1434 * Description:
1435 * Get Current Tx Power
1436 *
1437 * Parameters:
1438 * In:
1439 * hDeviceContext - device structure point
1440 * Out:
1441 * none
1442 *
1443 * Return Value: none.
1444 *
Charles Clément79566eb2010-06-21 10:39:51 -07001445 */
Charles Clémentec28c7f2010-05-28 12:34:18 -07001446char
Joe Perchesd4945f02013-03-18 10:44:40 -07001447CARDbyGetTransmitPower(
1448 void *pDeviceHandler
1449)
Forest Bond5449c682009-04-25 10:30:44 -04001450{
Joe Perchesd4945f02013-03-18 10:44:40 -07001451 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001452
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001453 return pDevice->byCurPwrdBm;
Forest Bond5449c682009-04-25 10:30:44 -04001454}
1455
Forest Bond5449c682009-04-25 10:30:44 -04001456//xxx
Charles Clément6b35b7b2010-05-07 12:30:19 -07001457void
Joe Perchesd4945f02013-03-18 10:44:40 -07001458CARDvSafeResetTx(
1459 void *pDeviceHandler
1460)
Forest Bond5449c682009-04-25 10:30:44 -04001461{
Joe Perchesd4945f02013-03-18 10:44:40 -07001462 PSDevice pDevice = (PSDevice) pDeviceHandler;
1463 unsigned int uu;
1464 PSTxDesc pCurrTD;
Forest Bond5449c682009-04-25 10:30:44 -04001465
Joe Perchesd4945f02013-03-18 10:44:40 -07001466 // initialize TD index
1467 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1468 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001469
Joe Perchesd4945f02013-03-18 10:44:40 -07001470 for (uu = 0; uu < TYPE_MAXTD; uu++)
1471 pDevice->iTDUsed[uu] = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001472
Joe Perchesd4945f02013-03-18 10:44:40 -07001473 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1474 pCurrTD = &(pDevice->apTD0Rings[uu]);
1475 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1476 // init all Tx Packet pointer to NULL
1477 }
1478 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1479 pCurrTD = &(pDevice->apTD1Rings[uu]);
1480 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1481 // init all Tx Packet pointer to NULL
1482 }
Forest Bond5449c682009-04-25 10:30:44 -04001483
Joe Perchesd4945f02013-03-18 10:44:40 -07001484 // set MAC TD pointer
1485 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1486 (pDevice->td0_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001487
Joe Perchesd4945f02013-03-18 10:44:40 -07001488 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1489 (pDevice->td1_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001490
Joe Perchesd4945f02013-03-18 10:44:40 -07001491 // set MAC Beacon TX pointer
1492 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1493 (pDevice->tx_beacon_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001494}
1495
Forest Bond5449c682009-04-25 10:30:44 -04001496/*+
1497 *
1498 * Description:
1499 * Reset Rx
1500 *
1501 * Parameters:
1502 * In:
1503 * pDevice - Pointer to the adapter
1504 * Out:
1505 * none
1506 *
1507 * Return Value: none
1508 *
Joe Perchesd4945f02013-03-18 10:44:40 -07001509 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -07001510void
Joe Perchesd4945f02013-03-18 10:44:40 -07001511CARDvSafeResetRx(
1512 void *pDeviceHandler
1513)
Forest Bond5449c682009-04-25 10:30:44 -04001514{
Joe Perchesd4945f02013-03-18 10:44:40 -07001515 PSDevice pDevice = (PSDevice) pDeviceHandler;
1516 unsigned int uu;
1517 PSRxDesc pDesc;
Forest Bond5449c682009-04-25 10:30:44 -04001518
Joe Perchesd4945f02013-03-18 10:44:40 -07001519 // initialize RD index
1520 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1521 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001522
Joe Perchesd4945f02013-03-18 10:44:40 -07001523 // init state, all RD is chip's
1524 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1525 pDesc = &(pDevice->aRD0Ring[uu]);
1526 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1527 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1528 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1529 }
Forest Bond5449c682009-04-25 10:30:44 -04001530
Joe Perchesd4945f02013-03-18 10:44:40 -07001531 // init state, all RD is chip's
1532 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1533 pDesc = &(pDevice->aRD1Ring[uu]);
1534 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1535 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1536 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1537 }
Forest Bond5449c682009-04-25 10:30:44 -04001538
Joe Perchesd4945f02013-03-18 10:44:40 -07001539 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1540 pDevice->cbFreeDFCB = pDevice->cbDFCB;
Forest Bond5449c682009-04-25 10:30:44 -04001541
Joe Perchesd4945f02013-03-18 10:44:40 -07001542 // set perPkt mode
1543 MACvRx0PerPktMode(pDevice->PortOffset);
1544 MACvRx1PerPktMode(pDevice->PortOffset);
1545 // set MAC RD pointer
1546 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1547 pDevice->rd0_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001548
Joe Perchesd4945f02013-03-18 10:44:40 -07001549 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1550 pDevice->rd1_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001551}
1552
Forest Bond5449c682009-04-25 10:30:44 -04001553/*
1554 * Description: Get response Control frame rate in CCK mode
1555 *
1556 * Parameters:
1557 * In:
1558 * pDevice - The adapter to be set
1559 * wRateIdx - Receiving data rate
1560 * Out:
1561 * none
1562 *
1563 * Return Value: response Control frame rate
1564 *
1565 */
Guillaume Clement9e4c5c22014-07-22 22:08:28 +02001566static unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001567{
Joe Perchesd4945f02013-03-18 10:44:40 -07001568 PSDevice pDevice = (PSDevice) pDeviceHandler;
1569 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001570
Joe Perchesd4945f02013-03-18 10:44:40 -07001571 while (ui > RATE_1M) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001572 if (pDevice->wBasicRate & ((unsigned short)1 << ui))
Joe Perchesd4945f02013-03-18 10:44:40 -07001573 return (unsigned short)ui;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001574
Joe Perchesd4945f02013-03-18 10:44:40 -07001575 ui--;
1576 }
1577 return (unsigned short)RATE_1M;
Forest Bond5449c682009-04-25 10:30:44 -04001578}
1579
1580/*
1581 * Description: Get response Control frame rate in OFDM mode
1582 *
1583 * Parameters:
1584 * In:
1585 * pDevice - The adapter to be set
1586 * wRateIdx - Receiving data rate
1587 * Out:
1588 * none
1589 *
1590 * Return Value: response Control frame rate
1591 *
1592 */
Guillaume Clement9e4c5c22014-07-22 22:08:28 +02001593static unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001594{
Joe Perchesd4945f02013-03-18 10:44:40 -07001595 PSDevice pDevice = (PSDevice) pDeviceHandler;
1596 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001597
Joe Perchesd4945f02013-03-18 10:44:40 -07001598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate);
Forest Bond5449c682009-04-25 10:30:44 -04001599
Joe Perchesd4945f02013-03-18 10:44:40 -07001600 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
1602 if (wRateIdx > RATE_24M)
1603 wRateIdx = RATE_24M;
1604 return wRateIdx;
1605 }
1606 while (ui > RATE_11M) {
1607 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
1608 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui);
1609 return (unsigned short)ui;
1610 }
1611 ui--;
1612 }
1613 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n");
1614 return (unsigned short)RATE_24M;
Forest Bond5449c682009-04-25 10:30:44 -04001615}
1616
Forest Bond5449c682009-04-25 10:30:44 -04001617/*
1618 * Description: Set RSPINF
1619 *
1620 * Parameters:
1621 * In:
1622 * pDevice - The adapter to be set
1623 * Out:
1624 * none
1625 *
1626 * Return Value: None.
1627 *
1628 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001629void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
Forest Bond5449c682009-04-25 10:30:44 -04001630{
Joe Perchesd4945f02013-03-18 10:44:40 -07001631 PSDevice pDevice = (PSDevice) pDeviceHandler;
1632 unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
1633 unsigned short wLen = 0x0000;
1634 unsigned char byTxRate, byRsvTime; //For OFDM
Forest Bond5449c682009-04-25 10:30:44 -04001635
Joe Perchesd4945f02013-03-18 10:44:40 -07001636 //Set to Page1
1637 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001638
Joe Perchesd4945f02013-03-18 10:44:40 -07001639 //RSPINF_b_1
1640 BBvCalculateParameter(pDevice,
1641 14,
1642 CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
1643 PK_TYPE_11B,
1644 &wLen,
1645 &byServ,
1646 &bySignal
1647);
Forest Bond5449c682009-04-25 10:30:44 -04001648
Joe Perchesd4945f02013-03-18 10:44:40 -07001649 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1650 ///RSPINF_b_2
1651 BBvCalculateParameter(pDevice,
1652 14,
1653 CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
1654 PK_TYPE_11B,
1655 &wLen,
1656 &byServ,
1657 &bySignal
1658);
Forest Bond5449c682009-04-25 10:30:44 -04001659
Joe Perchesd4945f02013-03-18 10:44:40 -07001660 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1661 //RSPINF_b_5
1662 BBvCalculateParameter(pDevice,
1663 14,
1664 CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
1665 PK_TYPE_11B,
1666 &wLen,
1667 &byServ,
1668 &bySignal
1669);
Forest Bond5449c682009-04-25 10:30:44 -04001670
Joe Perchesd4945f02013-03-18 10:44:40 -07001671 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1672 //RSPINF_b_11
1673 BBvCalculateParameter(pDevice,
1674 14,
1675 CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
1676 PK_TYPE_11B,
1677 &wLen,
1678 &byServ,
1679 &bySignal
1680);
Forest Bond5449c682009-04-25 10:30:44 -04001681
Joe Perchesd4945f02013-03-18 10:44:40 -07001682 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
1683 //RSPINF_a_6
1684 s_vCalculateOFDMRParameter(RATE_6M,
1685 ePHYType,
1686 &byTxRate,
1687 &byRsvTime);
1688 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1689 //RSPINF_a_9
1690 s_vCalculateOFDMRParameter(RATE_9M,
1691 ePHYType,
1692 &byTxRate,
1693 &byRsvTime);
1694 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1695 //RSPINF_a_12
1696 s_vCalculateOFDMRParameter(RATE_12M,
1697 ePHYType,
1698 &byTxRate,
1699 &byRsvTime);
1700 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1701 //RSPINF_a_18
1702 s_vCalculateOFDMRParameter(RATE_18M,
1703 ePHYType,
1704 &byTxRate,
1705 &byRsvTime);
1706 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1707 //RSPINF_a_24
1708 s_vCalculateOFDMRParameter(RATE_24M,
1709 ePHYType,
1710 &byTxRate,
1711 &byRsvTime);
1712 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1713 //RSPINF_a_36
1714 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1715 ePHYType,
1716 &byTxRate,
1717 &byRsvTime);
1718 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1719 //RSPINF_a_48
1720 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1721 ePHYType,
1722 &byTxRate,
1723 &byRsvTime);
1724 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1725 //RSPINF_a_54
1726 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1727 ePHYType,
1728 &byTxRate,
1729 &byRsvTime);
1730 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
Forest Bond5449c682009-04-25 10:30:44 -04001731
Joe Perchesd4945f02013-03-18 10:44:40 -07001732 //RSPINF_a_72
1733 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1734 ePHYType,
1735 &byTxRate,
1736 &byRsvTime);
1737 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1738 //Set to Page0
1739 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001740}
1741
1742/*
1743 * Description: Update IFS
1744 *
1745 * Parameters:
1746 * In:
1747 * pDevice - The adapter to be set
1748 * Out:
1749 * none
1750 *
1751 * Return Value: None.
1752 *
1753 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001754void vUpdateIFS(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001755{
Joe Perchesd4945f02013-03-18 10:44:40 -07001756 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
1757 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001758
Joe Perchesd4945f02013-03-18 10:44:40 -07001759 unsigned char byMaxMin = 0;
Guillaume Clement6b711272014-07-25 01:06:16 +02001760
Joe Perchesd4945f02013-03-18 10:44:40 -07001761 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1762 pDevice->uSlot = C_SLOT_SHORT;
1763 pDevice->uSIFS = C_SIFS_A;
1764 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1765 pDevice->uCwMin = C_CWMIN_A;
1766 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001767 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
Joe Perchesd4945f02013-03-18 10:44:40 -07001768 pDevice->uSlot = C_SLOT_LONG;
1769 pDevice->uSIFS = C_SIFS_BG;
1770 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1771 pDevice->uCwMin = C_CWMIN_B;
1772 byMaxMin = 5;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001773 } else { // PK_TYPE_11GA & PK_TYPE_11GB
Joe Perchesd4945f02013-03-18 10:44:40 -07001774 pDevice->uSIFS = C_SIFS_BG;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001775 if (pDevice->bShortSlotTime)
Joe Perchesd4945f02013-03-18 10:44:40 -07001776 pDevice->uSlot = C_SLOT_SHORT;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001777 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001778 pDevice->uSlot = C_SLOT_LONG;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001779
Joe Perchesd4945f02013-03-18 10:44:40 -07001780 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1781 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1782 pDevice->uCwMin = C_CWMIN_A;
1783 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001784 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07001785 pDevice->uCwMin = C_CWMIN_B;
1786 byMaxMin = 5;
1787 }
1788 }
Forest Bond5449c682009-04-25 10:30:44 -04001789
Joe Perchesd4945f02013-03-18 10:44:40 -07001790 pDevice->uCwMax = C_CWMAX;
1791 pDevice->uEIFS = C_EIFS;
1792 if (pDevice->byRFType == RF_RFMD2959) {
1793 // bcs TX_PE will reserve 3 us
1794 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1795 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1796 } else {
1797 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1798 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1799 }
1800 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1801 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1802 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1803 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
Forest Bond5449c682009-04-25 10:30:44 -04001804}
1805
Joe Perchesd4945f02013-03-18 10:44:40 -07001806void CARDvUpdateBasicTopRate(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001807{
Joe Perchesd4945f02013-03-18 10:44:40 -07001808 PSDevice pDevice = (PSDevice) pDeviceHandler;
1809 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1810 unsigned char ii;
Forest Bond5449c682009-04-25 10:30:44 -04001811
Joe Perchesd4945f02013-03-18 10:44:40 -07001812 //Determines the highest basic rate.
1813 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1814 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1815 byTopOFDM = ii;
1816 break;
1817 }
1818 }
1819 pDevice->byTopOFDMBasicRate = byTopOFDM;
Forest Bond5449c682009-04-25 10:30:44 -04001820
Joe Perchesd4945f02013-03-18 10:44:40 -07001821 for (ii = RATE_11M;; ii--) {
1822 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1823 byTopCCK = ii;
1824 break;
1825 }
1826 if (ii == RATE_1M)
1827 break;
1828 }
1829 pDevice->byTopCCKBasicRate = byTopCCK;
Forest Bond5449c682009-04-25 10:30:44 -04001830}
1831
Joe Perchesd4945f02013-03-18 10:44:40 -07001832bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001833{
Joe Perchesd4945f02013-03-18 10:44:40 -07001834 PSDevice pDevice = (PSDevice) pDeviceHandler;
1835 unsigned short wRate = (unsigned short)(1<<wRateIdx);
Forest Bond5449c682009-04-25 10:30:44 -04001836
Joe Perchesd4945f02013-03-18 10:44:40 -07001837 pDevice->wBasicRate |= wRate;
Forest Bond5449c682009-04-25 10:30:44 -04001838
Joe Perchesd4945f02013-03-18 10:44:40 -07001839 //Determines the highest basic rate.
1840 CARDvUpdateBasicTopRate((void *)pDevice);
Forest Bond5449c682009-04-25 10:30:44 -04001841
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001842 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001843}
1844
Joe Perchesd4945f02013-03-18 10:44:40 -07001845bool CARDbIsOFDMinBasicRate(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001846{
Joe Perchesd4945f02013-03-18 10:44:40 -07001847 PSDevice pDevice = (PSDevice)pDeviceHandler;
1848 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001849
Joe Perchesd4945f02013-03-18 10:44:40 -07001850 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1851 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1852 return true;
1853 }
1854 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001855}
1856
Joe Perchesd4945f02013-03-18 10:44:40 -07001857unsigned char CARDbyGetPktType(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001858{
Joe Perchesd4945f02013-03-18 10:44:40 -07001859 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001860
Guido Martínezbc5cf652014-04-19 16:45:00 -03001861 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
Joe Perchesd4945f02013-03-18 10:44:40 -07001862 return (unsigned char)pDevice->byBBType;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001863 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
Joe Perchesd4945f02013-03-18 10:44:40 -07001864 return PK_TYPE_11GA;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001865 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001866 return PK_TYPE_11GB;
Forest Bond5449c682009-04-25 10:30:44 -04001867}
1868
1869/*
1870 * Description: Set NIC Loopback mode
1871 *
1872 * Parameters:
1873 * In:
1874 * pDevice - The adapter to be set
1875 * wLoopbackMode - Loopback mode to be set
1876 * Out:
1877 * none
1878 *
1879 * Return Value: none
1880 *
1881 */
Guillaume Clement16834402014-07-22 22:08:26 +02001882void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -04001883{
Joe Perchesd4945f02013-03-18 10:44:40 -07001884 switch (wLoopbackMode) {
1885 case CARD_LB_NONE:
1886 case CARD_LB_MAC:
1887 case CARD_LB_PHY:
1888 break;
1889 default:
1890 ASSERT(false);
1891 break;
1892 }
1893 // set MAC loopback
1894 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1895 // set Baseband loopback
Forest Bond5449c682009-04-25 10:30:44 -04001896}
1897
Forest Bond5449c682009-04-25 10:30:44 -04001898/*
1899 * Description: Software Reset NIC
1900 *
1901 * Parameters:
1902 * In:
1903 * pDevice - The adapter to be reset
1904 * Out:
1905 * none
1906 *
1907 * Return Value: none
1908 *
1909 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001910bool CARDbSoftwareReset(void *pDeviceHandler)
Forest Bond5449c682009-04-25 10:30:44 -04001911{
Joe Perchesd4945f02013-03-18 10:44:40 -07001912 PSDevice pDevice = (PSDevice) pDeviceHandler;
Forest Bond5449c682009-04-25 10:30:44 -04001913
Joe Perchesd4945f02013-03-18 10:44:40 -07001914 // reset MAC
1915 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1916 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001917
Joe Perchesd4945f02013-03-18 10:44:40 -07001918 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001919}
1920
Forest Bond5449c682009-04-25 10:30:44 -04001921/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -07001922 * Description: Calculate TSF offset of two TSF input
Forest Bond5449c682009-04-25 10:30:44 -04001923 * Get TSF Offset from RxBCN's TSF and local TSF
1924 *
1925 * Parameters:
1926 * In:
1927 * pDevice - The adapter to be sync.
1928 * qwTSF1 - Rx BCN's TSF
1929 * qwTSF2 - Local TSF
1930 * Out:
1931 * none
1932 *
1933 * Return Value: TSF Offset value
1934 *
1935 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001936u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
Forest Bond5449c682009-04-25 10:30:44 -04001937{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001938 u64 qwTSFOffset = 0;
Joe Perchesd4945f02013-03-18 10:44:40 -07001939 unsigned short wRxBcnTSFOffst = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001940
Joe Perchesd4945f02013-03-18 10:44:40 -07001941 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
Guido Martínezbc5cf652014-04-19 16:45:00 -03001942
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001943 qwTSF2 += (u64)wRxBcnTSFOffst;
1944
1945 qwTSFOffset = qwTSF1 - qwTSF2;
1946
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001947 return qwTSFOffset;
Forest Bond5449c682009-04-25 10:30:44 -04001948}
1949
Forest Bond5449c682009-04-25 10:30:44 -04001950/*
1951 * Description: Read NIC TSF counter
1952 * Get local TSF counter
1953 *
1954 * Parameters:
1955 * In:
1956 * pDevice - The adapter to be read
1957 * Out:
1958 * qwCurrTSF - Current TSF counter
1959 *
Charles Clément5a5a2a62010-08-01 17:15:49 +02001960 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -04001961 *
1962 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001963bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF)
Forest Bond5449c682009-04-25 10:30:44 -04001964{
Joe Perchesd4945f02013-03-18 10:44:40 -07001965 unsigned short ww;
1966 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -04001967
Joe Perchesd4945f02013-03-18 10:44:40 -07001968 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
1969 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1970 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
1971 if (!(byData & TFTCTL_TSFCNTRRD))
1972 break;
1973 }
1974 if (ww == W_MAX_TIMEOUT)
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001975 return false;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001976 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
1977 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
Forest Bond5449c682009-04-25 10:30:44 -04001978
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001979 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001980}
1981
Forest Bond5449c682009-04-25 10:30:44 -04001982/*
1983 * Description: Read NIC TSF counter
1984 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1985 *
1986 * Parameters:
1987 * In:
1988 * qwTSF - Current TSF counter
1989 * wbeaconInterval - Beacon Interval
1990 * Out:
1991 * qwCurrTSF - Current TSF counter
1992 *
1993 * Return Value: TSF value of next Beacon
1994 *
1995 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001996u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04001997{
Joe Perchesd4945f02013-03-18 10:44:40 -07001998 unsigned int uLowNextTBTT;
1999 unsigned int uHighRemain, uLowRemain;
2000 unsigned int uBeaconInterval;
Forest Bond5449c682009-04-25 10:30:44 -04002001
Joe Perchesd4945f02013-03-18 10:44:40 -07002002 uBeaconInterval = wBeaconInterval * 1024;
2003 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002004 uLowNextTBTT = ((qwTSF & 0xffffffffULL) >> 10) << 10;
Joe Perchesd4945f02013-03-18 10:44:40 -07002005 // low dword (mod) bcn
2006 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
Joe Perchesd4945f02013-03-18 10:44:40 -07002007 // high dword (mod) bcn
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002008 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * (u32)(qwTSF >> 32))
Joe Perchesd4945f02013-03-18 10:44:40 -07002009 % uBeaconInterval;
2010 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
2011 uLowRemain = uBeaconInterval - uLowRemain;
Forest Bond5449c682009-04-25 10:30:44 -04002012
Joe Perchesd4945f02013-03-18 10:44:40 -07002013 // check if carry when add one beacon interval
2014 if ((~uLowNextTBTT) < uLowRemain)
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002015 qwTSF = ((qwTSF >> 32) + 1) << 32;
Forest Bond5449c682009-04-25 10:30:44 -04002016
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002017 qwTSF = (qwTSF & 0xffffffff00000000ULL) |
2018 (u64)(uLowNextTBTT + uLowRemain);
Forest Bond5449c682009-04-25 10:30:44 -04002019
Joe Perchesa4ef27a2013-03-18 20:55:38 -07002020 return qwTSF;
Forest Bond5449c682009-04-25 10:30:44 -04002021}
2022
Forest Bond5449c682009-04-25 10:30:44 -04002023/*
2024 * Description: Set NIC TSF counter for first Beacon time
2025 * Get NEXTTBTT from adjusted TSF and Beacon Interval
2026 *
2027 * Parameters:
2028 * In:
2029 * dwIoBase - IO Base
2030 * wBeaconInterval - Beacon Interval
2031 * Out:
2032 * none
2033 *
2034 * Return Value: none
2035 *
2036 */
Guillaume Clement16834402014-07-22 22:08:26 +02002037void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002038{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002039 u64 qwNextTBTT = 0;
Forest Bond5449c682009-04-25 10:30:44 -04002040
Joe Perchesd4945f02013-03-18 10:44:40 -07002041 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002042
Joe Perchesd4945f02013-03-18 10:44:40 -07002043 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
2044 // Set NextTBTT
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002045 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
2046 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -07002047 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -04002048}
2049
Forest Bond5449c682009-04-25 10:30:44 -04002050/*
2051 * Description: Sync NIC TSF counter for Beacon time
2052 * Get NEXTTBTT and write to HW
2053 *
2054 * Parameters:
2055 * In:
2056 * pDevice - The adapter to be set
2057 * qwTSF - Current TSF counter
2058 * wBeaconInterval - Beacon Interval
2059 * Out:
2060 * none
2061 *
2062 * Return Value: none
2063 *
2064 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002065void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04002066{
Joe Perchesd4945f02013-03-18 10:44:40 -07002067 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2068 // Set NextTBTT
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002069 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
2070 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -07002071 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01002072 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8llx]\n", qwTSF);
Forest Bond5449c682009-04-25 10:30:44 -04002073}