blob: 7fc8c25c7d41cf99ae9eaa9ce7e2752225f8a432 [file] [log] [blame]
Johannes Berg2295c662010-10-23 09:15:41 -07001/******************************************************************************
2 *
Wey-Yi Guyfb4961d2012-01-06 13:16:33 -08003 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
Johannes Berg2295c662010-10-23 09:15:41 -07004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
26
Meenakshi Venkataraman55620922012-03-15 13:27:02 -070027#include <linux/etherdevice.h>
Johannes Berg2295c662010-10-23 09:15:41 -070028#include "iwl-dev.h"
29#include "iwl-agn.h"
Johannes Berg2295c662010-10-23 09:15:41 -070030#include "iwl-agn-calib.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070031#include "iwl-trans.h"
Johannes Berg65de7e82012-04-17 07:36:30 -070032#include "iwl-modparams.h"
Johannes Berg2295c662010-10-23 09:15:41 -070033
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070034/*
35 * initialize rxon structure with default values from eeprom
36 */
37void iwl_connection_init_rx_config(struct iwl_priv *priv,
38 struct iwl_rxon_context *ctx)
39{
40 const struct iwl_channel_info *ch_info;
41
42 memset(&ctx->staging, 0, sizeof(ctx->staging));
43
44 if (!ctx->vif) {
45 ctx->staging.dev_type = ctx->unused_devtype;
46 } else
47 switch (ctx->vif->type) {
48 case NL80211_IFTYPE_AP:
49 ctx->staging.dev_type = ctx->ap_devtype;
50 break;
51
52 case NL80211_IFTYPE_STATION:
53 ctx->staging.dev_type = ctx->station_devtype;
54 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
55 break;
56
57 case NL80211_IFTYPE_ADHOC:
58 ctx->staging.dev_type = ctx->ibss_devtype;
59 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
60 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
61 RXON_FILTER_ACCEPT_GRP_MSK;
62 break;
63
Johannes Berg57897722012-05-11 10:53:18 +020064 case NL80211_IFTYPE_MONITOR:
65 ctx->staging.dev_type = RXON_DEV_TYPE_SNIFFER;
66 break;
67
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070068 default:
69 IWL_ERR(priv, "Unsupported interface type %d\n",
70 ctx->vif->type);
71 break;
72 }
73
74#if 0
75 /* TODO: Figure out when short_preamble would be set and cache from
76 * that */
77 if (!hw_to_local(priv->hw)->short_preamble)
78 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
79 else
80 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
81#endif
82
83 ch_info = iwl_get_channel_info(priv, priv->band,
84 le16_to_cpu(ctx->active.channel));
85
86 if (!ch_info)
87 ch_info = &priv->channel_info[0];
88
89 ctx->staging.channel = cpu_to_le16(ch_info->channel);
90 priv->band = ch_info->band;
91
92 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
93
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070094 /* clear both MIX and PURE40 mode flag */
95 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
96 RXON_FLG_CHANNEL_MODE_PURE_40);
97 if (ctx->vif)
98 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
99
100 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
101 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
102 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
103}
104
Johannes Berg2295c662010-10-23 09:15:41 -0700105static int iwlagn_disable_bss(struct iwl_priv *priv,
106 struct iwl_rxon_context *ctx,
107 struct iwl_rxon_cmd *send)
108{
109 __le32 old_filter = send->filter_flags;
110 int ret;
111
112 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800113 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700114 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700115
116 send->filter_flags = old_filter;
117
118 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800119 IWL_DEBUG_QUIET_RFKILL(priv,
120 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
Johannes Berg2295c662010-10-23 09:15:41 -0700121
122 return ret;
123}
124
125static int iwlagn_disable_pan(struct iwl_priv *priv,
126 struct iwl_rxon_context *ctx,
127 struct iwl_rxon_cmd *send)
128{
Johannes Berg311dce72011-01-04 16:22:01 -0800129 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -0700130 __le32 old_filter = send->filter_flags;
131 u8 old_dev_type = send->dev_type;
132 int ret;
Johannes Bergdb662d42012-03-15 13:26:44 -0700133 static const u8 deactivate_cmd[] = {
134 REPLY_WIPAN_DEACTIVATION_COMPLETE
135 };
Johannes Berg2295c662010-10-23 09:15:41 -0700136
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800137 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
Johannes Bergdb662d42012-03-15 13:26:44 -0700138 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800139 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -0800140
Johannes Berg2295c662010-10-23 09:15:41 -0700141 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
142 send->dev_type = RXON_DEV_TYPE_P2P;
Johannes Berge10a0532012-03-06 13:30:39 -0800143 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700144 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700145
146 send->filter_flags = old_filter;
147 send->dev_type = old_dev_type;
148
Johannes Berg311dce72011-01-04 16:22:01 -0800149 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -0700150 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800151 iwl_remove_notification(&priv->notif_wait, &disable_wait);
Johannes Berg311dce72011-01-04 16:22:01 -0800152 } else {
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800153 ret = iwl_wait_notification(&priv->notif_wait,
154 &disable_wait, HZ);
Johannes Berga8674a12011-04-13 03:14:48 -0700155 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -0800156 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
157 }
Johannes Berg2295c662010-10-23 09:15:41 -0700158
159 return ret;
160}
161
Johannes Berg2b9253d2011-05-27 08:40:26 -0700162static int iwlagn_disconn_pan(struct iwl_priv *priv,
163 struct iwl_rxon_context *ctx,
164 struct iwl_rxon_cmd *send)
165{
166 __le32 old_filter = send->filter_flags;
167 int ret;
168
169 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800170 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700171 sizeof(*send), send);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700172
173 send->filter_flags = old_filter;
174
175 return ret;
176}
177
Johannes Bergaca86262012-05-14 09:08:50 +0200178static void iwlagn_update_qos(struct iwl_priv *priv,
179 struct iwl_rxon_context *ctx)
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800180{
181 int ret;
182
183 if (!ctx->is_active)
184 return;
185
186 ctx->qos_data.def_qos_parm.qos_flags = 0;
187
188 if (ctx->qos_data.qos_active)
189 ctx->qos_data.def_qos_parm.qos_flags |=
190 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
191
192 if (ctx->ht.enabled)
193 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
194
Emmanuel Grumbach0dcf50c2011-11-10 06:55:23 -0800195 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800196 ctx->qos_data.qos_active,
197 ctx->qos_data.def_qos_parm.qos_flags);
198
Johannes Berge10a0532012-03-06 13:30:39 -0800199 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800200 sizeof(struct iwl_qosparam_cmd),
201 &ctx->qos_data.def_qos_parm);
202 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800203 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800204}
205
Johannes Bergaca86262012-05-14 09:08:50 +0200206static int iwlagn_update_beacon(struct iwl_priv *priv,
207 struct ieee80211_vif *vif)
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700208{
Johannes Bergb1eea292012-03-06 13:30:42 -0800209 lockdep_assert_held(&priv->mutex);
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700210
211 dev_kfree_skb(priv->beacon_skb);
212 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
213 if (!priv->beacon_skb)
214 return -ENOMEM;
215 return iwlagn_send_beacon_cmd(priv);
216}
217
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700218static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
Johannes Bergaca86262012-05-14 09:08:50 +0200219 struct iwl_rxon_context *ctx)
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700220{
221 int ret = 0;
Wey-Yi Guy89e746b2011-04-19 16:52:58 -0700222 struct iwl_rxon_assoc_cmd rxon_assoc;
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700223 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
224 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
225
226 if ((rxon1->flags == rxon2->flags) &&
227 (rxon1->filter_flags == rxon2->filter_flags) &&
228 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
229 (rxon1->ofdm_ht_single_stream_basic_rates ==
230 rxon2->ofdm_ht_single_stream_basic_rates) &&
231 (rxon1->ofdm_ht_dual_stream_basic_rates ==
232 rxon2->ofdm_ht_dual_stream_basic_rates) &&
233 (rxon1->ofdm_ht_triple_stream_basic_rates ==
234 rxon2->ofdm_ht_triple_stream_basic_rates) &&
235 (rxon1->acquisition_data == rxon2->acquisition_data) &&
236 (rxon1->rx_chain == rxon2->rx_chain) &&
237 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
238 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
239 return 0;
240 }
241
242 rxon_assoc.flags = ctx->staging.flags;
243 rxon_assoc.filter_flags = ctx->staging.filter_flags;
244 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
245 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
246 rxon_assoc.reserved1 = 0;
247 rxon_assoc.reserved2 = 0;
248 rxon_assoc.reserved3 = 0;
249 rxon_assoc.ofdm_ht_single_stream_basic_rates =
250 ctx->staging.ofdm_ht_single_stream_basic_rates;
251 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
252 ctx->staging.ofdm_ht_dual_stream_basic_rates;
253 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
254 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
255 ctx->staging.ofdm_ht_triple_stream_basic_rates;
256 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
257
Johannes Berge10a0532012-03-06 13:30:39 -0800258 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700259 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700260 return ret;
261}
262
Meenakshi Venkataramandff96c12012-03-15 13:26:59 -0700263static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
264{
265 u16 new_val;
266 u16 beacon_factor;
267
268 /*
269 * If mac80211 hasn't given us a beacon interval, program
270 * the default into the device (not checking this here
271 * would cause the adjustment below to return the maximum
272 * value, which may break PAN.)
273 */
274 if (!beacon_val)
275 return DEFAULT_BEACON_INTERVAL;
276
277 /*
278 * If the beacon interval we obtained from the peer
279 * is too large, we'll have to wake up more often
280 * (and in IBSS case, we'll beacon too much)
281 *
282 * For example, if max_beacon_val is 4096, and the
283 * requested beacon interval is 7000, we'll have to
284 * use 3500 to be able to wake up on the beacons.
285 *
286 * This could badly influence beacon detection stats.
287 */
288
289 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
290 new_val = beacon_val / beacon_factor;
291
292 if (!new_val)
293 new_val = max_beacon_val;
294
295 return new_val;
296}
297
298static int iwl_send_rxon_timing(struct iwl_priv *priv,
299 struct iwl_rxon_context *ctx)
300{
301 u64 tsf;
302 s32 interval_tm, rem;
303 struct ieee80211_conf *conf = NULL;
304 u16 beacon_int;
305 struct ieee80211_vif *vif = ctx->vif;
306
307 conf = &priv->hw->conf;
308
309 lockdep_assert_held(&priv->mutex);
310
311 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
312
313 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
314 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
315
316 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
317
318 /*
319 * TODO: For IBSS we need to get atim_window from mac80211,
320 * for now just always use 0
321 */
322 ctx->timing.atim_window = 0;
323
324 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
325 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
326 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
327 priv->contexts[IWL_RXON_CTX_BSS].vif &&
328 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
329 ctx->timing.beacon_interval =
330 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
331 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
332 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
333 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
334 priv->contexts[IWL_RXON_CTX_PAN].vif &&
335 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
336 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
337 !ctx->vif->bss_conf.beacon_int)) {
338 ctx->timing.beacon_interval =
339 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
340 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
341 } else {
342 beacon_int = iwl_adjust_beacon_interval(beacon_int,
343 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
344 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
345 }
346
347 ctx->beacon_int = beacon_int;
348
349 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
350 interval_tm = beacon_int * TIME_UNIT;
351 rem = do_div(tsf, interval_tm);
352 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
353
354 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
355
356 IWL_DEBUG_ASSOC(priv,
357 "beacon interval %d beacon timer %d beacon tim %d\n",
358 le16_to_cpu(ctx->timing.beacon_interval),
359 le32_to_cpu(ctx->timing.beacon_init_val),
360 le16_to_cpu(ctx->timing.atim_window));
361
362 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
363 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
364}
365
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700366static int iwlagn_rxon_disconn(struct iwl_priv *priv,
367 struct iwl_rxon_context *ctx)
368{
369 int ret;
370 struct iwl_rxon_cmd *active = (void *)&ctx->active;
371
Johannes Berg2b9253d2011-05-27 08:40:26 -0700372 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700373 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700374 } else {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700375 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700376 if (ret)
377 return ret;
378 if (ctx->vif) {
379 ret = iwl_send_rxon_timing(priv, ctx);
380 if (ret) {
381 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
382 return ret;
383 }
384 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
385 }
386 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700387 if (ret)
388 return ret;
389
390 /*
391 * Un-assoc RXON clears the station table and WEP
392 * keys, so we have to restore those afterwards.
393 */
394 iwl_clear_ucode_stations(priv, ctx);
Johannes Bergf775aa06d2011-06-22 06:34:09 -0700395 /* update -- might need P2P now */
396 iwl_update_bcast_station(priv, ctx);
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700397 iwl_restore_stations(priv, ctx);
398 ret = iwl_restore_default_wep_keys(priv, ctx);
399 if (ret) {
400 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
401 return ret;
402 }
403
404 memcpy(active, &ctx->staging, sizeof(*active));
405 return 0;
406}
407
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700408static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
409{
410 int ret;
411 s8 prev_tx_power;
412 bool defer;
413 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
414
Dor Shaishbfb45f52012-03-26 08:20:55 -0700415 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
416 return 0;
417
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700418 lockdep_assert_held(&priv->mutex);
419
420 if (priv->tx_power_user_lmt == tx_power && !force)
421 return 0;
422
423 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
424 IWL_WARN(priv,
425 "Requested user TXPOWER %d below lower limit %d.\n",
426 tx_power,
427 IWLAGN_TX_POWER_TARGET_POWER_MIN);
428 return -EINVAL;
429 }
430
431 if (tx_power > priv->tx_power_device_lmt) {
432 IWL_WARN(priv,
433 "Requested user TXPOWER %d above upper limit %d.\n",
434 tx_power, priv->tx_power_device_lmt);
435 return -EINVAL;
436 }
437
438 if (!iwl_is_ready_rf(priv))
439 return -EIO;
440
441 /* scan complete and commit_rxon use tx_power_next value,
442 * it always need to be updated for newest request */
443 priv->tx_power_next = tx_power;
444
445 /* do not set tx power when scanning or channel changing */
446 defer = test_bit(STATUS_SCANNING, &priv->status) ||
447 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
448 if (defer && !force) {
449 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
450 return 0;
451 }
452
453 prev_tx_power = priv->tx_power_user_lmt;
454 priv->tx_power_user_lmt = tx_power;
455
456 ret = iwlagn_send_tx_power(priv);
457
458 /* if fail to set tx_power, restore the orig. tx power */
459 if (ret) {
460 priv->tx_power_user_lmt = prev_tx_power;
461 priv->tx_power_next = prev_tx_power;
462 }
463 return ret;
464}
465
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700466static int iwlagn_rxon_connect(struct iwl_priv *priv,
467 struct iwl_rxon_context *ctx)
468{
469 int ret;
470 struct iwl_rxon_cmd *active = (void *)&ctx->active;
471
472 /* RXON timing must be before associated RXON */
Johannes Berg2b9253d2011-05-27 08:40:26 -0700473 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
474 ret = iwl_send_rxon_timing(priv, ctx);
475 if (ret) {
476 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
477 return ret;
478 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700479 }
480 /* QoS info may be cleared by previous un-assoc RXON */
481 iwlagn_update_qos(priv, ctx);
482
483 /*
484 * We'll run into this code path when beaconing is
485 * enabled, but then we also need to send the beacon
486 * to the device.
487 */
488 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
489 ret = iwlagn_update_beacon(priv, ctx->vif);
490 if (ret) {
491 IWL_ERR(priv,
492 "Error sending required beacon (%d)!\n",
493 ret);
494 return ret;
495 }
496 }
497
498 priv->start_calib = 0;
499 /*
500 * Apply the new configuration.
501 *
502 * Associated RXON doesn't clear the station table in uCode,
503 * so we don't need to restore stations etc. after this.
504 */
Johannes Berge10a0532012-03-06 13:30:39 -0800505 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700506 sizeof(struct iwl_rxon_cmd), &ctx->staging);
507 if (ret) {
508 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
509 return ret;
510 }
511 memcpy(active, &ctx->staging, sizeof(*active));
512
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700513 /* IBSS beacon needs to be sent after setting assoc */
514 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
515 if (iwlagn_update_beacon(priv, ctx->vif))
516 IWL_ERR(priv, "Error sending IBSS beacon\n");
517 iwl_init_sensitivity(priv);
518
519 /*
520 * If we issue a new RXON command which required a tune then
521 * we must send a new TXPOWER command or we won't be able to
522 * Tx any frames.
523 *
524 * It's expected we set power here if channel is changing.
525 */
526 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
527 if (ret) {
528 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
529 return ret;
530 }
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700531
Stanislaw Gruszka107ef972011-10-12 10:16:35 +0200532 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200533 priv->cfg->ht_params && priv->cfg->ht_params->smps_mode)
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700534 ieee80211_request_smps(ctx->vif,
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200535 priv->cfg->ht_params->smps_mode);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700536
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700537 return 0;
538}
539
Wey-Yi Guye505c432011-07-07 08:27:41 -0700540int iwlagn_set_pan_params(struct iwl_priv *priv)
541{
542 struct iwl_wipan_params_cmd cmd;
543 struct iwl_rxon_context *ctx_bss, *ctx_pan;
544 int slot0 = 300, slot1 = 0;
545 int ret;
546
Johannes Berga18f61b2012-03-15 13:26:53 -0700547 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
Wey-Yi Guye505c432011-07-07 08:27:41 -0700548 return 0;
549
550 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
551
Johannes Bergb1eea292012-03-06 13:30:42 -0800552 lockdep_assert_held(&priv->mutex);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700553
554 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
555 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
556
557 /*
558 * If the PAN context is inactive, then we don't need
559 * to update the PAN parameters, the last thing we'll
560 * have done before it goes inactive is making the PAN
561 * parameters be WLAN-only.
562 */
563 if (!ctx_pan->is_active)
564 return 0;
565
566 memset(&cmd, 0, sizeof(cmd));
567
568 /* only 2 slots are currently allowed */
569 cmd.num_slots = 2;
570
571 cmd.slots[0].type = 0; /* BSS */
572 cmd.slots[1].type = 1; /* PAN */
573
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700574 if (priv->hw_roc_setup) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700575 /* both contexts must be used for this to happen */
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700576 slot1 = IWL_MIN_SLOT_TIME;
577 slot0 = 3000;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700578 } else if (ctx_bss->vif && ctx_pan->vif) {
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700579 int bcnint = ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700580 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
581
582 /* should be set, but seems unused?? */
583 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
584
585 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
586 bcnint &&
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700587 bcnint != ctx_bss->beacon_int) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700588 IWL_ERR(priv,
589 "beacon intervals don't match (%d, %d)\n",
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700590 ctx_bss->beacon_int, ctx_pan->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700591 } else
592 bcnint = max_t(int, bcnint,
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700593 ctx_bss->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700594 if (!bcnint)
595 bcnint = DEFAULT_BEACON_INTERVAL;
596 slot0 = bcnint / 2;
597 slot1 = bcnint - slot0;
598
Don Fry83626402012-03-07 09:52:37 -0800599 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
Wey-Yi Guye505c432011-07-07 08:27:41 -0700600 (!ctx_bss->vif->bss_conf.idle &&
601 !ctx_bss->vif->bss_conf.assoc)) {
602 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
603 slot1 = IWL_MIN_SLOT_TIME;
604 } else if (!ctx_pan->vif->bss_conf.idle &&
605 !ctx_pan->vif->bss_conf.assoc) {
Johannes Berg325a7dd2011-09-22 15:14:55 -0700606 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700607 slot0 = IWL_MIN_SLOT_TIME;
608 }
609 } else if (ctx_pan->vif) {
610 slot0 = 0;
611 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700612 ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700613 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
614
Don Fry83626402012-03-07 09:52:37 -0800615 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700616 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
617 slot1 = IWL_MIN_SLOT_TIME;
618 }
619 }
620
621 cmd.slots[0].width = cpu_to_le16(slot0);
622 cmd.slots[1].width = cpu_to_le16(slot1);
623
Johannes Berge10a0532012-03-06 13:30:39 -0800624 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
Wey-Yi Guye505c432011-07-07 08:27:41 -0700625 sizeof(cmd), &cmd);
626 if (ret)
627 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
628
629 return ret;
630}
631
Meenakshi Venkataramandd641732012-03-13 16:25:38 -0700632static void _iwl_set_rxon_ht(struct iwl_priv *priv,
633 struct iwl_ht_config *ht_conf,
634 struct iwl_rxon_context *ctx)
635{
636 struct iwl_rxon_cmd *rxon = &ctx->staging;
637
638 if (!ctx->ht.enabled) {
639 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
640 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
641 RXON_FLG_HT40_PROT_MSK |
642 RXON_FLG_HT_PROT_MSK);
643 return;
644 }
645
646 /* FIXME: if the definition of ht.protection changed, the "translation"
647 * will be needed for rxon->flags
648 */
649 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
650 RXON_FLG_HT_OPERATING_MODE_POS);
651
652 /* Set up channel bandwidth:
653 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
654 /* clear the HT channel mode before set the mode */
655 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
656 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
657 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
658 /* pure ht40 */
659 if (ctx->ht.protection ==
660 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
661 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
662 /*
663 * Note: control channel is opposite of extension
664 * channel
665 */
666 switch (ctx->ht.extension_chan_offset) {
667 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
668 rxon->flags &=
669 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
670 break;
671 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
672 rxon->flags |=
673 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
674 break;
675 }
676 } else {
677 /*
678 * Note: control channel is opposite of extension
679 * channel
680 */
681 switch (ctx->ht.extension_chan_offset) {
682 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
683 rxon->flags &=
684 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
685 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
686 break;
687 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
688 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
689 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
690 break;
691 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
692 default:
693 /*
694 * channel location only valid if in Mixed
695 * mode
696 */
697 IWL_ERR(priv,
698 "invalid extension channel offset\n");
699 break;
700 }
701 }
702 } else {
703 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
704 }
705
706 iwlagn_set_rxon_chain(priv, ctx);
707
708 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
709 "extension channel offset 0x%x\n",
710 le32_to_cpu(rxon->flags), ctx->ht.protection,
711 ctx->ht.extension_chan_offset);
712}
713
714void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
715{
716 struct iwl_rxon_context *ctx;
717
718 for_each_context(priv, ctx)
719 _iwl_set_rxon_ht(priv, ht_conf, ctx);
720}
721
Meenakshi Venkataramanfedfa872012-03-13 16:31:34 -0700722/**
723 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
724 * @ch: requested channel as a pointer to struct ieee80211_channel
725
726 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
727 * in the staging RXON flag structure based on the ch->band
728 */
729void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
730 struct iwl_rxon_context *ctx)
731{
732 enum ieee80211_band band = ch->band;
733 u16 channel = ch->hw_value;
734
735 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
736 (priv->band == band))
737 return;
738
739 ctx->staging.channel = cpu_to_le16(channel);
740 if (band == IEEE80211_BAND_5GHZ)
741 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
742 else
743 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
744
745 priv->band = band;
746
747 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
748
749}
750
Meenakshi Venkataraman50319f72012-03-13 16:45:00 -0700751void iwl_set_flags_for_band(struct iwl_priv *priv,
752 struct iwl_rxon_context *ctx,
753 enum ieee80211_band band,
754 struct ieee80211_vif *vif)
755{
756 if (band == IEEE80211_BAND_5GHZ) {
757 ctx->staging.flags &=
758 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
759 | RXON_FLG_CCK_MSK);
760 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
761 } else {
762 /* Copied from iwl_post_associate() */
763 if (vif && vif->bss_conf.use_short_slot)
764 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
765 else
766 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
767
768 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
769 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
770 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
771 }
772}
773
Meenakshi Venkataraman354a4532012-03-15 13:27:00 -0700774static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
775 struct iwl_rxon_context *ctx, int hw_decrypt)
776{
777 struct iwl_rxon_cmd *rxon = &ctx->staging;
778
779 if (hw_decrypt)
780 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
781 else
782 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
783
784}
785
Meenakshi Venkataraman8931b572012-03-15 13:27:01 -0700786/* validate RXON structure is valid */
787static int iwl_check_rxon_cmd(struct iwl_priv *priv,
788 struct iwl_rxon_context *ctx)
789{
790 struct iwl_rxon_cmd *rxon = &ctx->staging;
791 u32 errors = 0;
792
793 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
794 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
795 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
796 errors |= BIT(0);
797 }
798 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
799 IWL_WARN(priv, "check 2.4G: wrong radar\n");
800 errors |= BIT(1);
801 }
802 } else {
803 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
804 IWL_WARN(priv, "check 5.2G: not short slot!\n");
805 errors |= BIT(2);
806 }
807 if (rxon->flags & RXON_FLG_CCK_MSK) {
808 IWL_WARN(priv, "check 5.2G: CCK!\n");
809 errors |= BIT(3);
810 }
811 }
812 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
813 IWL_WARN(priv, "mac/bssid mcast!\n");
814 errors |= BIT(4);
815 }
816
817 /* make sure basic rates 6Mbps and 1Mbps are supported */
818 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
819 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
820 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
821 errors |= BIT(5);
822 }
823
824 if (le16_to_cpu(rxon->assoc_id) > 2007) {
825 IWL_WARN(priv, "aid > 2007\n");
826 errors |= BIT(6);
827 }
828
829 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
830 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
831 IWL_WARN(priv, "CCK and short slot\n");
832 errors |= BIT(7);
833 }
834
835 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
836 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
837 IWL_WARN(priv, "CCK and auto detect");
838 errors |= BIT(8);
839 }
840
841 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
842 RXON_FLG_TGG_PROTECT_MSK)) ==
843 RXON_FLG_TGG_PROTECT_MSK) {
844 IWL_WARN(priv, "TGg but no auto-detect\n");
845 errors |= BIT(9);
846 }
847
848 if (rxon->channel == 0) {
849 IWL_WARN(priv, "zero channel is invalid\n");
850 errors |= BIT(10);
851 }
852
853 WARN(errors, "Invalid RXON (%#x), channel %d",
854 errors, le16_to_cpu(rxon->channel));
855
856 return errors ? -EINVAL : 0;
857}
858
Johannes Berg2295c662010-10-23 09:15:41 -0700859/**
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700860 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
861 * @priv: staging_rxon is compared to active_rxon
862 *
863 * If the RXON structure is changing enough to require a new tune,
864 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
865 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
866 */
Johannes Bergaca86262012-05-14 09:08:50 +0200867static int iwl_full_rxon_required(struct iwl_priv *priv,
868 struct iwl_rxon_context *ctx)
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700869{
870 const struct iwl_rxon_cmd *staging = &ctx->staging;
871 const struct iwl_rxon_cmd *active = &ctx->active;
872
873#define CHK(cond) \
874 if ((cond)) { \
875 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
876 return 1; \
877 }
878
879#define CHK_NEQ(c1, c2) \
880 if ((c1) != (c2)) { \
881 IWL_DEBUG_INFO(priv, "need full RXON - " \
882 #c1 " != " #c2 " - %d != %d\n", \
883 (c1), (c2)); \
884 return 1; \
885 }
886
887 /* These items are only settable from the full RXON command */
888 CHK(!iwl_is_associated_ctx(ctx));
Joe Perches2e42e472012-05-09 17:17:46 +0000889 CHK(!ether_addr_equal(staging->bssid_addr, active->bssid_addr));
890 CHK(!ether_addr_equal(staging->node_addr, active->node_addr));
891 CHK(!ether_addr_equal(staging->wlap_bssid_addr,
892 active->wlap_bssid_addr));
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700893 CHK_NEQ(staging->dev_type, active->dev_type);
894 CHK_NEQ(staging->channel, active->channel);
895 CHK_NEQ(staging->air_propagation, active->air_propagation);
896 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
897 active->ofdm_ht_single_stream_basic_rates);
898 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
899 active->ofdm_ht_dual_stream_basic_rates);
900 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
901 active->ofdm_ht_triple_stream_basic_rates);
902 CHK_NEQ(staging->assoc_id, active->assoc_id);
903
904 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
905 * be updated with the RXON_ASSOC command -- however only some
906 * flag transitions are allowed using RXON_ASSOC */
907
908 /* Check if we are not switching bands */
909 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
910 active->flags & RXON_FLG_BAND_24G_MSK);
911
912 /* Check if we are switching association toggle */
913 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
914 active->filter_flags & RXON_FILTER_ASSOC_MSK);
915
916#undef CHK
917#undef CHK_NEQ
918
919 return 0;
920}
921
Meenakshi Venkataraman4d323ac2012-03-14 15:15:33 -0700922#ifdef CONFIG_IWLWIFI_DEBUG
923void iwl_print_rx_config_cmd(struct iwl_priv *priv,
924 enum iwl_rxon_context_id ctxid)
925{
926 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
927 struct iwl_rxon_cmd *rxon = &ctx->staging;
928
929 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
930 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
931 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
932 le16_to_cpu(rxon->channel));
933 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
934 le32_to_cpu(rxon->flags));
935 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
936 le32_to_cpu(rxon->filter_flags));
937 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
938 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
939 rxon->ofdm_basic_rates);
940 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
941 rxon->cck_basic_rates);
942 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
943 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
944 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
945 le16_to_cpu(rxon->assoc_id));
946}
947#endif
948
Johannes Berg9543c5f2012-03-08 09:37:53 +0100949static void iwl_calc_basic_rates(struct iwl_priv *priv,
950 struct iwl_rxon_context *ctx)
951{
952 int lowest_present_ofdm = 100;
953 int lowest_present_cck = 100;
954 u8 cck = 0;
955 u8 ofdm = 0;
956
957 if (ctx->vif) {
958 struct ieee80211_supported_band *sband;
959 unsigned long basic = ctx->vif->bss_conf.basic_rates;
960 int i;
961
962 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
963
964 for_each_set_bit(i, &basic, BITS_PER_LONG) {
965 int hw = sband->bitrates[i].hw_value;
966 if (hw >= IWL_FIRST_OFDM_RATE) {
967 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
968 if (lowest_present_ofdm > hw)
969 lowest_present_ofdm = hw;
970 } else {
971 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
972
973 cck |= BIT(hw);
974 if (lowest_present_cck > hw)
975 lowest_present_cck = hw;
976 }
977 }
978 }
979
980 /*
981 * Now we've got the basic rates as bitmaps in the ofdm and cck
982 * variables. This isn't sufficient though, as there might not
983 * be all the right rates in the bitmap. E.g. if the only basic
984 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
985 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
986 *
987 * [...] a STA responding to a received frame shall transmit
988 * its Control Response frame [...] at the highest rate in the
989 * BSSBasicRateSet parameter that is less than or equal to the
990 * rate of the immediately previous frame in the frame exchange
991 * sequence ([...]) and that is of the same modulation class
992 * ([...]) as the received frame. If no rate contained in the
993 * BSSBasicRateSet parameter meets these conditions, then the
994 * control frame sent in response to a received frame shall be
995 * transmitted at the highest mandatory rate of the PHY that is
996 * less than or equal to the rate of the received frame, and
997 * that is of the same modulation class as the received frame.
998 *
999 * As a consequence, we need to add all mandatory rates that are
1000 * lower than all of the basic rates to these bitmaps.
1001 */
1002
1003 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
1004 ofdm |= IWL_RATE_24M_MASK >> IWL_FIRST_OFDM_RATE;
1005 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
1006 ofdm |= IWL_RATE_12M_MASK >> IWL_FIRST_OFDM_RATE;
1007 /* 6M already there or needed so always add */
1008 ofdm |= IWL_RATE_6M_MASK >> IWL_FIRST_OFDM_RATE;
1009
1010 /*
1011 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
1012 * Note, however:
1013 * - if no CCK rates are basic, it must be ERP since there must
1014 * be some basic rates at all, so they're OFDM => ERP PHY
1015 * (or we're in 5 GHz, and the cck bitmap will never be used)
1016 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
1017 * - if 5.5M is basic, 1M and 2M are mandatory
1018 * - if 2M is basic, 1M is mandatory
1019 * - if 1M is basic, that's the only valid ACK rate.
1020 * As a consequence, it's not as complicated as it sounds, just add
1021 * any lower rates to the ACK rate bitmap.
1022 */
1023 if (IWL_RATE_11M_INDEX < lowest_present_ofdm)
1024 ofdm |= IWL_RATE_11M_MASK >> IWL_FIRST_CCK_RATE;
1025 if (IWL_RATE_5M_INDEX < lowest_present_ofdm)
1026 ofdm |= IWL_RATE_5M_MASK >> IWL_FIRST_CCK_RATE;
1027 if (IWL_RATE_2M_INDEX < lowest_present_ofdm)
1028 ofdm |= IWL_RATE_2M_MASK >> IWL_FIRST_CCK_RATE;
1029 /* 1M already there or needed so always add */
1030 cck |= IWL_RATE_1M_MASK >> IWL_FIRST_CCK_RATE;
1031
1032 IWL_DEBUG_RATE(priv, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n",
1033 cck, ofdm);
1034
1035 /* "basic_rates" is a misnomer here -- should be called ACK rates */
1036 ctx->staging.cck_basic_rates = cck;
1037 ctx->staging.ofdm_basic_rates = ofdm;
1038}
1039
Meenakshi Venkataraman55620922012-03-15 13:27:02 -07001040/**
Johannes Berg2295c662010-10-23 09:15:41 -07001041 * iwlagn_commit_rxon - commit staging_rxon to hardware
1042 *
1043 * The RXON command in staging_rxon is committed to the hardware and
1044 * the active_rxon structure is updated with the new data. This
1045 * function correctly transitions out of the RXON_ASSOC_MSK state if
1046 * a HW tune is required based on the RXON structure changes.
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001047 *
1048 * The connect/disconnect flow should be as the following:
1049 *
1050 * 1. make sure send RXON command with association bit unset if not connect
1051 * this should include the channel and the band for the candidate
1052 * to be connected to
1053 * 2. Add Station before RXON association with the AP
1054 * 3. RXON_timing has to send before RXON for connection
1055 * 4. full RXON command - associated bit set
1056 * 5. use RXON_ASSOC command to update any flags changes
Johannes Berg2295c662010-10-23 09:15:41 -07001057 */
1058int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1059{
1060 /* cast away the const for active_rxon in this function */
1061 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -07001062 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
1063 int ret;
1064
Johannes Bergb1eea292012-03-06 13:30:42 -08001065 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001066
Don Fry83626402012-03-07 09:52:37 -08001067 if (!iwl_is_alive(priv))
Johannes Berg2295c662010-10-23 09:15:41 -07001068 return -EBUSY;
1069
1070 /* This function hardcodes a bunch of dual-mode assumptions */
1071 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1072
1073 if (!ctx->is_active)
1074 return 0;
1075
1076 /* always get timestamp with Rx frame */
1077 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1078
Johannes Berg9543c5f2012-03-08 09:37:53 +01001079 /* recalculate basic rates */
1080 iwl_calc_basic_rates(priv, ctx);
1081
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +02001082 /*
1083 * force CTS-to-self frames protection if RTS-CTS is not preferred
1084 * one aggregation protection method
1085 */
Johannes Berg9e295112012-04-09 17:46:55 -07001086 if (!priv->hw_params.use_rts_for_aggregation)
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +02001087 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1088
Johannes Berg2295c662010-10-23 09:15:41 -07001089 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1090 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1091 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1092 else
1093 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1094
Emmanuel Grumbach522376d2011-09-06 09:31:19 -07001095 iwl_print_rx_config_cmd(priv, ctx->ctxid);
Johannes Berg2295c662010-10-23 09:15:41 -07001096 ret = iwl_check_rxon_cmd(priv, ctx);
1097 if (ret) {
1098 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1099 return -EINVAL;
1100 }
1101
1102 /*
1103 * receive commit_rxon request
1104 * abort any previous channel switch if still in process
1105 */
Don Fry83626402012-03-07 09:52:37 -08001106 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001107 (priv->switch_channel != ctx->staging.channel)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001108 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001109 le16_to_cpu(priv->switch_channel));
Johannes Berg2295c662010-10-23 09:15:41 -07001110 iwl_chswitch_done(priv, false);
1111 }
1112
1113 /*
1114 * If we don't need to send a full RXON, we can use
1115 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1116 * and other flags for the current radio configuration.
1117 */
1118 if (!iwl_full_rxon_required(priv, ctx)) {
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -07001119 ret = iwlagn_send_rxon_assoc(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001120 if (ret) {
1121 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1122 return ret;
1123 }
1124
1125 memcpy(active, &ctx->staging, sizeof(*active));
Wey-Yi Guy891db882011-05-27 08:40:24 -07001126 /*
1127 * We do not commit tx power settings while channel changing,
1128 * do it now if after settings changed.
1129 */
1130 iwl_set_tx_power(priv, priv->tx_power_next, false);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -07001131
1132 /* make sure we are in the right PS state */
1133 iwl_power_update_mode(priv, true);
1134
Johannes Berg2295c662010-10-23 09:15:41 -07001135 return 0;
1136 }
1137
Johannes Berg65de7e82012-04-17 07:36:30 -07001138 iwl_set_rxon_hwcrypto(priv, ctx, !iwlwifi_mod_params.sw_crypto);
Johannes Berg2295c662010-10-23 09:15:41 -07001139
1140 IWL_DEBUG_INFO(priv,
1141 "Going to commit RXON\n"
1142 " * with%s RXON_FILTER_ASSOC_MSK\n"
1143 " * channel = %d\n"
1144 " * bssid = %pM\n",
1145 (new_assoc ? "" : "out"),
1146 le16_to_cpu(ctx->staging.channel),
1147 ctx->staging.bssid_addr);
1148
1149 /*
Johannes Berg52d980c2010-11-10 09:56:45 -08001150 * Always clear associated first, but with the correct config.
1151 * This is required as for example station addition for the
1152 * AP station must be done after the BSSID is set to correctly
1153 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -07001154 */
Wey-Yi Guy3083d032011-05-06 17:06:44 -07001155 ret = iwlagn_rxon_disconn(priv, ctx);
1156 if (ret)
1157 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -07001158
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001159 ret = iwlagn_set_pan_params(priv);
1160 if (ret)
1161 return ret;
Johannes Berg2b9253d2011-05-27 08:40:26 -07001162
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001163 if (new_assoc)
1164 return iwlagn_rxon_connect(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001165
1166 return 0;
1167}
1168
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001169void iwlagn_config_ht40(struct ieee80211_conf *conf,
1170 struct iwl_rxon_context *ctx)
1171{
1172 if (conf_is_ht40_minus(conf)) {
1173 ctx->ht.extension_chan_offset =
1174 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1175 ctx->ht.is_40mhz = true;
1176 } else if (conf_is_ht40_plus(conf)) {
1177 ctx->ht.extension_chan_offset =
1178 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1179 ctx->ht.is_40mhz = true;
1180 } else {
1181 ctx->ht.extension_chan_offset =
1182 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1183 ctx->ht.is_40mhz = false;
1184 }
1185}
1186
Johannes Berg2295c662010-10-23 09:15:41 -07001187int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1188{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001189 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001190 struct iwl_rxon_context *ctx;
1191 struct ieee80211_conf *conf = &hw->conf;
1192 struct ieee80211_channel *channel = conf->channel;
1193 const struct iwl_channel_info *ch_info;
1194 int ret = 0;
1195
Johannes Berg0ca24da2012-03-15 13:26:46 -07001196 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
Johannes Berg2295c662010-10-23 09:15:41 -07001197
Johannes Bergb1eea292012-03-06 13:30:42 -08001198 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001199
Don Fry83626402012-03-07 09:52:37 -08001200 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Johannes Berg2295c662010-10-23 09:15:41 -07001201 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1202 goto out;
1203 }
1204
Don Fry83626402012-03-07 09:52:37 -08001205 if (!iwl_is_ready(priv)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001206 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1207 goto out;
1208 }
1209
1210 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1211 IEEE80211_CONF_CHANGE_CHANNEL)) {
1212 /* mac80211 uses static for non-HT which is what we want */
1213 priv->current_ht_config.smps = conf->smps_mode;
1214
1215 /*
1216 * Recalculate chain counts.
1217 *
1218 * If monitor mode is enabled then mac80211 will
1219 * set up the SM PS mode to OFF if an HT channel is
1220 * configured.
1221 */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001222 for_each_context(priv, ctx)
1223 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001224 }
1225
1226 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Johannes Berg2295c662010-10-23 09:15:41 -07001227 ch_info = iwl_get_channel_info(priv, channel->band,
1228 channel->hw_value);
1229 if (!is_channel_valid(ch_info)) {
1230 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1231 ret = -EINVAL;
1232 goto out;
1233 }
1234
Johannes Berg2295c662010-10-23 09:15:41 -07001235 for_each_context(priv, ctx) {
1236 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -07001237 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001238 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001239
Johannes Berg2295c662010-10-23 09:15:41 -07001240 if (ctx->ht.enabled) {
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001241 /* if HT40 is used, it should not change
1242 * after associated except channel switch */
Wey-Yi Guy78feb352011-12-14 08:22:36 -08001243 if (!ctx->ht.is_40mhz ||
1244 !iwl_is_associated_ctx(ctx))
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001245 iwlagn_config_ht40(conf, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001246 } else
1247 ctx->ht.is_40mhz = false;
1248
1249 /*
1250 * Default to no protection. Protection mode will
1251 * later be set from BSS config in iwl_ht_conf
1252 */
1253 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1254
1255 /* if we are switching from ht to 2.4 clear flags
1256 * from any ht related info since 2.4 does not
1257 * support ht */
1258 if (le16_to_cpu(ctx->staging.channel) !=
1259 channel->hw_value)
1260 ctx->staging.flags = 0;
1261
1262 iwl_set_rxon_channel(priv, channel, ctx);
1263 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1264
1265 iwl_set_flags_for_band(priv, ctx, channel->band,
1266 ctx->vif);
1267 }
1268
Johannes Berg2295c662010-10-23 09:15:41 -07001269 iwl_update_bcast_stations(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001270 }
1271
1272 if (changed & (IEEE80211_CONF_CHANGE_PS |
1273 IEEE80211_CONF_CHANGE_IDLE)) {
1274 ret = iwl_power_update_mode(priv, false);
1275 if (ret)
1276 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1277 }
1278
1279 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1280 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1281 priv->tx_power_user_lmt, conf->power_level);
1282
1283 iwl_set_tx_power(priv, conf->power_level, false);
1284 }
1285
1286 for_each_context(priv, ctx) {
1287 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1288 continue;
1289 iwlagn_commit_rxon(priv, ctx);
1290 }
1291 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001292 mutex_unlock(&priv->mutex);
Wey-Yi Guy770c72c2011-10-10 07:27:10 -07001293 IWL_DEBUG_MAC80211(priv, "leave\n");
1294
Johannes Berg2295c662010-10-23 09:15:41 -07001295 return ret;
1296}
1297
Johannes Bergaca86262012-05-14 09:08:50 +02001298static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1299 struct iwl_rxon_context *ctx,
1300 struct ieee80211_bss_conf *bss_conf)
Johannes Berg2295c662010-10-23 09:15:41 -07001301{
1302 struct ieee80211_vif *vif = ctx->vif;
1303 struct iwl_rxon_context *tmp;
1304 struct ieee80211_sta *sta;
1305 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +01001306 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -07001307 bool need_multiple;
1308
Johannes Bergb1eea292012-03-06 13:30:42 -08001309 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001310
1311 switch (vif->type) {
1312 case NL80211_IFTYPE_STATION:
1313 rcu_read_lock();
1314 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +01001315 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -07001316 /*
1317 * If at all, this can only happen through a race
1318 * when the AP disconnects us while we're still
1319 * setting up the connection, in that case mac80211
1320 * will soon tell us about that.
1321 */
1322 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +01001323 rcu_read_unlock();
1324 break;
Johannes Berg2295c662010-10-23 09:15:41 -07001325 }
Johannes Berg850bedc2011-02-25 12:24:11 +01001326
1327 ht_cap = &sta->ht_cap;
1328
1329 need_multiple = true;
1330
1331 /*
1332 * If the peer advertises no support for receiving 2 and 3
1333 * stream MCS rates, it can't be transmitting them either.
1334 */
1335 if (ht_cap->mcs.rx_mask[1] == 0 &&
1336 ht_cap->mcs.rx_mask[2] == 0) {
1337 need_multiple = false;
1338 } else if (!(ht_cap->mcs.tx_params &
1339 IEEE80211_HT_MCS_TX_DEFINED)) {
1340 /* If it can't TX MCS at all ... */
1341 need_multiple = false;
1342 } else if (ht_cap->mcs.tx_params &
1343 IEEE80211_HT_MCS_TX_RX_DIFF) {
1344 int maxstreams;
1345
1346 /*
1347 * But if it can receive them, it might still not
1348 * be able to transmit them, which is what we need
1349 * to check here -- so check the number of streams
1350 * it advertises for TX (if different from RX).
1351 */
1352
1353 maxstreams = (ht_cap->mcs.tx_params &
1354 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1355 maxstreams >>=
1356 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1357 maxstreams += 1;
1358
1359 if (maxstreams <= 1)
1360 need_multiple = false;
1361 }
1362
Johannes Berg2295c662010-10-23 09:15:41 -07001363 rcu_read_unlock();
1364 break;
1365 case NL80211_IFTYPE_ADHOC:
1366 /* currently */
1367 need_multiple = false;
1368 break;
1369 default:
1370 /* only AP really */
1371 need_multiple = true;
1372 break;
1373 }
1374
1375 ctx->ht_need_multiple_chains = need_multiple;
1376
1377 if (!need_multiple) {
1378 /* check all contexts */
1379 for_each_context(priv, tmp) {
1380 if (!tmp->vif)
1381 continue;
1382 if (tmp->ht_need_multiple_chains) {
1383 need_multiple = true;
1384 break;
1385 }
1386 }
1387 }
1388
1389 ht_conf->single_chain_sufficient = !need_multiple;
1390}
1391
Johannes Bergaca86262012-05-14 09:08:50 +02001392static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
Don Fry5c3d29f2011-07-08 08:46:29 -07001393{
1394 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1395 int ret;
1396
Dor Shaishbfb45f52012-03-26 08:20:55 -07001397 if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED))
1398 return;
1399
Don Fry5c3d29f2011-07-08 08:46:29 -07001400 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1401 iwl_is_any_associated(priv)) {
1402 struct iwl_calib_chain_noise_reset_cmd cmd;
1403
1404 /* clear data for chain noise calibration algorithm */
1405 data->chain_noise_a = 0;
1406 data->chain_noise_b = 0;
1407 data->chain_noise_c = 0;
1408 data->chain_signal_a = 0;
1409 data->chain_signal_b = 0;
1410 data->chain_signal_c = 0;
1411 data->beacon_count = 0;
1412
1413 memset(&cmd, 0, sizeof(cmd));
1414 iwl_set_calib_hdr(&cmd.hdr,
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001415 priv->phy_calib_chain_noise_reset_cmd);
Johannes Berge10a0532012-03-06 13:30:39 -08001416 ret = iwl_dvm_send_cmd_pdu(priv,
Don Fry5c3d29f2011-07-08 08:46:29 -07001417 REPLY_PHY_CALIBRATION_CMD,
1418 CMD_SYNC, sizeof(cmd), &cmd);
1419 if (ret)
1420 IWL_ERR(priv,
1421 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1422 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1423 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1424 }
1425}
1426
Johannes Berg2295c662010-10-23 09:15:41 -07001427void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1428 struct ieee80211_vif *vif,
1429 struct ieee80211_bss_conf *bss_conf,
1430 u32 changes)
1431{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001432 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001433 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1434 int ret;
1435 bool force = false;
1436
Johannes Bergb1eea292012-03-06 13:30:42 -08001437 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001438
Don Fry83626402012-03-07 09:52:37 -08001439 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -08001440 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001441 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -08001442 return;
1443 }
1444
1445 if (unlikely(!ctx->vif)) {
1446 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001447 mutex_unlock(&priv->mutex);
Johannes Berg893654d2010-11-10 18:25:47 -08001448 return;
1449 }
1450
Johannes Berg2295c662010-10-23 09:15:41 -07001451 if (changes & BSS_CHANGED_BEACON_INT)
1452 force = true;
1453
1454 if (changes & BSS_CHANGED_QOS) {
1455 ctx->qos_data.qos_active = bss_conf->qos;
1456 iwlagn_update_qos(priv, ctx);
1457 }
1458
1459 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1460 if (vif->bss_conf.use_short_preamble)
1461 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1462 else
1463 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1464
1465 if (changes & BSS_CHANGED_ASSOC) {
1466 if (bss_conf->assoc) {
Johannes Berge9ac0742012-03-13 14:29:30 +01001467 priv->timestamp = bss_conf->last_tsf;
Johannes Berg2295c662010-10-23 09:15:41 -07001468 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1469 } else {
Garen Tamrazian68b99312011-03-30 02:29:32 -07001470 /*
1471 * If we disassociate while there are pending
1472 * frames, just wake up the queues and let the
1473 * frames "escape" ... This shouldn't really
1474 * be happening to start with, but we should
1475 * not get stuck in this case either since it
1476 * can happen if userspace gets confused.
1477 */
Johannes Berge755f882012-03-07 09:52:16 -08001478 iwlagn_lift_passive_no_rx(priv);
1479
Johannes Berg2295c662010-10-23 09:15:41 -07001480 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001481
1482 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1483 priv->have_rekey_data = false;
Johannes Berg2295c662010-10-23 09:15:41 -07001484 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001485
1486 iwlagn_bt_coex_rssi_monitor(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001487 }
1488
1489 if (ctx->ht.enabled) {
1490 ctx->ht.protection = bss_conf->ht_operation_mode &
1491 IEEE80211_HT_OP_MODE_PROTECTION;
1492 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1493 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1494 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -08001495 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -07001496 }
1497
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001498 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001499
1500 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1501 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1502 else
1503 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1504
1505 if (bss_conf->use_cts_prot)
1506 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1507 else
1508 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1509
1510 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1511
1512 if (vif->type == NL80211_IFTYPE_AP ||
1513 vif->type == NL80211_IFTYPE_ADHOC) {
1514 if (vif->bss_conf.enable_beacon) {
1515 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1516 priv->beacon_ctx = ctx;
1517 } else {
1518 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1519 priv->beacon_ctx = NULL;
1520 }
1521 }
1522
Meenakshi Venkataraman758f5552012-02-08 12:04:41 -08001523 /*
1524 * If the ucode decides to do beacon filtering before
1525 * association, it will lose beacons that are needed
1526 * before sending frames out on passive channels. This
1527 * causes association failures on those channels. Enable
1528 * receiving beacons in such cases.
1529 */
1530
1531 if (vif->type == NL80211_IFTYPE_STATION) {
1532 if (!bss_conf->assoc)
1533 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1534 else
1535 ctx->staging.filter_flags &=
1536 ~RXON_FILTER_BCON_AWARE_MSK;
1537 }
1538
Johannes Berg2295c662010-10-23 09:15:41 -07001539 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1540 iwlagn_commit_rxon(priv, ctx);
1541
Johannes Berg8da8e622010-11-10 09:56:46 -08001542 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1543 /*
1544 * The chain noise calibration will enable PM upon
1545 * completion. If calibration has already been run
1546 * then we need to enable power management here.
1547 */
1548 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1549 iwl_power_update_mode(priv, false);
1550
1551 /* Enable RX differential gain and sensitivity calibrations */
Dor Shaishbfb45f52012-03-26 08:20:55 -07001552 iwlagn_chain_noise_reset(priv);
Johannes Berg8da8e622010-11-10 09:56:46 -08001553 priv->start_calib = 1;
1554 }
1555
Johannes Berg2295c662010-10-23 09:15:41 -07001556 if (changes & BSS_CHANGED_IBSS) {
1557 ret = iwlagn_manage_ibss_station(priv, vif,
1558 bss_conf->ibss_joined);
1559 if (ret)
1560 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1561 bss_conf->ibss_joined ? "add" : "remove",
1562 bss_conf->bssid);
1563 }
1564
Johannes Bergbd50a8ab2010-10-23 09:15:42 -07001565 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1566 priv->beacon_ctx) {
1567 if (iwlagn_update_beacon(priv, vif))
1568 IWL_ERR(priv, "Error sending IBSS beacon\n");
1569 }
1570
Johannes Bergb1eea292012-03-06 13:30:42 -08001571 mutex_unlock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001572}
Johannes Bergae79d232010-11-10 09:56:38 -08001573
1574void iwlagn_post_scan(struct iwl_priv *priv)
1575{
1576 struct iwl_rxon_context *ctx;
1577
1578 /*
Wey-Yi Guyc2b821d2011-06-03 07:54:14 -07001579 * We do not commit power settings while scan is pending,
1580 * do it now if the settings changed.
1581 */
1582 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1583 iwl_set_tx_power(priv, priv->tx_power_next, false);
1584
1585 /*
Johannes Bergae79d232010-11-10 09:56:38 -08001586 * Since setting the RXON may have been deferred while
1587 * performing the scan, fire one off if needed
1588 */
1589 for_each_context(priv, ctx)
1590 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1591 iwlagn_commit_rxon(priv, ctx);
1592
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001593 iwlagn_set_pan_params(priv);
Johannes Bergae79d232010-11-10 09:56:38 -08001594}