Merge branch 'tipc_net-next' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg...
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-agn-rxon.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
4 *
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
27 #include <linux/etherdevice.h>
28 #include "iwl-dev.h"
29 #include "iwl-agn.h"
30 #include "iwl-core.h"
31 #include "iwl-agn-calib.h"
32 #include "iwl-trans.h"
33 #include "iwl-shared.h"
34
35 /*
36 * initialize rxon structure with default values from eeprom
37 */
38 void iwl_connection_init_rx_config(struct iwl_priv *priv,
39 struct iwl_rxon_context *ctx)
40 {
41 const struct iwl_channel_info *ch_info;
42
43 memset(&ctx->staging, 0, sizeof(ctx->staging));
44
45 if (!ctx->vif) {
46 ctx->staging.dev_type = ctx->unused_devtype;
47 } else
48 switch (ctx->vif->type) {
49 case NL80211_IFTYPE_AP:
50 ctx->staging.dev_type = ctx->ap_devtype;
51 break;
52
53 case NL80211_IFTYPE_STATION:
54 ctx->staging.dev_type = ctx->station_devtype;
55 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
56 break;
57
58 case NL80211_IFTYPE_ADHOC:
59 ctx->staging.dev_type = ctx->ibss_devtype;
60 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
61 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
62 RXON_FILTER_ACCEPT_GRP_MSK;
63 break;
64
65 default:
66 IWL_ERR(priv, "Unsupported interface type %d\n",
67 ctx->vif->type);
68 break;
69 }
70
71 #if 0
72 /* TODO: Figure out when short_preamble would be set and cache from
73 * that */
74 if (!hw_to_local(priv->hw)->short_preamble)
75 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
76 else
77 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
78 #endif
79
80 ch_info = iwl_get_channel_info(priv, priv->band,
81 le16_to_cpu(ctx->active.channel));
82
83 if (!ch_info)
84 ch_info = &priv->channel_info[0];
85
86 ctx->staging.channel = cpu_to_le16(ch_info->channel);
87 priv->band = ch_info->band;
88
89 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
90
91 ctx->staging.ofdm_basic_rates =
92 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
93 ctx->staging.cck_basic_rates =
94 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
95
96 /* clear both MIX and PURE40 mode flag */
97 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
98 RXON_FLG_CHANNEL_MODE_PURE_40);
99 if (ctx->vif)
100 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
101
102 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
103 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
104 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
105 }
106
107 static int iwlagn_disable_bss(struct iwl_priv *priv,
108 struct iwl_rxon_context *ctx,
109 struct iwl_rxon_cmd *send)
110 {
111 __le32 old_filter = send->filter_flags;
112 int ret;
113
114 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
115 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
116 CMD_SYNC, sizeof(*send), send);
117
118 send->filter_flags = old_filter;
119
120 if (ret)
121 IWL_DEBUG_QUIET_RFKILL(priv,
122 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
123
124 return ret;
125 }
126
127 static int iwlagn_disable_pan(struct iwl_priv *priv,
128 struct iwl_rxon_context *ctx,
129 struct iwl_rxon_cmd *send)
130 {
131 struct iwl_notification_wait disable_wait;
132 __le32 old_filter = send->filter_flags;
133 u8 old_dev_type = send->dev_type;
134 int ret;
135 static const u8 deactivate_cmd[] = {
136 REPLY_WIPAN_DEACTIVATION_COMPLETE
137 };
138
139 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
140 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
141 NULL, NULL);
142
143 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
144 send->dev_type = RXON_DEV_TYPE_P2P;
145 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
146 CMD_SYNC, sizeof(*send), send);
147
148 send->filter_flags = old_filter;
149 send->dev_type = old_dev_type;
150
151 if (ret) {
152 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
153 iwl_remove_notification(&priv->notif_wait, &disable_wait);
154 } else {
155 ret = iwl_wait_notification(&priv->notif_wait,
156 &disable_wait, HZ);
157 if (ret)
158 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
159 }
160
161 return ret;
162 }
163
164 static int iwlagn_disconn_pan(struct iwl_priv *priv,
165 struct iwl_rxon_context *ctx,
166 struct iwl_rxon_cmd *send)
167 {
168 __le32 old_filter = send->filter_flags;
169 int ret;
170
171 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
172 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
173 sizeof(*send), send);
174
175 send->filter_flags = old_filter;
176
177 return ret;
178 }
179
180 void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
181 {
182 int ret;
183
184 if (!ctx->is_active)
185 return;
186
187 ctx->qos_data.def_qos_parm.qos_flags = 0;
188
189 if (ctx->qos_data.qos_active)
190 ctx->qos_data.def_qos_parm.qos_flags |=
191 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
192
193 if (ctx->ht.enabled)
194 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
195
196 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
197 ctx->qos_data.qos_active,
198 ctx->qos_data.def_qos_parm.qos_flags);
199
200 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
201 sizeof(struct iwl_qosparam_cmd),
202 &ctx->qos_data.def_qos_parm);
203 if (ret)
204 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
205 }
206
207 int iwlagn_update_beacon(struct iwl_priv *priv,
208 struct ieee80211_vif *vif)
209 {
210 lockdep_assert_held(&priv->mutex);
211
212 dev_kfree_skb(priv->beacon_skb);
213 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
214 if (!priv->beacon_skb)
215 return -ENOMEM;
216 return iwlagn_send_beacon_cmd(priv);
217 }
218
219 static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
220 struct iwl_rxon_context *ctx)
221 {
222 int ret = 0;
223 struct iwl_rxon_assoc_cmd rxon_assoc;
224 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
225 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
226
227 if ((rxon1->flags == rxon2->flags) &&
228 (rxon1->filter_flags == rxon2->filter_flags) &&
229 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
230 (rxon1->ofdm_ht_single_stream_basic_rates ==
231 rxon2->ofdm_ht_single_stream_basic_rates) &&
232 (rxon1->ofdm_ht_dual_stream_basic_rates ==
233 rxon2->ofdm_ht_dual_stream_basic_rates) &&
234 (rxon1->ofdm_ht_triple_stream_basic_rates ==
235 rxon2->ofdm_ht_triple_stream_basic_rates) &&
236 (rxon1->acquisition_data == rxon2->acquisition_data) &&
237 (rxon1->rx_chain == rxon2->rx_chain) &&
238 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
239 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
240 return 0;
241 }
242
243 rxon_assoc.flags = ctx->staging.flags;
244 rxon_assoc.filter_flags = ctx->staging.filter_flags;
245 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
246 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
247 rxon_assoc.reserved1 = 0;
248 rxon_assoc.reserved2 = 0;
249 rxon_assoc.reserved3 = 0;
250 rxon_assoc.ofdm_ht_single_stream_basic_rates =
251 ctx->staging.ofdm_ht_single_stream_basic_rates;
252 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
253 ctx->staging.ofdm_ht_dual_stream_basic_rates;
254 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
255 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
256 ctx->staging.ofdm_ht_triple_stream_basic_rates;
257 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
258
259 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
260 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
261 return ret;
262 }
263
264 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
265 {
266 u16 new_val;
267 u16 beacon_factor;
268
269 /*
270 * If mac80211 hasn't given us a beacon interval, program
271 * the default into the device (not checking this here
272 * would cause the adjustment below to return the maximum
273 * value, which may break PAN.)
274 */
275 if (!beacon_val)
276 return DEFAULT_BEACON_INTERVAL;
277
278 /*
279 * If the beacon interval we obtained from the peer
280 * is too large, we'll have to wake up more often
281 * (and in IBSS case, we'll beacon too much)
282 *
283 * For example, if max_beacon_val is 4096, and the
284 * requested beacon interval is 7000, we'll have to
285 * use 3500 to be able to wake up on the beacons.
286 *
287 * This could badly influence beacon detection stats.
288 */
289
290 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
291 new_val = beacon_val / beacon_factor;
292
293 if (!new_val)
294 new_val = max_beacon_val;
295
296 return new_val;
297 }
298
299 static int iwl_send_rxon_timing(struct iwl_priv *priv,
300 struct iwl_rxon_context *ctx)
301 {
302 u64 tsf;
303 s32 interval_tm, rem;
304 struct ieee80211_conf *conf = NULL;
305 u16 beacon_int;
306 struct ieee80211_vif *vif = ctx->vif;
307
308 conf = &priv->hw->conf;
309
310 lockdep_assert_held(&priv->mutex);
311
312 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
313
314 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
315 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
316
317 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
318
319 /*
320 * TODO: For IBSS we need to get atim_window from mac80211,
321 * for now just always use 0
322 */
323 ctx->timing.atim_window = 0;
324
325 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
326 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
327 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
328 priv->contexts[IWL_RXON_CTX_BSS].vif &&
329 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
330 ctx->timing.beacon_interval =
331 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
332 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
333 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
334 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
335 priv->contexts[IWL_RXON_CTX_PAN].vif &&
336 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
337 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
338 !ctx->vif->bss_conf.beacon_int)) {
339 ctx->timing.beacon_interval =
340 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
341 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
342 } else {
343 beacon_int = iwl_adjust_beacon_interval(beacon_int,
344 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
345 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
346 }
347
348 ctx->beacon_int = beacon_int;
349
350 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
351 interval_tm = beacon_int * TIME_UNIT;
352 rem = do_div(tsf, interval_tm);
353 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
354
355 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
356
357 IWL_DEBUG_ASSOC(priv,
358 "beacon interval %d beacon timer %d beacon tim %d\n",
359 le16_to_cpu(ctx->timing.beacon_interval),
360 le32_to_cpu(ctx->timing.beacon_init_val),
361 le16_to_cpu(ctx->timing.atim_window));
362
363 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
364 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
365 }
366
367 static int iwlagn_rxon_disconn(struct iwl_priv *priv,
368 struct iwl_rxon_context *ctx)
369 {
370 int ret;
371 struct iwl_rxon_cmd *active = (void *)&ctx->active;
372
373 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
374 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
375 } else {
376 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
377 if (ret)
378 return ret;
379 if (ctx->vif) {
380 ret = iwl_send_rxon_timing(priv, ctx);
381 if (ret) {
382 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
383 return ret;
384 }
385 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
386 }
387 }
388 if (ret)
389 return ret;
390
391 /*
392 * Un-assoc RXON clears the station table and WEP
393 * keys, so we have to restore those afterwards.
394 */
395 iwl_clear_ucode_stations(priv, ctx);
396 /* update -- might need P2P now */
397 iwl_update_bcast_station(priv, ctx);
398 iwl_restore_stations(priv, ctx);
399 ret = iwl_restore_default_wep_keys(priv, ctx);
400 if (ret) {
401 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
402 return ret;
403 }
404
405 memcpy(active, &ctx->staging, sizeof(*active));
406 return 0;
407 }
408
409 static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
410 {
411 int ret;
412 s8 prev_tx_power;
413 bool defer;
414 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
415
416 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
417 return 0;
418
419 lockdep_assert_held(&priv->mutex);
420
421 if (priv->tx_power_user_lmt == tx_power && !force)
422 return 0;
423
424 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
425 IWL_WARN(priv,
426 "Requested user TXPOWER %d below lower limit %d.\n",
427 tx_power,
428 IWLAGN_TX_POWER_TARGET_POWER_MIN);
429 return -EINVAL;
430 }
431
432 if (tx_power > priv->tx_power_device_lmt) {
433 IWL_WARN(priv,
434 "Requested user TXPOWER %d above upper limit %d.\n",
435 tx_power, priv->tx_power_device_lmt);
436 return -EINVAL;
437 }
438
439 if (!iwl_is_ready_rf(priv))
440 return -EIO;
441
442 /* scan complete and commit_rxon use tx_power_next value,
443 * it always need to be updated for newest request */
444 priv->tx_power_next = tx_power;
445
446 /* do not set tx power when scanning or channel changing */
447 defer = test_bit(STATUS_SCANNING, &priv->status) ||
448 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
449 if (defer && !force) {
450 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
451 return 0;
452 }
453
454 prev_tx_power = priv->tx_power_user_lmt;
455 priv->tx_power_user_lmt = tx_power;
456
457 ret = iwlagn_send_tx_power(priv);
458
459 /* if fail to set tx_power, restore the orig. tx power */
460 if (ret) {
461 priv->tx_power_user_lmt = prev_tx_power;
462 priv->tx_power_next = prev_tx_power;
463 }
464 return ret;
465 }
466
467 static int iwlagn_rxon_connect(struct iwl_priv *priv,
468 struct iwl_rxon_context *ctx)
469 {
470 int ret;
471 struct iwl_rxon_cmd *active = (void *)&ctx->active;
472
473 /* RXON timing must be before associated RXON */
474 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
475 ret = iwl_send_rxon_timing(priv, ctx);
476 if (ret) {
477 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
478 return ret;
479 }
480 }
481 /* QoS info may be cleared by previous un-assoc RXON */
482 iwlagn_update_qos(priv, ctx);
483
484 /*
485 * We'll run into this code path when beaconing is
486 * enabled, but then we also need to send the beacon
487 * to the device.
488 */
489 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
490 ret = iwlagn_update_beacon(priv, ctx->vif);
491 if (ret) {
492 IWL_ERR(priv,
493 "Error sending required beacon (%d)!\n",
494 ret);
495 return ret;
496 }
497 }
498
499 priv->start_calib = 0;
500 /*
501 * Apply the new configuration.
502 *
503 * Associated RXON doesn't clear the station table in uCode,
504 * so we don't need to restore stations etc. after this.
505 */
506 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
507 sizeof(struct iwl_rxon_cmd), &ctx->staging);
508 if (ret) {
509 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
510 return ret;
511 }
512 memcpy(active, &ctx->staging, sizeof(*active));
513
514 /* IBSS beacon needs to be sent after setting assoc */
515 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
516 if (iwlagn_update_beacon(priv, ctx->vif))
517 IWL_ERR(priv, "Error sending IBSS beacon\n");
518 iwl_init_sensitivity(priv);
519
520 /*
521 * If we issue a new RXON command which required a tune then
522 * we must send a new TXPOWER command or we won't be able to
523 * Tx any frames.
524 *
525 * It's expected we set power here if channel is changing.
526 */
527 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
528 if (ret) {
529 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
530 return ret;
531 }
532
533 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
534 cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
535 ieee80211_request_smps(ctx->vif,
536 cfg(priv)->ht_params->smps_mode);
537
538 return 0;
539 }
540
541 int iwlagn_set_pan_params(struct iwl_priv *priv)
542 {
543 struct iwl_wipan_params_cmd cmd;
544 struct iwl_rxon_context *ctx_bss, *ctx_pan;
545 int slot0 = 300, slot1 = 0;
546 int ret;
547
548 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
549 return 0;
550
551 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
552
553 lockdep_assert_held(&priv->mutex);
554
555 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
556 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
557
558 /*
559 * If the PAN context is inactive, then we don't need
560 * to update the PAN parameters, the last thing we'll
561 * have done before it goes inactive is making the PAN
562 * parameters be WLAN-only.
563 */
564 if (!ctx_pan->is_active)
565 return 0;
566
567 memset(&cmd, 0, sizeof(cmd));
568
569 /* only 2 slots are currently allowed */
570 cmd.num_slots = 2;
571
572 cmd.slots[0].type = 0; /* BSS */
573 cmd.slots[1].type = 1; /* PAN */
574
575 if (priv->hw_roc_setup) {
576 /* both contexts must be used for this to happen */
577 slot1 = IWL_MIN_SLOT_TIME;
578 slot0 = 3000;
579 } else if (ctx_bss->vif && ctx_pan->vif) {
580 int bcnint = ctx_pan->beacon_int;
581 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
582
583 /* should be set, but seems unused?? */
584 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
585
586 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
587 bcnint &&
588 bcnint != ctx_bss->beacon_int) {
589 IWL_ERR(priv,
590 "beacon intervals don't match (%d, %d)\n",
591 ctx_bss->beacon_int, ctx_pan->beacon_int);
592 } else
593 bcnint = max_t(int, bcnint,
594 ctx_bss->beacon_int);
595 if (!bcnint)
596 bcnint = DEFAULT_BEACON_INTERVAL;
597 slot0 = bcnint / 2;
598 slot1 = bcnint - slot0;
599
600 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
601 (!ctx_bss->vif->bss_conf.idle &&
602 !ctx_bss->vif->bss_conf.assoc)) {
603 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
604 slot1 = IWL_MIN_SLOT_TIME;
605 } else if (!ctx_pan->vif->bss_conf.idle &&
606 !ctx_pan->vif->bss_conf.assoc) {
607 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
608 slot0 = IWL_MIN_SLOT_TIME;
609 }
610 } else if (ctx_pan->vif) {
611 slot0 = 0;
612 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
613 ctx_pan->beacon_int;
614 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
615
616 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
617 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
618 slot1 = IWL_MIN_SLOT_TIME;
619 }
620 }
621
622 cmd.slots[0].width = cpu_to_le16(slot0);
623 cmd.slots[1].width = cpu_to_le16(slot1);
624
625 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
626 sizeof(cmd), &cmd);
627 if (ret)
628 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
629
630 return ret;
631 }
632
633 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
634 struct iwl_ht_config *ht_conf,
635 struct iwl_rxon_context *ctx)
636 {
637 struct iwl_rxon_cmd *rxon = &ctx->staging;
638
639 if (!ctx->ht.enabled) {
640 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
641 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
642 RXON_FLG_HT40_PROT_MSK |
643 RXON_FLG_HT_PROT_MSK);
644 return;
645 }
646
647 /* FIXME: if the definition of ht.protection changed, the "translation"
648 * will be needed for rxon->flags
649 */
650 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
651 RXON_FLG_HT_OPERATING_MODE_POS);
652
653 /* Set up channel bandwidth:
654 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
655 /* clear the HT channel mode before set the mode */
656 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
657 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
658 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
659 /* pure ht40 */
660 if (ctx->ht.protection ==
661 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
662 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
663 /*
664 * Note: control channel is opposite of extension
665 * channel
666 */
667 switch (ctx->ht.extension_chan_offset) {
668 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
669 rxon->flags &=
670 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
671 break;
672 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
673 rxon->flags |=
674 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
675 break;
676 }
677 } else {
678 /*
679 * Note: control channel is opposite of extension
680 * channel
681 */
682 switch (ctx->ht.extension_chan_offset) {
683 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
684 rxon->flags &=
685 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
686 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
687 break;
688 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
689 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
690 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
691 break;
692 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
693 default:
694 /*
695 * channel location only valid if in Mixed
696 * mode
697 */
698 IWL_ERR(priv,
699 "invalid extension channel offset\n");
700 break;
701 }
702 }
703 } else {
704 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
705 }
706
707 iwlagn_set_rxon_chain(priv, ctx);
708
709 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
710 "extension channel offset 0x%x\n",
711 le32_to_cpu(rxon->flags), ctx->ht.protection,
712 ctx->ht.extension_chan_offset);
713 }
714
715 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
716 {
717 struct iwl_rxon_context *ctx;
718
719 for_each_context(priv, ctx)
720 _iwl_set_rxon_ht(priv, ht_conf, ctx);
721 }
722
723 /**
724 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
725 * @ch: requested channel as a pointer to struct ieee80211_channel
726
727 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
728 * in the staging RXON flag structure based on the ch->band
729 */
730 void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
731 struct iwl_rxon_context *ctx)
732 {
733 enum ieee80211_band band = ch->band;
734 u16 channel = ch->hw_value;
735
736 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
737 (priv->band == band))
738 return;
739
740 ctx->staging.channel = cpu_to_le16(channel);
741 if (band == IEEE80211_BAND_5GHZ)
742 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
743 else
744 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
745
746 priv->band = band;
747
748 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
749
750 }
751
752 void iwl_set_flags_for_band(struct iwl_priv *priv,
753 struct iwl_rxon_context *ctx,
754 enum ieee80211_band band,
755 struct ieee80211_vif *vif)
756 {
757 if (band == IEEE80211_BAND_5GHZ) {
758 ctx->staging.flags &=
759 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
760 | RXON_FLG_CCK_MSK);
761 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
762 } else {
763 /* Copied from iwl_post_associate() */
764 if (vif && vif->bss_conf.use_short_slot)
765 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
766 else
767 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
768
769 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
770 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
771 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
772 }
773 }
774
775 void iwl_set_rate(struct iwl_priv *priv)
776 {
777 struct iwl_rxon_context *ctx;
778
779 for_each_context(priv, ctx) {
780 ctx->staging.cck_basic_rates =
781 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
782
783 ctx->staging.ofdm_basic_rates =
784 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
785 }
786 }
787
788 static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
789 struct iwl_rxon_context *ctx, int hw_decrypt)
790 {
791 struct iwl_rxon_cmd *rxon = &ctx->staging;
792
793 if (hw_decrypt)
794 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
795 else
796 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
797
798 }
799
800 /* validate RXON structure is valid */
801 static int iwl_check_rxon_cmd(struct iwl_priv *priv,
802 struct iwl_rxon_context *ctx)
803 {
804 struct iwl_rxon_cmd *rxon = &ctx->staging;
805 u32 errors = 0;
806
807 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
808 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
809 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
810 errors |= BIT(0);
811 }
812 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
813 IWL_WARN(priv, "check 2.4G: wrong radar\n");
814 errors |= BIT(1);
815 }
816 } else {
817 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
818 IWL_WARN(priv, "check 5.2G: not short slot!\n");
819 errors |= BIT(2);
820 }
821 if (rxon->flags & RXON_FLG_CCK_MSK) {
822 IWL_WARN(priv, "check 5.2G: CCK!\n");
823 errors |= BIT(3);
824 }
825 }
826 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
827 IWL_WARN(priv, "mac/bssid mcast!\n");
828 errors |= BIT(4);
829 }
830
831 /* make sure basic rates 6Mbps and 1Mbps are supported */
832 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
833 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
834 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
835 errors |= BIT(5);
836 }
837
838 if (le16_to_cpu(rxon->assoc_id) > 2007) {
839 IWL_WARN(priv, "aid > 2007\n");
840 errors |= BIT(6);
841 }
842
843 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
844 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
845 IWL_WARN(priv, "CCK and short slot\n");
846 errors |= BIT(7);
847 }
848
849 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
850 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
851 IWL_WARN(priv, "CCK and auto detect");
852 errors |= BIT(8);
853 }
854
855 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
856 RXON_FLG_TGG_PROTECT_MSK)) ==
857 RXON_FLG_TGG_PROTECT_MSK) {
858 IWL_WARN(priv, "TGg but no auto-detect\n");
859 errors |= BIT(9);
860 }
861
862 if (rxon->channel == 0) {
863 IWL_WARN(priv, "zero channel is invalid\n");
864 errors |= BIT(10);
865 }
866
867 WARN(errors, "Invalid RXON (%#x), channel %d",
868 errors, le16_to_cpu(rxon->channel));
869
870 return errors ? -EINVAL : 0;
871 }
872
873 /**
874 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
875 * @priv: staging_rxon is compared to active_rxon
876 *
877 * If the RXON structure is changing enough to require a new tune,
878 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
879 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
880 */
881 int iwl_full_rxon_required(struct iwl_priv *priv,
882 struct iwl_rxon_context *ctx)
883 {
884 const struct iwl_rxon_cmd *staging = &ctx->staging;
885 const struct iwl_rxon_cmd *active = &ctx->active;
886
887 #define CHK(cond) \
888 if ((cond)) { \
889 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
890 return 1; \
891 }
892
893 #define CHK_NEQ(c1, c2) \
894 if ((c1) != (c2)) { \
895 IWL_DEBUG_INFO(priv, "need full RXON - " \
896 #c1 " != " #c2 " - %d != %d\n", \
897 (c1), (c2)); \
898 return 1; \
899 }
900
901 /* These items are only settable from the full RXON command */
902 CHK(!iwl_is_associated_ctx(ctx));
903 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
904 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
905 CHK(compare_ether_addr(staging->wlap_bssid_addr,
906 active->wlap_bssid_addr));
907 CHK_NEQ(staging->dev_type, active->dev_type);
908 CHK_NEQ(staging->channel, active->channel);
909 CHK_NEQ(staging->air_propagation, active->air_propagation);
910 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
911 active->ofdm_ht_single_stream_basic_rates);
912 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
913 active->ofdm_ht_dual_stream_basic_rates);
914 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
915 active->ofdm_ht_triple_stream_basic_rates);
916 CHK_NEQ(staging->assoc_id, active->assoc_id);
917
918 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
919 * be updated with the RXON_ASSOC command -- however only some
920 * flag transitions are allowed using RXON_ASSOC */
921
922 /* Check if we are not switching bands */
923 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
924 active->flags & RXON_FLG_BAND_24G_MSK);
925
926 /* Check if we are switching association toggle */
927 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
928 active->filter_flags & RXON_FILTER_ASSOC_MSK);
929
930 #undef CHK
931 #undef CHK_NEQ
932
933 return 0;
934 }
935
936 #ifdef CONFIG_IWLWIFI_DEBUG
937 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
938 enum iwl_rxon_context_id ctxid)
939 {
940 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
941 struct iwl_rxon_cmd *rxon = &ctx->staging;
942
943 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
944 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
945 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
946 le16_to_cpu(rxon->channel));
947 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
948 le32_to_cpu(rxon->flags));
949 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
950 le32_to_cpu(rxon->filter_flags));
951 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
952 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
953 rxon->ofdm_basic_rates);
954 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
955 rxon->cck_basic_rates);
956 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
957 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
958 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
959 le16_to_cpu(rxon->assoc_id));
960 }
961 #endif
962
963 /**
964 * iwlagn_commit_rxon - commit staging_rxon to hardware
965 *
966 * The RXON command in staging_rxon is committed to the hardware and
967 * the active_rxon structure is updated with the new data. This
968 * function correctly transitions out of the RXON_ASSOC_MSK state if
969 * a HW tune is required based on the RXON structure changes.
970 *
971 * The connect/disconnect flow should be as the following:
972 *
973 * 1. make sure send RXON command with association bit unset if not connect
974 * this should include the channel and the band for the candidate
975 * to be connected to
976 * 2. Add Station before RXON association with the AP
977 * 3. RXON_timing has to send before RXON for connection
978 * 4. full RXON command - associated bit set
979 * 5. use RXON_ASSOC command to update any flags changes
980 */
981 int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
982 {
983 /* cast away the const for active_rxon in this function */
984 struct iwl_rxon_cmd *active = (void *)&ctx->active;
985 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
986 int ret;
987
988 lockdep_assert_held(&priv->mutex);
989
990 if (!iwl_is_alive(priv))
991 return -EBUSY;
992
993 /* This function hardcodes a bunch of dual-mode assumptions */
994 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
995
996 if (!ctx->is_active)
997 return 0;
998
999 /* always get timestamp with Rx frame */
1000 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1001
1002 /*
1003 * force CTS-to-self frames protection if RTS-CTS is not preferred
1004 * one aggregation protection method
1005 */
1006 if (!priv->hw_params.use_rts_for_aggregation)
1007 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1008
1009 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1010 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1011 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1012 else
1013 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1014
1015 iwl_print_rx_config_cmd(priv, ctx->ctxid);
1016 ret = iwl_check_rxon_cmd(priv, ctx);
1017 if (ret) {
1018 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1019 return -EINVAL;
1020 }
1021
1022 /*
1023 * receive commit_rxon request
1024 * abort any previous channel switch if still in process
1025 */
1026 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
1027 (priv->switch_channel != ctx->staging.channel)) {
1028 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
1029 le16_to_cpu(priv->switch_channel));
1030 iwl_chswitch_done(priv, false);
1031 }
1032
1033 /*
1034 * If we don't need to send a full RXON, we can use
1035 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1036 * and other flags for the current radio configuration.
1037 */
1038 if (!iwl_full_rxon_required(priv, ctx)) {
1039 ret = iwlagn_send_rxon_assoc(priv, ctx);
1040 if (ret) {
1041 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1042 return ret;
1043 }
1044
1045 memcpy(active, &ctx->staging, sizeof(*active));
1046 /*
1047 * We do not commit tx power settings while channel changing,
1048 * do it now if after settings changed.
1049 */
1050 iwl_set_tx_power(priv, priv->tx_power_next, false);
1051
1052 /* make sure we are in the right PS state */
1053 iwl_power_update_mode(priv, true);
1054
1055 return 0;
1056 }
1057
1058 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
1059
1060 IWL_DEBUG_INFO(priv,
1061 "Going to commit RXON\n"
1062 " * with%s RXON_FILTER_ASSOC_MSK\n"
1063 " * channel = %d\n"
1064 " * bssid = %pM\n",
1065 (new_assoc ? "" : "out"),
1066 le16_to_cpu(ctx->staging.channel),
1067 ctx->staging.bssid_addr);
1068
1069 /*
1070 * Always clear associated first, but with the correct config.
1071 * This is required as for example station addition for the
1072 * AP station must be done after the BSSID is set to correctly
1073 * set up filters in the device.
1074 */
1075 ret = iwlagn_rxon_disconn(priv, ctx);
1076 if (ret)
1077 return ret;
1078
1079 ret = iwlagn_set_pan_params(priv);
1080 if (ret)
1081 return ret;
1082
1083 if (new_assoc)
1084 return iwlagn_rxon_connect(priv, ctx);
1085
1086 return 0;
1087 }
1088
1089 void iwlagn_config_ht40(struct ieee80211_conf *conf,
1090 struct iwl_rxon_context *ctx)
1091 {
1092 if (conf_is_ht40_minus(conf)) {
1093 ctx->ht.extension_chan_offset =
1094 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1095 ctx->ht.is_40mhz = true;
1096 } else if (conf_is_ht40_plus(conf)) {
1097 ctx->ht.extension_chan_offset =
1098 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1099 ctx->ht.is_40mhz = true;
1100 } else {
1101 ctx->ht.extension_chan_offset =
1102 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1103 ctx->ht.is_40mhz = false;
1104 }
1105 }
1106
1107 int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1108 {
1109 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1110 struct iwl_rxon_context *ctx;
1111 struct ieee80211_conf *conf = &hw->conf;
1112 struct ieee80211_channel *channel = conf->channel;
1113 const struct iwl_channel_info *ch_info;
1114 int ret = 0;
1115
1116 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
1117
1118 mutex_lock(&priv->mutex);
1119
1120 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
1121 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1122 goto out;
1123 }
1124
1125 if (!iwl_is_ready(priv)) {
1126 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1127 goto out;
1128 }
1129
1130 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1131 IEEE80211_CONF_CHANGE_CHANNEL)) {
1132 /* mac80211 uses static for non-HT which is what we want */
1133 priv->current_ht_config.smps = conf->smps_mode;
1134
1135 /*
1136 * Recalculate chain counts.
1137 *
1138 * If monitor mode is enabled then mac80211 will
1139 * set up the SM PS mode to OFF if an HT channel is
1140 * configured.
1141 */
1142 for_each_context(priv, ctx)
1143 iwlagn_set_rxon_chain(priv, ctx);
1144 }
1145
1146 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1147 ch_info = iwl_get_channel_info(priv, channel->band,
1148 channel->hw_value);
1149 if (!is_channel_valid(ch_info)) {
1150 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1151 ret = -EINVAL;
1152 goto out;
1153 }
1154
1155 for_each_context(priv, ctx) {
1156 /* Configure HT40 channels */
1157 if (ctx->ht.enabled != conf_is_ht(conf))
1158 ctx->ht.enabled = conf_is_ht(conf);
1159
1160 if (ctx->ht.enabled) {
1161 /* if HT40 is used, it should not change
1162 * after associated except channel switch */
1163 if (!ctx->ht.is_40mhz ||
1164 !iwl_is_associated_ctx(ctx))
1165 iwlagn_config_ht40(conf, ctx);
1166 } else
1167 ctx->ht.is_40mhz = false;
1168
1169 /*
1170 * Default to no protection. Protection mode will
1171 * later be set from BSS config in iwl_ht_conf
1172 */
1173 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1174
1175 /* if we are switching from ht to 2.4 clear flags
1176 * from any ht related info since 2.4 does not
1177 * support ht */
1178 if (le16_to_cpu(ctx->staging.channel) !=
1179 channel->hw_value)
1180 ctx->staging.flags = 0;
1181
1182 iwl_set_rxon_channel(priv, channel, ctx);
1183 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1184
1185 iwl_set_flags_for_band(priv, ctx, channel->band,
1186 ctx->vif);
1187 }
1188
1189 iwl_update_bcast_stations(priv);
1190
1191 /*
1192 * The list of supported rates and rate mask can be different
1193 * for each band; since the band may have changed, reset
1194 * the rate mask to what mac80211 lists.
1195 */
1196 iwl_set_rate(priv);
1197 }
1198
1199 if (changed & (IEEE80211_CONF_CHANGE_PS |
1200 IEEE80211_CONF_CHANGE_IDLE)) {
1201 ret = iwl_power_update_mode(priv, false);
1202 if (ret)
1203 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1204 }
1205
1206 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1207 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1208 priv->tx_power_user_lmt, conf->power_level);
1209
1210 iwl_set_tx_power(priv, conf->power_level, false);
1211 }
1212
1213 for_each_context(priv, ctx) {
1214 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1215 continue;
1216 iwlagn_commit_rxon(priv, ctx);
1217 }
1218 out:
1219 mutex_unlock(&priv->mutex);
1220 IWL_DEBUG_MAC80211(priv, "leave\n");
1221
1222 return ret;
1223 }
1224
1225 void iwlagn_check_needed_chains(struct iwl_priv *priv,
1226 struct iwl_rxon_context *ctx,
1227 struct ieee80211_bss_conf *bss_conf)
1228 {
1229 struct ieee80211_vif *vif = ctx->vif;
1230 struct iwl_rxon_context *tmp;
1231 struct ieee80211_sta *sta;
1232 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1233 struct ieee80211_sta_ht_cap *ht_cap;
1234 bool need_multiple;
1235
1236 lockdep_assert_held(&priv->mutex);
1237
1238 switch (vif->type) {
1239 case NL80211_IFTYPE_STATION:
1240 rcu_read_lock();
1241 sta = ieee80211_find_sta(vif, bss_conf->bssid);
1242 if (!sta) {
1243 /*
1244 * If at all, this can only happen through a race
1245 * when the AP disconnects us while we're still
1246 * setting up the connection, in that case mac80211
1247 * will soon tell us about that.
1248 */
1249 need_multiple = false;
1250 rcu_read_unlock();
1251 break;
1252 }
1253
1254 ht_cap = &sta->ht_cap;
1255
1256 need_multiple = true;
1257
1258 /*
1259 * If the peer advertises no support for receiving 2 and 3
1260 * stream MCS rates, it can't be transmitting them either.
1261 */
1262 if (ht_cap->mcs.rx_mask[1] == 0 &&
1263 ht_cap->mcs.rx_mask[2] == 0) {
1264 need_multiple = false;
1265 } else if (!(ht_cap->mcs.tx_params &
1266 IEEE80211_HT_MCS_TX_DEFINED)) {
1267 /* If it can't TX MCS at all ... */
1268 need_multiple = false;
1269 } else if (ht_cap->mcs.tx_params &
1270 IEEE80211_HT_MCS_TX_RX_DIFF) {
1271 int maxstreams;
1272
1273 /*
1274 * But if it can receive them, it might still not
1275 * be able to transmit them, which is what we need
1276 * to check here -- so check the number of streams
1277 * it advertises for TX (if different from RX).
1278 */
1279
1280 maxstreams = (ht_cap->mcs.tx_params &
1281 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1282 maxstreams >>=
1283 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1284 maxstreams += 1;
1285
1286 if (maxstreams <= 1)
1287 need_multiple = false;
1288 }
1289
1290 rcu_read_unlock();
1291 break;
1292 case NL80211_IFTYPE_ADHOC:
1293 /* currently */
1294 need_multiple = false;
1295 break;
1296 default:
1297 /* only AP really */
1298 need_multiple = true;
1299 break;
1300 }
1301
1302 ctx->ht_need_multiple_chains = need_multiple;
1303
1304 if (!need_multiple) {
1305 /* check all contexts */
1306 for_each_context(priv, tmp) {
1307 if (!tmp->vif)
1308 continue;
1309 if (tmp->ht_need_multiple_chains) {
1310 need_multiple = true;
1311 break;
1312 }
1313 }
1314 }
1315
1316 ht_conf->single_chain_sufficient = !need_multiple;
1317 }
1318
1319 void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1320 {
1321 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1322 int ret;
1323
1324 if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED))
1325 return;
1326
1327 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1328 iwl_is_any_associated(priv)) {
1329 struct iwl_calib_chain_noise_reset_cmd cmd;
1330
1331 /* clear data for chain noise calibration algorithm */
1332 data->chain_noise_a = 0;
1333 data->chain_noise_b = 0;
1334 data->chain_noise_c = 0;
1335 data->chain_signal_a = 0;
1336 data->chain_signal_b = 0;
1337 data->chain_signal_c = 0;
1338 data->beacon_count = 0;
1339
1340 memset(&cmd, 0, sizeof(cmd));
1341 iwl_set_calib_hdr(&cmd.hdr,
1342 priv->phy_calib_chain_noise_reset_cmd);
1343 ret = iwl_dvm_send_cmd_pdu(priv,
1344 REPLY_PHY_CALIBRATION_CMD,
1345 CMD_SYNC, sizeof(cmd), &cmd);
1346 if (ret)
1347 IWL_ERR(priv,
1348 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1349 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1350 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1351 }
1352 }
1353
1354 void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1355 struct ieee80211_vif *vif,
1356 struct ieee80211_bss_conf *bss_conf,
1357 u32 changes)
1358 {
1359 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1360 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1361 int ret;
1362 bool force = false;
1363
1364 mutex_lock(&priv->mutex);
1365
1366 if (unlikely(!iwl_is_ready(priv))) {
1367 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1368 mutex_unlock(&priv->mutex);
1369 return;
1370 }
1371
1372 if (unlikely(!ctx->vif)) {
1373 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
1374 mutex_unlock(&priv->mutex);
1375 return;
1376 }
1377
1378 if (changes & BSS_CHANGED_BEACON_INT)
1379 force = true;
1380
1381 if (changes & BSS_CHANGED_QOS) {
1382 ctx->qos_data.qos_active = bss_conf->qos;
1383 iwlagn_update_qos(priv, ctx);
1384 }
1385
1386 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1387 if (vif->bss_conf.use_short_preamble)
1388 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1389 else
1390 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1391
1392 if (changes & BSS_CHANGED_ASSOC) {
1393 if (bss_conf->assoc) {
1394 priv->timestamp = bss_conf->last_tsf;
1395 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1396 } else {
1397 /*
1398 * If we disassociate while there are pending
1399 * frames, just wake up the queues and let the
1400 * frames "escape" ... This shouldn't really
1401 * be happening to start with, but we should
1402 * not get stuck in this case either since it
1403 * can happen if userspace gets confused.
1404 */
1405 iwlagn_lift_passive_no_rx(priv);
1406
1407 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1408
1409 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1410 priv->have_rekey_data = false;
1411 }
1412
1413 iwlagn_bt_coex_rssi_monitor(priv);
1414 }
1415
1416 if (ctx->ht.enabled) {
1417 ctx->ht.protection = bss_conf->ht_operation_mode &
1418 IEEE80211_HT_OP_MODE_PROTECTION;
1419 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1420 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1421 iwlagn_check_needed_chains(priv, ctx, bss_conf);
1422 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1423 }
1424
1425 iwlagn_set_rxon_chain(priv, ctx);
1426
1427 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1428 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1429 else
1430 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1431
1432 if (bss_conf->use_cts_prot)
1433 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1434 else
1435 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1436
1437 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1438
1439 if (vif->type == NL80211_IFTYPE_AP ||
1440 vif->type == NL80211_IFTYPE_ADHOC) {
1441 if (vif->bss_conf.enable_beacon) {
1442 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1443 priv->beacon_ctx = ctx;
1444 } else {
1445 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1446 priv->beacon_ctx = NULL;
1447 }
1448 }
1449
1450 /*
1451 * If the ucode decides to do beacon filtering before
1452 * association, it will lose beacons that are needed
1453 * before sending frames out on passive channels. This
1454 * causes association failures on those channels. Enable
1455 * receiving beacons in such cases.
1456 */
1457
1458 if (vif->type == NL80211_IFTYPE_STATION) {
1459 if (!bss_conf->assoc)
1460 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1461 else
1462 ctx->staging.filter_flags &=
1463 ~RXON_FILTER_BCON_AWARE_MSK;
1464 }
1465
1466 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1467 iwlagn_commit_rxon(priv, ctx);
1468
1469 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1470 /*
1471 * The chain noise calibration will enable PM upon
1472 * completion. If calibration has already been run
1473 * then we need to enable power management here.
1474 */
1475 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1476 iwl_power_update_mode(priv, false);
1477
1478 /* Enable RX differential gain and sensitivity calibrations */
1479 iwlagn_chain_noise_reset(priv);
1480 priv->start_calib = 1;
1481 }
1482
1483 if (changes & BSS_CHANGED_IBSS) {
1484 ret = iwlagn_manage_ibss_station(priv, vif,
1485 bss_conf->ibss_joined);
1486 if (ret)
1487 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1488 bss_conf->ibss_joined ? "add" : "remove",
1489 bss_conf->bssid);
1490 }
1491
1492 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1493 priv->beacon_ctx) {
1494 if (iwlagn_update_beacon(priv, vif))
1495 IWL_ERR(priv, "Error sending IBSS beacon\n");
1496 }
1497
1498 mutex_unlock(&priv->mutex);
1499 }
1500
1501 void iwlagn_post_scan(struct iwl_priv *priv)
1502 {
1503 struct iwl_rxon_context *ctx;
1504
1505 /*
1506 * We do not commit power settings while scan is pending,
1507 * do it now if the settings changed.
1508 */
1509 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1510 iwl_set_tx_power(priv, priv->tx_power_next, false);
1511
1512 /*
1513 * Since setting the RXON may have been deferred while
1514 * performing the scan, fire one off if needed
1515 */
1516 for_each_context(priv, ctx)
1517 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1518 iwlagn_commit_rxon(priv, ctx);
1519
1520 iwlagn_set_pan_params(priv);
1521 }
This page took 0.083118 seconds and 6 git commands to generate.