iwlwifi: remove 4965 prefix from iwl4965_kw and iwl4965_tx_queue
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-4965.c
index d051aac..126ecf7 100644 (file)
@@ -39,7 +39,7 @@
 #include <asm/unaligned.h>
 
 #include "iwl-eeprom.h"
-#include "iwl-4965.h"
+#include "iwl-dev.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 = IWL4965_MAX_NUM_QUEUES,
+       .num_of_queues = IWL49_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,      \
-                                   IWL_RATE_SISO_##s##M_PLCP, \
-                                   IWL_RATE_MIMO_##s##M_PLCP, \
-                                   IWL_RATE_##r##M_IEEE,      \
-                                   IWL_RATE_##ip##M_INDEX,    \
-                                   IWL_RATE_##in##M_INDEX,    \
-                                   IWL_RATE_##rp##M_INDEX,    \
-                                   IWL_RATE_##rn##M_INDEX,    \
-                                   IWL_RATE_##pp##M_INDEX,    \
-                                   IWL_RATE_##np##M_INDEX }
-
-/*
- * Parameter order:
- *   rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
- *
- * If there isn't a valid next or previous rate then INV is used which
- * maps to IWL_RATE_INVALID
- *
- */
-const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
-       IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2),    /*  1mbps */
-       IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5),          /*  2mbps */
-       IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11),        /*5.5mbps */
-       IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18),      /* 11mbps */
-       IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11),        /*  6mbps */
-       IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11),       /*  9mbps */
-       IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18),   /* 12mbps */
-       IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24),   /* 18mbps */
-       IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36),   /* 24mbps */
-       IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48),   /* 36mbps */
-       IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54),   /* 48mbps */
-       IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
-       IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
-};
-
 #ifdef CONFIG_IWL4965_HT
 
 static const u16 default_tid_to_tx_fifo[] = {
@@ -260,99 +222,100 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
        return 0;
 }
 
-static int iwl4965_init_drv(struct iwl_priv *priv)
+/**
+ * iwl4965_set_ucode_ptrs - Set uCode address location
+ *
+ * Tell initialization uCode where to find runtime uCode.
+ *
+ * BSM registers initially contain pointers to initialization uCode.
+ * We need to replace them to load runtime uCode inst and data,
+ * and to save runtime data when powering down.
+ */
+static int iwl4965_set_ucode_ptrs(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);
+       dma_addr_t pinst;
+       dma_addr_t pdata;
+       unsigned long flags;
+       int ret = 0;
 
-       priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
-                                       sizeof(struct iwl4965_shared),
-                                       &priv->shared_phys);
+       /* bits 35:4 for 4965 */
+       pinst = priv->ucode_code.p_addr >> 4;
+       pdata = priv->ucode_data_backup.p_addr >> 4;
 
-       if (!priv->shared_virt) {
-               ret = -ENOMEM;
-               goto err;
+       spin_lock_irqsave(&priv->lock, flags);
+       ret = iwl_grab_nic_access(priv);
+       if (ret) {
+               spin_unlock_irqrestore(&priv->lock, flags);
+               return ret;
        }
 
-       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;
+       /* Tell bootstrap uCode where to find image to load */
+       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_DATA_BYTECOUNT_REG,
+                                priv->ucode_data.len);
 
-       iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
+       /* Inst bytecount must be last to set up, bit 31 signals uCode
+        *   that all new ptr/size info is in place */
+       iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
+                                priv->ucode_code.len | BSM_DRAM_INST_LOAD);
+       iwl_release_nic_access(priv);
 
-       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;
+       spin_unlock_irqrestore(&priv->lock, flags);
 
-       ret = iwl_init_channel_map(priv);
-       if (ret) {
-               IWL_ERROR("initializing regulatory failed: %d\n", ret);
-               goto err;
-       }
+       IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
 
-       ret = iwl4965_init_geos(priv);
-       if (ret) {
-               IWL_ERROR("initializing geos failed: %d\n", ret);
-               goto err_free_channel_map;
-       }
+       return ret;
+}
 
-       ret = ieee80211_register_hw(priv->hw);
-       if (ret) {
-               IWL_ERROR("Failed to register network device (error %d)\n",
-                               ret);
-               goto err_free_geos;
+/**
+ * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
+ *
+ * Called after REPLY_ALIVE notification received from "initialize" uCode.
+ *
+ * The 4965 "initialize" ALIVE reply contains calibration data for:
+ *   Voltage, temperature, and MIMO tx gain correction, now stored in priv
+ *   (3945 does not contain this data).
+ *
+ * Tell "initialize" uCode to go ahead and load the runtime uCode.
+*/
+static void iwl4965_init_alive_start(struct iwl_priv *priv)
+{
+       /* Check alive response for "valid" sign from uCode */
+       if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
+               /* We had an error bringing up the hardware, so take it
+                * all the way back down so we can try again */
+               IWL_DEBUG_INFO("Initialize Alive failed.\n");
+               goto restart;
+       }
+
+       /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
+        * This is a paranoid check, because we would not have gotten the
+        * "initialize" alive if code weren't properly loaded.  */
+       if (iwl_verify_ucode(priv)) {
+               /* Runtime instruction load was bad;
+                * take it all the way back down so we can try again */
+               IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
+               goto restart;
+       }
+
+       /* Calculate temperature */
+       priv->temperature = iwl4965_get_temperature(priv);
+
+       /* Send pointers to protocol/runtime uCode image ... init code will
+        * load and launch runtime uCode, which will send us another "Alive"
+        * notification. */
+       IWL_DEBUG_INFO("Initialization Alive received.\n");
+       if (iwl4965_set_ucode_ptrs(priv)) {
+               /* Runtime instruction load won't happen;
+                * take it all the way back down so we can try again */
+               IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
+               goto restart;
        }
+       return;
 
-       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;
+restart:
+       queue_work(priv->workqueue, &priv->restart);
 }
 
 static int is_fat_channel(__le32 rxon_flags)
@@ -361,19 +324,6 @@ static int is_fat_channel(__le32 rxon_flags)
                (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
 }
 
-static u8 is_single_stream(struct iwl_priv *priv)
-{
-#ifdef CONFIG_IWL4965_HT
-       if (!priv->current_ht_config.is_ht ||
-           (priv->current_ht_config.supp_mcs_set[1] == 0) ||
-           (priv->ps_mode == IWL_MIMO_PS_STATIC))
-               return 1;
-#else
-       return 1;
-#endif /*CONFIG_IWL4965_HT */
-       return 0;
-}
-
 int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
 {
        int idx = 0;
@@ -382,8 +332,8 @@ int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
        if (rate_n_flags & RATE_MCS_HT_MSK) {
                idx = (rate_n_flags & 0xff);
 
-               if (idx >= IWL_RATE_MIMO_6M_PLCP)
-                       idx = idx - IWL_RATE_MIMO_6M_PLCP;
+               if (idx >= IWL_RATE_MIMO2_6M_PLCP)
+                       idx = idx - IWL_RATE_MIMO2_6M_PLCP;
 
                idx += IWL_FIRST_OFDM_RATE;
                /* skip 9M not supported in ht*/
@@ -411,7 +361,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_POS);
+               ((rate_n_flags & RATE_MCS_ANT_ABC_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)
@@ -432,41 +382,6 @@ void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
                        &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
 }
 
-/*
- * Determine how many receiver/antenna chains to use.
- * More provides better reception via diversity.  Fewer saves power.
- * 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 iwl_priv *priv,
-                                       u8 *idle_state, u8 *rx_state)
-{
-       u8 is_single = is_single_stream(priv);
-       u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
-
-       /* # of Rx chains to use when expecting MIMO. */
-       if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
-               *rx_state = 2;
-       else
-               *rx_state = 3;
-
-       /* # Rx chains when idling and maybe trying to save power */
-       switch (priv->ps_mode) {
-       case IWL_MIMO_PS_STATIC:
-       case IWL_MIMO_PS_DYNAMIC:
-               *idle_state = (is_cam) ? 2 : 1;
-               break;
-       case IWL_MIMO_PS_NONE:
-               *idle_state = (is_cam) ? *rx_state : 1;
-               break;
-       default:
-               *idle_state = 1;
-               break;
-       }
-
-       return 0;
-}
-
 int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
 {
        int rc;
@@ -492,6 +407,31 @@ int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
        return 0;
 }
 
+/*
+ * EEPROM handlers
+ */
+
+static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
+{
+       u16 eeprom_ver;
+       u16 calib_ver;
+
+       eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
+
+       calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
+
+       if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
+           calib_ver < EEPROM_4965_TX_POWER_VERSION)
+               goto err;
+
+       return 0;
+err:
+       IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
+                 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
+                 calib_ver, EEPROM_4965_TX_POWER_VERSION);
+       return -EINVAL;
+
+}
 int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
 {
        int ret;
@@ -526,312 +466,108 @@ int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
        return ret;
 }
 
-static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
+static int iwl4965_disable_tx_fifo(struct iwl_priv *priv)
 {
-       int ret;
        unsigned long flags;
-       unsigned int rb_size;
+       int ret;
 
        spin_lock_irqsave(&priv->lock, flags);
+
        ret = iwl_grab_nic_access(priv);
-       if (ret) {
+       if (unlikely(ret)) {
+               IWL_ERROR("Tx fifo reset failed");
                spin_unlock_irqrestore(&priv->lock, flags);
                return ret;
        }
 
-       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 */
-       iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
-
-       /* Reset driver's Rx queue write index */
-       iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
-
-       /* Tell device where to find RBD circular buffer in DRAM */
-       iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
-                          rxq->dma_addr >> 8);
-
-       /* Tell device where in DRAM to update its Rx status */
-       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 */
-       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));
-
-       /*
-        * iwl_write32(priv,CSR_INT_COAL_REG,0);
-        */
-
-       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 iwl_priv *priv)
-{
-       unsigned long flags;
-       int rc;
-
-       spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl_grab_nic_access(priv);
-       if (rc)
-               goto out;
-
-       iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
-                            priv->kw.dma_addr >> 4);
-       iwl_release_nic_access(priv);
-out:
-       spin_unlock_irqrestore(&priv->lock, flags);
-       return rc;
-}
-
-static int iwl4965_kw_alloc(struct iwl_priv *priv)
-{
-       struct pci_dev *dev = priv->pci_dev;
-       struct iwl4965_kw *kw = &priv->kw;
-
-       kw->size = IWL4965_KW_SIZE;     /* TBW need set somewhere else */
-       kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
-       if (!kw->v_addr)
-               return -ENOMEM;
-
-       return 0;
-}
-
-/**
- * iwl4965_kw_free - Free the "keep warm" buffer
- */
-static void iwl4965_kw_free(struct iwl_priv *priv)
-{
-       struct pci_dev *dev = priv->pci_dev;
-       struct iwl4965_kw *kw = &priv->kw;
-
-       if (kw->v_addr) {
-               pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
-               memset(kw, 0, sizeof(*kw));
-       }
-}
-
-/**
- * iwl4965_txq_ctx_reset - Reset TX queue context
- * Destroys all DMA structures and initialise them again
- *
- * @param priv
- * @return error code
- */
-static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
-{
-       int rc = 0;
-       int txq_id, slots_num;
-       unsigned long flags;
-
-       iwl4965_kw_free(priv);
-
-       /* Free all tx/cmd queues and keep-warm buffer */
-       iwl4965_hw_txq_ctx_free(priv);
-
-       /* Alloc keep-warm buffer */
-       rc = iwl4965_kw_alloc(priv);
-       if (rc) {
-               IWL_ERROR("Keep Warm allocation failed");
-               goto error_kw;
-       }
-
-       spin_lock_irqsave(&priv->lock, flags);
-
-       rc = iwl_grab_nic_access(priv);
-       if (unlikely(rc)) {
-               IWL_ERROR("TX reset failed");
-               spin_unlock_irqrestore(&priv->lock, flags);
-               goto error_reset;
-       }
-
-       /* Turn off all Tx DMA channels */
        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 */
-       rc = iwl4965_kw_init(priv);
-       if (rc) {
-               IWL_ERROR("kw_init failed\n");
-               goto error_reset;
-       }
-
-       /* Alloc and init all (default 16) Tx queues,
-        * including the command queue (#4) */
-       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,
-                                      txq_id);
-               if (rc) {
-                       IWL_ERROR("Tx %d queue init failed\n", txq_id);
-                       goto error;
-               }
-       }
-
-       return rc;
-
- error:
-       iwl4965_hw_txq_ctx_free(priv);
- error_reset:
-       iwl4965_kw_free(priv);
- error_kw:
-       return rc;
+       return 0;
 }
 
-int iwl4965_hw_nic_init(struct iwl_priv *priv)
+static int iwl4965_apm_init(struct iwl_priv *priv)
 {
-       int rc;
        unsigned long flags;
-       struct iwl4965_rx_queue *rxq = &priv->rxq;
-       u8 rev_id;
-       u32 val;
-       u8 val_link;
+       int ret = 0;
 
-       /* nic_init */
        spin_lock_irqsave(&priv->lock, flags);
-
        iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
-                   CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
+                         CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
 
+       /* set "initialization complete" bit to move adapter
+        * D0U* --> D0A* state */
        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) {
-               spin_unlock_irqrestore(&priv->lock, flags);
-               IWL_DEBUG_INFO("Failed to init the card\n");
-               return rc;
-       }
 
-       rc = iwl_grab_nic_access(priv);
-       if (rc) {
-               spin_unlock_irqrestore(&priv->lock, flags);
-               return rc;
+       /* wait for clock stabilization */
+       ret = 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 (ret < 0) {
+               IWL_DEBUG_INFO("Failed to init the card\n");
+               goto out;
        }
 
-       iwl_read_prph(priv, APMG_CLK_CTRL_REG);
+       ret = iwl_grab_nic_access(priv);
+       if (ret)
+               goto out;
 
+       /* enable DMA */
        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);
 
        iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
-                               APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
+                         APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
 
        iwl_release_nic_access(priv);
-       iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
+out:
        spin_unlock_irqrestore(&priv->lock, flags);
+       return ret;
+}
 
-       /* Determine HW type */
-       rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
-       if (rc)
-               return rc;
-
-       IWL_DEBUG_INFO("HW Revision ID = 0x%X\n", rev_id);
 
-       rc = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
+static void iwl4965_nic_config(struct iwl_priv *priv)
+{
+       unsigned long flags;
+       u32 val;
+       u16 radio_cfg;
+       u8 val_link;
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       if ((rev_id & 0x80) == 0x80 && (rev_id & 0x7f) < 8) {
+       if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
                pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
                /* Enable No Snoop field */
                pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
                                       val & ~(1 << 11));
        }
 
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       if (priv->eeprom.calib_version < EEPROM_TX_POWER_VERSION_NEW) {
-               IWL_ERROR("Older EEPROM detected!  Aborting.\n");
-               return -EINVAL;
-       }
-
        pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
 
        /* disable L1 entry -- workaround for pre-B1 */
        pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
 
-       spin_lock_irqsave(&priv->lock, flags);
+       radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
 
-       /* set CSR_HW_CONFIG_REG for uCode use */
+       /* write radio config values to register */
+       if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
+               iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
+                           EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
+                           EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
+                           EEPROM_RF_CFG_DASH_MSK(radio_cfg));
 
+       /* set CSR_HW_CONFIG_REG for uCode use */
        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 = 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;
-       }
-
-       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);
-       iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
-
-       iwl_release_nic_access(priv);
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       iwl4965_hw_card_show_info(priv);
-
-       /* end nic_init */
-
-       /* Allocate the RX queue, or reset if it is already allocated */
-       if (!rxq->bd) {
-               rc = iwl4965_rx_queue_alloc(priv);
-               if (rc) {
-                       IWL_ERROR("Unable to initialize Rx queue\n");
-                       return -ENOMEM;
-               }
-       } else
-               iwl4965_rx_queue_reset(priv, rxq);
-
-       iwl4965_rx_replenish(priv);
-
-       iwl4965_rx_init(priv, rxq);
-
-       spin_lock_irqsave(&priv->lock, flags);
+                   CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
+                   CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
 
-       rxq->need_update = 1;
-       iwl4965_rx_queue_update_write_ptr(priv, rxq);
+       priv->calib_info = (struct iwl_eeprom_calib_info *)
+               iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
 
        spin_unlock_irqrestore(&priv->lock, flags);
-
-       /* Allocate and init all Tx and Command queues */
-       rc = iwl4965_txq_ctx_reset(priv);
-       if (rc)
-               return rc;
-
-       if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
-               IWL_DEBUG_RF_KILL("SW RF KILL supported in EEPROM.\n");
-
-       if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
-               IWL_DEBUG_RF_KILL("HW RF KILL supported in EEPROM.\n");
-
-       set_bit(STATUS_INIT, &priv->status);
-
-       return 0;
 }
 
 int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
@@ -885,16 +621,16 @@ void iwl4965_hw_txq_ctx_stop(struct iwl_priv *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
+                                  FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
+               iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
+                                   FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
                                    (txq_id), 200);
                iwl_release_nic_access(priv);
                spin_unlock_irqrestore(&priv->lock, flags);
        }
 
        /* Deallocate memory for all Tx queues */
-       iwl4965_hw_txq_ctx_free(priv);
+       iwl_hw_txq_ctx_free(priv);
 }
 
 int iwl4965_hw_nic_reset(struct iwl_priv *priv)
@@ -962,15 +698,9 @@ static void iwl4965_bg_statistics_periodic(unsigned long data)
        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 iwl_priv *priv)
 {
        struct iwl4965_ct_kill_config cmd;
-       u32 R1, R2, R3;
-       u32 temp_th;
-       u32 crit_temperature;
        unsigned long flags;
        int ret = 0;
 
@@ -979,26 +709,17 @@ void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
                    CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       if (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK) {
-               R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
-               R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
-               R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
-       } else {
-               R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
-               R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
-               R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
-       }
-
-       temp_th = CELSIUS_TO_KELVIN(TM_CT_KILL_THRESHOLD);
+       cmd.critical_temperature_R =
+               cpu_to_le32(priv->hw_params.ct_kill_threshold);
 
-       crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2;
-       cmd.critical_temperature_R =  cpu_to_le32(crit_temperature);
        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");
+               IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
+                       "critical temperature is %d\n",
+                       cmd.critical_temperature_R);
 }
 
 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
@@ -1159,7 +880,7 @@ static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
  * NOTE:  Acquire priv->lock before calling this function !
  */
 static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
-                                       struct iwl4965_tx_queue *txq,
+                                       struct iwl_tx_queue *txq,
                                        int tx_fifo_id, int scd_retry)
 {
        int txq_id = txq->q.id;
@@ -1169,11 +890,11 @@ static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
 
        /* Set up and activate */
        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) |
-                                (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
-                                SCD_QUEUE_STTS_REG_MSK);
+                        (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
+                        (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
+                        (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
+                        (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
+                        IWL49_SCD_QUEUE_STTS_REG_MSK);
 
        txq->sched_retry = scd_retry;
 
@@ -1187,7 +908,7 @@ static const u16 default_queue_to_tx_fifo[] = {
        IWL_TX_FIFO_AC2,
        IWL_TX_FIFO_AC1,
        IWL_TX_FIFO_AC0,
-       IWL_CMD_FIFO_NUM,
+       IWL49_CMD_FIFO_NUM,
        IWL_TX_FIFO_HCCA_1,
        IWL_TX_FIFO_HCCA_2
 };
@@ -1228,10 +949,10 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
 
        /* Clear 4965's internal Tx Scheduler data base */
        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)
+       a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
+       for (; a < priv->scd_base_addr + IWL49_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)
+       for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
                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);
@@ -1253,18 +974,18 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
 
                /* Max Tx Window size for Scheduler-ACK mode */
                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);
+                               IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
+                               (SCD_WIN_SIZE <<
+                               IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
+                               IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
 
                /* Frame limit */
                iwl_write_targ_mem(priv, priv->scd_base_addr +
-                                       SCD_CONTEXT_QUEUE_OFFSET(i) +
-                                       sizeof(u32),
-                                       (SCD_FRAME_LIMIT <<
-                                       SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
-                                       SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
+                               IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
+                               sizeof(u32),
+                               (SCD_FRAME_LIMIT <<
+                               IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
+                               IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
 
        }
        iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
@@ -1325,14 +1046,15 @@ static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
 int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
 {
 
-       if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) ||
+       if ((priv->cfg->mod_params->num_of_queues > IWL49_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);
+                         IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
                return -EINVAL;
        }
 
        priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
+       priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
        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;
@@ -1344,10 +1066,17 @@ int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
        priv->hw_params.max_stations = IWL4965_STATION_COUNT;
        priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
 
+       priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
+       priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
+       priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
+       priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
+
        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);
+       priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
+       priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
+       priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
+
 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
        priv->hw_params.sens = &iwl4965_sensitivity;
 #endif
@@ -1355,82 +1084,6 @@ int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
        return 0;
 }
 
-/**
- * iwl4965_hw_txq_ctx_free - Free TXQ Context
- *
- * Destroy all TX DMA queues and structures
- */
-void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv)
-{
-       int txq_id;
-
-       /* Tx queues */
-       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 */
-       iwl4965_kw_free(priv);
-}
-
-/**
- * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
- *
- * 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 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];
-       struct pci_dev *dev = priv->pci_dev;
-       int i;
-       int counter = 0;
-       int index, is_odd;
-
-       /* Host command buffers stay mapped in memory, nothing to clean */
-       if (txq->q.id == IWL_CMD_QUEUE_NUM)
-               return 0;
-
-       /* Sanity check on number of chunks */
-       counter = IWL_GET_BITS(*bd, num_tbs);
-       if (counter > MAX_NUM_OF_TBS) {
-               IWL_ERROR("Too many chunks: %i\n", counter);
-               /* @todo issue fatal error, it is quite serious situation */
-               return 0;
-       }
-
-       /* Unmap chunks, if any.
-        * TFD info for odd chunks is different format than for even chunks. */
-       for (i = 0; i < counter; i++) {
-               index = i / 2;
-               is_odd = i & 0x1;
-
-               if (is_odd)
-                       pci_unmap_single(
-                               dev,
-                               IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
-                               (IWL_GET_BITS(bd->pa[index],
-                                             tb2_addr_hi20) << 16),
-                               IWL_GET_BITS(bd->pa[index], tb2_len),
-                               PCI_DMA_TODEVICE);
-
-               else if (i > 0)
-                       pci_unmap_single(dev,
-                                        le32_to_cpu(bd->pa[index].tb1_addr),
-                                        IWL_GET_BITS(bd->pa[index], tb1_len),
-                                        PCI_DMA_TODEVICE);
-
-               /* Free SKB, if any, for this chunk */
-               if (txq->txb[txq->q.read_ptr].skb[i]) {
-                       struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i];
-
-                       dev_kfree_skb(skb);
-                       txq->txb[txq->q.read_ptr].skb[i] = NULL;
-               }
-       }
-       return 0;
-}
-
 /* set card power command */
 static int iwl4965_set_power(struct iwl_priv *priv,
                      void *cmd)
@@ -1542,11 +1195,11 @@ static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
        s32 b = -1;
 
        for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
-               if (priv->eeprom.calib_info.band_info[b].ch_from == 0)
+               if (priv->calib_info->band_info[b].ch_from == 0)
                        continue;
 
-               if ((channel >= priv->eeprom.calib_info.band_info[b].ch_from)
-                   && (channel <= priv->eeprom.calib_info.band_info[b].ch_to))
+               if ((channel >= priv->calib_info->band_info[b].ch_from)
+                   && (channel <= priv->calib_info->band_info[b].ch_to))
                        break;
        }
 
@@ -1574,14 +1227,14 @@ static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  * in channel number.
  */
 static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
-                                   struct iwl4965_eeprom_calib_ch_info *chan_info)
+                                   struct iwl_eeprom_calib_ch_info *chan_info)
 {
        s32 s = -1;
        u32 c;
        u32 m;
-       const struct iwl4965_eeprom_calib_measure *m1;
-       const struct iwl4965_eeprom_calib_measure *m2;
-       struct iwl4965_eeprom_calib_measure *omeas;
+       const struct iwl_eeprom_calib_measure *m1;
+       const struct iwl_eeprom_calib_measure *m2;
+       struct iwl_eeprom_calib_measure *omeas;
        u32 ch_i1;
        u32 ch_i2;
 
@@ -1591,8 +1244,8 @@ static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
                return -1;
        }
 
-       ch_i1 = priv->eeprom.calib_info.band_info[s].ch1.ch_num;
-       ch_i2 = priv->eeprom.calib_info.band_info[s].ch2.ch_num;
+       ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
+       ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
        chan_info->ch_num = (u8) channel;
 
        IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
@@ -1600,9 +1253,9 @@ static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
 
        for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
                for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
-                       m1 = &(priv->eeprom.calib_info.band_info[s].ch1.
+                       m1 = &(priv->calib_info->band_info[s].ch1.
                               measurements[c][m]);
-                       m2 = &(priv->eeprom.calib_info.band_info[s].ch2.
+                       m2 = &(priv->calib_info->band_info[s].ch2.
                               measurements[c][m]);
                        omeas = &(chan_info->measurements[c][m]);
 
@@ -1921,8 +1574,8 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
        int i;
        int c;
        const struct iwl_channel_info *ch_info = NULL;
-       struct iwl4965_eeprom_calib_ch_info ch_eeprom_info;
-       const struct iwl4965_eeprom_calib_measure *measurement;
+       struct iwl_eeprom_calib_ch_info ch_eeprom_info;
+       const struct iwl_eeprom_calib_measure *measurement;
        s16 voltage;
        s32 init_voltage;
        s32 voltage_compensation;
@@ -1979,9 +1632,9 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
        /* hardware txpower limits ...
         * saturation (clipping distortion) txpowers are in half-dBm */
        if (band)
-               saturation_power = priv->eeprom.calib_info.saturation_power24;
+               saturation_power = priv->calib_info->saturation_power24;
        else
-               saturation_power = priv->eeprom.calib_info.saturation_power52;
+               saturation_power = priv->calib_info->saturation_power52;
 
        if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
            saturation_power > IWL_TX_POWER_SATURATION_MAX) {
@@ -2011,7 +1664,7 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
        iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
 
        /* calculate tx gain adjustment based on power supply voltage */
-       voltage = priv->eeprom.calib_info.voltage;
+       voltage = priv->calib_info->voltage;
        init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
        voltage_compensation =
            iwl4965_get_voltage_compensation(voltage, init_voltage);
@@ -2353,7 +2006,7 @@ void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
        tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
 }
 
-int iwl4965_hw_get_rx_read(struct iwl_priv *priv)
+static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
 {
        struct iwl4965_shared *s = priv->shared_virt;
        return le32_to_cpu(s->rb_closed) & 0xFFF;
@@ -2396,46 +2049,11 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
        return (sizeof(*tx_beacon_cmd) + frame_size);
 }
 
-/*
- * Tell 4965 where to find circular buffer of Tx Frame Descriptors for
- * given Tx queue, and enable the DMA channel used for that queue.
- *
- * 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 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 = iwl_grab_nic_access(priv);
-       if (rc) {
-               spin_unlock_irqrestore(&priv->lock, flags);
-               return rc;
-       }
-
-       /* Circular buffer (TFD queue in DRAM) physical base address */
-       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 */
-       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);
-       iwl_release_nic_access(priv);
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       return 0;
-}
-
 int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
                                 dma_addr_t addr, u16 len)
 {
        int index, is_odd;
-       struct iwl4965_tfd_frame *tfd = ptr;
+       struct iwl_tfd_frame *tfd = ptr;
        u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
 
        /* Each TFD can point to a maximum 20 Tx buffers */
@@ -2465,26 +2083,35 @@ int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
        return 0;
 }
 
-static void iwl4965_hw_card_show_info(struct iwl_priv *priv)
+static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
 {
-       u16 hw_version = priv->eeprom.board_revision_4965;
+       priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
+                                       sizeof(struct iwl4965_shared),
+                                       &priv->shared_phys);
+       if (!priv->shared_virt)
+               return -ENOMEM;
 
-       IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n",
-                      ((hw_version >> 8) & 0x0F),
-                      ((hw_version >> 8) >> 4), (hw_version & 0x00FF));
+       memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
+
+       priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
 
-       IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n",
-                      priv->eeprom.board_pba_number_4965);
+       return 0;
 }
 
-#define IWL_TX_CRC_SIZE                4
-#define IWL_TX_DELIMITER_SIZE  4
+static void iwl4965_free_shared_mem(struct iwl_priv *priv)
+{
+       if (priv->shared_virt)
+               pci_free_consistent(priv->pci_dev,
+                                   sizeof(struct iwl4965_shared),
+                                   priv->shared_virt,
+                                   priv->shared_phys);
+}
 
 /**
  * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  */
 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
-                                           struct iwl4965_tx_queue *txq,
+                                           struct iwl_tx_queue *txq,
                                            u16 byte_cnt)
 {
        int len;
@@ -2498,50 +2125,13 @@ static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
                       tfd_offset[txq->q.write_ptr], byte_cnt, len);
 
        /* If within first 64 entries, duplicate at end */
-       if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE)
+       if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
                IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
-                       tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr],
+                       tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
                        byte_cnt, len);
 }
 
 /**
- * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
- *
- * 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 iwl_priv *priv)
-{
-       u8 is_single = is_single_stream(priv);
-       u8 idle_state, rx_state;
-
-       priv->staging_rxon.rx_chain = 0;
-       rx_state = idle_state = 3;
-
-       /* Tell uCode which antennas are actually connected.
-        * Before first association, we assume all antennas are connected.
-        * Just after first association, iwl_chain_noise_calibration()
-        *    checks which antennas actually *are* connected. */
-       priv->staging_rxon.rx_chain |=
-           cpu_to_le16(priv->valid_antenna << RXON_RX_CHAIN_VALID_POS);
-
-       /* How many receivers should we use? */
-       iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state);
-       priv->staging_rxon.rx_chain |=
-               cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
-       priv->staging_rxon.rx_chain |=
-               cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
-
-       if (!is_single && (rx_state >= 2) &&
-           !test_bit(STATUS_POWER_PMI, &priv->status))
-               priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
-       else
-               priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
-
-       IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
-}
-
-/**
  * sign_extend - Sign extend a value using specified bit as sign-bit
  *
  * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
@@ -2701,9 +2291,10 @@ static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
                        priv->last_rx_noise);
 }
 
-void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
+void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
+                             struct iwl_rx_mem_buffer *rxb)
 {
-       struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
+       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        int change;
        s32 temp;
 
@@ -2927,7 +2518,7 @@ static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
        return 0;
 }
 
-static u32 iwl4965_translate_rx_status(u32 decrypt_in)
+static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
 {
        u32 decrypt_out = 0;
 
@@ -2988,10 +2579,10 @@ static u32 iwl4965_translate_rx_status(u32 decrypt_in)
 
 static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
                                       int include_phy,
-                                      struct iwl4965_rx_mem_buffer *rxb,
+                                      struct iwl_rx_mem_buffer *rxb,
                                       struct ieee80211_rx_status *stats)
 {
-       struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
+       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
            (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
        struct ieee80211_hdr *hdr;
@@ -3028,7 +2619,9 @@ 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_params.max_pkt_size || len < 16) {
+       /* In monitor mode allow 802.11 ACk frames (10 bytes) */
+       if (len > priv->hw_params.max_pkt_size ||
+           len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
                IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
                return;
        }
@@ -3039,7 +2632,7 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
        if (!include_phy) {
                /* New status scheme, need to translate */
                ampdu_status_legacy = ampdu_status;
-               ampdu_status = iwl4965_translate_rx_status(ampdu_status);
+               ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
        }
 
        /* start from MAC */
@@ -3057,7 +2650,7 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
        hdr = (struct ieee80211_hdr *)rxb->skb->data;
 
        /*  in case of HW accelerated crypto and bad decryption, drop */
-       if (!priv->cfg->mod_params->sw_crypto &&
+       if (!priv->hw_params.sw_crypto &&
            iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
                return;
 
@@ -3071,7 +2664,8 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
 }
 
 /* Calc max signal level (dBm) among 3 possible receivers */
-static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
+static int iwl4965_calc_rssi(struct iwl_priv *priv,
+                            struct iwl4965_rx_phy_res *rx_resp)
 {
        /* data from PHY/DSP regarding signal strength, etc.,
         *   contents are always there, not configurable by host.  */
@@ -3104,38 +2698,6 @@ static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
        return (max_rssi - agc - IWL_RSSI_OFFSET);
 }
 
-#ifdef CONFIG_IWL4965_HT
-
-void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
-                             struct ieee80211_ht_info *ht_info,
-                             enum ieee80211_band band)
-{
-       ht_info->cap = 0;
-       memset(ht_info->supp_mcs_set, 0, 16);
-
-       ht_info->ht_supported = 1;
-
-       if (band == IEEE80211_BAND_5GHZ) {
-               ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
-               ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
-               ht_info->supp_mcs_set[4] = 0x01;
-       }
-       ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
-       ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
-       ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
-                            (IWL_MIMO_PS_NONE << 2));
-
-       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;
-
-       ht_info->supp_mcs_set[0] = 0xFF;
-       ht_info->supp_mcs_set[1] = 0xFF;
-}
-#endif /* CONFIG_IWL4965_HT */
-
 static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
 {
        unsigned long flags;
@@ -3147,7 +2709,7 @@ static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
        priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
        spin_unlock_irqrestore(&priv->sta_lock, flags);
 
-       iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
+       iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
 }
 
 static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
@@ -3180,7 +2742,7 @@ static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
  *        proper operation with 4965.
  */
 static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
-                     struct iwl4965_rx_packet *pkt,
+                     struct iwl_rx_packet *pkt,
                      struct ieee80211_hdr *header, int group100)
 {
        u32 to_us;
@@ -3207,7 +2769,7 @@ static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
        struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
        u8 *data = IWL_RX_DATA(pkt);
 
-       if (likely(!(iwl_debug_level & IWL_DL_RX)))
+       if (likely(!(priv->debug_level & IWL_DL_RX)))
                return;
 
        /* MAC header */
@@ -3310,11 +2872,11 @@ static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
                }
        }
        if (print_dump)
-               iwl_print_hex_dump(IWL_DL_RX, data, length);
+               iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
 }
 #else
 static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
-                                           struct iwl4965_rx_packet *pkt,
+                                           struct iwl_rx_packet *pkt,
                                            struct ieee80211_hdr *header,
                                            int group100)
 {
@@ -3326,11 +2888,11 @@ static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
 /* Called for REPLY_RX (legacy ABG frames), or
  * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
 static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
-                               struct iwl4965_rx_mem_buffer *rxb)
+                               struct iwl_rx_mem_buffer *rxb)
 {
        struct ieee80211_hdr *header;
        struct ieee80211_rx_status rx_status;
-       struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
+       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        /* 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. */
@@ -3403,7 +2965,7 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
        priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
 
        /* Find max signal strength (dBm) among 3 antenna/receiver chains */
-       rx_status.ssi = iwl4965_calc_rssi(rx_start);
+       rx_status.ssi = iwl4965_calc_rssi(priv, rx_start);
 
        /* Meaningful noise values are available only from beacon statistics,
         *   which are gathered only when associated, and indicate noise
@@ -3431,6 +2993,13 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
                              rx_status.ssi, rx_status.noise, rx_status.signal,
                              (unsigned long long)rx_status.mactime);
 
+
+       if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
+               iwl4965_handle_data_packet(priv, 1, include_phy,
+                                                rxb, &rx_status);
+               return;
+       }
+
        network_packet = iwl4965_is_network_packet(priv, header);
        if (network_packet) {
                priv->last_rx_rssi = rx_status.ssi;
@@ -3495,19 +3064,19 @@ static void iwl4965_rx_reply_rx(struct iwl_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 iwl_priv *priv,
-                                   struct iwl4965_rx_mem_buffer *rxb)
+                                   struct iwl_rx_mem_buffer *rxb)
 {
-       struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
+       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        priv->last_phy_res[0] = 1;
        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)
+                                          struct iwl_rx_mem_buffer *rxb)
 
 {
 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
-       struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
+       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        struct iwl4965_missed_beacon_notif *missed_beacon;
 
        missed_beacon = &pkt->u.missed_beacon;
@@ -3539,7 +3108,7 @@ static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
        priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
        spin_unlock_irqrestore(&priv->sta_lock, flags);
 
-       iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
+       iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
 }
 
 /**
@@ -3549,7 +3118,7 @@ static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
  * ACK vs. not.  This gets sent to mac80211, then to rate scaling algo.
  */
 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
-                                                struct iwl4965_ht_agg *agg,
+                                                struct iwl_ht_agg *agg,
                                                 struct iwl4965_compressed_ba_resp*
                                                 ba_resp)
 
@@ -3620,8 +3189,8 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
         * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
        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));
+               (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
+               (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
 }
 
 /**
@@ -3666,7 +3235,7 @@ int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
 {
        struct iwl4965_queue *q = &priv->txq[txq_id].q;
        u8 *addr = priv->stations[sta_id].sta.sta.addr;
-       struct iwl4965_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
+       struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
 
        switch (priv->stations[sta_id].tid[tid].agg.state) {
        case IWL_EMPTYING_HW_QUEUE_DELBA:
@@ -3712,13 +3281,13 @@ static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
  * of frames sent via aggregation.
  */
 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
-                                          struct iwl4965_rx_mem_buffer *rxb)
+                                          struct iwl_rx_mem_buffer *rxb)
 {
-       struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
+       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
        struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
        int index;
-       struct iwl4965_tx_queue *txq = NULL;
-       struct iwl4965_ht_agg *agg;
+       struct iwl_tx_queue *txq = NULL;
+       struct iwl_ht_agg *agg;
        DECLARE_MAC_BUF(mac);
 
        /* "flow" corresponds to Tx queue */
@@ -3764,13 +3333,16 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
         * block-ack window (we assume that they've been successfully
         * transmitted ... if not, it's too late anyway). */
        if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
+               /* calculate mac80211 ampdu sw queue to wake */
+               int ampdu_q =
+                  scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues;
                int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index);
                priv->stations[ba_resp->sta_id].
                        tid[ba_resp->tid].tfds_in_queue -= freed;
                if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
                        priv->mac80211_registered &&
                        agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
-                       ieee80211_wake_queue(priv->hw, scd_flow);
+                       ieee80211_wake_queue(priv->hw, ampdu_q);
                iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id,
                        ba_resp->tid, scd_flow);
        }
@@ -3786,10 +3358,10 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
        u32 tbl_dw;
        u16 scd_q2ratid;
 
-       scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK;
+       scd_q2ratid = ra_tid & IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
 
        tbl_dw_addr = priv->scd_base_addr +
-                       SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
+                       IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
 
        tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
 
@@ -3851,14 +3423,14 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
 
        /* Set up Tx window size and frame limit for this queue */
        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);
+               priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
+               (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
+               IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
 
        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);
+               IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
+               (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
+               & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
 
        iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
 
@@ -3910,8 +3482,7 @@ void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
                        rate_flags |= RATE_MCS_CCK_MSK;
 
                /* Use Tx antenna B only */
-               rate_flags |= RATE_MCS_ANT_B_MSK;
-               rate_flags &= ~RATE_MCS_ANT_A_MSK;
+               rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
 
                link_cmd.rs_table[i].rate_n_flags =
                        iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags);
@@ -3932,101 +3503,6 @@ void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
 
 #ifdef CONFIG_IWL4965_HT
 
-static u8 iwl4965_is_channel_extension(struct iwl_priv *priv,
-                                      enum ieee80211_band band,
-                                      u16 channel, u8 extension_chan_offset)
-{
-       const struct iwl_channel_info *ch_info;
-
-       ch_info = iwl_get_channel_info(priv, band, channel);
-       if (!is_channel_valid(ch_info))
-               return 0;
-
-       if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)
-               return 0;
-
-       if ((ch_info->fat_extension_channel == extension_chan_offset) ||
-           (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
-               return 1;
-
-       return 0;
-}
-
-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;
-
-       if ((!iwl_ht_conf->is_ht) ||
-          (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) ||
-          (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE))
-               return 0;
-
-       if (sta_ht_inf) {
-               if ((!sta_ht_inf->ht_supported) ||
-                  (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
-                       return 0;
-       }
-
-       return (iwl4965_is_channel_extension(priv, priv->band,
-                                        iwl_ht_conf->control_channel,
-                                        iwl_ht_conf->extension_chan_offset));
-}
-
-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;
-
-       if (!ht_info->is_ht)
-               return;
-
-       /* Set up channel bandwidth:  20 MHz only, or 20/40 mixed if fat ok */
-       if (iwl4965_is_fat_tx_allowed(priv, NULL))
-               rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
-       else
-               rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
-                                RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
-
-       if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
-               IWL_DEBUG_ASSOC("control diff than current %d %d\n",
-                               le16_to_cpu(rxon->channel),
-                               ht_info->control_channel);
-               rxon->channel = cpu_to_le16(ht_info->control_channel);
-               return;
-       }
-
-       /* Note: control channel is opposite of extension channel */
-       switch (ht_info->extension_chan_offset) {
-       case IWL_EXT_CHANNEL_OFFSET_ABOVE:
-               rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
-               break;
-       case IWL_EXT_CHANNEL_OFFSET_BELOW:
-               rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
-               break;
-       case IWL_EXT_CHANNEL_OFFSET_NONE:
-       default:
-               rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
-               break;
-       }
-
-       val = ht_info->ht_protection;
-
-       rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
-
-       iwl4965_set_rxon_chain(priv);
-
-       IWL_DEBUG_ASSOC("supported HT rate 0x%X %X "
-                       "rxon flags 0x%X operation mode :0x%X "
-                       "extension channel offset 0x%x "
-                       "control chan %d\n",
-                       ht_info->supp_mcs_set[0], ht_info->supp_mcs_set[1],
-                       le32_to_cpu(rxon->flags), ht_info->ht_protection,
-                       ht_info->extension_chan_offset,
-                       ht_info->control_channel);
-       return;
-}
-
 void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
                                struct ieee80211_ht_info *sta_ht_inf)
 {
@@ -4062,7 +3538,7 @@ void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
        sta_flags |= cpu_to_le32(
              (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
 
-       if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf))
+       if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
                sta_flags |= STA_FLG_FAT_EN_MSK;
        else
                sta_flags &= ~STA_FLG_FAT_EN_MSK;
@@ -4090,7 +3566,7 @@ static int iwl4965_rx_agg_start(struct iwl_priv *priv,
        priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
        spin_unlock_irqrestore(&priv->sta_lock, flags);
 
-       return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta,
+       return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
                                        CMD_ASYNC);
 }
 
@@ -4111,7 +3587,7 @@ static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
        priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
        spin_unlock_irqrestore(&priv->sta_lock, flags);
 
-       return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta,
+       return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
                                        CMD_ASYNC);
 }
 
@@ -4141,7 +3617,7 @@ static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra,
        int ssn = -1;
        int ret = 0;
        unsigned long flags;
-       struct iwl4965_tid_data *tid_data;
+       struct iwl_tid_data *tid_data;
        DECLARE_MAC_BUF(mac);
 
        if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
@@ -4194,7 +3670,7 @@ static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid)
 {
        struct iwl_priv *priv = hw->priv;
        int tx_fifo_id, txq_id, sta_id, ssn = -1;
-       struct iwl4965_tid_data *tid_data;
+       struct iwl_tid_data *tid_data;
        int ret, write_ptr, read_ptr;
        unsigned long flags;
        DECLARE_MAC_BUF(mac);
@@ -4276,11 +3752,28 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
        }
        return 0;
 }
-
 #endif /* CONFIG_IWL4965_HT */
 
+
+static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
+{
+       struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
+       addsta->mode = cmd->mode;
+       memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
+       memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
+       addsta->station_flags = cmd->station_flags;
+       addsta->station_flags_msk = cmd->station_flags_msk;
+       addsta->tid_disable_tx = cmd->tid_disable_tx;
+       addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
+       addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
+       addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
+       addsta->reserved1 = __constant_cpu_to_le16(0);
+       addsta->reserved2 = __constant_cpu_to_le32(0);
+
+       return (u16)sizeof(struct iwl4965_addsta_cmd);
+}
 /* Set up 4965-specific Rx frame reply handlers */
-void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv)
+static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
 {
        /* Legacy Rx frames */
        priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
@@ -4322,6 +3815,7 @@ static struct iwl_hcmd_ops iwl4965_hcmd = {
 
 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
        .enqueue_hcmd = iwl4965_enqueue_hcmd,
+       .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
        .chain_noise_reset = iwl4965_chain_noise_reset,
        .gain_computation = iwl4965_gain_computation,
@@ -4329,20 +3823,37 @@ static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
 };
 
 static struct iwl_lib_ops iwl4965_lib = {
-       .init_drv = iwl4965_init_drv,
        .set_hw_params = iwl4965_hw_set_hw_params,
+       .alloc_shared_mem = iwl4965_alloc_shared_mem,
+       .free_shared_mem = iwl4965_free_shared_mem,
+       .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
        .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
-       .hw_nic_init = iwl4965_hw_nic_init,
+       .disable_tx_fifo = iwl4965_disable_tx_fifo,
+       .rx_handler_setup = iwl4965_rx_handler_setup,
        .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
        .alive_notify = iwl4965_alive_notify,
+       .init_alive_start = iwl4965_init_alive_start,
        .load_ucode = iwl4965_load_bsm,
        .apm_ops = {
+               .init = iwl4965_apm_init,
+               .config = iwl4965_nic_config,
                .set_pwr_src = iwl4965_set_pwr_src,
        },
        .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REGULATORY_BAND_1_CHANNELS,
+                       EEPROM_REGULATORY_BAND_2_CHANNELS,
+                       EEPROM_REGULATORY_BAND_3_CHANNELS,
+                       EEPROM_REGULATORY_BAND_4_CHANNELS,
+                       EEPROM_REGULATORY_BAND_5_CHANNELS,
+                       EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
+                       EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
+               },
                .verify_signature  = iwlcore_eeprom_verify_signature,
                .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
                .release_semaphore = iwlcore_eeprom_release_semaphore,
+               .check_version = iwl4965_eeprom_check_version,
+               .query_addr = iwlcore_eeprom_query_addr,
        },
        .radio_kill_sw = iwl4965_radio_kill_sw,
        .set_power = iwl4965_set_power,
@@ -4359,6 +3870,7 @@ 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,
+       .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
        .ops = &iwl4965_ops,
        .mod_params = &iwl4965_mod_params,
 };