blob: 8e00377c26ec848dbb01eba9bc4d4388d6c31d33 [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 "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "desc.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "power.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "key.h"
Malcolm Priestley62c85262014-05-26 13:59:07 +010056#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040057
Peter Senna Tschudin618d7d02014-07-15 23:23:25 +020058/* const u16 cwRXBCNTSFOff[MAX_RATE] =
59 {17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3}; */
Forest Bond92b96792009-06-13 07:38:31 -040060
Peter Senna Tschudin42b138d2014-07-15 23:23:26 +020061static const u16 cwRXBCNTSFOff[MAX_RATE] = {
62 192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3
63};
Forest Bond92b96792009-06-13 07:38:31 -040064
Forest Bond92b96792009-06-13 07:38:31 -040065/*
66 * Description: Set NIC media channel
67 *
68 * Parameters:
69 * In:
70 * pDevice - The adapter to be set
Malcolm Priestley7387f432013-12-12 23:33:08 +000071 * connection_channel - Channel to be set
Forest Bond92b96792009-06-13 07:38:31 -040072 * Out:
73 * none
Forest Bond92b96792009-06-13 07:38:31 -040074 */
Malcolm Priestley084fc8f2014-05-30 16:27:40 +010075void vnt_set_channel(struct vnt_private *priv, u32 connection_channel)
Forest Bond92b96792009-06-13 07:38:31 -040076{
Forest Bond92b96792009-06-13 07:38:31 -040077
Malcolm Priestley04f2ff12014-07-05 19:24:25 +010078 if (connection_channel > CB_MAX_CHANNEL || !connection_channel)
79 return;
Forest Bond92b96792009-06-13 07:38:31 -040080
Malcolm Priestley7387f432013-12-12 23:33:08 +000081 /* clear NAV */
Malcolm Priestley36957532014-05-31 11:50:42 +010082 vnt_mac_reg_bits_on(priv, MAC_REG_MACCR, MACCR_CLRNAV);
Forest Bond92b96792009-06-13 07:38:31 -040083
Malcolm Priestley7387f432013-12-12 23:33:08 +000084 /* Set Channel[7] = 0 to tell H/W channel is changing now. */
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +010085 vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, 0xb0);
Forest Bond92b96792009-06-13 07:38:31 -040086
Malcolm Priestley1390b022014-05-26 13:59:01 +010087 vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNLE,
Malcolm Priestley7387f432013-12-12 23:33:08 +000088 connection_channel, 0, 0, NULL);
Forest Bond92b96792009-06-13 07:38:31 -040089
Malcolm Priestley285d58c2014-05-26 13:59:03 +010090 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL,
Malcolm Priestley7387f432013-12-12 23:33:08 +000091 (u8)(connection_channel|0x80));
Forest Bond92b96792009-06-13 07:38:31 -040092}
93
94/*
95 * Description: Get CCK mode basic rate
96 *
97 * Parameters:
98 * In:
Malcolm Priestley3d2988c2014-05-25 21:36:23 +010099 * priv - The adapter to be set
100 * rate_idx - Receiving data rate
Forest Bond92b96792009-06-13 07:38:31 -0400101 * Out:
102 * none
103 *
104 * Return Value: response Control frame rate
105 *
106 */
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100107static u16 vnt_get_cck_rate(struct vnt_private *priv, u16 rate_idx)
Forest Bond92b96792009-06-13 07:38:31 -0400108{
Malcolm Priestley3d2988c2014-05-25 21:36:23 +0100109 u16 ui = rate_idx;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000110
111 while (ui > RATE_1M) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100112 if (priv->basic_rates & (1 << ui))
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000113 return ui;
114 ui--;
115 }
116
117 return RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -0400118}
119
120/*
121 * Description: Get OFDM mode basic rate
122 *
123 * Parameters:
124 * In:
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100125 * priv - The adapter to be set
126 * rate_idx - Receiving data rate
Forest Bond92b96792009-06-13 07:38:31 -0400127 * Out:
128 * none
129 *
130 * Return Value: response Control frame rate
131 *
132 */
Malcolm Priestley15fa7ce2014-05-30 16:27:42 +0100133static u16 vnt_get_ofdm_rate(struct vnt_private *priv, u16 rate_idx)
Forest Bond92b96792009-06-13 07:38:31 -0400134{
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100135 u16 ui = rate_idx;
Forest Bond92b96792009-06-13 07:38:31 -0400136
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100137 dev_dbg(&priv->usb->dev, "%s basic rate: %d\n",
Malcolm Priestley93a73552014-07-20 15:33:13 +0100138 __func__, priv->basic_rates);
Forest Bond92b96792009-06-13 07:38:31 -0400139
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +0100140 if (!vnt_ofdm_min_rate(priv)) {
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100141 dev_dbg(&priv->usb->dev, "%s (NO OFDM) %d\n",
142 __func__, rate_idx);
Malcolm Priestleya5a7c432014-05-25 21:36:22 +0100143 if (rate_idx > RATE_24M)
144 rate_idx = RATE_24M;
145 return rate_idx;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000146 }
147
148 while (ui > RATE_11M) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100149 if (priv->basic_rates & (1 << ui)) {
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100150 dev_dbg(&priv->usb->dev, "%s rate: %d\n",
151 __func__, ui);
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000152 return ui;
153 }
154 ui--;
155 }
156
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100157 dev_dbg(&priv->usb->dev, "%s basic rate: 24M\n", __func__);
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000158
159 return RATE_24M;
Forest Bond92b96792009-06-13 07:38:31 -0400160}
161
162/*
Justin P. Mattocka0a1f612012-08-26 08:16:43 -0700163 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond92b96792009-06-13 07:38:31 -0400164 *
165 * Parameters:
Malcolm Priestley3605f842014-05-23 18:00:15 +0100166 * In:
167 * rate - Tx Rate
168 * bb_type - Tx Packet type
169 * Out:
170 * tx_rate - pointer to RSPINF TxRate field
171 * rsv_time- pointer to RSPINF RsvTime field
Forest Bond92b96792009-06-13 07:38:31 -0400172 *
173 * Return Value: none
174 *
175 */
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100176static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type,
Malcolm Priestley3605f842014-05-23 18:00:15 +0100177 u8 *tx_rate, u8 *rsv_time)
Forest Bond92b96792009-06-13 07:38:31 -0400178{
Forest Bond92b96792009-06-13 07:38:31 -0400179
Malcolm Priestley3605f842014-05-23 18:00:15 +0100180 switch (rate) {
181 case RATE_6M:
182 if (bb_type == BB_TYPE_11A) {
183 *tx_rate = 0x9b;
184 *rsv_time = 24;
185 } else {
186 *tx_rate = 0x8b;
187 *rsv_time = 30;
188 }
189 break;
190 case RATE_9M:
191 if (bb_type == BB_TYPE_11A) {
192 *tx_rate = 0x9f;
193 *rsv_time = 16;
194 } else {
195 *tx_rate = 0x8f;
196 *rsv_time = 22;
197 }
198 break;
199 case RATE_12M:
200 if (bb_type == BB_TYPE_11A) {
201 *tx_rate = 0x9a;
202 *rsv_time = 12;
203 } else {
204 *tx_rate = 0x8a;
205 *rsv_time = 18;
206 }
207 break;
208 case RATE_18M:
209 if (bb_type == BB_TYPE_11A) {
210 *tx_rate = 0x9e;
211 *rsv_time = 8;
212 } else {
213 *tx_rate = 0x8e;
214 *rsv_time = 14;
215 }
216 break;
217 case RATE_36M:
218 if (bb_type == BB_TYPE_11A) {
219 *tx_rate = 0x9d;
220 *rsv_time = 4;
221 } else {
222 *tx_rate = 0x8d;
223 *rsv_time = 10;
224 }
225 break;
226 case RATE_48M:
227 if (bb_type == BB_TYPE_11A) {
228 *tx_rate = 0x98;
229 *rsv_time = 4;
230 } else {
231 *tx_rate = 0x88;
Malcolm Priestleyfd4859f2014-05-24 14:37:10 +0100232 *rsv_time = 10;
Malcolm Priestley3605f842014-05-23 18:00:15 +0100233 }
234 break;
235 case RATE_54M:
236 if (bb_type == BB_TYPE_11A) {
237 *tx_rate = 0x9c;
238 *rsv_time = 4;
239 } else {
240 *tx_rate = 0x8c;
241 *rsv_time = 10;
242 }
243 break;
244 case RATE_24M:
245 default:
246 if (bb_type == BB_TYPE_11A) {
247 *tx_rate = 0x99;
248 *rsv_time = 8;
249 } else {
250 *tx_rate = 0x89;
251 *rsv_time = 14;
252 }
253 break;
254 }
Forest Bond92b96792009-06-13 07:38:31 -0400255}
256
257/*
258 * Description: Set RSPINF
259 *
260 * Parameters:
261 * In:
262 * pDevice - The adapter to be set
263 * Out:
264 * none
265 *
266 * Return Value: None.
267 *
268 */
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100269
Malcolm Priestley1a792942014-05-30 16:27:46 +0100270void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type)
Forest Bond92b96792009-06-13 07:38:31 -0400271{
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100272 struct vnt_phy_field phy[4];
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100273 u8 tx_rate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
274 u8 rsv_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
275 u8 data[34];
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000276 int i;
Forest Bond92b96792009-06-13 07:38:31 -0400277
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100278 /*RSPINF_b_1*/
Malcolm Priestley205056f2014-06-04 18:25:34 +0100279 vnt_get_phy_field(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100280 vnt_get_cck_rate(priv, RATE_1M), PK_TYPE_11B, &phy[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400281
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100282 /*RSPINF_b_2*/
Malcolm Priestley205056f2014-06-04 18:25:34 +0100283 vnt_get_phy_field(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100284 vnt_get_cck_rate(priv, RATE_2M), PK_TYPE_11B, &phy[1]);
Forest Bond92b96792009-06-13 07:38:31 -0400285
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100286 /*RSPINF_b_5*/
Malcolm Priestley205056f2014-06-04 18:25:34 +0100287 vnt_get_phy_field(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100288 vnt_get_cck_rate(priv, RATE_5M), PK_TYPE_11B, &phy[2]);
Forest Bond92b96792009-06-13 07:38:31 -0400289
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100290 /*RSPINF_b_11*/
Malcolm Priestley205056f2014-06-04 18:25:34 +0100291 vnt_get_phy_field(priv, 14,
Malcolm Priestley073d02e2014-05-30 16:27:41 +0100292 vnt_get_cck_rate(priv, RATE_11M), PK_TYPE_11B, &phy[3]);
Forest Bond92b96792009-06-13 07:38:31 -0400293
Forest Bond92b96792009-06-13 07:38:31 -0400294
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100295 /*RSPINF_a_6*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100296 vnt_calculate_ofdm_rate(RATE_6M, bb_type, &tx_rate[0], &rsv_time[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400297
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100298 /*RSPINF_a_9*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100299 vnt_calculate_ofdm_rate(RATE_9M, bb_type, &tx_rate[1], &rsv_time[1]);
Forest Bond92b96792009-06-13 07:38:31 -0400300
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100301 /*RSPINF_a_12*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100302 vnt_calculate_ofdm_rate(RATE_12M, bb_type, &tx_rate[2], &rsv_time[2]);
Forest Bond92b96792009-06-13 07:38:31 -0400303
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100304 /*RSPINF_a_18*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100305 vnt_calculate_ofdm_rate(RATE_18M, bb_type, &tx_rate[3], &rsv_time[3]);
Forest Bond92b96792009-06-13 07:38:31 -0400306
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100307 /*RSPINF_a_24*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100308 vnt_calculate_ofdm_rate(RATE_24M, bb_type, &tx_rate[4], &rsv_time[4]);
Forest Bond92b96792009-06-13 07:38:31 -0400309
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100310 /*RSPINF_a_36*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100311 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_36M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100312 bb_type, &tx_rate[5], &rsv_time[5]);
Forest Bond92b96792009-06-13 07:38:31 -0400313
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100314 /*RSPINF_a_48*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100315 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_48M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100316 bb_type, &tx_rate[6], &rsv_time[6]);
Forest Bond92b96792009-06-13 07:38:31 -0400317
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100318 /*RSPINF_a_54*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100319 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100320 bb_type, &tx_rate[7], &rsv_time[7]);
Forest Bond92b96792009-06-13 07:38:31 -0400321
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100322 /*RSPINF_a_72*/
Malcolm Priestleyc9a04872014-05-30 16:27:43 +0100323 vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M),
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100324 bb_type, &tx_rate[8], &rsv_time[8]);
Forest Bond92b96792009-06-13 07:38:31 -0400325
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100326 put_unaligned(phy[0].len, (u16 *)&data[0]);
327 data[2] = phy[0].signal;
328 data[3] = phy[0].service;
Forest Bond92b96792009-06-13 07:38:31 -0400329
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100330 put_unaligned(phy[1].len, (u16 *)&data[4]);
331 data[6] = phy[1].signal;
332 data[7] = phy[1].service;
Forest Bond92b96792009-06-13 07:38:31 -0400333
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100334 put_unaligned(phy[2].len, (u16 *)&data[8]);
335 data[10] = phy[2].signal;
336 data[11] = phy[2].service;
Forest Bond92b96792009-06-13 07:38:31 -0400337
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100338 put_unaligned(phy[3].len, (u16 *)&data[12]);
339 data[14] = phy[3].signal;
340 data[15] = phy[3].service;
Forest Bond92b96792009-06-13 07:38:31 -0400341
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100342 for (i = 0; i < 9; i++) {
343 data[16 + i * 2] = tx_rate[i];
344 data[16 + i * 2 + 1] = rsv_time[i];
345 }
Forest Bond92b96792009-06-13 07:38:31 -0400346
Malcolm Priestley1390b022014-05-26 13:59:01 +0100347 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
Malcolm Priestley652d0f02014-05-23 18:00:16 +0100348 MAC_REG_RSPINF_B_1, MESSAGE_REQUEST_MACREG, 34, &data[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400349}
350
351/*
352 * Description: Update IFS
353 *
354 * Parameters:
355 * In:
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100356 * priv - The adapter to be set
357 * Out:
358 * none
Forest Bond92b96792009-06-13 07:38:31 -0400359 *
360 * Return Value: None.
361 *
362 */
Malcolm Priestleyc7ee9ee2014-05-30 16:27:44 +0100363void vnt_update_ifs(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400364{
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100365 u8 max_min = 0;
366 u8 data[4];
Forest Bond92b96792009-06-13 07:38:31 -0400367
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100368 if (priv->packet_type == PK_TYPE_11A) {
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100369 priv->slot = C_SLOT_SHORT;
370 priv->sifs = C_SIFS_A;
371 priv->difs = C_SIFS_A + 2 * C_SLOT_SHORT;
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100372 max_min = 4;
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100373 } else if (priv->packet_type == PK_TYPE_11B) {
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100374 priv->slot = C_SLOT_LONG;
375 priv->sifs = C_SIFS_BG;
376 priv->difs = C_SIFS_BG + 2 * C_SLOT_LONG;
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100377 max_min = 5;
378 } else {/* PK_TYPE_11GA & PK_TYPE_11GB */
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100379 bool ofdm_rate = false;
380 unsigned int ii = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400381
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100382 priv->sifs = C_SIFS_BG;
Forest Bond92b96792009-06-13 07:38:31 -0400383
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100384 if (priv->bShortSlotTime)
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100385 priv->slot = C_SLOT_SHORT;
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100386 else
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100387 priv->slot = C_SLOT_LONG;
Forest Bond92b96792009-06-13 07:38:31 -0400388
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100389 priv->difs = C_SIFS_BG + 2 * priv->slot;
Forest Bond92b96792009-06-13 07:38:31 -0400390
Malcolm Priestleyee61fde2014-06-25 21:14:28 +0100391 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100392 if (priv->basic_rates & ((u32)(0x1 << ii))) {
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100393 ofdm_rate = true;
394 break;
395 }
396 }
397
Malcolm Priestley995c91e2014-07-19 12:30:17 +0100398 if (ofdm_rate == true)
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100399 max_min = 4;
Malcolm Priestley995c91e2014-07-19 12:30:17 +0100400 else
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100401 max_min = 5;
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100402 }
403
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100404 priv->eifs = C_EIFS;
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100405
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100406 switch (priv->rf_type) {
Malcolm Priestley9fe109c2014-07-06 23:19:48 +0100407 case RF_VT3226D0:
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100408 if (priv->bb_type != BB_TYPE_11B) {
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100409 priv->sifs -= 1;
410 priv->difs -= 1;
Malcolm Priestley9fe109c2014-07-06 23:19:48 +0100411 break;
412 }
413 case RF_AIROHA7230:
414 case RF_AL2230:
415 case RF_AL2230S:
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100416 if (priv->bb_type != BB_TYPE_11B)
Malcolm Priestley9fe109c2014-07-06 23:19:48 +0100417 break;
418 case RF_RFMD2959:
419 case RF_VT3226:
420 case RF_VT3342A0:
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100421 priv->sifs -= 3;
422 priv->difs -= 3;
Malcolm Priestley9fe109c2014-07-06 23:19:48 +0100423 break;
424 case RF_MAXIM2829:
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100425 if (priv->bb_type == BB_TYPE_11A) {
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100426 priv->sifs -= 5;
427 priv->difs -= 5;
Malcolm Priestley9fe109c2014-07-06 23:19:48 +0100428 } else {
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100429 priv->sifs -= 2;
430 priv->difs -= 2;
Malcolm Priestley9fe109c2014-07-06 23:19:48 +0100431 }
432
433 break;
434 }
435
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100436 data[0] = (u8)priv->sifs;
437 data[1] = (u8)priv->difs;
438 data[2] = (u8)priv->eifs;
439 data[3] = (u8)priv->slot;
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100440
Malcolm Priestley1390b022014-05-26 13:59:01 +0100441 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS,
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100442 MESSAGE_REQUEST_MACREG, 4, &data[0]);
443
444 max_min |= 0xa0;
445
Malcolm Priestley1390b022014-05-26 13:59:01 +0100446 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0,
Malcolm Priestley5ebc46d2014-05-23 18:00:17 +0100447 MESSAGE_REQUEST_MACREG, 1, &max_min);
Forest Bond92b96792009-06-13 07:38:31 -0400448}
449
Malcolm Priestley47203c42014-05-30 16:27:45 +0100450void vnt_update_top_rates(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400451{
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100452 u8 top_ofdm = RATE_24M, top_cck = RATE_1M;
453 u8 i;
Forest Bond92b96792009-06-13 07:38:31 -0400454
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100455 /*Determines the highest basic rate.*/
456 for (i = RATE_54M; i >= RATE_6M; i--) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100457 if (priv->basic_rates & (u16)(1 << i)) {
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100458 top_ofdm = i;
459 break;
460 }
461 }
Forest Bond92b96792009-06-13 07:38:31 -0400462
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100463 priv->top_ofdm_basic_rate = top_ofdm;
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100464
465 for (i = RATE_11M;; i--) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100466 if (priv->basic_rates & (u16)(1 << i)) {
Malcolm Priestleydcce9e02014-05-23 18:00:18 +0100467 top_cck = i;
468 break;
469 }
470 if (i == RATE_1M)
471 break;
472 }
473
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100474 priv->top_cck_basic_rate = top_cck;
Peter Senna Tschudin42b138d2014-07-15 23:23:26 +0200475}
Forest Bond92b96792009-06-13 07:38:31 -0400476
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +0100477int vnt_ofdm_min_rate(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400478{
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000479 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400480
Malcolm Priestleyde0eb9e2014-05-24 14:36:58 +0100481 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100482 if ((priv->basic_rates) & ((u16)(1 << ii)))
Malcolm Priestleyde0eb9e2014-05-24 14:36:58 +0100483 return true;
484 }
485
486 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400487}
488
Malcolm Priestleye809c962014-05-30 16:27:49 +0100489u8 vnt_get_pkt_type(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400490{
Forest Bond92b96792009-06-13 07:38:31 -0400491
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100492 if (priv->bb_type == BB_TYPE_11A || priv->bb_type == BB_TYPE_11B)
493 return (u8)priv->bb_type;
Malcolm Priestleycfa4d8d2014-05-30 16:27:48 +0100494 else if (vnt_ofdm_min_rate(priv))
Malcolm Priestley1f442382014-05-24 14:36:59 +0100495 return PK_TYPE_11GA;
496 else
497 return PK_TYPE_11GB;
Forest Bond92b96792009-06-13 07:38:31 -0400498}
499
Forest Bond92b96792009-06-13 07:38:31 -0400500/*
Justin P. Mattocka0a1f612012-08-26 08:16:43 -0700501 * Description: Calculate TSF offset of two TSF input
Forest Bond92b96792009-06-13 07:38:31 -0400502 * Get TSF Offset from RxBCN's TSF and local TSF
503 *
504 * Parameters:
505 * In:
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100506 * rx_rate - rx rate.
507 * tsf1 - Rx BCN's TSF
508 * tsf2 - Local TSF
Forest Bond92b96792009-06-13 07:38:31 -0400509 * Out:
510 * none
511 *
512 * Return Value: TSF Offset value
513 *
514 */
Malcolm Priestleyecbc0a12014-05-30 16:27:50 +0100515u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2)
Forest Bond92b96792009-06-13 07:38:31 -0400516{
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100517 u64 tsf_offset = 0;
518 u16 rx_bcn_offset = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400519
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100520 rx_bcn_offset = cwRXBCNTSFOff[rx_rate % MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400521
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100522 tsf2 += (u64)rx_bcn_offset;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000523
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100524 tsf_offset = tsf1 - tsf2;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +0000525
Malcolm Priestley3fd2a692014-05-24 14:37:00 +0100526 return tsf_offset;
Forest Bond92b96792009-06-13 07:38:31 -0400527}
528
Forest Bond92b96792009-06-13 07:38:31 -0400529/*
530 * Description: Sync. TSF counter to BSS
531 * Get TSF offset and write to HW
532 *
533 * Parameters:
534 * In:
Malcolm Priestley302361d2014-05-24 14:37:01 +0100535 * priv - The adapter to be sync.
536 * time_stamp - Rx BCN's TSF
537 * local_tsf - Local TSF
Forest Bond92b96792009-06-13 07:38:31 -0400538 * Out:
539 * none
540 *
541 * Return Value: none
542 *
543 */
Malcolm Priestley14c68c52014-05-30 16:27:51 +0100544void vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate,
Malcolm Priestley302361d2014-05-24 14:37:01 +0100545 u64 time_stamp, u64 local_tsf)
Forest Bond92b96792009-06-13 07:38:31 -0400546{
Malcolm Priestley302361d2014-05-24 14:37:01 +0100547 u64 tsf_offset = 0;
548 u8 data[8];
Forest Bond92b96792009-06-13 07:38:31 -0400549
Malcolm Priestleyecbc0a12014-05-30 16:27:50 +0100550 tsf_offset = vnt_get_tsf_offset(rx_rate, time_stamp, local_tsf);
Forest Bond92b96792009-06-13 07:38:31 -0400551
Malcolm Priestley302361d2014-05-24 14:37:01 +0100552 data[0] = (u8)tsf_offset;
553 data[1] = (u8)(tsf_offset >> 8);
554 data[2] = (u8)(tsf_offset >> 16);
555 data[3] = (u8)(tsf_offset >> 24);
556 data[4] = (u8)(tsf_offset >> 32);
557 data[5] = (u8)(tsf_offset >> 40);
558 data[6] = (u8)(tsf_offset >> 48);
559 data[7] = (u8)(tsf_offset >> 56);
Forest Bond92b96792009-06-13 07:38:31 -0400560
Malcolm Priestley1390b022014-05-26 13:59:01 +0100561 vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
Malcolm Priestley302361d2014-05-24 14:37:01 +0100562 MESSAGE_REQUEST_TSF, 0, 8, data);
Forest Bond92b96792009-06-13 07:38:31 -0400563}
564/*
565 * Description: Read NIC TSF counter
566 * Get local TSF counter
567 *
568 * Parameters:
569 * In:
Malcolm Priestley2092dfa2014-05-24 14:37:02 +0100570 * priv - The adapter to be read
Forest Bond92b96792009-06-13 07:38:31 -0400571 * Out:
Malcolm Priestley2092dfa2014-05-24 14:37:02 +0100572 * current_tsf - Current TSF counter
Forest Bond92b96792009-06-13 07:38:31 -0400573 *
Andres More4e9b5e22013-02-12 20:36:30 -0500574 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400575 *
576 */
Malcolm Priestley4a9f4c62014-05-30 23:22:47 +0100577bool vnt_get_current_tsf(struct vnt_private *priv, u64 *current_tsf)
Forest Bond92b96792009-06-13 07:38:31 -0400578{
Forest Bond92b96792009-06-13 07:38:31 -0400579
Malcolm Priestley113f0b92014-07-19 12:30:13 +0100580 *current_tsf = priv->current_tsf;
Forest Bond92b96792009-06-13 07:38:31 -0400581
Andres More4e9b5e22013-02-12 20:36:30 -0500582 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400583}
584
Forest Bond92b96792009-06-13 07:38:31 -0400585/*
586 * Description: Clear NIC TSF counter
587 * Clear local TSF counter
588 *
589 * Parameters:
590 * In:
Malcolm Priestleye151e472014-05-24 14:37:03 +0100591 * priv - The adapter to be read
Forest Bond92b96792009-06-13 07:38:31 -0400592 *
Andres More4e9b5e22013-02-12 20:36:30 -0500593 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400594 *
595 */
Malcolm Priestleydba066e2014-05-30 23:22:48 +0100596bool vnt_clear_current_tsf(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400597{
Forest Bond92b96792009-06-13 07:38:31 -0400598
Malcolm Priestley36957532014-05-31 11:50:42 +0100599 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
Forest Bond92b96792009-06-13 07:38:31 -0400600
Malcolm Priestley113f0b92014-07-19 12:30:13 +0100601 priv->current_tsf = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400602
Andres More4e9b5e22013-02-12 20:36:30 -0500603 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400604}
605
606/*
607 * Description: Read NIC TSF counter
608 * Get NEXTTBTT from adjusted TSF and Beacon Interval
609 *
610 * Parameters:
611 * In:
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100612 * tsf - Current TSF counter
613 * beacon_interval - Beacon Interval
Forest Bond92b96792009-06-13 07:38:31 -0400614 * Out:
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100615 * tsf - Current TSF counter
Forest Bond92b96792009-06-13 07:38:31 -0400616 *
617 * Return Value: TSF value of next Beacon
618 *
619 */
Malcolm Priestley75ef1b512014-05-30 23:22:49 +0100620u64 vnt_get_next_tbtt(u64 tsf, u16 beacon_interval)
Forest Bond92b96792009-06-13 07:38:31 -0400621{
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100622 u32 beacon_int;
Forest Bond92b96792009-06-13 07:38:31 -0400623
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100624 beacon_int = beacon_interval * 1024;
Forest Bond92b96792009-06-13 07:38:31 -0400625
Malcolm Priestley6e280242014-01-01 19:20:40 +0000626 /* Next TBTT =
627 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
628 */
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100629 if (beacon_int) {
630 do_div(tsf, beacon_int);
631 tsf += 1;
632 tsf *= beacon_int;
Malcolm Priestley6e280242014-01-01 19:20:40 +0000633 }
Forest Bond92b96792009-06-13 07:38:31 -0400634
Malcolm Priestley5f4dfb62014-05-24 14:37:04 +0100635 return tsf;
Forest Bond92b96792009-06-13 07:38:31 -0400636}
637
Forest Bond92b96792009-06-13 07:38:31 -0400638/*
639 * Description: Set NIC TSF counter for first Beacon time
640 * Get NEXTTBTT from adjusted TSF and Beacon Interval
641 *
642 * Parameters:
643 * In:
644 * dwIoBase - IO Base
Malcolm Priestley414475f2014-05-24 14:37:05 +0100645 * beacon_interval - Beacon Interval
Forest Bond92b96792009-06-13 07:38:31 -0400646 * Out:
647 * none
648 *
649 * Return Value: none
650 *
651 */
Malcolm Priestley6964cd12014-05-30 23:22:50 +0100652void vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval)
Forest Bond92b96792009-06-13 07:38:31 -0400653{
Malcolm Priestley414475f2014-05-24 14:37:05 +0100654 u64 next_tbtt = 0;
655 u8 data[8];
Forest Bond92b96792009-06-13 07:38:31 -0400656
Malcolm Priestleydba066e2014-05-30 23:22:48 +0100657 vnt_clear_current_tsf(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400658
Malcolm Priestley75ef1b512014-05-30 23:22:49 +0100659 next_tbtt = vnt_get_next_tbtt(next_tbtt, beacon_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400660
Malcolm Priestley414475f2014-05-24 14:37:05 +0100661 data[0] = (u8)next_tbtt;
662 data[1] = (u8)(next_tbtt >> 8);
663 data[2] = (u8)(next_tbtt >> 16);
664 data[3] = (u8)(next_tbtt >> 24);
665 data[4] = (u8)(next_tbtt >> 32);
666 data[5] = (u8)(next_tbtt >> 40);
667 data[6] = (u8)(next_tbtt >> 48);
668 data[7] = (u8)(next_tbtt >> 56);
Forest Bond92b96792009-06-13 07:38:31 -0400669
Malcolm Priestley1390b022014-05-26 13:59:01 +0100670 vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
Malcolm Priestley414475f2014-05-24 14:37:05 +0100671 MESSAGE_REQUEST_TBTT, 0, 8, data);
672
673 return;
Forest Bond92b96792009-06-13 07:38:31 -0400674}
675
Forest Bond92b96792009-06-13 07:38:31 -0400676/*
677 * Description: Sync NIC TSF counter for Beacon time
678 * Get NEXTTBTT and write to HW
679 *
680 * Parameters:
681 * In:
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100682 * priv - The adapter to be set
683 * tsf - Current TSF counter
684 * beacon_interval - Beacon Interval
Forest Bond92b96792009-06-13 07:38:31 -0400685 * Out:
686 * none
687 *
688 * Return Value: none
689 *
690 */
Malcolm Priestley88ec2f72014-05-30 23:22:51 +0100691void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100692 u16 beacon_interval)
Forest Bond92b96792009-06-13 07:38:31 -0400693{
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100694 u8 data[8];
Forest Bond92b96792009-06-13 07:38:31 -0400695
Malcolm Priestley75ef1b512014-05-30 23:22:49 +0100696 tsf = vnt_get_next_tbtt(tsf, beacon_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400697
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100698 data[0] = (u8)tsf;
699 data[1] = (u8)(tsf >> 8);
700 data[2] = (u8)(tsf >> 16);
701 data[3] = (u8)(tsf >> 24);
702 data[4] = (u8)(tsf >> 32);
703 data[5] = (u8)(tsf >> 40);
704 data[6] = (u8)(tsf >> 48);
705 data[7] = (u8)(tsf >> 56);
Forest Bond92b96792009-06-13 07:38:31 -0400706
Malcolm Priestley1390b022014-05-26 13:59:01 +0100707 vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
Peter Senna Tschudin42b138d2014-07-15 23:23:26 +0200708 MESSAGE_REQUEST_TBTT, 0, 8, data);
Forest Bond92b96792009-06-13 07:38:31 -0400709
Malcolm Priestley842e3ecc2014-05-25 21:36:24 +0100710 dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf);
Forest Bond92b96792009-06-13 07:38:31 -0400711
Malcolm Priestley8b515de2014-05-24 14:37:06 +0100712 return;
Forest Bond92b96792009-06-13 07:38:31 -0400713}
714
715/*
716 * Description: Turn off Radio power
717 *
718 * Parameters:
719 * In:
Malcolm Priestley07deb712014-05-24 14:37:07 +0100720 * priv - The adapter to be turned off
Forest Bond92b96792009-06-13 07:38:31 -0400721 * Out:
722 * none
723 *
Andres More4e9b5e22013-02-12 20:36:30 -0500724 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400725 *
726 */
Malcolm Priestleyfa26e0b2014-05-30 23:22:52 +0100727int vnt_radio_power_off(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400728{
Malcolm Priestley07deb712014-05-24 14:37:07 +0100729 int ret = true;
Forest Bond92b96792009-06-13 07:38:31 -0400730
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100731 switch (priv->rf_type) {
Malcolm Priestley07deb712014-05-24 14:37:07 +0100732 case RF_AL2230:
733 case RF_AL2230S:
734 case RF_AIROHA7230:
735 case RF_VT3226:
736 case RF_VT3226D0:
737 case RF_VT3342A0:
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +0100738 vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL,
Malcolm Priestley07deb712014-05-24 14:37:07 +0100739 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
740 break;
741 }
Forest Bond92b96792009-06-13 07:38:31 -0400742
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +0100743 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond92b96792009-06-13 07:38:31 -0400744
Malcolm Priestleye8e072d2014-07-16 22:21:56 +0100745 vnt_set_deep_sleep(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400746
Malcolm Priestleyd7f2d8f2014-07-18 23:00:54 +0100747 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);
748
Malcolm Priestley07deb712014-05-24 14:37:07 +0100749 return ret;
Forest Bond92b96792009-06-13 07:38:31 -0400750}
751
Forest Bond92b96792009-06-13 07:38:31 -0400752/*
753 * Description: Turn on Radio power
754 *
755 * Parameters:
756 * In:
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100757 * priv - The adapter to be turned on
Forest Bond92b96792009-06-13 07:38:31 -0400758 * Out:
759 * none
760 *
Andres More4e9b5e22013-02-12 20:36:30 -0500761 * Return Value: true if success; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -0400762 *
763 */
Malcolm Priestley8a5e6c82014-05-30 23:22:53 +0100764int vnt_radio_power_on(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400765{
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100766 int ret = true;
Forest Bond92b96792009-06-13 07:38:31 -0400767
Malcolm Priestley0e951752014-07-16 22:21:57 +0100768 vnt_exit_deep_sleep(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400769
Malcolm Priestley36957532014-05-31 11:50:42 +0100770 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond92b96792009-06-13 07:38:31 -0400771
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100772 switch (priv->rf_type) {
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100773 case RF_AL2230:
774 case RF_AL2230S:
775 case RF_AIROHA7230:
776 case RF_VT3226:
777 case RF_VT3226D0:
778 case RF_VT3342A0:
Malcolm Priestley36957532014-05-31 11:50:42 +0100779 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100780 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
781 break;
782 }
Forest Bond92b96792009-06-13 07:38:31 -0400783
Malcolm Priestleyd7f2d8f2014-07-18 23:00:54 +0100784 vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);
785
Malcolm Priestleyf3203142014-05-24 14:37:08 +0100786 return ret;
Forest Bond92b96792009-06-13 07:38:31 -0400787}
788
Malcolm Priestleybc240f52014-05-30 23:22:54 +0100789void vnt_set_bss_mode(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400790{
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100791 if (priv->rf_type == RF_AIROHA7230 && priv->bb_type == BB_TYPE_11A)
Malcolm Priestley05089fb2014-05-31 11:50:38 +0100792 vnt_mac_set_bb_type(priv, BB_TYPE_11G);
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100793 else
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100794 vnt_mac_set_bb_type(priv, priv->bb_type);
Forest Bond92b96792009-06-13 07:38:31 -0400795
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100796 priv->packet_type = vnt_get_pkt_type(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400797
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100798 if (priv->bb_type == BB_TYPE_11A)
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100799 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100800 else if (priv->bb_type == BB_TYPE_11B)
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100801 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100802 else if (priv->bb_type == BB_TYPE_11G)
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100803 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
Forest Bond92b96792009-06-13 07:38:31 -0400804
Malcolm Priestleyc7ee9ee2014-05-30 16:27:44 +0100805 vnt_update_ifs(priv);
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100806 vnt_set_rspinf(priv, (u8)priv->bb_type);
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100807
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100808 if (priv->bb_type == BB_TYPE_11A) {
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100809 if (priv->rf_type == RF_AIROHA7230) {
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100810 priv->abyBBVGA[0] = 0x20;
811
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100812 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100813 0xe7, priv->abyBBVGA[0]);
814 }
815
816 priv->abyBBVGA[2] = 0x10;
817 priv->abyBBVGA[3] = 0x10;
818 } else {
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100819 if (priv->rf_type == RF_AIROHA7230) {
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100820 priv->abyBBVGA[0] = 0x1c;
821
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100822 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
Malcolm Priestley1efb8fa2014-05-24 14:37:09 +0100823 0xe7, priv->abyBBVGA[0]);
824 }
825
826 priv->abyBBVGA[2] = 0x0;
827 priv->abyBBVGA[3] = 0x0;
828 }
Malcolm Priestleyd3584772014-06-28 23:55:45 +0100829
Malcolm Priestleyde8690a2014-07-16 22:21:55 +0100830 vnt_set_vga_gain_offset(priv, priv->abyBBVGA[0]);
Forest Bond92b96792009-06-13 07:38:31 -0400831}