iwlwifi: fix incorrect 5GHz rates reported in monitor mode
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-4965.c
index add6311..de330ae 100644 (file)
 #include <asm/unaligned.h>
 
 #include "iwl-eeprom.h"
-#include "iwl-core.h"
 #include "iwl-4965.h"
+#include "iwl-core.h"
 #include "iwl-io.h"
 #include "iwl-helpers.h"
 
 /* module parameters */
 static struct iwl_mod_params iwl4965_mod_params = {
-       .num_of_queues = IWL_MAX_NUM_QUEUES,
+       .num_of_queues = IWL4965_MAX_NUM_QUEUES,
        .enable_qos = 1,
        .amsdu_size_8K = 1,
        /* the rest are 0 by default */
@@ -114,6 +114,151 @@ 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;
@@ -129,6 +274,18 @@ static int iwl4965_init_drv(struct iwl_priv *priv)
        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]);
 
@@ -253,7 +410,7 @@ void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
        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)
@@ -347,10 +504,10 @@ u8 iwl4965_hw_find_station(struct iwl_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))) {
@@ -401,15 +558,15 @@ static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
 
 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 = iwl_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 (priv->cfg->mod_params->amsdu_size_8K)
@@ -429,15 +586,15 @@ static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
 
        /* Tell device where in DRAM to update its Rx status */
        iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
-                          (priv->hw_setting.shared_phys +
-                               offsetof(struct iwl4965_shared, val0)) >> 4);
+                          (priv->shared_phys +
+                           offsetof(struct iwl4965_shared, rb_closed)) >> 4);
 
        /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */
        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 | */
+                            /* 0x10 << 4 | */
                           (RX_QUEUE_SIZE_LOG <<
                              FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT));
 
@@ -532,7 +689,7 @@ static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
        }
 
        /* Turn off all Tx DMA channels */
-       iwl_write_prph(priv, KDR_SCD_TXFACT, 0);
+       iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
        iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -545,7 +702,7 @@ static int iwl4965_txq_ctx_reset(struct iwl_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,
@@ -751,7 +908,7 @@ void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
        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 (iwl_grab_nic_access(priv)) {
                        spin_unlock_irqrestore(&priv->lock, flags);
@@ -819,40 +976,21 @@ int iwl4965_hw_nic_reset(struct iwl_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 iwl_priv *priv = (struct iwl_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 iwl_priv *priv = container_of(work, struct iwl_priv,
-                                            statistics_work);
-
        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
@@ -1306,7 +1444,7 @@ void iwl4965_chain_noise_reset(struct iwl_priv *priv)
        struct iwl4965_chain_noise_data *data = NULL;
 
        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));
@@ -1314,8 +1452,8 @@ void iwl4965_chain_noise_reset(struct iwl_priv *priv)
                cmd.diff_gain_a = 0;
                cmd.diff_gain_b = 0;
                cmd.diff_gain_c = 0;
-               iwl_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");
@@ -1581,7 +1719,7 @@ static void iwl4965_sensitivity_calibration(struct iwl_priv *priv,
 
        data = &(priv->sensitivity_data);
 
-       if (!iwl4965_is_associated(priv)) {
+       if (!iwl_is_associated(priv)) {
                IWL_DEBUG_CALIB("<< - not associated\n");
                return;
        }
@@ -1731,7 +1869,7 @@ static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
 {
        iwl_write_direct32(priv, HBUS_TARG_WRPTR,
                             (index & 0xff) | (txq_id << 8));
-       iwl_write_prph(priv, KDR_SCD_QUEUE_RDPTR(txq_id), index);
+       iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
 }
 
 /**
@@ -1751,7 +1889,7 @@ static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
        int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
 
        /* Set up and activate */
-       iwl_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) |
@@ -1810,28 +1948,28 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
        }
 
        /* Clear 4965's internal Tx Scheduler data base */
-       priv->scd_base_addr = iwl_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)
                iwl_write_targ_mem(priv, a, 0);
        for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4)
                iwl_write_targ_mem(priv, a, 0);
-       for (; a < sizeof(u16) * priv->hw_setting.max_txq_num; a += 4)
+       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 */
-       iwl_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 */
-       iwl_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 */
-               iwl_write_prph(priv, KDR_SCD_QUEUE_RDPTR(i), 0);
+               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 */
@@ -1850,11 +1988,11 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
                                        SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
 
        }
-       iwl_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 */
-       iwl_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);
@@ -1869,55 +2007,45 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
        iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
+       /* 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 iwl_priv *priv)
+int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
 {
-       int ret = 0;
 
-       if ((priv->cfg->mod_params->num_of_queues > IWL_MAX_NUM_QUEUES) ||
+       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, IWL_MAX_NUM_QUEUES);
-               ret = -EINVAL;
-               goto out;
-       }
-
-       /* 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) {
-               ret = -ENOMEM;
-               goto out;
+                         IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES);
+               return -EINVAL;
        }
 
-       memset(priv->hw_setting.shared_virt, 0, sizeof(struct iwl4965_shared));
-
-       priv->hw_setting.max_txq_num = priv->cfg->mod_params->num_of_queues;
-       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;
+       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_setting.rx_buf_size = IWL_RX_BUF_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);
 
-out:
-       return ret;
+       return 0;
 }
 
 /**
@@ -1930,7 +2058,7 @@ 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 */
@@ -2756,6 +2884,46 @@ 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 iwl_priv *priv, u16 channel)
 {
        int rc;
@@ -2869,9 +3037,8 @@ void iwl4965_hw_build_tx_cmd_rate(struct iwl_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 iwl_priv *priv)
@@ -2888,7 +3055,7 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_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,
@@ -2996,17 +3163,15 @@ static void iwl4965_hw_card_show_info(struct iwl_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 iwl_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;
 
@@ -3019,8 +3184,6 @@ int iwl4965_tx_queue_update_wr_ptr(struct iwl_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;
 }
 
 /**
@@ -3296,6 +3459,7 @@ static void iwl4965_add_radiotap(struct iwl_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;
@@ -3364,8 +3528,12 @@ static void iwl4965_add_radiotap(struct iwl_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"
@@ -3380,8 +3548,8 @@ static void iwl4965_add_radiotap(struct iwl_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)
@@ -3499,7 +3667,7 @@ static void iwl4965_handle_data_packet(struct iwl_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;
        }
@@ -3527,7 +3695,7 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
        stats->flag = 0;
        hdr = (struct ieee80211_hdr *)rxb->skb->data;
 
-       if (priv->cfg->mod_params->hw_crypto)
+       if (!priv->cfg->mod_params->sw_crypto)
                iwl4965_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats);
 
        if (priv->add_radiotap)
@@ -3575,77 +3743,6 @@ 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 iwl_priv *priv,
                              struct ieee80211_ht_info *ht_info,
                              enum ieee80211_band band)
@@ -3862,7 +3959,6 @@ static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
 #endif
 
 
-#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
 
 /* Called for REPLY_RX (legacy ABG frames), or
  * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
@@ -3885,12 +3981,12 @@ static void iwl4965_rx_reply_rx(struct iwl_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;
 
@@ -3898,9 +3994,8 @@ static void iwl4965_rx_reply_rx(struct iwl_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;
        }
 
@@ -3951,7 +4046,7 @@ static void iwl4965_rx_reply_rx(struct iwl_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,
@@ -3962,7 +4057,7 @@ static void iwl4965_rx_reply_rx(struct iwl_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 */
@@ -3971,7 +4066,7 @@ static void iwl4965_rx_reply_rx(struct iwl_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) {
@@ -3983,101 +4078,9 @@ static void iwl4965_rx_reply_rx(struct iwl_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;
 
@@ -4136,7 +4139,6 @@ static void iwl4965_rx_reply_rx_phy(struct iwl_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 iwl_priv *priv,
                                           struct iwl4965_rx_mem_buffer *rxb)
 
@@ -4158,7 +4160,6 @@ static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
        }
 #endif /*CONFIG_IWL4965_SENSITIVITY*/
 }
-
 #ifdef CONFIG_IWL4965_HT
 
 /**
@@ -4256,7 +4257,7 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
        /* Simply stop the queue, but don't change any configuration;
         * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
        iwl_write_prph(priv,
-               KDR_SCD_QUEUE_STATUS_BITS(txq_id),
+               IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
                (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
                (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
 }
@@ -4282,14 +4283,14 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
 
        iwl4965_tx_queue_stop_scheduler(priv, txq_id);
 
-       iwl_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);
 
-       iwl_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);
 
@@ -4365,7 +4366,7 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl_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;
        }
@@ -4478,7 +4479,7 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
        iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
 
        /* Set this queue as a chain-building queue */
-       iwl_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) */
@@ -4497,7 +4498,7 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
                        (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
                        & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
 
-       iwl_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);
@@ -4527,7 +4528,7 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
 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;
@@ -4561,10 +4562,10 @@ void iwl4965_add_station(struct iwl_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;
 
-       iwl_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
@@ -4750,7 +4751,7 @@ 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;
@@ -4933,7 +4934,6 @@ void iwl4965_hw_rx_handler_setup(struct iwl_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
@@ -4949,12 +4949,23 @@ void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
        cancel_delayed_work(&priv->init_alive_start);
 }
 
+
+static struct iwl_hcmd_ops iwl4965_hcmd = {
+       .rxon_assoc = iwl4965_send_rxon_assoc,
+};
+
 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
        .enqueue_hcmd = iwl4965_enqueue_hcmd,
 };
 
 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,
@@ -4965,10 +4976,11 @@ static struct iwl_lib_ops iwl4965_lib = {
 
 static struct iwl_ops iwl4965_ops = {
        .lib = &iwl4965_lib,
+       .hcmd = &iwl4965_hcmd,
        .utils = &iwl4965_hcmd_utils,
 };
 
-static struct iwl_cfg iwl4965_agn_cfg = {
+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,
@@ -4976,21 +4988,12 @@ static struct iwl_cfg iwl4965_agn_cfg = {
        .mod_params = &iwl4965_mod_params,
 };
 
-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}
-};
-
-MODULE_DEVICE_TABLE(pci, iwl4965_hw_card_ids);
-
 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(hwcrypto, iwl4965_mod_params.hw_crypto, int, 0444);
-MODULE_PARM_DESC(hwcrypto,
-                "using hardware crypto engine (default 0 [software])\n");
+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(