blob: 9794116a241b2ba91b9d660d3eae03ad48897164 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -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
Malcolm Priestley1a792942014-05-30 16:27:46 +010023 * vnt_set_rspinf - Set RSPINF
Malcolm Priestleyc7ee9ee2014-05-30 16:27:44 +010024 * vnt_update_ifs - Update slotTime,SIFS,DIFS, and EIFS
Malcolm Priestley47203c42014-05-30 16:27:45 +010025 * vnt_update_top_rates - Update BasicTopRate
Malcolm Priestley9a2cffd2014-05-30 16:27:47 +010026 * vnt_add_basic_rate - Add to BasicRateSet
Forest Bond92b96792009-06-13 07:38:31 -040027 * CARDbSetBasicRate - Set Basic Tx Rate
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +010028 * vnt_ofdm_min_rate - Check if any OFDM rate is in BasicRateSet
Forest Bond92b96792009-06-13 07:38:31 -040029 * CARDvSetLoopbackMode - Set Loopback mode
30 * CARDbSoftwareReset - Sortware reset NIC
Malcolm Priestleyecbc0a12014-05-30 16:27:50 +010031 * vnt_get_tsf_offset - Calculate TSFOffset
Malcolm Priestley4a9f4c62014-05-30 23:22:47 +010032 * vnt_get_current_tsf - Read Current NIC TSF counter
Malcolm Priestley75ef1b512014-05-30 23:22:49 +010033 * vnt_get_next_tbtt - Calculate Next Beacon TSF counter
Malcolm Priestley6964cd12014-05-30 23:22:50 +010034 * vnt_reset_next_tbtt - Set NIC Beacon time
Malcolm Priestley88ec2f72014-05-30 23:22:51 +010035 * vnt_update_next_tbtt - Sync. NIC Beacon time
Malcolm Priestleyfa26e0b2014-05-30 23:22:52 +010036 * vnt_radio_power_off - Turn Off NIC Radio Power
Malcolm Priestley8a5e6c82014-05-30 23:22:53 +010037 * vnt_radio_power_on - Turn On NIC Radio Power
Forest Bond92b96792009-06-13 07:38:31 -040038 * CARDbSetWEPMode - Set NIC Wep mode
39 * CARDbSetTxPower - Set NIC tx power
40 *
41 * Revision History:
42 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
Justin P. Mattocka0a1f612012-08-26 08:16:43 -070043 * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase.
Malcolm Priestleyc7ee9ee2014-05-30 16:27:44 +010044 * 09-01-2003 Bryan YC Fan: Add vnt_update_ifs().
Forest Bond92b96792009-06-13 07:38:31 -040045 *
46 */
47
Malcolm Priestleydd0a7742012-12-10 21:59:10 +000048#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040049#include "tmacro.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "desc.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "power.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "key.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "rc4.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "country.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "datarate.h"
Malcolm Priestley62c85262014-05-26 13:59:07 +010060#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040061
Andres More3eaca0d2013-02-25 20:32:52 -050062//const u16 cwRXBCNTSFOff[MAX_RATE] =
Forest Bond92b96792009-06-13 07:38:31 -040063//{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
64
Valentina Manea3b138852013-11-04 10:44:02 +020065static const u16 cwRXBCNTSFOff[MAX_RATE] =
Forest Bond92b96792009-06-13 07:38:31 -040066{192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3};
67
Forest Bond92b96792009-06-13 07:38:31 -040068/*
69 * Description: Set NIC media channel
70 *
71 * Parameters:
72 * In:
73 * pDevice - The adapter to be set
Malcolm Priestley7387f432013-12-12 23:33:08 +000074 * connection_channel - Channel to be set
Forest Bond92b96792009-06-13 07:38:31 -040075 * Out:
76 * none
Forest Bond92b96792009-06-13 07:38:31 -040077 */
Malcolm Priestley084fc8f2014-05-30 16:27:40 +010078void vnt_set_channel(struct vnt_private *priv, u32 connection_channel)
Forest Bond92b96792009-06-13 07:38:31 -040079{
Forest Bond92b96792009-06-13 07:38:31 -040080
Malcolm Priestley7387f432013-12-12 23:33:08 +000081 if (priv->byBBType == BB_TYPE_11A) {
82 if ((connection_channel < (CB_MAX_CHANNEL_24G + 1)) ||
83 (connection_channel > CB_MAX_CHANNEL))
84 connection_channel = (CB_MAX_CHANNEL_24G + 1);
85 } else {
86 if ((connection_channel > CB_MAX_CHANNEL_24G) ||
87 (connection_channel == 0))
88 connection_channel = 1;
89 }
Forest Bond92b96792009-06-13 07:38:31 -040090
Malcolm Priestley7387f432013-12-12 23:33:08 +000091 /* clear NAV */
Malcolm Priestley36957532014-05-31 11:50:42 +010092 vnt_mac_reg_bits_on(priv, MAC_REG_MACCR, MACCR_CLRNAV);
Forest Bond92b96792009-06-13 07:38:31 -040093
Malcolm Priestley7387f432013-12-12 23:33:08 +000094 /* Set Channel[7] = 0 to tell H/W channel is changing now. */
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +010095 vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, 0xb0);
Forest Bond92b96792009-06-13 07:38:31 -040096
Malcolm Priestley1390b022014-05-26 13:59:01 +010097 vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNLE,
Malcolm Priestley7387f432013-12-12 23:33:08 +000098 connection_channel, 0, 0, NULL);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestley7387f432013-12-12 23:33:08 +0000100 if (priv->byBBType == BB_TYPE_11A) {
101 priv->byCurPwr = 0xff;
Malcolm Priestley8543bb92014-05-27 21:05:22 +0100102 vnt_rf_set_txpower(priv,
Malcolm Priestley7387f432013-12-12 23:33:08 +0000103 priv->abyOFDMAPwrTbl[connection_channel-15], RATE_54M);
104 } else if (priv->byBBType == BB_TYPE_11G) {
105 priv->byCurPwr = 0xff;
Malcolm Priestley8543bb92014-05-27 21:05:22 +0100106 vnt_rf_set_txpower(priv,
Malcolm Priestley7387f432013-12-12 23:33:08 +0000107 priv->abyOFDMPwrTbl[connection_channel-1], RATE_54M);
108 } else {
109 priv->byCurPwr = 0xff;
Malcolm Priestley8543bb92014-05-27 21:05:22 +0100110 vnt_rf_set_txpower(priv,
Malcolm Priestley7387f432013-12-12 23:33:08 +0000111 priv->abyCCKPwrTbl[connection_channel-1], RATE_1M);
112 }
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100114 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL,
Malcolm Priestley7387f432013-12-12 23:33:08 +0000115 (u8)(connection_channel|0x80));
Forest Bond92b96792009-06-13 07:38:31 -0400116}
117
118/*
119 * Description: Get CCK mode basic rate
120 *
121 * Parameters:
122 * In:
Malcolm Priestley3d2988c2014-05-25 21:36:23 +0100123 * priv - The adapter to be set
124 * rate_idx - Receiving data rate
Forest Bond92b96792009-06-13 07:38:31 -0400125 * Out:
126 * none
127 *
128 * Return Value: response Control frame rate
129 *
130 */
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100131static u16 vnt_get_cck_rate(struct vnt_private *priv, u16 rate_idx)
Forest Bond92b96792009-06-13 07:38:31 -0400132{
Malcolm Priestley3d2988c2014-05-25 21:36:23 +0100133 u16 ui = rate_idx;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000134
135 while (ui > RATE_1M) {
Malcolm Priestley3d2988c2014-05-25 21:36:23 +0100136 if (priv->wBasicRate & (1 << ui))
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000137 return ui;
138 ui--;
139 }
140
141 return RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -0400142}
143
144/*
145 * Description: Get OFDM mode basic rate
146 *
147 * Parameters:
148 * In:
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100149 * priv - The adapter to be set
150 * rate_idx - Receiving data rate
Forest Bond92b96792009-06-13 07:38:31 -0400151 * Out:
152 * none
153 *
154 * Return Value: response Control frame rate
155 *
156 */
Malcolm Priestley15fa7ce2014-05-30 16:27:42 +0100157static u16 vnt_get_ofdm_rate(struct vnt_private *priv, u16 rate_idx)
Forest Bond92b96792009-06-13 07:38:31 -0400158{
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100159 u16 ui = rate_idx;
Forest Bond92b96792009-06-13 07:38:31 -0400160
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100161 dev_dbg(&priv->usb->dev, "%s basic rate: %d\n",
162 __func__, priv->wBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400163
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +0100164 if (!vnt_ofdm_min_rate(priv)) {
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100165 dev_dbg(&priv->usb->dev, "%s (NO OFDM) %d\n",
166 __func__, rate_idx);
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100167 if (rate_idx > RATE_24M)
168 rate_idx = RATE_24M;
169 return rate_idx;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000170 }
171
172 while (ui > RATE_11M) {
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100173 if (priv->wBasicRate & (1 << ui)) {
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100174 dev_dbg(&priv->usb->dev, "%s rate: %d\n",
175 __func__, ui);
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000176 return ui;
177 }
178 ui--;
179 }
180
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100181 dev_dbg(&priv->usb->dev, "%s basic rate: 24M\n", __func__);
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000182
183 return RATE_24M;
Forest Bond92b96792009-06-13 07:38:31 -0400184}
185
186/*
Justin P. Mattocka0a1f612012-08-26 08:16:43 -0700187 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond92b96792009-06-13 07:38:31 -0400188 *
189 * Parameters:
Malcolm Priestley3605f842014-05-23 18:00:15 +0100190 * In:
191 * rate - Tx Rate
192 * bb_type - Tx Packet type
193 * Out:
194 * tx_rate - pointer to RSPINF TxRate field
195 * rsv_time- pointer to RSPINF RsvTime field
Forest Bond92b96792009-06-13 07:38:31 -0400196 *
197 * Return Value: none
198 *
199 */
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100200static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type,
Malcolm Priestley3605f842014-05-23 18:00:15 +0100201 u8 *tx_rate, u8 *rsv_time)
Forest Bond92b96792009-06-13 07:38:31 -0400202{
Forest Bond92b96792009-06-13 07:38:31 -0400203
Malcolm Priestley3605f842014-05-23 18:00:15 +0100204 switch (rate) {
205 case RATE_6M:
206 if (bb_type == BB_TYPE_11A) {
207 *tx_rate = 0x9b;
208 *rsv_time = 24;
209 } else {
210 *tx_rate = 0x8b;
211 *rsv_time = 30;
212 }
213 break;
214 case RATE_9M:
215 if (bb_type == BB_TYPE_11A) {
216 *tx_rate = 0x9f;
217 *rsv_time = 16;
218 } else {
219 *tx_rate = 0x8f;
220 *rsv_time = 22;
221 }
222 break;
223 case RATE_12M:
224 if (bb_type == BB_TYPE_11A) {
225 *tx_rate = 0x9a;
226 *rsv_time = 12;
227 } else {
228 *tx_rate = 0x8a;
229 *rsv_time = 18;
230 }
231 break;
232 case RATE_18M:
233 if (bb_type == BB_TYPE_11A) {
234 *tx_rate = 0x9e;
235 *rsv_time = 8;
236 } else {
237 *tx_rate = 0x8e;
238 *rsv_time = 14;
239 }
240 break;
241 case RATE_36M:
242 if (bb_type == BB_TYPE_11A) {
243 *tx_rate = 0x9d;
244 *rsv_time = 4;
245 } else {
246 *tx_rate = 0x8d;
247 *rsv_time = 10;
248 }
249 break;
250 case RATE_48M:
251 if (bb_type == BB_TYPE_11A) {
252 *tx_rate = 0x98;
253 *rsv_time = 4;
254 } else {
255 *tx_rate = 0x88;
Malcolm Priestleyfd4859f2014-05-24 14:37:10 +0100256 *rsv_time = 10;
Malcolm Priestley3605f842014-05-23 18:00:15 +0100257 }
258 break;
259 case RATE_54M:
260 if (bb_type == BB_TYPE_11A) {
261 *tx_rate = 0x9c;
262 *rsv_time = 4;
263 } else {
264 *tx_rate = 0x8c;
265 *rsv_time = 10;
266 }
267 break;
268 case RATE_24M:
269 default:
270 if (bb_type == BB_TYPE_11A) {
271 *tx_rate = 0x99;
272 *rsv_time = 8;
273 } else {
274 *tx_rate = 0x89;
275 *rsv_time = 14;
276 }
277 break;
278 }
Forest Bond92b96792009-06-13 07:38:31 -0400279}
280
281/*
282 * Description: Set RSPINF
283 *
284 * Parameters:
285 * In:
286 * pDevice - The adapter to be set
287 * Out:
288 * none
289 *
290 * Return Value: None.
291 *
292 */
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100293
Malcolm Priestley1a792942014-05-30 16:27:46 +0100294void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type)
Forest Bond92b96792009-06-13 07:38:31 -0400295{
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100296 struct vnt_phy_field phy[4];
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100297 u8 tx_rate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
298 u8 rsv_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
299 u8 data[34];
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000300 int i;
Forest Bond92b96792009-06-13 07:38:31 -0400301
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100302 /*RSPINF_b_1*/
303 BBvCalculateParameter(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100304 vnt_get_cck_rate(priv, RATE_1M), PK_TYPE_11B, &phy[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400305
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100306 /*RSPINF_b_2*/
307 BBvCalculateParameter(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100308 vnt_get_cck_rate(priv, RATE_2M), PK_TYPE_11B, &phy[1]);
Forest Bond92b96792009-06-13 07:38:31 -0400309
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100310 /*RSPINF_b_5*/
311 BBvCalculateParameter(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100312 vnt_get_cck_rate(priv, RATE_5M), PK_TYPE_11B, &phy[2]);
Forest Bond92b96792009-06-13 07:38:31 -0400313
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100314 /*RSPINF_b_11*/
315 BBvCalculateParameter(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100316 vnt_get_cck_rate(priv, RATE_11M), PK_TYPE_11B, &phy[3]);
Forest Bond92b96792009-06-13 07:38:31 -0400317
Forest Bond92b96792009-06-13 07:38:31 -0400318
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100319 /*RSPINF_a_6*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100320 vnt_calculate_ofdm_rate(RATE_6M, bb_type, &tx_rate[0], &rsv_time[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400321
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100322 /*RSPINF_a_9*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100323 vnt_calculate_ofdm_rate(RATE_9M, bb_type, &tx_rate[1], &rsv_time[1]);
Forest Bond92b96792009-06-13 07:38:31 -0400324
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100325 /*RSPINF_a_12*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100326 vnt_calculate_ofdm_rate(RATE_12M, bb_type, &tx_rate[2], &rsv_time[2]);
Forest Bond92b96792009-06-13 07:38:31 -0400327
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100328 /*RSPINF_a_18*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100329 vnt_calculate_ofdm_rate(RATE_18M, bb_type, &tx_rate[3], &rsv_time[3]);
Forest Bond92b96792009-06-13 07:38:31 -0400330
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100331 /*RSPINF_a_24*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100332 vnt_calculate_ofdm_rate(RATE_24M, bb_type, &tx_rate[4], &rsv_time[4]);
Forest Bond92b96792009-06-13 07:38:31 -0400333
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100334 /*RSPINF_a_36*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100335 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_36M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100336 bb_type, &tx_rate[5], &rsv_time[5]);
Forest Bond92b96792009-06-13 07:38:31 -0400337
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100338 /*RSPINF_a_48*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100339 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_48M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100340 bb_type, &tx_rate[6], &rsv_time[6]);
Forest Bond92b96792009-06-13 07:38:31 -0400341
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100342 /*RSPINF_a_54*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100343 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100344 bb_type, &tx_rate[7], &rsv_time[7]);
Forest Bond92b96792009-06-13 07:38:31 -0400345
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100346 /*RSPINF_a_72*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100347 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100348 bb_type, &tx_rate[8], &rsv_time[8]);
Forest Bond92b96792009-06-13 07:38:31 -0400349
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100350 put_unaligned(phy[0].len, (u16 *)&data[0]);
351 data[2] = phy[0].signal;
352 data[3] = phy[0].service;
Forest Bond92b96792009-06-13 07:38:31 -0400353
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100354 put_unaligned(phy[1].len, (u16 *)&data[4]);
355 data[6] = phy[1].signal;
356 data[7] = phy[1].service;
Forest Bond92b96792009-06-13 07:38:31 -0400357
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100358 put_unaligned(phy[2].len, (u16 *)&data[8]);
359 data[10] = phy[2].signal;
360 data[11] = phy[2].service;
Forest Bond92b96792009-06-13 07:38:31 -0400361
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100362 put_unaligned(phy[3].len, (u16 *)&data[12]);
363 data[14] = phy[3].signal;
364 data[15] = phy[3].service;
Forest Bond92b96792009-06-13 07:38:31 -0400365
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100366 for (i = 0; i < 9; i++) {
367 data[16 + i * 2] = tx_rate[i];
368 data[16 + i * 2 + 1] = rsv_time[i];
369 }
Forest Bond92b96792009-06-13 07:38:31 -0400370
Malcolm Priestley1390b022014-05-26 13:59:01 +0100371 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100372 MAC_REG_RSPINF_B_1, MESSAGE_REQUEST_MACREG, 34, &data[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400373}
374
375/*
376 * Description: Update IFS
377 *
378 * Parameters:
379 * In:
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100380 * priv - The adapter to be set
381 * Out:
382 * none
Forest Bond92b96792009-06-13 07:38:31 -0400383 *
384 * Return Value: None.
385 *
386 */
Malcolm Priestleyc7ee9ee2014-05-30 16:27:44 +0100387void vnt_update_ifs(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400388{
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100389 u8 max_min = 0;
390 u8 data[4];
Forest Bond92b96792009-06-13 07:38:31 -0400391
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100392 if (priv->byPacketType == PK_TYPE_11A) {
393 priv->uSlot = C_SLOT_SHORT;
394 priv->uSIFS = C_SIFS_A;
395 priv->uDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
396 priv->uCwMin = C_CWMIN_A;
397 max_min = 4;
398 } else if (priv->byPacketType == PK_TYPE_11B) {
399 priv->uSlot = C_SLOT_LONG;
400 priv->uSIFS = C_SIFS_BG;
401 priv->uDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
402 priv->uCwMin = C_CWMIN_B;
403 max_min = 5;
404 } else {/* PK_TYPE_11GA & PK_TYPE_11GB */
405 u8 rate = 0;
406 bool ofdm_rate = false;
407 unsigned int ii = 0;
408 PWLAN_IE_SUPP_RATES item_rates = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400409
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100410 priv->uSIFS = C_SIFS_BG;
Forest Bond92b96792009-06-13 07:38:31 -0400411
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100412 if (priv->bShortSlotTime)
413 priv->uSlot = C_SLOT_SHORT;
414 else
415 priv->uSlot = C_SLOT_LONG;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100417 priv->uDIFS = C_SIFS_BG + 2 * priv->uSlot;
Forest Bond92b96792009-06-13 07:38:31 -0400418
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100419 item_rates =
420 (PWLAN_IE_SUPP_RATES)priv->vnt_mgmt.abyCurrSuppRates;
Forest Bond92b96792009-06-13 07:38:31 -0400421
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100422 for (ii = 0; ii < item_rates->len; ii++) {
423 rate = (u8)(item_rates->abyRates[ii] & 0x7f);
424 if (RATEwGetRateIdx(rate) > RATE_11M) {
425 ofdm_rate = true;
426 break;
427 }
428 }
429
430 if (ofdm_rate == false) {
431 item_rates = (PWLAN_IE_SUPP_RATES)priv->vnt_mgmt
432 .abyCurrExtSuppRates;
433 for (ii = 0; ii < item_rates->len; ii++) {
434 rate = (u8)(item_rates->abyRates[ii] & 0x7f);
435 if (RATEwGetRateIdx(rate) > RATE_11M) {
436 ofdm_rate = true;
437 break;
438 }
439 }
440 }
441
442 if (ofdm_rate == true) {
443 priv->uCwMin = C_CWMIN_A;
444 max_min = 4;
445 } else {
446 priv->uCwMin = C_CWMIN_B;
447 max_min = 5;
448 }
449 }
450
451 priv->uCwMax = C_CWMAX;
452 priv->uEIFS = C_EIFS;
453
454 data[0] = (u8)priv->uSIFS;
455 data[1] = (u8)priv->uDIFS;
456 data[2] = (u8)priv->uEIFS;
457 data[3] = (u8)priv->uSlot;
458
Malcolm Priestley1390b022014-05-26 13:59:01 +0100459 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS,
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100460 MESSAGE_REQUEST_MACREG, 4, &data[0]);
461
462 max_min |= 0xa0;
463
Malcolm Priestley1390b022014-05-26 13:59:01 +0100464 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0,
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100465 MESSAGE_REQUEST_MACREG, 1, &max_min);
Forest Bond92b96792009-06-13 07:38:31 -0400466}
467
Malcolm Priestley47203c42014-05-30 16:27:45 +0100468void vnt_update_top_rates(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400469{
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100470 u8 top_ofdm = RATE_24M, top_cck = RATE_1M;
471 u8 i;
Forest Bond92b96792009-06-13 07:38:31 -0400472
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100473 /*Determines the highest basic rate.*/
474 for (i = RATE_54M; i >= RATE_6M; i--) {
475 if (priv->wBasicRate & (u16)(1 << i)) {
476 top_ofdm = i;
477 break;
478 }
479 }
Forest Bond92b96792009-06-13 07:38:31 -0400480
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100481 priv->byTopOFDMBasicRate = top_ofdm;
482
483 for (i = RATE_11M;; i--) {
484 if (priv->wBasicRate & (u16)(1 << i)) {
485 top_cck = i;
486 break;
487 }
488 if (i == RATE_1M)
489 break;
490 }
491
492 priv->byTopCCKBasicRate = top_cck;
Forest Bond92b96792009-06-13 07:38:31 -0400493 }
494
495/*
496 * Description: Set NIC Tx Basic Rate
497 *
498 * Parameters:
499 * In:
500 * pDevice - The adapter to be set
501 * wBasicRate - Basic Rate to be set
502 * Out:
503 * none
504 *
Andres More4e9b5e22013-02-12 20:36:30 -0500505 * Return Value: true if succeeded; false if failed.
Forest Bond92b96792009-06-13 07:38:31 -0400506 *
507 */
Malcolm Priestley9a2cffd2014-05-30 16:27:47 +0100508void vnt_add_basic_rate(struct vnt_private *priv, u16 rate_idx)
Forest Bond92b96792009-06-13 07:38:31 -0400509{
Forest Bond92b96792009-06-13 07:38:31 -0400510
Malcolm Priestley6db0dea2014-05-23 18:00:19 +0100511 priv->wBasicRate |= (1 << rate_idx);
Forest Bond92b96792009-06-13 07:38:31 -0400512
Malcolm Priestley6db0dea2014-05-23 18:00:19 +0100513 /*Determines the highest basic rate.*/
Malcolm Priestley47203c42014-05-30 16:27:45 +0100514 vnt_update_top_rates(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400515}
516
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +0100517int vnt_ofdm_min_rate(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400518{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000519 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400520
Malcolm Priestleyde0eb9e2014-05-24 14:36:58 +0100521 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
522 if ((priv->wBasicRate) & ((u16)(1 << ii)))
523 return true;
524 }
525
526 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400527}
528
Malcolm Priestleye809c962014-05-30 16:27:49 +0100529u8 vnt_get_pkt_type(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400530{
Forest Bond92b96792009-06-13 07:38:31 -0400531
Malcolm Priestley1f442382014-05-24 14:36:59 +0100532 if (priv->byBBType == BB_TYPE_11A || priv->byBBType == BB_TYPE_11B)
533 return (u8)priv->byBBType;
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +0100534 else if (vnt_ofdm_min_rate(priv))
Malcolm Priestley1f442382014-05-24 14:36:59 +0100535 return PK_TYPE_11GA;
536 else
537 return PK_TYPE_11GB;
Forest Bond92b96792009-06-13 07:38:31 -0400538}
539
Forest Bond92b96792009-06-13 07:38:31 -0400540/*
Justin P. Mattocka0a1f612012-08-26 08:16:43 -0700541 * Description: Calculate TSF offset of two TSF input
Forest Bond92b96792009-06-13 07:38:31 -0400542 * Get TSF Offset from RxBCN's TSF and local TSF
543 *
544 * Parameters:
545 * In:
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100546 * rx_rate - rx rate.
547 * tsf1 - Rx BCN's TSF
548 * tsf2 - Local TSF
Forest Bond92b96792009-06-13 07:38:31 -0400549 * Out:
550 * none
551 *
552 * Return Value: TSF Offset value
553 *
554 */
Malcolm Priestleyecbc0a12014-05-30 16:27:50 +0100555u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2)
Forest Bond92b96792009-06-13 07:38:31 -0400556{
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100557 u64 tsf_offset = 0;
558 u16 rx_bcn_offset = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400559
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100560 rx_bcn_offset = cwRXBCNTSFOff[rx_rate % MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400561
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100562 tsf2 += (u64)rx_bcn_offset;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000563
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100564 tsf_offset = tsf1 - tsf2;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000565
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100566 return tsf_offset;
Forest Bond92b96792009-06-13 07:38:31 -0400567}
568
Forest Bond92b96792009-06-13 07:38:31 -0400569/*
570 * Description: Sync. TSF counter to BSS
571 * Get TSF offset and write to HW
572 *
573 * Parameters:
574 * In:
Malcolm Priestley302361d2014-05-24 14:37:01 +0100575 * priv - The adapter to be sync.
576 * time_stamp - Rx BCN's TSF
577 * local_tsf - Local TSF
Forest Bond92b96792009-06-13 07:38:31 -0400578 * Out:
579 * none
580 *
581 * Return Value: none
582 *
583 */
Malcolm Priestley14c68c52014-05-30 16:27:51 +0100584void vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate,
Malcolm Priestley302361d2014-05-24 14:37:01 +0100585 u64 time_stamp, u64 local_tsf)
Forest Bond92b96792009-06-13 07:38:31 -0400586{
Malcolm Priestley302361d2014-05-24 14:37:01 +0100587 u64 tsf_offset = 0;
588 u8 data[8];
Forest Bond92b96792009-06-13 07:38:31 -0400589
Malcolm Priestleyecbc0a12014-05-30 16:27:50 +0100590 tsf_offset = vnt_get_tsf_offset(rx_rate, time_stamp, local_tsf);
Forest Bond92b96792009-06-13 07:38:31 -0400591
Malcolm Priestley302361d2014-05-24 14:37:01 +0100592 data[0] = (u8)tsf_offset;
593 data[1] = (u8)(tsf_offset >> 8);
594 data[2] = (u8)(tsf_offset >> 16);
595 data[3] = (u8)(tsf_offset >> 24);
596 data[4] = (u8)(tsf_offset >> 32);
597 data[5] = (u8)(tsf_offset >> 40);
598 data[6] = (u8)(tsf_offset >> 48);
599 data[7] = (u8)(tsf_offset >> 56);
Forest Bond92b96792009-06-13 07:38:31 -0400600
Malcolm Priestley1390b022014-05-26 13:59:01 +0100601 vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
Malcolm Priestley302361d2014-05-24 14:37:01 +0100602 MESSAGE_REQUEST_TSF, 0, 8, data);
Forest Bond92b96792009-06-13 07:38:31 -0400603}
604/*
605 * Description: Read NIC TSF counter
606 * Get local TSF counter
607 *
608 * Parameters:
609 * In:
Malcolm Priestley2092dfa2014-05-24 14:37:02 +0100610 * priv - The adapter to be read
Forest Bond92b96792009-06-13 07:38:31 -0400611 * Out:
Malcolm Priestley2092dfa2014-05-24 14:37:02 +0100612 * current_tsf - Current TSF counter
Forest Bond92b96792009-06-13 07:38:31 -0400613 *
Andres More4e9b5e22013-02-12 20:36:30 -0500614 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400615 *
616 */
Malcolm Priestley4a9f4c62014-05-30 23:22:47 +0100617bool vnt_get_current_tsf(struct vnt_private *priv, u64 *current_tsf)
Forest Bond92b96792009-06-13 07:38:31 -0400618{
Forest Bond92b96792009-06-13 07:38:31 -0400619
Malcolm Priestley2092dfa2014-05-24 14:37:02 +0100620 *current_tsf = priv->qwCurrTSF;
Forest Bond92b96792009-06-13 07:38:31 -0400621
Andres More4e9b5e22013-02-12 20:36:30 -0500622 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400623}
624
Forest Bond92b96792009-06-13 07:38:31 -0400625/*
626 * Description: Clear NIC TSF counter
627 * Clear local TSF counter
628 *
629 * Parameters:
630 * In:
Malcolm Priestleye151e472014-05-24 14:37:03 +0100631 * priv - The adapter to be read
Forest Bond92b96792009-06-13 07:38:31 -0400632 *
Andres More4e9b5e22013-02-12 20:36:30 -0500633 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400634 *
635 */
Malcolm Priestleydba066e2014-05-30 23:22:48 +0100636bool vnt_clear_current_tsf(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400637{
Forest Bond92b96792009-06-13 07:38:31 -0400638
Malcolm Priestley36957532014-05-31 11:50:42 +0100639 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
Forest Bond92b96792009-06-13 07:38:31 -0400640
Malcolm Priestleye151e472014-05-24 14:37:03 +0100641 priv->qwCurrTSF = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400642
Andres More4e9b5e22013-02-12 20:36:30 -0500643 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400644}
645
646/*
647 * Description: Read NIC TSF counter
648 * Get NEXTTBTT from adjusted TSF and Beacon Interval
649 *
650 * Parameters:
651 * In:
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100652 * tsf - Current TSF counter
653 * beacon_interval - Beacon Interval
Forest Bond92b96792009-06-13 07:38:31 -0400654 * Out:
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100655 * tsf - Current TSF counter
Forest Bond92b96792009-06-13 07:38:31 -0400656 *
657 * Return Value: TSF value of next Beacon
658 *
659 */
Malcolm Priestley75ef1b512014-05-30 23:22:49 +0100660u64 vnt_get_next_tbtt(u64 tsf, u16 beacon_interval)
Forest Bond92b96792009-06-13 07:38:31 -0400661{
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100662 u32 beacon_int;
Forest Bond92b96792009-06-13 07:38:31 -0400663
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100664 beacon_int = beacon_interval * 1024;
Forest Bond92b96792009-06-13 07:38:31 -0400665
Malcolm Priestley6e280242014-01-01 19:20:40 +0000666 /* Next TBTT =
667 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
668 */
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100669 if (beacon_int) {
670 do_div(tsf, beacon_int);
671 tsf += 1;
672 tsf *= beacon_int;
Malcolm Priestley6e280242014-01-01 19:20:40 +0000673 }
Forest Bond92b96792009-06-13 07:38:31 -0400674
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100675 return tsf;
Forest Bond92b96792009-06-13 07:38:31 -0400676}
677
Forest Bond92b96792009-06-13 07:38:31 -0400678/*
679 * Description: Set NIC TSF counter for first Beacon time
680 * Get NEXTTBTT from adjusted TSF and Beacon Interval
681 *
682 * Parameters:
683 * In:
684 * dwIoBase - IO Base
Malcolm Priestley414475f2014-05-24 14:37:05 +0100685 * beacon_interval - Beacon Interval
Forest Bond92b96792009-06-13 07:38:31 -0400686 * Out:
687 * none
688 *
689 * Return Value: none
690 *
691 */
Malcolm Priestley6964cd12014-05-30 23:22:50 +0100692void vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval)
Forest Bond92b96792009-06-13 07:38:31 -0400693{
Malcolm Priestley414475f2014-05-24 14:37:05 +0100694 u64 next_tbtt = 0;
695 u8 data[8];
Forest Bond92b96792009-06-13 07:38:31 -0400696
Malcolm Priestleydba066e2014-05-30 23:22:48 +0100697 vnt_clear_current_tsf(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400698
Malcolm Priestley75ef1b512014-05-30 23:22:49 +0100699 next_tbtt = vnt_get_next_tbtt(next_tbtt, beacon_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400700
Malcolm Priestley414475f2014-05-24 14:37:05 +0100701 data[0] = (u8)next_tbtt;
702 data[1] = (u8)(next_tbtt >> 8);
703 data[2] = (u8)(next_tbtt >> 16);
704 data[3] = (u8)(next_tbtt >> 24);
705 data[4] = (u8)(next_tbtt >> 32);
706 data[5] = (u8)(next_tbtt >> 40);
707 data[6] = (u8)(next_tbtt >> 48);
708 data[7] = (u8)(next_tbtt >> 56);
Forest Bond92b96792009-06-13 07:38:31 -0400709
Malcolm Priestley1390b022014-05-26 13:59:01 +0100710 vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
Malcolm Priestley414475f2014-05-24 14:37:05 +0100711 MESSAGE_REQUEST_TBTT, 0, 8, data);
712
713 return;
Forest Bond92b96792009-06-13 07:38:31 -0400714}
715
Forest Bond92b96792009-06-13 07:38:31 -0400716/*
717 * Description: Sync NIC TSF counter for Beacon time
718 * Get NEXTTBTT and write to HW
719 *
720 * Parameters:
721 * In:
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100722 * priv - The adapter to be set
723 * tsf - Current TSF counter
724 * beacon_interval - Beacon Interval
Forest Bond92b96792009-06-13 07:38:31 -0400725 * Out:
726 * none
727 *
728 * Return Value: none
729 *
730 */
Malcolm Priestley88ec2f72014-05-30 23:22:51 +0100731void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100732 u16 beacon_interval)
Forest Bond92b96792009-06-13 07:38:31 -0400733{
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100734 u8 data[8];
Forest Bond92b96792009-06-13 07:38:31 -0400735
Malcolm Priestley75ef1b512014-05-30 23:22:49 +0100736 tsf = vnt_get_next_tbtt(tsf, beacon_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400737
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100738 data[0] = (u8)tsf;
739 data[1] = (u8)(tsf >> 8);
740 data[2] = (u8)(tsf >> 16);
741 data[3] = (u8)(tsf >> 24);
742 data[4] = (u8)(tsf >> 32);
743 data[5] = (u8)(tsf >> 40);
744 data[6] = (u8)(tsf >> 48);
745 data[7] = (u8)(tsf >> 56);
Forest Bond92b96792009-06-13 07:38:31 -0400746
Malcolm Priestley1390b022014-05-26 13:59:01 +0100747 vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100748 MESSAGE_REQUEST_TBTT, 0, 8, data);
Forest Bond92b96792009-06-13 07:38:31 -0400749
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100750 dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf);
Forest Bond92b96792009-06-13 07:38:31 -0400751
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100752 return;
Forest Bond92b96792009-06-13 07:38:31 -0400753}
754
755/*
756 * Description: Turn off Radio power
757 *
758 * Parameters:
759 * In:
Malcolm Priestley07deb712014-05-24 14:37:07 +0100760 * priv - The adapter to be turned off
Forest Bond92b96792009-06-13 07:38:31 -0400761 * Out:
762 * none
763 *
Andres More4e9b5e22013-02-12 20:36:30 -0500764 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400765 *
766 */
Malcolm Priestleyfa26e0b2014-05-30 23:22:52 +0100767int vnt_radio_power_off(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400768{
Malcolm Priestley07deb712014-05-24 14:37:07 +0100769 int ret = true;
Forest Bond92b96792009-06-13 07:38:31 -0400770
Malcolm Priestley07deb712014-05-24 14:37:07 +0100771 priv->bRadioOff = true;
Forest Bond92b96792009-06-13 07:38:31 -0400772
Malcolm Priestley07deb712014-05-24 14:37:07 +0100773 switch (priv->byRFType) {
774 case RF_AL2230:
775 case RF_AL2230S:
776 case RF_AIROHA7230:
777 case RF_VT3226:
778 case RF_VT3226D0:
779 case RF_VT3342A0:
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +0100780 vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL,
Malcolm Priestley07deb712014-05-24 14:37:07 +0100781 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
782 break;
783 }
Forest Bond92b96792009-06-13 07:38:31 -0400784
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +0100785 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond92b96792009-06-13 07:38:31 -0400786
Malcolm Priestley07deb712014-05-24 14:37:07 +0100787 BBvSetDeepSleep(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400788
Malcolm Priestley07deb712014-05-24 14:37:07 +0100789 return ret;
Forest Bond92b96792009-06-13 07:38:31 -0400790}
791
Forest Bond92b96792009-06-13 07:38:31 -0400792/*
793 * Description: Turn on Radio power
794 *
795 * Parameters:
796 * In:
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100797 * priv - The adapter to be turned on
Forest Bond92b96792009-06-13 07:38:31 -0400798 * Out:
799 * none
800 *
Andres More4e9b5e22013-02-12 20:36:30 -0500801 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400802 *
803 */
Malcolm Priestley8a5e6c82014-05-30 23:22:53 +0100804int vnt_radio_power_on(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400805{
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100806 int ret = true;
Forest Bond92b96792009-06-13 07:38:31 -0400807
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100808 if (priv->bHWRadioOff == true || priv->bRadioControlOff == true)
809 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400810
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100811 priv->bRadioOff = false;
Forest Bond92b96792009-06-13 07:38:31 -0400812
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100813 BBvExitDeepSleep(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400814
Malcolm Priestley36957532014-05-31 11:50:42 +0100815 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond92b96792009-06-13 07:38:31 -0400816
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100817 switch (priv->byRFType) {
818 case RF_AL2230:
819 case RF_AL2230S:
820 case RF_AIROHA7230:
821 case RF_VT3226:
822 case RF_VT3226D0:
823 case RF_VT3342A0:
Malcolm Priestley36957532014-05-31 11:50:42 +0100824 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100825 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
826 break;
827 }
Forest Bond92b96792009-06-13 07:38:31 -0400828
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100829 return ret;
Forest Bond92b96792009-06-13 07:38:31 -0400830}
831
Malcolm Priestleybc240f52014-05-30 23:22:54 +0100832void vnt_set_bss_mode(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400833{
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100834 if (priv->byRFType == RF_AIROHA7230 && priv->byBBType == BB_TYPE_11A)
Malcolm Priestley05089fb2014-05-31 11:50:38 +0100835 vnt_mac_set_bb_type(priv, BB_TYPE_11G);
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100836 else
Malcolm Priestley05089fb2014-05-31 11:50:38 +0100837 vnt_mac_set_bb_type(priv, priv->byBBType);
Forest Bond92b96792009-06-13 07:38:31 -0400838
Malcolm Priestleye809c962014-05-30 16:27:49 +0100839 priv->byPacketType = vnt_get_pkt_type(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400840
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100841 if (priv->byBBType == BB_TYPE_11A)
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100842 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100843 else if (priv->byBBType == BB_TYPE_11B)
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100844 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100845 else if (priv->byBBType == BB_TYPE_11G)
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100846 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
Forest Bond92b96792009-06-13 07:38:31 -0400847
Malcolm Priestleyc7ee9ee2014-05-30 16:27:44 +0100848 vnt_update_ifs(priv);
Malcolm Priestley1a792942014-05-30 16:27:46 +0100849 vnt_set_rspinf(priv, (u8)priv->byBBType);
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100850
851 if (priv->byBBType == BB_TYPE_11A) {
852 if (priv->byRFType == RF_AIROHA7230) {
853 priv->abyBBVGA[0] = 0x20;
854
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100855 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100856 0xe7, priv->abyBBVGA[0]);
857 }
858
859 priv->abyBBVGA[2] = 0x10;
860 priv->abyBBVGA[3] = 0x10;
861 } else {
862 if (priv->byRFType == RF_AIROHA7230) {
863 priv->abyBBVGA[0] = 0x1c;
864
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100865 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100866 0xe7, priv->abyBBVGA[0]);
867 }
868
869 priv->abyBBVGA[2] = 0x0;
870 priv->abyBBVGA[3] = 0x0;
871 }
Forest Bond92b96792009-06-13 07:38:31 -0400872}