blob: eae67897a61560038249b283e6e7c49de73e14ec [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
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020062#define C_SIFS_A 16 /* micro sec. */
Forest Bond5449c682009-04-25 10:30:44 -040063#define C_SIFS_BG 10
64
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020065#define C_EIFS 80 /* micro sec. */
Forest Bond5449c682009-04-25 10:30:44 -040066
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020067#define C_SLOT_SHORT 9 /* micro sec. */
Forest Bond5449c682009-04-25 10:30:44 -040068#define C_SLOT_LONG 20
69
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020070#define C_CWMIN_A 15 /* slot time */
Forest Bond5449c682009-04-25 10:30:44 -040071#define C_CWMIN_B 31
72
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020073#define C_CWMAX 1023 /* slot time */
Forest Bond5449c682009-04-25 10:30:44 -040074
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020075#define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
Forest Bond5449c682009-04-25 10:30:44 -040076
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020077/* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M */
Charles Clément3fc9b582010-06-24 11:02:27 -070078static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020079/* 6M, 9M, 12M, 48M */
Charles Clément3fc9b582010-06-24 11:02:27 -070080static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020081/* 6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M */
Charles Clément3fc9b582010-06-24 11:02:27 -070082static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020083/* 1M, 2M, 5M, 11M, */
Charles Clément3fc9b582010-06-24 11:02:27 -070084static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
Forest Bond5449c682009-04-25 10:30:44 -040085
Forest Bond5449c682009-04-25 10:30:44 -040086/*--------------------- Static Variables --------------------------*/
87
Guillaume Clement9e4c5c22014-07-22 22:08:28 +020088static const unsigned short cwRXBCNTSFOff[MAX_RATE] =
Forest Bond5449c682009-04-25 10:30:44 -040089{17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
90
Forest Bond5449c682009-04-25 10:30:44 -040091/*--------------------- Static Functions --------------------------*/
92
93static
Charles Clément6b35b7b2010-05-07 12:30:19 -070094void
Justin P. Mattock7664ec82012-08-20 08:43:15 -070095s_vCalculateOFDMRParameter(
Joe Perchesd4945f02013-03-18 10:44:40 -070096 unsigned char byRate,
97 CARD_PHY_TYPE ePHYType,
98 unsigned char *pbyTxRate,
99 unsigned char *pbyRsvTime
100);
Forest Bond5449c682009-04-25 10:30:44 -0400101
Forest Bond5449c682009-04-25 10:30:44 -0400102/*--------------------- Export Functions --------------------------*/
103
Forest Bond5449c682009-04-25 10:30:44 -0400104/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -0700105 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond5449c682009-04-25 10:30:44 -0400106 *
107 * Parameters:
108 * In:
109 * wRate - Tx Rate
110 * byPktType - Tx Packet type
111 * Out:
112 * pbyTxRate - pointer to RSPINF TxRate field
113 * pbyRsvTime - pointer to RSPINF RsvTime field
114 *
115 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -0400116 */
117static
Charles Clément6b35b7b2010-05-07 12:30:19 -0700118void
Joe Perchesd4945f02013-03-18 10:44:40 -0700119s_vCalculateOFDMRParameter(
120 unsigned char byRate,
121 CARD_PHY_TYPE ePHYType,
122 unsigned char *pbyTxRate,
123 unsigned char *pbyRsvTime
124)
Forest Bond5449c682009-04-25 10:30:44 -0400125{
Joe Perchesd4945f02013-03-18 10:44:40 -0700126 switch (byRate) {
127 case RATE_6M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200128 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700129 *pbyTxRate = 0x9B;
130 *pbyRsvTime = 44;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700131 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700132 *pbyTxRate = 0x8B;
133 *pbyRsvTime = 50;
134 }
135 break;
Forest Bond5449c682009-04-25 10:30:44 -0400136
Joe Perchesd4945f02013-03-18 10:44:40 -0700137 case RATE_9M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200138 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700139 *pbyTxRate = 0x9F;
140 *pbyRsvTime = 36;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700141 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700142 *pbyTxRate = 0x8F;
143 *pbyRsvTime = 42;
144 }
145 break;
Forest Bond5449c682009-04-25 10:30:44 -0400146
Joe Perchesd4945f02013-03-18 10:44:40 -0700147 case RATE_12M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200148 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700149 *pbyTxRate = 0x9A;
150 *pbyRsvTime = 32;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700151 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700152 *pbyTxRate = 0x8A;
153 *pbyRsvTime = 38;
154 }
155 break;
Forest Bond5449c682009-04-25 10:30:44 -0400156
Joe Perchesd4945f02013-03-18 10:44:40 -0700157 case RATE_18M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200158 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700159 *pbyTxRate = 0x9E;
160 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700161 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700162 *pbyTxRate = 0x8E;
163 *pbyRsvTime = 34;
164 }
165 break;
Forest Bond5449c682009-04-25 10:30:44 -0400166
Joe Perchesd4945f02013-03-18 10:44:40 -0700167 case RATE_36M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200168 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700169 *pbyTxRate = 0x9D;
170 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700171 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700172 *pbyTxRate = 0x8D;
173 *pbyRsvTime = 30;
174 }
175 break;
Forest Bond5449c682009-04-25 10:30:44 -0400176
Joe Perchesd4945f02013-03-18 10:44:40 -0700177 case RATE_48M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200178 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700179 *pbyTxRate = 0x98;
180 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700181 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700182 *pbyTxRate = 0x88;
183 *pbyRsvTime = 30;
184 }
185 break;
Forest Bond5449c682009-04-25 10:30:44 -0400186
Joe Perchesd4945f02013-03-18 10:44:40 -0700187 case RATE_54M:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200188 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700189 *pbyTxRate = 0x9C;
190 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700191 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700192 *pbyTxRate = 0x8C;
193 *pbyRsvTime = 30;
194 }
195 break;
Forest Bond5449c682009-04-25 10:30:44 -0400196
Joe Perchesd4945f02013-03-18 10:44:40 -0700197 case RATE_24M:
198 default:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200199 if (ePHYType == PHY_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700200 *pbyTxRate = 0x99;
201 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700202 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700203 *pbyTxRate = 0x89;
204 *pbyRsvTime = 34;
205 }
206 break;
207 }
Forest Bond5449c682009-04-25 10:30:44 -0400208}
209
Forest Bond5449c682009-04-25 10:30:44 -0400210/*
211 * Description: Set RSPINF
212 *
213 * Parameters:
214 * In:
215 * pDevice - The adapter to be set
216 * Out:
217 * none
218 *
219 * Return Value: None.
Forest Bond5449c682009-04-25 10:30:44 -0400220 */
221static
Charles Clément6b35b7b2010-05-07 12:30:19 -0700222void
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100223s_vSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
224 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
Forest Bond5449c682009-04-25 10:30:44 -0400225{
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100226 union vnt_phy_field_swap phy;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200227 unsigned char byTxRate = 0, byRsvTime = 0; /* For OFDM */
Forest Bond5449c682009-04-25 10:30:44 -0400228
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200229 /* Set to Page1 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700230 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400231
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100232 /* RSPINF_b_1 */
233 vnt_get_phy_field(pDevice,
234 14,
235 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
236 PK_TYPE_11B,
237 &phy.field_read);
Forest Bond5449c682009-04-25 10:30:44 -0400238
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100239 /* swap over to get correct write order */
240 swap(phy.swap[0], phy.swap[1]);
Forest Bond5449c682009-04-25 10:30:44 -0400241
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100242 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
Forest Bond5449c682009-04-25 10:30:44 -0400243
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100244 /* RSPINF_b_2 */
245 vnt_get_phy_field(pDevice, 14,
246 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
247 PK_TYPE_11B, &phy.field_read);
Forest Bond5449c682009-04-25 10:30:44 -0400248
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100249 swap(phy.swap[0], phy.swap[1]);
250
251 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
252
253 /* RSPINF_b_5 */
254 vnt_get_phy_field(pDevice, 14,
255 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
256 PK_TYPE_11B, &phy.field_read);
257
258 swap(phy.swap[0], phy.swap[1]);
259
260 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
261
262 /* RSPINF_b_11 */
263 vnt_get_phy_field(pDevice, 14,
264 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
265 PK_TYPE_11B, &phy.field_read);
266
267 swap(phy.swap[0], phy.swap[1]);
268
269 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
270
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200271 /* RSPINF_a_6 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700272 s_vCalculateOFDMRParameter(RATE_6M,
273 ePHYType,
274 &byTxRate,
275 &byRsvTime);
276 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200277 /* RSPINF_a_9 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700278 s_vCalculateOFDMRParameter(RATE_9M,
279 ePHYType,
280 &byTxRate,
281 &byRsvTime);
282 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200283 /* RSPINF_a_12 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700284 s_vCalculateOFDMRParameter(RATE_12M,
285 ePHYType,
286 &byTxRate,
287 &byRsvTime);
288 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200289 /* RSPINF_a_18 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700290 s_vCalculateOFDMRParameter(RATE_18M,
291 ePHYType,
292 &byTxRate,
293 &byRsvTime);
294 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200295 /* RSPINF_a_24 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700296 s_vCalculateOFDMRParameter(RATE_24M,
297 ePHYType,
298 &byTxRate,
299 &byRsvTime);
300 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200301 /* RSPINF_a_36 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700302 s_vCalculateOFDMRParameter(
303 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
304 ePHYType,
305 &byTxRate,
306 &byRsvTime);
307 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200308 /* RSPINF_a_48 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700309 s_vCalculateOFDMRParameter(
310 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
311 ePHYType,
312 &byTxRate,
313 &byRsvTime);
314 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200315 /* RSPINF_a_54 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700316 s_vCalculateOFDMRParameter(
317 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
318 ePHYType,
319 &byTxRate,
320 &byRsvTime);
321 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200322 /* RSPINF_a_72 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700323 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200324 /* Set to Page0 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700325 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400326}
327
Forest Bond5449c682009-04-25 10:30:44 -0400328/*--------------------- Export Functions --------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -0400329
330/*
Forest Bond5449c682009-04-25 10:30:44 -0400331 * Description: Get Card short preamble option value
332 *
333 * Parameters:
334 * In:
335 * pDevice - The adapter to be set
336 * Out:
337 * none
338 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200339 * Return Value: true if short preamble; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400340 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100341bool CARDbIsShortPreamble(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -0400342{
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300343
Guido Martínezbc5cf652014-04-19 16:45:00 -0300344 if (pDevice->byPreambleType == 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700345 return false;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300346
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700347 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400348}
349
350/*
351 * Description: Get Card short slot time option value
352 *
353 * Parameters:
354 * In:
355 * pDevice - The adapter to be set
356 * Out:
357 * none
358 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200359 * Return Value: true if short slot time; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400360 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100361bool CARDbIsShorSlotTime(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -0400362{
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300363
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700364 return pDevice->bShortSlotTime;
Forest Bond5449c682009-04-25 10:30:44 -0400365}
366
Forest Bond5449c682009-04-25 10:30:44 -0400367/*
368 * Description: Update IFS
369 *
370 * Parameters:
371 * In:
372 * pDevice - The adapter to be set
373 * Out:
374 * none
375 *
376 * Return Value: None.
Forest Bond5449c682009-04-25 10:30:44 -0400377 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100378bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
379 unsigned short wCapInfo, unsigned char byERPField,
380 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
Forest Bond5449c682009-04-25 10:30:44 -0400381{
Joe Perchesd4945f02013-03-18 10:44:40 -0700382 unsigned char byCWMaxMin = 0;
383 unsigned char bySlot = 0;
384 unsigned char bySIFS = 0;
385 unsigned char byDIFS = 0;
386 unsigned char byData;
Joe Perchesd4945f02013-03-18 10:44:40 -0700387 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
388 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
Forest Bond5449c682009-04-25 10:30:44 -0400389
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200390 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
Joe Perchesd4945f02013-03-18 10:44:40 -0700391 if (ePHYType == PHY_TYPE_11A) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300392 if (pSupportRates == NULL)
Joe Perchesd4945f02013-03-18 10:44:40 -0700393 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300394
Joe Perchesd4945f02013-03-18 10:44:40 -0700395 if (pDevice->byRFType == RF_AIROHA7230) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200396 /* AL7230 use single PAPE and connect to PAPE_2.4G */
Joe Perchesd4945f02013-03-18 10:44:40 -0700397 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
398 pDevice->abyBBVGA[0] = 0x20;
399 pDevice->abyBBVGA[2] = 0x10;
400 pDevice->abyBBVGA[3] = 0x10;
401 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300402 if (byData == 0x1C)
Joe Perchesd4945f02013-03-18 10:44:40 -0700403 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300404
Joe Perchesd4945f02013-03-18 10:44:40 -0700405 } else if (pDevice->byRFType == RF_UW2452) {
406 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
407 pDevice->abyBBVGA[0] = 0x18;
408 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
409 if (byData == 0x14) {
410 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
411 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
412 }
413 } else {
414 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
415 }
416 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
417 bySlot = C_SLOT_SHORT;
418 bySIFS = C_SIFS_A;
419 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
420 byCWMaxMin = 0xA4;
421 } else if (ePHYType == PHY_TYPE_11B) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300422 if (pSupportRates == NULL)
Joe Perchesd4945f02013-03-18 10:44:40 -0700423 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300424
Joe Perchesd4945f02013-03-18 10:44:40 -0700425 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
426 if (pDevice->byRFType == RF_AIROHA7230) {
427 pDevice->abyBBVGA[0] = 0x1C;
428 pDevice->abyBBVGA[2] = 0x00;
429 pDevice->abyBBVGA[3] = 0x00;
430 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300431 if (byData == 0x20)
Joe Perchesd4945f02013-03-18 10:44:40 -0700432 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300433
Joe Perchesd4945f02013-03-18 10:44:40 -0700434 } else if (pDevice->byRFType == RF_UW2452) {
435 pDevice->abyBBVGA[0] = 0x14;
436 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
437 if (byData == 0x18) {
438 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
439 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
440 }
441 }
442 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02);
443 bySlot = C_SLOT_LONG;
444 bySIFS = C_SIFS_BG;
445 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
446 byCWMaxMin = 0xA5;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200447 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
Joe Perchesd4945f02013-03-18 10:44:40 -0700448 if (pSupportRates == NULL) {
449 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
450 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
451 }
452 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
453 if (pDevice->byRFType == RF_AIROHA7230) {
454 pDevice->abyBBVGA[0] = 0x1C;
455 pDevice->abyBBVGA[2] = 0x00;
456 pDevice->abyBBVGA[3] = 0x00;
457 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300458 if (byData == 0x20)
Joe Perchesd4945f02013-03-18 10:44:40 -0700459 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300460
Joe Perchesd4945f02013-03-18 10:44:40 -0700461 } else if (pDevice->byRFType == RF_UW2452) {
462 pDevice->abyBBVGA[0] = 0x14;
463 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
464 if (byData == 0x18) {
465 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
466 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
467 }
468 }
469 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
470 bySIFS = C_SIFS_BG;
471 if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
472 bySlot = C_SLOT_SHORT;
473 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
474 } else {
475 bySlot = C_SLOT_LONG;
476 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
477 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300478 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M)
Joe Perchesd4945f02013-03-18 10:44:40 -0700479 byCWMaxMin = 0xA4;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300480 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700481 byCWMaxMin = 0xA5;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300482
Joe Perchesd4945f02013-03-18 10:44:40 -0700483 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
484 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300485 if (pDevice->bProtectMode)
Joe Perchesd4945f02013-03-18 10:44:40 -0700486 MACvEnableProtectMD(pDevice->PortOffset);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300487 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700488 MACvDisableProtectMD(pDevice->PortOffset);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300489
Joe Perchesd4945f02013-03-18 10:44:40 -0700490 }
491 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
492 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300493 if (pDevice->bBarkerPreambleMd)
Joe Perchesd4945f02013-03-18 10:44:40 -0700494 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300495 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700496 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
Joe Perchesd4945f02013-03-18 10:44:40 -0700497 }
498 }
Forest Bond5449c682009-04-25 10:30:44 -0400499
Joe Perchesd4945f02013-03-18 10:44:40 -0700500 if (pDevice->byRFType == RF_RFMD2959) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200501 /*
502 * bcs TX_PE will reserve 3 us hardware's processing
503 * time here is 2 us.
504 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700505 bySIFS -= 3;
506 byDIFS -= 3;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200507 /*
508 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
509 * better TX throughput; MAC will need 2 us to process, so the
510 * SIFS, DIFS can be shorter by 2 us.
511 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700512 }
Forest Bond5449c682009-04-25 10:30:44 -0400513
Joe Perchesd4945f02013-03-18 10:44:40 -0700514 if (pDevice->bySIFS != bySIFS) {
515 pDevice->bySIFS = bySIFS;
516 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
517 }
518 if (pDevice->byDIFS != byDIFS) {
519 pDevice->byDIFS = byDIFS;
520 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
521 }
522 if (pDevice->byEIFS != C_EIFS) {
523 pDevice->byEIFS = C_EIFS;
524 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
525 }
526 if (pDevice->bySlot != bySlot) {
527 pDevice->bySlot = bySlot;
528 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300529 if (pDevice->bySlot == C_SLOT_SHORT)
Joe Perchesd4945f02013-03-18 10:44:40 -0700530 pDevice->bShortSlotTime = true;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300531 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700532 pDevice->bShortSlotTime = false;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300533
Joe Perchesd4945f02013-03-18 10:44:40 -0700534 BBvSetShortSlotTime(pDevice);
535 }
536 if (pDevice->byCWMaxMin != byCWMaxMin) {
537 pDevice->byCWMaxMin = byCWMaxMin;
538 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
539 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300540 if (VNTWIFIbIsShortPreamble(wCapInfo))
Joe Perchesd4945f02013-03-18 10:44:40 -0700541 pDevice->byPreambleType = pDevice->byShortPreamble;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300542 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700543 pDevice->byPreambleType = 0;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300544
Joe Perchesd4945f02013-03-18 10:44:40 -0700545 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
546 pDevice->eCurrentPHYType = ePHYType;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200547 /* set for NDIS OID_802_11SUPPORTED_RATES */
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700548 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400549}
550
551/*
552 * Description: Sync. TSF counter to BSS
553 * Get TSF offset and write to HW
554 *
555 * Parameters:
556 * In:
557 * pDevice - The adapter to be sync.
558 * byRxRate - data rate of receive beacon
559 * qwBSSTimestamp - Rx BCN's TSF
560 * qwLocalTSF - Local TSF
561 * Out:
562 * none
563 *
564 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -0400565 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100566bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
567 u64 qwBSSTimestamp, u64 qwLocalTSF)
Forest Bond5449c682009-04-25 10:30:44 -0400568{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100569 u64 qwTSFOffset = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400570
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100571 if (qwBSSTimestamp != qwLocalTSF) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700572 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200573 /* adjust TSF, HW's TSF add TSF Offset reg */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100574 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
575 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -0700576 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
577 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700578 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400579}
580
Forest Bond5449c682009-04-25 10:30:44 -0400581/*
582 * Description: Set NIC TSF counter for first Beacon time
583 * Get NEXTTBTT from adjusted TSF and Beacon Interval
584 *
585 * Parameters:
586 * In:
587 * pDevice - The adapter to be set.
588 * wBeaconInterval - Beacon Interval
589 * Out:
590 * none
591 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200592 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400593 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100594bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
595 unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400596{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100597 u64 qwNextTBTT = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400598
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200599 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); /* Get Local TSF counter */
Forest Bond5449c682009-04-25 10:30:44 -0400600
Malcolm Priestley4a5f7182014-08-10 12:22:00 +0100601 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
Forest Bond5449c682009-04-25 10:30:44 -0400602
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200603 /* set HW beacon interval */
Joe Perchesd4945f02013-03-18 10:44:40 -0700604 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
605 pDevice->wBeaconInterval = wBeaconInterval;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200606 /* Set NextTBTT */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100607 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
608 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -0700609 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -0400610
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700611 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400612}
613
Forest Bond5449c682009-04-25 10:30:44 -0400614/*
615 * Description: Card Stop Hardware Tx
616 *
617 * Parameters:
618 * In:
619 * pDeviceHandler - The adapter to be set
620 * ePktType - Packet type to stop
621 * Out:
622 * none
623 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200624 * Return Value: true if all data packet complete; otherwise false.
Forest Bond5449c682009-04-25 10:30:44 -0400625 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100626bool CARDbStopTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400627{
Forest Bond5449c682009-04-25 10:30:44 -0400628
Joe Perchesd4945f02013-03-18 10:44:40 -0700629 if (ePktType == PKT_TYPE_802_11_ALL) {
630 pDevice->bStopBeacon = true;
631 pDevice->bStopTx0Pkt = true;
632 pDevice->bStopDataPkt = true;
633 } else if (ePktType == PKT_TYPE_802_11_BCN) {
634 pDevice->bStopBeacon = true;
635 } else if (ePktType == PKT_TYPE_802_11_MNG) {
636 pDevice->bStopTx0Pkt = true;
637 } else if (ePktType == PKT_TYPE_802_11_DATA) {
638 pDevice->bStopDataPkt = true;
639 }
Forest Bond5449c682009-04-25 10:30:44 -0400640
Joe Perchesd4945f02013-03-18 10:44:40 -0700641 if (pDevice->bStopBeacon == true) {
642 if (pDevice->bIsBeaconBufReadySet == true) {
643 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
644 pDevice->cbBeaconBufReadySetCnt++;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700645 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700646 }
647 }
648 pDevice->bIsBeaconBufReadySet = false;
649 pDevice->cbBeaconBufReadySetCnt = 0;
650 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
651 }
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200652 /* wait all TD0 complete */
Joe Perchesd4945f02013-03-18 10:44:40 -0700653 if (pDevice->bStopTx0Pkt == true) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300654 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700655 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700656 }
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200657 /* wait all Data TD complete */
Joe Perchesd4945f02013-03-18 10:44:40 -0700658 if (pDevice->bStopDataPkt == true) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300659 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700660 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -0700661 }
Forest Bond5449c682009-04-25 10:30:44 -0400662
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700663 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400664}
665
Forest Bond5449c682009-04-25 10:30:44 -0400666/*
667 * Description: Card Start Hardware Tx
668 *
669 * Parameters:
670 * In:
671 * pDeviceHandler - The adapter to be set
672 * ePktType - Packet type to start
673 * Out:
674 * none
675 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200676 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400677 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100678bool CARDbStartTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
Forest Bond5449c682009-04-25 10:30:44 -0400679{
Forest Bond5449c682009-04-25 10:30:44 -0400680
Joe Perchesd4945f02013-03-18 10:44:40 -0700681 if (ePktType == PKT_TYPE_802_11_ALL) {
682 pDevice->bStopBeacon = false;
683 pDevice->bStopTx0Pkt = false;
684 pDevice->bStopDataPkt = false;
685 } else if (ePktType == PKT_TYPE_802_11_BCN) {
686 pDevice->bStopBeacon = false;
687 } else if (ePktType == PKT_TYPE_802_11_MNG) {
688 pDevice->bStopTx0Pkt = false;
689 } else if (ePktType == PKT_TYPE_802_11_DATA) {
690 pDevice->bStopDataPkt = false;
691 }
Forest Bond5449c682009-04-25 10:30:44 -0400692
Joe Perchesd4945f02013-03-18 10:44:40 -0700693 if ((pDevice->bStopBeacon == false) &&
694 (pDevice->bBeaconBufReady == true) &&
Malcolm Priestleya9873672014-08-30 22:25:49 +0100695 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700696 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
697 }
Forest Bond5449c682009-04-25 10:30:44 -0400698
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700699 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400700}
701
Forest Bond5449c682009-04-25 10:30:44 -0400702/*
703 * Description: Card Set BSSID value
704 *
705 * Parameters:
706 * In:
707 * pDeviceHandler - The adapter to be set
708 * pbyBSSID - pointer to BSSID field
709 * bAdhoc - flag to indicate IBSS
710 * Out:
711 * none
712 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200713 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400714 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100715bool CARDbSetBSSID(struct vnt_private *pDevice,
Malcolm Priestleya9873672014-08-30 22:25:49 +0100716 unsigned char *pbyBSSID, enum nl80211_iftype op_mode)
Forest Bond5449c682009-04-25 10:30:44 -0400717{
Forest Bond5449c682009-04-25 10:30:44 -0400718
Joe Perchesd4945f02013-03-18 10:44:40 -0700719 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
720 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
Malcolm Priestleya9873672014-08-30 22:25:49 +0100721 if (op_mode == NL80211_IFTYPE_ADHOC)
Joe Perchesd4945f02013-03-18 10:44:40 -0700722 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300723 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700724 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300725
Malcolm Priestleya9873672014-08-30 22:25:49 +0100726 if (op_mode == NL80211_IFTYPE_AP)
Joe Perchesd4945f02013-03-18 10:44:40 -0700727 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300728 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700729 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300730
Malcolm Priestleya9873672014-08-30 22:25:49 +0100731 if (op_mode == NL80211_IFTYPE_UNSPECIFIED) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700732 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
733 pDevice->bBSSIDFilter = false;
734 pDevice->byRxMode &= ~RCR_BSSID;
Joe Perches48caf5a2014-08-17 09:17:04 -0700735 pr_debug("wcmd: rx_mode = %x\n", pDevice->byRxMode);
Joe Perchesd4945f02013-03-18 10:44:40 -0700736 } else {
737 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
738 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
739 pDevice->bBSSIDFilter = true;
740 pDevice->byRxMode |= RCR_BSSID;
741 }
Joe Perches48caf5a2014-08-17 09:17:04 -0700742 pr_debug("wmgr: rx_mode = %x\n", pDevice->byRxMode);
Joe Perchesd4945f02013-03-18 10:44:40 -0700743 }
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200744 /* Adopt BSS state in Adapter Device Object */
Malcolm Priestleya9873672014-08-30 22:25:49 +0100745 pDevice->op_mode = op_mode;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700746 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400747}
748
Forest Bond5449c682009-04-25 10:30:44 -0400749/*
750 * Description: Card indicate status
751 *
752 * Parameters:
753 * In:
754 * pDeviceHandler - The adapter to be set
755 * eStatus - Status
756 * Out:
757 * none
758 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200759 * Return Value: true if success; false if failed.
Forest Bond5449c682009-04-25 10:30:44 -0400760 */
761
Forest Bond5449c682009-04-25 10:30:44 -0400762/*
763 * Description: Save Assoc info. contain in assoc. response frame
764 *
765 * Parameters:
766 * In:
767 * pDevice - The adapter to be set
768 * wCapabilityInfo - Capability information
769 * wStatus - Status code
770 * wAID - Assoc. ID
771 * uLen - Length of IEs
772 * pbyIEs - pointer to IEs
773 * Out:
774 * none
775 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200776 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400777 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200778bool CARDbSetTxDataRate(
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100779 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -0700780 unsigned short wDataRate
781)
Forest Bond5449c682009-04-25 10:30:44 -0400782{
Forest Bond5449c682009-04-25 10:30:44 -0400783
Joe Perchesd4945f02013-03-18 10:44:40 -0700784 pDevice->wCurrentRate = wDataRate;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700785 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400786}
787
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200788/*
Forest Bond5449c682009-04-25 10:30:44 -0400789 * Routine Description:
790 * Consider to power down when no more packets to tx or rx.
791 *
792 * Parameters:
793 * In:
794 * pDevice - The adapter to be set
795 * Out:
796 * none
797 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200798 * Return Value: true if power down success; otherwise false
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200799 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200800bool
Forest Bond5449c682009-04-25 10:30:44 -0400801CARDbPowerDown(
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100802 struct vnt_private *pDevice
Joe Perchesd4945f02013-03-18 10:44:40 -0700803)
Forest Bond5449c682009-04-25 10:30:44 -0400804{
Joe Perchesd4945f02013-03-18 10:44:40 -0700805 unsigned int uIdx;
Forest Bond5449c682009-04-25 10:30:44 -0400806
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200807 /* check if already in Doze mode */
Joe Perchesd4945f02013-03-18 10:44:40 -0700808 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
809 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400810
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200811 /* Froce PSEN on */
Joe Perchesd4945f02013-03-18 10:44:40 -0700812 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -0400813
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200814 /* check if all TD are empty */
Forest Bond5449c682009-04-25 10:30:44 -0400815
Joe Perchesd4945f02013-03-18 10:44:40 -0700816 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
817 if (pDevice->iTDUsed[uIdx] != 0)
818 return false;
819 }
Forest Bond5449c682009-04-25 10:30:44 -0400820
Joe Perchesd4945f02013-03-18 10:44:40 -0700821 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
Joe Perches48caf5a2014-08-17 09:17:04 -0700822 pr_debug("Go to Doze ZZZZZZZZZZZZZZZ\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700823 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400824}
825
826/*
827 * Description: Turn off Radio power
828 *
829 * Parameters:
830 * In:
831 * pDevice - The adapter to be turned off
832 * Out:
833 * none
834 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200835 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400836 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100837bool CARDbRadioPowerOff(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -0400838{
Joe Perchesd4945f02013-03-18 10:44:40 -0700839 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -0400840
Joe Perchesd4945f02013-03-18 10:44:40 -0700841 if (pDevice->bRadioOff == true)
842 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400843
Joe Perchesd4945f02013-03-18 10:44:40 -0700844 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700845 case RF_RFMD2959:
846 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
847 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
848 break;
Forest Bond5449c682009-04-25 10:30:44 -0400849
Joe Perchesd4945f02013-03-18 10:44:40 -0700850 case RF_AIROHA:
851 case RF_AL2230S:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200852 case RF_AIROHA7230:
Joe Perchesd4945f02013-03-18 10:44:40 -0700853 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
854 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
855 break;
Forest Bond5449c682009-04-25 10:30:44 -0400856
Joe Perchesd4945f02013-03-18 10:44:40 -0700857 }
Forest Bond5449c682009-04-25 10:30:44 -0400858
Joe Perchesd4945f02013-03-18 10:44:40 -0700859 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400860
Joe Perchesd4945f02013-03-18 10:44:40 -0700861 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400862
Joe Perchesd4945f02013-03-18 10:44:40 -0700863 pDevice->bRadioOff = true;
Guillaume Clement941ead92014-07-25 01:06:21 +0200864 pr_debug("chester power off\n");
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200865 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
Joe Perchesd4945f02013-03-18 10:44:40 -0700866 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400867}
868
Forest Bond5449c682009-04-25 10:30:44 -0400869/*
870 * Description: Turn on Radio power
871 *
872 * Parameters:
873 * In:
874 * pDevice - The adapter to be turned on
875 * Out:
876 * none
877 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200878 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400879 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100880bool CARDbRadioPowerOn(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -0400881{
Joe Perchesd4945f02013-03-18 10:44:40 -0700882 bool bResult = true;
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300883
Guillaume Clement941ead92014-07-25 01:06:21 +0200884 pr_debug("chester power on\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700885 if (pDevice->bRadioControlOff == true) {
Guillaume Clementa1613422014-07-25 01:06:22 +0200886 if (pDevice->bHWRadioOff == true)
887 pr_debug("chester bHWRadioOff\n");
888 if (pDevice->bRadioControlOff == true)
889 pr_debug("chester bRadioControlOff\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700890 return false; }
Forest Bond5449c682009-04-25 10:30:44 -0400891
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700892 if (pDevice->bRadioOff == false) {
Guillaume Clement941ead92014-07-25 01:06:21 +0200893 pr_debug("chester pbRadioOff\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700894 return true; }
Forest Bond5449c682009-04-25 10:30:44 -0400895
Joe Perchesd4945f02013-03-18 10:44:40 -0700896 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400897
Joe Perchesd4945f02013-03-18 10:44:40 -0700898 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400899
Joe Perchesd4945f02013-03-18 10:44:40 -0700900 switch (pDevice->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700901 case RF_RFMD2959:
902 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
903 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
904 break;
Forest Bond5449c682009-04-25 10:30:44 -0400905
Joe Perchesd4945f02013-03-18 10:44:40 -0700906 case RF_AIROHA:
907 case RF_AL2230S:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200908 case RF_AIROHA7230:
Joe Perchesd4945f02013-03-18 10:44:40 -0700909 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
910 SOFTPWRCTL_SWPE3));
911 break;
Forest Bond5449c682009-04-25 10:30:44 -0400912
Joe Perchesd4945f02013-03-18 10:44:40 -0700913 }
Forest Bond5449c682009-04-25 10:30:44 -0400914
Joe Perchesd4945f02013-03-18 10:44:40 -0700915 pDevice->bRadioOff = false;
Guillaume Clement941ead92014-07-25 01:06:21 +0200916 pr_debug("chester power on\n");
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200917 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
Joe Perchesd4945f02013-03-18 10:44:40 -0700918 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400919}
920
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100921bool CARDbRemoveKey(struct vnt_private *pDevice, unsigned char *pbyBSSID)
Forest Bond5449c682009-04-25 10:30:44 -0400922{
Forest Bond5449c682009-04-25 10:30:44 -0400923
Joe Perchesd4945f02013-03-18 10:44:40 -0700924 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700925 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400926}
927
Forest Bond5449c682009-04-25 10:30:44 -0400928/*
Forest Bond5449c682009-04-25 10:30:44 -0400929 * Description:
930 * Add BSSID in PMKID Candidate list.
931 *
932 * Parameters:
933 * In:
934 * hDeviceContext - device structure point
935 * pbyBSSID - BSSID address for adding
936 * wRSNCap - BSS's RSN capability
937 * Out:
938 * none
939 *
940 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200941 */
Charles Clément7b6a0012010-08-01 17:15:50 +0200942bool
Joe Perchesd4945f02013-03-18 10:44:40 -0700943CARDbAdd_PMKID_Candidate(
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100944 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -0700945 unsigned char *pbyBSSID,
946 bool bRSNCapExist,
947 unsigned short wRSNCap
948)
Forest Bond5449c682009-04-25 10:30:44 -0400949{
Martin Kepplingerff87dbc2014-06-16 18:05:36 +0200950 struct pmkid_candidate *pCandidateList;
Joe Perchesd4945f02013-03-18 10:44:40 -0700951 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400952
Joe Perches48caf5a2014-08-17 09:17:04 -0700953 pr_debug("bAdd_PMKID_Candidate START: (%d)\n",
954 (int)pDevice->gsPMKIDCandidate.NumCandidates);
Forest Bond5449c682009-04-25 10:30:44 -0400955
Joe Perchesd4945f02013-03-18 10:44:40 -0700956 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700957 pr_debug("vFlush_PMKID_Candidate: 3\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700958 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
959 }
Forest Bond5449c682009-04-25 10:30:44 -0400960
Guido Martínezbc5cf652014-04-19 16:45:00 -0300961 for (ii = 0; ii < 6; ii++)
Joe Perches48caf5a2014-08-17 09:17:04 -0700962 pr_debug("%02X ", *(pbyBSSID + ii));
Guido Martínezbc5cf652014-04-19 16:45:00 -0300963
Joe Perches48caf5a2014-08-17 09:17:04 -0700964 pr_debug("\n");
Forest Bond5449c682009-04-25 10:30:44 -0400965
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200966 /* Update Old Candidate */
Joe Perchesd4945f02013-03-18 10:44:40 -0700967 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
968 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
969 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300970 if (bRSNCapExist && (wRSNCap & BIT0))
Joe Perchesd4945f02013-03-18 10:44:40 -0700971 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300972 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700973 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300974
Joe Perchesd4945f02013-03-18 10:44:40 -0700975 return true;
976 }
977 }
Forest Bond5449c682009-04-25 10:30:44 -0400978
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200979 /* New Candidate */
Joe Perchesd4945f02013-03-18 10:44:40 -0700980 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
Guido Martínezbc5cf652014-04-19 16:45:00 -0300981 if (bRSNCapExist && (wRSNCap & BIT0))
Joe Perchesd4945f02013-03-18 10:44:40 -0700982 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300983 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700984 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300985
Aya Mahfouze1499e82014-10-11 02:25:34 +0200986 ether_addr_copy(pCandidateList->BSSID, pbyBSSID);
Joe Perchesd4945f02013-03-18 10:44:40 -0700987 pDevice->gsPMKIDCandidate.NumCandidates++;
Joe Perches48caf5a2014-08-17 09:17:04 -0700988 pr_debug("NumCandidates:%d\n",
989 (int)pDevice->gsPMKIDCandidate.NumCandidates);
Joe Perchesd4945f02013-03-18 10:44:40 -0700990 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400991}
992
Charles Clément830a6192010-05-07 12:30:20 -0700993void *
Joe Perchesd4945f02013-03-18 10:44:40 -0700994CARDpGetCurrentAddress(
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100995 struct vnt_private *pDevice
Joe Perchesd4945f02013-03-18 10:44:40 -0700996)
Forest Bond5449c682009-04-25 10:30:44 -0400997{
Forest Bond5449c682009-04-25 10:30:44 -0400998
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700999 return pDevice->abyCurrentNetAddr;
Forest Bond5449c682009-04-25 10:30:44 -04001000}
1001
Forest Bond5449c682009-04-25 10:30:44 -04001002/*
Forest Bond5449c682009-04-25 10:30:44 -04001003 * Description:
1004 * Start Spectrum Measure defined in 802.11h
1005 *
1006 * Parameters:
1007 * In:
1008 * hDeviceContext - device structure point
1009 * Out:
1010 * none
1011 *
1012 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001013 */
Charles Clément7b6a0012010-08-01 17:15:50 +02001014bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001015CARDbStartMeasure(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001016 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -07001017 void *pvMeasureEIDs,
1018 unsigned int uNumOfMeasureEIDs
1019)
Forest Bond5449c682009-04-25 10:30:44 -04001020{
Joe Perchesd4945f02013-03-18 10:44:40 -07001021 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001022 u64 qwCurrTSF;
1023 u64 qwStartTSF;
Joe Perchesd4945f02013-03-18 10:44:40 -07001024 bool bExpired = true;
1025 unsigned short wDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001026
Joe Perchesd4945f02013-03-18 10:44:40 -07001027 if ((pEID == NULL) ||
1028 (uNumOfMeasureEIDs == 0)) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001029 return true;
Joe Perchesd4945f02013-03-18 10:44:40 -07001030 }
1031 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1032 if (pDevice->bMeasureInProgress == true) {
1033 pDevice->bMeasureInProgress = false;
1034 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1035 MACvSelectPage1(pDevice->PortOffset);
1036 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1037 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001038 /* clear measure control */
Joe Perchesd4945f02013-03-18 10:44:40 -07001039 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1040 MACvSelectPage0(pDevice->PortOffset);
1041 set_channel(pDevice, pDevice->byOrgChannel);
1042 MACvSelectPage1(pDevice->PortOffset);
1043 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1044 MACvSelectPage0(pDevice->PortOffset);
1045 }
1046 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
Forest Bond5449c682009-04-25 10:30:44 -04001047
Joe Perchesd4945f02013-03-18 10:44:40 -07001048 do {
1049 pDevice->pCurrMeasureEID = pEID;
1050 pEID++;
1051 pDevice->uNumOfMeasureEIDs--;
Forest Bond5449c682009-04-25 10:30:44 -04001052
Joe Perchesd4945f02013-03-18 10:44:40 -07001053 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001054 qwStartTSF = *((u64 *)(pDevice->pCurrMeasureEID->sReq.abyStartTime));
Joe Perchesd4945f02013-03-18 10:44:40 -07001055 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001056 wDuration += 1; /* 1 TU for channel switching */
Forest Bond5449c682009-04-25 10:30:44 -04001057
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001058 if (qwStartTSF == 0) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001059 /* start immediately by setting start TSF == current TSF + 2 TU */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001060 qwStartTSF = qwCurrTSF + 2048;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001061
Joe Perchesd4945f02013-03-18 10:44:40 -07001062 bExpired = false;
1063 break;
1064 } else {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001065 /* start at setting start TSF - 1TU(for channel switching) */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001066 qwStartTSF -= 1024;
Joe Perchesd4945f02013-03-18 10:44:40 -07001067 }
Forest Bond5449c682009-04-25 10:30:44 -04001068
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001069 if (qwCurrTSF < qwStartTSF) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001070 bExpired = false;
1071 break;
1072 }
1073 VNTWIFIbMeasureReport(pDevice->pMgmt,
1074 false,
1075 pDevice->pCurrMeasureEID,
1076 MEASURE_MODE_LATE,
1077 pDevice->byBasicMap,
1078 pDevice->byCCAFraction,
1079 pDevice->abyRPIs
1080 );
1081 } else {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001082 /* hardware do not support measure */
Joe Perchesd4945f02013-03-18 10:44:40 -07001083 VNTWIFIbMeasureReport(pDevice->pMgmt,
1084 false,
1085 pDevice->pCurrMeasureEID,
1086 MEASURE_MODE_INCAPABLE,
1087 pDevice->byBasicMap,
1088 pDevice->byCCAFraction,
1089 pDevice->abyRPIs
1090 );
1091 }
1092 } while (pDevice->uNumOfMeasureEIDs != 0);
Forest Bond5449c682009-04-25 10:30:44 -04001093
Teodora Baluta1208f142013-11-10 17:12:42 +02001094 if (!bExpired) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001095 MACvSelectPage1(pDevice->PortOffset);
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001096 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, (u32)qwStartTSF);
1097 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, (u32)(qwStartTSF >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -07001098 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1099 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1100 MACvSelectPage0(pDevice->PortOffset);
1101 } else {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001102 /* all measure start time expired we should complete action */
Joe Perchesd4945f02013-03-18 10:44:40 -07001103 VNTWIFIbMeasureReport(pDevice->pMgmt,
1104 true,
1105 NULL,
1106 0,
1107 pDevice->byBasicMap,
1108 pDevice->byCCAFraction,
1109 pDevice->abyRPIs
1110 );
1111 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001112 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001113}
1114
Forest Bond5449c682009-04-25 10:30:44 -04001115/*
Forest Bond5449c682009-04-25 10:30:44 -04001116 * Description:
1117 * Do Channel Switch defined in 802.11h
1118 *
1119 * Parameters:
1120 * In:
1121 * hDeviceContext - device structure point
1122 * Out:
1123 * none
1124 *
1125 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001126 */
Charles Clément7b6a0012010-08-01 17:15:50 +02001127bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001128CARDbChannelSwitch(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001129 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -07001130 unsigned char byMode,
1131 unsigned char byNewChannel,
1132 unsigned char byCount
1133)
Forest Bond5449c682009-04-25 10:30:44 -04001134{
Joe Perchesd4945f02013-03-18 10:44:40 -07001135 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -04001136
Joe Perchesd4945f02013-03-18 10:44:40 -07001137 if (byCount == 0) {
1138 bResult = set_channel(pDevice, byNewChannel);
1139 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1140 MACvSelectPage1(pDevice->PortOffset);
1141 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1142 MACvSelectPage0(pDevice->PortOffset);
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001143 return bResult;
Joe Perchesd4945f02013-03-18 10:44:40 -07001144 }
1145 pDevice->byChannelSwitchCount = byCount;
1146 pDevice->byNewChannel = byNewChannel;
1147 pDevice->bChannelSwitch = true;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001148 if (byMode == 1)
Joe Perchesd4945f02013-03-18 10:44:40 -07001149 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
Guido Martínezbc5cf652014-04-19 16:45:00 -03001150
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001151 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -04001152}
1153
Forest Bond5449c682009-04-25 10:30:44 -04001154/*
Forest Bond5449c682009-04-25 10:30:44 -04001155 * Description:
1156 * Handle Quiet EID defined in 802.11h
1157 *
1158 * Parameters:
1159 * In:
1160 * hDeviceContext - device structure point
1161 * Out:
1162 * none
1163 *
1164 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001165 */
Charles Clément7b6a0012010-08-01 17:15:50 +02001166bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001167CARDbSetQuiet(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001168 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -07001169 bool bResetQuiet,
1170 unsigned char byQuietCount,
1171 unsigned char byQuietPeriod,
1172 unsigned short wQuietDuration,
1173 unsigned short wQuietOffset
1174)
Forest Bond5449c682009-04-25 10:30:44 -04001175{
Joe Perchesd4945f02013-03-18 10:44:40 -07001176 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001177
Teodora Baluta1208f142013-11-10 17:12:42 +02001178 if (bResetQuiet) {
Joe Perchesd4945f02013-03-18 10:44:40 -07001179 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
Guido Martínezbc5cf652014-04-19 16:45:00 -03001180 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
Joe Perchesd4945f02013-03-18 10:44:40 -07001181 pDevice->sQuiet[ii].bEnable = false;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001182
Joe Perchesd4945f02013-03-18 10:44:40 -07001183 pDevice->uQuietEnqueue = 0;
1184 pDevice->bEnableFirstQuiet = false;
1185 pDevice->bQuietEnable = false;
1186 pDevice->byQuietStartCount = byQuietCount;
1187 }
1188 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1189 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1190 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1191 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1192 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1193 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1194 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1195 pDevice->uQuietEnqueue++;
1196 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001197 if (pDevice->byQuietStartCount < byQuietCount)
Joe Perchesd4945f02013-03-18 10:44:40 -07001198 pDevice->byQuietStartCount = byQuietCount;
Joe Perchesd4945f02013-03-18 10:44:40 -07001199 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001200 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001201}
1202
Forest Bond5449c682009-04-25 10:30:44 -04001203/*
Forest Bond5449c682009-04-25 10:30:44 -04001204 * Description:
Joe Perchesd4945f02013-03-18 10:44:40 -07001205 * Do Quiet, It will be called by either ISR(after start)
Justin P. Mattock789d1ae2012-08-20 08:43:13 -07001206 * or VNTWIFI(before start) so we do not need a SPINLOCK
Forest Bond5449c682009-04-25 10:30:44 -04001207 *
1208 * Parameters:
1209 * In:
1210 * hDeviceContext - device structure point
1211 * Out:
1212 * none
1213 *
1214 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001215 */
Charles Clément7b6a0012010-08-01 17:15:50 +02001216bool
Joe Perchesd4945f02013-03-18 10:44:40 -07001217CARDbStartQuiet(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001218 struct vnt_private *pDevice
Joe Perchesd4945f02013-03-18 10:44:40 -07001219)
Forest Bond5449c682009-04-25 10:30:44 -04001220{
Joe Perchesd4945f02013-03-18 10:44:40 -07001221 unsigned int ii = 0;
1222 unsigned long dwStartTime = 0xFFFFFFFF;
1223 unsigned int uCurrentQuietIndex = 0;
1224 unsigned long dwNextTime = 0;
1225 unsigned long dwGap = 0;
1226 unsigned long dwDuration = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001227
Joe Perchesd4945f02013-03-18 10:44:40 -07001228 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1229 if ((pDevice->sQuiet[ii].bEnable == true) &&
1230 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1231 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1232 uCurrentQuietIndex = ii;
1233 }
1234 }
1235 if (dwStartTime == 0xFFFFFFFF) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001236 /* no more quiet */
Joe Perchesd4945f02013-03-18 10:44:40 -07001237 pDevice->bQuietEnable = false;
1238 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1239 } else {
1240 if (pDevice->bQuietEnable == false) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001241 /* first quiet */
Joe Perchesd4945f02013-03-18 10:44:40 -07001242 pDevice->byQuietStartCount--;
1243 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1244 dwNextTime %= pDevice->wBeaconInterval;
1245 MACvSelectPage1(pDevice->PortOffset);
1246 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1247 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1248 if (pDevice->byQuietStartCount == 0) {
1249 pDevice->bEnableFirstQuiet = false;
1250 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1251 } else {
1252 pDevice->bEnableFirstQuiet = true;
1253 }
1254 MACvSelectPage0(pDevice->PortOffset);
1255 } else {
1256 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001257 /* overlap with previous Quiet */
Joe Perchesd4945f02013-03-18 10:44:40 -07001258 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1259 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001260 /*
1261 * return false to indicate next quiet
1262 * expired, should call this function
1263 * again
1264 */
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001265 return false;
Joe Perchesd4945f02013-03-18 10:44:40 -07001266 }
1267 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1268 dwGap = 0;
1269 } else {
1270 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1271 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1272 }
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001273 /* set GAP and Next duration */
Joe Perchesd4945f02013-03-18 10:44:40 -07001274 MACvSelectPage1(pDevice->PortOffset);
1275 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1276 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1277 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1278 MACvSelectPage0(pDevice->PortOffset);
1279 }
1280 pDevice->bQuietEnable = true;
1281 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1282 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1283 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001284 /* not period disable current quiet element */
Joe Perchesd4945f02013-03-18 10:44:40 -07001285 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1286 } else {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001287 /* set next period start time */
Joe Perchesd4945f02013-03-18 10:44:40 -07001288 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1289 dwNextTime *= pDevice->wBeaconInterval;
1290 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1291 }
1292 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001293 /* decreament all time to avoid wrap around */
Joe Perchesd4945f02013-03-18 10:44:40 -07001294 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001295 if (pDevice->sQuiet[ii].bEnable == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001296 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001297
Joe Perchesd4945f02013-03-18 10:44:40 -07001298 }
1299 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1300 }
1301 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001302 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001303}
1304
Forest Bond5449c682009-04-25 10:30:44 -04001305/*
Forest Bond5449c682009-04-25 10:30:44 -04001306 * Description:
1307 * Set Local Power Constraint
1308 *
1309 * Parameters:
1310 * In:
1311 * hDeviceContext - device structure point
1312 * Out:
1313 * none
1314 *
1315 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001316 */
Charles Clément6b35b7b2010-05-07 12:30:19 -07001317void
Joe Perchesd4945f02013-03-18 10:44:40 -07001318CARDvSetPowerConstraint(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001319 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -07001320 unsigned char byChannel,
1321 char byPower
1322)
Forest Bond5449c682009-04-25 10:30:44 -04001323{
Forest Bond5449c682009-04-25 10:30:44 -04001324
Joe Perchesd4945f02013-03-18 10:44:40 -07001325 if (byChannel > CB_MAX_CHANNEL_24G) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001326 if (pDevice->bCountryInfo5G == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001327 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001328
Joe Perchesd4945f02013-03-18 10:44:40 -07001329 } else {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001330 if (pDevice->bCountryInfo24G == true)
Joe Perchesd4945f02013-03-18 10:44:40 -07001331 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001332
Joe Perchesd4945f02013-03-18 10:44:40 -07001333 }
Forest Bond5449c682009-04-25 10:30:44 -04001334}
1335
Forest Bond5449c682009-04-25 10:30:44 -04001336/*
Forest Bond5449c682009-04-25 10:30:44 -04001337 * Description:
1338 * Set Local Power Constraint
1339 *
1340 * Parameters:
1341 * In:
1342 * hDeviceContext - device structure point
1343 * Out:
1344 * none
1345 *
1346 * Return Value: none.
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001347 */
Charles Clément6b35b7b2010-05-07 12:30:19 -07001348void
Joe Perchesd4945f02013-03-18 10:44:40 -07001349CARDvGetPowerCapability(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001350 struct vnt_private *pDevice,
Joe Perchesd4945f02013-03-18 10:44:40 -07001351 unsigned char *pbyMinPower,
1352 unsigned char *pbyMaxPower
1353)
Forest Bond5449c682009-04-25 10:30:44 -04001354{
Joe Perchesd4945f02013-03-18 10:44:40 -07001355 unsigned char byDec = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001356
Joe Perchesd4945f02013-03-18 10:44:40 -07001357 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1358 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1359 if (pDevice->byRFType == RF_UW2452) {
1360 byDec *= 3;
1361 byDec >>= 1;
1362 } else {
1363 byDec <<= 1;
1364 }
1365 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
Forest Bond5449c682009-04-25 10:30:44 -04001366}
1367
Forest Bond5449c682009-04-25 10:30:44 -04001368/*
Forest Bond5449c682009-04-25 10:30:44 -04001369 * Description:
1370 * Get Current Tx Power
1371 *
1372 * Parameters:
1373 * In:
1374 * hDeviceContext - device structure point
1375 * Out:
1376 * none
1377 *
1378 * Return Value: none.
Charles Clément79566eb2010-06-21 10:39:51 -07001379 */
Charles Clémentec28c7f2010-05-28 12:34:18 -07001380char
Joe Perchesd4945f02013-03-18 10:44:40 -07001381CARDbyGetTransmitPower(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001382 struct vnt_private *pDevice
Joe Perchesd4945f02013-03-18 10:44:40 -07001383)
Forest Bond5449c682009-04-25 10:30:44 -04001384{
Forest Bond5449c682009-04-25 10:30:44 -04001385
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001386 return pDevice->byCurPwrdBm;
Forest Bond5449c682009-04-25 10:30:44 -04001387}
1388
Charles Clément6b35b7b2010-05-07 12:30:19 -07001389void
Joe Perchesd4945f02013-03-18 10:44:40 -07001390CARDvSafeResetTx(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001391 struct vnt_private *pDevice
Joe Perchesd4945f02013-03-18 10:44:40 -07001392)
Forest Bond5449c682009-04-25 10:30:44 -04001393{
Joe Perchesd4945f02013-03-18 10:44:40 -07001394 unsigned int uu;
1395 PSTxDesc pCurrTD;
Forest Bond5449c682009-04-25 10:30:44 -04001396
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001397 /* initialize TD index */
Joe Perchesd4945f02013-03-18 10:44:40 -07001398 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1399 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001400
Joe Perchesd4945f02013-03-18 10:44:40 -07001401 for (uu = 0; uu < TYPE_MAXTD; uu++)
1402 pDevice->iTDUsed[uu] = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001403
Joe Perchesd4945f02013-03-18 10:44:40 -07001404 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1405 pCurrTD = &(pDevice->apTD0Rings[uu]);
1406 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001407 /* init all Tx Packet pointer to NULL */
Joe Perchesd4945f02013-03-18 10:44:40 -07001408 }
1409 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1410 pCurrTD = &(pDevice->apTD1Rings[uu]);
1411 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001412 /* init all Tx Packet pointer to NULL */
Joe Perchesd4945f02013-03-18 10:44:40 -07001413 }
Forest Bond5449c682009-04-25 10:30:44 -04001414
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001415 /* set MAC TD pointer */
Joe Perchesd4945f02013-03-18 10:44:40 -07001416 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1417 (pDevice->td0_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001418
Joe Perchesd4945f02013-03-18 10:44:40 -07001419 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1420 (pDevice->td1_pool_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001421
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001422 /* set MAC Beacon TX pointer */
Joe Perchesd4945f02013-03-18 10:44:40 -07001423 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1424 (pDevice->tx_beacon_dma));
Forest Bond5449c682009-04-25 10:30:44 -04001425}
1426
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001427/*
Forest Bond5449c682009-04-25 10:30:44 -04001428 * Description:
1429 * Reset Rx
1430 *
1431 * Parameters:
1432 * In:
1433 * pDevice - Pointer to the adapter
1434 * Out:
1435 * none
1436 *
1437 * Return Value: none
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001438 */
Charles Clément6b35b7b2010-05-07 12:30:19 -07001439void
Joe Perchesd4945f02013-03-18 10:44:40 -07001440CARDvSafeResetRx(
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001441 struct vnt_private *pDevice
Joe Perchesd4945f02013-03-18 10:44:40 -07001442)
Forest Bond5449c682009-04-25 10:30:44 -04001443{
Joe Perchesd4945f02013-03-18 10:44:40 -07001444 unsigned int uu;
1445 PSRxDesc pDesc;
Forest Bond5449c682009-04-25 10:30:44 -04001446
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001447 /* initialize RD index */
Joe Perchesd4945f02013-03-18 10:44:40 -07001448 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1449 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
Forest Bond5449c682009-04-25 10:30:44 -04001450
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001451 /* init state, all RD is chip's */
Joe Perchesd4945f02013-03-18 10:44:40 -07001452 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1453 pDesc = &(pDevice->aRD0Ring[uu]);
1454 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1455 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1456 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1457 }
Forest Bond5449c682009-04-25 10:30:44 -04001458
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001459 /* init state, all RD is chip's */
Joe Perchesd4945f02013-03-18 10:44:40 -07001460 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1461 pDesc = &(pDevice->aRD1Ring[uu]);
1462 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
1463 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1464 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1465 }
Forest Bond5449c682009-04-25 10:30:44 -04001466
Joe Perchesd4945f02013-03-18 10:44:40 -07001467 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1468 pDevice->cbFreeDFCB = pDevice->cbDFCB;
Forest Bond5449c682009-04-25 10:30:44 -04001469
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001470 /* set perPkt mode */
Joe Perchesd4945f02013-03-18 10:44:40 -07001471 MACvRx0PerPktMode(pDevice->PortOffset);
1472 MACvRx1PerPktMode(pDevice->PortOffset);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001473 /* set MAC RD pointer */
Joe Perchesd4945f02013-03-18 10:44:40 -07001474 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1475 pDevice->rd0_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001476
Joe Perchesd4945f02013-03-18 10:44:40 -07001477 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
1478 pDevice->rd1_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -04001479}
1480
Forest Bond5449c682009-04-25 10:30:44 -04001481/*
1482 * Description: Get response Control frame rate in CCK mode
1483 *
1484 * Parameters:
1485 * In:
1486 * pDevice - The adapter to be set
1487 * wRateIdx - Receiving data rate
1488 * Out:
1489 * none
1490 *
1491 * Return Value: response Control frame rate
Forest Bond5449c682009-04-25 10:30:44 -04001492 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001493static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
1494 unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001495{
Joe Perchesd4945f02013-03-18 10:44:40 -07001496 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001497
Joe Perchesd4945f02013-03-18 10:44:40 -07001498 while (ui > RATE_1M) {
Guido Martínezbc5cf652014-04-19 16:45:00 -03001499 if (pDevice->wBasicRate & ((unsigned short)1 << ui))
Joe Perchesd4945f02013-03-18 10:44:40 -07001500 return (unsigned short)ui;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001501
Joe Perchesd4945f02013-03-18 10:44:40 -07001502 ui--;
1503 }
1504 return (unsigned short)RATE_1M;
Forest Bond5449c682009-04-25 10:30:44 -04001505}
1506
1507/*
1508 * Description: Get response Control frame rate in OFDM mode
1509 *
1510 * Parameters:
1511 * In:
1512 * pDevice - The adapter to be set
1513 * wRateIdx - Receiving data rate
1514 * Out:
1515 * none
1516 *
1517 * Return Value: response Control frame rate
Forest Bond5449c682009-04-25 10:30:44 -04001518 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001519static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
1520 unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001521{
Joe Perchesd4945f02013-03-18 10:44:40 -07001522 unsigned int ui = (unsigned int) wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -04001523
Joe Perches48caf5a2014-08-17 09:17:04 -07001524 pr_debug("BASIC RATE: %X\n", pDevice->wBasicRate);
Forest Bond5449c682009-04-25 10:30:44 -04001525
Joe Perchesd4945f02013-03-18 10:44:40 -07001526 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
Joe Perches48caf5a2014-08-17 09:17:04 -07001527 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
Joe Perchesd4945f02013-03-18 10:44:40 -07001528 if (wRateIdx > RATE_24M)
1529 wRateIdx = RATE_24M;
1530 return wRateIdx;
1531 }
1532 while (ui > RATE_11M) {
1533 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
Joe Perches48caf5a2014-08-17 09:17:04 -07001534 pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
Joe Perchesd4945f02013-03-18 10:44:40 -07001535 return (unsigned short)ui;
1536 }
1537 ui--;
1538 }
Joe Perches48caf5a2014-08-17 09:17:04 -07001539 pr_debug("CARDwGetOFDMControlRate: 6M\n");
Joe Perchesd4945f02013-03-18 10:44:40 -07001540 return (unsigned short)RATE_24M;
Forest Bond5449c682009-04-25 10:30:44 -04001541}
1542
Forest Bond5449c682009-04-25 10:30:44 -04001543/*
1544 * Description: Set RSPINF
1545 *
1546 * Parameters:
1547 * In:
1548 * pDevice - The adapter to be set
1549 * Out:
1550 * none
1551 *
1552 * Return Value: None.
Forest Bond5449c682009-04-25 10:30:44 -04001553 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001554void CARDvSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType)
Forest Bond5449c682009-04-25 10:30:44 -04001555{
Malcolm Priestley864a5a32014-08-20 22:30:30 +01001556 union vnt_phy_field_swap phy;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001557 unsigned char byTxRate, byRsvTime; /* For OFDM */
Forest Bond5449c682009-04-25 10:30:44 -04001558
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001559 /* Set to Page1 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001560 MACvSelectPage1(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001561
Malcolm Priestley864a5a32014-08-20 22:30:30 +01001562 /* RSPINF_b_1 */
1563 vnt_get_phy_field(pDevice, 14,
1564 CARDwGetCCKControlRate(pDevice, RATE_1M),
1565 PK_TYPE_11B, &phy.field_read);
Forest Bond5449c682009-04-25 10:30:44 -04001566
Malcolm Priestley864a5a32014-08-20 22:30:30 +01001567 /* swap over to get correct write order */
1568 swap(phy.swap[0], phy.swap[1]);
Forest Bond5449c682009-04-25 10:30:44 -04001569
Malcolm Priestley864a5a32014-08-20 22:30:30 +01001570 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
Forest Bond5449c682009-04-25 10:30:44 -04001571
Malcolm Priestley864a5a32014-08-20 22:30:30 +01001572 /* RSPINF_b_2 */
1573 vnt_get_phy_field(pDevice, 14,
1574 CARDwGetCCKControlRate(pDevice, RATE_2M),
1575 PK_TYPE_11B, &phy.field_read);
Forest Bond5449c682009-04-25 10:30:44 -04001576
Malcolm Priestley864a5a32014-08-20 22:30:30 +01001577 swap(phy.swap[0], phy.swap[1]);
1578
1579 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
1580
1581 /* RSPINF_b_5 */
1582 vnt_get_phy_field(pDevice, 14,
1583 CARDwGetCCKControlRate(pDevice, RATE_5M),
1584 PK_TYPE_11B, &phy.field_read);
1585
1586 swap(phy.swap[0], phy.swap[1]);
1587
1588 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
1589
1590 /* RSPINF_b_11 */
1591 vnt_get_phy_field(pDevice, 14,
1592 CARDwGetCCKControlRate(pDevice, RATE_11M),
1593 PK_TYPE_11B, &phy.field_read);
1594
1595 swap(phy.swap[0], phy.swap[1]);
1596
1597 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
1598
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001599 /* RSPINF_a_6 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001600 s_vCalculateOFDMRParameter(RATE_6M,
1601 ePHYType,
1602 &byTxRate,
1603 &byRsvTime);
1604 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001605 /* RSPINF_a_9 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001606 s_vCalculateOFDMRParameter(RATE_9M,
1607 ePHYType,
1608 &byTxRate,
1609 &byRsvTime);
1610 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001611 /* RSPINF_a_12 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001612 s_vCalculateOFDMRParameter(RATE_12M,
1613 ePHYType,
1614 &byTxRate,
1615 &byRsvTime);
1616 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001617 /* RSPINF_a_18 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001618 s_vCalculateOFDMRParameter(RATE_18M,
1619 ePHYType,
1620 &byTxRate,
1621 &byRsvTime);
1622 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001623 /* RSPINF_a_24 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001624 s_vCalculateOFDMRParameter(RATE_24M,
1625 ePHYType,
1626 &byTxRate,
1627 &byRsvTime);
1628 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001629 /* RSPINF_a_36 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001630 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1631 ePHYType,
1632 &byTxRate,
1633 &byRsvTime);
1634 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001635 /* RSPINF_a_48 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001636 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1637 ePHYType,
1638 &byTxRate,
1639 &byRsvTime);
1640 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001641 /* RSPINF_a_54 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001642 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1643 ePHYType,
1644 &byTxRate,
1645 &byRsvTime);
1646 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001647 /* RSPINF_a_72 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001648 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1649 ePHYType,
1650 &byTxRate,
1651 &byRsvTime);
1652 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001653 /* Set to Page0 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001654 MACvSelectPage0(pDevice->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -04001655}
1656
1657/*
1658 * Description: Update IFS
1659 *
1660 * Parameters:
1661 * In:
1662 * pDevice - The adapter to be set
1663 * Out:
1664 * none
1665 *
1666 * Return Value: None.
Forest Bond5449c682009-04-25 10:30:44 -04001667 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001668void vUpdateIFS(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -04001669{
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001670 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
Forest Bond5449c682009-04-25 10:30:44 -04001671
Joe Perchesd4945f02013-03-18 10:44:40 -07001672 unsigned char byMaxMin = 0;
Guillaume Clement6b711272014-07-25 01:06:16 +02001673
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001674 if (pDevice->byPacketType == PK_TYPE_11A) { /*0000 0000 0000 0000,11a*/
Joe Perchesd4945f02013-03-18 10:44:40 -07001675 pDevice->uSlot = C_SLOT_SHORT;
1676 pDevice->uSIFS = C_SIFS_A;
1677 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1678 pDevice->uCwMin = C_CWMIN_A;
1679 byMaxMin = 4;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001680 } else if (pDevice->byPacketType == PK_TYPE_11B) {
1681 /* 0000 0001 0000 0000,11b */
Joe Perchesd4945f02013-03-18 10:44:40 -07001682 pDevice->uSlot = C_SLOT_LONG;
1683 pDevice->uSIFS = C_SIFS_BG;
1684 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1685 pDevice->uCwMin = C_CWMIN_B;
1686 byMaxMin = 5;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001687 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
Joe Perchesd4945f02013-03-18 10:44:40 -07001688 pDevice->uSIFS = C_SIFS_BG;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001689 if (pDevice->bShortSlotTime)
Joe Perchesd4945f02013-03-18 10:44:40 -07001690 pDevice->uSlot = C_SLOT_SHORT;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001691 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001692 pDevice->uSlot = C_SLOT_LONG;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001693
Joe Perchesd4945f02013-03-18 10:44:40 -07001694 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001695 if (pDevice->wBasicRate & 0x0150) {
1696 /* 0000 0001 0101 0000,24M,12M,6M */
Joe Perchesd4945f02013-03-18 10:44:40 -07001697 pDevice->uCwMin = C_CWMIN_A;
1698 byMaxMin = 4;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001699 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -07001700 pDevice->uCwMin = C_CWMIN_B;
1701 byMaxMin = 5;
1702 }
1703 }
Forest Bond5449c682009-04-25 10:30:44 -04001704
Joe Perchesd4945f02013-03-18 10:44:40 -07001705 pDevice->uCwMax = C_CWMAX;
1706 pDevice->uEIFS = C_EIFS;
1707 if (pDevice->byRFType == RF_RFMD2959) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001708 /* bcs TX_PE will reserve 3 us */
Joe Perchesd4945f02013-03-18 10:44:40 -07001709 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1710 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1711 } else {
1712 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1713 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1714 }
1715 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1716 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001717 byMaxMin |= 0xA0; /* 1010 1111,C_CWMAX = 1023 */
Joe Perchesd4945f02013-03-18 10:44:40 -07001718 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
Forest Bond5449c682009-04-25 10:30:44 -04001719}
1720
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001721void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -04001722{
Joe Perchesd4945f02013-03-18 10:44:40 -07001723 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1724 unsigned char ii;
Forest Bond5449c682009-04-25 10:30:44 -04001725
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001726 /* Determines the highest basic rate. */
Joe Perchesd4945f02013-03-18 10:44:40 -07001727 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1728 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1729 byTopOFDM = ii;
1730 break;
1731 }
1732 }
1733 pDevice->byTopOFDMBasicRate = byTopOFDM;
Forest Bond5449c682009-04-25 10:30:44 -04001734
Joe Perchesd4945f02013-03-18 10:44:40 -07001735 for (ii = RATE_11M;; ii--) {
1736 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
1737 byTopCCK = ii;
1738 break;
1739 }
1740 if (ii == RATE_1M)
1741 break;
1742 }
1743 pDevice->byTopCCKBasicRate = byTopCCK;
Forest Bond5449c682009-04-25 10:30:44 -04001744}
1745
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001746bool CARDbAddBasicRate(struct vnt_private *pDevice, unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001747{
Joe Perchesd4945f02013-03-18 10:44:40 -07001748 unsigned short wRate = (unsigned short)(1<<wRateIdx);
Forest Bond5449c682009-04-25 10:30:44 -04001749
Joe Perchesd4945f02013-03-18 10:44:40 -07001750 pDevice->wBasicRate |= wRate;
Forest Bond5449c682009-04-25 10:30:44 -04001751
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001752 /* Determines the highest basic rate. */
Joe Perchesd4945f02013-03-18 10:44:40 -07001753 CARDvUpdateBasicTopRate((void *)pDevice);
Forest Bond5449c682009-04-25 10:30:44 -04001754
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001755 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001756}
1757
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001758bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -04001759{
Joe Perchesd4945f02013-03-18 10:44:40 -07001760 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001761
Joe Perchesd4945f02013-03-18 10:44:40 -07001762 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1763 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
1764 return true;
1765 }
1766 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001767}
1768
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001769unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -04001770{
Forest Bond5449c682009-04-25 10:30:44 -04001771
Guido Martínezbc5cf652014-04-19 16:45:00 -03001772 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
Joe Perchesd4945f02013-03-18 10:44:40 -07001773 return (unsigned char)pDevice->byBBType;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001774 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
Joe Perchesd4945f02013-03-18 10:44:40 -07001775 return PK_TYPE_11GA;
Guido Martínezbc5cf652014-04-19 16:45:00 -03001776 else
Joe Perchesd4945f02013-03-18 10:44:40 -07001777 return PK_TYPE_11GB;
Forest Bond5449c682009-04-25 10:30:44 -04001778}
1779
1780/*
1781 * Description: Set NIC Loopback mode
1782 *
1783 * Parameters:
1784 * In:
1785 * pDevice - The adapter to be set
1786 * wLoopbackMode - Loopback mode to be set
1787 * Out:
1788 * none
1789 *
1790 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -04001791 */
Guillaume Clement16834402014-07-22 22:08:26 +02001792void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -04001793{
Joe Perchesd4945f02013-03-18 10:44:40 -07001794 switch (wLoopbackMode) {
1795 case CARD_LB_NONE:
1796 case CARD_LB_MAC:
1797 case CARD_LB_PHY:
1798 break;
1799 default:
1800 ASSERT(false);
1801 break;
1802 }
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001803 /* set MAC loopback */
Joe Perchesd4945f02013-03-18 10:44:40 -07001804 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001805 /* set Baseband loopback */
Forest Bond5449c682009-04-25 10:30:44 -04001806}
1807
Forest Bond5449c682009-04-25 10:30:44 -04001808/*
1809 * Description: Software Reset NIC
1810 *
1811 * Parameters:
1812 * In:
1813 * pDevice - The adapter to be reset
1814 * Out:
1815 * none
1816 *
1817 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -04001818 */
Malcolm Priestleyd0522702014-08-10 15:46:57 +01001819bool CARDbSoftwareReset(struct vnt_private *pDevice)
Forest Bond5449c682009-04-25 10:30:44 -04001820{
Forest Bond5449c682009-04-25 10:30:44 -04001821
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001822 /* reset MAC */
Joe Perchesd4945f02013-03-18 10:44:40 -07001823 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1824 return false;
Forest Bond5449c682009-04-25 10:30:44 -04001825
Joe Perchesd4945f02013-03-18 10:44:40 -07001826 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001827}
1828
Forest Bond5449c682009-04-25 10:30:44 -04001829/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -07001830 * Description: Calculate TSF offset of two TSF input
Forest Bond5449c682009-04-25 10:30:44 -04001831 * Get TSF Offset from RxBCN's TSF and local TSF
1832 *
1833 * Parameters:
1834 * In:
1835 * pDevice - The adapter to be sync.
1836 * qwTSF1 - Rx BCN's TSF
1837 * qwTSF2 - Local TSF
1838 * Out:
1839 * none
1840 *
1841 * Return Value: TSF Offset value
Forest Bond5449c682009-04-25 10:30:44 -04001842 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001843u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
Forest Bond5449c682009-04-25 10:30:44 -04001844{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001845 u64 qwTSFOffset = 0;
Joe Perchesd4945f02013-03-18 10:44:40 -07001846 unsigned short wRxBcnTSFOffst = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001847
Joe Perchesd4945f02013-03-18 10:44:40 -07001848 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
Guido Martínezbc5cf652014-04-19 16:45:00 -03001849
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001850 qwTSF2 += (u64)wRxBcnTSFOffst;
1851
1852 qwTSFOffset = qwTSF1 - qwTSF2;
1853
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001854 return qwTSFOffset;
Forest Bond5449c682009-04-25 10:30:44 -04001855}
1856
Forest Bond5449c682009-04-25 10:30:44 -04001857/*
1858 * Description: Read NIC TSF counter
1859 * Get local TSF counter
1860 *
1861 * Parameters:
1862 * In:
1863 * pDevice - The adapter to be read
1864 * Out:
1865 * qwCurrTSF - Current TSF counter
1866 *
Charles Clément5a5a2a62010-08-01 17:15:49 +02001867 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -04001868 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001869bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF)
Forest Bond5449c682009-04-25 10:30:44 -04001870{
Joe Perchesd4945f02013-03-18 10:44:40 -07001871 unsigned short ww;
1872 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -04001873
Joe Perchesd4945f02013-03-18 10:44:40 -07001874 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
1875 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1876 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
1877 if (!(byData & TFTCTL_TSFCNTRRD))
1878 break;
1879 }
1880 if (ww == W_MAX_TIMEOUT)
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001881 return false;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001882 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
1883 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
Forest Bond5449c682009-04-25 10:30:44 -04001884
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001885 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001886}
1887
Forest Bond5449c682009-04-25 10:30:44 -04001888/*
1889 * Description: Read NIC TSF counter
1890 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1891 *
1892 * Parameters:
1893 * In:
1894 * qwTSF - Current TSF counter
1895 * wbeaconInterval - Beacon Interval
1896 * Out:
1897 * qwCurrTSF - Current TSF counter
1898 *
1899 * Return Value: TSF value of next Beacon
Forest Bond5449c682009-04-25 10:30:44 -04001900 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001901u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04001902{
Malcolm Priestley989ae862014-08-10 12:21:59 +01001903 u32 beacon_int;
Forest Bond5449c682009-04-25 10:30:44 -04001904
Malcolm Priestley989ae862014-08-10 12:21:59 +01001905 beacon_int = wBeaconInterval * 1024;
Malcolm Priestley989ae862014-08-10 12:21:59 +01001906 if (beacon_int) {
1907 do_div(qwTSF, beacon_int);
1908 qwTSF += 1;
1909 qwTSF *= beacon_int;
1910 }
Forest Bond5449c682009-04-25 10:30:44 -04001911
Joe Perchesa4ef27a2013-03-18 20:55:38 -07001912 return qwTSF;
Forest Bond5449c682009-04-25 10:30:44 -04001913}
1914
Forest Bond5449c682009-04-25 10:30:44 -04001915/*
1916 * Description: Set NIC TSF counter for first Beacon time
1917 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1918 *
1919 * Parameters:
1920 * In:
1921 * dwIoBase - IO Base
1922 * wBeaconInterval - Beacon Interval
1923 * Out:
1924 * none
1925 *
1926 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -04001927 */
Guillaume Clement16834402014-07-22 22:08:26 +02001928void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04001929{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001930 u64 qwNextTBTT = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001931
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001932 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); /* Get Local TSF counter */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001933
Joe Perchesd4945f02013-03-18 10:44:40 -07001934 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001935 /* Set NextTBTT */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001936 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
1937 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -07001938 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -04001939}
1940
Forest Bond5449c682009-04-25 10:30:44 -04001941/*
1942 * Description: Sync NIC TSF counter for Beacon time
1943 * Get NEXTTBTT and write to HW
1944 *
1945 * Parameters:
1946 * In:
1947 * pDevice - The adapter to be set
1948 * qwTSF - Current TSF counter
1949 * wBeaconInterval - Beacon Interval
1950 * Out:
1951 * none
1952 *
1953 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -04001954 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001955void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04001956{
Joe Perchesd4945f02013-03-18 10:44:40 -07001957 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001958 /* Set NextTBTT */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001959 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
1960 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
Joe Perchesd4945f02013-03-18 10:44:40 -07001961 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Joe Perches48caf5a2014-08-17 09:17:04 -07001962 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);
Forest Bond5449c682009-04-25 10:30:44 -04001963}