aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2011-09-20 18:37:20 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-09-21 16:19:41 -0400
commit6e809a16d98efa8b1483a25ab8886dd2aa200d0f (patch)
tree86f1c8443cb82c766910ff53451468994f559840
parentba4a14e1024fd783f0e56d96538a959a44651897 (diff)
iwlagn: move scan code to scan file
Since the driver split there's no longer a need to have the scan code scattered across multiple files, so move it all back to iwl-scan.c Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Wey-Yi Guy <wey-yi.guy@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c427
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c439
4 files changed, 433 insertions, 440 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index e8b324c84da8..0a1f331cb572 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -190,433 +190,6 @@ int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
190 return -1; 190 return -1;
191} 191}
192 192
193static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
194 struct ieee80211_vif *vif,
195 enum ieee80211_band band,
196 struct iwl_scan_channel *scan_ch)
197{
198 const struct ieee80211_supported_band *sband;
199 u16 passive_dwell = 0;
200 u16 active_dwell = 0;
201 int added = 0;
202 u16 channel = 0;
203
204 sband = iwl_get_hw_mode(priv, band);
205 if (!sband) {
206 IWL_ERR(priv, "invalid band\n");
207 return added;
208 }
209
210 active_dwell = iwl_get_active_dwell_time(priv, band, 0);
211 passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
212
213 if (passive_dwell <= active_dwell)
214 passive_dwell = active_dwell + 1;
215
216 channel = iwl_get_single_channel_number(priv, band);
217 if (channel) {
218 scan_ch->channel = cpu_to_le16(channel);
219 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
220 scan_ch->active_dwell = cpu_to_le16(active_dwell);
221 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
222 /* Set txpower levels to defaults */
223 scan_ch->dsp_atten = 110;
224 if (band == IEEE80211_BAND_5GHZ)
225 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
226 else
227 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
228 added++;
229 } else
230 IWL_ERR(priv, "no valid channel found\n");
231 return added;
232}
233
234static int iwl_get_channels_for_scan(struct iwl_priv *priv,
235 struct ieee80211_vif *vif,
236 enum ieee80211_band band,
237 u8 is_active, u8 n_probes,
238 struct iwl_scan_channel *scan_ch)
239{
240 struct ieee80211_channel *chan;
241 const struct ieee80211_supported_band *sband;
242 const struct iwl_channel_info *ch_info;
243 u16 passive_dwell = 0;
244 u16 active_dwell = 0;
245 int added, i;
246 u16 channel;
247
248 sband = iwl_get_hw_mode(priv, band);
249 if (!sband)
250 return 0;
251
252 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
253 passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
254
255 if (passive_dwell <= active_dwell)
256 passive_dwell = active_dwell + 1;
257
258 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
259 chan = priv->scan_request->channels[i];
260
261 if (chan->band != band)
262 continue;
263
264 channel = chan->hw_value;
265 scan_ch->channel = cpu_to_le16(channel);
266
267 ch_info = iwl_get_channel_info(priv, band, channel);
268 if (!is_channel_valid(ch_info)) {
269 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
270 channel);
271 continue;
272 }
273
274 if (!is_active || is_channel_passive(ch_info) ||
275 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
276 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
277 else
278 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
279
280 if (n_probes)
281 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
282
283 scan_ch->active_dwell = cpu_to_le16(active_dwell);
284 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
285
286 /* Set txpower levels to defaults */
287 scan_ch->dsp_atten = 110;
288
289 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
290 * power level:
291 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
292 */
293 if (band == IEEE80211_BAND_5GHZ)
294 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
295 else
296 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
297
298 IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
299 channel, le32_to_cpu(scan_ch->type),
300 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
301 "ACTIVE" : "PASSIVE",
302 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
303 active_dwell : passive_dwell);
304
305 scan_ch++;
306 added++;
307 }
308
309 IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
310 return added;
311}
312
313int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
314{
315 struct iwl_host_cmd cmd = {
316 .id = REPLY_SCAN_CMD,
317 .len = { sizeof(struct iwl_scan_cmd), },
318 .flags = CMD_SYNC,
319 };
320 struct iwl_scan_cmd *scan;
321 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
322 u32 rate_flags = 0;
323 u16 cmd_len;
324 u16 rx_chain = 0;
325 enum ieee80211_band band;
326 u8 n_probes = 0;
327 u8 rx_ant = hw_params(priv).valid_rx_ant;
328 u8 rate;
329 bool is_active = false;
330 int chan_mod;
331 u8 active_chains;
332 u8 scan_tx_antennas = hw_params(priv).valid_tx_ant;
333 int ret;
334
335 lockdep_assert_held(&priv->shrd->mutex);
336
337 if (vif)
338 ctx = iwl_rxon_ctx_from_vif(vif);
339
340 if (!priv->scan_cmd) {
341 priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
342 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
343 if (!priv->scan_cmd) {
344 IWL_DEBUG_SCAN(priv,
345 "fail to allocate memory for scan\n");
346 return -ENOMEM;
347 }
348 }
349 scan = priv->scan_cmd;
350 memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
351
352 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
353 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
354
355 if (priv->scan_type != IWL_SCAN_ROC &&
356 iwl_is_any_associated(priv)) {
357 u16 interval = 0;
358 u32 extra;
359 u32 suspend_time = 100;
360 u32 scan_suspend_time = 100;
361
362 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
363 switch (priv->scan_type) {
364 case IWL_SCAN_ROC:
365 WARN_ON(1);
366 break;
367 case IWL_SCAN_RADIO_RESET:
368 interval = 0;
369 break;
370 case IWL_SCAN_NORMAL:
371 interval = vif->bss_conf.beacon_int;
372 break;
373 }
374
375 scan->suspend_time = 0;
376 scan->max_out_time = cpu_to_le32(200 * 1024);
377 if (!interval)
378 interval = suspend_time;
379
380 extra = (suspend_time / interval) << 22;
381 scan_suspend_time = (extra |
382 ((suspend_time % interval) * 1024));
383 scan->suspend_time = cpu_to_le32(scan_suspend_time);
384 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
385 scan_suspend_time, interval);
386 } else if (priv->scan_type == IWL_SCAN_ROC) {
387 scan->suspend_time = 0;
388 scan->max_out_time = 0;
389 scan->quiet_time = 0;
390 scan->quiet_plcp_th = 0;
391 }
392
393 switch (priv->scan_type) {
394 case IWL_SCAN_RADIO_RESET:
395 IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
396 break;
397 case IWL_SCAN_NORMAL:
398 if (priv->scan_request->n_ssids) {
399 int i, p = 0;
400 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
401 for (i = 0; i < priv->scan_request->n_ssids; i++) {
402 /* always does wildcard anyway */
403 if (!priv->scan_request->ssids[i].ssid_len)
404 continue;
405 scan->direct_scan[p].id = WLAN_EID_SSID;
406 scan->direct_scan[p].len =
407 priv->scan_request->ssids[i].ssid_len;
408 memcpy(scan->direct_scan[p].ssid,
409 priv->scan_request->ssids[i].ssid,
410 priv->scan_request->ssids[i].ssid_len);
411 n_probes++;
412 p++;
413 }
414 is_active = true;
415 } else
416 IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
417 break;
418 case IWL_SCAN_ROC:
419 IWL_DEBUG_SCAN(priv, "Start ROC scan.\n");
420 break;
421 }
422
423 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
424 scan->tx_cmd.sta_id = ctx->bcast_sta_id;
425 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
426
427 switch (priv->scan_band) {
428 case IEEE80211_BAND_2GHZ:
429 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
430 chan_mod = le32_to_cpu(
431 priv->contexts[IWL_RXON_CTX_BSS].active.flags &
432 RXON_FLG_CHANNEL_MODE_MSK)
433 >> RXON_FLG_CHANNEL_MODE_POS;
434 if (chan_mod == CHANNEL_MODE_PURE_40) {
435 rate = IWL_RATE_6M_PLCP;
436 } else {
437 rate = IWL_RATE_1M_PLCP;
438 rate_flags = RATE_MCS_CCK_MSK;
439 }
440 /*
441 * Internal scans are passive, so we can indiscriminately set
442 * the BT ignore flag on 2.4 GHz since it applies to TX only.
443 */
444 if (priv->cfg->bt_params &&
445 priv->cfg->bt_params->advanced_bt_coexist)
446 scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
447 break;
448 case IEEE80211_BAND_5GHZ:
449 rate = IWL_RATE_6M_PLCP;
450 break;
451 default:
452 IWL_WARN(priv, "Invalid scan band\n");
453 return -EIO;
454 }
455
456 /*
457 * If active scanning is requested but a certain channel is
458 * marked passive, we can do active scanning if we detect
459 * transmissions.
460 *
461 * There is an issue with some firmware versions that triggers
462 * a sysassert on a "good CRC threshold" of zero (== disabled),
463 * on a radar channel even though this means that we should NOT
464 * send probes.
465 *
466 * The "good CRC threshold" is the number of frames that we
467 * need to receive during our dwell time on a channel before
468 * sending out probes -- setting this to a huge value will
469 * mean we never reach it, but at the same time work around
470 * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
471 * here instead of IWL_GOOD_CRC_TH_DISABLED.
472 *
473 * This was fixed in later versions along with some other
474 * scan changes, and the threshold behaves as a flag in those
475 * versions.
476 */
477 if (priv->new_scan_threshold_behaviour)
478 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
479 IWL_GOOD_CRC_TH_DISABLED;
480 else
481 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
482 IWL_GOOD_CRC_TH_NEVER;
483
484 band = priv->scan_band;
485
486 if (priv->cfg->scan_rx_antennas[band])
487 rx_ant = priv->cfg->scan_rx_antennas[band];
488
489 if (band == IEEE80211_BAND_2GHZ &&
490 priv->cfg->bt_params &&
491 priv->cfg->bt_params->advanced_bt_coexist) {
492 /* transmit 2.4 GHz probes only on first antenna */
493 scan_tx_antennas = first_antenna(scan_tx_antennas);
494 }
495
496 priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band],
497 scan_tx_antennas);
498 rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
499 scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
500
501 /* In power save mode use one chain, otherwise use all chains */
502 if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) {
503 /* rx_ant has been set to all valid chains previously */
504 active_chains = rx_ant &
505 ((u8)(priv->chain_noise_data.active_chains));
506 if (!active_chains)
507 active_chains = rx_ant;
508
509 IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
510 priv->chain_noise_data.active_chains);
511
512 rx_ant = first_antenna(active_chains);
513 }
514 if (priv->cfg->bt_params &&
515 priv->cfg->bt_params->advanced_bt_coexist &&
516 priv->bt_full_concurrent) {
517 /* operated as 1x1 in full concurrency mode */
518 rx_ant = first_antenna(rx_ant);
519 }
520
521 /* MIMO is not used here, but value is required */
522 rx_chain |=
523 hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
524 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
525 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
526 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
527 scan->rx_chain = cpu_to_le16(rx_chain);
528 switch (priv->scan_type) {
529 case IWL_SCAN_NORMAL:
530 cmd_len = iwl_fill_probe_req(priv,
531 (struct ieee80211_mgmt *)scan->data,
532 vif->addr,
533 priv->scan_request->ie,
534 priv->scan_request->ie_len,
535 IWL_MAX_SCAN_SIZE - sizeof(*scan));
536 break;
537 case IWL_SCAN_RADIO_RESET:
538 case IWL_SCAN_ROC:
539 /* use bcast addr, will not be transmitted but must be valid */
540 cmd_len = iwl_fill_probe_req(priv,
541 (struct ieee80211_mgmt *)scan->data,
542 iwl_bcast_addr, NULL, 0,
543 IWL_MAX_SCAN_SIZE - sizeof(*scan));
544 break;
545 default:
546 BUG();
547 }
548 scan->tx_cmd.len = cpu_to_le16(cmd_len);
549
550 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
551 RXON_FILTER_BCON_AWARE_MSK);
552
553 switch (priv->scan_type) {
554 case IWL_SCAN_RADIO_RESET:
555 scan->channel_count =
556 iwl_get_single_channel_for_scan(priv, vif, band,
557 (void *)&scan->data[cmd_len]);
558 break;
559 case IWL_SCAN_NORMAL:
560 scan->channel_count =
561 iwl_get_channels_for_scan(priv, vif, band,
562 is_active, n_probes,
563 (void *)&scan->data[cmd_len]);
564 break;
565 case IWL_SCAN_ROC: {
566 struct iwl_scan_channel *scan_ch;
567
568 scan->channel_count = 1;
569
570 scan_ch = (void *)&scan->data[cmd_len];
571 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
572 scan_ch->channel =
573 cpu_to_le16(priv->hw_roc_channel->hw_value);
574 scan_ch->active_dwell =
575 scan_ch->passive_dwell =
576 cpu_to_le16(priv->hw_roc_duration);
577
578 /* Set txpower levels to defaults */
579 scan_ch->dsp_atten = 110;
580
581 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
582 * power level:
583 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
584 */
585 if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
586 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
587 else
588 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
589 }
590 break;
591 }
592
593 if (scan->channel_count == 0) {
594 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
595 return -EIO;
596 }
597
598 cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
599 scan->channel_count * sizeof(struct iwl_scan_channel);
600 cmd.data[0] = scan;
601 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
602 scan->len = cpu_to_le16(cmd.len[0]);
603
604 /* set scan bit here for PAN params */
605 set_bit(STATUS_SCAN_HW, &priv->shrd->status);
606
607 ret = iwlagn_set_pan_params(priv);
608 if (ret)
609 return ret;
610
611 ret = iwl_trans_send_cmd(trans(priv), &cmd);
612 if (ret) {
613 clear_bit(STATUS_SCAN_HW, &priv->shrd->status);
614 iwlagn_set_pan_params(priv);
615 }
616
617 return ret;
618}
619
620int iwlagn_manage_ibss_station(struct iwl_priv *priv, 193int iwlagn_manage_ibss_station(struct iwl_priv *priv,
621 struct ieee80211_vif *vif, bool add) 194 struct ieee80211_vif *vif, bool add)
622{ 195{
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/iwl-agn.h
index 4bc1f4669e5a..5c4f8c72ee60 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.h
@@ -146,7 +146,6 @@ static inline bool iwl_is_tx_success(u32 status)
146u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid); 146u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid);
147 147
148/* scan */ 148/* scan */
149int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif);
150void iwlagn_post_scan(struct iwl_priv *priv); 149void iwlagn_post_scan(struct iwl_priv *priv);
151void iwlagn_disable_roc(struct iwl_priv *priv); 150void iwlagn_disable_roc(struct iwl_priv *priv);
152 151
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index 6d7ad45c6d6f..74d4cff09fae 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -330,12 +330,6 @@ int iwl_force_reset(struct iwl_priv *priv, int mode, bool external);
330u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, 330u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
331 const u8 *ta, const u8 *ie, int ie_len, int left); 331 const u8 *ta, const u8 *ie, int ie_len, int left);
332void iwl_setup_rx_scan_handlers(struct iwl_priv *priv); 332void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
333u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
334 enum ieee80211_band band,
335 u8 n_probes);
336u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
337 enum ieee80211_band band,
338 struct ieee80211_vif *vif);
339void iwl_setup_scan_deferred_work(struct iwl_priv *priv); 333void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
340void iwl_cancel_scan_deferred_work(struct iwl_priv *priv); 334void iwl_cancel_scan_deferred_work(struct iwl_priv *priv);
341int __must_check iwl_scan_initiate(struct iwl_priv *priv, 335int __must_check iwl_scan_initiate(struct iwl_priv *priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index fc5af3475392..8ac6b05c6c78 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -299,9 +299,8 @@ void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
299 iwl_rx_scan_complete_notif; 299 iwl_rx_scan_complete_notif;
300} 300}
301 301
302inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv, 302static u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
303 enum ieee80211_band band, 303 enum ieee80211_band band, u8 n_probes)
304 u8 n_probes)
305{ 304{
306 if (band == IEEE80211_BAND_5GHZ) 305 if (band == IEEE80211_BAND_5GHZ)
307 return IWL_ACTIVE_DWELL_TIME_52 + 306 return IWL_ACTIVE_DWELL_TIME_52 +
@@ -311,9 +310,8 @@ inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
311 IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); 310 IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
312} 311}
313 312
314u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, 313static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
315 enum ieee80211_band band, 314 enum ieee80211_band band)
316 struct ieee80211_vif *vif)
317{ 315{
318 struct iwl_rxon_context *ctx; 316 struct iwl_rxon_context *ctx;
319 u16 passive = (band == IEEE80211_BAND_2GHZ) ? 317 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
@@ -342,6 +340,435 @@ u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
342 return passive; 340 return passive;
343} 341}
344 342
343static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
344 struct ieee80211_vif *vif,
345 enum ieee80211_band band,
346 struct iwl_scan_channel *scan_ch)
347{
348 const struct ieee80211_supported_band *sband;
349 u16 passive_dwell = 0;
350 u16 active_dwell = 0;
351 int added = 0;
352 u16 channel = 0;
353
354 sband = iwl_get_hw_mode(priv, band);
355 if (!sband) {
356 IWL_ERR(priv, "invalid band\n");
357 return added;
358 }
359
360 active_dwell = iwl_get_active_dwell_time(priv, band, 0);
361 passive_dwell = iwl_get_passive_dwell_time(priv, band);
362
363 if (passive_dwell <= active_dwell)
364 passive_dwell = active_dwell + 1;
365
366 channel = iwl_get_single_channel_number(priv, band);
367 if (channel) {
368 scan_ch->channel = cpu_to_le16(channel);
369 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
370 scan_ch->active_dwell = cpu_to_le16(active_dwell);
371 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
372 /* Set txpower levels to defaults */
373 scan_ch->dsp_atten = 110;
374 if (band == IEEE80211_BAND_5GHZ)
375 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
376 else
377 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
378 added++;
379 } else
380 IWL_ERR(priv, "no valid channel found\n");
381 return added;
382}
383
384static int iwl_get_channels_for_scan(struct iwl_priv *priv,
385 struct ieee80211_vif *vif,
386 enum ieee80211_band band,
387 u8 is_active, u8 n_probes,
388 struct iwl_scan_channel *scan_ch)
389{
390 struct ieee80211_channel *chan;
391 const struct ieee80211_supported_band *sband;
392 const struct iwl_channel_info *ch_info;
393 u16 passive_dwell = 0;
394 u16 active_dwell = 0;
395 int added, i;
396 u16 channel;
397
398 sband = iwl_get_hw_mode(priv, band);
399 if (!sband)
400 return 0;
401
402 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
403 passive_dwell = iwl_get_passive_dwell_time(priv, band);
404
405 if (passive_dwell <= active_dwell)
406 passive_dwell = active_dwell + 1;
407
408 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
409 chan = priv->scan_request->channels[i];
410
411 if (chan->band != band)
412 continue;
413
414 channel = chan->hw_value;
415 scan_ch->channel = cpu_to_le16(channel);
416
417 ch_info = iwl_get_channel_info(priv, band, channel);
418 if (!is_channel_valid(ch_info)) {
419 IWL_DEBUG_SCAN(priv,
420 "Channel %d is INVALID for this band.\n",
421 channel);
422 continue;
423 }
424
425 if (!is_active || is_channel_passive(ch_info) ||
426 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
427 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
428 else
429 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
430
431 if (n_probes)
432 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
433
434 scan_ch->active_dwell = cpu_to_le16(active_dwell);
435 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
436
437 /* Set txpower levels to defaults */
438 scan_ch->dsp_atten = 110;
439
440 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
441 * power level:
442 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
443 */
444 if (band == IEEE80211_BAND_5GHZ)
445 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
446 else
447 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
448
449 IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
450 channel, le32_to_cpu(scan_ch->type),
451 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
452 "ACTIVE" : "PASSIVE",
453 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
454 active_dwell : passive_dwell);
455
456 scan_ch++;
457 added++;
458 }
459
460 IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
461 return added;
462}
463
464static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
465{
466 struct iwl_host_cmd cmd = {
467 .id = REPLY_SCAN_CMD,
468 .len = { sizeof(struct iwl_scan_cmd), },
469 .flags = CMD_SYNC,
470 };
471 struct iwl_scan_cmd *scan;
472 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
473 u32 rate_flags = 0;
474 u16 cmd_len;
475 u16 rx_chain = 0;
476 enum ieee80211_band band;
477 u8 n_probes = 0;
478 u8 rx_ant = hw_params(priv).valid_rx_ant;
479 u8 rate;
480 bool is_active = false;
481 int chan_mod;
482 u8 active_chains;
483 u8 scan_tx_antennas = hw_params(priv).valid_tx_ant;
484 int ret;
485
486 lockdep_assert_held(&priv->shrd->mutex);
487
488 if (vif)
489 ctx = iwl_rxon_ctx_from_vif(vif);
490
491 if (!priv->scan_cmd) {
492 priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
493 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
494 if (!priv->scan_cmd) {
495 IWL_DEBUG_SCAN(priv,
496 "fail to allocate memory for scan\n");
497 return -ENOMEM;
498 }
499 }
500 scan = priv->scan_cmd;
501 memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
502
503 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
504 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
505
506 if (priv->scan_type != IWL_SCAN_ROC &&
507 iwl_is_any_associated(priv)) {
508 u16 interval = 0;
509 u32 extra;
510 u32 suspend_time = 100;
511 u32 scan_suspend_time = 100;
512
513 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
514 switch (priv->scan_type) {
515 case IWL_SCAN_ROC:
516 WARN_ON(1);
517 break;
518 case IWL_SCAN_RADIO_RESET:
519 interval = 0;
520 break;
521 case IWL_SCAN_NORMAL:
522 interval = vif->bss_conf.beacon_int;
523 break;
524 }
525
526 scan->suspend_time = 0;
527 scan->max_out_time = cpu_to_le32(200 * 1024);
528 if (!interval)
529 interval = suspend_time;
530
531 extra = (suspend_time / interval) << 22;
532 scan_suspend_time = (extra |
533 ((suspend_time % interval) * 1024));
534 scan->suspend_time = cpu_to_le32(scan_suspend_time);
535 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
536 scan_suspend_time, interval);
537 } else if (priv->scan_type == IWL_SCAN_ROC) {
538 scan->suspend_time = 0;
539 scan->max_out_time = 0;
540 scan->quiet_time = 0;
541 scan->quiet_plcp_th = 0;
542 }
543
544 switch (priv->scan_type) {
545 case IWL_SCAN_RADIO_RESET:
546 IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
547 break;
548 case IWL_SCAN_NORMAL:
549 if (priv->scan_request->n_ssids) {
550 int i, p = 0;
551 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
552 for (i = 0; i < priv->scan_request->n_ssids; i++) {
553 /* always does wildcard anyway */
554 if (!priv->scan_request->ssids[i].ssid_len)
555 continue;
556 scan->direct_scan[p].id = WLAN_EID_SSID;
557 scan->direct_scan[p].len =
558 priv->scan_request->ssids[i].ssid_len;
559 memcpy(scan->direct_scan[p].ssid,
560 priv->scan_request->ssids[i].ssid,
561 priv->scan_request->ssids[i].ssid_len);
562 n_probes++;
563 p++;
564 }
565 is_active = true;
566 } else
567 IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
568 break;
569 case IWL_SCAN_ROC:
570 IWL_DEBUG_SCAN(priv, "Start ROC scan.\n");
571 break;
572 }
573
574 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
575 scan->tx_cmd.sta_id = ctx->bcast_sta_id;
576 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
577
578 switch (priv->scan_band) {
579 case IEEE80211_BAND_2GHZ:
580 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
581 chan_mod = le32_to_cpu(
582 priv->contexts[IWL_RXON_CTX_BSS].active.flags &
583 RXON_FLG_CHANNEL_MODE_MSK)
584 >> RXON_FLG_CHANNEL_MODE_POS;
585 if (chan_mod == CHANNEL_MODE_PURE_40) {
586 rate = IWL_RATE_6M_PLCP;
587 } else {
588 rate = IWL_RATE_1M_PLCP;
589 rate_flags = RATE_MCS_CCK_MSK;
590 }
591 /*
592 * Internal scans are passive, so we can indiscriminately set
593 * the BT ignore flag on 2.4 GHz since it applies to TX only.
594 */
595 if (priv->cfg->bt_params &&
596 priv->cfg->bt_params->advanced_bt_coexist)
597 scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
598 break;
599 case IEEE80211_BAND_5GHZ:
600 rate = IWL_RATE_6M_PLCP;
601 break;
602 default:
603 IWL_WARN(priv, "Invalid scan band\n");
604 return -EIO;
605 }
606
607 /*
608 * If active scanning is requested but a certain channel is
609 * marked passive, we can do active scanning if we detect
610 * transmissions.
611 *
612 * There is an issue with some firmware versions that triggers
613 * a sysassert on a "good CRC threshold" of zero (== disabled),
614 * on a radar channel even though this means that we should NOT
615 * send probes.
616 *
617 * The "good CRC threshold" is the number of frames that we
618 * need to receive during our dwell time on a channel before
619 * sending out probes -- setting this to a huge value will
620 * mean we never reach it, but at the same time work around
621 * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
622 * here instead of IWL_GOOD_CRC_TH_DISABLED.
623 *
624 * This was fixed in later versions along with some other
625 * scan changes, and the threshold behaves as a flag in those
626 * versions.
627 */
628 if (priv->new_scan_threshold_behaviour)
629 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
630 IWL_GOOD_CRC_TH_DISABLED;
631 else
632 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
633 IWL_GOOD_CRC_TH_NEVER;
634
635 band = priv->scan_band;
636
637 if (priv->cfg->scan_rx_antennas[band])
638 rx_ant = priv->cfg->scan_rx_antennas[band];
639
640 if (band == IEEE80211_BAND_2GHZ &&
641 priv->cfg->bt_params &&
642 priv->cfg->bt_params->advanced_bt_coexist) {
643 /* transmit 2.4 GHz probes only on first antenna */
644 scan_tx_antennas = first_antenna(scan_tx_antennas);
645 }
646
647 priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv,
648 priv->scan_tx_ant[band],
649 scan_tx_antennas);
650 rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
651 scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
652
653 /* In power save mode use one chain, otherwise use all chains */
654 if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) {
655 /* rx_ant has been set to all valid chains previously */
656 active_chains = rx_ant &
657 ((u8)(priv->chain_noise_data.active_chains));
658 if (!active_chains)
659 active_chains = rx_ant;
660
661 IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
662 priv->chain_noise_data.active_chains);
663
664 rx_ant = first_antenna(active_chains);
665 }
666 if (priv->cfg->bt_params &&
667 priv->cfg->bt_params->advanced_bt_coexist &&
668 priv->bt_full_concurrent) {
669 /* operated as 1x1 in full concurrency mode */
670 rx_ant = first_antenna(rx_ant);
671 }
672
673 /* MIMO is not used here, but value is required */
674 rx_chain |=
675 hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
676 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
677 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
678 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
679 scan->rx_chain = cpu_to_le16(rx_chain);
680 switch (priv->scan_type) {
681 case IWL_SCAN_NORMAL:
682 cmd_len = iwl_fill_probe_req(priv,
683 (struct ieee80211_mgmt *)scan->data,
684 vif->addr,
685 priv->scan_request->ie,
686 priv->scan_request->ie_len,
687 IWL_MAX_SCAN_SIZE - sizeof(*scan));
688 break;
689 case IWL_SCAN_RADIO_RESET:
690 case IWL_SCAN_ROC:
691 /* use bcast addr, will not be transmitted but must be valid */
692 cmd_len = iwl_fill_probe_req(priv,
693 (struct ieee80211_mgmt *)scan->data,
694 iwl_bcast_addr, NULL, 0,
695 IWL_MAX_SCAN_SIZE - sizeof(*scan));
696 break;
697 default:
698 BUG();
699 }
700 scan->tx_cmd.len = cpu_to_le16(cmd_len);
701
702 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
703 RXON_FILTER_BCON_AWARE_MSK);
704
705 switch (priv->scan_type) {
706 case IWL_SCAN_RADIO_RESET:
707 scan->channel_count =
708 iwl_get_single_channel_for_scan(priv, vif, band,
709 (void *)&scan->data[cmd_len]);
710 break;
711 case IWL_SCAN_NORMAL:
712 scan->channel_count =
713 iwl_get_channels_for_scan(priv, vif, band,
714 is_active, n_probes,
715 (void *)&scan->data[cmd_len]);
716 break;
717 case IWL_SCAN_ROC: {
718 struct iwl_scan_channel *scan_ch;
719
720 scan->channel_count = 1;
721
722 scan_ch = (void *)&scan->data[cmd_len];
723 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
724 scan_ch->channel =
725 cpu_to_le16(priv->hw_roc_channel->hw_value);
726 scan_ch->active_dwell =
727 scan_ch->passive_dwell =
728 cpu_to_le16(priv->hw_roc_duration);
729
730 /* Set txpower levels to defaults */
731 scan_ch->dsp_atten = 110;
732
733 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
734 * power level:
735 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
736 */
737 if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
738 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
739 else
740 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
741 }
742 break;
743 }
744
745 if (scan->channel_count == 0) {
746 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
747 return -EIO;
748 }
749
750 cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
751 scan->channel_count * sizeof(struct iwl_scan_channel);
752 cmd.data[0] = scan;
753 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
754 scan->len = cpu_to_le16(cmd.len[0]);
755
756 /* set scan bit here for PAN params */
757 set_bit(STATUS_SCAN_HW, &priv->shrd->status);
758
759 ret = iwlagn_set_pan_params(priv);
760 if (ret)
761 return ret;
762
763 ret = iwl_trans_send_cmd(trans(priv), &cmd);
764 if (ret) {
765 clear_bit(STATUS_SCAN_HW, &priv->shrd->status);
766 iwlagn_set_pan_params(priv);
767 }
768
769 return ret;
770}
771
345void iwl_init_scan_params(struct iwl_priv *priv) 772void iwl_init_scan_params(struct iwl_priv *priv)
346{ 773{
347 u8 ant_idx = fls(hw_params(priv).valid_tx_ant) - 1; 774 u8 ant_idx = fls(hw_params(priv).valid_tx_ant) - 1;