iwlwifi: fix incorrect 5GHz rates reported in monitor mode
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-4965.c
index a79e8c3..de330ae 100644 (file)
 #include <linux/etherdevice.h>
 #include <asm/unaligned.h>
 
-#include "iwl-core.h"
+#include "iwl-eeprom.h"
 #include "iwl-4965.h"
+#include "iwl-core.h"
+#include "iwl-io.h"
 #include "iwl-helpers.h"
 
-static void iwl4965_hw_card_show_info(struct iwl4965_priv *priv);
+/* module parameters */
+static struct iwl_mod_params iwl4965_mod_params = {
+       .num_of_queues = IWL4965_MAX_NUM_QUEUES,
+       .enable_qos = 1,
+       .amsdu_size_8K = 1,
+       /* the rest are 0 by default */
+};
+
+static void iwl4965_hw_card_show_info(struct iwl_priv *priv);
 
 #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np)    \
        [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP,      \
@@ -104,13 +114,253 @@ static const u16 default_tid_to_tx_fifo[] = {
 
 #endif /*CONFIG_IWL4965_HT */
 
+/* check contents of special bootstrap uCode SRAM */
+static int iwl4965_verify_bsm(struct iwl_priv *priv)
+{
+       __le32 *image = priv->ucode_boot.v_addr;
+       u32 len = priv->ucode_boot.len;
+       u32 reg;
+       u32 val;
+
+       IWL_DEBUG_INFO("Begin verify bsm\n");
+
+       /* verify BSM SRAM contents */
+       val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
+       for (reg = BSM_SRAM_LOWER_BOUND;
+            reg < BSM_SRAM_LOWER_BOUND + len;
+            reg += sizeof(u32), image++) {
+               val = iwl_read_prph(priv, reg);
+               if (val != le32_to_cpu(*image)) {
+                       IWL_ERROR("BSM uCode verification failed at "
+                                 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
+                                 BSM_SRAM_LOWER_BOUND,
+                                 reg - BSM_SRAM_LOWER_BOUND, len,
+                                 val, le32_to_cpu(*image));
+                       return -EIO;
+               }
+       }
+
+       IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
+
+       return 0;
+}
+
+/**
+ * iwl4965_load_bsm - Load bootstrap instructions
+ *
+ * BSM operation:
+ *
+ * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
+ * in special SRAM that does not power down during RFKILL.  When powering back
+ * up after power-saving sleeps (or during initial uCode load), the BSM loads
+ * the bootstrap program into the on-board processor, and starts it.
+ *
+ * The bootstrap program loads (via DMA) instructions and data for a new
+ * program from host DRAM locations indicated by the host driver in the
+ * BSM_DRAM_* registers.  Once the new program is loaded, it starts
+ * automatically.
+ *
+ * When initializing the NIC, the host driver points the BSM to the
+ * "initialize" uCode image.  This uCode sets up some internal data, then
+ * notifies host via "initialize alive" that it is complete.
+ *
+ * The host then replaces the BSM_DRAM_* pointer values to point to the
+ * normal runtime uCode instructions and a backup uCode data cache buffer
+ * (filled initially with starting data values for the on-board processor),
+ * then triggers the "initialize" uCode to load and launch the runtime uCode,
+ * which begins normal operation.
+ *
+ * When doing a power-save shutdown, runtime uCode saves data SRAM into
+ * the backup data cache in DRAM before SRAM is powered down.
+ *
+ * When powering back up, the BSM loads the bootstrap program.  This reloads
+ * the runtime uCode instructions and the backup data cache into SRAM,
+ * and re-launches the runtime uCode from where it left off.
+ */
+static int iwl4965_load_bsm(struct iwl_priv *priv)
+{
+       __le32 *image = priv->ucode_boot.v_addr;
+       u32 len = priv->ucode_boot.len;
+       dma_addr_t pinst;
+       dma_addr_t pdata;
+       u32 inst_len;
+       u32 data_len;
+       int i;
+       u32 done;
+       u32 reg_offset;
+       int ret;
+
+       IWL_DEBUG_INFO("Begin load bsm\n");
+
+       /* make sure bootstrap program is no larger than BSM's SRAM size */
+       if (len > IWL_MAX_BSM_SIZE)
+               return -EINVAL;
+
+       /* Tell bootstrap uCode where to find the "Initialize" uCode
+        *   in host DRAM ... host DRAM physical address bits 35:4 for 4965.
+        * NOTE:  iwl4965_initialize_alive_start() will replace these values,
+        *        after the "initialize" uCode has run, to point to
+        *        runtime/protocol instructions and backup data cache. */
+       pinst = priv->ucode_init.p_addr >> 4;
+       pdata = priv->ucode_init_data.p_addr >> 4;
+       inst_len = priv->ucode_init.len;
+       data_len = priv->ucode_init_data.len;
+
+       ret = iwl_grab_nic_access(priv);
+       if (ret)
+               return ret;
+
+       iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
+       iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
+       iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
+       iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
+
+       /* Fill BSM memory with bootstrap instructions */
+       for (reg_offset = BSM_SRAM_LOWER_BOUND;
+            reg_offset < BSM_SRAM_LOWER_BOUND + len;
+            reg_offset += sizeof(u32), image++)
+               _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
+
+       ret = iwl4965_verify_bsm(priv);
+       if (ret) {
+               iwl_release_nic_access(priv);
+               return ret;
+       }
+
+       /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
+       iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
+       iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
+       iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
+
+       /* Load bootstrap code into instruction SRAM now,
+        *   to prepare to load "initialize" uCode */
+       iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
+
+       /* Wait for load of bootstrap uCode to finish */
+       for (i = 0; i < 100; i++) {
+               done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
+               if (!(done & BSM_WR_CTRL_REG_BIT_START))
+                       break;
+               udelay(10);
+       }
+       if (i < 100)
+               IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
+       else {
+               IWL_ERROR("BSM write did not complete!\n");
+               return -EIO;
+       }
+
+       /* Enable future boot loads whenever power management unit triggers it
+        *   (e.g. when powering back up after power-save shutdown) */
+       iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
+
+       iwl_release_nic_access(priv);
+
+       return 0;
+}
+
+static int iwl4965_init_drv(struct iwl_priv *priv)
+{
+       int ret;
+       int i;
+
+       priv->antenna = (enum iwl4965_antenna)priv->cfg->mod_params->antenna;
+       priv->retry_rate = 1;
+       priv->ibss_beacon = NULL;
+
+       spin_lock_init(&priv->lock);
+       spin_lock_init(&priv->power_data.lock);
+       spin_lock_init(&priv->sta_lock);
+       spin_lock_init(&priv->hcmd_lock);
+       spin_lock_init(&priv->lq_mngr.lock);
+
+       priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
+                                       sizeof(struct iwl4965_shared),
+                                       &priv->shared_phys);
+
+       if (!priv->shared_virt) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
+
+
+       for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
+               INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
+
+       INIT_LIST_HEAD(&priv->free_frames);
+
+       mutex_init(&priv->mutex);
+
+       /* Clear the driver's (not device's) station table */
+       iwlcore_clear_stations_table(priv);
+
+       priv->data_retry_limit = -1;
+       priv->ieee_channels = NULL;
+       priv->ieee_rates = NULL;
+       priv->band = IEEE80211_BAND_2GHZ;
+
+       priv->iw_mode = IEEE80211_IF_TYPE_STA;
+
+       priv->use_ant_b_for_management_frame = 1; /* start with ant B */
+       priv->valid_antenna = 0x7;      /* assume all 3 connected */
+       priv->ps_mode = IWL_MIMO_PS_NONE;
+
+       /* Choose which receivers/antennas to use */
+       iwl4965_set_rxon_chain(priv);
+
+       iwlcore_reset_qos(priv);
+
+       priv->qos_data.qos_active = 0;
+       priv->qos_data.qos_cap.val = 0;
+
+       iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
+
+       priv->rates_mask = IWL_RATES_MASK;
+       /* If power management is turned on, default to AC mode */
+       priv->power_mode = IWL_POWER_AC;
+       priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
+
+       ret = iwl_init_channel_map(priv);
+       if (ret) {
+               IWL_ERROR("initializing regulatory failed: %d\n", ret);
+               goto err;
+       }
+
+       ret = iwl4965_init_geos(priv);
+       if (ret) {
+               IWL_ERROR("initializing geos failed: %d\n", ret);
+               goto err_free_channel_map;
+       }
+
+       ret = ieee80211_register_hw(priv->hw);
+       if (ret) {
+               IWL_ERROR("Failed to register network device (error %d)\n",
+                               ret);
+               goto err_free_geos;
+       }
+
+       priv->hw->conf.beacon_int = 100;
+       priv->mac80211_registered = 1;
+
+       return 0;
+
+err_free_geos:
+       iwl4965_free_geos(priv);
+err_free_channel_map:
+       iwl_free_channel_map(priv);
+err:
+       return ret;
+}
+
 static int is_fat_channel(__le32 rxon_flags)
 {
        return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
                (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
 }
 
-static u8 is_single_stream(struct iwl4965_priv *priv)
+static u8 is_single_stream(struct iwl_priv *priv)
 {
 #ifdef CONFIG_IWL4965_HT
        if (!priv->current_ht_config.is_ht ||
@@ -154,13 +404,13 @@ int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
 /**
  * translate ucode response to mac80211 tx status control values
  */
-void iwl4965_hwrate_to_tx_control(struct iwl4965_priv *priv, u32 rate_n_flags,
+void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
                                  struct ieee80211_tx_control *control)
 {
        int rate_index;
 
        control->antenna_sel_tx =
-               ((rate_n_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_A_POS);
+               ((rate_n_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS);
        if (rate_n_flags & RATE_MCS_HT_MSK)
                control->flags |= IEEE80211_TXCTL_OFDM_HT;
        if (rate_n_flags & RATE_MCS_GF_MSK)
@@ -187,7 +437,7 @@ void iwl4965_hwrate_to_tx_control(struct iwl4965_priv *priv, u32 rate_n_flags,
  * MIMO (dual stream) requires at least 2, but works better with 3.
  * This does not determine *which* chains to use, just how many.
  */
-static int iwl4965_get_rx_chain_counter(struct iwl4965_priv *priv,
+static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv,
                                        u8 *idle_state, u8 *rx_state)
 {
        u8 is_single = is_single_stream(priv);
@@ -216,32 +466,32 @@ static int iwl4965_get_rx_chain_counter(struct iwl4965_priv *priv,
        return 0;
 }
 
-int iwl4965_hw_rxq_stop(struct iwl4965_priv *priv)
+int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
 {
        int rc;
        unsigned long flags;
 
        spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                spin_unlock_irqrestore(&priv->lock, flags);
                return rc;
        }
 
        /* stop Rx DMA */
-       iwl4965_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
-       rc = iwl4965_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
+       iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
+       rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
                                     (1 << 24), 1000);
        if (rc < 0)
                IWL_ERROR("Can't stop Rx DMA.\n");
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return 0;
 }
 
-u8 iwl4965_hw_find_station(struct iwl4965_priv *priv, const u8 *addr)
+u8 iwl4965_hw_find_station(struct iwl_priv *priv, const u8 *addr)
 {
        int i;
        int start = 0;
@@ -254,10 +504,10 @@ u8 iwl4965_hw_find_station(struct iwl4965_priv *priv, const u8 *addr)
                start = IWL_STA_ID;
 
        if (is_broadcast_ether_addr(addr))
-               return priv->hw_setting.bcast_sta_id;
+               return priv->hw_params.bcast_sta_id;
 
        spin_lock_irqsave(&priv->sta_lock, flags);
-       for (i = start; i < priv->hw_setting.max_stations; i++)
+       for (i = start; i < priv->hw_params.max_stations; i++)
                if ((priv->stations[i].used) &&
                    (!compare_ether_addr
                     (priv->stations[i].sta.sta.addr, addr))) {
@@ -273,13 +523,13 @@ u8 iwl4965_hw_find_station(struct iwl4965_priv *priv, const u8 *addr)
        return ret;
 }
 
-static int iwl4965_nic_set_pwr_src(struct iwl4965_priv *priv, int pwr_max)
+static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
 {
        int ret;
        unsigned long flags;
 
        spin_lock_irqsave(&priv->lock, flags);
-       ret = iwl4965_grab_nic_access(priv);
+       ret = iwl_grab_nic_access(priv);
        if (ret) {
                spin_unlock_irqrestore(&priv->lock, flags);
                return ret;
@@ -292,92 +542,92 @@ static int iwl4965_nic_set_pwr_src(struct iwl4965_priv *priv, int pwr_max)
                                           &val);
 
                if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
-                       iwl4965_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
+                       iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
                                APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
                                ~APMG_PS_CTRL_MSK_PWR_SRC);
        } else
-               iwl4965_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
+               iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
                        APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
                        ~APMG_PS_CTRL_MSK_PWR_SRC);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return ret;
 }
 
-static int iwl4965_rx_init(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
+static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
 {
-       int rc;
+       int ret;
        unsigned long flags;
        unsigned int rb_size;
 
        spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl4965_grab_nic_access(priv);
-       if (rc) {
+       ret = iwl_grab_nic_access(priv);
+       if (ret) {
                spin_unlock_irqrestore(&priv->lock, flags);
-               return rc;
+               return ret;
        }
 
-       if (iwl4965_param_amsdu_size_8K)
+       if (priv->cfg->mod_params->amsdu_size_8K)
                rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
        else
                rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
 
        /* Stop Rx DMA */
-       iwl4965_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
+       iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
 
        /* Reset driver's Rx queue write index */
-       iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
+       iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
 
        /* Tell device where to find RBD circular buffer in DRAM */
-       iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
-                            rxq->dma_addr >> 8);
+       iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
+                          rxq->dma_addr >> 8);
 
        /* Tell device where in DRAM to update its Rx status */
-       iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
-                            (priv->hw_setting.shared_phys +
-                             offsetof(struct iwl4965_shared, val0)) >> 4);
+       iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
+                          (priv->shared_phys +
+                           offsetof(struct iwl4965_shared, rb_closed)) >> 4);
 
        /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */
-       iwl4965_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
-                            FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
-                            FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
-                            rb_size |
-                            /*0x10 << 4 | */
-                            (RX_QUEUE_SIZE_LOG <<
+       iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
+                          FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
+                          FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
+                          rb_size |
+                            /* 0x10 << 4 | */
+                          (RX_QUEUE_SIZE_LOG <<
                              FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT));
 
        /*
-        * iwl4965_write32(priv,CSR_INT_COAL_REG,0);
+        * iwl_write32(priv,CSR_INT_COAL_REG,0);
         */
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return 0;
 }
 
 /* Tell 4965 where to find the "keep warm" buffer */
-static int iwl4965_kw_init(struct iwl4965_priv *priv)
+static int iwl4965_kw_init(struct iwl_priv *priv)
 {
        unsigned long flags;
        int rc;
 
        spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc)
                goto out;
 
-       iwl4965_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
+       iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
                             priv->kw.dma_addr >> 4);
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 out:
        spin_unlock_irqrestore(&priv->lock, flags);
        return rc;
 }
 
-static int iwl4965_kw_alloc(struct iwl4965_priv *priv)
+static int iwl4965_kw_alloc(struct iwl_priv *priv)
 {
        struct pci_dev *dev = priv->pci_dev;
        struct iwl4965_kw *kw = &priv->kw;
@@ -390,59 +640,10 @@ static int iwl4965_kw_alloc(struct iwl4965_priv *priv)
        return 0;
 }
 
-#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
-                           ? # x " " : "")
-
-/**
- * iwl4965_set_fat_chan_info - Copy fat channel info into driver's priv.
- *
- * Does not set up a command, or touch hardware.
- */
-int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv,
-                             enum ieee80211_band band, u16 channel,
-                             const struct iwl4965_eeprom_channel *eeprom_ch,
-                             u8 fat_extension_channel)
-{
-       struct iwl4965_channel_info *ch_info;
-
-       ch_info = (struct iwl4965_channel_info *)
-                       iwl4965_get_channel_info(priv, band, channel);
-
-       if (!is_channel_valid(ch_info))
-               return -1;
-
-       IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
-                       " %ddBm): Ad-Hoc %ssupported\n",
-                       ch_info->channel,
-                       is_channel_a_band(ch_info) ?
-                       "5.2" : "2.4",
-                       CHECK_AND_PRINT(IBSS),
-                       CHECK_AND_PRINT(ACTIVE),
-                       CHECK_AND_PRINT(RADAR),
-                       CHECK_AND_PRINT(WIDE),
-                       CHECK_AND_PRINT(NARROW),
-                       CHECK_AND_PRINT(DFS),
-                       eeprom_ch->flags,
-                       eeprom_ch->max_power_avg,
-                       ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
-                        && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
-                       "" : "not ");
-
-       ch_info->fat_eeprom = *eeprom_ch;
-       ch_info->fat_max_power_avg = eeprom_ch->max_power_avg;
-       ch_info->fat_curr_txpow = eeprom_ch->max_power_avg;
-       ch_info->fat_min_power = 0;
-       ch_info->fat_scan_power = eeprom_ch->max_power_avg;
-       ch_info->fat_flags = eeprom_ch->flags;
-       ch_info->fat_extension_channel = fat_extension_channel;
-
-       return 0;
-}
-
 /**
  * iwl4965_kw_free - Free the "keep warm" buffer
  */
-static void iwl4965_kw_free(struct iwl4965_priv *priv)
+static void iwl4965_kw_free(struct iwl_priv *priv)
 {
        struct pci_dev *dev = priv->pci_dev;
        struct iwl4965_kw *kw = &priv->kw;
@@ -460,7 +661,7 @@ static void iwl4965_kw_free(struct iwl4965_priv *priv)
  * @param priv
  * @return error code
  */
-static int iwl4965_txq_ctx_reset(struct iwl4965_priv *priv)
+static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
 {
        int rc = 0;
        int txq_id, slots_num;
@@ -480,7 +681,7 @@ static int iwl4965_txq_ctx_reset(struct iwl4965_priv *priv)
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (unlikely(rc)) {
                IWL_ERROR("TX reset failed");
                spin_unlock_irqrestore(&priv->lock, flags);
@@ -488,8 +689,8 @@ static int iwl4965_txq_ctx_reset(struct iwl4965_priv *priv)
        }
 
        /* Turn off all Tx DMA channels */
-       iwl4965_write_prph(priv, KDR_SCD_TXFACT, 0);
-       iwl4965_release_nic_access(priv);
+       iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        /* Tell 4965 where to find the keep-warm buffer */
@@ -501,7 +702,7 @@ static int iwl4965_txq_ctx_reset(struct iwl4965_priv *priv)
 
        /* Alloc and init all (default 16) Tx queues,
         * including the command queue (#4) */
-       for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) {
+       for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
                slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
                                        TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
                rc = iwl4965_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
@@ -522,7 +723,7 @@ static int iwl4965_txq_ctx_reset(struct iwl4965_priv *priv)
        return rc;
 }
 
-int iwl4965_hw_nic_init(struct iwl4965_priv *priv)
+int iwl4965_hw_nic_init(struct iwl_priv *priv)
 {
        int rc;
        unsigned long flags;
@@ -536,11 +737,11 @@ int iwl4965_hw_nic_init(struct iwl4965_priv *priv)
        /* nic_init */
        spin_lock_irqsave(&priv->lock, flags);
 
-       iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS,
+       iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
                    CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
 
-       iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
-       rc = iwl4965_poll_bit(priv, CSR_GP_CNTRL,
+       iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
+       rc = iwl_poll_bit(priv, CSR_GP_CNTRL,
                          CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
                          CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
        if (rc < 0) {
@@ -549,26 +750,25 @@ int iwl4965_hw_nic_init(struct iwl4965_priv *priv)
                return rc;
        }
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                spin_unlock_irqrestore(&priv->lock, flags);
                return rc;
        }
 
-       iwl4965_read_prph(priv, APMG_CLK_CTRL_REG);
+       iwl_read_prph(priv, APMG_CLK_CTRL_REG);
 
-       iwl4965_write_prph(priv, APMG_CLK_CTRL_REG,
-                                APMG_CLK_VAL_DMA_CLK_RQT |
-                                APMG_CLK_VAL_BSM_CLK_RQT);
-       iwl4965_read_prph(priv, APMG_CLK_CTRL_REG);
+       iwl_write_prph(priv, APMG_CLK_CTRL_REG,
+                       APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
+       iwl_read_prph(priv, APMG_CLK_CTRL_REG);
 
        udelay(20);
 
-       iwl4965_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
-                                   APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
+       iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
+                               APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
 
-       iwl4965_release_nic_access(priv);
-       iwl4965_write32(priv, CSR_INT_COALESCING, 512 / 32);
+       iwl_release_nic_access(priv);
+       iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        /* Determine HW type */
@@ -604,26 +804,24 @@ int iwl4965_hw_nic_init(struct iwl4965_priv *priv)
 
        /* set CSR_HW_CONFIG_REG for uCode use */
 
-       iwl4965_set_bit(priv, CSR_HW_IF_CONFIG_REG,
-                       CSR49_HW_IF_CONFIG_REG_BIT_4965_R |
-                       CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI |
-                       CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI);
+       iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
+                   CSR49_HW_IF_CONFIG_REG_BIT_4965_R |
+                   CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI |
+                   CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI);
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc < 0) {
                spin_unlock_irqrestore(&priv->lock, flags);
                IWL_DEBUG_INFO("Failed to init the card\n");
                return rc;
        }
 
-       iwl4965_read_prph(priv, APMG_PS_CTRL_REG);
-       iwl4965_set_bits_prph(priv, APMG_PS_CTRL_REG,
-                                   APMG_PS_CTRL_VAL_RESET_REQ);
+       iwl_read_prph(priv, APMG_PS_CTRL_REG);
+       iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
        udelay(5);
-       iwl4965_clear_bits_prph(priv, APMG_PS_CTRL_REG,
-                                     APMG_PS_CTRL_VAL_RESET_REQ);
+       iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        iwl4965_hw_card_show_info(priv);
@@ -667,7 +865,7 @@ int iwl4965_hw_nic_init(struct iwl4965_priv *priv)
        return 0;
 }
 
-int iwl4965_hw_nic_stop_master(struct iwl4965_priv *priv)
+int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
 {
        int rc = 0;
        u32 reg_val;
@@ -676,16 +874,16 @@ int iwl4965_hw_nic_stop_master(struct iwl4965_priv *priv)
        spin_lock_irqsave(&priv->lock, flags);
 
        /* set stop master bit */
-       iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
+       iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
 
-       reg_val = iwl4965_read32(priv, CSR_GP_CNTRL);
+       reg_val = iwl_read32(priv, CSR_GP_CNTRL);
 
        if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
            (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
                IWL_DEBUG_INFO("Card in power save, master is already "
                               "stopped\n");
        else {
-               rc = iwl4965_poll_bit(priv, CSR_RESET,
+               rc = iwl_poll_bit(priv, CSR_RESET,
                                  CSR_RESET_REG_FLAG_MASTER_DISABLED,
                                  CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
                if (rc < 0) {
@@ -703,27 +901,26 @@ int iwl4965_hw_nic_stop_master(struct iwl4965_priv *priv)
 /**
  * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
  */
-void iwl4965_hw_txq_ctx_stop(struct iwl4965_priv *priv)
+void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
 {
 
        int txq_id;
        unsigned long flags;
 
        /* Stop each Tx DMA channel, and wait for it to be idle */
-       for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) {
+       for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
                spin_lock_irqsave(&priv->lock, flags);
-               if (iwl4965_grab_nic_access(priv)) {
+               if (iwl_grab_nic_access(priv)) {
                        spin_unlock_irqrestore(&priv->lock, flags);
                        continue;
                }
 
-               iwl4965_write_direct32(priv,
-                                    IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
-                                    0x0);
-               iwl4965_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG,
-                                       IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
-                                       (txq_id), 200);
-               iwl4965_release_nic_access(priv);
+               iwl_write_direct32(priv,
+                                  IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
+               iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG,
+                                   IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
+                                   (txq_id), 200);
+               iwl_release_nic_access(priv);
                spin_unlock_irqrestore(&priv->lock, flags);
        }
 
@@ -731,7 +928,7 @@ void iwl4965_hw_txq_ctx_stop(struct iwl4965_priv *priv)
        iwl4965_hw_txq_ctx_free(priv);
 }
 
-int iwl4965_hw_nic_reset(struct iwl4965_priv *priv)
+int iwl4965_hw_nic_reset(struct iwl_priv *priv)
 {
        int rc = 0;
        unsigned long flags;
@@ -740,29 +937,29 @@ int iwl4965_hw_nic_reset(struct iwl4965_priv *priv)
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
+       iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
 
        udelay(10);
 
-       iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
-       rc = iwl4965_poll_bit(priv, CSR_RESET,
+       iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
+       rc = iwl_poll_bit(priv, CSR_RESET,
                          CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
                          CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
 
        udelay(10);
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (!rc) {
-               iwl4965_write_prph(priv, APMG_CLK_EN_REG,
-                                        APMG_CLK_VAL_DMA_CLK_RQT |
-                                        APMG_CLK_VAL_BSM_CLK_RQT);
+               iwl_write_prph(priv, APMG_CLK_EN_REG,
+                               APMG_CLK_VAL_DMA_CLK_RQT |
+                               APMG_CLK_VAL_BSM_CLK_RQT);
 
                udelay(10);
 
-               iwl4965_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
-                               APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
+               iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
+                                       APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
 
-               iwl4965_release_nic_access(priv);
+               iwl_release_nic_access(priv);
        }
 
        clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
@@ -779,56 +976,37 @@ int iwl4965_hw_nic_reset(struct iwl4965_priv *priv)
 /**
  * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
  *
- * This callback is provided in order to queue the statistics_work
- * in work_queue context (v. softirq)
+ * This callback is provided in order to send a statistics request.
  *
  * This timer function is continually reset to execute within
  * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  * was received.  We need to ensure we receive the statistics in order
- * to update the temperature used for calibrating the TXPOWER.  However,
- * we can't send the statistics command from softirq context (which
- * is the context which timers run at) so we have to queue off the
- * statistics_work to actually send the command to the hardware.
+ * to update the temperature used for calibrating the TXPOWER.
  */
 static void iwl4965_bg_statistics_periodic(unsigned long data)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)data;
-
-       queue_work(priv->workqueue, &priv->statistics_work);
-}
-
-/**
- * iwl4965_bg_statistics_work - Send the statistics request to the hardware.
- *
- * This is queued by iwl4965_bg_statistics_periodic.
- */
-static void iwl4965_bg_statistics_work(struct work_struct *work)
-{
-       struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv,
-                                            statistics_work);
+       struct iwl_priv *priv = (struct iwl_priv *)data;
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
 
-       mutex_lock(&priv->mutex);
-       iwl4965_send_statistics_request(priv);
-       mutex_unlock(&priv->mutex);
+       iwl_send_statistics_request(priv, CMD_ASYNC);
 }
 
 #define CT_LIMIT_CONST         259
 #define TM_CT_KILL_THRESHOLD   110
 
-void iwl4965_rf_kill_ct_config(struct iwl4965_priv *priv)
+void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
 {
        struct iwl4965_ct_kill_config cmd;
        u32 R1, R2, R3;
        u32 temp_th;
        u32 crit_temperature;
        unsigned long flags;
-       int rc = 0;
+       int ret = 0;
 
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
+       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
                    CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
        spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -846,9 +1024,9 @@ void iwl4965_rf_kill_ct_config(struct iwl4965_priv *priv)
 
        crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2;
        cmd.critical_temperature_R =  cpu_to_le32(crit_temperature);
-       rc = iwl4965_send_cmd_pdu(priv,
-                             REPLY_CT_KILL_CONFIG_CMD, sizeof(cmd), &cmd);
-       if (rc)
+       ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
+                              sizeof(cmd), &cmd);
+       if (ret)
                IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
        else
                IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded\n");
@@ -864,7 +1042,7 @@ void iwl4965_rf_kill_ct_config(struct iwl4965_priv *priv)
  *   enough to receive all of our own network traffic, but not so
  *   high that our DSP gets too busy trying to lock onto non-network
  *   activity/noise. */
-static int iwl4965_sens_energy_cck(struct iwl4965_priv *priv,
+static int iwl4965_sens_energy_cck(struct iwl_priv *priv,
                                   u32 norm_fa,
                                   u32 rx_enable_time,
                                   struct statistics_general_data *rx_info)
@@ -1055,7 +1233,7 @@ static int iwl4965_sens_energy_cck(struct iwl4965_priv *priv,
 }
 
 
-static int iwl4965_sens_auto_corr_ofdm(struct iwl4965_priv *priv,
+static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv,
                                       u32 norm_fa,
                                       u32 rx_enable_time)
 {
@@ -1120,25 +1298,25 @@ static int iwl4965_sens_auto_corr_ofdm(struct iwl4965_priv *priv,
        return 0;
 }
 
-static int iwl4965_sensitivity_callback(struct iwl4965_priv *priv,
-                                   struct iwl4965_cmd *cmd, struct sk_buff *skb)
+static int iwl4965_sensitivity_callback(struct iwl_priv *priv,
+                                   struct iwl_cmd *cmd, struct sk_buff *skb)
 {
        /* We didn't cache the SKB; let the caller free it */
        return 1;
 }
 
 /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
-static int iwl4965_sensitivity_write(struct iwl4965_priv *priv, u8 flags)
+static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags)
 {
-       int rc = 0;
        struct iwl4965_sensitivity_cmd cmd ;
        struct iwl4965_sensitivity_data *data = NULL;
-       struct iwl4965_host_cmd cmd_out = {
+       struct iwl_host_cmd cmd_out = {
                .id = SENSITIVITY_CMD,
                .len = sizeof(struct iwl4965_sensitivity_cmd),
                .meta.flags = flags,
                .data = &cmd,
        };
+       int ret;
 
        data = &(priv->sensitivity_data);
 
@@ -1196,20 +1374,18 @@ static int iwl4965_sensitivity_write(struct iwl4965_priv *priv, u8 flags)
        memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
               sizeof(u16)*HD_TABLE_SIZE);
 
-       rc = iwl4965_send_cmd(priv, &cmd_out);
-       if (!rc) {
-               IWL_DEBUG_CALIB("SENSITIVITY_CMD succeeded\n");
-               return rc;
-       }
+       ret = iwl_send_cmd(priv, &cmd_out);
+       if (ret)
+               IWL_ERROR("SENSITIVITY_CMD failed\n");
 
-       return 0;
+       return ret;
 }
 
-void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags, u8 force)
+void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force)
 {
-       int rc = 0;
-       int i;
        struct iwl4965_sensitivity_data *data = NULL;
+       int i;
+       int ret  = 0;
 
        IWL_DEBUG_CALIB("Start iwl4965_init_sensitivity\n");
 
@@ -1253,8 +1429,8 @@ void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags, u8 force)
                memset(&(priv->sensitivity_tbl[0]), 0,
                    sizeof(u16)*HD_TABLE_SIZE);
 
-       rc |= iwl4965_sensitivity_write(priv, flags);
-       IWL_DEBUG_CALIB("<<return 0x%X\n", rc);
+       ret |= iwl4965_sensitivity_write(priv, flags);
+       IWL_DEBUG_CALIB("<<return 0x%X\n", ret);
 
        return;
 }
@@ -1263,13 +1439,12 @@ void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags, u8 force)
 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  * Called after every association, but this runs only once!
  *  ... once chain noise is calibrated the first time, it's good forever.  */
-void iwl4965_chain_noise_reset(struct iwl4965_priv *priv)
+void iwl4965_chain_noise_reset(struct iwl_priv *priv)
 {
        struct iwl4965_chain_noise_data *data = NULL;
-       int rc = 0;
 
        data = &(priv->chain_noise_data);
-       if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl4965_is_associated(priv)) {
+       if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
                struct iwl4965_calibration_cmd cmd;
 
                memset(&cmd, 0, sizeof(cmd));
@@ -1277,8 +1452,8 @@ void iwl4965_chain_noise_reset(struct iwl4965_priv *priv)
                cmd.diff_gain_a = 0;
                cmd.diff_gain_b = 0;
                cmd.diff_gain_c = 0;
-               rc = iwl4965_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
-                                sizeof(cmd), &cmd);
+               iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
+                                sizeof(cmd), &cmd, NULL);
                msleep(4);
                data->state = IWL_CHAIN_NOISE_ACCUMULATE;
                IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
@@ -1292,11 +1467,11 @@ void iwl4965_chain_noise_reset(struct iwl4965_priv *priv)
  * 1)  Which antennas are connected.
  * 2)  Differential rx gain settings to balance the 3 receivers.
  */
-static void iwl4965_noise_calibration(struct iwl4965_priv *priv,
+static void iwl4965_noise_calibration(struct iwl_priv *priv,
                                      struct iwl4965_notif_statistics *stat_resp)
 {
        struct iwl4965_chain_noise_data *data = NULL;
-       int rc = 0;
+       int ret = 0;
 
        u32 chain_noise_a;
        u32 chain_noise_b;
@@ -1502,9 +1677,9 @@ static void iwl4965_noise_calibration(struct iwl4965_priv *priv,
                        cmd.diff_gain_a = data->delta_gain_code[0];
                        cmd.diff_gain_b = data->delta_gain_code[1];
                        cmd.diff_gain_c = data->delta_gain_code[2];
-                       rc = iwl4965_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
+                       ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
                                              sizeof(cmd), &cmd);
-                       if (rc)
+                       if (ret)
                                IWL_DEBUG_CALIB("fail sending cmd "
                                             "REPLY_PHY_CALIBRATION_CMD \n");
 
@@ -1525,10 +1700,9 @@ static void iwl4965_noise_calibration(struct iwl4965_priv *priv,
        return;
 }
 
-static void iwl4965_sensitivity_calibration(struct iwl4965_priv *priv,
+static void iwl4965_sensitivity_calibration(struct iwl_priv *priv,
                                            struct iwl4965_notif_statistics *resp)
 {
-       int rc = 0;
        u32 rx_enable_time;
        u32 fa_cck;
        u32 fa_ofdm;
@@ -1541,10 +1715,11 @@ static void iwl4965_sensitivity_calibration(struct iwl4965_priv *priv,
        struct statistics_rx *statistics = &(resp->rx);
        unsigned long flags;
        struct statistics_general_data statis;
+       int ret;
 
        data = &(priv->sensitivity_data);
 
-       if (!iwl4965_is_associated(priv)) {
+       if (!iwl_is_associated(priv)) {
                IWL_DEBUG_CALIB("<< - not associated\n");
                return;
        }
@@ -1625,14 +1800,14 @@ static void iwl4965_sensitivity_calibration(struct iwl4965_priv *priv,
 
        iwl4965_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
        iwl4965_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
-       rc |= iwl4965_sensitivity_write(priv, CMD_ASYNC);
+       ret = iwl4965_sensitivity_write(priv, CMD_ASYNC);
 
        return;
 }
 
 static void iwl4965_bg_sensitivity_work(struct work_struct *work)
 {
-       struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv,
+       struct iwl_priv *priv = container_of(work, struct iwl_priv,
                        sensitivity_work);
 
        mutex_lock(&priv->mutex);
@@ -1662,7 +1837,7 @@ static void iwl4965_bg_sensitivity_work(struct work_struct *work)
 
 static void iwl4965_bg_txpower_work(struct work_struct *work)
 {
-       struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv,
+       struct iwl_priv *priv = container_of(work, struct iwl_priv,
                        txpower_work);
 
        /* If a scan happened to start before we got here
@@ -1690,11 +1865,11 @@ static void iwl4965_bg_txpower_work(struct work_struct *work)
 /*
  * Acquire priv->lock before calling this function !
  */
-static void iwl4965_set_wr_ptrs(struct iwl4965_priv *priv, int txq_id, u32 index)
+static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
 {
-       iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
+       iwl_write_direct32(priv, HBUS_TARG_WRPTR,
                             (index & 0xff) | (txq_id << 8));
-       iwl4965_write_prph(priv, KDR_SCD_QUEUE_RDPTR(txq_id), index);
+       iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
 }
 
 /**
@@ -1704,7 +1879,7 @@ static void iwl4965_set_wr_ptrs(struct iwl4965_priv *priv, int txq_id, u32 index
  *
  * NOTE:  Acquire priv->lock before calling this function !
  */
-static void iwl4965_tx_queue_set_status(struct iwl4965_priv *priv,
+static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
                                        struct iwl4965_tx_queue *txq,
                                        int tx_fifo_id, int scd_retry)
 {
@@ -1714,7 +1889,7 @@ static void iwl4965_tx_queue_set_status(struct iwl4965_priv *priv,
        int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
 
        /* Set up and activate */
-       iwl4965_write_prph(priv, KDR_SCD_QUEUE_STATUS_BITS(txq_id),
+       iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
                                 (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
                                 (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) |
                                 (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) |
@@ -1738,22 +1913,22 @@ static const u16 default_queue_to_tx_fifo[] = {
        IWL_TX_FIFO_HCCA_2
 };
 
-static inline void iwl4965_txq_ctx_activate(struct iwl4965_priv *priv, int txq_id)
+static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
 {
        set_bit(txq_id, &priv->txq_ctx_active_msk);
 }
 
-static inline void iwl4965_txq_ctx_deactivate(struct iwl4965_priv *priv, int txq_id)
+static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
 {
        clear_bit(txq_id, &priv->txq_ctx_active_msk);
 }
 
-int iwl4965_alive_notify(struct iwl4965_priv *priv)
+int iwl4965_alive_notify(struct iwl_priv *priv)
 {
        u32 a;
        int i = 0;
        unsigned long flags;
-       int rc;
+       int ret;
 
        spin_lock_irqsave(&priv->lock, flags);
 
@@ -1766,46 +1941,46 @@ int iwl4965_alive_notify(struct iwl4965_priv *priv)
                priv->chain_noise_data.delta_gain_code[i] =
                                CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
 #endif /* CONFIG_IWL4965_SENSITIVITY*/
-       rc = iwl4965_grab_nic_access(priv);
-       if (rc) {
+       ret = iwl_grab_nic_access(priv);
+       if (ret) {
                spin_unlock_irqrestore(&priv->lock, flags);
-               return rc;
+               return ret;
        }
 
        /* Clear 4965's internal Tx Scheduler data base */
-       priv->scd_base_addr = iwl4965_read_prph(priv, KDR_SCD_SRAM_BASE_ADDR);
+       priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
        a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET;
        for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4)
-               iwl4965_write_targ_mem(priv, a, 0);
+               iwl_write_targ_mem(priv, a, 0);
        for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4)
-               iwl4965_write_targ_mem(priv, a, 0);
-       for (; a < sizeof(u16) * priv->hw_setting.max_txq_num; a += 4)
-               iwl4965_write_targ_mem(priv, a, 0);
+               iwl_write_targ_mem(priv, a, 0);
+       for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
+               iwl_write_targ_mem(priv, a, 0);
 
        /* Tel 4965 where to find Tx byte count tables */
-       iwl4965_write_prph(priv, KDR_SCD_DRAM_BASE_ADDR,
-               (priv->hw_setting.shared_phys +
+       iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
+               (priv->shared_phys +
                 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
 
        /* Disable chain mode for all queues */
-       iwl4965_write_prph(priv, KDR_SCD_QUEUECHAIN_SEL, 0);
+       iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
 
        /* Initialize each Tx queue (including the command queue) */
-       for (i = 0; i < priv->hw_setting.max_txq_num; i++) {
+       for (i = 0; i < priv->hw_params.max_txq_num; i++) {
 
                /* TFD circular buffer read/write indexes */
-               iwl4965_write_prph(priv, KDR_SCD_QUEUE_RDPTR(i), 0);
-               iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
+               iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
+               iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
 
                /* Max Tx Window size for Scheduler-ACK mode */
-               iwl4965_write_targ_mem(priv, priv->scd_base_addr +
+               iwl_write_targ_mem(priv, priv->scd_base_addr +
                                        SCD_CONTEXT_QUEUE_OFFSET(i),
                                        (SCD_WIN_SIZE <<
                                        SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
                                        SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
 
                /* Frame limit */
-               iwl4965_write_targ_mem(priv, priv->scd_base_addr +
+               iwl_write_targ_mem(priv, priv->scd_base_addr +
                                        SCD_CONTEXT_QUEUE_OFFSET(i) +
                                        sizeof(u32),
                                        (SCD_FRAME_LIMIT <<
@@ -1813,11 +1988,11 @@ int iwl4965_alive_notify(struct iwl4965_priv *priv)
                                        SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
 
        }
-       iwl4965_write_prph(priv, KDR_SCD_INTERRUPT_MASK,
-                                (1 << priv->hw_setting.max_txq_num) - 1);
+       iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
+                                (1 << priv->hw_params.max_txq_num) - 1);
 
        /* Activate all Tx DMA/FIFO channels */
-       iwl4965_write_prph(priv, KDR_SCD_TXFACT,
+       iwl_write_prph(priv, IWL49_SCD_TXFACT,
                                 SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
 
        iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
@@ -1829,43 +2004,46 @@ int iwl4965_alive_notify(struct iwl4965_priv *priv)
                iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
        }
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       return 0;
+       /* Ask for statistics now, the uCode will send statistics notification
+        * periodically after association */
+       iwl_send_statistics_request(priv, CMD_ASYNC);
+       return ret;
 }
 
 /**
- * iwl4965_hw_set_hw_setting
+ * iwl4965_hw_set_hw_params
  *
  * Called when initializing driver
  */
-int iwl4965_hw_set_hw_setting(struct iwl4965_priv *priv)
+int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
 {
-       /* Allocate area for Tx byte count tables and Rx queue status */
-       priv->hw_setting.shared_virt =
-           pci_alloc_consistent(priv->pci_dev,
-                                sizeof(struct iwl4965_shared),
-                                &priv->hw_setting.shared_phys);
-
-       if (!priv->hw_setting.shared_virt)
-               return -1;
 
-       memset(priv->hw_setting.shared_virt, 0, sizeof(struct iwl4965_shared));
+       if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) ||
+           (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
+               IWL_ERROR("invalid queues_num, should be between %d and %d\n",
+                         IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES);
+               return -EINVAL;
+       }
 
-       priv->hw_setting.max_txq_num = iwl4965_param_queues_num;
-       priv->hw_setting.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
-       priv->hw_setting.max_rxq_size = RX_QUEUE_SIZE;
-       priv->hw_setting.max_rxq_log = RX_QUEUE_SIZE_LOG;
-       if (iwl4965_param_amsdu_size_8K)
-               priv->hw_setting.rx_buf_size = IWL_RX_BUF_SIZE_8K;
+       priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
+       priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
+       priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
+       priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
+       if (priv->cfg->mod_params->amsdu_size_8K)
+               priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
        else
-               priv->hw_setting.rx_buf_size = IWL_RX_BUF_SIZE_4K;
-       priv->hw_setting.max_pkt_size = priv->hw_setting.rx_buf_size - 256;
-       priv->hw_setting.max_stations = IWL4965_STATION_COUNT;
-       priv->hw_setting.bcast_sta_id = IWL4965_BROADCAST_ID;
+               priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
+       priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
+       priv->hw_params.max_stations = IWL4965_STATION_COUNT;
+       priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
 
-       priv->hw_setting.tx_ant_num = 2;
+       priv->hw_params.tx_chains_num = 2;
+       priv->hw_params.rx_chains_num = 2;
+       priv->hw_params.valid_tx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX);
+       priv->hw_params.valid_rx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX);
 
        return 0;
 }
@@ -1875,12 +2053,12 @@ int iwl4965_hw_set_hw_setting(struct iwl4965_priv *priv)
  *
  * Destroy all TX DMA queues and structures
  */
-void iwl4965_hw_txq_ctx_free(struct iwl4965_priv *priv)
+void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv)
 {
        int txq_id;
 
        /* Tx queues */
-       for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++)
+       for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
                iwl4965_tx_queue_free(priv, &priv->txq[txq_id]);
 
        /* Keep-warm buffer */
@@ -1893,7 +2071,7 @@ void iwl4965_hw_txq_ctx_free(struct iwl4965_priv *priv)
  * Does NOT advance any TFD circular buffer read/write indexes
  * Does NOT free the TFD itself (which is within circular buffer)
  */
-int iwl4965_hw_txq_free_tfd(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
+int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
 {
        struct iwl4965_tfd_frame *bd_tmp = (struct iwl4965_tfd_frame *)&txq->bd[0];
        struct iwl4965_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
@@ -1946,7 +2124,7 @@ int iwl4965_hw_txq_free_tfd(struct iwl4965_priv *priv, struct iwl4965_tx_queue *
        return 0;
 }
 
-int iwl4965_hw_reg_set_txpower(struct iwl4965_priv *priv, s8 power)
+int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
 {
        IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
        return -EINVAL;
@@ -2001,13 +2179,13 @@ static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
        return comp;
 }
 
-static const struct iwl4965_channel_info *
-iwl4965_get_channel_txpower_info(struct iwl4965_priv *priv,
+static const struct iwl_channel_info *
+iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
                                 enum ieee80211_band band, u16 channel)
 {
-       const struct iwl4965_channel_info *ch_info;
+       const struct iwl_channel_info *ch_info;
 
-       ch_info = iwl4965_get_channel_info(priv, band, channel);
+       ch_info = iwl_get_channel_info(priv, band, channel);
 
        if (!is_channel_valid(ch_info))
                return NULL;
@@ -2041,7 +2219,7 @@ static s32 iwl4965_get_tx_atten_grp(u16 channel)
        return -1;
 }
 
-static u32 iwl4965_get_sub_band(const struct iwl4965_priv *priv, u32 channel)
+static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
 {
        s32 b = -1;
 
@@ -2077,7 +2255,7 @@ static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  * differences in channel frequencies, which is proportional to differences
  * in channel number.
  */
-static int iwl4965_interpolate_chan(struct iwl4965_priv *priv, u32 channel,
+static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
                                    struct iwl4965_eeprom_calib_ch_info *chan_info)
 {
        s32 s = -1;
@@ -2410,7 +2588,7 @@ static const struct gain_entry gain_table[2][108] = {
         }
 };
 
-static int iwl4965_fill_txpower_tbl(struct iwl4965_priv *priv, u8 band, u16 channel,
+static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
                                    u8 is_fat, u8 ctrl_chan_high,
                                    struct iwl4965_tx_power_db *tx_power_tbl)
 {
@@ -2424,7 +2602,7 @@ static int iwl4965_fill_txpower_tbl(struct iwl4965_priv *priv, u8 band, u16 chan
        s32 txatten_grp = CALIB_CH_GROUP_MAX;
        int i;
        int c;
-       const struct iwl4965_channel_info *ch_info = NULL;
+       const struct iwl_channel_info *ch_info = NULL;
        struct iwl4965_eeprom_calib_ch_info ch_eeprom_info;
        const struct iwl4965_eeprom_calib_measure *measurement;
        s16 voltage;
@@ -2667,10 +2845,10 @@ static int iwl4965_fill_txpower_tbl(struct iwl4965_priv *priv, u8 band, u16 chan
  * Uses the active RXON for channel, band, and characteristics (fat, high)
  * The power limit is taken from priv->user_txpower_limit.
  */
-int iwl4965_hw_reg_send_txpower(struct iwl4965_priv *priv)
+int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
 {
        struct iwl4965_txpowertable_cmd cmd = { 0 };
-       int rc = 0;
+       int ret;
        u8 band = 0;
        u8 is_fat = 0;
        u8 ctrl_chan_high = 0;
@@ -2694,28 +2872,70 @@ int iwl4965_hw_reg_send_txpower(struct iwl4965_priv *priv)
        cmd.band = band;
        cmd.channel = priv->active_rxon.channel;
 
-       rc = iwl4965_fill_txpower_tbl(priv, band,
+       ret = iwl4965_fill_txpower_tbl(priv, band,
                                le16_to_cpu(priv->active_rxon.channel),
                                is_fat, ctrl_chan_high, &cmd.tx_power);
-       if (rc)
-               return rc;
+       if (ret)
+               goto out;
 
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
-       return rc;
+       ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
+
+out:
+       return ret;
+}
+
+static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
+{
+       int ret = 0;
+       struct iwl4965_rxon_assoc_cmd rxon_assoc;
+       const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
+       const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
+
+       if ((rxon1->flags == rxon2->flags) &&
+           (rxon1->filter_flags == rxon2->filter_flags) &&
+           (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
+           (rxon1->ofdm_ht_single_stream_basic_rates ==
+            rxon2->ofdm_ht_single_stream_basic_rates) &&
+           (rxon1->ofdm_ht_dual_stream_basic_rates ==
+            rxon2->ofdm_ht_dual_stream_basic_rates) &&
+           (rxon1->rx_chain == rxon2->rx_chain) &&
+           (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
+               IWL_DEBUG_INFO("Using current RXON_ASSOC.  Not resending.\n");
+               return 0;
+       }
+
+       rxon_assoc.flags = priv->staging_rxon.flags;
+       rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
+       rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
+       rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
+       rxon_assoc.reserved = 0;
+       rxon_assoc.ofdm_ht_single_stream_basic_rates =
+           priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
+       rxon_assoc.ofdm_ht_dual_stream_basic_rates =
+           priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
+       rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
+
+       ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
+                                    sizeof(rxon_assoc), &rxon_assoc, NULL);
+       if (ret)
+               return ret;
+
+       return ret;
 }
 
-int iwl4965_hw_channel_switch(struct iwl4965_priv *priv, u16 channel)
+
+int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
 {
        int rc;
        u8 band = 0;
        u8 is_fat = 0;
        u8 ctrl_chan_high = 0;
        struct iwl4965_channel_switch_cmd cmd = { 0 };
-       const struct iwl4965_channel_info *ch_info;
+       const struct iwl_channel_info *ch_info;
 
        band = priv->band == IEEE80211_BAND_2GHZ;
 
-       ch_info = iwl4965_get_channel_info(priv, priv->band, channel);
+       ch_info = iwl_get_channel_info(priv, priv->band, channel);
 
        is_fat = is_fat_channel(priv->staging_rxon.flags);
 
@@ -2741,15 +2961,15 @@ int iwl4965_hw_channel_switch(struct iwl4965_priv *priv, u16 channel)
                return rc;
        }
 
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
+       rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
        return rc;
 }
 
 #define RTS_HCCA_RETRY_LIMIT           3
 #define RTS_DFAULT_RETRY_LIMIT         60
 
-void iwl4965_hw_build_tx_cmd_rate(struct iwl4965_priv *priv,
-                             struct iwl4965_cmd *cmd,
+void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
+                             struct iwl_cmd *cmd,
                              struct ieee80211_tx_control *ctrl,
                              struct ieee80211_hdr *hdr, int sta_id,
                              int is_hcca)
@@ -2815,19 +3035,18 @@ void iwl4965_hw_build_tx_cmd_rate(struct iwl4965_priv *priv,
        tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
 }
 
-int iwl4965_hw_get_rx_read(struct iwl4965_priv *priv)
+int iwl4965_hw_get_rx_read(struct iwl_priv *priv)
 {
-       struct iwl4965_shared *shared_data = priv->hw_setting.shared_virt;
-
-       return IWL_GET_BITS(*shared_data, rb_closed_stts_rb_num);
+       struct iwl4965_shared *s = priv->shared_virt;
+       return le32_to_cpu(s->rb_closed) & 0xFFF;
 }
 
-int iwl4965_hw_get_temperature(struct iwl4965_priv *priv)
+int iwl4965_hw_get_temperature(struct iwl_priv *priv)
 {
        return priv->temperature;
 }
 
-unsigned int iwl4965_hw_get_beacon_cmd(struct iwl4965_priv *priv,
+unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
                          struct iwl4965_frame *frame, u8 rate)
 {
        struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
@@ -2836,7 +3055,7 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl4965_priv *priv,
        tx_beacon_cmd = &frame->u.beacon;
        memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
 
-       tx_beacon_cmd->tx.sta_id = priv->hw_setting.bcast_sta_id;
+       tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
        tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
 
        frame_size = iwl4965_fill_beacon_frame(priv,
@@ -2866,35 +3085,35 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl4965_priv *priv,
  * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  * channels supported in hardware.
  */
-int iwl4965_hw_tx_queue_init(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
+int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
 {
        int rc;
        unsigned long flags;
        int txq_id = txq->q.id;
 
        spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                spin_unlock_irqrestore(&priv->lock, flags);
                return rc;
        }
 
        /* Circular buffer (TFD queue in DRAM) physical base address */
-       iwl4965_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
+       iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
                             txq->q.dma_addr >> 8);
 
        /* Enable DMA channel, using same id as for TFD queue */
-       iwl4965_write_direct32(
+       iwl_write_direct32(
                priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
                IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
                IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return 0;
 }
 
-int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl4965_priv *priv, void *ptr,
+int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
                                 dma_addr_t addr, u16 len)
 {
        int index, is_odd;
@@ -2928,7 +3147,7 @@ int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl4965_priv *priv, void *ptr,
        return 0;
 }
 
-static void iwl4965_hw_card_show_info(struct iwl4965_priv *priv)
+static void iwl4965_hw_card_show_info(struct iwl_priv *priv)
 {
        u16 hw_version = priv->eeprom.board_revision_4965;
 
@@ -2944,17 +3163,15 @@ static void iwl4965_hw_card_show_info(struct iwl4965_priv *priv)
 #define IWL_TX_DELIMITER_SIZE  4
 
 /**
- * iwl4965_tx_queue_update_wr_ptr - Set up entry in Tx byte-count array
+ * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  */
-int iwl4965_tx_queue_update_wr_ptr(struct iwl4965_priv *priv,
-                                  struct iwl4965_tx_queue *txq, u16 byte_cnt)
+static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
+                                           struct iwl4965_tx_queue *txq,
+                                           u16 byte_cnt)
 {
        int len;
        int txq_id = txq->q.id;
-       struct iwl4965_shared *shared_data = priv->hw_setting.shared_virt;
-
-       if (txq->need_update == 0)
-               return 0;
+       struct iwl4965_shared *shared_data = priv->shared_virt;
 
        len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
 
@@ -2967,8 +3184,6 @@ int iwl4965_tx_queue_update_wr_ptr(struct iwl4965_priv *priv,
                IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
                        tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr],
                        byte_cnt, len);
-
-       return 0;
 }
 
 /**
@@ -2977,7 +3192,7 @@ int iwl4965_tx_queue_update_wr_ptr(struct iwl4965_priv *priv,
  * Selects how many and which Rx receivers/antennas/chains to use.
  * This should not be used for scan command ... it puts data in wrong place.
  */
-void iwl4965_set_rxon_chain(struct iwl4965_priv *priv)
+void iwl4965_set_rxon_chain(struct iwl_priv *priv)
 {
        u8 is_single = is_single_stream(priv);
        u8 idle_state, rx_state;
@@ -3030,7 +3245,7 @@ static s32 sign_extend(u32 oper, int index)
  *
  * A return of <0 indicates bogus data in the statistics
  */
-int iwl4965_get_temperature(const struct iwl4965_priv *priv)
+int iwl4965_get_temperature(const struct iwl_priv *priv)
 {
        s32 temperature;
        s32 vt;
@@ -3098,7 +3313,7 @@ int iwl4965_get_temperature(const struct iwl4965_priv *priv)
  * Assumes caller will replace priv->last_temperature once calibration
  * executed.
  */
-static int iwl4965_is_temp_calib_needed(struct iwl4965_priv *priv)
+static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
 {
        int temp_diff;
 
@@ -3131,7 +3346,7 @@ static int iwl4965_is_temp_calib_needed(struct iwl4965_priv *priv)
 /* Calculate noise level, based on measurements during network silence just
  *   before arriving beacon.  This measurement can be done only if we know
  *   exactly when to expect beacons, therefore only when we're associated. */
-static void iwl4965_rx_calc_noise(struct iwl4965_priv *priv)
+static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
 {
        struct statistics_rx_non_phy *rx_info
                                = &(priv->statistics.rx.general);
@@ -3168,7 +3383,7 @@ static void iwl4965_rx_calc_noise(struct iwl4965_priv *priv)
                        priv->last_rx_noise);
 }
 
-void iwl4965_hw_rx_statistics(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
+void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
        int change;
@@ -3202,6 +3417,8 @@ void iwl4965_hw_rx_statistics(struct iwl4965_priv *priv, struct iwl4965_rx_mem_b
 #endif
        }
 
+       iwl_leds_background(priv);
+
        /* If the hardware hasn't reported a change in
         * temperature then don't bother computing a
         * calibrated temperature value */
@@ -3232,7 +3449,7 @@ void iwl4965_hw_rx_statistics(struct iwl4965_priv *priv, struct iwl4965_rx_mem_b
                queue_work(priv->workqueue, &priv->txpower_work);
 }
 
-static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
+static void iwl4965_add_radiotap(struct iwl_priv *priv,
                                 struct sk_buff *skb,
                                 struct iwl4965_rx_phy_res *rx_start,
                                 struct ieee80211_rx_status *stats,
@@ -3242,6 +3459,7 @@ static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
        s8 noise = 0;
        int rate = stats->rate_idx;
        u64 tsf = stats->mactime;
+       __le16 antenna;
        __le16 phy_flags_hw = rx_start->phy_flags;
        struct iwl4965_rt_rx_hdr {
                struct ieee80211_radiotap_header rt_hdr;
@@ -3310,8 +3528,12 @@ static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
 
        if (rate == -1)
                iwl4965_rt->rt_rate = 0;
-       else
+       else {
+               if (stats->band == IEEE80211_BAND_5GHZ)
+                       rate += IWL_FIRST_OFDM_RATE;
+
                iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
+       }
 
        /*
         * "antenna number"
@@ -3326,8 +3548,8 @@ static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
         * new 802.11n radiotap field "RX chains" that is defined
         * as a bitmask.
         */
-       iwl4965_rt->rt_antenna =
-               le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
+       antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
+       iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
 
        /* set the preamble flag if appropriate */
        if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
@@ -3336,7 +3558,74 @@ static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
        stats->flag |= RX_FLAG_RADIOTAP;
 }
 
-static void iwl4965_handle_data_packet(struct iwl4965_priv *priv, int is_data,
+static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
+{
+       /* 0 - mgmt, 1 - cnt, 2 - data */
+       int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
+       priv->rx_stats[idx].cnt++;
+       priv->rx_stats[idx].bytes += len;
+}
+
+static u32 iwl4965_translate_rx_status(u32 decrypt_in)
+{
+       u32 decrypt_out = 0;
+
+       if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
+                                       RX_RES_STATUS_STATION_FOUND)
+               decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
+                               RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
+
+       decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
+
+       /* packet was not encrypted */
+       if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
+                                       RX_RES_STATUS_SEC_TYPE_NONE)
+               return decrypt_out;
+
+       /* packet was encrypted with unknown alg */
+       if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
+                                       RX_RES_STATUS_SEC_TYPE_ERR)
+               return decrypt_out;
+
+       /* decryption was not done in HW */
+       if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
+                                       RX_MPDU_RES_STATUS_DEC_DONE_MSK)
+               return decrypt_out;
+
+       switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
+
+       case RX_RES_STATUS_SEC_TYPE_CCMP:
+               /* alg is CCM: check MIC only */
+               if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
+                       /* Bad MIC */
+                       decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
+               else
+                       decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
+
+               break;
+
+       case RX_RES_STATUS_SEC_TYPE_TKIP:
+               if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
+                       /* Bad TTAK */
+                       decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
+                       break;
+               }
+               /* fall through if TTAK OK */
+       default:
+               if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
+                       decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
+               else
+                       decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
+               break;
+       };
+
+       IWL_DEBUG_RX("decrypt_in:0x%x  decrypt_out = 0x%x\n",
+                                       decrypt_in, decrypt_out);
+
+       return decrypt_out;
+}
+
+static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
                                       int include_phy,
                                       struct iwl4965_rx_mem_buffer *rxb,
                                       struct ieee80211_rx_status *stats)
@@ -3349,6 +3638,7 @@ static void iwl4965_handle_data_packet(struct iwl4965_priv *priv, int is_data,
        __le32 *rx_end;
        unsigned int skblen;
        u32 ampdu_status;
+       u32 ampdu_status_legacy;
 
        if (!include_phy && priv->last_phy_res[0])
                rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
@@ -3377,7 +3667,7 @@ static void iwl4965_handle_data_packet(struct iwl4965_priv *priv, int is_data,
                rx_start->byte_count = amsdu->byte_count;
                rx_end = (__le32 *) (((u8 *) hdr) + len);
        }
-       if (len > priv->hw_setting.max_pkt_size || len < 16) {
+       if (len > priv->hw_params.max_pkt_size || len < 16) {
                IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
                return;
        }
@@ -3385,6 +3675,12 @@ static void iwl4965_handle_data_packet(struct iwl4965_priv *priv, int is_data,
        ampdu_status = le32_to_cpu(*rx_end);
        skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
 
+       if (!include_phy) {
+               /* New status scheme, need to translate */
+               ampdu_status_legacy = ampdu_status;
+               ampdu_status = iwl4965_translate_rx_status(ampdu_status);
+       }
+
        /* start from MAC */
        skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
        skb_put(rxb->skb, len); /* end where data ends */
@@ -3399,19 +3695,16 @@ static void iwl4965_handle_data_packet(struct iwl4965_priv *priv, int is_data,
        stats->flag = 0;
        hdr = (struct ieee80211_hdr *)rxb->skb->data;
 
-       if (iwl4965_param_hwcrypto)
+       if (!priv->cfg->mod_params->sw_crypto)
                iwl4965_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats);
 
        if (priv->add_radiotap)
                iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
 
+       iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
        ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
        priv->alloc_rxb_skb--;
        rxb->skb = NULL;
-#ifdef LED
-       priv->led_packets += len;
-       iwl4965_setup_activity_timer(priv);
-#endif
 }
 
 /* Calc max signal level (dBm) among 3 possible receivers */
@@ -3450,78 +3743,8 @@ static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
 
 #ifdef CONFIG_IWL4965_HT
 
-/* Parsed Information Elements */
-struct ieee802_11_elems {
-       u8 *ds_params;
-       u8 ds_params_len;
-       u8 *tim;
-       u8 tim_len;
-       u8 *ibss_params;
-       u8 ibss_params_len;
-       u8 *erp_info;
-       u8 erp_info_len;
-       u8 *ht_cap_param;
-       u8 ht_cap_param_len;
-       u8 *ht_extra_param;
-       u8 ht_extra_param_len;
-};
-
-static int parse_elems(u8 *start, size_t len, struct ieee802_11_elems *elems)
-{
-       size_t left = len;
-       u8 *pos = start;
-       int unknown = 0;
-
-       memset(elems, 0, sizeof(*elems));
-
-       while (left >= 2) {
-               u8 id, elen;
-
-               id = *pos++;
-               elen = *pos++;
-               left -= 2;
-
-               if (elen > left)
-                       return -1;
-
-               switch (id) {
-               case WLAN_EID_DS_PARAMS:
-                       elems->ds_params = pos;
-                       elems->ds_params_len = elen;
-                       break;
-               case WLAN_EID_TIM:
-                       elems->tim = pos;
-                       elems->tim_len = elen;
-                       break;
-               case WLAN_EID_IBSS_PARAMS:
-                       elems->ibss_params = pos;
-                       elems->ibss_params_len = elen;
-                       break;
-               case WLAN_EID_ERP_INFO:
-                       elems->erp_info = pos;
-                       elems->erp_info_len = elen;
-                       break;
-               case WLAN_EID_HT_CAPABILITY:
-                       elems->ht_cap_param = pos;
-                       elems->ht_cap_param_len = elen;
-                       break;
-               case WLAN_EID_HT_EXTRA_INFO:
-                       elems->ht_extra_param = pos;
-                       elems->ht_extra_param_len = elen;
-                       break;
-               default:
-                       unknown++;
-                       break;
-               }
-
-               left -= elen;
-               pos += elen;
-       }
-
-       return 0;
-}
-
-void iwl4965_init_ht_hw_capab(struct ieee80211_ht_info *ht_info,
+void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
+                             struct ieee80211_ht_info *ht_info,
                              enum ieee80211_band band)
 {
        ht_info->cap = 0;
@@ -3538,10 +3761,9 @@ void iwl4965_init_ht_hw_capab(struct ieee80211_ht_info *ht_info,
        ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
        ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
                             (IWL_MIMO_PS_NONE << 2));
-       if (iwl4965_param_amsdu_size_8K) {
-               printk(KERN_DEBUG "iwl4965 in A-MSDU 8K support mode\n");
+
+       if (priv->cfg->mod_params->amsdu_size_8K)
                ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
-       }
 
        ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
        ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
@@ -3551,7 +3773,7 @@ void iwl4965_init_ht_hw_capab(struct ieee80211_ht_info *ht_info,
 }
 #endif /* CONFIG_IWL4965_HT */
 
-static void iwl4965_sta_modify_ps_wake(struct iwl4965_priv *priv, int sta_id)
+static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
 {
        unsigned long flags;
 
@@ -3565,7 +3787,7 @@ static void iwl4965_sta_modify_ps_wake(struct iwl4965_priv *priv, int sta_id)
        iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
 }
 
-static void iwl4965_update_ps_mode(struct iwl4965_priv *priv, u16 ps_bit, u8 *addr)
+static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
 {
        /* FIXME: need locking over ps_status ??? */
        u8 sta_id = iwl4965_hw_find_station(priv, addr);
@@ -3582,7 +3804,7 @@ static void iwl4965_update_ps_mode(struct iwl4965_priv *priv, u16 ps_bit, u8 *ad
                }
        }
 }
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
 
 /**
  * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
@@ -3594,7 +3816,7 @@ static void iwl4965_update_ps_mode(struct iwl4965_priv *priv, u16 ps_bit, u8 *ad
  * TODO:  This was originally written for 3945, need to audit for
  *        proper operation with 4965.
  */
-static void iwl4965_dbg_report_frame(struct iwl4965_priv *priv,
+static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
                      struct iwl4965_rx_packet *pkt,
                      struct ieee80211_hdr *header, int group100)
 {
@@ -3622,7 +3844,7 @@ static void iwl4965_dbg_report_frame(struct iwl4965_priv *priv,
        struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
        u8 *data = IWL_RX_DATA(pkt);
 
-       if (likely(!(iwl4965_debug_level & IWL_DL_RX)))
+       if (likely(!(iwl_debug_level & IWL_DL_RX)))
                return;
 
        /* MAC header */
@@ -3725,10 +3947,10 @@ static void iwl4965_dbg_report_frame(struct iwl4965_priv *priv,
                }
        }
        if (print_dump)
-               iwl4965_print_hex_dump(IWL_DL_RX, data, length);
+               iwl_print_hex_dump(IWL_DL_RX, data, length);
 }
 #else
-static inline void iwl4965_dbg_report_frame(struct iwl4965_priv *priv,
+static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
                                            struct iwl4965_rx_packet *pkt,
                                            struct ieee80211_hdr *header,
                                            int group100)
@@ -3737,11 +3959,10 @@ static inline void iwl4965_dbg_report_frame(struct iwl4965_priv *priv,
 #endif
 
 
-#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
 
-/* Called for REPLY_4965_RX (legacy ABG frames), or
+/* Called for REPLY_RX (legacy ABG frames), or
  * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
-static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
                                struct iwl4965_rx_mem_buffer *rxb)
 {
        struct ieee80211_hdr *header;
@@ -3750,7 +3971,7 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
        /* Use phy data (Rx signal strength, etc.) contained within
         *   this rx packet for legacy frames,
         *   or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
-       int include_phy = (pkt->hdr.cmd == REPLY_4965_RX);
+       int include_phy = (pkt->hdr.cmd == REPLY_RX);
        struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
                (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
                (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
@@ -3760,12 +3981,12 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
        u8 network_packet;
 
        rx_status.mactime = le64_to_cpu(rx_start->timestamp);
-       rx_status.freq = ieee80211chan2mhz(le16_to_cpu(rx_start->channel));
+       rx_status.freq =
+               ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
        rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
                                IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
-       rx_status.rate_idx = iwl4965_hwrate_to_plcp_idx(
-                                       le32_to_cpu(rx_start->rate_n_flags));
-
+       rx_status.rate_idx =
+               iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
        if (rx_status.band == IEEE80211_BAND_5GHZ)
                rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
 
@@ -3773,9 +3994,8 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
        rx_status.flag = 0;
 
        if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
-               IWL_DEBUG_DROP
-                       ("dsp size out of range [0,20]: "
-                        "%d/n", rx_start->cfg_phy_cnt);
+               IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
+                               rx_start->cfg_phy_cnt);
                return;
        }
 
@@ -3826,7 +4046,7 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
         *   which are gathered only when associated, and indicate noise
         *   only for the associated network channel ...
         * Ignore these noise values while scanning (other channels) */
-       if (iwl4965_is_associated(priv) &&
+       if (iwl_is_associated(priv) &&
            !test_bit(STATUS_SCANNING, &priv->status)) {
                rx_status.noise = priv->last_rx_noise;
                rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi,
@@ -3837,7 +4057,7 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
        }
 
        /* Reset beacon noise level if not associated. */
-       if (!iwl4965_is_associated(priv))
+       if (!iwl_is_associated(priv))
                priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
 
        /* Set "1" to report good data frames in groups of 100 */
@@ -3846,7 +4066,7 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
 
        IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
                              rx_status.ssi, rx_status.noise, rx_status.signal,
-                             rx_status.mactime);
+                             (unsigned long long)rx_status.mactime);
 
        network_packet = iwl4965_is_network_packet(priv, header);
        if (network_packet) {
@@ -3858,101 +4078,9 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
        fc = le16_to_cpu(header->frame_control);
        switch (fc & IEEE80211_FCTL_FTYPE) {
        case IEEE80211_FTYPE_MGMT:
-
                if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
                        iwl4965_update_ps_mode(priv, fc  & IEEE80211_FCTL_PM,
                                                header->addr2);
-               switch (fc & IEEE80211_FCTL_STYPE) {
-               case IEEE80211_STYPE_PROBE_RESP:
-               case IEEE80211_STYPE_BEACON:
-                       if ((priv->iw_mode == IEEE80211_IF_TYPE_STA &&
-                            !compare_ether_addr(header->addr2, priv->bssid)) ||
-                           (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
-                            !compare_ether_addr(header->addr3, priv->bssid))) {
-                               struct ieee80211_mgmt *mgmt =
-                                       (struct ieee80211_mgmt *)header;
-                               u64 timestamp =
-                                       le64_to_cpu(mgmt->u.beacon.timestamp);
-
-                               priv->timestamp0 = timestamp & 0xFFFFFFFF;
-                               priv->timestamp1 =
-                                       (timestamp >> 32) & 0xFFFFFFFF;
-                               priv->beacon_int = le16_to_cpu(
-                                   mgmt->u.beacon.beacon_int);
-                               if (priv->call_post_assoc_from_beacon &&
-                                   (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
-                                       priv->call_post_assoc_from_beacon = 0;
-                                       queue_work(priv->workqueue,
-                                           &priv->post_associate.work);
-                               }
-                       }
-                       break;
-
-               case IEEE80211_STYPE_ACTION:
-                       break;
-
-                       /*
-                        * TODO: Use the new callback function from
-                        * mac80211 instead of sniffing these packets.
-                        */
-               case IEEE80211_STYPE_ASSOC_RESP:
-               case IEEE80211_STYPE_REASSOC_RESP:
-                       if (network_packet) {
-#ifdef CONFIG_IWL4965_HT
-                               u8 *pos = NULL;
-                               struct ieee802_11_elems elems;
-#endif                         /*CONFIG_IWL4965_HT */
-                               struct ieee80211_mgmt *mgnt =
-                                       (struct ieee80211_mgmt *)header;
-
-                               /* We have just associated, give some
-                                * time for the 4-way handshake if
-                                * any. Don't start scan too early. */
-                               priv->next_scan_jiffies = jiffies +
-                                       IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
-
-                               priv->assoc_id = (~((1 << 15) | (1 << 14))
-                                       & le16_to_cpu(mgnt->u.assoc_resp.aid));
-                               priv->assoc_capability =
-                                       le16_to_cpu(
-                                               mgnt->u.assoc_resp.capab_info);
-#ifdef CONFIG_IWL4965_HT
-                               pos = mgnt->u.assoc_resp.variable;
-                               if (!parse_elems(pos,
-                                                len - (pos - (u8 *) mgnt),
-                                                &elems)) {
-                                       if (elems.ht_extra_param &&
-                                           elems.ht_cap_param)
-                                               break;
-                               }
-#endif                         /*CONFIG_IWL4965_HT */
-                               /* assoc_id is 0 no association */
-                               if (!priv->assoc_id)
-                                       break;
-                               if (priv->beacon_int)
-                                       queue_work(priv->workqueue,
-                                           &priv->post_associate.work);
-                               else
-                                       priv->call_post_assoc_from_beacon = 1;
-                       }
-
-                       break;
-
-               case IEEE80211_STYPE_PROBE_REQ:
-                       if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
-                           !iwl4965_is_associated(priv)) {
-                               DECLARE_MAC_BUF(mac1);
-                               DECLARE_MAC_BUF(mac2);
-                               DECLARE_MAC_BUF(mac3);
-
-                               IWL_DEBUG_DROP("Dropping (non network): "
-                                              "%s, %s, %s\n",
-                                              print_mac(mac1, header->addr1),
-                                              print_mac(mac2, header->addr2),
-                                              print_mac(mac3, header->addr3));
-                               return;
-                       }
-               }
                iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
                break;
 
@@ -4003,7 +4131,7 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
 
 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
-static void iwl4965_rx_reply_rx_phy(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
                                    struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -4011,8 +4139,7 @@ static void iwl4965_rx_reply_rx_phy(struct iwl4965_priv *priv,
        memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
               sizeof(struct iwl4965_rx_phy_res));
 }
-
-static void iwl4965_rx_missed_beacon_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
                                           struct iwl4965_rx_mem_buffer *rxb)
 
 {
@@ -4033,13 +4160,12 @@ static void iwl4965_rx_missed_beacon_notif(struct iwl4965_priv *priv,
        }
 #endif /*CONFIG_IWL4965_SENSITIVITY*/
 }
-
 #ifdef CONFIG_IWL4965_HT
 
 /**
  * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
  */
-static void iwl4965_sta_modify_enable_tid_tx(struct iwl4965_priv *priv,
+static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
                                         int sta_id, int tid)
 {
        unsigned long flags;
@@ -4060,7 +4186,7 @@ static void iwl4965_sta_modify_enable_tid_tx(struct iwl4965_priv *priv,
  * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  * ACK vs. not.  This gets sent to mac80211, then to rate scaling algo.
  */
-static int iwl4965_tx_status_reply_compressed_ba(struct iwl4965_priv *priv,
+static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
                                                 struct iwl4965_ht_agg *agg,
                                                 struct iwl4965_compressed_ba_resp*
                                                 ba_resp)
@@ -4125,13 +4251,13 @@ static int iwl4965_tx_status_reply_compressed_ba(struct iwl4965_priv *priv,
 /**
  * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  */
-static void iwl4965_tx_queue_stop_scheduler(struct iwl4965_priv *priv,
+static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
                                            u16 txq_id)
 {
        /* Simply stop the queue, but don't change any configuration;
         * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
-       iwl4965_write_prph(priv,
-               KDR_SCD_QUEUE_STATUS_BITS(txq_id),
+       iwl_write_prph(priv,
+               IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
                (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
                (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
 }
@@ -4140,7 +4266,7 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl4965_priv *priv,
  * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
  * priv->lock must be held by the caller
  */
-static int iwl4965_tx_queue_agg_disable(struct iwl4965_priv *priv, u16 txq_id,
+static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
                                        u16 ssn_idx, u8 tx_fifo)
 {
        int ret = 0;
@@ -4151,29 +4277,29 @@ static int iwl4965_tx_queue_agg_disable(struct iwl4965_priv *priv, u16 txq_id,
                return -EINVAL;
        }
 
-       ret = iwl4965_grab_nic_access(priv);
+       ret = iwl_grab_nic_access(priv);
        if (ret)
                return ret;
 
        iwl4965_tx_queue_stop_scheduler(priv, txq_id);
 
-       iwl4965_clear_bits_prph(priv, KDR_SCD_QUEUECHAIN_SEL, (1 << txq_id));
+       iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
 
        priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
        priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
        /* supposes that ssn_idx is valid (!= 0xFFF) */
        iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
 
-       iwl4965_clear_bits_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << txq_id));
+       iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
        iwl4965_txq_ctx_deactivate(priv, txq_id);
        iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 
        return 0;
 }
 
-int iwl4965_check_empty_hw_queue(struct iwl4965_priv *priv, int sta_id,
+int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
                                         u8 tid, int txq_id)
 {
        struct iwl4965_queue *q = &priv->txq[txq_id].q;
@@ -4223,7 +4349,7 @@ static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
  * Handles block-acknowledge notification from device, which reports success
  * of frames sent via aggregation.
  */
-static void iwl4965_rx_reply_compressed_ba(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
                                           struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -4240,7 +4366,7 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl4965_priv *priv,
         * (in Tx queue's circular buffer) of first TFD/frame in window */
        u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
 
-       if (scd_flow >= ARRAY_SIZE(priv->txq)) {
+       if (scd_flow >= priv->hw_params.max_txq_num) {
                IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
                return;
        }
@@ -4262,7 +4388,7 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl4965_priv *priv,
                           "%d, scd_ssn = %d\n",
                           ba_resp->tid,
                           ba_resp->seq_ctl,
-                          (unsigned long long)ba_resp->bitmap,
+                          (unsigned long long)le64_to_cpu(ba_resp->bitmap),
                           ba_resp->scd_flow,
                           ba_resp->scd_ssn);
        IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
@@ -4291,7 +4417,7 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl4965_priv *priv,
 /**
  * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  */
-static int iwl4965_tx_queue_set_q2ratid(struct iwl4965_priv *priv, u16 ra_tid,
+static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
                                        u16 txq_id)
 {
        u32 tbl_dw_addr;
@@ -4303,14 +4429,14 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl4965_priv *priv, u16 ra_tid,
        tbl_dw_addr = priv->scd_base_addr +
                        SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
 
-       tbl_dw = iwl4965_read_targ_mem(priv, tbl_dw_addr);
+       tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
 
        if (txq_id & 0x1)
                tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
        else
                tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
 
-       iwl4965_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
+       iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
 
        return 0;
 }
@@ -4322,7 +4448,7 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl4965_priv *priv, u16 ra_tid,
  * NOTE:  txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
  *        i.e. it must be one of the higher queues used for aggregation
  */
-static int iwl4965_tx_queue_agg_enable(struct iwl4965_priv *priv, int txq_id,
+static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
                                       int tx_fifo, int sta_id, int tid,
                                       u16 ssn_idx)
 {
@@ -4340,7 +4466,7 @@ static int iwl4965_tx_queue_agg_enable(struct iwl4965_priv *priv, int txq_id,
        iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid);
 
        spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                spin_unlock_irqrestore(&priv->lock, flags);
                return rc;
@@ -4353,7 +4479,7 @@ static int iwl4965_tx_queue_agg_enable(struct iwl4965_priv *priv, int txq_id,
        iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
 
        /* Set this queue as a chain-building queue */
-       iwl4965_set_bits_prph(priv, KDR_SCD_QUEUECHAIN_SEL, (1 << txq_id));
+       iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
 
        /* Place first TFD at index corresponding to start sequence number.
         * Assumes that ssn_idx is valid (!= 0xFFF) */
@@ -4362,22 +4488,22 @@ static int iwl4965_tx_queue_agg_enable(struct iwl4965_priv *priv, int txq_id,
        iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
 
        /* Set up Tx window size and frame limit for this queue */
-       iwl4965_write_targ_mem(priv,
+       iwl_write_targ_mem(priv,
                        priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id),
                        (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
                        SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
 
-       iwl4965_write_targ_mem(priv, priv->scd_base_addr +
+       iwl_write_targ_mem(priv, priv->scd_base_addr +
                        SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
                        (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
                        & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
 
-       iwl4965_set_bits_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << txq_id));
+       iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
 
        /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
        iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return 0;
@@ -4399,10 +4525,10 @@ static int iwl4965_tx_queue_agg_enable(struct iwl4965_priv *priv, int txq_id,
  *       calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  *       which requires station table entry to exist).
  */
-void iwl4965_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
+void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
 {
        int i, r;
-       struct iwl4965_link_quality_cmd link_cmd = {
+       struct iwl_link_quality_cmd link_cmd = {
                .reserved1 = 0,
        };
        u16 rate_flags;
@@ -4436,21 +4562,21 @@ void iwl4965_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
        link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
 
        /* Update the rate scaling for control frame Tx to AP */
-       link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_setting.bcast_sta_id;
+       link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
 
-       iwl4965_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD, sizeof(link_cmd),
-                        &link_cmd);
+       iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
+                              sizeof(link_cmd), &link_cmd, NULL);
 }
 
 #ifdef CONFIG_IWL4965_HT
 
-static u8 iwl4965_is_channel_extension(struct iwl4965_priv *priv,
+static u8 iwl4965_is_channel_extension(struct iwl_priv *priv,
                                       enum ieee80211_band band,
                                       u16 channel, u8 extension_chan_offset)
 {
-       const struct iwl4965_channel_info *ch_info;
+       const struct iwl_channel_info *ch_info;
 
-       ch_info = iwl4965_get_channel_info(priv, band, channel);
+       ch_info = iwl_get_channel_info(priv, band, channel);
        if (!is_channel_valid(ch_info))
                return 0;
 
@@ -4464,7 +4590,7 @@ static u8 iwl4965_is_channel_extension(struct iwl4965_priv *priv,
        return 0;
 }
 
-static u8 iwl4965_is_fat_tx_allowed(struct iwl4965_priv *priv,
+static u8 iwl4965_is_fat_tx_allowed(struct iwl_priv *priv,
                                struct ieee80211_ht_info *sta_ht_inf)
 {
        struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
@@ -4485,7 +4611,7 @@ static u8 iwl4965_is_fat_tx_allowed(struct iwl4965_priv *priv,
                                         iwl_ht_conf->extension_chan_offset));
 }
 
-void iwl4965_set_rxon_ht(struct iwl4965_priv *priv, struct iwl_ht_info *ht_info)
+void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
 {
        struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
        u32 val;
@@ -4539,7 +4665,7 @@ void iwl4965_set_rxon_ht(struct iwl4965_priv *priv, struct iwl_ht_info *ht_info)
        return;
 }
 
-void iwl4965_set_ht_add_station(struct iwl4965_priv *priv, u8 index,
+void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
                                struct ieee80211_ht_info *sta_ht_inf)
 {
        __le32 sta_flags;
@@ -4584,7 +4710,7 @@ void iwl4965_set_ht_add_station(struct iwl4965_priv *priv, u8 index,
        return;
 }
 
-static void iwl4965_sta_modify_add_ba_tid(struct iwl4965_priv *priv,
+static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv,
                                          int sta_id, int tid, u16 ssn)
 {
        unsigned long flags;
@@ -4600,7 +4726,7 @@ static void iwl4965_sta_modify_add_ba_tid(struct iwl4965_priv *priv,
        iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
 }
 
-static void iwl4965_sta_modify_del_ba_tid(struct iwl4965_priv *priv,
+static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv,
                                          int sta_id, int tid)
 {
        unsigned long flags;
@@ -4621,11 +4747,11 @@ static void iwl4965_sta_modify_del_ba_tid(struct iwl4965_priv *priv,
  * Should never return anything < 7, because they should already
  * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
  */
-static int iwl4965_txq_ctx_activate_free(struct iwl4965_priv *priv)
+static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
 {
        int txq_id;
 
-       for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++)
+       for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
                if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
                        return txq_id;
        return -1;
@@ -4634,7 +4760,7 @@ static int iwl4965_txq_ctx_activate_free(struct iwl4965_priv *priv)
 static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da,
                                       u16 tid, u16 *start_seq_num)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        int sta_id;
        int tx_fifo;
        int txq_id;
@@ -4694,7 +4820,7 @@ static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
                                      u16 tid)
 {
 
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        int tx_fifo_id, txq_id, sta_id, ssn = -1;
        struct iwl4965_tid_data *tid_data;
        int ret, write_ptr, read_ptr;
@@ -4755,7 +4881,7 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
                             enum ieee80211_ampdu_mlme_action action,
                             const u8 *addr, u16 tid, u16 *ssn)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        int sta_id;
        DECLARE_MAC_BUF(mac);
 
@@ -4788,10 +4914,10 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
 #endif /* CONFIG_IWL4965_HT */
 
 /* Set up 4965-specific Rx frame reply handlers */
-void iwl4965_hw_rx_handler_setup(struct iwl4965_priv *priv)
+void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv)
 {
        /* Legacy Rx frames */
-       priv->rx_handlers[REPLY_4965_RX] = iwl4965_rx_reply_rx;
+       priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
 
        /* High-throughput (HT) Rx frames */
        priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
@@ -4805,10 +4931,9 @@ void iwl4965_hw_rx_handler_setup(struct iwl4965_priv *priv)
 #endif /* CONFIG_IWL4965_HT */
 }
 
-void iwl4965_hw_setup_deferred_work(struct iwl4965_priv *priv)
+void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
 {
        INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
-       INIT_WORK(&priv->statistics_work, iwl4965_bg_statistics_work);
 #ifdef CONFIG_IWL4965_SENSITIVITY
        INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
 #endif
@@ -4817,54 +4942,70 @@ void iwl4965_hw_setup_deferred_work(struct iwl4965_priv *priv)
        priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
 }
 
-void iwl4965_hw_cancel_deferred_work(struct iwl4965_priv *priv)
+void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
 {
        del_timer_sync(&priv->statistics_periodic);
 
        cancel_delayed_work(&priv->init_alive_start);
 }
 
-static struct iwl_cfg iwl4965_agn_cfg = {
-       .name = "4965AGN",
-       .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
-       .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
+
+static struct iwl_hcmd_ops iwl4965_hcmd = {
+       .rxon_assoc = iwl4965_send_rxon_assoc,
 };
 
-struct pci_device_id iwl4965_hw_card_ids[] = {
-       {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
-       {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
-       {0}
+static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
+       .enqueue_hcmd = iwl4965_enqueue_hcmd,
 };
 
-/*
- * The device's EEPROM semaphore prevents conflicts between driver and uCode
- * when accessing the EEPROM; each access is a series of pulses to/from the
- * EEPROM chip, not a single event, so even reads could conflict if they
- * weren't arbitrated by the semaphore.
- */
-int iwl4965_eeprom_acquire_semaphore(struct iwl4965_priv *priv)
-{
-       u16 count;
-       int rc;
+static struct iwl_lib_ops iwl4965_lib = {
+       .init_drv = iwl4965_init_drv,
+       .set_hw_params = iwl4965_hw_set_hw_params,
+       .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
+       .hw_nic_init = iwl4965_hw_nic_init,
+       .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
+       .alive_notify = iwl4965_alive_notify,
+       .load_ucode = iwl4965_load_bsm,
+       .eeprom_ops = {
+               .verify_signature  = iwlcore_eeprom_verify_signature,
+               .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
+               .release_semaphore = iwlcore_eeprom_release_semaphore,
+       },
+       .radio_kill_sw = iwl4965_radio_kill_sw,
+};
 
-       for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
-               /* Request semaphore */
-               iwl4965_set_bit(priv, CSR_HW_IF_CONFIG_REG,
-                       CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
-
-               /* See if we got it */
-               rc = iwl4965_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
-                                       CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
-                                       CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
-                                       EEPROM_SEM_TIMEOUT);
-               if (rc >= 0) {
-                       IWL_DEBUG_IO("Acquired semaphore after %d tries.\n",
-                               count+1);
-                       return rc;
-               }
-       }
+static struct iwl_ops iwl4965_ops = {
+       .lib = &iwl4965_lib,
+       .hcmd = &iwl4965_hcmd,
+       .utils = &iwl4965_hcmd_utils,
+};
 
-       return rc;
-}
+struct iwl_cfg iwl4965_agn_cfg = {
+       .name = "4965AGN",
+       .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
+       .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
+       .ops = &iwl4965_ops,
+       .mod_params = &iwl4965_mod_params,
+};
+
+module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
+MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
+module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
+MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
+module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
+MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
+module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
+MODULE_PARM_DESC(debug, "debug output mask");
+module_param_named(
+       disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
+MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
+
+module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
+MODULE_PARM_DESC(queues_num, "number of hw queues.");
+
+/* QoS */
+module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
+MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
+module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
+MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
 
-MODULE_DEVICE_TABLE(pci, iwl4965_hw_card_ids);