iwlwifi: Move iwl_send_rxon_timing and make it static
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-agn-rxon.c
CommitLineData
2295c66b
JB
1/******************************************************************************
2 *
fb4961db 3 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
2295c66b
JB
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 "iwl-dev.h"
28#include "iwl-agn.h"
2295c66b
JB
29#include "iwl-core.h"
30#include "iwl-agn-calib.h"
bdfbf092 31#include "iwl-trans.h"
48f20d35 32#include "iwl-shared.h"
2295c66b
JB
33
34static int iwlagn_disable_bss(struct iwl_priv *priv,
35 struct iwl_rxon_context *ctx,
36 struct iwl_rxon_cmd *send)
37{
38 __le32 old_filter = send->filter_flags;
39 int ret;
40
41 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
e10a0533 42 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
e419d62d 43 CMD_SYNC, sizeof(*send), send);
2295c66b
JB
44
45 send->filter_flags = old_filter;
46
47 if (ret)
b36b110c
TP
48 IWL_DEBUG_QUIET_RFKILL(priv,
49 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
2295c66b
JB
50
51 return ret;
52}
53
54static int iwlagn_disable_pan(struct iwl_priv *priv,
55 struct iwl_rxon_context *ctx,
56 struct iwl_rxon_cmd *send)
57{
311dce71 58 struct iwl_notification_wait disable_wait;
2295c66b
JB
59 __le32 old_filter = send->filter_flags;
60 u8 old_dev_type = send->dev_type;
61 int ret;
db662d47
JB
62 static const u8 deactivate_cmd[] = {
63 REPLY_WIPAN_DEACTIVATION_COMPLETE
64 };
2295c66b 65
4bd14dd5 66 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
db662d47 67 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
4bd14dd5 68 NULL, NULL);
311dce71 69
2295c66b
JB
70 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
71 send->dev_type = RXON_DEV_TYPE_P2P;
e10a0533 72 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
e419d62d 73 CMD_SYNC, sizeof(*send), send);
2295c66b
JB
74
75 send->filter_flags = old_filter;
76 send->dev_type = old_dev_type;
77
311dce71 78 if (ret) {
2295c66b 79 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
4bd14dd5 80 iwl_remove_notification(&priv->notif_wait, &disable_wait);
311dce71 81 } else {
4bd14dd5
JB
82 ret = iwl_wait_notification(&priv->notif_wait,
83 &disable_wait, HZ);
a8674a1e 84 if (ret)
311dce71
JB
85 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
86 }
2295c66b
JB
87
88 return ret;
89}
90
2b9253d2
JB
91static int iwlagn_disconn_pan(struct iwl_priv *priv,
92 struct iwl_rxon_context *ctx,
93 struct iwl_rxon_cmd *send)
94{
95 __le32 old_filter = send->filter_flags;
96 int ret;
97
98 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
e10a0533 99 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
e419d62d 100 sizeof(*send), send);
2b9253d2
JB
101
102 send->filter_flags = old_filter;
103
104 return ret;
105}
106
f4115d46
SZ
107static void iwlagn_update_qos(struct iwl_priv *priv,
108 struct iwl_rxon_context *ctx)
109{
110 int ret;
111
112 if (!ctx->is_active)
113 return;
114
115 ctx->qos_data.def_qos_parm.qos_flags = 0;
116
117 if (ctx->qos_data.qos_active)
118 ctx->qos_data.def_qos_parm.qos_flags |=
119 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
120
121 if (ctx->ht.enabled)
122 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
123
0dcf50ca 124 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
f4115d46
SZ
125 ctx->qos_data.qos_active,
126 ctx->qos_data.def_qos_parm.qos_flags);
127
e10a0533 128 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
f4115d46
SZ
129 sizeof(struct iwl_qosparam_cmd),
130 &ctx->qos_data.def_qos_parm);
131 if (ret)
b36b110c 132 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
f4115d46
SZ
133}
134
bd50a8ab
JB
135static int iwlagn_update_beacon(struct iwl_priv *priv,
136 struct ieee80211_vif *vif)
137{
b1eea297 138 lockdep_assert_held(&priv->mutex);
bd50a8ab
JB
139
140 dev_kfree_skb(priv->beacon_skb);
141 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
142 if (!priv->beacon_skb)
143 return -ENOMEM;
144 return iwlagn_send_beacon_cmd(priv);
145}
146
c3f6e9cf
WYG
147static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
148 struct iwl_rxon_context *ctx)
149{
150 int ret = 0;
89e746b2 151 struct iwl_rxon_assoc_cmd rxon_assoc;
c3f6e9cf
WYG
152 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
153 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
154
155 if ((rxon1->flags == rxon2->flags) &&
156 (rxon1->filter_flags == rxon2->filter_flags) &&
157 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
158 (rxon1->ofdm_ht_single_stream_basic_rates ==
159 rxon2->ofdm_ht_single_stream_basic_rates) &&
160 (rxon1->ofdm_ht_dual_stream_basic_rates ==
161 rxon2->ofdm_ht_dual_stream_basic_rates) &&
162 (rxon1->ofdm_ht_triple_stream_basic_rates ==
163 rxon2->ofdm_ht_triple_stream_basic_rates) &&
164 (rxon1->acquisition_data == rxon2->acquisition_data) &&
165 (rxon1->rx_chain == rxon2->rx_chain) &&
166 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
167 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
168 return 0;
169 }
170
171 rxon_assoc.flags = ctx->staging.flags;
172 rxon_assoc.filter_flags = ctx->staging.filter_flags;
173 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
174 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
175 rxon_assoc.reserved1 = 0;
176 rxon_assoc.reserved2 = 0;
177 rxon_assoc.reserved3 = 0;
178 rxon_assoc.ofdm_ht_single_stream_basic_rates =
179 ctx->staging.ofdm_ht_single_stream_basic_rates;
180 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
181 ctx->staging.ofdm_ht_dual_stream_basic_rates;
182 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
183 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
184 ctx->staging.ofdm_ht_triple_stream_basic_rates;
185 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
186
e10a0533 187 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
e419d62d 188 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
c3f6e9cf
WYG
189 return ret;
190}
191
dff96c1e
MV
192static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
193{
194 u16 new_val;
195 u16 beacon_factor;
196
197 /*
198 * If mac80211 hasn't given us a beacon interval, program
199 * the default into the device (not checking this here
200 * would cause the adjustment below to return the maximum
201 * value, which may break PAN.)
202 */
203 if (!beacon_val)
204 return DEFAULT_BEACON_INTERVAL;
205
206 /*
207 * If the beacon interval we obtained from the peer
208 * is too large, we'll have to wake up more often
209 * (and in IBSS case, we'll beacon too much)
210 *
211 * For example, if max_beacon_val is 4096, and the
212 * requested beacon interval is 7000, we'll have to
213 * use 3500 to be able to wake up on the beacons.
214 *
215 * This could badly influence beacon detection stats.
216 */
217
218 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
219 new_val = beacon_val / beacon_factor;
220
221 if (!new_val)
222 new_val = max_beacon_val;
223
224 return new_val;
225}
226
227static int iwl_send_rxon_timing(struct iwl_priv *priv,
228 struct iwl_rxon_context *ctx)
229{
230 u64 tsf;
231 s32 interval_tm, rem;
232 struct ieee80211_conf *conf = NULL;
233 u16 beacon_int;
234 struct ieee80211_vif *vif = ctx->vif;
235
236 conf = &priv->hw->conf;
237
238 lockdep_assert_held(&priv->mutex);
239
240 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
241
242 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
243 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
244
245 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
246
247 /*
248 * TODO: For IBSS we need to get atim_window from mac80211,
249 * for now just always use 0
250 */
251 ctx->timing.atim_window = 0;
252
253 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
254 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
255 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
256 priv->contexts[IWL_RXON_CTX_BSS].vif &&
257 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
258 ctx->timing.beacon_interval =
259 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
260 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
261 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
262 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
263 priv->contexts[IWL_RXON_CTX_PAN].vif &&
264 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
265 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
266 !ctx->vif->bss_conf.beacon_int)) {
267 ctx->timing.beacon_interval =
268 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
269 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
270 } else {
271 beacon_int = iwl_adjust_beacon_interval(beacon_int,
272 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
273 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
274 }
275
276 ctx->beacon_int = beacon_int;
277
278 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
279 interval_tm = beacon_int * TIME_UNIT;
280 rem = do_div(tsf, interval_tm);
281 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
282
283 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
284
285 IWL_DEBUG_ASSOC(priv,
286 "beacon interval %d beacon timer %d beacon tim %d\n",
287 le16_to_cpu(ctx->timing.beacon_interval),
288 le32_to_cpu(ctx->timing.beacon_init_val),
289 le16_to_cpu(ctx->timing.atim_window));
290
291 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
292 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
293}
294
c1821c95
WYG
295static int iwlagn_rxon_disconn(struct iwl_priv *priv,
296 struct iwl_rxon_context *ctx)
297{
298 int ret;
299 struct iwl_rxon_cmd *active = (void *)&ctx->active;
300
2b9253d2 301 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
c1821c95 302 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
2b9253d2 303 } else {
c1821c95 304 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
2b9253d2
JB
305 if (ret)
306 return ret;
307 if (ctx->vif) {
308 ret = iwl_send_rxon_timing(priv, ctx);
309 if (ret) {
310 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
311 return ret;
312 }
313 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
314 }
315 }
c1821c95
WYG
316 if (ret)
317 return ret;
318
319 /*
320 * Un-assoc RXON clears the station table and WEP
321 * keys, so we have to restore those afterwards.
322 */
323 iwl_clear_ucode_stations(priv, ctx);
f775aa06
JB
324 /* update -- might need P2P now */
325 iwl_update_bcast_station(priv, ctx);
c1821c95
WYG
326 iwl_restore_stations(priv, ctx);
327 ret = iwl_restore_default_wep_keys(priv, ctx);
328 if (ret) {
329 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
330 return ret;
331 }
332
333 memcpy(active, &ctx->staging, sizeof(*active));
334 return 0;
335}
336
337static int iwlagn_rxon_connect(struct iwl_priv *priv,
338 struct iwl_rxon_context *ctx)
339{
340 int ret;
341 struct iwl_rxon_cmd *active = (void *)&ctx->active;
342
343 /* RXON timing must be before associated RXON */
2b9253d2
JB
344 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
345 ret = iwl_send_rxon_timing(priv, ctx);
346 if (ret) {
347 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
348 return ret;
349 }
c1821c95
WYG
350 }
351 /* QoS info may be cleared by previous un-assoc RXON */
352 iwlagn_update_qos(priv, ctx);
353
354 /*
355 * We'll run into this code path when beaconing is
356 * enabled, but then we also need to send the beacon
357 * to the device.
358 */
359 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
360 ret = iwlagn_update_beacon(priv, ctx->vif);
361 if (ret) {
362 IWL_ERR(priv,
363 "Error sending required beacon (%d)!\n",
364 ret);
365 return ret;
366 }
367 }
368
369 priv->start_calib = 0;
370 /*
371 * Apply the new configuration.
372 *
373 * Associated RXON doesn't clear the station table in uCode,
374 * so we don't need to restore stations etc. after this.
375 */
e10a0533 376 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
c1821c95
WYG
377 sizeof(struct iwl_rxon_cmd), &ctx->staging);
378 if (ret) {
379 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
380 return ret;
381 }
382 memcpy(active, &ctx->staging, sizeof(*active));
383
c1821c95
WYG
384 /* IBSS beacon needs to be sent after setting assoc */
385 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
386 if (iwlagn_update_beacon(priv, ctx->vif))
387 IWL_ERR(priv, "Error sending IBSS beacon\n");
388 iwl_init_sensitivity(priv);
389
390 /*
391 * If we issue a new RXON command which required a tune then
392 * we must send a new TXPOWER command or we won't be able to
393 * Tx any frames.
394 *
395 * It's expected we set power here if channel is changing.
396 */
397 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
398 if (ret) {
399 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
400 return ret;
401 }
15b3f3b0 402
107ef97a 403 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
38622419 404 cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
15b3f3b0 405 ieee80211_request_smps(ctx->vif,
38622419 406 cfg(priv)->ht_params->smps_mode);
15b3f3b0 407
c1821c95
WYG
408 return 0;
409}
410
e505c433
WYG
411int iwlagn_set_pan_params(struct iwl_priv *priv)
412{
413 struct iwl_wipan_params_cmd cmd;
414 struct iwl_rxon_context *ctx_bss, *ctx_pan;
415 int slot0 = 300, slot1 = 0;
416 int ret;
417
a18f61bc 418 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
e505c433
WYG
419 return 0;
420
421 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
422
b1eea297 423 lockdep_assert_held(&priv->mutex);
e505c433
WYG
424
425 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
426 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
427
428 /*
429 * If the PAN context is inactive, then we don't need
430 * to update the PAN parameters, the last thing we'll
431 * have done before it goes inactive is making the PAN
432 * parameters be WLAN-only.
433 */
434 if (!ctx_pan->is_active)
435 return 0;
436
437 memset(&cmd, 0, sizeof(cmd));
438
439 /* only 2 slots are currently allowed */
440 cmd.num_slots = 2;
441
442 cmd.slots[0].type = 0; /* BSS */
443 cmd.slots[1].type = 1; /* PAN */
444
c6baf7fb 445 if (priv->hw_roc_setup) {
e505c433 446 /* both contexts must be used for this to happen */
c6baf7fb
JB
447 slot1 = IWL_MIN_SLOT_TIME;
448 slot0 = 3000;
e505c433 449 } else if (ctx_bss->vif && ctx_pan->vif) {
bbb05cb5 450 int bcnint = ctx_pan->beacon_int;
e505c433
WYG
451 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
452
453 /* should be set, but seems unused?? */
454 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
455
456 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
457 bcnint &&
bbb05cb5 458 bcnint != ctx_bss->beacon_int) {
e505c433
WYG
459 IWL_ERR(priv,
460 "beacon intervals don't match (%d, %d)\n",
bbb05cb5 461 ctx_bss->beacon_int, ctx_pan->beacon_int);
e505c433
WYG
462 } else
463 bcnint = max_t(int, bcnint,
bbb05cb5 464 ctx_bss->beacon_int);
e505c433
WYG
465 if (!bcnint)
466 bcnint = DEFAULT_BEACON_INTERVAL;
467 slot0 = bcnint / 2;
468 slot1 = bcnint - slot0;
469
83626404 470 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
e505c433
WYG
471 (!ctx_bss->vif->bss_conf.idle &&
472 !ctx_bss->vif->bss_conf.assoc)) {
473 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
474 slot1 = IWL_MIN_SLOT_TIME;
475 } else if (!ctx_pan->vif->bss_conf.idle &&
476 !ctx_pan->vif->bss_conf.assoc) {
325a7ddf 477 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
e505c433
WYG
478 slot0 = IWL_MIN_SLOT_TIME;
479 }
480 } else if (ctx_pan->vif) {
481 slot0 = 0;
482 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
bbb05cb5 483 ctx_pan->beacon_int;
e505c433
WYG
484 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
485
83626404 486 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
e505c433
WYG
487 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
488 slot1 = IWL_MIN_SLOT_TIME;
489 }
490 }
491
492 cmd.slots[0].width = cpu_to_le16(slot0);
493 cmd.slots[1].width = cpu_to_le16(slot1);
494
e10a0533 495 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
e505c433
WYG
496 sizeof(cmd), &cmd);
497 if (ret)
498 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
499
500 return ret;
501}
502
2295c66b
JB
503/**
504 * iwlagn_commit_rxon - commit staging_rxon to hardware
505 *
506 * The RXON command in staging_rxon is committed to the hardware and
507 * the active_rxon structure is updated with the new data. This
508 * function correctly transitions out of the RXON_ASSOC_MSK state if
509 * a HW tune is required based on the RXON structure changes.
c1821c95
WYG
510 *
511 * The connect/disconnect flow should be as the following:
512 *
513 * 1. make sure send RXON command with association bit unset if not connect
514 * this should include the channel and the band for the candidate
515 * to be connected to
516 * 2. Add Station before RXON association with the AP
517 * 3. RXON_timing has to send before RXON for connection
518 * 4. full RXON command - associated bit set
519 * 5. use RXON_ASSOC command to update any flags changes
2295c66b
JB
520 */
521int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
522{
523 /* cast away the const for active_rxon in this function */
524 struct iwl_rxon_cmd *active = (void *)&ctx->active;
2295c66b
JB
525 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
526 int ret;
527
b1eea297 528 lockdep_assert_held(&priv->mutex);
2295c66b 529
83626404 530 if (!iwl_is_alive(priv))
2295c66b
JB
531 return -EBUSY;
532
533 /* This function hardcodes a bunch of dual-mode assumptions */
534 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
535
536 if (!ctx->is_active)
537 return 0;
538
539 /* always get timestamp with Rx frame */
540 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
541
42b70a5f
SG
542 /*
543 * force CTS-to-self frames protection if RTS-CTS is not preferred
544 * one aggregation protection method
545 */
b9ad70da 546 if (!hw_params(priv).use_rts_for_aggregation)
42b70a5f
SG
547 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
548
2295c66b
JB
549 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
550 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
551 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
552 else
553 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
554
522376d2 555 iwl_print_rx_config_cmd(priv, ctx->ctxid);
2295c66b
JB
556 ret = iwl_check_rxon_cmd(priv, ctx);
557 if (ret) {
558 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
559 return -EINVAL;
560 }
561
562 /*
563 * receive commit_rxon request
564 * abort any previous channel switch if still in process
565 */
83626404 566 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
6f213ff1 567 (priv->switch_channel != ctx->staging.channel)) {
2295c66b 568 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
6f213ff1 569 le16_to_cpu(priv->switch_channel));
2295c66b
JB
570 iwl_chswitch_done(priv, false);
571 }
572
573 /*
574 * If we don't need to send a full RXON, we can use
575 * iwl_rxon_assoc_cmd which is used to reconfigure filter
576 * and other flags for the current radio configuration.
577 */
578 if (!iwl_full_rxon_required(priv, ctx)) {
c3f6e9cf 579 ret = iwlagn_send_rxon_assoc(priv, ctx);
2295c66b
JB
580 if (ret) {
581 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
582 return ret;
583 }
584
585 memcpy(active, &ctx->staging, sizeof(*active));
891db881
WYG
586 /*
587 * We do not commit tx power settings while channel changing,
588 * do it now if after settings changed.
589 */
590 iwl_set_tx_power(priv, priv->tx_power_next, false);
15b3f3b0
WYG
591
592 /* make sure we are in the right PS state */
593 iwl_power_update_mode(priv, true);
594
2295c66b
JB
595 return 0;
596 }
597
9d143e9a 598 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
2295c66b
JB
599
600 IWL_DEBUG_INFO(priv,
601 "Going to commit RXON\n"
602 " * with%s RXON_FILTER_ASSOC_MSK\n"
603 " * channel = %d\n"
604 " * bssid = %pM\n",
605 (new_assoc ? "" : "out"),
606 le16_to_cpu(ctx->staging.channel),
607 ctx->staging.bssid_addr);
608
609 /*
52d980c0
JB
610 * Always clear associated first, but with the correct config.
611 * This is required as for example station addition for the
612 * AP station must be done after the BSSID is set to correctly
613 * set up filters in the device.
2295c66b 614 */
3083d03c
WYG
615 ret = iwlagn_rxon_disconn(priv, ctx);
616 if (ret)
617 return ret;
2295c66b 618
e3f10cea
WYG
619 ret = iwlagn_set_pan_params(priv);
620 if (ret)
621 return ret;
2b9253d2 622
c1821c95
WYG
623 if (new_assoc)
624 return iwlagn_rxon_connect(priv, ctx);
2295c66b
JB
625
626 return 0;
627}
628
34a5b4b6
WYG
629void iwlagn_config_ht40(struct ieee80211_conf *conf,
630 struct iwl_rxon_context *ctx)
631{
632 if (conf_is_ht40_minus(conf)) {
633 ctx->ht.extension_chan_offset =
634 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
635 ctx->ht.is_40mhz = true;
636 } else if (conf_is_ht40_plus(conf)) {
637 ctx->ht.extension_chan_offset =
638 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
639 ctx->ht.is_40mhz = true;
640 } else {
641 ctx->ht.extension_chan_offset =
642 IEEE80211_HT_PARAM_CHA_SEC_NONE;
643 ctx->ht.is_40mhz = false;
644 }
645}
646
2295c66b
JB
647int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
648{
d0f76d68 649 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
2295c66b
JB
650 struct iwl_rxon_context *ctx;
651 struct ieee80211_conf *conf = &hw->conf;
652 struct ieee80211_channel *channel = conf->channel;
653 const struct iwl_channel_info *ch_info;
654 int ret = 0;
655
0ca24daf 656 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
2295c66b 657
b1eea297 658 mutex_lock(&priv->mutex);
2295c66b 659
83626404 660 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
2295c66b
JB
661 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
662 goto out;
663 }
664
83626404 665 if (!iwl_is_ready(priv)) {
2295c66b
JB
666 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
667 goto out;
668 }
669
670 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
671 IEEE80211_CONF_CHANGE_CHANNEL)) {
672 /* mac80211 uses static for non-HT which is what we want */
673 priv->current_ht_config.smps = conf->smps_mode;
674
675 /*
676 * Recalculate chain counts.
677 *
678 * If monitor mode is enabled then mac80211 will
679 * set up the SM PS mode to OFF if an HT channel is
680 * configured.
681 */
e3f10cea
WYG
682 for_each_context(priv, ctx)
683 iwlagn_set_rxon_chain(priv, ctx);
2295c66b
JB
684 }
685
686 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2295c66b
JB
687 ch_info = iwl_get_channel_info(priv, channel->band,
688 channel->hw_value);
689 if (!is_channel_valid(ch_info)) {
690 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
691 ret = -EINVAL;
692 goto out;
693 }
694
2295c66b
JB
695 for_each_context(priv, ctx) {
696 /* Configure HT40 channels */
7caa2316 697 if (ctx->ht.enabled != conf_is_ht(conf))
35a6eb36 698 ctx->ht.enabled = conf_is_ht(conf);
35a6eb36 699
2295c66b 700 if (ctx->ht.enabled) {
34a5b4b6
WYG
701 /* if HT40 is used, it should not change
702 * after associated except channel switch */
78feb35b
WYG
703 if (!ctx->ht.is_40mhz ||
704 !iwl_is_associated_ctx(ctx))
34a5b4b6 705 iwlagn_config_ht40(conf, ctx);
2295c66b
JB
706 } else
707 ctx->ht.is_40mhz = false;
708
709 /*
710 * Default to no protection. Protection mode will
711 * later be set from BSS config in iwl_ht_conf
712 */
713 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
714
715 /* if we are switching from ht to 2.4 clear flags
716 * from any ht related info since 2.4 does not
717 * support ht */
718 if (le16_to_cpu(ctx->staging.channel) !=
719 channel->hw_value)
720 ctx->staging.flags = 0;
721
722 iwl_set_rxon_channel(priv, channel, ctx);
723 iwl_set_rxon_ht(priv, &priv->current_ht_config);
724
725 iwl_set_flags_for_band(priv, ctx, channel->band,
726 ctx->vif);
727 }
728
2295c66b
JB
729 iwl_update_bcast_stations(priv);
730
731 /*
732 * The list of supported rates and rate mask can be different
733 * for each band; since the band may have changed, reset
734 * the rate mask to what mac80211 lists.
735 */
736 iwl_set_rate(priv);
737 }
738
739 if (changed & (IEEE80211_CONF_CHANGE_PS |
740 IEEE80211_CONF_CHANGE_IDLE)) {
741 ret = iwl_power_update_mode(priv, false);
742 if (ret)
743 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
744 }
745
746 if (changed & IEEE80211_CONF_CHANGE_POWER) {
747 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
748 priv->tx_power_user_lmt, conf->power_level);
749
750 iwl_set_tx_power(priv, conf->power_level, false);
751 }
752
753 for_each_context(priv, ctx) {
754 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
755 continue;
756 iwlagn_commit_rxon(priv, ctx);
757 }
758 out:
b1eea297 759 mutex_unlock(&priv->mutex);
770c72c4
WYG
760 IWL_DEBUG_MAC80211(priv, "leave\n");
761
2295c66b
JB
762 return ret;
763}
764
2295c66b
JB
765static void iwlagn_check_needed_chains(struct iwl_priv *priv,
766 struct iwl_rxon_context *ctx,
767 struct ieee80211_bss_conf *bss_conf)
768{
769 struct ieee80211_vif *vif = ctx->vif;
770 struct iwl_rxon_context *tmp;
771 struct ieee80211_sta *sta;
772 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
850bedcc 773 struct ieee80211_sta_ht_cap *ht_cap;
2295c66b
JB
774 bool need_multiple;
775
b1eea297 776 lockdep_assert_held(&priv->mutex);
2295c66b
JB
777
778 switch (vif->type) {
779 case NL80211_IFTYPE_STATION:
780 rcu_read_lock();
781 sta = ieee80211_find_sta(vif, bss_conf->bssid);
850bedcc 782 if (!sta) {
2295c66b
JB
783 /*
784 * If at all, this can only happen through a race
785 * when the AP disconnects us while we're still
786 * setting up the connection, in that case mac80211
787 * will soon tell us about that.
788 */
789 need_multiple = false;
850bedcc
JB
790 rcu_read_unlock();
791 break;
792 }
793
794 ht_cap = &sta->ht_cap;
795
796 need_multiple = true;
797
798 /*
799 * If the peer advertises no support for receiving 2 and 3
800 * stream MCS rates, it can't be transmitting them either.
801 */
802 if (ht_cap->mcs.rx_mask[1] == 0 &&
803 ht_cap->mcs.rx_mask[2] == 0) {
804 need_multiple = false;
805 } else if (!(ht_cap->mcs.tx_params &
806 IEEE80211_HT_MCS_TX_DEFINED)) {
807 /* If it can't TX MCS at all ... */
808 need_multiple = false;
809 } else if (ht_cap->mcs.tx_params &
810 IEEE80211_HT_MCS_TX_RX_DIFF) {
811 int maxstreams;
812
813 /*
814 * But if it can receive them, it might still not
815 * be able to transmit them, which is what we need
816 * to check here -- so check the number of streams
817 * it advertises for TX (if different from RX).
818 */
819
820 maxstreams = (ht_cap->mcs.tx_params &
821 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
822 maxstreams >>=
823 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
824 maxstreams += 1;
825
826 if (maxstreams <= 1)
827 need_multiple = false;
2295c66b 828 }
850bedcc 829
2295c66b
JB
830 rcu_read_unlock();
831 break;
832 case NL80211_IFTYPE_ADHOC:
833 /* currently */
834 need_multiple = false;
835 break;
836 default:
837 /* only AP really */
838 need_multiple = true;
839 break;
840 }
841
842 ctx->ht_need_multiple_chains = need_multiple;
843
844 if (!need_multiple) {
845 /* check all contexts */
846 for_each_context(priv, tmp) {
847 if (!tmp->vif)
848 continue;
849 if (tmp->ht_need_multiple_chains) {
850 need_multiple = true;
851 break;
852 }
853 }
854 }
855
856 ht_conf->single_chain_sufficient = !need_multiple;
857}
858
5c3d29fc
DF
859static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
860{
861 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
862 int ret;
863
864 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
865 iwl_is_any_associated(priv)) {
866 struct iwl_calib_chain_noise_reset_cmd cmd;
867
868 /* clear data for chain noise calibration algorithm */
869 data->chain_noise_a = 0;
870 data->chain_noise_b = 0;
871 data->chain_noise_c = 0;
872 data->chain_signal_a = 0;
873 data->chain_signal_b = 0;
874 data->chain_signal_c = 0;
875 data->beacon_count = 0;
876
877 memset(&cmd, 0, sizeof(cmd));
878 iwl_set_calib_hdr(&cmd.hdr,
898ed67b 879 priv->phy_calib_chain_noise_reset_cmd);
e10a0533 880 ret = iwl_dvm_send_cmd_pdu(priv,
5c3d29fc
DF
881 REPLY_PHY_CALIBRATION_CMD,
882 CMD_SYNC, sizeof(cmd), &cmd);
883 if (ret)
884 IWL_ERR(priv,
885 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
886 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
887 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
888 }
889}
890
2295c66b
JB
891void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
892 struct ieee80211_vif *vif,
893 struct ieee80211_bss_conf *bss_conf,
894 u32 changes)
895{
d0f76d68 896 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
2295c66b
JB
897 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
898 int ret;
899 bool force = false;
900
b1eea297 901 mutex_lock(&priv->mutex);
2295c66b 902
83626404 903 if (unlikely(!iwl_is_ready(priv))) {
14a085e7 904 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
b1eea297 905 mutex_unlock(&priv->mutex);
ae0b693c
SZ
906 return;
907 }
908
909 if (unlikely(!ctx->vif)) {
910 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
b1eea297 911 mutex_unlock(&priv->mutex);
893654de
JB
912 return;
913 }
914
2295c66b
JB
915 if (changes & BSS_CHANGED_BEACON_INT)
916 force = true;
917
918 if (changes & BSS_CHANGED_QOS) {
919 ctx->qos_data.qos_active = bss_conf->qos;
920 iwlagn_update_qos(priv, ctx);
921 }
922
923 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
924 if (vif->bss_conf.use_short_preamble)
925 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
926 else
927 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
928
929 if (changes & BSS_CHANGED_ASSOC) {
930 if (bss_conf->assoc) {
e9ac0745 931 priv->timestamp = bss_conf->last_tsf;
2295c66b
JB
932 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
933 } else {
68b99311
GT
934 /*
935 * If we disassociate while there are pending
936 * frames, just wake up the queues and let the
937 * frames "escape" ... This shouldn't really
938 * be happening to start with, but we should
939 * not get stuck in this case either since it
940 * can happen if userspace gets confused.
941 */
e755f882
JB
942 iwlagn_lift_passive_no_rx(priv);
943
2295c66b 944 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
c8ac61cf
JB
945
946 if (ctx->ctxid == IWL_RXON_CTX_BSS)
947 priv->have_rekey_data = false;
2295c66b 948 }
207ecc5e
MV
949
950 iwlagn_bt_coex_rssi_monitor(priv);
2295c66b
JB
951 }
952
953 if (ctx->ht.enabled) {
954 ctx->ht.protection = bss_conf->ht_operation_mode &
955 IEEE80211_HT_OP_MODE_PROTECTION;
956 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
957 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
958 iwlagn_check_needed_chains(priv, ctx, bss_conf);
b2769b84 959 iwl_set_rxon_ht(priv, &priv->current_ht_config);
2295c66b
JB
960 }
961
e3f10cea 962 iwlagn_set_rxon_chain(priv, ctx);
2295c66b
JB
963
964 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
965 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
966 else
967 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
968
969 if (bss_conf->use_cts_prot)
970 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
971 else
972 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
973
974 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
975
976 if (vif->type == NL80211_IFTYPE_AP ||
977 vif->type == NL80211_IFTYPE_ADHOC) {
978 if (vif->bss_conf.enable_beacon) {
979 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
980 priv->beacon_ctx = ctx;
981 } else {
982 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
983 priv->beacon_ctx = NULL;
984 }
985 }
986
758f555f
MV
987 /*
988 * If the ucode decides to do beacon filtering before
989 * association, it will lose beacons that are needed
990 * before sending frames out on passive channels. This
991 * causes association failures on those channels. Enable
992 * receiving beacons in such cases.
993 */
994
995 if (vif->type == NL80211_IFTYPE_STATION) {
996 if (!bss_conf->assoc)
997 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
998 else
999 ctx->staging.filter_flags &=
1000 ~RXON_FILTER_BCON_AWARE_MSK;
1001 }
1002
2295c66b
JB
1003 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1004 iwlagn_commit_rxon(priv, ctx);
1005
8da8e628
JB
1006 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1007 /*
1008 * The chain noise calibration will enable PM upon
1009 * completion. If calibration has already been run
1010 * then we need to enable power management here.
1011 */
1012 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1013 iwl_power_update_mode(priv, false);
1014
1015 /* Enable RX differential gain and sensitivity calibrations */
5c3d29fc
DF
1016 if (!priv->disable_chain_noise_cal)
1017 iwlagn_chain_noise_reset(priv);
8da8e628
JB
1018 priv->start_calib = 1;
1019 }
1020
2295c66b
JB
1021 if (changes & BSS_CHANGED_IBSS) {
1022 ret = iwlagn_manage_ibss_station(priv, vif,
1023 bss_conf->ibss_joined);
1024 if (ret)
1025 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1026 bss_conf->ibss_joined ? "add" : "remove",
1027 bss_conf->bssid);
1028 }
1029
bd50a8ab
JB
1030 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1031 priv->beacon_ctx) {
1032 if (iwlagn_update_beacon(priv, vif))
1033 IWL_ERR(priv, "Error sending IBSS beacon\n");
1034 }
1035
b1eea297 1036 mutex_unlock(&priv->mutex);
2295c66b 1037}
ae79d23d
JB
1038
1039void iwlagn_post_scan(struct iwl_priv *priv)
1040{
1041 struct iwl_rxon_context *ctx;
1042
c2b821d7
WYG
1043 /*
1044 * We do not commit power settings while scan is pending,
1045 * do it now if the settings changed.
1046 */
1047 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1048 iwl_set_tx_power(priv, priv->tx_power_next, false);
1049
ae79d23d
JB
1050 /*
1051 * Since setting the RXON may have been deferred while
1052 * performing the scan, fire one off if needed
1053 */
1054 for_each_context(priv, ctx)
1055 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1056 iwlagn_commit_rxon(priv, ctx);
1057
e3f10cea 1058 iwlagn_set_pan_params(priv);
ae79d23d 1059}
This page took 0.231889 seconds and 5 git commands to generate.