iwlwifi: move channels sysfs to debugfs
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-agn.c
index a5feb0c..e8368b6 100644 (file)
@@ -96,7 +96,7 @@ MODULE_ALIAS("iwl4965");
 
 
 
-static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
+static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 {
        struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
 
@@ -108,79 +108,6 @@ static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 }
 
 /**
- * iwl4965_check_rxon_cmd - validate RXON structure is valid
- *
- * NOTE:  This is really only useful during development and can eventually
- * be #ifdef'd out once the driver is stable and folks aren't actively
- * making changes
- */
-static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
-{
-       int error = 0;
-       int counter = 1;
-
-       if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
-               error |= le32_to_cpu(rxon->flags &
-                               (RXON_FLG_TGJ_NARROW_BAND_MSK |
-                                RXON_FLG_RADAR_DETECT_MSK));
-               if (error)
-                       IWL_WARNING("check 24G fields %d | %d\n",
-                                   counter++, error);
-       } else {
-               error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
-                               0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
-               if (error)
-                       IWL_WARNING("check 52 fields %d | %d\n",
-                                   counter++, error);
-               error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
-               if (error)
-                       IWL_WARNING("check 52 CCK %d | %d\n",
-                                   counter++, error);
-       }
-       error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
-       if (error)
-               IWL_WARNING("check mac addr %d | %d\n", counter++, error);
-
-       /* make sure basic rates 6Mbps and 1Mbps are supported */
-       error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
-                 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
-       if (error)
-               IWL_WARNING("check basic rate %d | %d\n", counter++, error);
-
-       error |= (le16_to_cpu(rxon->assoc_id) > 2007);
-       if (error)
-               IWL_WARNING("check assoc id %d | %d\n", counter++, error);
-
-       error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
-                       == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
-       if (error)
-               IWL_WARNING("check CCK and short slot %d | %d\n",
-                           counter++, error);
-
-       error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
-                       == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
-       if (error)
-               IWL_WARNING("check CCK & auto detect %d | %d\n",
-                           counter++, error);
-
-       error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
-                       RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
-       if (error)
-               IWL_WARNING("check TGG and auto detect %d | %d\n",
-                           counter++, error);
-
-       if (error)
-               IWL_WARNING("Tuning to channel %d\n",
-                           le16_to_cpu(rxon->channel));
-
-       if (error) {
-               IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
-               return -1;
-       }
-       return 0;
-}
-
-/**
  * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  * @priv: staging_rxon is compared to active_rxon
  *
@@ -228,18 +155,17 @@ static int iwl_full_rxon_required(struct iwl_priv *priv)
 }
 
 /**
- * iwl4965_commit_rxon - commit staging_rxon to hardware
+ * iwl_commit_rxon - commit staging_rxon to hardware
  *
  * The RXON command in staging_rxon is committed to the hardware and
  * the active_rxon structure is updated with the new data.  This
  * function correctly transitions out of the RXON_ASSOC_MSK state if
  * a HW tune is required based on the RXON structure changes.
  */
-static int iwl4965_commit_rxon(struct iwl_priv *priv)
+static int iwl_commit_rxon(struct iwl_priv *priv)
 {
        /* cast away the const for active_rxon in this function */
        struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
-       DECLARE_MAC_BUF(mac);
        int ret;
        bool new_assoc =
                !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
@@ -253,14 +179,14 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
         * 5000, but will not damage 4965 */
        priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
 
-       ret = iwl4965_check_rxon_cmd(&priv->staging_rxon);
+       ret = iwl_agn_check_rxon_cmd(&priv->staging_rxon);
        if (ret) {
                IWL_ERROR("Invalid RXON configuration.  Not committing.\n");
                return -EINVAL;
        }
 
        /* If we don't need to send a full RXON, we can use
-        * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
+        * iwl_rxon_assoc_cmd which is used to reconfigure filter
         * and other flags for the current radio configuration. */
        if (!iwl_full_rxon_required(priv)) {
                ret = iwl_send_rxon_assoc(priv);
@@ -300,12 +226,12 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
        IWL_DEBUG_INFO("Sending RXON\n"
                       "* with%s RXON_FILTER_ASSOC_MSK\n"
                       "* channel = %d\n"
-                      "* bssid = %s\n",
+                      "* bssid = %pM\n",
                       (new_assoc ? "" : "out"),
                       le16_to_cpu(priv->staging_rxon.channel),
-                      print_mac(mac, priv->staging_rxon.bssid_addr));
+                      priv->staging_rxon.bssid_addr);
 
-       iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
+       iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
 
        /* Apply the new configuration
         * RXON unassoc clears the station table in uCode, send it before
@@ -337,7 +263,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
        /* If we have set the ASSOC_MSK and we are in BSS mode then
         * add the IWL_AP_ID to the station rate table */
        if (new_assoc) {
-               if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
+               if (priv->iw_mode == NL80211_IFTYPE_STATION) {
                        ret = iwl_rxon_add_station(priv,
                                           priv->active_rxon.bssid_addr, 1);
                        if (ret == IWL_INVALID_STATION) {
@@ -375,14 +301,14 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
        return 0;
 }
 
-void iwl4965_update_chain_flags(struct iwl_priv *priv)
+void iwl_update_chain_flags(struct iwl_priv *priv)
 {
 
        iwl_set_rxon_chain(priv);
-       iwl4965_commit_rxon(priv);
+       iwl_commit_rxon(priv);
 }
 
-static int iwl4965_send_bt_config(struct iwl_priv *priv)
+static int iwl_send_bt_config(struct iwl_priv *priv)
 {
        struct iwl4965_bt_cmd bt_cmd = {
                .flags = 3,
@@ -448,8 +374,8 @@ static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
                                          const u8 *dest, int left)
 {
        if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
-           ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
-            (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
+           ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
+            (priv->iw_mode != NL80211_IFTYPE_AP)))
                return 0;
 
        if (priv->ibss_beacon->len > left)
@@ -460,16 +386,16 @@ static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
        return priv->ibss_beacon->len;
 }
 
-static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
+static u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
 {
        int i;
        int rate_mask;
 
        /* Set rate mask*/
        if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
-               rate_mask = priv->active_rate_basic & 0xF;
+               rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
        else
-               rate_mask = priv->active_rate_basic & 0xFF0;
+               rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
 
        /* Find lowest valid rate */
        for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
@@ -485,7 +411,7 @@ static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
                return IWL_RATE_6M_PLCP;
 }
 
-unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
+static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
                                       struct iwl_frame *frame, u8 rate)
 {
        struct iwl_tx_beacon_cmd *tx_beacon_cmd;
@@ -517,7 +443,7 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
 
        return sizeof(*tx_beacon_cmd) + frame_size;
 }
-static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
+static int iwl_send_beacon_cmd(struct iwl_priv *priv)
 {
        struct iwl_frame *frame;
        unsigned int frame_size;
@@ -532,9 +458,9 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
                return -ENOMEM;
        }
 
-       rate = iwl4965_rate_get_lowest_plcp(priv);
+       rate = iwl_rate_get_lowest_plcp(priv);
 
-       frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
+       frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
 
        rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
                              &frame->u.cmd[0]);
@@ -550,21 +476,32 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  *
  ******************************************************************************/
 
-static void iwl4965_ht_conf(struct iwl_priv *priv,
+static void iwl_ht_conf(struct iwl_priv *priv,
                            struct ieee80211_bss_conf *bss_conf)
 {
-       struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
-       struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
+       struct ieee80211_sta_ht_cap *ht_conf;
        struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
+       struct ieee80211_sta *sta;
 
        IWL_DEBUG_MAC80211("enter: \n");
 
-       iwl_conf->is_ht = bss_conf->assoc_ht;
-
        if (!iwl_conf->is_ht)
                return;
 
-       priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
+
+       /*
+        * It is totally wrong to base global information on something
+        * that is valid only when associated, alas, this driver works
+        * that way and I don't know how to fix it.
+        */
+
+       rcu_read_lock();
+       sta = ieee80211_find_sta(priv->hw, priv->bssid);
+       if (!sta) {
+               rcu_read_unlock();
+               return;
+       }
+       ht_conf = &sta->ht_cap;
 
        if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
                iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
@@ -576,29 +513,28 @@ static void iwl4965_ht_conf(struct iwl_priv *priv,
                !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
 
        iwl_conf->supported_chan_width =
-               !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
-       iwl_conf->extension_chan_offset =
-               ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
+               !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
+
+       iwl_conf->extension_chan_offset = bss_conf->ht.secondary_channel_offset;
        /* If no above or below channel supplied disable FAT channel */
-       if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
-           iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
-               iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
+       if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
+           iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW) {
+               iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
                iwl_conf->supported_chan_width = 0;
        }
 
-       iwl_conf->tx_mimo_ps_mode =
-               (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
-       memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
+       iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
+
+       memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
 
-       iwl_conf->control_channel = ht_bss_conf->primary_channel;
-       iwl_conf->tx_chan_width =
-               !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
+       iwl_conf->tx_chan_width = bss_conf->ht.width_40_ok;
        iwl_conf->ht_protection =
-               ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
+               bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
        iwl_conf->non_GF_STA_present =
-               !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
+               !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
+
+       rcu_read_unlock();
 
-       IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
        IWL_DEBUG_MAC80211("leave\n");
 }
 
@@ -639,23 +575,22 @@ static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
 
 #define MAX_UCODE_BEACON_INTERVAL      4096
 
-static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
+static u16 iwl_adjust_beacon_interval(u16 beacon_val)
 {
        u16 new_val = 0;
        u16 beacon_factor = 0;
 
-       beacon_factor =
-           (beacon_val + MAX_UCODE_BEACON_INTERVAL)
-               / MAX_UCODE_BEACON_INTERVAL;
+       beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
+                                       / MAX_UCODE_BEACON_INTERVAL;
        new_val = beacon_val / beacon_factor;
 
-       return cpu_to_le16(new_val);
+       return new_val;
 }
 
-static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
+static void iwl_setup_rxon_timing(struct iwl_priv *priv)
 {
-       u64 interval_tm_unit;
-       u64 tsf, result;
+       u64 tsf;
+       s32 interval_tm, rem;
        unsigned long flags;
        struct ieee80211_conf *conf = NULL;
        u16 beacon_int = 0;
@@ -663,49 +598,32 @@ static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
        conf = ieee80211_get_hw_conf(priv->hw);
 
        spin_lock_irqsave(&priv->lock, flags);
-       priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
-       priv->rxon_timing.timestamp.dw[0] =
-                               cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
-
+       priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
        priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
 
-       tsf = priv->timestamp;
-
-       beacon_int = priv->beacon_int;
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
-               if (beacon_int == 0) {
-                       priv->rxon_timing.beacon_interval = cpu_to_le16(100);
-                       priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
-               } else {
-                       priv->rxon_timing.beacon_interval =
-                               cpu_to_le16(beacon_int);
-                       priv->rxon_timing.beacon_interval =
-                           iwl4965_adjust_beacon_interval(
-                               le16_to_cpu(priv->rxon_timing.beacon_interval));
-               }
-
+       if (priv->iw_mode == NL80211_IFTYPE_STATION) {
+               beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
                priv->rxon_timing.atim_window = 0;
        } else {
-               priv->rxon_timing.beacon_interval =
-                       iwl4965_adjust_beacon_interval(conf->beacon_int);
+               beacon_int = iwl_adjust_beacon_interval(conf->beacon_int);
+
                /* TODO: we need to get atim_window from upper stack
                 * for now we set to 0 */
                priv->rxon_timing.atim_window = 0;
        }
 
-       interval_tm_unit =
-               (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
-       result = do_div(tsf, interval_tm_unit);
-       priv->rxon_timing.beacon_init_val =
-           cpu_to_le32((u32) ((u64) interval_tm_unit - result));
+       priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
 
-       IWL_DEBUG_ASSOC
-           ("beacon interval %d beacon timer %d beacon tim %d\n",
-               le16_to_cpu(priv->rxon_timing.beacon_interval),
-               le32_to_cpu(priv->rxon_timing.beacon_init_val),
-               le16_to_cpu(priv->rxon_timing.atim_window));
+       tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
+       interval_tm = beacon_int * 1024;
+       rem = do_div(tsf, interval_tm);
+       priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+       IWL_DEBUG_ASSOC("beacon interval %d beacon timer %d beacon tim %d\n",
+                       le16_to_cpu(priv->rxon_timing.beacon_interval),
+                       le32_to_cpu(priv->rxon_timing.beacon_init_val),
+                       le16_to_cpu(priv->rxon_timing.atim_window));
 }
 
 static void iwl_set_flags_for_band(struct iwl_priv *priv,
@@ -717,13 +635,13 @@ static void iwl_set_flags_for_band(struct iwl_priv *priv,
                      | RXON_FLG_CCK_MSK);
                priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
        } else {
-               /* Copied from iwl4965_post_associate() */
+               /* Copied from iwl_post_associate() */
                if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
                        priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
                else
                        priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
 
-               if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
+               if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
                        priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
 
                priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
@@ -735,36 +653,36 @@ static void iwl_set_flags_for_band(struct iwl_priv *priv,
 /*
  * initialize rxon structure with default values from eeprom
  */
-static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
+static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
 {
        const struct iwl_channel_info *ch_info;
 
        memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
 
-       switch (priv->iw_mode) {
-       case IEEE80211_IF_TYPE_AP:
+       switch (mode) {
+       case NL80211_IFTYPE_AP:
                priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
                break;
 
-       case IEEE80211_IF_TYPE_STA:
+       case NL80211_IFTYPE_STATION:
                priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
                priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
                break;
 
-       case IEEE80211_IF_TYPE_IBSS:
+       case NL80211_IFTYPE_ADHOC:
                priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
                priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
                priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
                                                  RXON_FILTER_ACCEPT_GRP_MSK;
                break;
 
-       case IEEE80211_IF_TYPE_MNTR:
+       case NL80211_IFTYPE_MONITOR:
                priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
                priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
                    RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
                break;
        default:
-               IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
+               IWL_ERROR("Unsupported interface type %d\n", mode);
                break;
        }
 
@@ -787,7 +705,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
         * in some case A channels are all non IBSS
         * in this case force B/G channel
         */
-       if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
+       if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
            !(is_channel_ibss(ch_info)))
                ch_info = &priv->channel_info[0];
 
@@ -810,11 +728,9 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
        iwl_set_rxon_chain(priv);
 }
 
-static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
+static int iwl_set_mode(struct iwl_priv *priv, int mode)
 {
-       priv->iw_mode = mode;
-
-       iwl4965_connection_init_rx_config(priv);
+       iwl_connection_init_rx_config(priv, mode);
        memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
 
        iwl_clear_stations_table(priv);
@@ -830,12 +746,12 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
                return -EAGAIN;
        }
 
-       iwl4965_commit_rxon(priv);
+       iwl_commit_rxon(priv);
 
        return 0;
 }
 
-static void iwl4965_set_rate(struct iwl_priv *priv)
+static void iwl_set_rate(struct iwl_priv *priv)
 {
        const struct ieee80211_supported_band *hw = NULL;
        struct ieee80211_rate *rate;
@@ -882,138 +798,6 @@ static void iwl4965_set_rate(struct iwl_priv *priv)
                   (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
 }
 
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-
-#include "iwl-spectrum.h"
-
-#define BEACON_TIME_MASK_LOW   0x00FFFFFF
-#define BEACON_TIME_MASK_HIGH  0xFF000000
-#define TIME_UNIT              1024
-
-/*
- * extended beacon time format
- * time in usec will be changed into a 32-bit value in 8:24 format
- * the high 1 byte is the beacon counts
- * the lower 3 bytes is the time in usec within one beacon interval
- */
-
-static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
-{
-       u32 quot;
-       u32 rem;
-       u32 interval = beacon_interval * 1024;
-
-       if (!interval || !usec)
-               return 0;
-
-       quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
-       rem = (usec % interval) & BEACON_TIME_MASK_LOW;
-
-       return (quot << 24) + rem;
-}
-
-/* base is usually what we get from ucode with each received frame,
- * the same as HW timer counter counting down
- */
-
-static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
-{
-       u32 base_low = base & BEACON_TIME_MASK_LOW;
-       u32 addon_low = addon & BEACON_TIME_MASK_LOW;
-       u32 interval = beacon_interval * TIME_UNIT;
-       u32 res = (base & BEACON_TIME_MASK_HIGH) +
-           (addon & BEACON_TIME_MASK_HIGH);
-
-       if (base_low > addon_low)
-               res += base_low - addon_low;
-       else if (base_low < addon_low) {
-               res += interval + base_low - addon_low;
-               res += (1 << 24);
-       } else
-               res += (1 << 24);
-
-       return cpu_to_le32(res);
-}
-
-static int iwl4965_get_measurement(struct iwl_priv *priv,
-                              struct ieee80211_measurement_params *params,
-                              u8 type)
-{
-       struct iwl4965_spectrum_cmd spectrum;
-       struct iwl_rx_packet *res;
-       struct iwl_host_cmd cmd = {
-               .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
-               .data = (void *)&spectrum,
-               .meta.flags = CMD_WANT_SKB,
-       };
-       u32 add_time = le64_to_cpu(params->start_time);
-       int rc;
-       int spectrum_resp_status;
-       int duration = le16_to_cpu(params->duration);
-
-       if (iwl_is_associated(priv))
-               add_time =
-                   iwl4965_usecs_to_beacons(
-                       le64_to_cpu(params->start_time) - priv->last_tsf,
-                       le16_to_cpu(priv->rxon_timing.beacon_interval));
-
-       memset(&spectrum, 0, sizeof(spectrum));
-
-       spectrum.channel_count = cpu_to_le16(1);
-       spectrum.flags =
-           RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
-       spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
-       cmd.len = sizeof(spectrum);
-       spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
-
-       if (iwl_is_associated(priv))
-               spectrum.start_time =
-                   iwl4965_add_beacon_time(priv->last_beacon_time,
-                               add_time,
-                               le16_to_cpu(priv->rxon_timing.beacon_interval));
-       else
-               spectrum.start_time = 0;
-
-       spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
-       spectrum.channels[0].channel = params->channel;
-       spectrum.channels[0].type = type;
-       if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
-               spectrum.flags |= RXON_FLG_BAND_24G_MSK |
-                   RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
-
-       rc = iwl_send_cmd_sync(priv, &cmd);
-       if (rc)
-               return rc;
-
-       res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
-       if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
-               IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
-               rc = -EIO;
-       }
-
-       spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
-       switch (spectrum_resp_status) {
-       case 0:         /* Command will be handled */
-               if (res->u.spectrum.id != 0xff) {
-                       IWL_DEBUG_INFO
-                           ("Replaced existing measurement: %d\n",
-                            res->u.spectrum.id);
-                       priv->measurement_status &= ~MEASUREMENT_READY;
-               }
-               priv->measurement_status |= MEASUREMENT_ACTIVE;
-               rc = 0;
-               break;
-
-       case 1:         /* Command will not be handled */
-               rc = -EAGAIN;
-               break;
-       }
-
-       dev_kfree_skb_any(cmd.meta.u.skb);
-
-       return rc;
-}
-#endif
 
 /******************************************************************************
  *
@@ -1056,7 +840,7 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv,
                IWL_WARNING("uCode did not respond OK.\n");
 }
 
-static void iwl4965_rx_reply_error(struct iwl_priv *priv,
+static void iwl_rx_reply_error(struct iwl_priv *priv,
                                   struct iwl_rx_mem_buffer *rxb)
 {
        struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1072,7 +856,7 @@ static void iwl4965_rx_reply_error(struct iwl_priv *priv,
 
 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
 
-static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
+static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
 {
        struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
@@ -1083,25 +867,7 @@ static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
        priv->staging_rxon.channel = csa->channel;
 }
 
-static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
-                                         struct iwl_rx_mem_buffer *rxb)
-{
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
-       struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
-
-       if (!report->state) {
-               IWL_DEBUG(IWL_DL_11H,
-                       "Spectrum Measure Notification: Start\n");
-               return;
-       }
-
-       memcpy(&priv->measure_report, report, sizeof(*report));
-       priv->measurement_status |= MEASUREMENT_READY;
-#endif
-}
-
-static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
+static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
                                      struct iwl_rx_mem_buffer *rxb)
 {
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -1112,7 +878,7 @@ static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
 #endif
 }
 
-static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
+static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
                                             struct iwl_rx_mem_buffer *rxb)
 {
        struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1122,7 +888,7 @@ static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
        iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
 }
 
-static void iwl4965_bg_beacon_update(struct work_struct *work)
+static void iwl_bg_beacon_update(struct work_struct *work)
 {
        struct iwl_priv *priv =
                container_of(work, struct iwl_priv, beacon_update);
@@ -1144,11 +910,11 @@ static void iwl4965_bg_beacon_update(struct work_struct *work)
        priv->ibss_beacon = beacon;
        mutex_unlock(&priv->mutex);
 
-       iwl4965_send_beacon_cmd(priv);
+       iwl_send_beacon_cmd(priv);
 }
 
 /**
- * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
+ * iwl_bg_statistics_periodic - Timer callback to queue statistics
  *
  * This callback is provided in order to send a statistics request.
  *
@@ -1157,17 +923,21 @@ static void iwl4965_bg_beacon_update(struct work_struct *work)
  * was received.  We need to ensure we receive the statistics in order
  * to update the temperature used for calibrating the TXPOWER.
  */
-static void iwl4965_bg_statistics_periodic(unsigned long data)
+static void iwl_bg_statistics_periodic(unsigned long data)
 {
        struct iwl_priv *priv = (struct iwl_priv *)data;
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
 
+       /* dont send host command if rf-kill is on */
+       if (!iwl_is_ready_rf(priv))
+               return;
+
        iwl_send_statistics_request(priv, CMD_ASYNC);
 }
 
-static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
+static void iwl_rx_beacon_notif(struct iwl_priv *priv,
                                struct iwl_rx_mem_buffer *rxb)
 {
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -1184,14 +954,14 @@ static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
                le32_to_cpu(beacon->low_tsf), rate);
 #endif
 
-       if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
+       if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
            (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
                queue_work(priv->workqueue, &priv->beacon_update);
 }
 
 /* Handle notification from uCode that card's power state is changing
  * due to software, hardware, or critical temperature RFKILL */
-static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
+static void iwl_rx_card_state_notif(struct iwl_priv *priv,
                                    struct iwl_rx_mem_buffer *rxb)
 {
        struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1260,7 +1030,7 @@ static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
                wake_up_interruptible(&priv->wait_command_queue);
 }
 
-int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
+int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
 {
        int ret;
        unsigned long flags;
@@ -1272,7 +1042,7 @@ int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
 
        if (src == IWL_PWR_SRC_VAUX) {
                u32 val;
-               ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
+               ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
                                            &val);
 
                if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
@@ -1292,7 +1062,7 @@ err:
 }
 
 /**
- * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
+ * iwl_setup_rx_handlers - Initialize Rx handler callbacks
  *
  * Setup the RX handlers for each of the reply types sent from the uCode
  * to the host.
@@ -1303,14 +1073,12 @@ err:
 static void iwl_setup_rx_handlers(struct iwl_priv *priv)
 {
        priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
-       priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
-       priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
-       priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
-           iwl4965_rx_spectrum_measure_notif;
-       priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
+       priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
+       priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
+       priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
        priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
-           iwl4965_rx_pm_debug_statistics_notif;
-       priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
+           iwl_rx_pm_debug_statistics_notif;
+       priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
 
        /*
         * The same handler is used for both the REPLY to a discrete
@@ -1320,10 +1088,11 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv)
        priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
        priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
 
+       iwl_setup_spectrum_handlers(priv);
        iwl_setup_rx_scan_handlers(priv);
 
        /* status change handler */
-       priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
+       priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
 
        priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
            iwl_rx_missed_beacon_notif;
@@ -1366,7 +1135,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
 
        /* uCode's read index (stored in shared DRAM) indicates the last Rx
         * buffer that the driver may process (last buffer filled by ucode). */
-       r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
+       r = le16_to_cpu(rxq->rb_stts->closed_rb_num) &  0x0FFF;
        i = rxq->read;
 
        /* Rx interrupt, but nothing sent from uCode */
@@ -1386,9 +1155,11 @@ void iwl_rx_handle(struct iwl_priv *priv)
 
                rxq->queue[i] = NULL;
 
-               pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
-                                           priv->hw_params.rx_buf_size,
-                                           PCI_DMA_FROMDEVICE);
+               dma_sync_single_range_for_cpu(
+                               &priv->pci_dev->dev, rxb->real_dma_addr,
+                               rxb->aligned_dma_addr - rxb->real_dma_addr,
+                               priv->hw_params.rx_buf_size,
+                               PCI_DMA_FROMDEVICE);
                pkt = (struct iwl_rx_packet *)rxb->skb->data;
 
                /* Reclaim a command buffer only if this packet is a response
@@ -1400,13 +1171,14 @@ void iwl_rx_handle(struct iwl_priv *priv)
                reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
                        (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
                        (pkt->hdr.cmd != REPLY_RX) &&
+                       (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
                        (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
                        (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
                        (pkt->hdr.cmd != REPLY_TX);
 
                /* Based on type of command response or notification,
                 *   handle those that need handling via function in
-                *   rx_handlers table.  See iwl4965_setup_rx_handlers() */
+                *   rx_handlers table.  See iwl_setup_rx_handlers() */
                if (priv->rx_handlers[pkt->hdr.cmd]) {
                        IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
                                i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
@@ -1438,8 +1210,8 @@ void iwl_rx_handle(struct iwl_priv *priv)
                        rxb->skb = NULL;
                }
 
-               pci_unmap_single(priv->pci_dev, rxb->dma_addr,
-                                priv->hw_params.rx_buf_size,
+               pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
+                                priv->hw_params.rx_buf_size + 256,
                                 PCI_DMA_FROMDEVICE);
                spin_lock_irqsave(&rxq->lock, flags);
                list_add_tail(&rxb->list, &priv->rxq.rx_used);
@@ -1463,10 +1235,9 @@ void iwl_rx_handle(struct iwl_priv *priv)
 }
 
 #ifdef CONFIG_IWLWIFI_DEBUG
-static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
+static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
 {
        struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
-       DECLARE_MAC_BUF(mac);
 
        IWL_DEBUG_RADIO("RX CONFIG:\n");
        iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
@@ -1478,50 +1249,26 @@ static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
        IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
                        rxon->ofdm_basic_rates);
        IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
-       IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
-                       print_mac(mac, rxon->node_addr));
-       IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
-                       print_mac(mac, rxon->bssid_addr));
+       IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
+       IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
        IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
 }
 #endif
 
-static void iwl4965_enable_interrupts(struct iwl_priv *priv)
-{
-       IWL_DEBUG_ISR("Enabling interrupts\n");
-       set_bit(STATUS_INT_ENABLED, &priv->status);
-       iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
-}
-
 /* call this function to flush any scheduled tasklet */
 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
 {
-       /* wait to make sure we flush pedding tasklet*/
+       /* wait to make sure we flush pending tasklet*/
        synchronize_irq(priv->pci_dev->irq);
        tasklet_kill(&priv->irq_tasklet);
 }
 
-static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
-{
-       clear_bit(STATUS_INT_ENABLED, &priv->status);
-
-       /* disable interrupts from uCode/NIC to host */
-       iwl_write32(priv, CSR_INT_MASK, 0x00000000);
-
-       /* acknowledge/clear/reset any interrupts still pending
-        * from uCode or flow handler (Rx/Tx DMA) */
-       iwl_write32(priv, CSR_INT, 0xffffffff);
-       iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
-       IWL_DEBUG_ISR("Disabled interrupts\n");
-}
-
-
 /**
- * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
+ * iwl_irq_handle_error - called for HW or SW error interrupt from card
  */
-static void iwl4965_irq_handle_error(struct iwl_priv *priv)
+static void iwl_irq_handle_error(struct iwl_priv *priv)
 {
-       /* Set the FW error flag -- cleared on iwl4965_down */
+       /* Set the FW error flag -- cleared on iwl_down */
        set_bit(STATUS_FW_ERROR, &priv->status);
 
        /* Cancel currently queued command. */
@@ -1531,7 +1278,7 @@ static void iwl4965_irq_handle_error(struct iwl_priv *priv)
        if (priv->debug_level & IWL_DL_FW_ERRORS) {
                iwl_dump_nic_error_log(priv);
                iwl_dump_nic_event_log(priv);
-               iwl4965_print_rx_config_cmd(priv);
+               iwl_print_rx_config_cmd(priv);
        }
 #endif
 
@@ -1555,14 +1302,14 @@ static void iwl4965_irq_handle_error(struct iwl_priv *priv)
        }
 }
 
-static void iwl4965_error_recovery(struct iwl_priv *priv)
+static void iwl_error_recovery(struct iwl_priv *priv)
 {
        unsigned long flags;
 
        memcpy(&priv->staging_rxon, &priv->recovery_rxon,
               sizeof(priv->staging_rxon));
        priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
-       iwl4965_commit_rxon(priv);
+       iwl_commit_rxon(priv);
 
        iwl_rxon_add_station(priv, priv->bssid, 1);
 
@@ -1572,7 +1319,7 @@ static void iwl4965_error_recovery(struct iwl_priv *priv)
        spin_unlock_irqrestore(&priv->lock, flags);
 }
 
-static void iwl4965_irq_tasklet(struct iwl_priv *priv)
+static void iwl_irq_tasklet(struct iwl_priv *priv)
 {
        u32 inta, handled = 0;
        u32 inta_fh;
@@ -1618,9 +1365,9 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
                IWL_ERROR("Microcode HW error detected.  Restarting.\n");
 
                /* Tell the device to stop sending interrupts */
-               iwl4965_disable_interrupts(priv);
+               iwl_disable_interrupts(priv);
 
-               iwl4965_irq_handle_error(priv);
+               iwl_irq_handle_error(priv);
 
                handled |= CSR_INT_BIT_HW_ERR;
 
@@ -1652,7 +1399,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
                        hw_rf_kill = 1;
 
                IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
-                               hw_rf_kill ? "disable radio":"enable radio");
+                               hw_rf_kill ? "disable radio" : "enable radio");
 
                /* driver only loads ucode once setting the interface up.
                 * the driver as well won't allow loading if RFKILL is set
@@ -1674,7 +1421,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
        if (inta & CSR_INT_BIT_SW_ERR) {
                IWL_ERROR("Microcode SW error detected.  Restarting 0x%X.\n",
                          inta);
-               iwl4965_irq_handle_error(priv);
+               iwl_irq_handle_error(priv);
                handled |= CSR_INT_BIT_SW_ERR;
        }
 
@@ -1720,7 +1467,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
        /* Re-enable all interrupts */
        /* only Re-enable if diabled by irq */
        if (test_bit(STATUS_INT_ENABLED, &priv->status))
-               iwl4965_enable_interrupts(priv);
+               iwl_enable_interrupts(priv);
 
 #ifdef CONFIG_IWLWIFI_DEBUG
        if (priv->debug_level & (IWL_DL_ISR)) {
@@ -1734,7 +1481,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
        spin_unlock_irqrestore(&priv->lock, flags);
 }
 
-static irqreturn_t iwl4965_isr(int irq, void *data)
+static irqreturn_t iwl_isr(int irq, void *data)
 {
        struct iwl_priv *priv = data;
        u32 inta, inta_mask;
@@ -1766,7 +1513,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
        if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
                /* Hardware disappeared. It might have already raised
                 * an interrupt */
-               IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
+               IWL_WARNING("HARDWARE GONE?? INTA == 0x%08x\n", inta);
                goto unplugged;
        }
 
@@ -1775,7 +1522,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
 
        inta &= ~CSR_INT_BIT_SCD;
 
-       /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
+       /* iwl_irq_tasklet() will service interrupts and re-enable them */
        if (likely(inta || inta_fh))
                tasklet_schedule(&priv->irq_tasklet);
 
@@ -1787,7 +1534,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
        /* re-enable interrupts here since we don't have anything to service. */
        /* only Re-enable if diabled by irq */
        if (test_bit(STATUS_INT_ENABLED, &priv->status))
-               iwl4965_enable_interrupts(priv);
+               iwl_enable_interrupts(priv);
        spin_unlock(&priv->lock);
        return IRQ_NONE;
 }
@@ -1798,7 +1545,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
  *
  ******************************************************************************/
 
-static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
+static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
 {
        iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
        iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
@@ -1808,7 +1555,7 @@ static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
        iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
 }
 
-static void iwl4965_nic_start(struct iwl_priv *priv)
+static void iwl_nic_start(struct iwl_priv *priv)
 {
        /* Remove all resets to allow NIC to operate */
        iwl_write32(priv, CSR_RESET, 0);
@@ -1816,11 +1563,11 @@ static void iwl4965_nic_start(struct iwl_priv *priv)
 
 
 /**
- * iwl4965_read_ucode - Read uCode images from disk file.
+ * iwl_read_ucode - Read uCode images from disk file.
  *
  * Copy into buffers for card to fetch via bus-mastering
  */
-static int iwl4965_read_ucode(struct iwl_priv *priv)
+static int iwl_read_ucode(struct iwl_priv *priv)
 {
        struct iwl_ucode *ucode;
        int ret;
@@ -1964,7 +1711,7 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
                priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
 
        /* Runtime data (2nd block)
-        * NOTE:  Copy into backup buffer will be done in iwl4965_up()  */
+        * NOTE:  Copy into backup buffer will be done in iwl_up()  */
        src = &ucode->data[inst_size];
        len = priv->ucode_data.len;
        IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
@@ -2002,7 +1749,7 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
  err_pci_alloc:
        IWL_ERROR("failed to allocate pci memory\n");
        ret = -ENOMEM;
-       iwl4965_dealloc_ucode_pci(priv);
+       iwl_dealloc_ucode_pci(priv);
 
  err_release:
        release_firmware(ucode_raw);
@@ -2011,6 +1758,10 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
        return ret;
 }
 
+/* temporary */
+static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
+                                struct sk_buff *skb);
+
 /**
  * iwl_alive_start - called after REPLY_ALIVE notification received
  *                   from protocol/runtime uCode (initialization uCode's
@@ -2047,7 +1798,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
                goto restart;
        }
 
-       /* After the ALIVE response, we can send host commands to 4965 uCode */
+       /* After the ALIVE response, we can send host commands to the uCode */
        set_bit(STATUS_ALIVE, &priv->status);
 
        if (iwl_is_rfkill(priv))
@@ -2067,17 +1818,17 @@ static void iwl_alive_start(struct iwl_priv *priv)
                active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
        } else {
                /* Initialize our rx_config data */
-               iwl4965_connection_init_rx_config(priv);
+               iwl_connection_init_rx_config(priv, priv->iw_mode);
                memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
        }
 
        /* Configure Bluetooth device coexistence support */
-       iwl4965_send_bt_config(priv);
+       iwl_send_bt_config(priv);
 
        iwl_reset_run_time_calib(priv);
 
        /* Configure the adapter for unassociated operation */
-       iwl4965_commit_rxon(priv);
+       iwl_commit_rxon(priv);
 
        /* At this point, the NIC is initialized and operational */
        iwl_rf_kill_ct_config(priv);
@@ -2089,13 +1840,21 @@ static void iwl_alive_start(struct iwl_priv *priv)
        wake_up_interruptible(&priv->wait_command_queue);
 
        if (priv->error_recovering)
-               iwl4965_error_recovery(priv);
+               iwl_error_recovery(priv);
 
        iwl_power_update_mode(priv, 1);
-       ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
+
+       /* reassociate for ADHOC mode */
+       if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
+               struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
+                                                               priv->vif);
+               if (beacon)
+                       iwl_mac_beacon_update(priv->hw, beacon);
+       }
+
 
        if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
-               iwl4965_set_mode(priv, priv->iw_mode);
+               iwl_set_mode(priv, priv->iw_mode);
 
        return;
 
@@ -2105,7 +1864,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
 
 static void iwl_cancel_deferred_work(struct iwl_priv *priv);
 
-static void __iwl4965_down(struct iwl_priv *priv)
+static void __iwl_down(struct iwl_priv *priv)
 {
        unsigned long flags;
        int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
@@ -2132,14 +1891,14 @@ static void __iwl4965_down(struct iwl_priv *priv)
 
        /* tell the device to stop sending interrupts */
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_disable_interrupts(priv);
+       iwl_disable_interrupts(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
        iwl_synchronize_irq(priv);
 
        if (priv->mac80211_registered)
                ieee80211_stop_queues(priv->hw);
 
-       /* If we have not previously called iwl4965_init() then
+       /* If we have not previously called iwl_init() then
         * clear all bits but the RF Kill and SUSPEND bits and return */
        if (!iwl_is_init(priv)) {
                priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
@@ -2189,9 +1948,10 @@ static void __iwl4965_down(struct iwl_priv *priv)
        udelay(5);
 
        /* FIXME: apm_ops.suspend(priv) */
-       priv->cfg->ops->lib->apm_ops.reset(priv);
-       priv->cfg->ops->lib->free_shared_mem(priv);
-
+       if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
+               priv->cfg->ops->lib->apm_ops.stop(priv);
+       else
+               priv->cfg->ops->lib->apm_ops.reset(priv);
  exit:
        memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
 
@@ -2203,10 +1963,10 @@ static void __iwl4965_down(struct iwl_priv *priv)
        iwl_clear_free_frames(priv);
 }
 
-static void iwl4965_down(struct iwl_priv *priv)
+static void iwl_down(struct iwl_priv *priv)
 {
        mutex_lock(&priv->mutex);
-       __iwl4965_down(priv);
+       __iwl_down(priv);
        mutex_unlock(&priv->mutex);
 
        iwl_cancel_deferred_work(priv);
@@ -2214,7 +1974,7 @@ static void iwl4965_down(struct iwl_priv *priv)
 
 #define MAX_HW_RESTARTS 5
 
-static int __iwl4965_up(struct iwl_priv *priv)
+static int __iwl_up(struct iwl_priv *priv)
 {
        int i;
        int ret;
@@ -2236,7 +1996,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
                set_bit(STATUS_RF_KILL_HW, &priv->status);
 
        if (iwl_is_rfkill(priv)) {
-               iwl4965_enable_interrupts(priv);
+               iwl_enable_interrupts(priv);
                IWL_WARNING("Radio disabled by %s RF Kill switch\n",
                    test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
                return 0;
@@ -2244,12 +2004,6 @@ static int __iwl4965_up(struct iwl_priv *priv)
 
        iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
 
-       ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
-       if (ret) {
-               IWL_ERROR("Unable to allocate shared memory\n");
-               return ret;
-       }
-
        ret = iwl_hw_nic_init(priv);
        if (ret) {
                IWL_ERROR("Unable to init nic\n");
@@ -2263,7 +2017,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
 
        /* clear (again), then enable host interrupts */
        iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
-       iwl4965_enable_interrupts(priv);
+       iwl_enable_interrupts(priv);
 
        /* really make sure rfkill handshake bits are cleared */
        iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
@@ -2293,7 +2047,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
                clear_bit(STATUS_FW_ERROR, &priv->status);
 
                /* start card; "initialize" will load runtime ucode */
-               iwl4965_nic_start(priv);
+               iwl_nic_start(priv);
 
                IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
 
@@ -2301,7 +2055,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
        }
 
        set_bit(STATUS_EXIT_PENDING, &priv->status);
-       __iwl4965_down(priv);
+       __iwl_down(priv);
        clear_bit(STATUS_EXIT_PENDING, &priv->status);
 
        /* tried to restart and config the device for as long as our
@@ -2343,7 +2097,7 @@ static void iwl_bg_alive_start(struct work_struct *data)
        mutex_unlock(&priv->mutex);
 }
 
-static void iwl4965_bg_rf_kill(struct work_struct *work)
+static void iwl_bg_rf_kill(struct work_struct *work)
 {
        struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
 
@@ -2377,28 +2131,6 @@ static void iwl4965_bg_rf_kill(struct work_struct *work)
        iwl_rfkill_set_hw_state(priv);
 }
 
-static void iwl4965_bg_set_monitor(struct work_struct *work)
-{
-       struct iwl_priv *priv = container_of(work,
-                               struct iwl_priv, set_monitor);
-       int ret;
-
-       IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
-
-       mutex_lock(&priv->mutex);
-
-       ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
-
-       if (ret) {
-               if (ret == -EAGAIN)
-                       IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
-               else
-                       IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
-       }
-
-       mutex_unlock(&priv->mutex);
-}
-
 static void iwl_bg_run_time_calib_work(struct work_struct *work)
 {
        struct iwl_priv *priv = container_of(work, struct iwl_priv,
@@ -2422,7 +2154,7 @@ static void iwl_bg_run_time_calib_work(struct work_struct *work)
        return;
 }
 
-static void iwl4965_bg_up(struct work_struct *data)
+static void iwl_bg_up(struct work_struct *data)
 {
        struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
 
@@ -2430,23 +2162,23 @@ static void iwl4965_bg_up(struct work_struct *data)
                return;
 
        mutex_lock(&priv->mutex);
-       __iwl4965_up(priv);
+       __iwl_up(priv);
        mutex_unlock(&priv->mutex);
        iwl_rfkill_set_hw_state(priv);
 }
 
-static void iwl4965_bg_restart(struct work_struct *data)
+static void iwl_bg_restart(struct work_struct *data)
 {
        struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
 
-       iwl4965_down(priv);
+       iwl_down(priv);
        queue_work(priv->workqueue, &priv->up);
 }
 
-static void iwl4965_bg_rx_replenish(struct work_struct *data)
+static void iwl_bg_rx_replenish(struct work_struct *data)
 {
        struct iwl_priv *priv =
            container_of(data, struct iwl_priv, rx_replenish);
@@ -2461,21 +2193,19 @@ static void iwl4965_bg_rx_replenish(struct work_struct *data)
 
 #define IWL_DELAY_NEXT_SCAN (HZ*2)
 
-static void iwl4965_post_associate(struct iwl_priv *priv)
+static void iwl_post_associate(struct iwl_priv *priv)
 {
        struct ieee80211_conf *conf = NULL;
        int ret = 0;
-       DECLARE_MAC_BUF(mac);
        unsigned long flags;
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
+       if (priv->iw_mode == NL80211_IFTYPE_AP) {
                IWL_ERROR("%s Should not be called in AP mode\n", __func__);
                return;
        }
 
-       IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
-                       priv->assoc_id,
-                       print_mac(mac, priv->active_rxon.bssid_addr));
+       IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
+                       priv->assoc_id, priv->active_rxon.bssid_addr);
 
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
@@ -2485,15 +2215,15 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
        if (!priv->vif || !priv->is_open)
                return;
 
+       iwl_power_cancel_timeout(priv);
        iwl_scan_cancel_timeout(priv, 200);
 
        conf = ieee80211_get_hw_conf(priv->hw);
 
        priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
-       iwl4965_commit_rxon(priv);
+       iwl_commit_rxon(priv);
 
-       memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
-       iwl4965_setup_rxon_timing(priv);
+       iwl_setup_rxon_timing(priv);
        ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
                              sizeof(priv->rxon_timing), &priv->rxon_timing);
        if (ret)
@@ -2502,8 +2232,7 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
 
        priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
 
-       if (priv->current_ht_config.is_ht)
-               iwl_set_rxon_ht(priv, &priv->current_ht_config);
+       iwl_set_rxon_ht(priv, &priv->current_ht_config);
 
        iwl_set_rxon_chain(priv);
        priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
@@ -2522,24 +2251,24 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
                else
                        priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
 
-               if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
+               if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
                        priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
 
        }
 
-       iwl4965_commit_rxon(priv);
+       iwl_commit_rxon(priv);
 
        switch (priv->iw_mode) {
-       case IEEE80211_IF_TYPE_STA:
+       case NL80211_IFTYPE_STATION:
                break;
 
-       case IEEE80211_IF_TYPE_IBSS:
+       case NL80211_IFTYPE_ADHOC:
 
                /* assume default assoc id */
                priv->assoc_id = 1;
 
                iwl_rxon_add_station(priv, priv->bssid, 0);
-               iwl4965_send_beacon_cmd(priv);
+               iwl_send_beacon_cmd(priv);
 
                break;
 
@@ -2549,44 +2278,23 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
                break;
        }
 
-       /* Enable Rx differential gain and sensitivity calibrations */
-       iwl_chain_noise_reset(priv);
-       priv->start_calib = 1;
-
-       if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
+       if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
                priv->assoc_station_added = 1;
 
        spin_lock_irqsave(&priv->lock, flags);
        iwl_activate_qos(priv, 0);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       iwl_power_update_mode(priv, 0);
-       /* we have just associated, don't start scan too early */
-       priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
-}
-
-static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
-
-static void iwl_bg_scan_completed(struct work_struct *work)
-{
-       struct iwl_priv *priv =
-           container_of(work, struct iwl_priv, scan_completed);
+       /* the chain noise calibration will enabled PM upon completion
+        * If chain noise has already been run, then we need to enable
+        * power management here */
+       if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
+               iwl_power_enable_management(priv);
 
-       IWL_DEBUG_SCAN("SCAN complete scan\n");
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return;
-
-       if (test_bit(STATUS_CONF_PENDING, &priv->status))
-               iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
-
-       ieee80211_scan_completed(priv->hw);
+       /* Enable Rx differential gain and sensitivity calibrations */
+       iwl_chain_noise_reset(priv);
+       priv->start_calib = 1;
 
-       /* 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);
 }
 
 /*****************************************************************************
@@ -2597,7 +2305,7 @@ static void iwl_bg_scan_completed(struct work_struct *work)
 
 #define UCODE_READY_TIMEOUT    (4 * HZ)
 
-static int iwl4965_mac_start(struct ieee80211_hw *hw)
+static int iwl_mac_start(struct ieee80211_hw *hw)
 {
        struct iwl_priv *priv = hw->priv;
        int ret;
@@ -2619,7 +2327,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
                pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
        }
 
-       ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
+       ret = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
                          DRV_NAME, priv);
        if (ret) {
                IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
@@ -2634,7 +2342,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
         * ucode filename and max sizes are card-specific. */
 
        if (!priv->ucode_code.len) {
-               ret = iwl4965_read_ucode(priv);
+               ret = iwl_read_ucode(priv);
                if (ret) {
                        IWL_ERROR("Could not read microcode: %d\n", ret);
                        mutex_unlock(&priv->mutex);
@@ -2642,7 +2350,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
                }
        }
 
-       ret = __iwl4965_up(priv);
+       ret = __iwl_up(priv);
 
        mutex_unlock(&priv->mutex);
 
@@ -2688,7 +2396,7 @@ out_disable_msi:
        return ret;
 }
 
-static void iwl4965_mac_stop(struct ieee80211_hw *hw)
+static void iwl_mac_stop(struct ieee80211_hw *hw)
 {
        struct iwl_priv *priv = hw->priv;
 
@@ -2710,7 +2418,7 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
                mutex_unlock(&priv->mutex);
        }
 
-       iwl4965_down(priv);
+       iwl_down(priv);
 
        flush_workqueue(priv->workqueue);
        free_irq(priv->pci_dev->irq, priv);
@@ -2721,18 +2429,12 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
        IWL_DEBUG_MAC80211("leave\n");
 }
 
-static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
        struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MACDUMP("enter\n");
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
-               IWL_DEBUG_MAC80211("leave - monitor\n");
-               dev_kfree_skb_any(skb);
-               return 0;
-       }
-
        IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
                     ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
 
@@ -2743,12 +2445,11 @@ static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
        return 0;
 }
 
-static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
+static int iwl_mac_add_interface(struct ieee80211_hw *hw,
                                 struct ieee80211_if_init_conf *conf)
 {
        struct iwl_priv *priv = hw->priv;
        unsigned long flags;
-       DECLARE_MAC_BUF(mac);
 
        IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
 
@@ -2759,17 +2460,18 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
 
        spin_lock_irqsave(&priv->lock, flags);
        priv->vif = conf->vif;
+       priv->iw_mode = conf->type;
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
        mutex_lock(&priv->mutex);
 
        if (conf->mac_addr) {
-               IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
+               IWL_DEBUG_MAC80211("Set %pM\n", conf->mac_addr);
                memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
        }
 
-       if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
+       if (iwl_set_mode(priv, conf->type) == -EAGAIN)
                /* we are not ready, will run again when ready */
                set_bit(STATUS_MODE_PENDING, &priv->status);
 
@@ -2780,16 +2482,17 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
 }
 
 /**
- * iwl4965_mac_config - mac80211 config callback
+ * iwl_mac_config - mac80211 config callback
  *
  * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  * be set inappropriately and the driver currently sets the hardware up to
  * use it whenever needed.
  */
-static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
+static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
 {
        struct iwl_priv *priv = hw->priv;
        const struct iwl_channel_info *ch_info;
+       struct ieee80211_conf *conf = &hw->conf;
        unsigned long flags;
        int ret = 0;
        u16 channel;
@@ -2797,7 +2500,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
        mutex_lock(&priv->mutex);
        IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
 
-       priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
+       priv->current_ht_config.is_ht = conf->ht.enabled;
 
        if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
                IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
@@ -2816,7 +2519,6 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
        if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
                     test_bit(STATUS_SCANNING, &priv->status))) {
                IWL_DEBUG_MAC80211("leave - scanning\n");
-               set_bit(STATUS_CONF_PENDING, &priv->status);
                mutex_unlock(&priv->mutex);
                return 0;
        }
@@ -2829,7 +2531,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
                goto out;
        }
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
+       if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
            !is_channel_ibss(ch_info)) {
                IWL_ERROR("channel %d in band %d not IBSS channel\n",
                        conf->channel->hw_value, conf->channel->band);
@@ -2850,20 +2552,20 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
        )
                priv->staging_rxon.flags = 0;
 
-       iwl_set_rxon_channel(priv, conf->channel->band, channel);
+       iwl_set_rxon_channel(priv, conf->channel);
 
        iwl_set_flags_for_band(priv, conf->channel->band);
 
        /* The list of supported rates and rate mask can be different
         * for each band; since the band may have changed, reset
         * the rate mask to what mac80211 lists */
-       iwl4965_set_rate(priv);
+       iwl_set_rate(priv);
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
        if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
-               iwl4965_hw_channel_switch(priv, conf->channel);
+               iwl_hw_channel_switch(priv, conf->channel);
                goto out;
        }
 #endif
@@ -2879,28 +2581,34 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
                goto out;
        }
 
+       if (conf->flags & IEEE80211_CONF_PS)
+               ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
+       else
+               ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
+       if (ret)
+               IWL_DEBUG_MAC80211("Error setting power level\n");
+
        IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
                           priv->tx_power_user_lmt, conf->power_level);
 
        iwl_set_tx_power(priv, conf->power_level, false);
 
-       iwl4965_set_rate(priv);
+       iwl_set_rate(priv);
 
        if (memcmp(&priv->active_rxon,
                   &priv->staging_rxon, sizeof(priv->staging_rxon)))
-               iwl4965_commit_rxon(priv);
+               iwl_commit_rxon(priv);
        else
                IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
 
        IWL_DEBUG_MAC80211("leave\n");
 
 out:
-       clear_bit(STATUS_CONF_PENDING, &priv->status);
        mutex_unlock(&priv->mutex);
        return ret;
 }
 
-static void iwl4965_config_ap(struct iwl_priv *priv)
+static void iwl_config_ap(struct iwl_priv *priv)
 {
        int ret = 0;
        unsigned long flags;
@@ -2909,15 +2617,14 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
                return;
 
        /* The following should be done only at AP bring up */
-       if (!(iwl_is_associated(priv))) {
+       if (!iwl_is_associated(priv)) {
 
                /* RXON - unassoc (to set timing command) */
                priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
-               iwl4965_commit_rxon(priv);
+               iwl_commit_rxon(priv);
 
                /* RXON Timing */
-               memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
-               iwl4965_setup_rxon_timing(priv);
+               iwl_setup_rxon_timing(priv);
                ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
                                sizeof(priv->rxon_timing), &priv->rxon_timing);
                if (ret)
@@ -2944,35 +2651,31 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
                                priv->staging_rxon.flags &=
                                        ~RXON_FLG_SHORT_SLOT_MSK;
 
-                       if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
+                       if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
                                priv->staging_rxon.flags &=
                                        ~RXON_FLG_SHORT_SLOT_MSK;
                }
                /* restore RXON assoc */
                priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
-               iwl4965_commit_rxon(priv);
+               iwl_commit_rxon(priv);
                spin_lock_irqsave(&priv->lock, flags);
                iwl_activate_qos(priv, 1);
                spin_unlock_irqrestore(&priv->lock, flags);
                iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
        }
-       iwl4965_send_beacon_cmd(priv);
+       iwl_send_beacon_cmd(priv);
 
        /* FIXME - we need to add code here to detect a totally new
         * configuration, reset the AP, unassoc, rxon timing, assoc,
         * clear sta table, add BCAST sta... */
 }
 
-/* temporary */
-static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
 
-static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
+static int iwl_mac_config_interface(struct ieee80211_hw *hw,
                                        struct ieee80211_vif *vif,
                                    struct ieee80211_if_conf *conf)
 {
        struct iwl_priv *priv = hw->priv;
-       DECLARE_MAC_BUF(mac);
-       unsigned long flags;
        int rc;
 
        if (conf == NULL)
@@ -2983,31 +2686,25 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
                return 0;
        }
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
+       if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
            conf->changed & IEEE80211_IFCC_BEACON) {
                struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
                if (!beacon)
                        return -ENOMEM;
-               rc = iwl4965_mac_beacon_update(hw, beacon);
+               mutex_lock(&priv->mutex);
+               rc = iwl_mac_beacon_update(hw, beacon);
+               mutex_unlock(&priv->mutex);
                if (rc)
                        return rc;
        }
 
-       if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
-           (!conf->ssid_len)) {
-               IWL_DEBUG_MAC80211
-                   ("Leaving in AP mode because HostAPD is not ready.\n");
-               return 0;
-       }
-
        if (!iwl_is_alive(priv))
                return -EAGAIN;
 
        mutex_lock(&priv->mutex);
 
        if (conf->bssid)
-               IWL_DEBUG_MAC80211("bssid: %s\n",
-                                  print_mac(mac, conf->bssid));
+               IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
 
 /*
  * very dubious code was here; the probe filtering flag is never set:
@@ -3016,12 +2713,12 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
            !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  */
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
+       if (priv->iw_mode == NL80211_IFTYPE_AP) {
                if (!conf->bssid) {
                        conf->bssid = priv->mac_addr;
                        memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
-                       IWL_DEBUG_MAC80211("bssid was set to: %s\n",
-                                          print_mac(mac, conf->bssid));
+                       IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
+                                          conf->bssid);
                }
                if (priv->ibss_beacon)
                        dev_kfree_skb(priv->ibss_beacon);
@@ -3051,11 +2748,11 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
                 * to verify) - jpk */
                memcpy(priv->bssid, conf->bssid, ETH_ALEN);
 
-               if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
-                       iwl4965_config_ap(priv);
+               if (priv->iw_mode == NL80211_IFTYPE_AP)
+                       iwl_config_ap(priv);
                else {
-                       rc = iwl4965_commit_rxon(priv);
-                       if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
+                       rc = iwl_commit_rxon(priv);
+                       if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
                                iwl_rxon_add_station(
                                        priv, priv->active_rxon.bssid_addr, 1);
                }
@@ -3063,45 +2760,63 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
        } else {
                iwl_scan_cancel_timeout(priv, 100);
                priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
-               iwl4965_commit_rxon(priv);
+               iwl_commit_rxon(priv);
        }
 
  done:
-       spin_lock_irqsave(&priv->lock, flags);
-       if (!conf->ssid_len)
-               memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
-       else
-               memcpy(priv->essid, conf->ssid, conf->ssid_len);
-
-       priv->essid_len = conf->ssid_len;
-       spin_unlock_irqrestore(&priv->lock, flags);
-
        IWL_DEBUG_MAC80211("leave\n");
        mutex_unlock(&priv->mutex);
 
        return 0;
 }
 
-static void iwl4965_configure_filter(struct ieee80211_hw *hw,
+static void iwl_configure_filter(struct ieee80211_hw *hw,
                                 unsigned int changed_flags,
                                 unsigned int *total_flags,
                                 int mc_count, struct dev_addr_list *mc_list)
 {
        struct iwl_priv *priv = hw->priv;
+       __le32 *filter_flags = &priv->staging_rxon.filter_flags;
 
-       if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
-               IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
-                                  IEEE80211_IF_TYPE_MNTR,
-                                  changed_flags, *total_flags);
-               /* queue work 'cuz mac80211 is holding a lock which
-                * prevents us from issuing (synchronous) f/w cmds */
-               queue_work(priv->workqueue, &priv->set_monitor);
+       IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
+                       changed_flags, *total_flags);
+
+       if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
+               if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
+                       *filter_flags |= RXON_FILTER_PROMISC_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
+       }
+       if (changed_flags & FIF_ALLMULTI) {
+               if (*total_flags & FIF_ALLMULTI)
+                       *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
+       }
+       if (changed_flags & FIF_CONTROL) {
+               if (*total_flags & FIF_CONTROL)
+                       *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
        }
-       *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
+       if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
+               if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
+                       *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
+       }
+
+       /* We avoid iwl_commit_rxon here to commit the new filter flags
+        * since mac80211 will call ieee80211_hw_config immediately.
+        * (mc_list is not supported at this time). Otherwise, we need to
+        * queue a background iwl_commit_rxon work.
+        */
+
+       *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
                        FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
 }
 
-static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
+static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
                                     struct ieee80211_if_init_conf *conf)
 {
        struct iwl_priv *priv = hw->priv;
@@ -3113,13 +2828,11 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
        if (iwl_is_ready_rf(priv)) {
                iwl_scan_cancel_timeout(priv, 100);
                priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
-               iwl4965_commit_rxon(priv);
+               iwl_commit_rxon(priv);
        }
        if (priv->vif == conf->vif) {
                priv->vif = NULL;
                memset(priv->bssid, 0, ETH_ALEN);
-               memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
-               priv->essid_len = 0;
        }
        mutex_unlock(&priv->mutex);
 
@@ -3128,7 +2841,7 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
 }
 
 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
-static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
+static void iwl_bss_info_changed(struct ieee80211_hw *hw,
                                     struct ieee80211_vif *vif,
                                     struct ieee80211_bss_conf *bss_conf,
                                     u32 changes)
@@ -3155,8 +2868,7 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
        }
 
        if (changes & BSS_CHANGED_HT) {
-               IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
-               iwl4965_ht_conf(priv, bss_conf);
+               iwl_ht_conf(priv, bss_conf);
                iwl_set_rxon_chain(priv);
        }
 
@@ -3172,10 +2884,14 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
                        priv->power_data.dtim_period = bss_conf->dtim_period;
                        priv->timestamp = bss_conf->timestamp;
                        priv->assoc_capability = bss_conf->assoc_capability;
+
+                       /* we have just associated, don't start scan too early
+                        * leave time for EAPOL exchange to complete
+                        */
                        priv->next_scan_jiffies = jiffies +
                                        IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
                        mutex_lock(&priv->mutex);
-                       iwl4965_post_associate(priv);
+                       iwl_post_associate(priv);
                        mutex_unlock(&priv->mutex);
                } else {
                        priv->assoc_id = 0;
@@ -3188,11 +2904,11 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
 
 }
 
-static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
+static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
 {
-       int rc = 0;
        unsigned long flags;
        struct iwl_priv *priv = hw->priv;
+       int ret;
 
        IWL_DEBUG_MAC80211("enter\n");
 
@@ -3200,41 +2916,47 @@ static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
        spin_lock_irqsave(&priv->lock, flags);
 
        if (!iwl_is_ready_rf(priv)) {
-               rc = -EIO;
+               ret = -EIO;
                IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
                goto out_unlock;
        }
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {    /* APs don't scan */
-               rc = -EIO;
+       if (priv->iw_mode == NL80211_IFTYPE_AP) {       /* APs don't scan */
+               ret = -EIO;
                IWL_ERROR("ERROR: APs don't scan\n");
                goto out_unlock;
        }
 
-       /* we don't schedule scan within next_scan_jiffies period */
+       /* We don't schedule scan within next_scan_jiffies period.
+        * Avoid scanning during possible EAPOL exchange, return
+        * success immediately.
+        */
        if (priv->next_scan_jiffies &&
-                       time_after(priv->next_scan_jiffies, jiffies)) {
-               rc = -EAGAIN;
+           time_after(priv->next_scan_jiffies, jiffies)) {
+               IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
+               queue_work(priv->workqueue, &priv->scan_completed);
+               ret = 0;
                goto out_unlock;
        }
+
        /* if we just finished scan ask for delay */
-       if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
-                               IWL_DELAY_NEXT_SCAN, jiffies)) {
-               rc = -EAGAIN;
+       if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
+           time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
+               IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
+               queue_work(priv->workqueue, &priv->scan_completed);
+               ret = 0;
                goto out_unlock;
        }
-       if (len) {
-               IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
-                              iwl_escape_essid(ssid, len), (int)len);
 
+       if (ssid_len) {
                priv->one_direct_scan = 1;
-               priv->direct_ssid_len = (u8)
-                   min((u8) len, (u8) IW_ESSID_MAX_SIZE);
+               priv->direct_ssid_len =  min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
                memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
-       } else
+       } else {
                priv->one_direct_scan = 0;
+       }
 
-       rc = iwl_scan_initiate(priv);
+       ret = iwl_scan_initiate(priv);
 
        IWL_DEBUG_MAC80211("leave\n");
 
@@ -3242,63 +2964,27 @@ out_unlock:
        spin_unlock_irqrestore(&priv->lock, flags);
        mutex_unlock(&priv->mutex);
 
-       return rc;
+       return ret;
 }
 
-static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
+static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
                        struct ieee80211_key_conf *keyconf, const u8 *addr,
                        u32 iv32, u16 *phase1key)
 {
-       struct iwl_priv *priv = hw->priv;
-       u8 sta_id = IWL_INVALID_STATION;
-       unsigned long flags;
-       __le16 key_flags = 0;
-       int i;
-       DECLARE_MAC_BUF(mac);
 
+       struct iwl_priv *priv = hw->priv;
        IWL_DEBUG_MAC80211("enter\n");
 
-       sta_id = iwl_find_station(priv, addr);
-       if (sta_id == IWL_INVALID_STATION) {
-               IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
-                                  print_mac(mac, addr));
-               return;
-       }
-
-       iwl_scan_cancel_timeout(priv, 100);
-
-       key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
-       key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
-       key_flags &= ~STA_KEY_FLG_INVALID;
-
-       if (sta_id == priv->hw_params.bcast_sta_id)
-               key_flags |= STA_KEY_MULTICAST_MSK;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-
-       priv->stations[sta_id].sta.key.key_flags = key_flags;
-       priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
-
-       for (i = 0; i < 5; i++)
-               priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
-                       cpu_to_le16(phase1key[i]);
-
-       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-
-       iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
-
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
 
        IWL_DEBUG_MAC80211("leave\n");
 }
 
-static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                           const u8 *local_addr, const u8 *addr,
                           struct ieee80211_key_conf *key)
 {
        struct iwl_priv *priv = hw->priv;
-       DECLARE_MAC_BUF(mac);
        int ret = 0;
        u8 sta_id = IWL_INVALID_STATION;
        u8 is_default_wep_key = 0;
@@ -3316,8 +3002,8 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        sta_id = iwl_find_station(priv, addr);
        if (sta_id == IWL_INVALID_STATION) {
-               IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
-                                  print_mac(mac, addr));
+               IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
+                                  addr);
                return -EINVAL;
 
        }
@@ -3331,7 +3017,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
         * in 1X mode.
         * In legacy wep mode, we use another host command to the uCode */
        if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
-               priv->iw_mode != IEEE80211_IF_TYPE_AP) {
+               priv->iw_mode != NL80211_IFTYPE_AP) {
                if (cmd == SET_KEY)
                        is_default_wep_key = !priv->key_mapping_key;
                else
@@ -3365,7 +3051,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        return ret;
 }
 
-static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
+static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
                           const struct ieee80211_tx_queue_params *params)
 {
        struct iwl_priv *priv = hw->priv;
@@ -3402,7 +3088,7 @@ static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
        priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
        priv->qos_data.qos_active = 1;
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
+       if (priv->iw_mode == NL80211_IFTYPE_AP)
                iwl_activate_qos(priv, 1);
        else if (priv->assoc_id && iwl_is_associated(priv))
                iwl_activate_qos(priv, 0);
@@ -3413,15 +3099,14 @@ static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
        return 0;
 }
 
-static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
+static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
                             enum ieee80211_ampdu_mlme_action action,
-                            const u8 *addr, u16 tid, u16 *ssn)
+                            struct ieee80211_sta *sta, u16 tid, u16 *ssn)
 {
        struct iwl_priv *priv = hw->priv;
-       DECLARE_MAC_BUF(mac);
 
-       IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
-                    print_mac(mac, addr), tid);
+       IWL_DEBUG_HT("A-MPDU action on addr %pM tid %d\n",
+                    sta->addr, tid);
 
        if (!(priv->cfg->sku & IWL_SKU_N))
                return -EACCES;
@@ -3429,16 +3114,16 @@ static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
        switch (action) {
        case IEEE80211_AMPDU_RX_START:
                IWL_DEBUG_HT("start Rx\n");
-               return iwl_rx_agg_start(priv, addr, tid, *ssn);
+               return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
        case IEEE80211_AMPDU_RX_STOP:
                IWL_DEBUG_HT("stop Rx\n");
-               return iwl_rx_agg_stop(priv, addr, tid);
+               return iwl_sta_rx_agg_stop(priv, sta->addr, tid);
        case IEEE80211_AMPDU_TX_START:
                IWL_DEBUG_HT("start Tx\n");
-               return iwl_tx_agg_start(priv, addr, tid, ssn);
+               return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
        case IEEE80211_AMPDU_TX_STOP:
                IWL_DEBUG_HT("stop Tx\n");
-               return iwl_tx_agg_stop(priv, addr, tid);
+               return iwl_tx_agg_stop(priv, sta->addr, tid);
        default:
                IWL_DEBUG_HT("unknown\n");
                return -EINVAL;
@@ -3446,7 +3131,8 @@ static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
        }
        return 0;
 }
-static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
+
+static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
                                struct ieee80211_tx_queue_stats *stats)
 {
        struct iwl_priv *priv = hw->priv;
@@ -3481,7 +3167,7 @@ static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
        return 0;
 }
 
-static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
+static int iwl_mac_get_stats(struct ieee80211_hw *hw,
                             struct ieee80211_low_level_stats *stats)
 {
        struct iwl_priv *priv = hw->priv;
@@ -3493,7 +3179,7 @@ static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
        return 0;
 }
 
-static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
+static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
 {
        struct iwl_priv *priv = hw->priv;
        unsigned long flags;
@@ -3520,7 +3206,7 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
 
        priv->beacon_int = priv->hw->conf.beacon_int;
        priv->timestamp = 0;
-       if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
+       if ((priv->iw_mode == NL80211_IFTYPE_STATION))
                priv->beacon_int = 0;
 
        spin_unlock_irqrestore(&priv->lock, flags);
@@ -3534,47 +3220,54 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
        /* we are restarting association process
         * clear RXON_FILTER_ASSOC_MSK bit
         */
-       if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
+       if (priv->iw_mode != NL80211_IFTYPE_AP) {
                iwl_scan_cancel_timeout(priv, 100);
                priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
-               iwl4965_commit_rxon(priv);
+               iwl_commit_rxon(priv);
        }
 
        iwl_power_update_mode(priv, 0);
 
        /* Per mac80211.h: This is only used in IBSS mode... */
-       if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
+       if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
+
+               /* switch to CAM during association period.
+                * the ucode will block any association/authentication
+                * frome during assiciation period if it can not hear
+                * the AP because of PM. the timer enable PM back is
+                * association do not complete
+                */
+               if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
+                                                    IEEE80211_CHAN_RADAR))
+                               iwl_power_disable_management(priv, 3000);
 
                IWL_DEBUG_MAC80211("leave - not in IBSS\n");
                mutex_unlock(&priv->mutex);
                return;
        }
 
-       iwl4965_set_rate(priv);
+       iwl_set_rate(priv);
 
        mutex_unlock(&priv->mutex);
 
        IWL_DEBUG_MAC80211("leave\n");
 }
 
-static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
+static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
        struct iwl_priv *priv = hw->priv;
        unsigned long flags;
        __le64 timestamp;
 
-       mutex_lock(&priv->mutex);
        IWL_DEBUG_MAC80211("enter\n");
 
        if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_MAC80211("leave - RF not ready\n");
-               mutex_unlock(&priv->mutex);
                return -EIO;
        }
 
-       if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
+       if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
                IWL_DEBUG_MAC80211("leave - not IBSS\n");
-               mutex_unlock(&priv->mutex);
                return -EIO;
        }
 
@@ -3594,9 +3287,8 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
 
        iwl_reset_qos(priv);
 
-       iwl4965_post_associate(priv);
+       iwl_post_associate(priv);
 
-       mutex_unlock(&priv->mutex);
 
        return 0;
 }
@@ -3629,11 +3321,11 @@ static ssize_t store_debug_level(struct device *d,
                                 const char *buf, size_t count)
 {
        struct iwl_priv *priv = d->driver_data;
-       char *p = (char *)buf;
-       u32 val;
+       unsigned long val;
+       int ret;
 
-       val = simple_strtoul(p, &p, 0);
-       if (p == buf)
+       ret = strict_strtoul(buf, 0, &val);
+       if (ret)
                printk(KERN_INFO DRV_NAME
                       ": %s is not in hex or decimal form.\n", buf);
        else
@@ -3705,11 +3397,11 @@ static ssize_t store_tx_power(struct device *d,
                              const char *buf, size_t count)
 {
        struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
-       char *p = (char *)buf;
-       u32 val;
+       unsigned long val;
+       int ret;
 
-       val = simple_strtoul(p, &p, 10);
-       if (p == buf)
+       ret = strict_strtoul(buf, 10, &val);
+       if (ret)
                printk(KERN_INFO DRV_NAME
                       ": %s is not in decimal form.\n", buf);
        else
@@ -3733,7 +3425,12 @@ static ssize_t store_flags(struct device *d,
                           const char *buf, size_t count)
 {
        struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
-       u32 flags = simple_strtoul(buf, NULL, 0);
+       unsigned long val;
+       u32 flags;
+       int ret = strict_strtoul(buf, 0, &val);
+       if (ret)
+               return ret;
+       flags = (u32)val;
 
        mutex_lock(&priv->mutex);
        if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
@@ -3741,10 +3438,9 @@ static ssize_t store_flags(struct device *d,
                if (iwl_scan_cancel_timeout(priv, 100))
                        IWL_WARNING("Could not cancel scan.\n");
                else {
-                       IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
-                                      flags);
+                       IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
                        priv->staging_rxon.flags = cpu_to_le32(flags);
-                       iwl4965_commit_rxon(priv);
+                       iwl_commit_rxon(priv);
                }
        }
        mutex_unlock(&priv->mutex);
@@ -3768,7 +3464,12 @@ static ssize_t store_filter_flags(struct device *d,
                                  const char *buf, size_t count)
 {
        struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
-       u32 filter_flags = simple_strtoul(buf, NULL, 0);
+       unsigned long val;
+       u32 filter_flags;
+       int ret = strict_strtoul(buf, 0, &val);
+       if (ret)
+               return ret;
+       filter_flags = (u32)val;
 
        mutex_lock(&priv->mutex);
        if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
@@ -3780,7 +3481,7 @@ static ssize_t store_filter_flags(struct device *d,
                                       "0x%04X\n", filter_flags);
                        priv->staging_rxon.filter_flags =
                                cpu_to_le32(filter_flags);
-                       iwl4965_commit_rxon(priv);
+                       iwl_commit_rxon(priv);
                }
        }
        mutex_unlock(&priv->mutex);
@@ -3791,88 +3492,17 @@ static ssize_t store_filter_flags(struct device *d,
 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
                   store_filter_flags);
 
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-
-static ssize_t show_measurement(struct device *d,
-                               struct device_attribute *attr, char *buf)
-{
-       struct iwl_priv *priv = dev_get_drvdata(d);
-       struct iwl4965_spectrum_notification measure_report;
-       u32 size = sizeof(measure_report), len = 0, ofs = 0;
-       u8 *data = (u8 *)&measure_report;
-       unsigned long flags;
-
-       spin_lock_irqsave(&priv->lock, flags);
-       if (!(priv->measurement_status & MEASUREMENT_READY)) {
-               spin_unlock_irqrestore(&priv->lock, flags);
-               return 0;
-       }
-       memcpy(&measure_report, &priv->measure_report, size);
-       priv->measurement_status = 0;
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       while (size && (PAGE_SIZE - len)) {
-               hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
-                                  PAGE_SIZE - len, 1);
-               len = strlen(buf);
-               if (PAGE_SIZE - len)
-                       buf[len++] = '\n';
-
-               ofs += 16;
-               size -= min(size, 16U);
-       }
-
-       return len;
-}
-
-static ssize_t store_measurement(struct device *d,
-                                struct device_attribute *attr,
-                                const char *buf, size_t count)
-{
-       struct iwl_priv *priv = dev_get_drvdata(d);
-       struct ieee80211_measurement_params params = {
-               .channel = le16_to_cpu(priv->active_rxon.channel),
-               .start_time = cpu_to_le64(priv->last_tsf),
-               .duration = cpu_to_le16(1),
-       };
-       u8 type = IWL_MEASURE_BASIC;
-       u8 buffer[32];
-       u8 channel;
-
-       if (count) {
-               char *p = buffer;
-               strncpy(buffer, buf, min(sizeof(buffer), count));
-               channel = simple_strtoul(p, NULL, 0);
-               if (channel)
-                       params.channel = channel;
-
-               p = buffer;
-               while (*p && *p != ' ')
-                       p++;
-               if (*p)
-                       type = simple_strtoul(p + 1, NULL, 0);
-       }
-
-       IWL_DEBUG_INFO("Invoking measurement of type %d on "
-                      "channel %d (for '%s')\n", type, params.channel, buf);
-       iwl4965_get_measurement(priv, &params, type);
-
-       return count;
-}
-
-static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
-                  show_measurement, store_measurement);
-#endif /* CONFIG_IWLAGN_SPECTRUM_MEASUREMENT */
-
 static ssize_t store_retry_rate(struct device *d,
                                struct device_attribute *attr,
                                const char *buf, size_t count)
 {
        struct iwl_priv *priv = dev_get_drvdata(d);
+       long val;
+       int ret  = strict_strtol(buf, 10, &val);
+       if (!ret)
+               return ret;
 
-       priv->retry_rate = simple_strtoul(buf, NULL, 0);
-       if (priv->retry_rate <= 0)
-               priv->retry_rate = 1;
+       priv->retry_rate = (val > 0) ? val : 1;
 
        return count;
 }
@@ -3893,9 +3523,9 @@ static ssize_t store_power_level(struct device *d,
 {
        struct iwl_priv *priv = dev_get_drvdata(d);
        int ret;
-       int mode;
+       unsigned long mode;
+
 
-       mode = simple_strtoul(buf, NULL, 0);
        mutex_lock(&priv->mutex);
 
        if (!iwl_is_ready(priv)) {
@@ -3903,6 +3533,10 @@ static ssize_t store_power_level(struct device *d,
                goto out;
        }
 
+       ret = strict_strtoul(buf, 10, &mode);
+       if (ret)
+               goto out;
+
        ret = iwl_power_set_user_mode(priv, mode);
        if (ret) {
                IWL_DEBUG_MAC80211("failed setting power mode.\n");
@@ -3936,7 +3570,8 @@ static ssize_t show_power_level(struct device *d,
                break;
        }
 
-       p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO)?"fixed":"auto");
+       p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
+                       "fixed" : "auto");
        p += sprintf(p, "\tINDEX:%d", level);
        p += sprintf(p, "\n");
        return p - buf + 1;
@@ -3945,68 +3580,6 @@ static ssize_t show_power_level(struct device *d,
 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
                   store_power_level);
 
-static ssize_t show_channels(struct device *d,
-                            struct device_attribute *attr, char *buf)
-{
-
-       struct iwl_priv *priv = dev_get_drvdata(d);
-       struct ieee80211_channel *channels = NULL;
-       const struct ieee80211_supported_band *supp_band = NULL;
-       int len = 0, i;
-       int count = 0;
-
-       if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
-               return -EAGAIN;
-
-       supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
-       channels = supp_band->channels;
-       count = supp_band->n_channels;
-
-       len += sprintf(&buf[len],
-                       "Displaying %d channels in 2.4GHz band "
-                       "(802.11bg):\n", count);
-
-       for (i = 0; i < count; i++)
-               len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
-                               ieee80211_frequency_to_channel(
-                               channels[i].center_freq),
-                               channels[i].max_power,
-                               channels[i].flags & IEEE80211_CHAN_RADAR ?
-                               " (IEEE 802.11h required)" : "",
-                               (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
-                               || (channels[i].flags &
-                               IEEE80211_CHAN_RADAR)) ? "" :
-                               ", IBSS",
-                               channels[i].flags &
-                               IEEE80211_CHAN_PASSIVE_SCAN ?
-                               "passive only" : "active/passive");
-
-       supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
-       channels = supp_band->channels;
-       count = supp_band->n_channels;
-
-       len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
-                       "(802.11a):\n", count);
-
-       for (i = 0; i < count; i++)
-               len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
-                               ieee80211_frequency_to_channel(
-                               channels[i].center_freq),
-                               channels[i].max_power,
-                               channels[i].flags & IEEE80211_CHAN_RADAR ?
-                               " (IEEE 802.11h required)" : "",
-                               ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
-                               || (channels[i].flags &
-                               IEEE80211_CHAN_RADAR)) ? "" :
-                               ", IBSS",
-                               channels[i].flags &
-                               IEEE80211_CHAN_PASSIVE_SCAN ?
-                               "passive only" : "active/passive");
-
-       return len;
-}
-
-static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
 
 static ssize_t show_statistics(struct device *d,
                               struct device_attribute *attr, char *buf)
@@ -4069,29 +3642,27 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
 
        init_waitqueue_head(&priv->wait_command_queue);
 
-       INIT_WORK(&priv->up, iwl4965_bg_up);
-       INIT_WORK(&priv->restart, iwl4965_bg_restart);
-       INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
-       INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
-       INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
-       INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
+       INIT_WORK(&priv->up, iwl_bg_up);
+       INIT_WORK(&priv->restart, iwl_bg_restart);
+       INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
+       INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
+       INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
        INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
        INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
        INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
 
-       /* FIXME : remove when resolved PENDING */
-       INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
        iwl_setup_scan_deferred_work(priv);
+       iwl_setup_power_deferred_work(priv);
 
        if (priv->cfg->ops->lib->setup_deferred_work)
                priv->cfg->ops->lib->setup_deferred_work(priv);
 
        init_timer(&priv->statistics_periodic);
        priv->statistics_periodic.data = (unsigned long)priv;
-       priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
+       priv->statistics_periodic.function = iwl_bg_statistics_periodic;
 
        tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
-                    iwl4965_irq_tasklet, (unsigned long)priv);
+                    iwl_irq_tasklet, (unsigned long)priv);
 }
 
 static void iwl_cancel_deferred_work(struct iwl_priv *priv)
@@ -4101,18 +3672,15 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
 
        cancel_delayed_work_sync(&priv->init_alive_start);
        cancel_delayed_work(&priv->scan_check);
+       cancel_delayed_work_sync(&priv->set_power_save);
        cancel_delayed_work(&priv->alive_start);
        cancel_work_sync(&priv->beacon_update);
        del_timer_sync(&priv->statistics_periodic);
 }
 
-static struct attribute *iwl4965_sysfs_entries[] = {
-       &dev_attr_channels.attr,
+static struct attribute *iwl_sysfs_entries[] = {
        &dev_attr_flags.attr,
        &dev_attr_filter_flags.attr,
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-       &dev_attr_measurement.attr,
-#endif
        &dev_attr_power_level.attr,
        &dev_attr_retry_rate.attr,
        &dev_attr_statistics.attr,
@@ -4127,39 +3695,38 @@ static struct attribute *iwl4965_sysfs_entries[] = {
        NULL
 };
 
-static struct attribute_group iwl4965_attribute_group = {
+static struct attribute_group iwl_attribute_group = {
        .name = NULL,           /* put in device directory */
-       .attrs = iwl4965_sysfs_entries,
+       .attrs = iwl_sysfs_entries,
 };
 
-static struct ieee80211_ops iwl4965_hw_ops = {
-       .tx = iwl4965_mac_tx,
-       .start = iwl4965_mac_start,
-       .stop = iwl4965_mac_stop,
-       .add_interface = iwl4965_mac_add_interface,
-       .remove_interface = iwl4965_mac_remove_interface,
-       .config = iwl4965_mac_config,
-       .config_interface = iwl4965_mac_config_interface,
-       .configure_filter = iwl4965_configure_filter,
-       .set_key = iwl4965_mac_set_key,
-       .update_tkip_key = iwl4965_mac_update_tkip_key,
-       .get_stats = iwl4965_mac_get_stats,
-       .get_tx_stats = iwl4965_mac_get_tx_stats,
-       .conf_tx = iwl4965_mac_conf_tx,
-       .reset_tsf = iwl4965_mac_reset_tsf,
-       .bss_info_changed = iwl4965_bss_info_changed,
-       .ampdu_action = iwl4965_mac_ampdu_action,
-       .hw_scan = iwl4965_mac_hw_scan
+static struct ieee80211_ops iwl_hw_ops = {
+       .tx = iwl_mac_tx,
+       .start = iwl_mac_start,
+       .stop = iwl_mac_stop,
+       .add_interface = iwl_mac_add_interface,
+       .remove_interface = iwl_mac_remove_interface,
+       .config = iwl_mac_config,
+       .config_interface = iwl_mac_config_interface,
+       .configure_filter = iwl_configure_filter,
+       .set_key = iwl_mac_set_key,
+       .update_tkip_key = iwl_mac_update_tkip_key,
+       .get_stats = iwl_mac_get_stats,
+       .get_tx_stats = iwl_mac_get_tx_stats,
+       .conf_tx = iwl_mac_conf_tx,
+       .reset_tsf = iwl_mac_reset_tsf,
+       .bss_info_changed = iwl_bss_info_changed,
+       .ampdu_action = iwl_mac_ampdu_action,
+       .hw_scan = iwl_mac_hw_scan
 };
 
-static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        int err = 0;
        struct iwl_priv *priv;
        struct ieee80211_hw *hw;
        struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
        unsigned long flags;
-       DECLARE_MAC_BUF(mac);
 
        /************************
         * 1. Allocating HW data
@@ -4171,10 +3738,10 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
                if (cfg->mod_params->debug & IWL_DL_INFO)
                        dev_printk(KERN_DEBUG, &(pdev->dev),
                                   "Disabling hw_scan\n");
-               iwl4965_hw_ops.hw_scan = NULL;
+               iwl_hw_ops.hw_scan = NULL;
        }
 
-       hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
+       hw = iwl_alloc_all(cfg, &iwl_hw_ops);
        if (!hw) {
                err = -ENOMEM;
                goto out;
@@ -4203,13 +3770,13 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        pci_set_master(pdev);
 
-       err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
+       err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
        if (!err)
-               err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
+               err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
        if (err) {
-               err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+               err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
                if (!err)
-                       err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+                       err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
                /* both attempts failed: */
                if (err) {
                        printk(KERN_WARNING "%s: No suitable DMA available.\n",
@@ -4224,9 +3791,6 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        pci_set_drvdata(pdev, priv);
 
-       /* We disable the RETRY_TIMEOUT register (0x41) to keep
-        * PCI Tx retries from interfering with C3 CPU state */
-       pci_write_config_byte(pdev, 0x41, 0x00);
 
        /***********************
         * 3. Read REV register
@@ -4246,6 +3810,10 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
                ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
                priv->cfg->name, priv->hw_rev);
 
+       /* We disable the RETRY_TIMEOUT register (0x41) to keep
+        * PCI Tx retries from interfering with C3 CPU state */
+       pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
+
        /* amp init */
        err = priv->cfg->ops->lib->apm_ops.init(priv);
        if (err < 0) {
@@ -4267,7 +3835,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        /* extract MAC Address */
        iwl_eeprom_get_mac(priv, priv->mac_addr);
-       IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
+       IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
        SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
 
        /************************
@@ -4301,10 +3869,10 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
         * 8. Setup services
         ********************/
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_disable_interrupts(priv);
+       iwl_disable_interrupts(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
+       err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
        if (err) {
                IWL_ERROR("failed to create sysfs device attributes\n");
                goto out_uninit_drv;
@@ -4340,7 +3908,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        return 0;
 
  out_remove_sysfs:
-       sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
+       sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  out_uninit_drv:
        iwl_uninit_drv(priv);
  out_free_eeprom:
@@ -4358,7 +3926,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        return err;
 }
 
-static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
+static void __devexit iwl_pci_remove(struct pci_dev *pdev)
 {
        struct iwl_priv *priv = pci_get_drvdata(pdev);
        unsigned long flags;
@@ -4369,28 +3937,31 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
        IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
 
        iwl_dbgfs_unregister(priv);
-       sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
+       sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
 
+       /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
+        * to be called and iwl_down since we are removing the device
+        * we need to set STATUS_EXIT_PENDING bit.
+        */
+       set_bit(STATUS_EXIT_PENDING, &priv->status);
        if (priv->mac80211_registered) {
                ieee80211_unregister_hw(priv->hw);
                priv->mac80211_registered = 0;
+       } else {
+               iwl_down(priv);
        }
 
-       set_bit(STATUS_EXIT_PENDING, &priv->status);
-
-       iwl4965_down(priv);
-
        /* make sure we flush any pending irq or
         * tasklet for the driver
         */
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_disable_interrupts(priv);
+       iwl_disable_interrupts(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        iwl_synchronize_irq(priv);
 
        iwl_rfkill_unregister(priv);
-       iwl4965_dealloc_ucode_pci(priv);
+       iwl_dealloc_ucode_pci(priv);
 
        if (priv->rxq.bd)
                iwl_rx_queue_free(priv, &priv->rxq);
@@ -4403,7 +3974,7 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
        /*netif_stop_queue(dev); */
        flush_workqueue(priv->workqueue);
 
-       /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
+       /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
         * priv->workqueue... so we can't take down the workqueue
         * until now... */
        destroy_workqueue(priv->workqueue);
@@ -4424,13 +3995,13 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
 
 #ifdef CONFIG_PM
 
-static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct iwl_priv *priv = pci_get_drvdata(pdev);
 
        if (priv->is_open) {
                set_bit(STATUS_IN_SUSPEND, &priv->status);
-               iwl4965_mac_stop(priv->hw);
+               iwl_mac_stop(priv->hw);
                priv->is_open = 1;
        }
 
@@ -4439,14 +4010,14 @@ static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        return 0;
 }
 
-static int iwl4965_pci_resume(struct pci_dev *pdev)
+static int iwl_pci_resume(struct pci_dev *pdev)
 {
        struct iwl_priv *priv = pci_get_drvdata(pdev);
 
        pci_set_power_state(pdev, PCI_D0);
 
        if (priv->is_open)
-               iwl4965_mac_start(priv->hw);
+               iwl_mac_start(priv->hw);
 
        clear_bit(STATUS_IN_SUSPEND, &priv->status);
        return 0;
@@ -4477,8 +4048,15 @@ static struct pci_device_id iwl_hw_card_ids[] = {
        {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
        {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
        {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
-       {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
+/* 5350 WiFi/WiMax */
+       {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
+       {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
+       {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
+/* 5150 Wifi/WiMax */
+       {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
+       {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
 #endif /* CONFIG_IWL5000 */
+
        {0}
 };
 MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
@@ -4486,15 +4064,15 @@ MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
 static struct pci_driver iwl_driver = {
        .name = DRV_NAME,
        .id_table = iwl_hw_card_ids,
-       .probe = iwl4965_pci_probe,
-       .remove = __devexit_p(iwl4965_pci_remove),
+       .probe = iwl_pci_probe,
+       .remove = __devexit_p(iwl_pci_remove),
 #ifdef CONFIG_PM
-       .suspend = iwl4965_pci_suspend,
-       .resume = iwl4965_pci_resume,
+       .suspend = iwl_pci_suspend,
+       .resume = iwl_pci_resume,
 #endif
 };
 
-static int __init iwl4965_init(void)
+static int __init iwl_init(void)
 {
 
        int ret;
@@ -4520,11 +4098,11 @@ error_register:
        return ret;
 }
 
-static void __exit iwl4965_exit(void)
+static void __exit iwl_exit(void)
 {
        pci_unregister_driver(&iwl_driver);
        iwlagn_rate_control_unregister();
 }
 
-module_exit(iwl4965_exit);
-module_init(iwl4965_init);
+module_exit(iwl_exit);
+module_init(iwl_init);