blob: 944ad735593223269dc903b79dbbe0def6057b3a [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-core.h"
31#include "iwl-agn-calib.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070032#include "iwl-trans.h"
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070033#include "iwl-shared.h"
Johannes Berg2295c662010-10-23 09:15:41 -070034
35static int iwlagn_disable_bss(struct iwl_priv *priv,
36 struct iwl_rxon_context *ctx,
37 struct iwl_rxon_cmd *send)
38{
39 __le32 old_filter = send->filter_flags;
40 int ret;
41
42 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -080043 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -070044 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -070045
46 send->filter_flags = old_filter;
47
48 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -080049 IWL_DEBUG_QUIET_RFKILL(priv,
50 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
Johannes Berg2295c662010-10-23 09:15:41 -070051
52 return ret;
53}
54
55static int iwlagn_disable_pan(struct iwl_priv *priv,
56 struct iwl_rxon_context *ctx,
57 struct iwl_rxon_cmd *send)
58{
Johannes Berg311dce72011-01-04 16:22:01 -080059 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -070060 __le32 old_filter = send->filter_flags;
61 u8 old_dev_type = send->dev_type;
62 int ret;
Johannes Bergdb662d42012-03-15 13:26:44 -070063 static const u8 deactivate_cmd[] = {
64 REPLY_WIPAN_DEACTIVATION_COMPLETE
65 };
Johannes Berg2295c662010-10-23 09:15:41 -070066
Johannes Berg4bd14dd2012-03-06 13:30:58 -080067 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
Johannes Bergdb662d42012-03-15 13:26:44 -070068 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
Johannes Berg4bd14dd2012-03-06 13:30:58 -080069 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -080070
Johannes Berg2295c662010-10-23 09:15:41 -070071 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
72 send->dev_type = RXON_DEV_TYPE_P2P;
Johannes Berge10a0532012-03-06 13:30:39 -080073 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -070074 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -070075
76 send->filter_flags = old_filter;
77 send->dev_type = old_dev_type;
78
Johannes Berg311dce72011-01-04 16:22:01 -080079 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -070080 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg4bd14dd2012-03-06 13:30:58 -080081 iwl_remove_notification(&priv->notif_wait, &disable_wait);
Johannes Berg311dce72011-01-04 16:22:01 -080082 } else {
Johannes Berg4bd14dd2012-03-06 13:30:58 -080083 ret = iwl_wait_notification(&priv->notif_wait,
84 &disable_wait, HZ);
Johannes Berga8674a12011-04-13 03:14:48 -070085 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -080086 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
87 }
Johannes Berg2295c662010-10-23 09:15:41 -070088
89 return ret;
90}
91
Johannes Berg2b9253d2011-05-27 08:40:26 -070092static int iwlagn_disconn_pan(struct iwl_priv *priv,
93 struct iwl_rxon_context *ctx,
94 struct iwl_rxon_cmd *send)
95{
96 __le32 old_filter = send->filter_flags;
97 int ret;
98
99 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800100 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700101 sizeof(*send), send);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700102
103 send->filter_flags = old_filter;
104
105 return ret;
106}
107
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800108static void iwlagn_update_qos(struct iwl_priv *priv,
109 struct iwl_rxon_context *ctx)
110{
111 int ret;
112
113 if (!ctx->is_active)
114 return;
115
116 ctx->qos_data.def_qos_parm.qos_flags = 0;
117
118 if (ctx->qos_data.qos_active)
119 ctx->qos_data.def_qos_parm.qos_flags |=
120 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
121
122 if (ctx->ht.enabled)
123 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
124
Emmanuel Grumbach0dcf50c2011-11-10 06:55:23 -0800125 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800126 ctx->qos_data.qos_active,
127 ctx->qos_data.def_qos_parm.qos_flags);
128
Johannes Berge10a0532012-03-06 13:30:39 -0800129 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800130 sizeof(struct iwl_qosparam_cmd),
131 &ctx->qos_data.def_qos_parm);
132 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800133 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800134}
135
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700136static int iwlagn_update_beacon(struct iwl_priv *priv,
137 struct ieee80211_vif *vif)
138{
Johannes Bergb1eea292012-03-06 13:30:42 -0800139 lockdep_assert_held(&priv->mutex);
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700140
141 dev_kfree_skb(priv->beacon_skb);
142 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
143 if (!priv->beacon_skb)
144 return -ENOMEM;
145 return iwlagn_send_beacon_cmd(priv);
146}
147
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700148static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
149 struct iwl_rxon_context *ctx)
150{
151 int ret = 0;
Wey-Yi Guy89e746b2011-04-19 16:52:58 -0700152 struct iwl_rxon_assoc_cmd rxon_assoc;
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700153 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
154 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
155
156 if ((rxon1->flags == rxon2->flags) &&
157 (rxon1->filter_flags == rxon2->filter_flags) &&
158 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
159 (rxon1->ofdm_ht_single_stream_basic_rates ==
160 rxon2->ofdm_ht_single_stream_basic_rates) &&
161 (rxon1->ofdm_ht_dual_stream_basic_rates ==
162 rxon2->ofdm_ht_dual_stream_basic_rates) &&
163 (rxon1->ofdm_ht_triple_stream_basic_rates ==
164 rxon2->ofdm_ht_triple_stream_basic_rates) &&
165 (rxon1->acquisition_data == rxon2->acquisition_data) &&
166 (rxon1->rx_chain == rxon2->rx_chain) &&
167 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
168 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
169 return 0;
170 }
171
172 rxon_assoc.flags = ctx->staging.flags;
173 rxon_assoc.filter_flags = ctx->staging.filter_flags;
174 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
175 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
176 rxon_assoc.reserved1 = 0;
177 rxon_assoc.reserved2 = 0;
178 rxon_assoc.reserved3 = 0;
179 rxon_assoc.ofdm_ht_single_stream_basic_rates =
180 ctx->staging.ofdm_ht_single_stream_basic_rates;
181 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
182 ctx->staging.ofdm_ht_dual_stream_basic_rates;
183 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
184 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
185 ctx->staging.ofdm_ht_triple_stream_basic_rates;
186 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
187
Johannes Berge10a0532012-03-06 13:30:39 -0800188 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700189 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700190 return ret;
191}
192
Meenakshi Venkataramandff96c12012-03-15 13:26:59 -0700193static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
194{
195 u16 new_val;
196 u16 beacon_factor;
197
198 /*
199 * If mac80211 hasn't given us a beacon interval, program
200 * the default into the device (not checking this here
201 * would cause the adjustment below to return the maximum
202 * value, which may break PAN.)
203 */
204 if (!beacon_val)
205 return DEFAULT_BEACON_INTERVAL;
206
207 /*
208 * If the beacon interval we obtained from the peer
209 * is too large, we'll have to wake up more often
210 * (and in IBSS case, we'll beacon too much)
211 *
212 * For example, if max_beacon_val is 4096, and the
213 * requested beacon interval is 7000, we'll have to
214 * use 3500 to be able to wake up on the beacons.
215 *
216 * This could badly influence beacon detection stats.
217 */
218
219 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
220 new_val = beacon_val / beacon_factor;
221
222 if (!new_val)
223 new_val = max_beacon_val;
224
225 return new_val;
226}
227
228static int iwl_send_rxon_timing(struct iwl_priv *priv,
229 struct iwl_rxon_context *ctx)
230{
231 u64 tsf;
232 s32 interval_tm, rem;
233 struct ieee80211_conf *conf = NULL;
234 u16 beacon_int;
235 struct ieee80211_vif *vif = ctx->vif;
236
237 conf = &priv->hw->conf;
238
239 lockdep_assert_held(&priv->mutex);
240
241 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
242
243 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
244 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
245
246 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
247
248 /*
249 * TODO: For IBSS we need to get atim_window from mac80211,
250 * for now just always use 0
251 */
252 ctx->timing.atim_window = 0;
253
254 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
255 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
256 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
257 priv->contexts[IWL_RXON_CTX_BSS].vif &&
258 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
259 ctx->timing.beacon_interval =
260 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
261 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
262 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
263 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
264 priv->contexts[IWL_RXON_CTX_PAN].vif &&
265 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
266 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
267 !ctx->vif->bss_conf.beacon_int)) {
268 ctx->timing.beacon_interval =
269 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
270 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
271 } else {
272 beacon_int = iwl_adjust_beacon_interval(beacon_int,
273 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
274 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
275 }
276
277 ctx->beacon_int = beacon_int;
278
279 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
280 interval_tm = beacon_int * TIME_UNIT;
281 rem = do_div(tsf, interval_tm);
282 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
283
284 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
285
286 IWL_DEBUG_ASSOC(priv,
287 "beacon interval %d beacon timer %d beacon tim %d\n",
288 le16_to_cpu(ctx->timing.beacon_interval),
289 le32_to_cpu(ctx->timing.beacon_init_val),
290 le16_to_cpu(ctx->timing.atim_window));
291
292 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
293 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
294}
295
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700296static int iwlagn_rxon_disconn(struct iwl_priv *priv,
297 struct iwl_rxon_context *ctx)
298{
299 int ret;
300 struct iwl_rxon_cmd *active = (void *)&ctx->active;
301
Johannes Berg2b9253d2011-05-27 08:40:26 -0700302 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700303 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700304 } else {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700305 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700306 if (ret)
307 return ret;
308 if (ctx->vif) {
309 ret = iwl_send_rxon_timing(priv, ctx);
310 if (ret) {
311 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
312 return ret;
313 }
314 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
315 }
316 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700317 if (ret)
318 return ret;
319
320 /*
321 * Un-assoc RXON clears the station table and WEP
322 * keys, so we have to restore those afterwards.
323 */
324 iwl_clear_ucode_stations(priv, ctx);
Johannes Bergf775aa06d2011-06-22 06:34:09 -0700325 /* update -- might need P2P now */
326 iwl_update_bcast_station(priv, ctx);
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700327 iwl_restore_stations(priv, ctx);
328 ret = iwl_restore_default_wep_keys(priv, ctx);
329 if (ret) {
330 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
331 return ret;
332 }
333
334 memcpy(active, &ctx->staging, sizeof(*active));
335 return 0;
336}
337
338static int iwlagn_rxon_connect(struct iwl_priv *priv,
339 struct iwl_rxon_context *ctx)
340{
341 int ret;
342 struct iwl_rxon_cmd *active = (void *)&ctx->active;
343
344 /* RXON timing must be before associated RXON */
Johannes Berg2b9253d2011-05-27 08:40:26 -0700345 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
346 ret = iwl_send_rxon_timing(priv, ctx);
347 if (ret) {
348 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
349 return ret;
350 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700351 }
352 /* QoS info may be cleared by previous un-assoc RXON */
353 iwlagn_update_qos(priv, ctx);
354
355 /*
356 * We'll run into this code path when beaconing is
357 * enabled, but then we also need to send the beacon
358 * to the device.
359 */
360 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
361 ret = iwlagn_update_beacon(priv, ctx->vif);
362 if (ret) {
363 IWL_ERR(priv,
364 "Error sending required beacon (%d)!\n",
365 ret);
366 return ret;
367 }
368 }
369
370 priv->start_calib = 0;
371 /*
372 * Apply the new configuration.
373 *
374 * Associated RXON doesn't clear the station table in uCode,
375 * so we don't need to restore stations etc. after this.
376 */
Johannes Berge10a0532012-03-06 13:30:39 -0800377 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700378 sizeof(struct iwl_rxon_cmd), &ctx->staging);
379 if (ret) {
380 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
381 return ret;
382 }
383 memcpy(active, &ctx->staging, sizeof(*active));
384
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700385 /* IBSS beacon needs to be sent after setting assoc */
386 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
387 if (iwlagn_update_beacon(priv, ctx->vif))
388 IWL_ERR(priv, "Error sending IBSS beacon\n");
389 iwl_init_sensitivity(priv);
390
391 /*
392 * If we issue a new RXON command which required a tune then
393 * we must send a new TXPOWER command or we won't be able to
394 * Tx any frames.
395 *
396 * It's expected we set power here if channel is changing.
397 */
398 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
399 if (ret) {
400 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
401 return ret;
402 }
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700403
Stanislaw Gruszka107ef972011-10-12 10:16:35 +0200404 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
Don Fry38622412011-12-16 07:07:36 -0800405 cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700406 ieee80211_request_smps(ctx->vif,
Don Fry38622412011-12-16 07:07:36 -0800407 cfg(priv)->ht_params->smps_mode);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700408
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700409 return 0;
410}
411
Wey-Yi Guye505c432011-07-07 08:27:41 -0700412int iwlagn_set_pan_params(struct iwl_priv *priv)
413{
414 struct iwl_wipan_params_cmd cmd;
415 struct iwl_rxon_context *ctx_bss, *ctx_pan;
416 int slot0 = 300, slot1 = 0;
417 int ret;
418
Johannes Berga18f61b2012-03-15 13:26:53 -0700419 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
Wey-Yi Guye505c432011-07-07 08:27:41 -0700420 return 0;
421
422 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
423
Johannes Bergb1eea292012-03-06 13:30:42 -0800424 lockdep_assert_held(&priv->mutex);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700425
426 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
427 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
428
429 /*
430 * If the PAN context is inactive, then we don't need
431 * to update the PAN parameters, the last thing we'll
432 * have done before it goes inactive is making the PAN
433 * parameters be WLAN-only.
434 */
435 if (!ctx_pan->is_active)
436 return 0;
437
438 memset(&cmd, 0, sizeof(cmd));
439
440 /* only 2 slots are currently allowed */
441 cmd.num_slots = 2;
442
443 cmd.slots[0].type = 0; /* BSS */
444 cmd.slots[1].type = 1; /* PAN */
445
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700446 if (priv->hw_roc_setup) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700447 /* both contexts must be used for this to happen */
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700448 slot1 = IWL_MIN_SLOT_TIME;
449 slot0 = 3000;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700450 } else if (ctx_bss->vif && ctx_pan->vif) {
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700451 int bcnint = ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700452 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
453
454 /* should be set, but seems unused?? */
455 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
456
457 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
458 bcnint &&
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700459 bcnint != ctx_bss->beacon_int) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700460 IWL_ERR(priv,
461 "beacon intervals don't match (%d, %d)\n",
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700462 ctx_bss->beacon_int, ctx_pan->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700463 } else
464 bcnint = max_t(int, bcnint,
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700465 ctx_bss->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700466 if (!bcnint)
467 bcnint = DEFAULT_BEACON_INTERVAL;
468 slot0 = bcnint / 2;
469 slot1 = bcnint - slot0;
470
Don Fry83626402012-03-07 09:52:37 -0800471 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
Wey-Yi Guye505c432011-07-07 08:27:41 -0700472 (!ctx_bss->vif->bss_conf.idle &&
473 !ctx_bss->vif->bss_conf.assoc)) {
474 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
475 slot1 = IWL_MIN_SLOT_TIME;
476 } else if (!ctx_pan->vif->bss_conf.idle &&
477 !ctx_pan->vif->bss_conf.assoc) {
Johannes Berg325a7dd2011-09-22 15:14:55 -0700478 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700479 slot0 = IWL_MIN_SLOT_TIME;
480 }
481 } else if (ctx_pan->vif) {
482 slot0 = 0;
483 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700484 ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700485 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
486
Don Fry83626402012-03-07 09:52:37 -0800487 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700488 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
489 slot1 = IWL_MIN_SLOT_TIME;
490 }
491 }
492
493 cmd.slots[0].width = cpu_to_le16(slot0);
494 cmd.slots[1].width = cpu_to_le16(slot1);
495
Johannes Berge10a0532012-03-06 13:30:39 -0800496 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
Wey-Yi Guye505c432011-07-07 08:27:41 -0700497 sizeof(cmd), &cmd);
498 if (ret)
499 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
500
501 return ret;
502}
503
Meenakshi Venkataramandd641732012-03-13 16:25:38 -0700504static void _iwl_set_rxon_ht(struct iwl_priv *priv,
505 struct iwl_ht_config *ht_conf,
506 struct iwl_rxon_context *ctx)
507{
508 struct iwl_rxon_cmd *rxon = &ctx->staging;
509
510 if (!ctx->ht.enabled) {
511 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
512 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
513 RXON_FLG_HT40_PROT_MSK |
514 RXON_FLG_HT_PROT_MSK);
515 return;
516 }
517
518 /* FIXME: if the definition of ht.protection changed, the "translation"
519 * will be needed for rxon->flags
520 */
521 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
522 RXON_FLG_HT_OPERATING_MODE_POS);
523
524 /* Set up channel bandwidth:
525 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
526 /* clear the HT channel mode before set the mode */
527 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
528 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
529 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
530 /* pure ht40 */
531 if (ctx->ht.protection ==
532 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
533 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
534 /*
535 * Note: control channel is opposite of extension
536 * channel
537 */
538 switch (ctx->ht.extension_chan_offset) {
539 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
540 rxon->flags &=
541 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
542 break;
543 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
544 rxon->flags |=
545 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
546 break;
547 }
548 } else {
549 /*
550 * Note: control channel is opposite of extension
551 * channel
552 */
553 switch (ctx->ht.extension_chan_offset) {
554 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
555 rxon->flags &=
556 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
557 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
558 break;
559 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
560 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
561 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
562 break;
563 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
564 default:
565 /*
566 * channel location only valid if in Mixed
567 * mode
568 */
569 IWL_ERR(priv,
570 "invalid extension channel offset\n");
571 break;
572 }
573 }
574 } else {
575 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
576 }
577
578 iwlagn_set_rxon_chain(priv, ctx);
579
580 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
581 "extension channel offset 0x%x\n",
582 le32_to_cpu(rxon->flags), ctx->ht.protection,
583 ctx->ht.extension_chan_offset);
584}
585
586void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
587{
588 struct iwl_rxon_context *ctx;
589
590 for_each_context(priv, ctx)
591 _iwl_set_rxon_ht(priv, ht_conf, ctx);
592}
593
Meenakshi Venkataraman354a4532012-03-15 13:27:00 -0700594static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
595 struct iwl_rxon_context *ctx, int hw_decrypt)
596{
597 struct iwl_rxon_cmd *rxon = &ctx->staging;
598
599 if (hw_decrypt)
600 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
601 else
602 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
603
604}
605
Meenakshi Venkataraman8931b572012-03-15 13:27:01 -0700606/* validate RXON structure is valid */
607static int iwl_check_rxon_cmd(struct iwl_priv *priv,
608 struct iwl_rxon_context *ctx)
609{
610 struct iwl_rxon_cmd *rxon = &ctx->staging;
611 u32 errors = 0;
612
613 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
614 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
615 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
616 errors |= BIT(0);
617 }
618 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
619 IWL_WARN(priv, "check 2.4G: wrong radar\n");
620 errors |= BIT(1);
621 }
622 } else {
623 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
624 IWL_WARN(priv, "check 5.2G: not short slot!\n");
625 errors |= BIT(2);
626 }
627 if (rxon->flags & RXON_FLG_CCK_MSK) {
628 IWL_WARN(priv, "check 5.2G: CCK!\n");
629 errors |= BIT(3);
630 }
631 }
632 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
633 IWL_WARN(priv, "mac/bssid mcast!\n");
634 errors |= BIT(4);
635 }
636
637 /* make sure basic rates 6Mbps and 1Mbps are supported */
638 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
639 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
640 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
641 errors |= BIT(5);
642 }
643
644 if (le16_to_cpu(rxon->assoc_id) > 2007) {
645 IWL_WARN(priv, "aid > 2007\n");
646 errors |= BIT(6);
647 }
648
649 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
650 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
651 IWL_WARN(priv, "CCK and short slot\n");
652 errors |= BIT(7);
653 }
654
655 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
656 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
657 IWL_WARN(priv, "CCK and auto detect");
658 errors |= BIT(8);
659 }
660
661 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
662 RXON_FLG_TGG_PROTECT_MSK)) ==
663 RXON_FLG_TGG_PROTECT_MSK) {
664 IWL_WARN(priv, "TGg but no auto-detect\n");
665 errors |= BIT(9);
666 }
667
668 if (rxon->channel == 0) {
669 IWL_WARN(priv, "zero channel is invalid\n");
670 errors |= BIT(10);
671 }
672
673 WARN(errors, "Invalid RXON (%#x), channel %d",
674 errors, le16_to_cpu(rxon->channel));
675
676 return errors ? -EINVAL : 0;
677}
678
Johannes Berg2295c662010-10-23 09:15:41 -0700679/**
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700680 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
681 * @priv: staging_rxon is compared to active_rxon
682 *
683 * If the RXON structure is changing enough to require a new tune,
684 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
685 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
686 */
687static int iwl_full_rxon_required(struct iwl_priv *priv,
688 struct iwl_rxon_context *ctx)
689{
690 const struct iwl_rxon_cmd *staging = &ctx->staging;
691 const struct iwl_rxon_cmd *active = &ctx->active;
692
693#define CHK(cond) \
694 if ((cond)) { \
695 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
696 return 1; \
697 }
698
699#define CHK_NEQ(c1, c2) \
700 if ((c1) != (c2)) { \
701 IWL_DEBUG_INFO(priv, "need full RXON - " \
702 #c1 " != " #c2 " - %d != %d\n", \
703 (c1), (c2)); \
704 return 1; \
705 }
706
707 /* These items are only settable from the full RXON command */
708 CHK(!iwl_is_associated_ctx(ctx));
709 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
710 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
711 CHK(compare_ether_addr(staging->wlap_bssid_addr,
712 active->wlap_bssid_addr));
713 CHK_NEQ(staging->dev_type, active->dev_type);
714 CHK_NEQ(staging->channel, active->channel);
715 CHK_NEQ(staging->air_propagation, active->air_propagation);
716 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
717 active->ofdm_ht_single_stream_basic_rates);
718 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
719 active->ofdm_ht_dual_stream_basic_rates);
720 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
721 active->ofdm_ht_triple_stream_basic_rates);
722 CHK_NEQ(staging->assoc_id, active->assoc_id);
723
724 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
725 * be updated with the RXON_ASSOC command -- however only some
726 * flag transitions are allowed using RXON_ASSOC */
727
728 /* Check if we are not switching bands */
729 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
730 active->flags & RXON_FLG_BAND_24G_MSK);
731
732 /* Check if we are switching association toggle */
733 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
734 active->filter_flags & RXON_FILTER_ASSOC_MSK);
735
736#undef CHK
737#undef CHK_NEQ
738
739 return 0;
740}
741
742/**
Johannes Berg2295c662010-10-23 09:15:41 -0700743 * iwlagn_commit_rxon - commit staging_rxon to hardware
744 *
745 * The RXON command in staging_rxon is committed to the hardware and
746 * the active_rxon structure is updated with the new data. This
747 * function correctly transitions out of the RXON_ASSOC_MSK state if
748 * a HW tune is required based on the RXON structure changes.
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700749 *
750 * The connect/disconnect flow should be as the following:
751 *
752 * 1. make sure send RXON command with association bit unset if not connect
753 * this should include the channel and the band for the candidate
754 * to be connected to
755 * 2. Add Station before RXON association with the AP
756 * 3. RXON_timing has to send before RXON for connection
757 * 4. full RXON command - associated bit set
758 * 5. use RXON_ASSOC command to update any flags changes
Johannes Berg2295c662010-10-23 09:15:41 -0700759 */
760int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
761{
762 /* cast away the const for active_rxon in this function */
763 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -0700764 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
765 int ret;
766
Johannes Bergb1eea292012-03-06 13:30:42 -0800767 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -0700768
Don Fry83626402012-03-07 09:52:37 -0800769 if (!iwl_is_alive(priv))
Johannes Berg2295c662010-10-23 09:15:41 -0700770 return -EBUSY;
771
772 /* This function hardcodes a bunch of dual-mode assumptions */
773 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
774
775 if (!ctx->is_active)
776 return 0;
777
778 /* always get timestamp with Rx frame */
779 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
780
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +0200781 /*
782 * force CTS-to-self frames protection if RTS-CTS is not preferred
783 * one aggregation protection method
784 */
Johannes Berg9e295112012-04-09 17:46:55 -0700785 if (!priv->hw_params.use_rts_for_aggregation)
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +0200786 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
787
Johannes Berg2295c662010-10-23 09:15:41 -0700788 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
789 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
790 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
791 else
792 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
793
Emmanuel Grumbach522376d2011-09-06 09:31:19 -0700794 iwl_print_rx_config_cmd(priv, ctx->ctxid);
Johannes Berg2295c662010-10-23 09:15:41 -0700795 ret = iwl_check_rxon_cmd(priv, ctx);
796 if (ret) {
797 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
798 return -EINVAL;
799 }
800
801 /*
802 * receive commit_rxon request
803 * abort any previous channel switch if still in process
804 */
Don Fry83626402012-03-07 09:52:37 -0800805 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200806 (priv->switch_channel != ctx->staging.channel)) {
Johannes Berg2295c662010-10-23 09:15:41 -0700807 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200808 le16_to_cpu(priv->switch_channel));
Johannes Berg2295c662010-10-23 09:15:41 -0700809 iwl_chswitch_done(priv, false);
810 }
811
812 /*
813 * If we don't need to send a full RXON, we can use
814 * iwl_rxon_assoc_cmd which is used to reconfigure filter
815 * and other flags for the current radio configuration.
816 */
817 if (!iwl_full_rxon_required(priv, ctx)) {
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700818 ret = iwlagn_send_rxon_assoc(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700819 if (ret) {
820 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
821 return ret;
822 }
823
824 memcpy(active, &ctx->staging, sizeof(*active));
Wey-Yi Guy891db882011-05-27 08:40:24 -0700825 /*
826 * We do not commit tx power settings while channel changing,
827 * do it now if after settings changed.
828 */
829 iwl_set_tx_power(priv, priv->tx_power_next, false);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700830
831 /* make sure we are in the right PS state */
832 iwl_power_update_mode(priv, true);
833
Johannes Berg2295c662010-10-23 09:15:41 -0700834 return 0;
835 }
836
Don Fry9d143e92011-04-20 15:23:57 -0700837 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
Johannes Berg2295c662010-10-23 09:15:41 -0700838
839 IWL_DEBUG_INFO(priv,
840 "Going to commit RXON\n"
841 " * with%s RXON_FILTER_ASSOC_MSK\n"
842 " * channel = %d\n"
843 " * bssid = %pM\n",
844 (new_assoc ? "" : "out"),
845 le16_to_cpu(ctx->staging.channel),
846 ctx->staging.bssid_addr);
847
848 /*
Johannes Berg52d980c2010-11-10 09:56:45 -0800849 * Always clear associated first, but with the correct config.
850 * This is required as for example station addition for the
851 * AP station must be done after the BSSID is set to correctly
852 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -0700853 */
Wey-Yi Guy3083d032011-05-06 17:06:44 -0700854 ret = iwlagn_rxon_disconn(priv, ctx);
855 if (ret)
856 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -0700857
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700858 ret = iwlagn_set_pan_params(priv);
859 if (ret)
860 return ret;
Johannes Berg2b9253d2011-05-27 08:40:26 -0700861
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700862 if (new_assoc)
863 return iwlagn_rxon_connect(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700864
865 return 0;
866}
867
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -0800868void iwlagn_config_ht40(struct ieee80211_conf *conf,
869 struct iwl_rxon_context *ctx)
870{
871 if (conf_is_ht40_minus(conf)) {
872 ctx->ht.extension_chan_offset =
873 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
874 ctx->ht.is_40mhz = true;
875 } else if (conf_is_ht40_plus(conf)) {
876 ctx->ht.extension_chan_offset =
877 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
878 ctx->ht.is_40mhz = true;
879 } else {
880 ctx->ht.extension_chan_offset =
881 IEEE80211_HT_PARAM_CHA_SEC_NONE;
882 ctx->ht.is_40mhz = false;
883 }
884}
885
Johannes Berg2295c662010-10-23 09:15:41 -0700886int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
887{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200888 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -0700889 struct iwl_rxon_context *ctx;
890 struct ieee80211_conf *conf = &hw->conf;
891 struct ieee80211_channel *channel = conf->channel;
892 const struct iwl_channel_info *ch_info;
893 int ret = 0;
894
Johannes Berg0ca24da2012-03-15 13:26:46 -0700895 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
Johannes Berg2295c662010-10-23 09:15:41 -0700896
Johannes Bergb1eea292012-03-06 13:30:42 -0800897 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -0700898
Don Fry83626402012-03-07 09:52:37 -0800899 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Johannes Berg2295c662010-10-23 09:15:41 -0700900 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
901 goto out;
902 }
903
Don Fry83626402012-03-07 09:52:37 -0800904 if (!iwl_is_ready(priv)) {
Johannes Berg2295c662010-10-23 09:15:41 -0700905 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
906 goto out;
907 }
908
909 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
910 IEEE80211_CONF_CHANGE_CHANNEL)) {
911 /* mac80211 uses static for non-HT which is what we want */
912 priv->current_ht_config.smps = conf->smps_mode;
913
914 /*
915 * Recalculate chain counts.
916 *
917 * If monitor mode is enabled then mac80211 will
918 * set up the SM PS mode to OFF if an HT channel is
919 * configured.
920 */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700921 for_each_context(priv, ctx)
922 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700923 }
924
925 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Johannes Berg2295c662010-10-23 09:15:41 -0700926 ch_info = iwl_get_channel_info(priv, channel->band,
927 channel->hw_value);
928 if (!is_channel_valid(ch_info)) {
929 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
930 ret = -EINVAL;
931 goto out;
932 }
933
Johannes Berg2295c662010-10-23 09:15:41 -0700934 for_each_context(priv, ctx) {
935 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -0700936 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800937 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800938
Johannes Berg2295c662010-10-23 09:15:41 -0700939 if (ctx->ht.enabled) {
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -0800940 /* if HT40 is used, it should not change
941 * after associated except channel switch */
Wey-Yi Guy78feb352011-12-14 08:22:36 -0800942 if (!ctx->ht.is_40mhz ||
943 !iwl_is_associated_ctx(ctx))
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -0800944 iwlagn_config_ht40(conf, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700945 } else
946 ctx->ht.is_40mhz = false;
947
948 /*
949 * Default to no protection. Protection mode will
950 * later be set from BSS config in iwl_ht_conf
951 */
952 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
953
954 /* if we are switching from ht to 2.4 clear flags
955 * from any ht related info since 2.4 does not
956 * support ht */
957 if (le16_to_cpu(ctx->staging.channel) !=
958 channel->hw_value)
959 ctx->staging.flags = 0;
960
961 iwl_set_rxon_channel(priv, channel, ctx);
962 iwl_set_rxon_ht(priv, &priv->current_ht_config);
963
964 iwl_set_flags_for_band(priv, ctx, channel->band,
965 ctx->vif);
966 }
967
Johannes Berg2295c662010-10-23 09:15:41 -0700968 iwl_update_bcast_stations(priv);
969
970 /*
971 * The list of supported rates and rate mask can be different
972 * for each band; since the band may have changed, reset
973 * the rate mask to what mac80211 lists.
974 */
975 iwl_set_rate(priv);
976 }
977
978 if (changed & (IEEE80211_CONF_CHANGE_PS |
979 IEEE80211_CONF_CHANGE_IDLE)) {
980 ret = iwl_power_update_mode(priv, false);
981 if (ret)
982 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
983 }
984
985 if (changed & IEEE80211_CONF_CHANGE_POWER) {
986 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
987 priv->tx_power_user_lmt, conf->power_level);
988
989 iwl_set_tx_power(priv, conf->power_level, false);
990 }
991
992 for_each_context(priv, ctx) {
993 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
994 continue;
995 iwlagn_commit_rxon(priv, ctx);
996 }
997 out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800998 mutex_unlock(&priv->mutex);
Wey-Yi Guy770c72c2011-10-10 07:27:10 -0700999 IWL_DEBUG_MAC80211(priv, "leave\n");
1000
Johannes Berg2295c662010-10-23 09:15:41 -07001001 return ret;
1002}
1003
Johannes Berg2295c662010-10-23 09:15:41 -07001004static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1005 struct iwl_rxon_context *ctx,
1006 struct ieee80211_bss_conf *bss_conf)
1007{
1008 struct ieee80211_vif *vif = ctx->vif;
1009 struct iwl_rxon_context *tmp;
1010 struct ieee80211_sta *sta;
1011 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +01001012 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -07001013 bool need_multiple;
1014
Johannes Bergb1eea292012-03-06 13:30:42 -08001015 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001016
1017 switch (vif->type) {
1018 case NL80211_IFTYPE_STATION:
1019 rcu_read_lock();
1020 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +01001021 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -07001022 /*
1023 * If at all, this can only happen through a race
1024 * when the AP disconnects us while we're still
1025 * setting up the connection, in that case mac80211
1026 * will soon tell us about that.
1027 */
1028 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +01001029 rcu_read_unlock();
1030 break;
Johannes Berg2295c662010-10-23 09:15:41 -07001031 }
Johannes Berg850bedc2011-02-25 12:24:11 +01001032
1033 ht_cap = &sta->ht_cap;
1034
1035 need_multiple = true;
1036
1037 /*
1038 * If the peer advertises no support for receiving 2 and 3
1039 * stream MCS rates, it can't be transmitting them either.
1040 */
1041 if (ht_cap->mcs.rx_mask[1] == 0 &&
1042 ht_cap->mcs.rx_mask[2] == 0) {
1043 need_multiple = false;
1044 } else if (!(ht_cap->mcs.tx_params &
1045 IEEE80211_HT_MCS_TX_DEFINED)) {
1046 /* If it can't TX MCS at all ... */
1047 need_multiple = false;
1048 } else if (ht_cap->mcs.tx_params &
1049 IEEE80211_HT_MCS_TX_RX_DIFF) {
1050 int maxstreams;
1051
1052 /*
1053 * But if it can receive them, it might still not
1054 * be able to transmit them, which is what we need
1055 * to check here -- so check the number of streams
1056 * it advertises for TX (if different from RX).
1057 */
1058
1059 maxstreams = (ht_cap->mcs.tx_params &
1060 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1061 maxstreams >>=
1062 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1063 maxstreams += 1;
1064
1065 if (maxstreams <= 1)
1066 need_multiple = false;
1067 }
1068
Johannes Berg2295c662010-10-23 09:15:41 -07001069 rcu_read_unlock();
1070 break;
1071 case NL80211_IFTYPE_ADHOC:
1072 /* currently */
1073 need_multiple = false;
1074 break;
1075 default:
1076 /* only AP really */
1077 need_multiple = true;
1078 break;
1079 }
1080
1081 ctx->ht_need_multiple_chains = need_multiple;
1082
1083 if (!need_multiple) {
1084 /* check all contexts */
1085 for_each_context(priv, tmp) {
1086 if (!tmp->vif)
1087 continue;
1088 if (tmp->ht_need_multiple_chains) {
1089 need_multiple = true;
1090 break;
1091 }
1092 }
1093 }
1094
1095 ht_conf->single_chain_sufficient = !need_multiple;
1096}
1097
Don Fry5c3d29f2011-07-08 08:46:29 -07001098static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1099{
1100 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1101 int ret;
1102
1103 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1104 iwl_is_any_associated(priv)) {
1105 struct iwl_calib_chain_noise_reset_cmd cmd;
1106
1107 /* clear data for chain noise calibration algorithm */
1108 data->chain_noise_a = 0;
1109 data->chain_noise_b = 0;
1110 data->chain_noise_c = 0;
1111 data->chain_signal_a = 0;
1112 data->chain_signal_b = 0;
1113 data->chain_signal_c = 0;
1114 data->beacon_count = 0;
1115
1116 memset(&cmd, 0, sizeof(cmd));
1117 iwl_set_calib_hdr(&cmd.hdr,
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001118 priv->phy_calib_chain_noise_reset_cmd);
Johannes Berge10a0532012-03-06 13:30:39 -08001119 ret = iwl_dvm_send_cmd_pdu(priv,
Don Fry5c3d29f2011-07-08 08:46:29 -07001120 REPLY_PHY_CALIBRATION_CMD,
1121 CMD_SYNC, sizeof(cmd), &cmd);
1122 if (ret)
1123 IWL_ERR(priv,
1124 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1125 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1126 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1127 }
1128}
1129
Johannes Berg2295c662010-10-23 09:15:41 -07001130void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1131 struct ieee80211_vif *vif,
1132 struct ieee80211_bss_conf *bss_conf,
1133 u32 changes)
1134{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001135 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001136 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1137 int ret;
1138 bool force = false;
1139
Johannes Bergb1eea292012-03-06 13:30:42 -08001140 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001141
Don Fry83626402012-03-07 09:52:37 -08001142 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -08001143 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001144 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -08001145 return;
1146 }
1147
1148 if (unlikely(!ctx->vif)) {
1149 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001150 mutex_unlock(&priv->mutex);
Johannes Berg893654d2010-11-10 18:25:47 -08001151 return;
1152 }
1153
Johannes Berg2295c662010-10-23 09:15:41 -07001154 if (changes & BSS_CHANGED_BEACON_INT)
1155 force = true;
1156
1157 if (changes & BSS_CHANGED_QOS) {
1158 ctx->qos_data.qos_active = bss_conf->qos;
1159 iwlagn_update_qos(priv, ctx);
1160 }
1161
1162 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1163 if (vif->bss_conf.use_short_preamble)
1164 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1165 else
1166 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1167
1168 if (changes & BSS_CHANGED_ASSOC) {
1169 if (bss_conf->assoc) {
Johannes Berge9ac0742012-03-13 14:29:30 +01001170 priv->timestamp = bss_conf->last_tsf;
Johannes Berg2295c662010-10-23 09:15:41 -07001171 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1172 } else {
Garen Tamrazian68b99312011-03-30 02:29:32 -07001173 /*
1174 * If we disassociate while there are pending
1175 * frames, just wake up the queues and let the
1176 * frames "escape" ... This shouldn't really
1177 * be happening to start with, but we should
1178 * not get stuck in this case either since it
1179 * can happen if userspace gets confused.
1180 */
Johannes Berge755f882012-03-07 09:52:16 -08001181 iwlagn_lift_passive_no_rx(priv);
1182
Johannes Berg2295c662010-10-23 09:15:41 -07001183 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001184
1185 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1186 priv->have_rekey_data = false;
Johannes Berg2295c662010-10-23 09:15:41 -07001187 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001188
1189 iwlagn_bt_coex_rssi_monitor(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001190 }
1191
1192 if (ctx->ht.enabled) {
1193 ctx->ht.protection = bss_conf->ht_operation_mode &
1194 IEEE80211_HT_OP_MODE_PROTECTION;
1195 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1196 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1197 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -08001198 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -07001199 }
1200
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001201 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001202
1203 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1204 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1205 else
1206 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1207
1208 if (bss_conf->use_cts_prot)
1209 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1210 else
1211 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1212
1213 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1214
1215 if (vif->type == NL80211_IFTYPE_AP ||
1216 vif->type == NL80211_IFTYPE_ADHOC) {
1217 if (vif->bss_conf.enable_beacon) {
1218 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1219 priv->beacon_ctx = ctx;
1220 } else {
1221 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1222 priv->beacon_ctx = NULL;
1223 }
1224 }
1225
Meenakshi Venkataraman758f5552012-02-08 12:04:41 -08001226 /*
1227 * If the ucode decides to do beacon filtering before
1228 * association, it will lose beacons that are needed
1229 * before sending frames out on passive channels. This
1230 * causes association failures on those channels. Enable
1231 * receiving beacons in such cases.
1232 */
1233
1234 if (vif->type == NL80211_IFTYPE_STATION) {
1235 if (!bss_conf->assoc)
1236 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1237 else
1238 ctx->staging.filter_flags &=
1239 ~RXON_FILTER_BCON_AWARE_MSK;
1240 }
1241
Johannes Berg2295c662010-10-23 09:15:41 -07001242 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1243 iwlagn_commit_rxon(priv, ctx);
1244
Johannes Berg8da8e622010-11-10 09:56:46 -08001245 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1246 /*
1247 * The chain noise calibration will enable PM upon
1248 * completion. If calibration has already been run
1249 * then we need to enable power management here.
1250 */
1251 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1252 iwl_power_update_mode(priv, false);
1253
1254 /* Enable RX differential gain and sensitivity calibrations */
Don Fry5c3d29f2011-07-08 08:46:29 -07001255 if (!priv->disable_chain_noise_cal)
1256 iwlagn_chain_noise_reset(priv);
Johannes Berg8da8e622010-11-10 09:56:46 -08001257 priv->start_calib = 1;
1258 }
1259
Johannes Berg2295c662010-10-23 09:15:41 -07001260 if (changes & BSS_CHANGED_IBSS) {
1261 ret = iwlagn_manage_ibss_station(priv, vif,
1262 bss_conf->ibss_joined);
1263 if (ret)
1264 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1265 bss_conf->ibss_joined ? "add" : "remove",
1266 bss_conf->bssid);
1267 }
1268
Johannes Bergbd50a8ab2010-10-23 09:15:42 -07001269 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1270 priv->beacon_ctx) {
1271 if (iwlagn_update_beacon(priv, vif))
1272 IWL_ERR(priv, "Error sending IBSS beacon\n");
1273 }
1274
Johannes Bergb1eea292012-03-06 13:30:42 -08001275 mutex_unlock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001276}
Johannes Bergae79d232010-11-10 09:56:38 -08001277
1278void iwlagn_post_scan(struct iwl_priv *priv)
1279{
1280 struct iwl_rxon_context *ctx;
1281
1282 /*
Wey-Yi Guyc2b821d2011-06-03 07:54:14 -07001283 * We do not commit power settings while scan is pending,
1284 * do it now if the settings changed.
1285 */
1286 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1287 iwl_set_tx_power(priv, priv->tx_power_next, false);
1288
1289 /*
Johannes Bergae79d232010-11-10 09:56:38 -08001290 * Since setting the RXON may have been deferred while
1291 * performing the scan, fire one off if needed
1292 */
1293 for_each_context(priv, ctx)
1294 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1295 iwlagn_commit_rxon(priv, ctx);
1296
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001297 iwlagn_set_pan_params(priv);
Johannes Bergae79d232010-11-10 09:56:38 -08001298}