802.11: clean up/fix HT support
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-scan.c
index 5b420b4..78d16bd 100644 (file)
 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  * sending probe req.  This should be set long enough to hear probe responses
  * from more than one AP.  */
-#define IWL_ACTIVE_DWELL_TIME_24    (20)       /* all times in msec */
-#define IWL_ACTIVE_DWELL_TIME_52    (10)
+#define IWL_ACTIVE_DWELL_TIME_24    (30)       /* all times in msec */
+#define IWL_ACTIVE_DWELL_TIME_52    (20)
+
+#define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
+#define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
 
 /* For faster active scanning, scan will move to the next channel if fewer than
  * PLCP_QUIET_THRESH packets are heard on this channel within
@@ -48,7 +51,7 @@
  * no other traffic).
  * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
 #define IWL_PLCP_QUIET_THRESH       __constant_cpu_to_le16(1)  /* packets */
-#define IWL_ACTIVE_QUIET_TIME       __constant_cpu_to_le16(5)  /* msec */
+#define IWL_ACTIVE_QUIET_TIME       __constant_cpu_to_le16(10)  /* msec */
 
 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  * Must be set longer than active dwell time.
 #define IWL_PASSIVE_DWELL_BASE      (100)
 #define IWL_CHANNEL_TUNE_TIME       5
 
+#define IWL_SCAN_PROBE_MASK(n)         cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
+
+
 static int scan_tx_ant[3] = {
        RATE_MCS_ANT_A_MSK, RATE_MCS_ANT_B_MSK, RATE_MCS_ANT_C_MSK
 };
 
+
+
 static int iwl_is_empty_essid(const char *essid, int essid_len)
 {
        /* Single white space is for Linksys APs */
@@ -80,7 +88,7 @@ static int iwl_is_empty_essid(const char *essid, int essid_len)
 
 
 
-const char *iwl_escape_essid(const char *essid, u8 essid_len)
+static const char *iwl_escape_essid(const char *essid, u8 essid_len)
 {
        static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
        const char *s = essid;
@@ -103,7 +111,6 @@ const char *iwl_escape_essid(const char *essid, u8 essid_len)
        *d = '\0';
        return escaped;
 }
-EXPORT_SYMBOL(iwl_escape_essid);
 
 /**
  * iwl_scan_cancel - Cancel any currently executing HW scan
@@ -194,6 +201,7 @@ static int iwl_send_scan_abort(struct iwl_priv *priv)
                clear_bit(STATUS_SCAN_HW, &priv->status);
        }
 
+       priv->alloc_rxb_skb--;
        dev_kfree_skb_any(cmd.meta.u.skb);
 
        return ret;
@@ -226,8 +234,9 @@ static void iwl_rx_scan_start_notif(struct iwl_priv *priv,
                       "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
                       notif->channel,
                       notif->band ? "bg" : "a",
-                      notif->tsf_high,
-                      notif->tsf_low, notif->status, notif->beacon_timer);
+                      le32_to_cpu(notif->tsf_high),
+                      le32_to_cpu(notif->tsf_low),
+                      notif->status, notif->beacon_timer);
 }
 
 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
@@ -261,6 +270,7 @@ static void iwl_rx_scan_results_notif(struct iwl_priv *priv,
 static void iwl_rx_scan_complete_notif(struct iwl_priv *priv,
                                       struct iwl_rx_mem_buffer *rxb)
 {
+#ifdef CONFIG_IWLWIFI_DEBUG
        struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
 
@@ -268,6 +278,7 @@ static void iwl_rx_scan_complete_notif(struct iwl_priv *priv,
                       scan_notif->scanned_channels,
                       scan_notif->tsf_low,
                       scan_notif->tsf_high, scan_notif->status);
+#endif
 
        /* The HW is no longer scanning */
        clear_bit(STATUS_SCAN_HW, &priv->status);
@@ -332,19 +343,21 @@ void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
 EXPORT_SYMBOL(iwl_setup_rx_scan_handlers);
 
 static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
-                                               enum ieee80211_band band)
+                                           enum ieee80211_band band,
+                                           u8 n_probes)
 {
        if (band == IEEE80211_BAND_5GHZ)
-               return IWL_ACTIVE_DWELL_TIME_52;
+               return IWL_ACTIVE_DWELL_TIME_52 +
+                       IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
        else
-               return IWL_ACTIVE_DWELL_TIME_24;
+               return IWL_ACTIVE_DWELL_TIME_24 +
+                       IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
 }
 
 static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
-                                         enum ieee80211_band band)
+                                     enum ieee80211_band band)
 {
-       u16 active = iwl_get_active_dwell_time(priv, band);
-       u16 passive = (band != IEEE80211_BAND_5GHZ) ?
+       u16 passive = (band == IEEE80211_BAND_2GHZ) ?
            IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
            IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
 
@@ -358,15 +371,12 @@ static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
                passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
        }
 
-       if (passive <= active)
-               passive = active + 1;
-
        return passive;
 }
 
 static int iwl_get_channels_for_scan(struct iwl_priv *priv,
                                     enum ieee80211_band band,
-                                    u8 is_active, u8 direct_mask,
+                                    u8 is_active, u8 n_probes,
                                     struct iwl_scan_channel *scan_ch)
 {
        const struct ieee80211_channel *channels = NULL;
@@ -375,6 +385,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
        u16 passive_dwell = 0;
        u16 active_dwell = 0;
        int added, i;
+       u16 channel;
 
        sband = iwl_get_hw_mode(priv, band);
        if (!sband)
@@ -382,31 +393,35 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
 
        channels = sband->channels;
 
-       active_dwell = iwl_get_active_dwell_time(priv, band);
+       active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
        passive_dwell = iwl_get_passive_dwell_time(priv, band);
 
+       if (passive_dwell <= active_dwell)
+               passive_dwell = active_dwell + 1;
+
        for (i = 0, added = 0; i < sband->n_channels; i++) {
                if (channels[i].flags & IEEE80211_CHAN_DISABLED)
                        continue;
 
-               scan_ch->channel =
+               channel =
                        ieee80211_frequency_to_channel(channels[i].center_freq);
+               scan_ch->channel = cpu_to_le16(channel);
 
-               ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
+               ch_info = iwl_get_channel_info(priv, band, channel);
                if (!is_channel_valid(ch_info)) {
                        IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
-                                      scan_ch->channel);
+                                       channel);
                        continue;
                }
 
                if (!is_active || is_channel_passive(ch_info) ||
                    (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
-                       scan_ch->type = 0;
+                       scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
                else
-                       scan_ch->type = 1;
+                       scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
 
-               if (scan_ch->type & 1)
-                       scan_ch->type |= (direct_mask << 1);
+               if (n_probes)
+                       scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
 
                scan_ch->active_dwell = cpu_to_le16(active_dwell);
                scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
@@ -414,20 +429,20 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
                /* Set txpower levels to defaults */
                scan_ch->dsp_atten = 110;
 
+               /* NOTE: if we were doing 6Mb OFDM for scans we'd use
+                * power level:
+                * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
+                */
                if (band == IEEE80211_BAND_5GHZ)
                        scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
-               else {
+               else
                        scan_ch->tx_gain = ((1 << 5) | (5 << 3));
-                       /* NOTE: if we were doing 6Mb OFDM for scans we'd use
-                        * power level:
-                        * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
-                        */
-               }
 
-               IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
-                              scan_ch->channel,
-                              (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
-                              (scan_ch->type & 1) ?
+               IWL_DEBUG_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n",
+                              channel, le32_to_cpu(scan_ch->type),
+                              (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
+                               "ACTIVE" : "PASSIVE",
+                              (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
                               active_dwell : passive_dwell);
 
                scan_ch++;
@@ -448,11 +463,6 @@ void iwl_init_scan_params(struct iwl_priv *priv)
 
 int iwl_scan_initiate(struct iwl_priv *priv)
 {
-       if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
-               IWL_ERROR("APs don't scan.\n");
-               return 0;
-       }
-
        if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
                return -EIO;
@@ -464,8 +474,7 @@ int iwl_scan_initiate(struct iwl_priv *priv)
        }
 
        if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
-               IWL_DEBUG_SCAN("Scan request while abort pending.  "
-                              "Queuing.\n");
+               IWL_DEBUG_SCAN("Scan request while abort pending\n");
                return -EAGAIN;
        }
 
@@ -541,7 +550,7 @@ static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
 {
        struct ieee80211_ht_cap *ht_cap;
 
-       if (!sband || !sband->ht_info.ht_supported)
+       if (!sband || !sband->ht_cap.ht_supported)
                return;
 
        if (*left < sizeof(struct ieee80211_ht_cap))
@@ -550,12 +559,12 @@ static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
        *pos++ = sizeof(struct ieee80211_ht_cap);
        ht_cap = (struct ieee80211_ht_cap *) pos;
 
-       ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
-       memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
+       ht_cap->cap_info = cpu_to_le16(sband->ht_cap.cap);
+       memcpy(&ht_cap->mcs, &sband->ht_cap.mcs, 16);
        ht_cap->ampdu_params_info =
-               (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
-               ((sband->ht_info.ampdu_density << 2) &
-                       IEEE80211_HT_CAP_AMPDU_DENSITY);
+               (sband->ht_cap.ampdu_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) |
+               ((sband->ht_cap.ampdu_density << 2) &
+                       IEEE80211_HT_AMPDU_PARM_DENSITY);
        *left -= sizeof(struct ieee80211_ht_cap);
 }
 
@@ -673,7 +682,7 @@ static u32 iwl_scan_tx_ant(struct iwl_priv *priv, enum ieee80211_band band)
                        break;
                }
        }
-
+       IWL_DEBUG_SCAN("select TX ANT = %c\n", 'A' + ind);
        return scan_tx_ant[ind];
 }
 
@@ -693,8 +702,8 @@ static void iwl_bg_request_scan(struct work_struct *data)
        u32 tx_ant;
        u16 cmd_len;
        enum ieee80211_band band;
-       u8 direct_mask;
-       u8 rx_chain = 0x7; /* bitmap: ABC chains */
+       u8 n_probes = 2;
+       u8 rx_chain = priv->hw_params.valid_rx_ant;
 
        conf = ieee80211_get_hw_conf(priv->hw);
 
@@ -793,17 +802,16 @@ static void iwl_bg_request_scan(struct work_struct *data)
                scan->direct_scan[0].len = priv->direct_ssid_len;
                memcpy(scan->direct_scan[0].ssid,
                       priv->direct_ssid, priv->direct_ssid_len);
-               direct_mask = 1;
+               n_probes++;
        } else if (!iwl_is_associated(priv) && priv->essid_len) {
                IWL_DEBUG_SCAN("Start direct scan for '%s' (not associated)\n",
                                iwl_escape_essid(priv->essid, priv->essid_len));
                scan->direct_scan[0].id = WLAN_EID_SSID;
                scan->direct_scan[0].len = priv->essid_len;
                memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
-               direct_mask = 1;
+               n_probes++;
        } else {
                IWL_DEBUG_SCAN("Start indirect scan.\n");
-               direct_mask = 0;
        }
 
        scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
@@ -835,7 +843,7 @@ static void iwl_bg_request_scan(struct work_struct *data)
 
                /* Force use of chains B and C (0x6) for scan Rx for 4965
                 * Avoid A (0x1) because of its off-channel reception on A-band.
-                * MIMO is not used here, but value is required */
+                */
                if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
                        rx_chain = 0x6;
        } else {
@@ -843,6 +851,7 @@ static void iwl_bg_request_scan(struct work_struct *data)
                goto done;
        }
 
+       /* MIMO is not used here, but value is required */
        scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
                                cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
                                (rx_chain << RXON_RX_CHAIN_FORCE_SEL_POS) |
@@ -854,22 +863,17 @@ static void iwl_bg_request_scan(struct work_struct *data)
 
        scan->tx_cmd.len = cpu_to_le16(cmd_len);
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
+       if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
                scan->filter_flags = RXON_FILTER_PROMISC_MSK;
 
        scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
                               RXON_FILTER_BCON_AWARE_MSK);
 
-       if (direct_mask)
-               scan->channel_count =
-                       iwl_get_channels_for_scan(priv, band, 1, /* active */
-                                                 direct_mask,
-                               (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
-       else
-               scan->channel_count =
-                       iwl_get_channels_for_scan(priv, band, 0, /* passive */
-                                                 direct_mask,
-                               (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
+       scan->channel_count =
+               iwl_get_channels_for_scan(priv, band, 1, /* active */
+                       n_probes,
+                       (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
+
        if (scan->channel_count == 0) {
                IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
                goto done;
@@ -912,10 +916,29 @@ static void iwl_bg_abort_scan(struct work_struct *work)
        mutex_unlock(&priv->mutex);
 }
 
+static void iwl_bg_scan_completed(struct work_struct *work)
+{
+       struct iwl_priv *priv =
+           container_of(work, struct iwl_priv, scan_completed);
+
+       IWL_DEBUG_SCAN("SCAN complete scan\n");
+
+       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
+               return;
+
+       ieee80211_scan_completed(priv->hw);
+
+       /* Since setting the TXPOWER may have been deferred while
+        * performing the scan, fire one off */
+       mutex_lock(&priv->mutex);
+       iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
+       mutex_unlock(&priv->mutex);
+}
+
+
 void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
 {
-       /*  FIXME: move here when resolved PENDING
-        *  INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); */
+       INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
        INIT_WORK(&priv->request_scan, iwl_bg_request_scan);
        INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
        INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);