Merge branch 'fixes-davem' of git://git.kernel.org/pub/scm/linux/kernel/git/linville...
[sfrench/cifs-2.6.git] / drivers / net / wireless / iwlwifi / iwl4965-base.c
index 5a8342664af193994ce3a34b3e15c1e5f510d3d2..9918780f5e866fe8286fb85c970b815c981b4968 100644 (file)
@@ -48,8 +48,6 @@
 #include <linux/netdevice.h>
 #include <linux/wireless.h>
 #include <linux/firmware.h>
-#include <linux/skbuff.h>
-#include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/if_arp.h>
 
@@ -1802,21 +1800,22 @@ static void iwl_unset_hw_setting(struct iwl_priv *priv)
  * return : set the bit for each supported rate insert in ie
  */
 static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate,
-                                   u16 basic_rate, int max_count)
+                                   u16 basic_rate, int *left)
 {
        u16 ret_rates = 0, bit;
        int i;
-       u8 *rates;
-
-       rates = &(ie[1]);
+       u8 *cnt = ie;
+       u8 *rates = ie + 1;
 
        for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
                if (bit & supported_rate) {
                        ret_rates |= bit;
-                       rates[*ie] = iwl_rates[i].ieee |
-                           ((bit & basic_rate) ? 0x80 : 0x00);
-                       *ie = *ie + 1;
-                       if (*ie >= max_count)
+                       rates[*cnt] = iwl_rates[i].ieee |
+                               ((bit & basic_rate) ? 0x80 : 0x00);
+                       (*cnt)++;
+                       (*left)--;
+                       if ((*left <= 0) ||
+                           (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
                                break;
                }
        }
@@ -1839,7 +1838,7 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv,
 {
        int len = 0;
        u8 *pos = NULL;
-       u16 ret_rates;
+       u16 active_rates, ret_rates, cck_rates;
 
        /* Make sure there is enough space for the probe request,
         * two mandatory IEs and the data */
@@ -1884,19 +1883,27 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv,
        left -= 2;
        if (left < 0)
                return 0;
+
        /* ... fill it in... */
        *pos++ = WLAN_EID_SUPP_RATES;
        *pos = 0;
-       ret_rates = priv->active_rate = priv->rates_mask;
+
+       priv->active_rate = priv->rates_mask;
+       active_rates = priv->active_rate;
        priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
 
-       iwl_supported_rate_to_ie(pos, priv->active_rate,
-                                priv->active_rate_basic, left);
+       cck_rates = IWL_CCK_RATES_MASK & active_rates;
+       ret_rates = iwl_supported_rate_to_ie(pos, cck_rates,
+                       priv->active_rate_basic, &left);
+       active_rates &= ~ret_rates;
+
+       ret_rates = iwl_supported_rate_to_ie(pos, active_rates,
+                                priv->active_rate_basic, &left);
+       active_rates &= ~ret_rates;
+
        len += 2 + *pos;
        pos += (*pos) + 1;
-       ret_rates = ~ret_rates & priv->active_rate;
-
-       if (ret_rates == 0)
+       if (active_rates == 0)
                goto fill_end;
 
        /* fill in supported extended rate */
@@ -1907,7 +1914,8 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv,
        /* ... fill it in... */
        *pos++ = WLAN_EID_EXT_SUPP_RATES;
        *pos = 0;
-       iwl_supported_rate_to_ie(pos, ret_rates, priv->active_rate_basic, left);
+       iwl_supported_rate_to_ie(pos, active_rates,
+                                priv->active_rate_basic, &left);
        if (*pos > 0)
                len += 2 + *pos;
 
@@ -2663,10 +2671,6 @@ static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
                             "with key %d\n", ctl->key_idx);
                break;
 
-       case ALG_NONE:
-               IWL_DEBUG_TX("Tx packet in the clear (encrypt requested).\n");
-               break;
-
        default:
                printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
                break;
@@ -4498,13 +4502,13 @@ static u8 ratio2dB[100] = {
  * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
 int iwl_calc_db_from_ratio(int sig_ratio)
 {
-       /* Anything above 1000:1 just report as 60 dB */
-       if (sig_ratio > 1000)
+       /* 1000:1 or higher just report as 60 dB */
+       if (sig_ratio >= 1000)
                return 60;
 
-       /* Above 100:1, divide by 10 and use table,
+       /* 100:1 or higher, divide by 10 and use table,
         *   add 20 dB to make up for divide by 10 */
-       if (sig_ratio > 100)
+       if (sig_ratio >= 100)
                return (20 + (int)ratio2dB[sig_ratio/10]);
 
        /* We shouldn't see this */
@@ -5152,9 +5156,10 @@ static irqreturn_t iwl_isr(int irq, void *data)
        }
 
        if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
-               /* Hardware disappeared */
+               /* Hardware disappeared. It might have already raised
+                * an interrupt */
                IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
-               goto none;
+               goto unplugged;
        }
 
        IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
@@ -5162,8 +5167,9 @@ static irqreturn_t iwl_isr(int irq, void *data)
 
        /* iwl_irq_tasklet() will service interrupts and re-enable them */
        tasklet_schedule(&priv->irq_tasklet);
-       spin_unlock(&priv->lock);
 
+ unplugged:
+       spin_unlock(&priv->lock);
        return IRQ_HANDLED;
 
  none:
@@ -6841,8 +6847,9 @@ static void iwl_bg_scan_check(struct work_struct *data)
                IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
                          "Scan completion watchdog resetting adapter (%dms)\n",
                          jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
+
                if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
-                       queue_work(priv->workqueue, &priv->restart);
+                       iwl_send_scan_abort(priv);
        }
        mutex_unlock(&priv->mutex);
 }
@@ -6938,7 +6945,7 @@ static void iwl_bg_request_scan(struct work_struct *data)
                spin_unlock_irqrestore(&priv->lock, flags);
 
                scan->suspend_time = 0;
-               scan->max_out_time = cpu_to_le32(600 * 1024);
+               scan->max_out_time = cpu_to_le32(200 * 1024);
                if (!interval)
                        interval = suspend_time;
 
@@ -6961,7 +6968,7 @@ static void iwl_bg_request_scan(struct work_struct *data)
                memcpy(scan->direct_scan[0].ssid,
                       priv->direct_ssid, priv->direct_ssid_len);
                direct_mask = 1;
-       } else if (!iwl_is_associated(priv)) {
+       } else if (!iwl_is_associated(priv) && 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);
@@ -7114,6 +7121,12 @@ static void iwl_bg_post_associate(struct work_struct *data)
 
        mutex_lock(&priv->mutex);
 
+       if (!priv->interface_id || !priv->is_open) {
+               mutex_unlock(&priv->mutex);
+               return;
+       }
+       iwl_scan_cancel_timeout(priv, 200);
+
        conf = ieee80211_get_hw_conf(priv->hw);
 
        priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
@@ -7267,9 +7280,19 @@ static void iwl_mac_stop(struct ieee80211_hw *hw)
        struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MAC80211("enter\n");
+
+
+       mutex_lock(&priv->mutex);
+       /* stop mac, cancel any scan request and clear
+        * RXON_FILTER_ASSOC_MSK BIT
+        */
        priv->is_open = 0;
-       /*netif_stop_queue(dev); */
-       flush_workqueue(priv->workqueue);
+       iwl_scan_cancel_timeout(priv, 100);
+       cancel_delayed_work(&priv->post_associate);
+       priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
+       iwl_commit_rxon(priv);
+       mutex_unlock(&priv->mutex);
+
        IWL_DEBUG_MAC80211("leave\n");
 }
 
@@ -7569,8 +7592,6 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id,
                if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
                        iwl_config_ap(priv);
                else {
-                       priv->staging_rxon.filter_flags |=
-                                               RXON_FILTER_ASSOC_MSK;
                        rc = iwl_commit_rxon(priv);
                        if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
                                iwl_rxon_add_station(
@@ -7578,6 +7599,7 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id,
                }
 
        } else {
+               iwl_scan_cancel_timeout(priv, 100);
                priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
                iwl_commit_rxon(priv);
        }
@@ -7617,6 +7639,12 @@ static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
        IWL_DEBUG_MAC80211("enter\n");
 
        mutex_lock(&priv->mutex);
+
+       iwl_scan_cancel_timeout(priv, 100);
+       cancel_delayed_work(&priv->post_associate);
+       priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
+       iwl_commit_rxon(priv);
+
        if (priv->interface_id == conf->if_id) {
                priv->interface_id = 0;
                memset(priv->bssid, 0, ETH_ALEN);
@@ -7638,6 +7666,7 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
 
        IWL_DEBUG_MAC80211("enter\n");
 
+       mutex_lock(&priv->mutex);
        spin_lock_irqsave(&priv->lock, flags);
 
        if (!iwl_is_ready_rf(priv)) {
@@ -7668,7 +7697,8 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
                priv->direct_ssid_len = (u8)
                    min((u8) len, (u8) IW_ESSID_MAX_SIZE);
                memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
-       }
+       } else
+               priv->one_direct_scan = 0;
 
        rc = iwl_scan_initiate(priv);
 
@@ -7676,6 +7706,7 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
 
 out_unlock:
        spin_unlock_irqrestore(&priv->lock, flags);
+       mutex_unlock(&priv->mutex);
 
        return rc;
 }
@@ -7709,6 +7740,8 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        mutex_lock(&priv->mutex);
 
+       iwl_scan_cancel_timeout(priv, 100);
+
        switch (cmd) {
        case  SET_KEY:
                rc = iwl_update_sta_key_info(priv, key, sta_id);
@@ -7899,8 +7932,18 @@ static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
+       /* we are restarting association process
+        * clear RXON_FILTER_ASSOC_MSK bit
+        */
+       if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
+               iwl_scan_cancel_timeout(priv, 100);
+               priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
+               iwl_commit_rxon(priv);
+       }
+
        /* Per mac80211.h: This is only used in IBSS mode... */
        if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
+
                IWL_DEBUG_MAC80211("leave - not in IBSS\n");
                mutex_unlock(&priv->mutex);
                return;
@@ -8914,6 +8957,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
        SET_IEEE80211_DEV(hw, &pdev->dev);
 
+       hw->rate_control_algorithm = "iwl-4965-rs";
+
        IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
        priv = hw->priv;
        priv->hw = hw;
@@ -9148,6 +9193,9 @@ static void iwl_pci_remove(struct pci_dev *pdev)
                iwl_rate_control_unregister(priv->hw);
        }
 
+       /*netif_stop_queue(dev); */
+       flush_workqueue(priv->workqueue);
+
        /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
         * priv->workqueue... so we can't take down the workqueue
         * until now... */