blob: 087e579854ab2f59486798e2c48f68aef63c477f [file] [log] [blame]
Johannes Berg2295c662010-10-23 09:15:41 -07001/******************************************************************************
2 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02003 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
Sara Sharon6eb031d2015-07-13 14:50:47 +03004 * Copyright(c) 2015 Intel Deutschland GmbH
Johannes Berg2295c662010-10-23 09:15:41 -07005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 *
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
21 *
22 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020023 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg2295c662010-10-23 09:15:41 -070024 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *
26 *****************************************************************************/
27
Meenakshi Venkataraman55620922012-03-15 13:27:02 -070028#include <linux/etherdevice.h>
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070029#include "iwl-trans.h"
Johannes Berg65de7e82012-04-17 07:36:30 -070030#include "iwl-modparams.h"
Johannes Berg1023fdc2012-05-15 12:16:34 +020031#include "dev.h"
32#include "agn.h"
33#include "calib.h"
Johannes Berg2295c662010-10-23 09:15:41 -070034
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070035/*
36 * initialize rxon structure with default values from eeprom
37 */
38void iwl_connection_init_rx_config(struct iwl_priv *priv,
39 struct iwl_rxon_context *ctx)
40{
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070041 memset(&ctx->staging, 0, sizeof(ctx->staging));
42
43 if (!ctx->vif) {
44 ctx->staging.dev_type = ctx->unused_devtype;
45 } else
46 switch (ctx->vif->type) {
47 case NL80211_IFTYPE_AP:
48 ctx->staging.dev_type = ctx->ap_devtype;
49 break;
50
51 case NL80211_IFTYPE_STATION:
52 ctx->staging.dev_type = ctx->station_devtype;
53 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
54 break;
55
56 case NL80211_IFTYPE_ADHOC:
57 ctx->staging.dev_type = ctx->ibss_devtype;
58 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
59 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
60 RXON_FILTER_ACCEPT_GRP_MSK;
61 break;
62
Johannes Berg57897722012-05-11 10:53:18 +020063 case NL80211_IFTYPE_MONITOR:
64 ctx->staging.dev_type = RXON_DEV_TYPE_SNIFFER;
65 break;
66
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070067 default:
68 IWL_ERR(priv, "Unsupported interface type %d\n",
69 ctx->vif->type);
70 break;
71 }
72
73#if 0
74 /* TODO: Figure out when short_preamble would be set and cache from
75 * that */
76 if (!hw_to_local(priv->hw)->short_preamble)
77 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
78 else
79 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
80#endif
81
Karl Beldan675a0b02013-03-25 16:26:57 +010082 ctx->staging.channel =
83 cpu_to_le16(priv->hw->conf.chandef.chan->hw_value);
84 priv->band = priv->hw->conf.chandef.chan->band;
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070085
86 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
87
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070088 /* clear both MIX and PURE40 mode flag */
89 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
90 RXON_FLG_CHANNEL_MODE_PURE_40);
91 if (ctx->vif)
92 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
93
94 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
95 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
96 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
97}
98
Johannes Berg2295c662010-10-23 09:15:41 -070099static int iwlagn_disable_bss(struct iwl_priv *priv,
100 struct iwl_rxon_context *ctx,
101 struct iwl_rxon_cmd *send)
102{
103 __le32 old_filter = send->filter_flags;
104 int ret;
105
106 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800107 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300108 0, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700109
110 send->filter_flags = old_filter;
111
112 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800113 IWL_DEBUG_QUIET_RFKILL(priv,
114 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
Johannes Berg2295c662010-10-23 09:15:41 -0700115
116 return ret;
117}
118
119static int iwlagn_disable_pan(struct iwl_priv *priv,
120 struct iwl_rxon_context *ctx,
121 struct iwl_rxon_cmd *send)
122{
Johannes Berg311dce72011-01-04 16:22:01 -0800123 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -0700124 __le32 old_filter = send->filter_flags;
125 u8 old_dev_type = send->dev_type;
126 int ret;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300127 static const u16 deactivate_cmd[] = {
Johannes Bergdb662d42012-03-15 13:26:44 -0700128 REPLY_WIPAN_DEACTIVATION_COMPLETE
129 };
Johannes Berg2295c662010-10-23 09:15:41 -0700130
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800131 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
Johannes Bergdb662d42012-03-15 13:26:44 -0700132 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800133 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -0800134
Johannes Berg2295c662010-10-23 09:15:41 -0700135 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
136 send->dev_type = RXON_DEV_TYPE_P2P;
Johannes Berge10a0532012-03-06 13:30:39 -0800137 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300138 0, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700139
140 send->filter_flags = old_filter;
141 send->dev_type = old_dev_type;
142
Johannes Berg311dce72011-01-04 16:22:01 -0800143 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -0700144 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800145 iwl_remove_notification(&priv->notif_wait, &disable_wait);
Johannes Berg311dce72011-01-04 16:22:01 -0800146 } else {
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800147 ret = iwl_wait_notification(&priv->notif_wait,
148 &disable_wait, HZ);
Johannes Berga8674a12011-04-13 03:14:48 -0700149 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -0800150 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
151 }
Johannes Berg2295c662010-10-23 09:15:41 -0700152
153 return ret;
154}
155
Johannes Berg2b9253d2011-05-27 08:40:26 -0700156static int iwlagn_disconn_pan(struct iwl_priv *priv,
157 struct iwl_rxon_context *ctx,
158 struct iwl_rxon_cmd *send)
159{
160 __le32 old_filter = send->filter_flags;
161 int ret;
162
163 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300164 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, 0,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700165 sizeof(*send), send);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700166
167 send->filter_flags = old_filter;
168
169 return ret;
170}
171
Johannes Bergaca86262012-05-14 09:08:50 +0200172static void iwlagn_update_qos(struct iwl_priv *priv,
173 struct iwl_rxon_context *ctx)
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800174{
175 int ret;
176
177 if (!ctx->is_active)
178 return;
179
180 ctx->qos_data.def_qos_parm.qos_flags = 0;
181
182 if (ctx->qos_data.qos_active)
183 ctx->qos_data.def_qos_parm.qos_flags |=
184 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
185
186 if (ctx->ht.enabled)
187 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
188
Emmanuel Grumbach0dcf50c2011-11-10 06:55:23 -0800189 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800190 ctx->qos_data.qos_active,
191 ctx->qos_data.def_qos_parm.qos_flags);
192
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300193 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, 0,
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800194 sizeof(struct iwl_qosparam_cmd),
195 &ctx->qos_data.def_qos_parm);
196 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800197 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800198}
199
Johannes Bergaca86262012-05-14 09:08:50 +0200200static int iwlagn_update_beacon(struct iwl_priv *priv,
201 struct ieee80211_vif *vif)
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700202{
Johannes Bergb1eea292012-03-06 13:30:42 -0800203 lockdep_assert_held(&priv->mutex);
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700204
205 dev_kfree_skb(priv->beacon_skb);
206 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
207 if (!priv->beacon_skb)
208 return -ENOMEM;
209 return iwlagn_send_beacon_cmd(priv);
210}
211
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700212static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
Johannes Bergaca86262012-05-14 09:08:50 +0200213 struct iwl_rxon_context *ctx)
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700214{
215 int ret = 0;
Wey-Yi Guy89e746b2011-04-19 16:52:58 -0700216 struct iwl_rxon_assoc_cmd rxon_assoc;
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700217 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
218 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
219
220 if ((rxon1->flags == rxon2->flags) &&
221 (rxon1->filter_flags == rxon2->filter_flags) &&
222 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
223 (rxon1->ofdm_ht_single_stream_basic_rates ==
224 rxon2->ofdm_ht_single_stream_basic_rates) &&
225 (rxon1->ofdm_ht_dual_stream_basic_rates ==
226 rxon2->ofdm_ht_dual_stream_basic_rates) &&
227 (rxon1->ofdm_ht_triple_stream_basic_rates ==
228 rxon2->ofdm_ht_triple_stream_basic_rates) &&
229 (rxon1->acquisition_data == rxon2->acquisition_data) &&
230 (rxon1->rx_chain == rxon2->rx_chain) &&
231 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
232 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
233 return 0;
234 }
235
236 rxon_assoc.flags = ctx->staging.flags;
237 rxon_assoc.filter_flags = ctx->staging.filter_flags;
238 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
239 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
240 rxon_assoc.reserved1 = 0;
241 rxon_assoc.reserved2 = 0;
242 rxon_assoc.reserved3 = 0;
243 rxon_assoc.ofdm_ht_single_stream_basic_rates =
244 ctx->staging.ofdm_ht_single_stream_basic_rates;
245 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
246 ctx->staging.ofdm_ht_dual_stream_basic_rates;
247 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
248 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
249 ctx->staging.ofdm_ht_triple_stream_basic_rates;
250 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
251
Johannes Berge10a0532012-03-06 13:30:39 -0800252 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700253 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700254 return ret;
255}
256
Meenakshi Venkataramandff96c12012-03-15 13:26:59 -0700257static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
258{
259 u16 new_val;
260 u16 beacon_factor;
261
262 /*
263 * If mac80211 hasn't given us a beacon interval, program
264 * the default into the device (not checking this here
265 * would cause the adjustment below to return the maximum
266 * value, which may break PAN.)
267 */
268 if (!beacon_val)
269 return DEFAULT_BEACON_INTERVAL;
270
271 /*
272 * If the beacon interval we obtained from the peer
273 * is too large, we'll have to wake up more often
274 * (and in IBSS case, we'll beacon too much)
275 *
276 * For example, if max_beacon_val is 4096, and the
277 * requested beacon interval is 7000, we'll have to
278 * use 3500 to be able to wake up on the beacons.
279 *
280 * This could badly influence beacon detection stats.
281 */
282
283 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
284 new_val = beacon_val / beacon_factor;
285
286 if (!new_val)
287 new_val = max_beacon_val;
288
289 return new_val;
290}
291
292static int iwl_send_rxon_timing(struct iwl_priv *priv,
293 struct iwl_rxon_context *ctx)
294{
295 u64 tsf;
296 s32 interval_tm, rem;
297 struct ieee80211_conf *conf = NULL;
298 u16 beacon_int;
299 struct ieee80211_vif *vif = ctx->vif;
300
301 conf = &priv->hw->conf;
302
303 lockdep_assert_held(&priv->mutex);
304
305 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
306
307 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
308 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
309
310 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
311
312 /*
313 * TODO: For IBSS we need to get atim_window from mac80211,
314 * for now just always use 0
315 */
316 ctx->timing.atim_window = 0;
317
318 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
319 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
320 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
321 priv->contexts[IWL_RXON_CTX_BSS].vif &&
322 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
323 ctx->timing.beacon_interval =
324 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
325 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
326 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
327 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
328 priv->contexts[IWL_RXON_CTX_PAN].vif &&
329 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
330 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
331 !ctx->vif->bss_conf.beacon_int)) {
332 ctx->timing.beacon_interval =
333 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
334 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
335 } else {
336 beacon_int = iwl_adjust_beacon_interval(beacon_int,
337 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
338 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
339 }
340
341 ctx->beacon_int = beacon_int;
342
343 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
344 interval_tm = beacon_int * TIME_UNIT;
345 rem = do_div(tsf, interval_tm);
346 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
347
348 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
349
350 IWL_DEBUG_ASSOC(priv,
351 "beacon interval %d beacon timer %d beacon tim %d\n",
352 le16_to_cpu(ctx->timing.beacon_interval),
353 le32_to_cpu(ctx->timing.beacon_init_val),
354 le16_to_cpu(ctx->timing.atim_window));
355
356 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300357 0, sizeof(ctx->timing), &ctx->timing);
Meenakshi Venkataramandff96c12012-03-15 13:26:59 -0700358}
359
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700360static int iwlagn_rxon_disconn(struct iwl_priv *priv,
361 struct iwl_rxon_context *ctx)
362{
363 int ret;
364 struct iwl_rxon_cmd *active = (void *)&ctx->active;
365
Johannes Berg2b9253d2011-05-27 08:40:26 -0700366 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700367 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700368 } else {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700369 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700370 if (ret)
371 return ret;
372 if (ctx->vif) {
373 ret = iwl_send_rxon_timing(priv, ctx);
374 if (ret) {
375 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
376 return ret;
377 }
378 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
379 }
380 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700381 if (ret)
382 return ret;
383
384 /*
385 * Un-assoc RXON clears the station table and WEP
386 * keys, so we have to restore those afterwards.
387 */
388 iwl_clear_ucode_stations(priv, ctx);
Johannes Bergf775aa06d2011-06-22 06:34:09 -0700389 /* update -- might need P2P now */
390 iwl_update_bcast_station(priv, ctx);
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700391 iwl_restore_stations(priv, ctx);
392 ret = iwl_restore_default_wep_keys(priv, ctx);
393 if (ret) {
394 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
395 return ret;
396 }
397
398 memcpy(active, &ctx->staging, sizeof(*active));
399 return 0;
400}
401
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700402static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
403{
404 int ret;
405 s8 prev_tx_power;
406 bool defer;
407 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
408
Dor Shaishbfb45f52012-03-26 08:20:55 -0700409 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
410 return 0;
411
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700412 lockdep_assert_held(&priv->mutex);
413
414 if (priv->tx_power_user_lmt == tx_power && !force)
415 return 0;
416
417 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
418 IWL_WARN(priv,
419 "Requested user TXPOWER %d below lower limit %d.\n",
420 tx_power,
421 IWLAGN_TX_POWER_TARGET_POWER_MIN);
422 return -EINVAL;
423 }
424
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200425 if (tx_power > DIV_ROUND_UP(priv->nvm_data->max_tx_pwr_half_dbm, 2)) {
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700426 IWL_WARN(priv,
427 "Requested user TXPOWER %d above upper limit %d.\n",
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200428 tx_power, priv->nvm_data->max_tx_pwr_half_dbm);
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700429 return -EINVAL;
430 }
431
432 if (!iwl_is_ready_rf(priv))
433 return -EIO;
434
435 /* scan complete and commit_rxon use tx_power_next value,
436 * it always need to be updated for newest request */
437 priv->tx_power_next = tx_power;
438
439 /* do not set tx power when scanning or channel changing */
440 defer = test_bit(STATUS_SCANNING, &priv->status) ||
441 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
442 if (defer && !force) {
443 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
444 return 0;
445 }
446
447 prev_tx_power = priv->tx_power_user_lmt;
448 priv->tx_power_user_lmt = tx_power;
449
450 ret = iwlagn_send_tx_power(priv);
451
452 /* if fail to set tx_power, restore the orig. tx power */
453 if (ret) {
454 priv->tx_power_user_lmt = prev_tx_power;
455 priv->tx_power_next = prev_tx_power;
456 }
457 return ret;
458}
459
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700460static int iwlagn_rxon_connect(struct iwl_priv *priv,
461 struct iwl_rxon_context *ctx)
462{
463 int ret;
464 struct iwl_rxon_cmd *active = (void *)&ctx->active;
465
466 /* RXON timing must be before associated RXON */
Johannes Berg2b9253d2011-05-27 08:40:26 -0700467 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
468 ret = iwl_send_rxon_timing(priv, ctx);
469 if (ret) {
470 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
471 return ret;
472 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700473 }
474 /* QoS info may be cleared by previous un-assoc RXON */
475 iwlagn_update_qos(priv, ctx);
476
477 /*
478 * We'll run into this code path when beaconing is
479 * enabled, but then we also need to send the beacon
480 * to the device.
481 */
482 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
483 ret = iwlagn_update_beacon(priv, ctx->vif);
484 if (ret) {
485 IWL_ERR(priv,
486 "Error sending required beacon (%d)!\n",
487 ret);
488 return ret;
489 }
490 }
491
492 priv->start_calib = 0;
493 /*
494 * Apply the new configuration.
495 *
496 * Associated RXON doesn't clear the station table in uCode,
497 * so we don't need to restore stations etc. after this.
498 */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300499 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, 0,
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700500 sizeof(struct iwl_rxon_cmd), &ctx->staging);
501 if (ret) {
502 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
503 return ret;
504 }
505 memcpy(active, &ctx->staging, sizeof(*active));
506
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700507 /* IBSS beacon needs to be sent after setting assoc */
508 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
509 if (iwlagn_update_beacon(priv, ctx->vif))
510 IWL_ERR(priv, "Error sending IBSS beacon\n");
511 iwl_init_sensitivity(priv);
512
513 /*
514 * If we issue a new RXON command which required a tune then
515 * we must send a new TXPOWER command or we won't be able to
516 * Tx any frames.
517 *
518 * It's expected we set power here if channel is changing.
519 */
520 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
521 if (ret) {
522 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
523 return ret;
524 }
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700525
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700526 return 0;
527}
528
Wey-Yi Guye505c432011-07-07 08:27:41 -0700529int iwlagn_set_pan_params(struct iwl_priv *priv)
530{
531 struct iwl_wipan_params_cmd cmd;
532 struct iwl_rxon_context *ctx_bss, *ctx_pan;
533 int slot0 = 300, slot1 = 0;
534 int ret;
535
Johannes Berga18f61b2012-03-15 13:26:53 -0700536 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
Wey-Yi Guye505c432011-07-07 08:27:41 -0700537 return 0;
538
539 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
540
Johannes Bergb1eea292012-03-06 13:30:42 -0800541 lockdep_assert_held(&priv->mutex);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700542
543 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
544 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
545
546 /*
547 * If the PAN context is inactive, then we don't need
548 * to update the PAN parameters, the last thing we'll
549 * have done before it goes inactive is making the PAN
550 * parameters be WLAN-only.
551 */
552 if (!ctx_pan->is_active)
553 return 0;
554
555 memset(&cmd, 0, sizeof(cmd));
556
557 /* only 2 slots are currently allowed */
558 cmd.num_slots = 2;
559
560 cmd.slots[0].type = 0; /* BSS */
561 cmd.slots[1].type = 1; /* PAN */
562
Johannes Bergda4f87f2013-07-01 13:48:56 +0200563 if (ctx_bss->vif && ctx_pan->vif) {
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700564 int bcnint = ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700565 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
566
567 /* should be set, but seems unused?? */
568 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
569
570 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
571 bcnint &&
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700572 bcnint != ctx_bss->beacon_int) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700573 IWL_ERR(priv,
574 "beacon intervals don't match (%d, %d)\n",
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700575 ctx_bss->beacon_int, ctx_pan->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700576 } else
577 bcnint = max_t(int, bcnint,
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700578 ctx_bss->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700579 if (!bcnint)
580 bcnint = DEFAULT_BEACON_INTERVAL;
581 slot0 = bcnint / 2;
582 slot1 = bcnint - slot0;
583
Don Fry83626402012-03-07 09:52:37 -0800584 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
Wey-Yi Guye505c432011-07-07 08:27:41 -0700585 (!ctx_bss->vif->bss_conf.idle &&
586 !ctx_bss->vif->bss_conf.assoc)) {
587 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
588 slot1 = IWL_MIN_SLOT_TIME;
589 } else if (!ctx_pan->vif->bss_conf.idle &&
590 !ctx_pan->vif->bss_conf.assoc) {
Johannes Berg325a7dd2011-09-22 15:14:55 -0700591 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700592 slot0 = IWL_MIN_SLOT_TIME;
593 }
594 } else if (ctx_pan->vif) {
595 slot0 = 0;
596 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700597 ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700598 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
599
Don Fry83626402012-03-07 09:52:37 -0800600 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700601 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
602 slot1 = IWL_MIN_SLOT_TIME;
603 }
604 }
605
606 cmd.slots[0].width = cpu_to_le16(slot0);
607 cmd.slots[1].width = cpu_to_le16(slot1);
608
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300609 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, 0,
Wey-Yi Guye505c432011-07-07 08:27:41 -0700610 sizeof(cmd), &cmd);
611 if (ret)
612 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
613
614 return ret;
615}
616
Meenakshi Venkataramandd641732012-03-13 16:25:38 -0700617static void _iwl_set_rxon_ht(struct iwl_priv *priv,
618 struct iwl_ht_config *ht_conf,
619 struct iwl_rxon_context *ctx)
620{
621 struct iwl_rxon_cmd *rxon = &ctx->staging;
622
623 if (!ctx->ht.enabled) {
624 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
625 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
626 RXON_FLG_HT40_PROT_MSK |
627 RXON_FLG_HT_PROT_MSK);
628 return;
629 }
630
631 /* FIXME: if the definition of ht.protection changed, the "translation"
632 * will be needed for rxon->flags
633 */
634 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
635 RXON_FLG_HT_OPERATING_MODE_POS);
636
637 /* Set up channel bandwidth:
638 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
639 /* clear the HT channel mode before set the mode */
640 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
641 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
642 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
643 /* pure ht40 */
644 if (ctx->ht.protection ==
645 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
646 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
647 /*
648 * Note: control channel is opposite of extension
649 * channel
650 */
651 switch (ctx->ht.extension_chan_offset) {
652 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
653 rxon->flags &=
654 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
655 break;
656 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
657 rxon->flags |=
658 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
659 break;
660 }
661 } else {
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 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
671 break;
672 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
673 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
674 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
675 break;
676 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
677 default:
678 /*
679 * channel location only valid if in Mixed
680 * mode
681 */
682 IWL_ERR(priv,
683 "invalid extension channel offset\n");
684 break;
685 }
686 }
687 } else {
688 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
689 }
690
691 iwlagn_set_rxon_chain(priv, ctx);
692
693 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
694 "extension channel offset 0x%x\n",
695 le32_to_cpu(rxon->flags), ctx->ht.protection,
696 ctx->ht.extension_chan_offset);
697}
698
699void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
700{
701 struct iwl_rxon_context *ctx;
702
703 for_each_context(priv, ctx)
704 _iwl_set_rxon_ht(priv, ht_conf, ctx);
705}
706
Meenakshi Venkataramanfedfa872012-03-13 16:31:34 -0700707/**
708 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
709 * @ch: requested channel as a pointer to struct ieee80211_channel
710
711 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
712 * in the staging RXON flag structure based on the ch->band
713 */
714void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
715 struct iwl_rxon_context *ctx)
716{
Johannes Berg57fbcce2016-04-12 15:56:15 +0200717 enum nl80211_band band = ch->band;
Meenakshi Venkataramanfedfa872012-03-13 16:31:34 -0700718 u16 channel = ch->hw_value;
719
720 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
721 (priv->band == band))
722 return;
723
724 ctx->staging.channel = cpu_to_le16(channel);
Johannes Berg57fbcce2016-04-12 15:56:15 +0200725 if (band == NL80211_BAND_5GHZ)
Meenakshi Venkataramanfedfa872012-03-13 16:31:34 -0700726 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
727 else
728 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
729
730 priv->band = band;
731
732 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
733
734}
735
Meenakshi Venkataraman50319f72012-03-13 16:45:00 -0700736void iwl_set_flags_for_band(struct iwl_priv *priv,
737 struct iwl_rxon_context *ctx,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200738 enum nl80211_band band,
Meenakshi Venkataraman50319f72012-03-13 16:45:00 -0700739 struct ieee80211_vif *vif)
740{
Johannes Berg57fbcce2016-04-12 15:56:15 +0200741 if (band == NL80211_BAND_5GHZ) {
Meenakshi Venkataraman50319f72012-03-13 16:45:00 -0700742 ctx->staging.flags &=
743 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
744 | RXON_FLG_CCK_MSK);
745 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
746 } else {
747 /* Copied from iwl_post_associate() */
748 if (vif && vif->bss_conf.use_short_slot)
749 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
750 else
751 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
752
753 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
754 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
755 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
756 }
757}
758
Meenakshi Venkataraman354a4532012-03-15 13:27:00 -0700759static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
760 struct iwl_rxon_context *ctx, int hw_decrypt)
761{
762 struct iwl_rxon_cmd *rxon = &ctx->staging;
763
764 if (hw_decrypt)
765 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
766 else
767 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
768
769}
770
Meenakshi Venkataraman8931b572012-03-15 13:27:01 -0700771/* validate RXON structure is valid */
772static int iwl_check_rxon_cmd(struct iwl_priv *priv,
773 struct iwl_rxon_context *ctx)
774{
775 struct iwl_rxon_cmd *rxon = &ctx->staging;
776 u32 errors = 0;
777
778 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
779 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
780 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
781 errors |= BIT(0);
782 }
783 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
784 IWL_WARN(priv, "check 2.4G: wrong radar\n");
785 errors |= BIT(1);
786 }
787 } else {
788 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
789 IWL_WARN(priv, "check 5.2G: not short slot!\n");
790 errors |= BIT(2);
791 }
792 if (rxon->flags & RXON_FLG_CCK_MSK) {
793 IWL_WARN(priv, "check 5.2G: CCK!\n");
794 errors |= BIT(3);
795 }
796 }
797 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
798 IWL_WARN(priv, "mac/bssid mcast!\n");
799 errors |= BIT(4);
800 }
801
802 /* make sure basic rates 6Mbps and 1Mbps are supported */
803 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
804 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
805 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
806 errors |= BIT(5);
807 }
808
809 if (le16_to_cpu(rxon->assoc_id) > 2007) {
810 IWL_WARN(priv, "aid > 2007\n");
811 errors |= BIT(6);
812 }
813
814 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
815 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
816 IWL_WARN(priv, "CCK and short slot\n");
817 errors |= BIT(7);
818 }
819
820 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
821 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
Johannes Berg3c6acb62014-05-07 11:47:53 +0200822 IWL_WARN(priv, "CCK and auto detect\n");
Meenakshi Venkataraman8931b572012-03-15 13:27:01 -0700823 errors |= BIT(8);
824 }
825
826 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
827 RXON_FLG_TGG_PROTECT_MSK)) ==
828 RXON_FLG_TGG_PROTECT_MSK) {
829 IWL_WARN(priv, "TGg but no auto-detect\n");
830 errors |= BIT(9);
831 }
832
833 if (rxon->channel == 0) {
834 IWL_WARN(priv, "zero channel is invalid\n");
835 errors |= BIT(10);
836 }
837
838 WARN(errors, "Invalid RXON (%#x), channel %d",
839 errors, le16_to_cpu(rxon->channel));
840
841 return errors ? -EINVAL : 0;
842}
843
Johannes Berg2295c662010-10-23 09:15:41 -0700844/**
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700845 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
846 * @priv: staging_rxon is compared to active_rxon
847 *
848 * If the RXON structure is changing enough to require a new tune,
849 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
850 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
851 */
Johannes Bergaca86262012-05-14 09:08:50 +0200852static int iwl_full_rxon_required(struct iwl_priv *priv,
853 struct iwl_rxon_context *ctx)
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700854{
855 const struct iwl_rxon_cmd *staging = &ctx->staging;
856 const struct iwl_rxon_cmd *active = &ctx->active;
857
858#define CHK(cond) \
859 if ((cond)) { \
860 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
861 return 1; \
862 }
863
864#define CHK_NEQ(c1, c2) \
865 if ((c1) != (c2)) { \
866 IWL_DEBUG_INFO(priv, "need full RXON - " \
867 #c1 " != " #c2 " - %d != %d\n", \
868 (c1), (c2)); \
869 return 1; \
870 }
871
872 /* These items are only settable from the full RXON command */
873 CHK(!iwl_is_associated_ctx(ctx));
Joe Perches2e42e472012-05-09 17:17:46 +0000874 CHK(!ether_addr_equal(staging->bssid_addr, active->bssid_addr));
875 CHK(!ether_addr_equal(staging->node_addr, active->node_addr));
876 CHK(!ether_addr_equal(staging->wlap_bssid_addr,
877 active->wlap_bssid_addr));
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700878 CHK_NEQ(staging->dev_type, active->dev_type);
879 CHK_NEQ(staging->channel, active->channel);
880 CHK_NEQ(staging->air_propagation, active->air_propagation);
881 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
882 active->ofdm_ht_single_stream_basic_rates);
883 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
884 active->ofdm_ht_dual_stream_basic_rates);
885 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
886 active->ofdm_ht_triple_stream_basic_rates);
887 CHK_NEQ(staging->assoc_id, active->assoc_id);
888
889 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
890 * be updated with the RXON_ASSOC command -- however only some
891 * flag transitions are allowed using RXON_ASSOC */
892
893 /* Check if we are not switching bands */
894 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
895 active->flags & RXON_FLG_BAND_24G_MSK);
896
897 /* Check if we are switching association toggle */
898 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
899 active->filter_flags & RXON_FILTER_ASSOC_MSK);
900
901#undef CHK
902#undef CHK_NEQ
903
904 return 0;
905}
906
Meenakshi Venkataraman4d323ac2012-03-14 15:15:33 -0700907#ifdef CONFIG_IWLWIFI_DEBUG
908void iwl_print_rx_config_cmd(struct iwl_priv *priv,
909 enum iwl_rxon_context_id ctxid)
910{
911 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
912 struct iwl_rxon_cmd *rxon = &ctx->staging;
913
914 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
915 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
916 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
917 le16_to_cpu(rxon->channel));
918 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
919 le32_to_cpu(rxon->flags));
920 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
921 le32_to_cpu(rxon->filter_flags));
922 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
923 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
924 rxon->ofdm_basic_rates);
925 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
926 rxon->cck_basic_rates);
927 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
928 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
929 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
930 le16_to_cpu(rxon->assoc_id));
931}
932#endif
933
Johannes Berg9543c5f2012-03-08 09:37:53 +0100934static void iwl_calc_basic_rates(struct iwl_priv *priv,
935 struct iwl_rxon_context *ctx)
936{
937 int lowest_present_ofdm = 100;
938 int lowest_present_cck = 100;
939 u8 cck = 0;
940 u8 ofdm = 0;
941
942 if (ctx->vif) {
943 struct ieee80211_supported_band *sband;
944 unsigned long basic = ctx->vif->bss_conf.basic_rates;
945 int i;
946
Karl Beldan675a0b02013-03-25 16:26:57 +0100947 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
Johannes Berg9543c5f2012-03-08 09:37:53 +0100948
949 for_each_set_bit(i, &basic, BITS_PER_LONG) {
950 int hw = sband->bitrates[i].hw_value;
951 if (hw >= IWL_FIRST_OFDM_RATE) {
952 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
953 if (lowest_present_ofdm > hw)
954 lowest_present_ofdm = hw;
955 } else {
956 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
957
958 cck |= BIT(hw);
959 if (lowest_present_cck > hw)
960 lowest_present_cck = hw;
961 }
962 }
963 }
964
965 /*
966 * Now we've got the basic rates as bitmaps in the ofdm and cck
967 * variables. This isn't sufficient though, as there might not
968 * be all the right rates in the bitmap. E.g. if the only basic
969 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
970 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
971 *
972 * [...] a STA responding to a received frame shall transmit
973 * its Control Response frame [...] at the highest rate in the
974 * BSSBasicRateSet parameter that is less than or equal to the
975 * rate of the immediately previous frame in the frame exchange
976 * sequence ([...]) and that is of the same modulation class
977 * ([...]) as the received frame. If no rate contained in the
978 * BSSBasicRateSet parameter meets these conditions, then the
979 * control frame sent in response to a received frame shall be
980 * transmitted at the highest mandatory rate of the PHY that is
981 * less than or equal to the rate of the received frame, and
982 * that is of the same modulation class as the received frame.
983 *
984 * As a consequence, we need to add all mandatory rates that are
985 * lower than all of the basic rates to these bitmaps.
986 */
987
988 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
989 ofdm |= IWL_RATE_24M_MASK >> IWL_FIRST_OFDM_RATE;
990 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
991 ofdm |= IWL_RATE_12M_MASK >> IWL_FIRST_OFDM_RATE;
992 /* 6M already there or needed so always add */
993 ofdm |= IWL_RATE_6M_MASK >> IWL_FIRST_OFDM_RATE;
994
995 /*
996 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
997 * Note, however:
998 * - if no CCK rates are basic, it must be ERP since there must
999 * be some basic rates at all, so they're OFDM => ERP PHY
1000 * (or we're in 5 GHz, and the cck bitmap will never be used)
1001 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
1002 * - if 5.5M is basic, 1M and 2M are mandatory
1003 * - if 2M is basic, 1M is mandatory
1004 * - if 1M is basic, that's the only valid ACK rate.
1005 * As a consequence, it's not as complicated as it sounds, just add
1006 * any lower rates to the ACK rate bitmap.
1007 */
Emmanuel Grumbach5edd0b92012-11-20 16:31:25 +02001008 if (IWL_RATE_11M_INDEX < lowest_present_cck)
1009 cck |= IWL_RATE_11M_MASK >> IWL_FIRST_CCK_RATE;
1010 if (IWL_RATE_5M_INDEX < lowest_present_cck)
1011 cck |= IWL_RATE_5M_MASK >> IWL_FIRST_CCK_RATE;
1012 if (IWL_RATE_2M_INDEX < lowest_present_cck)
1013 cck |= IWL_RATE_2M_MASK >> IWL_FIRST_CCK_RATE;
Johannes Berg9543c5f2012-03-08 09:37:53 +01001014 /* 1M already there or needed so always add */
1015 cck |= IWL_RATE_1M_MASK >> IWL_FIRST_CCK_RATE;
1016
1017 IWL_DEBUG_RATE(priv, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n",
1018 cck, ofdm);
1019
1020 /* "basic_rates" is a misnomer here -- should be called ACK rates */
1021 ctx->staging.cck_basic_rates = cck;
1022 ctx->staging.ofdm_basic_rates = ofdm;
1023}
1024
Meenakshi Venkataraman55620922012-03-15 13:27:02 -07001025/**
Johannes Berg2295c662010-10-23 09:15:41 -07001026 * iwlagn_commit_rxon - commit staging_rxon to hardware
1027 *
1028 * The RXON command in staging_rxon is committed to the hardware and
1029 * the active_rxon structure is updated with the new data. This
1030 * function correctly transitions out of the RXON_ASSOC_MSK state if
1031 * a HW tune is required based on the RXON structure changes.
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001032 *
1033 * The connect/disconnect flow should be as the following:
1034 *
1035 * 1. make sure send RXON command with association bit unset if not connect
1036 * this should include the channel and the band for the candidate
1037 * to be connected to
1038 * 2. Add Station before RXON association with the AP
1039 * 3. RXON_timing has to send before RXON for connection
1040 * 4. full RXON command - associated bit set
1041 * 5. use RXON_ASSOC command to update any flags changes
Johannes Berg2295c662010-10-23 09:15:41 -07001042 */
1043int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1044{
1045 /* cast away the const for active_rxon in this function */
1046 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -07001047 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
1048 int ret;
1049
Johannes Bergb1eea292012-03-06 13:30:42 -08001050 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001051
Don Fry83626402012-03-07 09:52:37 -08001052 if (!iwl_is_alive(priv))
Johannes Berg2295c662010-10-23 09:15:41 -07001053 return -EBUSY;
1054
1055 /* This function hardcodes a bunch of dual-mode assumptions */
1056 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1057
1058 if (!ctx->is_active)
1059 return 0;
1060
1061 /* always get timestamp with Rx frame */
1062 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1063
Johannes Berg9543c5f2012-03-08 09:37:53 +01001064 /* recalculate basic rates */
1065 iwl_calc_basic_rates(priv, ctx);
1066
Emmanuel Grumbachf47f46d2014-08-31 22:11:11 +03001067 /*
1068 * force CTS-to-self frames protection if RTS-CTS is not preferred
1069 * one aggregation protection method
1070 */
1071 if (!priv->hw_params.use_rts_for_aggregation)
1072 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1073
Johannes Berg2295c662010-10-23 09:15:41 -07001074 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1075 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1076 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1077 else
1078 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1079
Emmanuel Grumbach522376d2011-09-06 09:31:19 -07001080 iwl_print_rx_config_cmd(priv, ctx->ctxid);
Johannes Berg2295c662010-10-23 09:15:41 -07001081 ret = iwl_check_rxon_cmd(priv, ctx);
1082 if (ret) {
1083 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1084 return -EINVAL;
1085 }
1086
1087 /*
1088 * receive commit_rxon request
1089 * abort any previous channel switch if still in process
1090 */
Don Fry83626402012-03-07 09:52:37 -08001091 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001092 (priv->switch_channel != ctx->staging.channel)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001093 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001094 le16_to_cpu(priv->switch_channel));
Johannes Berg2295c662010-10-23 09:15:41 -07001095 iwl_chswitch_done(priv, false);
1096 }
1097
1098 /*
1099 * If we don't need to send a full RXON, we can use
1100 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1101 * and other flags for the current radio configuration.
1102 */
1103 if (!iwl_full_rxon_required(priv, ctx)) {
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -07001104 ret = iwlagn_send_rxon_assoc(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001105 if (ret) {
1106 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1107 return ret;
1108 }
1109
1110 memcpy(active, &ctx->staging, sizeof(*active));
Wey-Yi Guy891db882011-05-27 08:40:24 -07001111 /*
1112 * We do not commit tx power settings while channel changing,
1113 * do it now if after settings changed.
1114 */
1115 iwl_set_tx_power(priv, priv->tx_power_next, false);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -07001116
1117 /* make sure we are in the right PS state */
1118 iwl_power_update_mode(priv, true);
1119
Johannes Berg2295c662010-10-23 09:15:41 -07001120 return 0;
1121 }
1122
Johannes Berg65de7e82012-04-17 07:36:30 -07001123 iwl_set_rxon_hwcrypto(priv, ctx, !iwlwifi_mod_params.sw_crypto);
Johannes Berg2295c662010-10-23 09:15:41 -07001124
1125 IWL_DEBUG_INFO(priv,
1126 "Going to commit RXON\n"
1127 " * with%s RXON_FILTER_ASSOC_MSK\n"
1128 " * channel = %d\n"
1129 " * bssid = %pM\n",
1130 (new_assoc ? "" : "out"),
1131 le16_to_cpu(ctx->staging.channel),
1132 ctx->staging.bssid_addr);
1133
1134 /*
Johannes Berg52d980c2010-11-10 09:56:45 -08001135 * Always clear associated first, but with the correct config.
1136 * This is required as for example station addition for the
1137 * AP station must be done after the BSSID is set to correctly
1138 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -07001139 */
Wey-Yi Guy3083d032011-05-06 17:06:44 -07001140 ret = iwlagn_rxon_disconn(priv, ctx);
1141 if (ret)
1142 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -07001143
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001144 ret = iwlagn_set_pan_params(priv);
1145 if (ret)
1146 return ret;
Johannes Berg2b9253d2011-05-27 08:40:26 -07001147
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001148 if (new_assoc)
1149 return iwlagn_rxon_connect(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001150
1151 return 0;
1152}
1153
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001154void iwlagn_config_ht40(struct ieee80211_conf *conf,
Johannes Berg85220d72013-03-25 18:29:27 +01001155 struct iwl_rxon_context *ctx)
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001156{
1157 if (conf_is_ht40_minus(conf)) {
1158 ctx->ht.extension_chan_offset =
1159 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1160 ctx->ht.is_40mhz = true;
1161 } else if (conf_is_ht40_plus(conf)) {
1162 ctx->ht.extension_chan_offset =
1163 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1164 ctx->ht.is_40mhz = true;
1165 } else {
1166 ctx->ht.extension_chan_offset =
1167 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1168 ctx->ht.is_40mhz = false;
1169 }
1170}
1171
Johannes Berg2295c662010-10-23 09:15:41 -07001172int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1173{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001174 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001175 struct iwl_rxon_context *ctx;
1176 struct ieee80211_conf *conf = &hw->conf;
Karl Beldan675a0b02013-03-25 16:26:57 +01001177 struct ieee80211_channel *channel = conf->chandef.chan;
Johannes Berg2295c662010-10-23 09:15:41 -07001178 int ret = 0;
1179
Johannes Berg0ca24da2012-03-15 13:26:46 -07001180 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
Johannes Berg2295c662010-10-23 09:15:41 -07001181
Johannes Bergb1eea292012-03-06 13:30:42 -08001182 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001183
Don Fry83626402012-03-07 09:52:37 -08001184 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Johannes Berg2295c662010-10-23 09:15:41 -07001185 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1186 goto out;
1187 }
1188
Don Fry83626402012-03-07 09:52:37 -08001189 if (!iwl_is_ready(priv)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001190 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1191 goto out;
1192 }
1193
1194 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1195 IEEE80211_CONF_CHANGE_CHANNEL)) {
1196 /* mac80211 uses static for non-HT which is what we want */
1197 priv->current_ht_config.smps = conf->smps_mode;
1198
1199 /*
1200 * Recalculate chain counts.
1201 *
1202 * If monitor mode is enabled then mac80211 will
1203 * set up the SM PS mode to OFF if an HT channel is
1204 * configured.
1205 */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001206 for_each_context(priv, ctx)
1207 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001208 }
1209
1210 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Johannes Berg2295c662010-10-23 09:15:41 -07001211 for_each_context(priv, ctx) {
1212 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -07001213 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001214 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001215
Johannes Berg2295c662010-10-23 09:15:41 -07001216 if (ctx->ht.enabled) {
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001217 /* if HT40 is used, it should not change
1218 * after associated except channel switch */
Wey-Yi Guy78feb352011-12-14 08:22:36 -08001219 if (!ctx->ht.is_40mhz ||
1220 !iwl_is_associated_ctx(ctx))
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001221 iwlagn_config_ht40(conf, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001222 } else
1223 ctx->ht.is_40mhz = false;
1224
1225 /*
1226 * Default to no protection. Protection mode will
1227 * later be set from BSS config in iwl_ht_conf
1228 */
1229 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1230
1231 /* if we are switching from ht to 2.4 clear flags
1232 * from any ht related info since 2.4 does not
1233 * support ht */
1234 if (le16_to_cpu(ctx->staging.channel) !=
1235 channel->hw_value)
1236 ctx->staging.flags = 0;
1237
1238 iwl_set_rxon_channel(priv, channel, ctx);
1239 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1240
1241 iwl_set_flags_for_band(priv, ctx, channel->band,
1242 ctx->vif);
1243 }
1244
Johannes Berg2295c662010-10-23 09:15:41 -07001245 iwl_update_bcast_stations(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001246 }
1247
1248 if (changed & (IEEE80211_CONF_CHANGE_PS |
1249 IEEE80211_CONF_CHANGE_IDLE)) {
1250 ret = iwl_power_update_mode(priv, false);
1251 if (ret)
1252 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1253 }
1254
1255 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1256 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1257 priv->tx_power_user_lmt, conf->power_level);
1258
1259 iwl_set_tx_power(priv, conf->power_level, false);
1260 }
1261
1262 for_each_context(priv, ctx) {
1263 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1264 continue;
1265 iwlagn_commit_rxon(priv, ctx);
1266 }
1267 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001268 mutex_unlock(&priv->mutex);
Wey-Yi Guy770c72c2011-10-10 07:27:10 -07001269 IWL_DEBUG_MAC80211(priv, "leave\n");
1270
Johannes Berg2295c662010-10-23 09:15:41 -07001271 return ret;
1272}
1273
Johannes Bergaca86262012-05-14 09:08:50 +02001274static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1275 struct iwl_rxon_context *ctx,
1276 struct ieee80211_bss_conf *bss_conf)
Johannes Berg2295c662010-10-23 09:15:41 -07001277{
1278 struct ieee80211_vif *vif = ctx->vif;
1279 struct iwl_rxon_context *tmp;
1280 struct ieee80211_sta *sta;
1281 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +01001282 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -07001283 bool need_multiple;
1284
Johannes Bergb1eea292012-03-06 13:30:42 -08001285 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001286
1287 switch (vif->type) {
1288 case NL80211_IFTYPE_STATION:
1289 rcu_read_lock();
1290 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +01001291 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -07001292 /*
1293 * If at all, this can only happen through a race
1294 * when the AP disconnects us while we're still
1295 * setting up the connection, in that case mac80211
1296 * will soon tell us about that.
1297 */
1298 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +01001299 rcu_read_unlock();
1300 break;
Johannes Berg2295c662010-10-23 09:15:41 -07001301 }
Johannes Berg850bedc2011-02-25 12:24:11 +01001302
1303 ht_cap = &sta->ht_cap;
1304
1305 need_multiple = true;
1306
1307 /*
1308 * If the peer advertises no support for receiving 2 and 3
1309 * stream MCS rates, it can't be transmitting them either.
1310 */
1311 if (ht_cap->mcs.rx_mask[1] == 0 &&
1312 ht_cap->mcs.rx_mask[2] == 0) {
1313 need_multiple = false;
1314 } else if (!(ht_cap->mcs.tx_params &
1315 IEEE80211_HT_MCS_TX_DEFINED)) {
1316 /* If it can't TX MCS at all ... */
1317 need_multiple = false;
1318 } else if (ht_cap->mcs.tx_params &
1319 IEEE80211_HT_MCS_TX_RX_DIFF) {
1320 int maxstreams;
1321
1322 /*
1323 * But if it can receive them, it might still not
1324 * be able to transmit them, which is what we need
1325 * to check here -- so check the number of streams
1326 * it advertises for TX (if different from RX).
1327 */
1328
1329 maxstreams = (ht_cap->mcs.tx_params &
1330 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1331 maxstreams >>=
1332 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1333 maxstreams += 1;
1334
1335 if (maxstreams <= 1)
1336 need_multiple = false;
1337 }
1338
Johannes Berg2295c662010-10-23 09:15:41 -07001339 rcu_read_unlock();
1340 break;
1341 case NL80211_IFTYPE_ADHOC:
1342 /* currently */
1343 need_multiple = false;
1344 break;
1345 default:
1346 /* only AP really */
1347 need_multiple = true;
1348 break;
1349 }
1350
1351 ctx->ht_need_multiple_chains = need_multiple;
1352
1353 if (!need_multiple) {
1354 /* check all contexts */
1355 for_each_context(priv, tmp) {
1356 if (!tmp->vif)
1357 continue;
1358 if (tmp->ht_need_multiple_chains) {
1359 need_multiple = true;
1360 break;
1361 }
1362 }
1363 }
1364
1365 ht_conf->single_chain_sufficient = !need_multiple;
1366}
1367
Johannes Bergaca86262012-05-14 09:08:50 +02001368static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
Don Fry5c3d29f2011-07-08 08:46:29 -07001369{
1370 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1371 int ret;
1372
Nikolay Martynovb28b6df2013-05-31 01:29:12 -04001373 if (priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED)
Dor Shaishbfb45f52012-03-26 08:20:55 -07001374 return;
1375
Don Fry5c3d29f2011-07-08 08:46:29 -07001376 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1377 iwl_is_any_associated(priv)) {
1378 struct iwl_calib_chain_noise_reset_cmd cmd;
1379
1380 /* clear data for chain noise calibration algorithm */
1381 data->chain_noise_a = 0;
1382 data->chain_noise_b = 0;
1383 data->chain_noise_c = 0;
1384 data->chain_signal_a = 0;
1385 data->chain_signal_b = 0;
1386 data->chain_signal_c = 0;
1387 data->beacon_count = 0;
1388
1389 memset(&cmd, 0, sizeof(cmd));
1390 iwl_set_calib_hdr(&cmd.hdr,
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001391 priv->phy_calib_chain_noise_reset_cmd);
Johannes Berge10a0532012-03-06 13:30:39 -08001392 ret = iwl_dvm_send_cmd_pdu(priv,
Don Fry5c3d29f2011-07-08 08:46:29 -07001393 REPLY_PHY_CALIBRATION_CMD,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001394 0, sizeof(cmd), &cmd);
Don Fry5c3d29f2011-07-08 08:46:29 -07001395 if (ret)
1396 IWL_ERR(priv,
1397 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1398 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1399 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1400 }
1401}
1402
Johannes Berg2295c662010-10-23 09:15:41 -07001403void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1404 struct ieee80211_vif *vif,
1405 struct ieee80211_bss_conf *bss_conf,
1406 u32 changes)
1407{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001408 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001409 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1410 int ret;
1411 bool force = false;
1412
Johannes Bergb1eea292012-03-06 13:30:42 -08001413 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001414
Johannes Bergb8730b42013-03-27 20:49:58 +01001415 if (changes & BSS_CHANGED_IDLE && bss_conf->idle) {
1416 /*
1417 * If we go idle, then clearly no "passive-no-rx"
1418 * workaround is needed any more, this is a reset.
1419 */
1420 iwlagn_lift_passive_no_rx(priv);
1421 }
1422
Don Fry83626402012-03-07 09:52:37 -08001423 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -08001424 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001425 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -08001426 return;
1427 }
1428
1429 if (unlikely(!ctx->vif)) {
1430 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001431 mutex_unlock(&priv->mutex);
Johannes Berg893654d2010-11-10 18:25:47 -08001432 return;
1433 }
1434
Johannes Berg2295c662010-10-23 09:15:41 -07001435 if (changes & BSS_CHANGED_BEACON_INT)
1436 force = true;
1437
1438 if (changes & BSS_CHANGED_QOS) {
1439 ctx->qos_data.qos_active = bss_conf->qos;
1440 iwlagn_update_qos(priv, ctx);
1441 }
1442
1443 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1444 if (vif->bss_conf.use_short_preamble)
1445 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1446 else
1447 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1448
1449 if (changes & BSS_CHANGED_ASSOC) {
1450 if (bss_conf->assoc) {
Johannes Berg8c358bc2012-05-22 22:13:05 +02001451 priv->timestamp = bss_conf->sync_tsf;
Johannes Berg2295c662010-10-23 09:15:41 -07001452 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1453 } else {
1454 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001455
1456 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1457 priv->have_rekey_data = false;
Johannes Berg2295c662010-10-23 09:15:41 -07001458 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001459
1460 iwlagn_bt_coex_rssi_monitor(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001461 }
1462
1463 if (ctx->ht.enabled) {
1464 ctx->ht.protection = bss_conf->ht_operation_mode &
1465 IEEE80211_HT_OP_MODE_PROTECTION;
1466 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1467 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1468 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -08001469 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -07001470 }
1471
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001472 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001473
Johannes Berg57fbcce2016-04-12 15:56:15 +02001474 if (bss_conf->use_cts_prot && (priv->band != NL80211_BAND_5GHZ))
Johannes Berg2295c662010-10-23 09:15:41 -07001475 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1476 else
1477 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1478
Emmanuel Grumbachf47f46d2014-08-31 22:11:11 +03001479 if (bss_conf->use_cts_prot)
1480 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1481 else
1482 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1483
Johannes Berg2295c662010-10-23 09:15:41 -07001484 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1485
1486 if (vif->type == NL80211_IFTYPE_AP ||
1487 vif->type == NL80211_IFTYPE_ADHOC) {
1488 if (vif->bss_conf.enable_beacon) {
1489 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1490 priv->beacon_ctx = ctx;
1491 } else {
1492 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1493 priv->beacon_ctx = NULL;
1494 }
1495 }
1496
Meenakshi Venkataraman758f5552012-02-08 12:04:41 -08001497 /*
1498 * If the ucode decides to do beacon filtering before
1499 * association, it will lose beacons that are needed
1500 * before sending frames out on passive channels. This
1501 * causes association failures on those channels. Enable
1502 * receiving beacons in such cases.
1503 */
1504
1505 if (vif->type == NL80211_IFTYPE_STATION) {
1506 if (!bss_conf->assoc)
1507 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1508 else
1509 ctx->staging.filter_flags &=
1510 ~RXON_FILTER_BCON_AWARE_MSK;
1511 }
1512
Johannes Berg2295c662010-10-23 09:15:41 -07001513 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1514 iwlagn_commit_rxon(priv, ctx);
1515
Johannes Berg8da8e622010-11-10 09:56:46 -08001516 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1517 /*
1518 * The chain noise calibration will enable PM upon
1519 * completion. If calibration has already been run
1520 * then we need to enable power management here.
1521 */
1522 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1523 iwl_power_update_mode(priv, false);
1524
1525 /* Enable RX differential gain and sensitivity calibrations */
Dor Shaishbfb45f52012-03-26 08:20:55 -07001526 iwlagn_chain_noise_reset(priv);
Johannes Berg8da8e622010-11-10 09:56:46 -08001527 priv->start_calib = 1;
1528 }
1529
Johannes Berg2295c662010-10-23 09:15:41 -07001530 if (changes & BSS_CHANGED_IBSS) {
1531 ret = iwlagn_manage_ibss_station(priv, vif,
1532 bss_conf->ibss_joined);
1533 if (ret)
1534 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1535 bss_conf->ibss_joined ? "add" : "remove",
1536 bss_conf->bssid);
1537 }
1538
Johannes Berg739e42f2013-02-08 23:13:39 +01001539 if (changes & BSS_CHANGED_BEACON && priv->beacon_ctx == ctx) {
Johannes Bergbd50a8ab2010-10-23 09:15:42 -07001540 if (iwlagn_update_beacon(priv, vif))
Johannes Berg739e42f2013-02-08 23:13:39 +01001541 IWL_ERR(priv, "Error updating beacon\n");
Johannes Bergbd50a8ab2010-10-23 09:15:42 -07001542 }
1543
Johannes Bergb1eea292012-03-06 13:30:42 -08001544 mutex_unlock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001545}
Johannes Bergae79d232010-11-10 09:56:38 -08001546
1547void iwlagn_post_scan(struct iwl_priv *priv)
1548{
1549 struct iwl_rxon_context *ctx;
1550
1551 /*
Wey-Yi Guyc2b821d2011-06-03 07:54:14 -07001552 * We do not commit power settings while scan is pending,
1553 * do it now if the settings changed.
1554 */
1555 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1556 iwl_set_tx_power(priv, priv->tx_power_next, false);
1557
1558 /*
Johannes Bergae79d232010-11-10 09:56:38 -08001559 * Since setting the RXON may have been deferred while
1560 * performing the scan, fire one off if needed
1561 */
1562 for_each_context(priv, ctx)
1563 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1564 iwlagn_commit_rxon(priv, ctx);
1565
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001566 iwlagn_set_pan_params(priv);
Johannes Bergae79d232010-11-10 09:56:38 -08001567}